summaryrefslogtreecommitdiff
path: root/clients/cli/settings.c
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2015-09-18 11:03:17 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2015-12-09 14:30:08 +0100
commitc3e6e25239ea691cc3eb7ee3d443a29f54d3bdfb (patch)
treed2c7ab330422d00049e2cd5c26c5b5147a145ba2 /clients/cli/settings.c
parent4d0192e661e08727bb53295934ec8c3756bd93d7 (diff)
downloadNetworkManager-c3e6e25239ea691cc3eb7ee3d443a29f54d3bdfb.tar.gz
cli: add macvlan support
Diffstat (limited to 'clients/cli/settings.c')
-rw-r--r--clients/cli/settings.c131
1 files changed, 131 insertions, 0 deletions
diff --git a/clients/cli/settings.c b/clients/cli/settings.c
index 3e8c10f4c2..05e5580165 100644
--- a/clients/cli/settings.c
+++ b/clients/cli/settings.c
@@ -748,6 +748,22 @@ NmcOutputField nmc_fields_setting_ip_tunnel[] = {
NM_SETTING_IP_TUNNEL_FLOW_LABEL
#define NMC_FIELDS_SETTING_IP_TUNNEL_COMMON NMC_FIELDS_SETTING_IP_TUNNEL_ALL
+/* Available fields for NM_SETTING_MACVLAN_SETTING_NAME */
+NmcOutputField nmc_fields_setting_macvlan[] = {
+ SETTING_FIELD ("name"), /* 0 */
+ SETTING_FIELD (NM_SETTING_MACVLAN_PARENT), /* 1 */
+ SETTING_FIELD (NM_SETTING_MACVLAN_MODE), /* 2 */
+ SETTING_FIELD (NM_SETTING_MACVLAN_PROMISCUOUS), /* 3 */
+ SETTING_FIELD (NM_SETTING_MACVLAN_TAP), /* 4 */
+ {NULL, NULL, 0, NULL, FALSE, FALSE, 0}
+};
+#define NMC_FIELDS_SETTING_MACVLAN_ALL "name"","\
+ NM_SETTING_MACVLAN_PARENT","\
+ NM_SETTING_MACVLAN_MODE","\
+ NM_SETTING_MACVLAN_PROMISCUOUS","\
+ NM_SETTING_MACVLAN_TAP
+#define NMC_FIELDS_SETTING_MACVLAN_COMMON NMC_FIELDS_SETTING_MACVLAN_ALL
+
/*----------------------------------------------------------------------------*/
static char *
wep_key_type_to_string (NMWepKeyType type)
@@ -1866,6 +1882,61 @@ nmc_property_wifi_sec_get_wep_key_type (NMSetting *setting, NmcPropertyGetType g
return wep_key_type_to_string (nm_setting_wireless_security_get_wep_key_type (s_wireless_sec));
}
+/* --- NM_SETTING_MACVLAN_SETTING_NAME property get functions --- */
+DEFINE_GETTER (nmc_property_macvlan_get_parent, NM_SETTING_MACVLAN_PARENT)
+DEFINE_GETTER (nmc_property_macvlan_get_promiscuous, NM_SETTING_MACVLAN_PROMISCUOUS)
+DEFINE_GETTER (nmc_property_macvlan_get_tap, NM_SETTING_MACVLAN_TAP)
+
+static char *
+nmc_property_macvlan_get_mode (NMSetting *setting, NmcPropertyGetType get_type)
+{
+ NMSettingMacvlan *s_macvlan = NM_SETTING_MACVLAN (setting);
+ NMSettingMacvlanMode mode;
+ char *tmp, *str;
+
+ mode = nm_setting_macvlan_get_mode (s_macvlan);
+ tmp = nm_utils_enum_to_str (nm_setting_macvlan_mode_get_type (), mode);
+
+ if (get_type == NMC_PROPERTY_GET_PARSABLE)
+ str = g_strdup (tmp ? tmp : "");
+ else
+ str = g_strdup_printf ("%d (%s)", mode, tmp ? tmp : "");
+ g_free (tmp);
+
+ return str;
+}
+
+static gboolean
+nmc_property_macvlan_set_mode (NMSetting *setting, const char *prop,
+ const char *val, GError **error)
+{
+ NMSettingMacvlanMode mode;
+ gs_free const char **options = NULL;
+ gs_free char *options_str = NULL;
+ long int t;
+ gboolean ret;
+
+ if (nmc_string_to_int_base (val, 0, TRUE, 0, _NM_SETTING_MACVLAN_MODE_NUM - 1, &t))
+ mode = (NMSettingMacvlanMode) t;
+ else {
+ ret = nm_utils_enum_from_str (nm_setting_macvlan_mode_get_type (), val,
+ (int *) &mode, NULL);
+
+ if (!ret) {
+ options = nm_utils_enum_get_values (nm_setting_macvlan_mode_get_type(),
+ NM_SETTING_MACVLAN_MODE_UNKNOWN + 1,
+ G_MAXINT);
+ options_str = g_strjoinv (",", (char **) options);
+ g_set_error (error, 1, 0, _("invalid option '%s', use one of [%s]"),
+ val, options_str);
+ return FALSE;
+ }
+ }
+
+ g_object_set (setting, prop, (guint) mode, NULL);
+ return TRUE;
+}
+
/*----------------------------------------------------------------------------*/
static void
@@ -7231,6 +7302,36 @@ nmc_properties_init (void)
NULL,
NULL,
NULL);
+
+ /* Add editable properties for NM_SETTING_MACVLAN_SETTING_NAME */
+ nmc_add_prop_funcs (GLUE (MACVLAN, PARENT),
+ nmc_property_macvlan_get_parent,
+ nmc_property_set_string,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+ nmc_add_prop_funcs (GLUE (MACVLAN, MODE),
+ nmc_property_macvlan_get_mode,
+ nmc_property_macvlan_set_mode,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+ nmc_add_prop_funcs (GLUE (MACVLAN, PROMISCUOUS),
+ nmc_property_macvlan_get_promiscuous,
+ nmc_property_set_bool,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+ nmc_add_prop_funcs (GLUE (MACVLAN, TAP),
+ nmc_property_macvlan_get_tap,
+ nmc_property_set_bool,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
}
void
@@ -8447,6 +8548,35 @@ setting_ip_tunnel_details (NMSetting *setting, NmCli *nmc, const char *one_prop
return TRUE;
}
+static gboolean
+setting_macvlan_details (NMSetting *setting, NmCli *nmc, const char *one_prop, gboolean secrets)
+{
+ NMSettingMacvlan *s_macvlan = NM_SETTING_MACVLAN (setting);
+ NmcOutputField *tmpl, *arr;
+ size_t tmpl_len;
+
+ g_return_val_if_fail (NM_IS_SETTING_MACVLAN (s_macvlan), FALSE);
+
+ tmpl = nmc_fields_setting_macvlan;
+ tmpl_len = sizeof (nmc_fields_setting_macvlan);
+ nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_MACVLAN_ALL,
+ tmpl, FALSE, NULL, NULL);
+ arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES);
+ g_ptr_array_add (nmc->output_data, arr);
+
+ arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX);
+ set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting)));
+ set_val_str (arr, 1, nmc_property_macvlan_get_parent (setting, NMC_PROPERTY_GET_PRETTY));
+ set_val_str (arr, 2, nmc_property_macvlan_get_mode (setting, NMC_PROPERTY_GET_PRETTY));
+ set_val_str (arr, 3, nmc_property_macvlan_get_promiscuous (setting, NMC_PROPERTY_GET_PRETTY));
+ set_val_str (arr, 4, nmc_property_macvlan_get_tap (setting, NMC_PROPERTY_GET_PRETTY));
+ g_ptr_array_add (nmc->output_data, arr);
+
+ print_data (nmc); /* Print all data */
+
+ return TRUE;
+}
+
typedef struct {
const char *sname;
gboolean (*func) (NMSetting *setting, NmCli *nmc, const char *one_prop, gboolean secrets);
@@ -8480,6 +8610,7 @@ static const SettingDetails detail_printers[] = {
{ NM_SETTING_DCB_SETTING_NAME, setting_dcb_details },
{ NM_SETTING_TUN_SETTING_NAME, setting_tun_details },
{ NM_SETTING_IP_TUNNEL_SETTING_NAME, setting_ip_tunnel_details },
+ { NM_SETTING_MACVLAN_SETTING_NAME, setting_macvlan_details },
{ NULL },
};