diff options
author | Dan Winship <danw@gnome.org> | 2014-09-16 16:42:46 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2014-11-07 07:49:40 -0500 |
commit | 21c8a6b20effbe1e689505a0cbb23594be06068c (patch) | |
tree | 15e43867853d0242950e40e049499e1c2d29cc78 /callouts | |
parent | 303e84e65e5b9b5a403e4f8366e094447d51a9fa (diff) | |
download | NetworkManager-21c8a6b20effbe1e689505a0cbb23594be06068c.tar.gz |
libnm-core, all: merge IPv4 and IPv6 address/route types
Merge NMIP4Address and NMIP6Address into NMIPAddress, and NMIP4Route
and NMIP6Route into NMIPRoute. The new types represent IP addresses as
strings, rather than in binary, and so are address-family agnostic.
Diffstat (limited to 'callouts')
-rw-r--r-- | callouts/nm-dispatcher-utils.c | 64 | ||||
-rw-r--r-- | callouts/tests/test-dispatcher-envp.c | 76 |
2 files changed, 74 insertions, 66 deletions
diff --git a/callouts/nm-dispatcher-utils.c b/callouts/nm-dispatcher-utils.c index 66b6a07fd8..d2deb41fdf 100644 --- a/callouts/nm-dispatcher-utils.c +++ b/callouts/nm-dispatcher-utils.c @@ -95,8 +95,6 @@ construct_ip4_items (GSList *items, GVariant *ip4_config, const char *prefix) char **dns, **wins; GString *tmp; GVariant *val; - char str_addr[INET_ADDRSTRLEN]; - char str_gw[INET_ADDRSTRLEN]; int i; if (ip4_config == NULL) @@ -111,14 +109,18 @@ construct_ip4_items (GSList *items, GVariant *ip4_config, const char *prefix) addresses = nm_utils_ip4_addresses_from_variant (val); for (i = 0; i < addresses->len; i++) { - NMIP4Address *addr = addresses->pdata[i]; - guint32 ip_prefix = nm_ip4_address_get_prefix (addr); + NMIPAddress *addr = addresses->pdata[i]; + const char *gw; char *addrtmp; - nm_utils_inet4_ntop (nm_ip4_address_get_address (addr), str_addr); - nm_utils_inet4_ntop (nm_ip4_address_get_gateway (addr), str_gw); + 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, str_addr, ip_prefix, str_gw); + 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); items = g_slist_prepend (items, addrtmp); } if (addresses->len) @@ -177,15 +179,19 @@ construct_ip4_items (GSList *items, GVariant *ip4_config, const char *prefix) routes = nm_utils_ip4_routes_from_variant (val); for (i = 0; i < routes->len; i++) { - NMIP4Route *route = routes->pdata[i]; - guint32 ip_prefix = nm_ip4_route_get_prefix (route); - guint32 metric = nm_ip4_route_get_metric (route); + NMIPRoute *route = routes->pdata[i]; + const char *next_hop; char *routetmp; - nm_utils_inet4_ntop (nm_ip4_route_get_dest (route), str_addr); - nm_utils_inet4_ntop (nm_ip4_route_get_next_hop (route), str_gw); + next_hop = nm_ip_route_get_next_hop (route); + if (!next_hop) + next_hop = "0.0.0.0"; - routetmp = g_strdup_printf ("%sIP4_ROUTE_%d=%s/%d %s %d", prefix, i, str_addr, ip_prefix, str_gw, metric); + routetmp = g_strdup_printf ("%sIP4_ROUTE_%d=%s/%d %s %d", prefix, i, + nm_ip_route_get_dest (route), + nm_ip_route_get_prefix (route), + next_hop, + nm_ip_route_get_metric (route)); items = g_slist_prepend (items, routetmp); } items = g_slist_prepend (items, g_strdup_printf ("%sIP4_NUM_ROUTES=%d", prefix, routes->len)); @@ -225,8 +231,6 @@ construct_ip6_items (GSList *items, GVariant *ip6_config, const char *prefix) char **dns; GString *tmp; GVariant *val; - char str_addr[INET6_ADDRSTRLEN]; - char str_gw[INET6_ADDRSTRLEN]; int i; if (ip6_config == NULL) @@ -241,14 +245,18 @@ construct_ip6_items (GSList *items, GVariant *ip6_config, const char *prefix) addresses = nm_utils_ip6_addresses_from_variant (val); for (i = 0; i < addresses->len; i++) { - NMIP6Address *addr = addresses->pdata[i]; - guint32 ip_prefix = nm_ip6_address_get_prefix (addr); + NMIPAddress *addr = addresses->pdata[i]; + const char *gw; char *addrtmp; - nm_utils_inet6_ntop (nm_ip6_address_get_address (addr), str_addr); - nm_utils_inet6_ntop (nm_ip6_address_get_gateway (addr), str_gw); + gw = nm_ip_address_get_gateway (addr); + if (!gw) + gw = "::"; - addrtmp = g_strdup_printf ("%sIP6_ADDRESS_%d=%s/%d %s", prefix, i, str_addr, ip_prefix, str_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); items = g_slist_prepend (items, addrtmp); } if (addresses->len) @@ -287,15 +295,19 @@ construct_ip6_items (GSList *items, GVariant *ip6_config, const char *prefix) routes = nm_utils_ip6_routes_from_variant (val); for (i = 0; i < routes->len; i++) { - NMIP6Route *route = routes->pdata[i]; - guint32 ip_prefix = nm_ip6_route_get_prefix (route); - guint32 metric = nm_ip6_route_get_metric (route); + NMIPRoute *route = routes->pdata[i]; + const char *next_hop; char *routetmp; - nm_utils_inet6_ntop (nm_ip6_route_get_dest (route), str_addr); - nm_utils_inet6_ntop (nm_ip6_route_get_next_hop (route), str_gw); + next_hop = nm_ip_route_get_next_hop (route); + if (!next_hop) + next_hop = "::"; - routetmp = g_strdup_printf ("%sIP6_ROUTE_%d=%s/%d %s %d", prefix, i, str_addr, ip_prefix, str_gw, metric); + routetmp = g_strdup_printf ("%sIP6_ROUTE_%d=%s/%d %s %d", prefix, i, + nm_ip_route_get_dest (route), + nm_ip_route_get_prefix (route), + next_hop, + nm_ip_route_get_metric (route)); items = g_slist_prepend (items, routetmp); } if (routes->len) diff --git a/callouts/tests/test-dispatcher-envp.c b/callouts/tests/test-dispatcher-envp.c index a8c65f8413..5daf5e9a64 100644 --- a/callouts/tests/test-dispatcher-envp.c +++ b/callouts/tests/test-dispatcher-envp.c @@ -218,32 +218,29 @@ parse_ip4 (GKeyFile *kf, GVariant **out_props, const char *section, GError **err g_free (tmp); if (g_strv_length (split) > 0) { - addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip4_address_unref); + addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref); for (iter = split; iter && *iter; iter++) { - NMIP4Address *addr; - guint32 a; - char *p; + NMIPAddress *addr; + char *ip, *prefix, *gw; if (strlen (g_strstrip (*iter)) == 0) continue; - addr = nm_ip4_address_new (); + ip = *iter; - p = strchr (*iter, '/'); - g_assert (p); - *p++ = '\0'; + prefix = strchr (ip, '/'); + g_assert (prefix); + *prefix++ = '\0'; - g_assert_cmpint (inet_pton (AF_INET, *iter, &a), ==, 1); - nm_ip4_address_set_address (addr, a); - nm_ip4_address_set_prefix (addr, (guint) atoi (p)); - - p = strchr (p, ' '); - g_assert (p); - p++; - - g_assert_cmpint (inet_pton (AF_INET, p, &a), ==, 1); - nm_ip4_address_set_gateway (addr, a); + gw = strchr (prefix, ' '); + g_assert (gw); + gw++; + addr = nm_ip_address_new (AF_INET, ip, (guint) atoi (prefix), gw, error); + if (!addr) { + g_ptr_array_unref (addresses); + return FALSE; + } g_ptr_array_add (addresses, addr); } @@ -261,37 +258,36 @@ parse_ip4 (GKeyFile *kf, GVariant **out_props, const char *section, GError **err g_free (tmp); if (g_strv_length (split) > 0) { - routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip4_route_unref); + routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref); for (iter = split; iter && *iter; iter++) { - NMIP4Route *route; - guint32 a; - char *p; + NMIPRoute *route; + char *dest, *prefix, *next_hop, *metric; if (strlen (g_strstrip (*iter)) == 0) continue; - route = nm_ip4_route_new (); - - p = strchr (*iter, '/'); - g_assert (p); - *p++ = '\0'; - - g_assert_cmpint (inet_pton (AF_INET, *iter, &a), ==, 1); - nm_ip4_route_set_dest (route, a); - nm_ip4_route_set_prefix (route, (guint) atoi (p)); + dest = *iter; - p = strchr (p, ' '); - g_assert (p); - p++; + prefix = strchr (dest, '/'); + g_assert (prefix); + *prefix++ = '\0'; - g_assert_cmpint (inet_pton (AF_INET, p, &a), ==, 1); - nm_ip4_route_set_next_hop (route, a); + next_hop = strchr (prefix, ' '); + g_assert (next_hop); + next_hop++; - p = strchr (p, ' '); - g_assert (p); - p++; - nm_ip4_route_set_metric (route, (guint) atoi (p)); + metric = strchr (next_hop, ' '); + g_assert (metric); + metric++; + route = nm_ip_route_new (AF_INET, + dest, (guint) atoi (prefix), + next_hop, (guint) atoi (metric), + error); + if (!route) { + g_ptr_array_unref (routes); + return FALSE; + } g_ptr_array_add (routes, route); } |