Commit 39012810 authored by Jiří Klimeš's avatar Jiří Klimeš

cli: 'connection add' command for adding NM connections non-interactively

A few examples:
nmcli --ask connection add
nmcli connection add type ethernet
nmcli -p connection add type ethernet con-name "my ethernet connection 1"
nmcli connection add type ethernet ip4 192.168.100.5/24
nmcli connection add type ethernet ip4 192.168.100.100/24 gw4 192.168.100.1 ip4 1.2.3.4 ip6 abbe::cafe
nmcli connection add type ethernet ifname eth0
nmcli connection add type ethernet autoconnect no ifname eth0
nmcli connection add type wifi con-name Rakosnicek ssid Brcalnik
nmcli --ask connection add type wifi con-name My_WiFi
nmcli c a type infiniband con-name Infi1 transport-mode connected
nmcli c a type bluetooth addr 12:54:00:fd:db:26
nmcli c a type bluetooth addr 12:54:00:fd:db:26 bt-type dun-cdma
nmcli c a type gsm apn internet
nmcli c a type cdma
nmcli c a type bond
nmcli c a type bond ifname mybond0 mode active-backup
nmcli c a ifname maxipes-fik type vlan dev eth0 id 55
nmcli c a con-name VLAN1 type vlan dev eth0 id 44 ingress "2:4,3:55" egress "1:3" flags 6
nmcli c a type bridge ifname br0 stp on ip4 10.0.0.25
nmcli c a ifname eth0 type bridge-slave master 30fc816a-e7dd-4ae7-a86e-ab0c9cee51c2 hairpin no path-cost 333 priority 20
nmcli c a type bridge-slave master br2
parent 5761a46d
......@@ -801,3 +801,64 @@ nmc_device_reason_to_string (NMDeviceStateReason reason)
}
}
/* Max priority values from libnm-util/nm-setting-vlan.c */
#define MAX_SKB_PRIO G_MAXUINT32
#define MAX_8021P_PRIO 7 /* Max 802.1p priority */
/*
* Parse VLAN priority mappings from the following format: 2:1,3:4,7:3
* and verify if the priority numbers are valid
*
* Return: string array with split maps, or NULL on error
* Caller is responsible for freeing the array.
*/
char **
nmc_vlan_parse_priority_maps (const char *priority_map,
NMVlanPriorityMap map_type,
GError **error)
{
char **mapping = NULL, **iter;
unsigned long from, to, from_max, to_max;
g_return_val_if_fail (priority_map != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
if (map_type == NM_VLAN_INGRESS_MAP) {
from_max = MAX_8021P_PRIO;
to_max = MAX_SKB_PRIO;
} else {
from_max = MAX_SKB_PRIO;
to_max = MAX_8021P_PRIO;
}
mapping = g_strsplit (priority_map, ",", 0);
for (iter = mapping; iter && *iter; iter++) {
char *left, *right;
left = g_strstrip (*iter);
right = strchr (left, ':');
if (!right) {
g_set_error (error, 1, 0, _("invalid priority map '%s'"), *iter);
g_strfreev (mapping);
return NULL;
}
*right++ = '\0';
if (!nmc_string_to_uint (left, TRUE, 0, from_max, &from)) {
g_set_error (error, 1, 0, _("priority '%s' is not valid (<0-%ld>)"),
left, from_max);
g_strfreev (mapping);
return NULL;
}
if (!nmc_string_to_uint (right, TRUE, 0, to_max, &to)) {
g_set_error (error, 1, 0, _("priority '%s' is not valid (<0-%ld>)"),
right, to_max);
g_strfreev (mapping);
return NULL;
}
*(right-1) = ':'; /* Put back ':' */
}
return mapping;
}
......@@ -46,4 +46,9 @@ NMIP6Route *nmc_parse_and_build_ip6_route (const char *ip_str, const char *next_
const char * nmc_device_state_to_string (NMDeviceState state);
const char * nmc_device_reason_to_string (NMDeviceStateReason reason);
char **
nmc_vlan_parse_priority_maps (const char *priority_map,
NMVlanPriorityMap map_type,
GError **error);
#endif /* NMC_COMMON_H */
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment