cli: allow specifying a 'dev' option when adding IP tunnels

This commit is contained in:
Beniamino Galvani
2015-12-16 13:49:31 +01:00
parent e62c0c2547
commit f4dd37fdcb

View File

@@ -4579,12 +4579,12 @@ do_questionnaire_tun (char **user, char **group,
} }
static void static void
do_questionnaire_ip_tunnel (char **local) do_questionnaire_ip_tunnel (char **local, char **parent)
{ {
gboolean once_more; gboolean once_more;
/* Ask for optional 'ip-tunnel' arguments. */ /* Ask for optional 'ip-tunnel' arguments. */
if (!want_provide_opt_args (_("IP Tunnel"), 1)) if (!want_provide_opt_args (_("IP Tunnel"), 2))
return; return;
if (!*local) { if (!*local) {
@@ -4601,6 +4601,20 @@ do_questionnaire_ip_tunnel (char **local)
} }
} while (once_more); } while (once_more);
} }
if (!*parent) {
do {
*parent = nmc_readline (_("Parent device [none]: "));
once_more = *parent
&& !nm_utils_is_uuid (*parent)
&& !nm_utils_iface_valid_name (*parent);
if (once_more) {
g_print (_("Error: 'dev': '%s' is neither UUID nor interface name.\n"),
*parent);
g_free (*parent);
}
} while (once_more);
}
} }
static gboolean static gboolean
@@ -6135,11 +6149,14 @@ cleanup_tun:
/* Build up the settings required for 'ip-tunnel' */ /* Build up the settings required for 'ip-tunnel' */
const char *mode_c = NULL, *local_c = NULL, *remote_c = NULL; const char *mode_c = NULL, *local_c = NULL, *remote_c = NULL;
char *mode_ask = NULL, *remote_ask = NULL, *local = NULL; char *mode_ask = NULL, *remote_ask = NULL, *local = NULL;
const char *parent_c = NULL;
char *parent = NULL;
gboolean success = FALSE; gboolean success = FALSE;
NMIPTunnelMode mode_enum; NMIPTunnelMode mode_enum;
nmc_arg_t exp_args[] = { {"mode", TRUE, &mode_c, !ask}, nmc_arg_t exp_args[] = { {"mode", TRUE, &mode_c, !ask},
{"local", TRUE, &local_c, FALSE}, {"local", TRUE, &local_c, FALSE},
{"remote", TRUE, &remote_c, !ask}, {"remote", TRUE, &remote_c, !ask},
{"dev", TRUE, &parent_c, FALSE},
{NULL} }; {NULL} };
if (!nmc_parse_args (exp_args, FALSE, &argc, &argv, error)) if (!nmc_parse_args (exp_args, FALSE, &argc, &argv, error))
@@ -6185,8 +6202,9 @@ cleanup_tun:
} }
local = g_strdup (local_c); local = g_strdup (local_c);
parent = g_strdup (parent_c);
if (ask) if (ask)
do_questionnaire_ip_tunnel (&local); do_questionnaire_ip_tunnel (&local, &parent);
if ( local if ( local
&& !nm_utils_ipaddr_valid (AF_INET, local) && !nm_utils_ipaddr_valid (AF_INET, local)
@@ -6197,6 +6215,16 @@ cleanup_tun:
goto cleanup_tunnel; goto cleanup_tunnel;
} }
if (parent) {
if ( !nm_utils_is_uuid (parent)
&& !nm_utils_iface_valid_name (parent)) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("Error: 'dev': '%s' is neither UUID nor interface name."),
parent);
goto cleanup_tunnel;
}
}
/* Add 'tunnel' setting */ /* Add 'tunnel' setting */
s_ip_tunnel = (NMSettingIPTunnel *) nm_setting_ip_tunnel_new (); s_ip_tunnel = (NMSettingIPTunnel *) nm_setting_ip_tunnel_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip_tunnel)); nm_connection_add_setting (connection, NM_SETTING (s_ip_tunnel));
@@ -6206,6 +6234,8 @@ cleanup_tun:
g_object_set (s_ip_tunnel, NM_SETTING_IP_TUNNEL_REMOTE, remote_c, NULL); g_object_set (s_ip_tunnel, NM_SETTING_IP_TUNNEL_REMOTE, remote_c, NULL);
if (local) if (local)
g_object_set (s_ip_tunnel, NM_SETTING_IP_TUNNEL_LOCAL, local, NULL); g_object_set (s_ip_tunnel, NM_SETTING_IP_TUNNEL_LOCAL, local, NULL);
if (parent)
g_object_set (s_ip_tunnel, NM_SETTING_IP_TUNNEL_PARENT, parent, NULL);
/* Set default values for IPv6 tunnels */ /* Set default values for IPv6 tunnels */
if (nm_utils_ipaddr_valid (AF_INET6, remote_c)) { if (nm_utils_ipaddr_valid (AF_INET6, remote_c)) {
@@ -6217,6 +6247,8 @@ cleanup_tun:
cleanup_tunnel: cleanup_tunnel:
g_free (remote_ask); g_free (remote_ask);
g_free (mode_ask); g_free (mode_ask);
g_free (parent);
g_free (local);
if (!success) if (!success)
return FALSE; return FALSE;