Commit 64c6b124 authored by Beniamino Galvani's avatar Beniamino Galvani

cli: add support for tun settings

Add nmcli support for adding and modifying TUN/TAP connections.
parent 1f30147a
This diff is collapsed.
......@@ -698,8 +698,27 @@ NmcOutputField nmc_fields_setting_dcb[] = {
NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS
#define NMC_FIELDS_SETTING_DCB_COMMON NMC_FIELDS_SETTING_DCB_ALL
/*----------------------------------------------------------------------------*/
/* Available fields for NM_SETTING_TUN_SETTING_NAME */
NmcOutputField nmc_fields_setting_tun[] = {
SETTING_FIELD ("name"), /* 0 */
SETTING_FIELD (NM_SETTING_TUN_MODE), /* 1 */
SETTING_FIELD (NM_SETTING_TUN_OWNER), /* 2 */
SETTING_FIELD (NM_SETTING_TUN_GROUP), /* 3 */
SETTING_FIELD (NM_SETTING_TUN_PI), /* 4 */
SETTING_FIELD (NM_SETTING_TUN_VNET_HDR), /* 5 */
SETTING_FIELD (NM_SETTING_TUN_MULTI_QUEUE), /* 6 */
{NULL, NULL, 0, NULL, FALSE, FALSE, 0}
};
#define NMC_FIELDS_SETTING_TUN_ALL "name"","\
NM_SETTING_TUN_MODE","\
NM_SETTING_TUN_OWNER","\
NM_SETTING_TUN_GROUP","\
NM_SETTING_TUN_PI","\
NM_SETTING_TUN_VNET_HDR","\
NM_SETTING_TUN_MULTI_QUEUE
#define NMC_FIELDS_SETTING_TUN_COMMON NMC_FIELDS_SETTING_TUN_ALL
/*----------------------------------------------------------------------------*/
static char *
wep_key_type_to_string (NMWepKeyType type)
{
......@@ -1284,6 +1303,13 @@ DEFINE_GETTER (nmc_property_gsm_get_sim_operator_id, NM_SETTING_GSM_SIM_OPERATOR
DEFINE_GETTER (nmc_property_ib_get_mac_address, NM_SETTING_INFINIBAND_MAC_ADDRESS)
DEFINE_GETTER (nmc_property_ib_get_transport_mode, NM_SETTING_INFINIBAND_TRANSPORT_MODE)
/* --- NM_SETTING_TUN_SETTING_NAME property get functions --- */
DEFINE_GETTER (nmc_property_tun_get_owner, NM_SETTING_TUN_OWNER);
DEFINE_GETTER (nmc_property_tun_get_group, NM_SETTING_TUN_GROUP);
DEFINE_GETTER (nmc_property_tun_get_pi, NM_SETTING_TUN_PI);
DEFINE_GETTER (nmc_property_tun_get_vnet_hdr, NM_SETTING_TUN_VNET_HDR);
DEFINE_GETTER (nmc_property_tun_get_multi_queue, NM_SETTING_TUN_MULTI_QUEUE);
static char *
nmc_property_ib_get_mtu (NMSetting *setting, NmcPropertyGetType get_type)
{
......@@ -5226,7 +5252,6 @@ nmc_property_gsm_set_sim_operator_id (NMSetting *setting, const char *prop, cons
return FALSE;
}
}
g_object_set (G_OBJECT (setting),
NM_SETTING_GSM_SIM_OPERATOR_ID,
val,
......@@ -5234,6 +5259,48 @@ nmc_property_gsm_set_sim_operator_id (NMSetting *setting, const char *prop, cons
return TRUE;
}
static char *
nmc_property_tun_get_mode (NMSetting *setting, NmcPropertyGetType get_type)
{
NMSettingTun *s_tun = NM_SETTING_TUN (setting);
NMSettingTunMode mode;
char *tmp, *str;
mode = nm_setting_tun_get_mode (s_tun);
tmp = nm_utils_enum_to_str (nm_setting_tun_mode_get_type (), mode);
if (get_type == NMC_PROPERTY_GET_PARSABLE)
str = g_strdup_printf ("%s", tmp ? tmp : "");
else
str = g_strdup_printf ("%d (%s)", mode, tmp ? tmp : "");
g_free (tmp);
return str;
}
static gboolean
nmc_property_tun_set_mode (NMSetting *setting, const char *prop,
const char *val, GError **error)
{
NMSettingTunMode mode;
gboolean ret;
long int t;
if (nmc_string_to_int_base (val, 0, TRUE, 0, NM_SETTING_TUN_MODE_TAP, &t))
mode = (NMSettingTunMode) t;
else {
ret = nm_utils_enum_from_str (nm_setting_tun_mode_get_type (), val,
(int *) &mode, NULL);
if (!ret) {
g_set_error (error, 1, 0, _("invalid option '%s', use '%s' or '%s"),
val, "tun", "tap");
return FALSE;
}
}
g_object_set (setting, prop, (guint) mode, NULL);
return TRUE;
}
/*----------------------------------------------------------------------------*/
static inline void
......@@ -6934,6 +7001,50 @@ nmc_properties_init (void)
NULL,
NULL,
NULL);
/* Add editable properties for NM_SETTING_TUN_SETTING_NAME */
nmc_add_prop_funcs (GLUE (TUN, MODE),
nmc_property_tun_get_mode,
nmc_property_tun_set_mode,
NULL,
NULL,
NULL,
NULL);
nmc_add_prop_funcs (GLUE (TUN, OWNER),
nmc_property_tun_get_owner,
nmc_property_set_string,
NULL,
NULL,
NULL,
NULL);
nmc_add_prop_funcs (GLUE (TUN, GROUP),
nmc_property_tun_get_group,
nmc_property_set_string,
NULL,
NULL,
NULL,
NULL);
nmc_add_prop_funcs (GLUE (TUN, PI),
nmc_property_tun_get_pi,
nmc_property_set_bool,
NULL,
NULL,
NULL,
NULL);
nmc_add_prop_funcs (GLUE (TUN, VNET_HDR),
nmc_property_tun_get_vnet_hdr,
nmc_property_set_bool,
NULL,
NULL,
NULL,
NULL);
nmc_add_prop_funcs (GLUE (TUN, MULTI_QUEUE),
nmc_property_tun_get_multi_queue,
nmc_property_set_bool,
NULL,
NULL,
NULL,
NULL);
}
void
......@@ -8083,6 +8194,37 @@ setting_dcb_details (NMSetting *setting, NmCli *nmc, const char *one_prop, gboo
return TRUE;
}
static gboolean
setting_tun_details (NMSetting *setting, NmCli *nmc, const char *one_prop, gboolean secrets)
{
NMSettingTun *s_tun = NM_SETTING_TUN (setting);
NmcOutputField *tmpl, *arr;
size_t tmpl_len;
g_return_val_if_fail (NM_IS_SETTING_TUN (s_tun), FALSE);
tmpl = nmc_fields_setting_tun;
tmpl_len = sizeof (nmc_fields_setting_tun);
nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_TUN_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_tun_get_mode (setting, NMC_PROPERTY_GET_PRETTY));
set_val_str (arr, 2, nmc_property_tun_get_owner (setting, NMC_PROPERTY_GET_PRETTY));
set_val_str (arr, 3, nmc_property_tun_get_group (setting, NMC_PROPERTY_GET_PRETTY));
set_val_str (arr, 4, nmc_property_tun_get_pi (setting, NMC_PROPERTY_GET_PRETTY));
set_val_str (arr, 5, nmc_property_tun_get_vnet_hdr (setting, NMC_PROPERTY_GET_PRETTY));
set_val_str (arr, 6, nmc_property_tun_get_multi_queue (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);
......@@ -8114,6 +8256,7 @@ static const SettingDetails detail_printers[] = {
{ NM_SETTING_TEAM_SETTING_NAME, setting_team_details },
{ NM_SETTING_TEAM_PORT_SETTING_NAME, setting_team_port_details },
{ NM_SETTING_DCB_SETTING_NAME, setting_dcb_details },
{ NM_SETTING_TUN_SETTING_NAME, setting_tun_details },
{ NULL },
};
......
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