Commit f17699f4 authored by Dan Winship's avatar Dan Winship

libnm-core: add NMSettingIPConfig:gateway, drop NMIPAddress:gateway

The gateway is a global property of the IPv4/IPv6 configuration, not
an attribute of any particular address. So represent it as such in the
API; remove the gateway from NMIPAddress, and add it to
NMSettingIPConfig.

Behind the scenes, the gateway is still serialized along with the
first address in NMSettingIPConfig:addresses, and is deserialized from
that if the settings dictionary doesn't contain a 'gateway' key.

Adjust nmcli's interactive mode to prompt for IP addresses and gateway
separately. (Patch partly from Jirka Klimeš.)
parent 329791ad
......@@ -92,7 +92,7 @@ static GSList *
construct_ip4_items (GSList *items, GVariant *ip4_config, const char *prefix)
{
GPtrArray *addresses, *routes;
char **dns, **wins;
char **dns, **wins, *gateway;
GString *tmp;
GVariant *val;
int i;
......@@ -106,26 +106,24 @@ construct_ip4_items (GSList *items, GVariant *ip4_config, const char *prefix)
/* IP addresses */
val = g_variant_lookup_value (ip4_config, "addresses", G_VARIANT_TYPE ("aau"));
if (val) {
addresses = nm_utils_ip4_addresses_from_variant (val);
addresses = nm_utils_ip4_addresses_from_variant (val, &gateway);
if (!gateway)
gateway = g_strdup ("0.0.0.0");
for (i = 0; i < addresses->len; i++) {
NMIPAddress *addr = addresses->pdata[i];
const char *gw;
char *addrtmp;
gw = nm_ip_address_get_gateway (addr);
if (!gw)
gw = "0.0.0.0";
addrtmp = g_strdup_printf ("%sIP4_ADDRESS_%d=%s/%d %s", prefix, i,
nm_ip_address_get_address (addr),
nm_ip_address_get_prefix (addr),
gw);
gateway);
items = g_slist_prepend (items, addrtmp);
}
if (addresses->len)
items = g_slist_prepend (items, g_strdup_printf ("%sIP4_NUM_ADDRESSES=%d", prefix, addresses->len));
g_ptr_array_unref (addresses);
g_free (gateway);
g_variant_unref (val);
}
......@@ -228,7 +226,7 @@ static GSList *
construct_ip6_items (GSList *items, GVariant *ip6_config, const char *prefix)
{
GPtrArray *addresses, *routes;
char **dns;
char **dns, *gateway = NULL;
GString *tmp;
GVariant *val;
int i;
......@@ -242,26 +240,24 @@ construct_ip6_items (GSList *items, GVariant *ip6_config, const char *prefix)
/* IP addresses */
val = g_variant_lookup_value (ip6_config, "addresses", G_VARIANT_TYPE ("a(ayuay)"));
if (val) {
addresses = nm_utils_ip6_addresses_from_variant (val);
addresses = nm_utils_ip6_addresses_from_variant (val, &gateway);
if (!gateway)
gateway = g_strdup ("::");
for (i = 0; i < addresses->len; i++) {
NMIPAddress *addr = addresses->pdata[i];
const char *gw;
char *addrtmp;
gw = nm_ip_address_get_gateway (addr);
if (!gw)
gw = "::";
addrtmp = g_strdup_printf ("%sIP6_ADDRESS_%d=%s/%d %s", prefix, i,
nm_ip_address_get_address (addr),
nm_ip_address_get_prefix (addr),
gw);
gateway);
items = g_slist_prepend (items, addrtmp);
}
if (addresses->len)
items = g_slist_prepend (items, g_strdup_printf ("%sIP6_NUM_ADDRESSES=%d", prefix, addresses->len));
g_ptr_array_unref (addresses);
g_free (gateway);
g_variant_unref (val);
}
......
......@@ -183,6 +183,7 @@ parse_ip4 (GKeyFile *kf, GVariant **out_props, const char *section, GError **err
char *tmp;
char **split, **iter;
GPtrArray *addresses, *routes;
const char *gateway = NULL;
g_variant_builder_init (&props, G_VARIANT_TYPE ("a{sv}"));
......@@ -221,7 +222,7 @@ parse_ip4 (GKeyFile *kf, GVariant **out_props, const char *section, GError **err
addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref);
for (iter = split; iter && *iter; iter++) {
NMIPAddress *addr;
char *ip, *prefix, *gw;
char *ip, *prefix;
if (strlen (g_strstrip (*iter)) == 0)
continue;
......@@ -232,11 +233,13 @@ parse_ip4 (GKeyFile *kf, GVariant **out_props, const char *section, GError **err
g_assert (prefix);
*prefix++ = '\0';
gw = strchr (prefix, ' ');
g_assert (gw);
gw++;
if (addresses->len == 0) {
gateway = strchr (prefix, ' ');
g_assert (gateway);
gateway++;
}
addr = nm_ip_address_new (AF_INET, ip, (guint) atoi (prefix), gw, error);
addr = nm_ip_address_new (AF_INET, ip, (guint) atoi (prefix), error);
if (!addr) {
g_ptr_array_unref (addresses);
return FALSE;
......@@ -245,7 +248,7 @@ parse_ip4 (GKeyFile *kf, GVariant **out_props, const char *section, GError **err
}
g_variant_builder_add (&props, "{sv}", "addresses",
nm_utils_ip4_addresses_to_variant (addresses));
nm_utils_ip4_addresses_to_variant (addresses, gateway));
g_ptr_array_unref (addresses);
}
g_strfreev (split);
......
......@@ -82,6 +82,7 @@ print_ip4_config (NMIP4Config *cfg4,
const char *one_field)
{
GPtrArray *ptr_array;
const char *gw;
char **addr_arr = NULL;
char **route_arr = NULL;
char **dns_arr = NULL;
......@@ -103,20 +104,16 @@ print_ip4_config (NMIP4Config *cfg4,
/* addresses */
ptr_array = nm_ip4_config_get_addresses (cfg4);
gw = nm_ip4_config_get_gateway (cfg4);
if (ptr_array) {
addr_arr = g_new (char *, ptr_array->len + 1);
for (i = 0; i < ptr_array->len; i++) {
NMIPAddress *addr = (NMIPAddress *) g_ptr_array_index (ptr_array, i);
const char *gw;
gw = nm_ip_address_get_gateway (addr);
if (!gw)
gw = "0.0.0.0";
addr_arr[i] = g_strdup_printf ("ip = %s/%u, gw = %s",
nm_ip_address_get_address (addr),
nm_ip_address_get_prefix (addr),
gw);
(i == 0) && gw ? gw : "0.0.0.0");
}
addr_arr[i] = NULL;
}
......@@ -175,6 +172,7 @@ print_ip6_config (NMIP6Config *cfg6,
const char *one_field)
{
GPtrArray *ptr_array;
const char *gw;
char **addr_arr = NULL;
char **route_arr = NULL;
char **dns_arr = NULL;
......@@ -195,20 +193,16 @@ print_ip6_config (NMIP6Config *cfg6,
/* addresses */
ptr_array = nm_ip6_config_get_addresses (cfg6);
gw = nm_ip6_config_get_gateway (cfg6);
if (ptr_array) {
addr_arr = g_new (char *, ptr_array->len + 1);
for (i = 0; i < ptr_array->len; i++) {
NMIPAddress *addr = (NMIPAddress *) g_ptr_array_index (ptr_array, i);
const char *gw;
gw = nm_ip_address_get_gateway (addr);
if (!gw)
gw = "::";
addr_arr[i] = g_strdup_printf ("ip = %s/%u, gw = %s",
nm_ip_address_get_address (addr),
nm_ip_address_get_prefix (addr),
gw);
(i == 0) && gw ? gw : "::");
}
addr_arr[i] = NULL;
}
......@@ -355,10 +349,9 @@ print_dhcp6_config (NMDhcp6Config *dhcp6,
/*
* Parse IP address from string to NMIPAddress stucture.
* ip_str is the IP address in the form address/prefix
* gw_str is the gateway address (it is optional)
*/
NMIPAddress *
nmc_parse_and_build_address (int family, const char *ip_str, const char *gw_str, GError **error)
nmc_parse_and_build_address (int family, const char *ip_str, GError **error)
{
int max_prefix = (family == AF_INET) ? 32 : 128;
NMIPAddress *addr = NULL;
......@@ -387,7 +380,7 @@ nmc_parse_and_build_address (int family, const char *ip_str, const char *gw_str,
}
}
addr = nm_ip_address_new (family, ip, (guint32) prefix, gw_str, &local);
addr = nm_ip_address_new (family, ip, (guint32) prefix, &local);
if (!addr) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("invalid IP address: %s"), local->message);
......
......@@ -29,7 +29,7 @@ gboolean print_ip6_config (NMIP6Config *cfg6, NmCli *nmc, const char *group_pref
gboolean print_dhcp4_config (NMDhcp4Config *dhcp4, NmCli *nmc, const char *group_prefix, const char *one_field);
gboolean print_dhcp6_config (NMDhcp6Config *dhcp6, NmCli *nmc, const char *group_prefix, const char *one_field);
NMIPAddress *nmc_parse_and_build_address (int family, const char *ip_str, const char *gw_str, GError **error);
NMIPAddress *nmc_parse_and_build_address (int family, const char *ip_str, GError **error);
NMIPRoute *nmc_parse_and_build_route (int family, const char *first, const char *second, const char *third, GError **error);
const char * nmc_device_state_to_string (NMDeviceState state);
......
......@@ -3811,24 +3811,21 @@ do_questionnaire_olpc (char **channel, char **dhcp_anycast)
}
static gboolean
split_address (char* str, char **ip, char **gw, char **rest)
split_address (char* str, char **ip, char **rest)
{
size_t n1, n2, n3, n4, n5;
size_t n1, n2, n3;
*ip = *gw = *rest = NULL;
*ip = *rest = NULL;
if (!str)
return FALSE;
n1 = strspn (str, " \t");
n2 = strcspn (str+n1, " \t\0") + n1;
n3 = strspn (str+n2, " \t") + n2;
n4 = strcspn (str+n3, " \t\0") + n3;
n5 = strspn (str+n4, " \t") + n4;
str[n2] = str[n4] = '\0';
str[n2] = '\0';
*ip = str[n1] ? str + n1 : NULL;
*gw = str[n3] ? str + n3 : NULL;
*rest = str[n5] ? str + n5 : NULL;
*rest = str[n3] ? str + n3 : NULL;
return TRUE;
}
......@@ -3838,32 +3835,31 @@ ask_for_ip_addresses (NMConnection *connection, int family)
{
gboolean ip_loop;
GError *error = NULL;
char *str, *ip, *gw, *rest;
char *str, *ip, *rest;
const char *prompt;
gboolean added;
NMIPAddress *ipaddr;
if (family == AF_INET)
prompt =_("IPv4 address (IP[/plen] [gateway]) [none]: ");
prompt =_("IPv4 address (IP[/plen]) [none]: ");
else
prompt =_("IPv6 address (IP[/plen] [gateway]) [none]: ");
prompt =_("IPv6 address (IP[/plen]) [none]: ");
ip_loop = TRUE;
do {
str = nmc_readline ("%s", prompt);
split_address (str, &ip, &gw, &rest);
split_address (str, &ip, &rest);
if (ip) {
ipaddr = nmc_parse_and_build_address (family, ip, gw, &error);
ipaddr = nmc_parse_and_build_address (family, ip, &error);
if (ipaddr) {
if (family == AF_INET)
added = add_ip4_address_to_connection (ipaddr, connection);
else
added = add_ip6_address_to_connection (ipaddr, connection);
gw = gw ? gw : (family == AF_INET) ? "0.0.0.0" : "::";
if (added)
g_print (_(" Address successfully added: %s %s\n"), ip, gw);
g_print (_(" Address successfully added: %s\n"), ip);
else
g_print (_(" Warning: address already present: %s %s\n"), ip, gw);
g_print (_(" Warning: address already present: %s\n"), ip);
if (rest)
g_print (_(" Warning: ignoring garbage at the end: '%s'\n"), rest);
} else {
......@@ -3878,6 +3874,45 @@ ask_for_ip_addresses (NMConnection *connection, int family)
} while (ip_loop);
}
static void
maybe_ask_for_gateway (NMConnection *connection, int family)
{
gboolean gw_loop;
char *str, *gw, *rest;
const char *prompt;
NMSettingIPConfig *s_ip;
if (family == AF_INET) {
prompt =_("IPv4 gateway [none]: ");
s_ip = nm_connection_get_setting_ip4_config (connection);
} else {
prompt =_("IPv6 gateway [none]: ");
s_ip = nm_connection_get_setting_ip6_config (connection);
}
if (s_ip == NULL)
return;
if ( nm_setting_ip_config_get_num_addresses (s_ip) == 0
|| nm_setting_ip_config_get_gateway (s_ip) != NULL)
return;
gw_loop = TRUE;
do {
str = nmc_readline ("%s", prompt);
split_address (str, &gw, &rest);
if (gw) {
if (nm_utils_ipaddr_valid (family, gw)) {
g_object_set (s_ip,
NM_SETTING_IP_CONFIG_GATEWAY, gw,
NULL);
gw_loop = FALSE;
} else
g_print (_("Error: invalid gateway address '%s'\n"), gw);
} else
gw_loop = FALSE;
g_free (str);
} while (gw_loop);
}
static void
do_questionnaire_ip (NMConnection *connection)
{
......@@ -3890,14 +3925,14 @@ do_questionnaire_ip (NMConnection *connection)
g_free (answer);
return;
}
g_free (answer);
g_print (_("Press <Enter> to finish adding addresses.\n"));
ask_for_ip_addresses (connection, AF_INET);
maybe_ask_for_gateway (connection, AF_INET);
ask_for_ip_addresses (connection, AF_INET6);
g_free (answer);
return;
maybe_ask_for_gateway (connection, AF_INET6);
}
static gboolean
......@@ -5168,7 +5203,7 @@ cleanup_olpc:
/* coverity[dead_error_begin] */
if (ip4) {
ip4addr = nmc_parse_and_build_address (AF_INET, ip4, gw4, error);
ip4addr = nmc_parse_and_build_address (AF_INET, ip4, error);
if (!ip4addr) {
g_prefix_error (error, _("Error: "));
return FALSE;
......@@ -5176,15 +5211,59 @@ cleanup_olpc:
add_ip4_address_to_connection (ip4addr, connection);
}
if (gw4) {
NMSettingIPConfig *s_ip = nm_connection_get_setting_ip4_config (connection);
if (!s_ip) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("Error: IPv4 gateway specified without IPv4 addresses"));
return FALSE;
} else if (nm_setting_ip_config_get_gateway (s_ip)) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("Error: multiple IPv4 gateways specified"));
return FALSE;
} else if (!nm_utils_ipaddr_valid (AF_INET, gw4)) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("Error: Invalid IPv4 gateway '%s'"),
gw4);
}
g_object_set (s_ip,
NM_SETTING_IP_CONFIG_GATEWAY, gw4,
NULL);
}
/* coverity[dead_error_begin] */
if (ip6) {
ip6addr = nmc_parse_and_build_address (AF_INET6, ip6, gw6, error);
ip6addr = nmc_parse_and_build_address (AF_INET6, ip6, error);
if (!ip6addr) {
g_prefix_error (error, _("Error: "));
return FALSE;
}
add_ip6_address_to_connection (ip6addr, connection);
}
if (gw6) {
NMSettingIPConfig *s_ip = nm_connection_get_setting_ip6_config (connection);
if (!s_ip) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("Error: IPv6 gateway specified without IPv6 addresses"));
return FALSE;
} else if (nm_setting_ip_config_get_gateway (s_ip)) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("Error: multiple IPv6 gateways specified"));
return FALSE;
} else if (!nm_utils_ipaddr_valid (AF_INET, gw6)) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("Error: Invalid IPv6 gateway '%s'"),
gw6);
}
g_object_set (s_ip,
NM_SETTING_IP_CONFIG_GATEWAY, gw6,
NULL);
}
}
/* Ask for addresses if '--ask' is specified. */
......
......@@ -257,14 +257,15 @@ NmcOutputField nmc_fields_setting_ip4_config[] = {
SETTING_FIELD (NM_SETTING_IP_CONFIG_DNS, 20), /* 2 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_DNS_SEARCH, 15), /* 3 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_ADDRESSES, 20), /* 4 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_ROUTES, 20), /* 5 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, 19), /* 6 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, 16), /* 7 */
SETTING_FIELD (NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, 15), /* 8 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, 19), /* 9 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, 14), /* 10 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_NEVER_DEFAULT, 15), /* 11 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_MAY_FAIL, 12), /* 12 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_GATEWAY, 20), /* 5 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_ROUTES, 20), /* 7 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, 19), /* 7 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, 16), /* 8 */
SETTING_FIELD (NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, 15), /* 9 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, 19), /* 10 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, 14), /* 11 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_NEVER_DEFAULT, 15), /* 12 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_MAY_FAIL, 12), /* 13 */
{NULL, NULL, 0, NULL, FALSE, FALSE, 0}
};
#define NMC_FIELDS_SETTING_IP4_CONFIG_ALL "name"","\
......@@ -272,6 +273,7 @@ NmcOutputField nmc_fields_setting_ip4_config[] = {
NM_SETTING_IP_CONFIG_DNS","\
NM_SETTING_IP_CONFIG_DNS_SEARCH","\
NM_SETTING_IP_CONFIG_ADDRESSES","\
NM_SETTING_IP_CONFIG_GATEWAY","\
NM_SETTING_IP_CONFIG_ROUTES","\
NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES","\
NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS","\
......@@ -289,14 +291,15 @@ NmcOutputField nmc_fields_setting_ip6_config[] = {
SETTING_FIELD (NM_SETTING_IP_CONFIG_DNS, 20), /* 2 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_DNS_SEARCH, 15), /* 3 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_ADDRESSES, 20), /* 4 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_ROUTES, 20), /* 5 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, 19), /* 6 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, 16), /* 7 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_NEVER_DEFAULT, 15), /* 8 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_MAY_FAIL, 12), /* 9 */
SETTING_FIELD (NM_SETTING_IP6_CONFIG_IP6_PRIVACY, 15), /* 10 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, 19), /* 11 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, 14), /* 12 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_GATEWAY, 20), /* 5 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_ROUTES, 20), /* 6 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, 19), /* 7 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, 16), /* 8 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_NEVER_DEFAULT, 15), /* 9 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_MAY_FAIL, 12), /* 10 */
SETTING_FIELD (NM_SETTING_IP6_CONFIG_IP6_PRIVACY, 15), /* 11 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, 19), /* 12 */
SETTING_FIELD (NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, 14), /* 13 */
{NULL, NULL, 0, NULL, FALSE, FALSE, 0}
};
#define NMC_FIELDS_SETTING_IP6_CONFIG_ALL "name"","\
......@@ -304,6 +307,7 @@ NmcOutputField nmc_fields_setting_ip6_config[] = {
NM_SETTING_IP_CONFIG_DNS","\
NM_SETTING_IP_CONFIG_DNS_SEARCH","\
NM_SETTING_IP_CONFIG_ADDRESSES","\
NM_SETTING_IP_CONFIG_GATEWAY","\
NM_SETTING_IP_CONFIG_ROUTES","\
NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES","\
NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS","\
......@@ -1207,34 +1211,25 @@ DEFINE_GETTER (nmc_property_ipv4_get_dns, NM_SETTING_IP_CONFIG_DNS)
DEFINE_GETTER (nmc_property_ipv4_get_dns_search, NM_SETTING_IP_CONFIG_DNS_SEARCH)
static char *
nmc_property_ipv4_get_addresses (NMSetting *setting)
nmc_property_ip_get_addresses (NMSetting *setting)
{
NMSettingIPConfig *s_ip4 = NM_SETTING_IP_CONFIG (setting);
NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG (setting);
GString *printable;
guint32 num_addresses, i;
NMIPAddress *addr;
printable = g_string_new (NULL);
num_addresses = nm_setting_ip_config_get_num_addresses (s_ip4);
num_addresses = nm_setting_ip_config_get_num_addresses (s_ip);
for (i = 0; i < num_addresses; i++) {
addr = nm_setting_ip_config_get_address (s_ip4, i);
addr = nm_setting_ip_config_get_address (s_ip, i);
if (printable->len > 0)
g_string_append (printable, "; ");
g_string_append (printable, "{ ");
g_string_append (printable, ", ");
g_string_append_printf (printable, "ip = %s/%u",
g_string_append_printf (printable, "%s/%u",
nm_ip_address_get_address (addr),
nm_ip_address_get_prefix (addr));
if (nm_ip_address_get_gateway (addr)) {
g_string_append_printf (printable, ", gw = %s",
nm_ip_address_get_gateway (addr));
}
g_string_append (printable, " }");
}
return g_string_free (printable, FALSE);
......@@ -1277,6 +1272,7 @@ nmc_property_ipv4_get_routes (NMSetting *setting)
return g_string_free (printable, FALSE);
}
DEFINE_GETTER (nmc_property_ipv4_get_gateway, NM_SETTING_IP_CONFIG_GATEWAY)
DEFINE_GETTER (nmc_property_ipv4_get_ignore_auto_routes, NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES)
DEFINE_GETTER (nmc_property_ipv4_get_ignore_auto_dns, NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS)
DEFINE_GETTER (nmc_property_ipv4_get_dhcp_client_id, NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID)
......@@ -1290,40 +1286,6 @@ DEFINE_GETTER (nmc_property_ipv6_get_method, NM_SETTING_IP_CONFIG_METHOD)
DEFINE_GETTER (nmc_property_ipv6_get_dns, NM_SETTING_IP_CONFIG_DNS)
DEFINE_GETTER (nmc_property_ipv6_get_dns_search, NM_SETTING_IP_CONFIG_DNS_SEARCH)
static char *
nmc_property_ipv6_get_addresses (NMSetting *setting)
{
NMSettingIPConfig *s_ip6 = NM_SETTING_IP_CONFIG (setting);
GString *printable;
guint32 num_addresses, i;
NMIPAddress *addr;
printable = g_string_new (NULL);
num_addresses = nm_setting_ip_config_get_num_addresses (s_ip6);
for (i = 0; i < num_addresses; i++) {
addr = nm_setting_ip_config_get_address (s_ip6, i);
if (printable->len > 0)
g_string_append (printable, "; ");
g_string_append (printable, "{ ");
g_string_append_printf (printable, "ip = %s/%u",
nm_ip_address_get_address (addr),
nm_ip_address_get_prefix (addr));
if (nm_ip_address_get_gateway (addr)) {
g_string_append_printf (printable, ", gw = %s",
nm_ip_address_get_gateway (addr));
}
g_string_append (printable, " }");
}
return g_string_free (printable, FALSE);
}
static char *
nmc_property_ipv6_get_routes (NMSetting *setting)
{
......@@ -1361,6 +1323,7 @@ nmc_property_ipv6_get_routes (NMSetting *setting)
return g_string_free (printable, FALSE);
}
DEFINE_GETTER (nmc_property_ipv6_get_gateway, NM_SETTING_IP_CONFIG_GATEWAY)
DEFINE_GETTER (nmc_property_ipv6_get_ignore_auto_routes, NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES)
DEFINE_GETTER (nmc_property_ipv6_get_ignore_auto_dns, NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS)
DEFINE_GETTER (nmc_property_ipv6_get_never_default, NM_SETTING_IP_CONFIG_NEVER_DEFAULT)
......@@ -3075,20 +3038,10 @@ static NMIPAddress *
_parse_ip_address (int family, const char *address, GError **error)
{
char *value = g_strdup (address);
char **addrv;
NMIPAddress *ipaddr;
addrv = nmc_strsplit_set (g_strstrip (value), " \t", 0);
if (addrv[0] == NULL || g_strv_length (addrv) > 2) {
g_set_error (error, 1, 0, _("'%s' is not valid (use ip[/prefix] [gateway])"),
address);
g_free (value);
g_strfreev (addrv);
return NULL;
}
ipaddr = nmc_parse_and_build_address (family, addrv[0], addrv[1], error);
ipaddr = nmc_parse_and_build_address (family, g_strstrip (value), error);
g_free (value);
g_strfreev (addrv);
return ipaddr;
}
......@@ -3292,44 +3245,31 @@ static const char *
nmc_property_ipv4_describe_addresses (NMSetting *setting, const char *prop)
{
return _("Enter a list of IPv4 addresses formatted as:\n"
" ip[/prefix] [gateway], ip[/prefix] [gateway],...\n"
" ip[/prefix], ip[/prefix],...\n"
"Missing prefix is regarded as prefix of 32.\n\n"
"Example: 192.168.1.5/24 192.168.1.1, 10.0.0.11/24\n");
"Example: 192.168.1.5/24, 10.0.0.11/24\n");
}
/*
* from: { ip = 1.2.3.4/24, gw = 1.2.3.254 }; { ip = 2.2.2.2/16, gw = 5.5.5.5 }
* to: 1.2.3.4/24 1.2.3.254, 2.2.2.2/16 5.5.5.5
* from: { ip = 11::22/64, gw = 22::33 }; { ip = ab::cd/64, gw = ab::1 }
* to: 11::22/64 22:33, ab::cd/64 ab::1
*/
static char *
nmc_property_out2in_addresses (const char *out_format)
/* 'gateway' */
static gboolean
nmc_property_ipv4_set_gateway (NMSetting *setting, const char *prop, const char *val, GError **error)
{
GRegex *regex;