diff options
author | Dan Winship <danw@gnome.org> | 2009-06-11 15:52:11 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2009-07-29 21:34:19 -0400 |
commit | 90bd1ad5cd6b3ddf00749a61f8f959f274ee41d8 (patch) | |
tree | fa365ea86d234329b12705ab5ef9470d2ba39dfd /libnm-util | |
parent | e324f783e27144b92866f92976bc8a14cfc7ff0a (diff) |
Install and fix up libnm-util IPv6 config stuff
Diffstat (limited to 'libnm-util')
-rw-r--r-- | libnm-util/Makefile.am | 3 | ||||
-rw-r--r-- | libnm-util/libnm-util.ver | 54 | ||||
-rw-r--r-- | libnm-util/nm-connection.c | 5 | ||||
-rw-r--r-- | libnm-util/nm-setting-ip6-config.c | 199 | ||||
-rw-r--r-- | libnm-util/nm-setting-ip6-config.h | 101 | ||||
-rw-r--r-- | libnm-util/nm-utils.c | 154 | ||||
-rw-r--r-- | libnm-util/nm-utils.h | 9 |
7 files changed, 295 insertions, 230 deletions
diff --git a/libnm-util/Makefile.am b/libnm-util/Makefile.am index bc7befb060..1a5a94eb3f 100644 --- a/libnm-util/Makefile.am +++ b/libnm-util/Makefile.am @@ -17,6 +17,7 @@ libnm_util_include_HEADERS = \ nm-setting-bluetooth.h \ nm-setting-connection.h \ nm-setting-ip4-config.h \ + nm-setting-ip6-config.h \ nm-setting-ppp.h \ nm-setting-pppoe.h \ nm-setting-serial.h \ @@ -106,5 +107,5 @@ pkgconfig_DATA = libnm-util.pc DISTCLEANFILES = libnm-util.pc -EXTRA_DIST = libnm-util.pc.in libnm-util.ver nm-setting-ip6-config.h +EXTRA_DIST = libnm-util.pc.in libnm-util.ver diff --git a/libnm-util/libnm-util.ver b/libnm-util/libnm-util.ver index 4d372a7437..92228f5257 100644 --- a/libnm-util/libnm-util.ver +++ b/libnm-util/libnm-util.ver @@ -140,6 +140,56 @@ global: nm_setting_ip4_config_get_dhcp_hostname; nm_setting_ip4_config_get_dhcp_send_hostname; nm_setting_ip4_config_get_never_default; + nm_setting_ip6_config_error_get_type; + nm_setting_ip6_config_error_quark; + nm_ip6_address_new; + nm_ip6_address_dup; + nm_ip6_address_ref; + nm_ip6_address_unref; + nm_ip6_address_compare; + nm_ip6_address_get_address; + nm_ip6_address_set_address; + nm_ip6_address_get_prefix; + nm_ip6_address_set_prefix; + nm_ip6_route_new; + nm_ip6_route_dup; + nm_ip6_route_ref; + nm_ip6_route_unref; + nm_ip6_route_compare; + nm_ip6_route_get_dest; + nm_ip6_route_set_dest; + nm_ip6_route_get_prefix; + nm_ip6_route_set_prefix; + nm_ip6_route_get_next_hop; + nm_ip6_route_set_next_hop; + nm_ip6_route_get_metric; + nm_ip6_route_set_metric; + nm_setting_ip6_config_get_type; + nm_setting_ip6_config_new; + nm_setting_ip6_config_get_method; + nm_setting_ip6_config_get_num_dns; + nm_setting_ip6_config_get_dns; + nm_setting_ip6_config_add_dns; + nm_setting_ip6_config_remove_dns; + nm_setting_ip6_config_clear_dns; + nm_setting_ip6_config_get_num_dns_searches; + nm_setting_ip6_config_get_dns_search; + nm_setting_ip6_config_add_dns_search; + nm_setting_ip6_config_remove_dns_search; + nm_setting_ip6_config_clear_dns_searches; + nm_setting_ip6_config_get_num_addresses; + nm_setting_ip6_config_get_address; + nm_setting_ip6_config_add_address; + nm_setting_ip6_config_remove_address; + nm_setting_ip6_config_clear_addresses; + nm_setting_ip6_config_get_num_routes; + nm_setting_ip6_config_get_route; + nm_setting_ip6_config_add_route; + nm_setting_ip6_config_remove_route; + nm_setting_ip6_config_clear_routes; + nm_setting_ip6_config_get_ignore_auto_routes; + nm_setting_ip6_config_get_ignore_auto_dns; + nm_setting_ip6_config_get_never_default; nm_setting_need_secrets; nm_setting_ppp_error_get_type; nm_setting_ppp_error_quark; @@ -263,6 +313,10 @@ global: nm_utils_ip4_prefix_to_netmask; nm_utils_ip4_routes_from_gvalue; nm_utils_ip4_routes_to_gvalue; + nm_utils_ip6_addresses_from_gvalue; + nm_utils_ip6_addresses_to_gvalue; + nm_utils_ip6_routes_from_gvalue; + nm_utils_ip6_routes_to_gvalue; nm_utils_is_empty_ssid; nm_utils_same_ssid; nm_utils_security_valid; diff --git a/libnm-util/nm-connection.c b/libnm-util/nm-connection.c index e0160232cd..810032ae54 100644 --- a/libnm-util/nm-connection.c +++ b/libnm-util/nm-connection.c @@ -266,6 +266,11 @@ register_default_settings (void) NM_SETTING_IP4_CONFIG_ERROR, 6); + register_one_setting (NM_SETTING_IP6_CONFIG_SETTING_NAME, + NM_TYPE_SETTING_IP6_CONFIG, + NM_SETTING_IP6_CONFIG_ERROR, + 6); + /* Be sure to update DEFAULT_MAP_SIZE if you add another setting!! */ } diff --git a/libnm-util/nm-setting-ip6-config.c b/libnm-util/nm-setting-ip6-config.c index 66defb38c6..d9da92fa8f 100644 --- a/libnm-util/nm-setting-ip6-config.c +++ b/libnm-util/nm-setting-ip6-config.c @@ -30,13 +30,6 @@ #include "nm-utils.h" #include "nm-dbus-glib-types.h" -GSList *nm_utils_ip6_addresses_from_gvalue (const GValue *value); -void nm_utils_ip6_addresses_to_gvalue (GSList *list, GValue *value); - -GSList *nm_utils_ip6_dns_from_gvalue (const GValue *value); -void nm_utils_ip6_dns_to_gvalue (GSList *list, GValue *value); - - GQuark nm_setting_ip6_config_error_quark (void) { @@ -83,9 +76,9 @@ typedef struct { GSList *dns_search; /* list of strings */ GSList *addresses; /* array of NMIP6Address */ GSList *routes; /* array of NMIP6Route */ + gboolean ignore_auto_routes; gboolean ignore_auto_dns; - gboolean ignore_ra; - char *dhcp_mode; + gboolean never_default; } NMSettingIP6ConfigPrivate; @@ -96,9 +89,9 @@ enum { PROP_DNS_SEARCH, PROP_ADDRESSES, PROP_ROUTES, + PROP_IGNORE_AUTO_ROUTES, PROP_IGNORE_AUTO_DNS, - PROP_IGNORE_ROUTER_ADV, - PROP_DHCP_MODE, + PROP_NEVER_DEFAULT, LAST_PROP }; @@ -398,27 +391,27 @@ nm_setting_ip6_config_clear_routes (NMSettingIP6Config *setting) } gboolean -nm_setting_ip6_config_get_ignore_auto_dns (NMSettingIP6Config *setting) +nm_setting_ip6_config_get_ignore_auto_routes (NMSettingIP6Config *setting) { g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE); - return NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->ignore_auto_dns; + return NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->ignore_auto_routes; } gboolean -nm_setting_ip6_config_get_ignore_router_adv (NMSettingIP6Config *setting) +nm_setting_ip6_config_get_ignore_auto_dns (NMSettingIP6Config *setting) { g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE); - return NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->ignore_ra; + return NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->ignore_auto_dns; } -const char * -nm_setting_ip6_config_get_dhcp_mode (NMSettingIP6Config *setting) +gboolean +nm_setting_ip6_config_get_never_default (NMSettingIP6Config *setting) { g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE); - return NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->dhcp_mode; + return NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->never_default; } static gboolean @@ -443,6 +436,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error) return FALSE; } } else if ( !strcmp (priv->method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) + || !strcmp (priv->method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL) || !strcmp (priv->method, NM_SETTING_IP6_CONFIG_METHOD_SHARED)) { if (!priv->ignore_auto_dns) { if (priv->dns && g_slist_length (priv->dns)) { @@ -469,17 +463,6 @@ verify (NMSetting *setting, GSList *all_settings, GError **error) NM_SETTING_IP6_CONFIG_ADDRESSES); return FALSE; } - - /* if router advertisement autoconf is disabled, dhcpv6 mode must - * be SOMETHING as long as the user has selected the auto method - */ - if (priv->ignore_ra && (priv->dhcp_mode == NULL)) { - g_set_error (error, - NM_SETTING_IP6_CONFIG_ERROR, - NM_SETTING_IP6_CONFIG_ERROR_INVALID_PROPERTY, - NM_SETTING_IP6_CONFIG_DHCP_MODE); - return FALSE; - } } else { g_set_error (error, NM_SETTING_IP6_CONFIG_ERROR, @@ -540,17 +523,16 @@ set_property (GObject *object, guint prop_id, break; case PROP_ROUTES: nm_utils_slist_free (priv->routes, g_free); - priv->routes = nm_utils_ip6_addresses_from_gvalue (value); + priv->routes = nm_utils_ip6_routes_from_gvalue (value); + break; + case PROP_IGNORE_AUTO_ROUTES: + priv->ignore_auto_routes = g_value_get_boolean (value); break; case PROP_IGNORE_AUTO_DNS: priv->ignore_auto_dns = g_value_get_boolean (value); break; - case PROP_IGNORE_ROUTER_ADV: - priv->ignore_ra = g_value_get_boolean (value); - break; - case PROP_DHCP_MODE: - g_free (priv->dhcp_mode); - priv->dhcp_mode = g_value_dup_string (value); + case PROP_NEVER_DEFAULT: + priv->never_default = g_value_get_boolean (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -578,16 +560,16 @@ get_property (GObject *object, guint prop_id, nm_utils_ip6_addresses_to_gvalue (priv->addresses, value); break; case PROP_ROUTES: - nm_utils_ip6_addresses_to_gvalue (priv->routes, value); + nm_utils_ip6_routes_to_gvalue (priv->routes, value); + break; + case PROP_IGNORE_AUTO_ROUTES: + g_value_set_boolean (value, priv->ignore_auto_routes); break; case PROP_IGNORE_AUTO_DNS: g_value_set_boolean (value, priv->ignore_auto_dns); break; - case PROP_IGNORE_ROUTER_ADV: - g_value_set_boolean (value, priv->ignore_ra); - break; - case PROP_DHCP_MODE: - g_value_set_string (value, priv->dhcp_mode); + case PROP_NEVER_DEFAULT: + g_value_set_boolean (value, priv->never_default); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -601,6 +583,8 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *setting_class) GObjectClass *object_class = G_OBJECT_CLASS (setting_class); NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class); + g_type_class_add_private (setting_class, sizeof (NMSettingIP6ConfigPrivate)); + /* virtual methods */ object_class->set_property = set_property; object_class->get_property = get_property; @@ -645,39 +629,39 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *setting_class) _nm_param_spec_specialized (NM_SETTING_IP6_CONFIG_ROUTES, "Routes", "List of NMSettingIP6Addresses", - DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS, + DBUS_TYPE_G_ARRAY_OF_IP6_ROUTE, G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE)); g_object_class_install_property + (object_class, PROP_IGNORE_AUTO_ROUTES, + g_param_spec_boolean (NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES, + "Ignore automatic routes", + "Ignore automatic routes", + FALSE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE)); + + g_object_class_install_property (object_class, PROP_IGNORE_AUTO_DNS, g_param_spec_boolean (NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS, - "Ignore DHCPv6 DNS", - "Ignore DHCPv6 DNS", + "Ignore DHCPv6/RDNSS DNS", + "Ignore DHCPv6/RDNSS DNS", FALSE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE)); g_object_class_install_property - (object_class, PROP_IGNORE_ROUTER_ADV, - g_param_spec_boolean (NM_SETTING_IP6_CONFIG_IGNORE_ROUTER_ADV, - "Ignore Router Advertisements", - "Ignore Router Advertisements", + (object_class, PROP_NEVER_DEFAULT, + g_param_spec_boolean (NM_SETTING_IP6_CONFIG_NEVER_DEFAULT, + "Never default", + "Never make this connection the default IPv6 connection", FALSE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE)); - g_object_class_install_property - (object_class, PROP_DHCP_MODE, - g_param_spec_string (NM_SETTING_IP6_CONFIG_DHCP_MODE, - "DHCPv6 Client Mode", - "DHCPv6 Client Mode", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE)); } struct NMIP6Address { guint32 refcount; - struct in6_addr *address; /* network byte order */ + struct in6_addr address; guint32 prefix; - struct in6_addr *gateway; /* network byte order */ }; NMIP6Address * @@ -700,16 +684,7 @@ nm_ip6_address_dup (NMIP6Address *source) address = nm_ip6_address_new (); address->prefix = source->prefix; - - if (source->address) { - address->address = g_malloc0 (sizeof (struct in6_addr)); - memcpy (address->address, source->address, sizeof (struct in6_addr)); - } - - if (source->gateway) { - address->gateway = g_malloc0 (sizeof (struct in6_addr)); - memcpy (address->gateway, source->gateway, sizeof (struct in6_addr)); - } + memcpy (&address->address, &source->address, sizeof (struct in6_addr)); return address; } @@ -731,8 +706,6 @@ nm_ip6_address_unref (NMIP6Address *address) address->refcount--; if (address->refcount == 0) { - g_free (address->address); - g_free (address->gateway); memset (address, 0, sizeof (NMIP6Address)); g_free (address); } @@ -747,9 +720,8 @@ nm_ip6_address_compare (NMIP6Address *address, NMIP6Address *other) g_return_val_if_fail (other != NULL, FALSE); g_return_val_if_fail (other->refcount > 0, FALSE); - if ( memcmp (address->address, other->address, sizeof (struct in6_addr)) - || address->prefix != other->prefix - || memcmp (address->gateway, other->gateway, sizeof (struct in6_addr))) + if ( memcmp (&address->address, &other->address, sizeof (struct in6_addr)) + || address->prefix != other->prefix) return FALSE; return TRUE; } @@ -760,7 +732,7 @@ nm_ip6_address_get_address (NMIP6Address *address) g_return_val_if_fail (address != NULL, 0); g_return_val_if_fail (address->refcount > 0, 0); - return address->address; + return &address->address; } void @@ -768,14 +740,9 @@ nm_ip6_address_set_address (NMIP6Address *address, const struct in6_addr *addr) { g_return_if_fail (address != NULL); g_return_if_fail (address->refcount > 0); + g_return_if_fail (addr != NULL); - g_free (address->address); - address->address = NULL; - - if (addr) { - address->address = g_malloc0 (sizeof (struct in6_addr)); - memcpy (address->address, addr, sizeof (struct in6_addr)); - } + memcpy (&address->address, addr, sizeof (struct in6_addr)); } guint32 @@ -796,37 +763,12 @@ nm_ip6_address_set_prefix (NMIP6Address *address, guint32 prefix) address->prefix = prefix; } -const struct in6_addr * -nm_ip6_address_get_gateway (NMIP6Address *address) -{ - g_return_val_if_fail (address != NULL, 0); - g_return_val_if_fail (address->refcount > 0, 0); - - return address->gateway; -} - -void -nm_ip6_address_set_gateway (NMIP6Address *address, const struct in6_addr *gateway) -{ - g_return_if_fail (address != NULL); - g_return_if_fail (address->refcount > 0); - - g_free (address->gateway); - address->gateway = NULL; - - if (gateway) { - address->gateway = g_malloc0 (sizeof (struct in6_addr)); - memcpy (address->gateway, gateway, sizeof (struct in6_addr)); - } -} - - struct NMIP6Route { guint32 refcount; - struct in6_addr *dest; /* network byte order */ + struct in6_addr dest; guint32 prefix; - struct in6_addr *next_hop; /* network byte order */ + struct in6_addr next_hop; guint32 metric; /* lower metric == more preferred */ }; @@ -851,16 +793,8 @@ nm_ip6_route_dup (NMIP6Route *source) route = nm_ip6_route_new (); route->prefix = source->prefix; route->metric = source->metric; - - if (source->dest) { - route->dest = g_malloc0 (sizeof (struct in6_addr)); - memcpy (route->dest, source->dest, sizeof (struct in6_addr)); - } - - if (source->next_hop) { - route->next_hop = g_malloc0 (sizeof (struct in6_addr)); - memcpy (route->next_hop, source->next_hop, sizeof (struct in6_addr)); - } + memcpy (&route->dest, &source->dest, sizeof (struct in6_addr)); + memcpy (&route->next_hop, &source->next_hop, sizeof (struct in6_addr)); return route; } @@ -882,8 +816,6 @@ nm_ip6_route_unref (NMIP6Route *route) route->refcount--; if (route->refcount == 0) { - g_free (route->dest); - g_free (route->next_hop); memset (route, 0, sizeof (NMIP6Route)); g_free (route); } @@ -898,9 +830,9 @@ nm_ip6_route_compare (NMIP6Route *route, NMIP6Route *other) g_return_val_if_fail (other != NULL, FALSE); g_return_val_if_fail (other->refcount > 0, FALSE); - if ( memcmp (route->dest, other->dest, sizeof (struct in6_addr)) + if ( memcmp (&route->dest, &other->dest, sizeof (struct in6_addr)) || route->prefix != other->prefix - || memcmp (route->next_hop, other->next_hop, sizeof (struct in6_addr)) + || memcmp (&route->next_hop, &other->next_hop, sizeof (struct in6_addr)) || route->metric != other->metric) return FALSE; return TRUE; @@ -912,7 +844,7 @@ nm_ip6_route_get_dest (NMIP6Route *route) g_return_val_if_fail (route != NULL, 0); g_return_val_if_fail (route->refcount > 0, 0); - return route->dest; + return &route->dest; } void @@ -920,14 +852,9 @@ nm_ip6_route_set_dest (NMIP6Route *route, const struct in6_addr *dest) { g_return_if_fail (route != NULL); g_return_if_fail (route->refcount > 0); + g_return_if_fail (dest != NULL); - g_free (route->dest); - route->dest = NULL; - - if (dest) { - route->dest = g_malloc0 (sizeof (struct in6_addr)); - memcpy (route->dest, dest, sizeof (struct in6_addr)); - } + memcpy (&route->dest, dest, sizeof (struct in6_addr)); } guint32 @@ -954,7 +881,7 @@ nm_ip6_route_get_next_hop (NMIP6Route *route) g_return_val_if_fail (route != NULL, 0); g_return_val_if_fail (route->refcount > 0, 0); - return route->next_hop; + return &route->next_hop; } void @@ -962,14 +889,9 @@ nm_ip6_route_set_next_hop (NMIP6Route *route, const struct in6_addr *next_hop) { g_return_if_fail (route != NULL); g_return_if_fail (route->refcount > 0); + g_return_if_fail (next_hop != NULL); - g_free (route->next_hop); - route->next_hop = NULL; - - if (next_hop) { - route->next_hop = g_malloc0 (sizeof (struct in6_addr)); - memcpy (route->next_hop, next_hop, sizeof (struct in6_addr)); - } + memcpy (&route->next_hop, next_hop, sizeof (struct in6_addr)); } guint32 @@ -989,4 +911,3 @@ nm_ip6_route_set_metric (NMIP6Route *route, guint32 metric) route->metric = metric; } - diff --git a/libnm-util/nm-setting-ip6-config.h b/libnm-util/nm-setting-ip6-config.h index 879d82e0cb..4e39940231 100644 --- a/libnm-util/nm-setting-ip6-config.h +++ b/libnm-util/nm-setting-ip6-config.h @@ -54,21 +54,20 @@ GType nm_setting_ip6_config_error_get_type (void); #define NM_SETTING_IP6_CONFIG_ERROR nm_setting_ip6_config_error_quark () GQuark nm_setting_ip6_config_error_quark (void); -#define NM_SETTING_IP6_CONFIG_METHOD "method" -#define NM_SETTING_IP6_CONFIG_DNS "dns" -#define NM_SETTING_IP6_CONFIG_DNS_SEARCH "dns-search" -#define NM_SETTING_IP6_CONFIG_ADDRESSES "addresses" -#define NM_SETTING_IP6_CONFIG_ROUTES "routes" -#define NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS "ignore-auto-dns" -#define NM_SETTING_IP6_CONFIG_IGNORE_ROUTER_ADV "ignore-router-adv" -#define NM_SETTING_IP6_CONFIG_DHCP_MODE "dhcp-mode" - -#define NM_SETTING_IP6_CONFIG_METHOD_AUTO "auto" -#define NM_SETTING_IP6_CONFIG_METHOD_MANUAL "manual" -#define NM_SETTING_IP6_CONFIG_METHOD_SHARED "shared" - -#define NM_SETTING_IP6_CONFIG_DHCPV6_MODE_INFO "info" -#define NM_SETTING_IP6_CONFIG_DHCPV6_MODE_REQUEST "request" +#define NM_SETTING_IP6_CONFIG_METHOD "method" +#define NM_SETTING_IP6_CONFIG_DNS "dns" +#define NM_SETTING_IP6_CONFIG_DNS_SEARCH "dns-search" +#define NM_SETTING_IP6_CONFIG_ADDRESSES "addresses" +#define NM_SETTING_IP6_CONFIG_ROUTES "routes" +#define NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES "ignore-auto-routes" +#define NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS "ignore-auto-dns" +#define NM_SETTING_IP6_CONFIG_NEVER_DEFAULT "never-default" + +#define NM_SETTING_IP6_CONFIG_METHOD_IGNORE "ignore" +#define NM_SETTING_IP6_CONFIG_METHOD_AUTO "auto" +#define NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL "link-local" +#define NM_SETTING_IP6_CONFIG_METHOD_MANUAL "manual" +#define NM_SETTING_IP6_CONFIG_METHOD_SHARED "shared" typedef struct NMIP6Address NMIP6Address; @@ -82,16 +81,12 @@ gboolean nm_ip6_address_compare (NMIP6Address *address, NMIP6A const struct in6_addr *nm_ip6_address_get_address (NMIP6Address *address); void nm_ip6_address_set_address (NMIP6Address *address, - const struct in6_addr *addr); /* network byte order */ + const struct in6_addr *addr); guint32 nm_ip6_address_get_prefix (NMIP6Address *address); void nm_ip6_address_set_prefix (NMIP6Address *address, guint32 prefix); -const struct in6_addr *nm_ip6_address_get_gateway (NMIP6Address *address); -void nm_ip6_address_set_gateway (NMIP6Address *address, - const struct in6_addr *addr); /* network byte order */ - typedef struct NMIP6Route NMIP6Route; NMIP6Route * nm_ip6_route_new (void); @@ -103,7 +98,7 @@ gboolean nm_ip6_route_compare (NMIP6Route *route, NMIP6Route const struct in6_addr *nm_ip6_route_get_dest (NMIP6Route *route); void nm_ip6_route_set_dest (NMIP6Route *route, - const struct in6_addr *dest); /* network byte order */ + const struct in6_addr *dest); guint32 nm_ip6_route_get_prefix (NMIP6Route *route); void nm_ip6_route_set_prefix (NMIP6Route *route, @@ -111,7 +106,7 @@ void nm_ip6_route_set_prefix (NMIP6Route *route, const struct in6_addr *nm_ip6_route_get_next_hop (NMIP6Route *route); void nm_ip6_route_set_next_hop (NMIP6Route *route, - const struct in6_addr *next_hop); /* network byte order */ + const struct in6_addr *next_hop); guint32 nm_ip6_route_get_metric (NMIP6Route *route); void nm_ip6_route_set_metric (NMIP6Route *route, @@ -125,40 +120,38 @@ typedef struct { NMSettingClass parent; } NMSettingIP6ConfigClass; -/* IPv6 support is currently incomplete. Do not use. */ - GType nm_setting_ip6_config_get_type (void); -NMSetting * nm_setting_ip6_config_new (void); -const char * nm_setting_ip6_config_get_method (NMSettingIP6Config *setting); - -guint32 nm_setting_ip6_config_get_num_dns (NMSettingIP6Config *setting); -const struct in6_addr *nm_setting_ip6_config_get_dns (NMSettingIP6Config *setting, guint32 i); -gboolean nm_setting_ip6_config_add_dns (NMSettingIP6Config *setting, const struct in6_addr *dns); -void nm_setting_ip6_config_remove_dns (NMSettingIP6Config *setting, guint32 i); -void nm_setting_ip6_config_clear_dns (NMSettingIP6Config *setting); - -guint32 nm_setting_ip6_config_get_num_dns_searches (NMSettingIP6Config *setting); -const char * nm_setting_ip6_config_get_dns_search (NMSettingIP6Config *setting, guint32 i); -gboolean nm_setting_ip6_config_add_dns_search (NMSettingIP6Config *setting, const char *dns_search); -void nm_setting_ip6_config_remove_dns_search (NMSettingIP6Config *setting, guint32 i); -void nm_setting_ip6_config_clear_dns_searches (NMSettingIP6Config *setting); - -guint32 nm_setting_ip6_config_get_num_addresses (NMSettingIP6Config *setting); -NMIP6Address * nm_setting_ip6_config_get_address (NMSettingIP6Config *setting, guint32 i); -gboolean nm_setting_ip6_config_add_address (NMSettingIP6Config *setting, NMIP6Address *address); -void nm_setting_ip6_config_remove_address (NMSettingIP6Config *setting, guint32 i); -void nm_setting_ip6_config_clear_addresses (NMSettingIP6Config *setting); - -guint32 nm_setting_ip6_config_get_num_routes (NMSettingIP6Config *setting); -NMIP6Route * nm_setting_ip6_config_get_route (NMSettingIP6Config *setting, guint32 i); -gboolean nm_setting_ip6_config_add_route (NMSettingIP6Config *setting, NMIP6Route *route); -void nm_setting_ip6_config_remove_route (NMSettingIP6Config *setting, guint32 i); -void nm_setting_ip6_config_clear_routes (NMSettingIP6Config *setting); - -gboolean nm_setting_ip6_config_get_ignore_auto_dns (NMSettingIP6Config *setting); -gboolean nm_setting_ip6_config_get_ignore_router_adv (NMSettingIP6Config *setting); -const char * nm_setting_ip6_config_get_dhcp_mode (NMSettingIP6Config *setting); +NMSetting * nm_setting_ip6_config_new (void); +const char * nm_setting_ip6_config_get_method (NMSettingIP6Config *setting); + +guint32 nm_setting_ip6_config_get_num_dns (NMSettingIP6Config *setting); +const struct in6_addr *nm_setting_ip6_config_get_dns (NMSettingIP6Config *setting, guint32 i); +gboolean nm_setting_ip6_config_add_dns (NMSettingIP6Config *setting, const struct in6_addr *dns); +void nm_setting_ip6_config_remove_dns (NMSettingIP6Config *setting, guint32 i); +void nm_setting_ip6_config_clear_dns (NMSettingIP6Config *setting); + +guint32 nm_setting_ip6_config_get_num_dns_searches (NMSettingIP6Config *setting); +const char * nm_setting_ip6_config_get_dns_search (NMSettingIP6Config *setting, guint32 i); +gboolean nm_setting_ip6_config_add_dns_search (NMSettingIP6Config *setting, const char *dns_search); +void nm_setting_ip6_config_remove_dns_search (NMSettingIP6Config *setting, guint32 i); +void nm_setting_ip6_config_clear_dns_searches (NMSettingIP6Config *setting); + +guint32 nm_setting_ip6_config_get_num_addresses (NMSettingIP6Config *setting); +NMIP6Address * nm_setting_ip6_config_get_address (NMSettingIP6Config *setting, guint32 i); +gboolean nm_setting_ip6_config_add_address (NMSettingIP6Config *setting, NMIP6Address *address); +void nm_setting_ip6_config_remove_address (NMSettingIP6Config *setting, guint32 i); +void nm_setting_ip6_config_clear_addresses (NMSettingIP6Config *setting); + +guint32 nm_setting_ip6_config_get_num_routes (NMSettingIP6Config *setting); +NMIP6Route * nm_setting_ip6_config_get_route (NMSettingIP6Config *setting, guint32 i); +gboolean nm_setting_ip6_config_add_route (NMSettingIP6Config *setting, NMIP6Route *route); +void nm_setting_ip6_config_remove_route (NMSettingIP6Config *setting, guint32 i); +void nm_setting_ip6_config_clear_routes (NMSettingIP6Config *setting); +gboolean nm_setting_ip6_config_get_ignore_auto_routes (NMSettingIP6Config *setting); + +gboolean nm_setting_ip6_config_get_ignore_auto_dns (NMSettingIP6Config *setting); +gboolean nm_setting_ip6_config_get_never_default (NMSettingIP6Config *setting); G_END_DECLS diff --git a/libnm-util/nm-utils.c b/libnm-util/nm-utils.c index f9a56f4702..a034121405 100644 --- a/libnm-util/nm-utils.c +++ b/libnm-util/nm-utils.c @@ -54,14 +54,6 @@ * access points and devices, among other things. */ -/* IP6 currently incomplete */ -GSList *nm_utils_ip6_addresses_from_gvalue (const GValue *value); -void nm_utils_ip6_addresses_to_gvalue (GSList *list, GValue *value); - -GSList *nm_utils_ip6_dns_from_gvalue (const GValue *value); -void nm_utils_ip6_dns_to_gvalue (GSList *list, GValue *value); - - struct EncodingTriplet { const char *encoding1; @@ -1228,14 +1220,13 @@ nm_utils_ip6_addresses_from_gvalue (const GValue *value) for (i = 0; addresses && (i < addresses->len); i++) { GValueArray *elements = (GValueArray *) g_ptr_array_index (addresses, i); GValue *tmp; - GByteArray *ba_addr, *ba_gw; + GByteArray *ba_addr; NMIP6Address *addr; guint32 prefix; - if ( (elements->n_values != 3) + if ( (elements->n_values != 2) || (G_VALUE_TYPE (g_value_array_get_nth (elements, 0)) != DBUS_TYPE_G_UCHAR_ARRAY) - || (G_VALUE_TYPE (g_value_array_get_nth (elements, 1)) != G_TYPE_UINT) - || (G_VALUE_TYPE (g_value_array_get_nth (elements, 2)) != DBUS_TYPE_G_UCHAR_ARRAY)) { + || (G_VALUE_TYPE (g_value_array_get_nth (elements, 1)) != G_TYPE_UINT)) { nm_warning ("%s: ignoring invalid IP6 address structure", __func__); continue; } @@ -1256,18 +1247,9 @@ nm_utils_ip6_addresses_from_gvalue (const GValue *value) continue; } - tmp = g_value_array_get_nth (elements, 2); - ba_gw = g_value_get_boxed (tmp); - if (ba_gw->len != 16) { - nm_warning ("%s: ignoring invalid IP6 gateway of length %d", - __func__, ba_gw->len); - continue; - } - addr = nm_ip6_address_new (); nm_ip6_address_set_prefix (addr, prefix); nm_ip6_address_set_address (addr, (const struct in6_addr *) ba_addr->data); - nm_ip6_address_set_gateway (addr, (const struct in6_addr *) ba_gw->data); list = g_slist_prepend (list, addr); } @@ -1284,29 +1266,129 @@ nm_utils_ip6_addresses_to_gvalue (GSList *list, GValue *value) for (iter = list; iter; iter = iter->next) { NMIP6Address *addr = (NMIP6Address *) iter->data; - GValue element = { 0, }; - GByteArray *ba_addr, *ba_gw; + GValueArray *array; + GValue element = {0, }; + GByteArray *ba; + + array = g_value_array_new (2); + + g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY); + ba = g_byte_array_new (); + g_byte_array_append (ba, (guint8 *) nm_ip6_address_get_address (addr), 16); + g_value_take_boxed (&element, ba); + g_value_array_append (array, &element); + g_value_unset (&element); + + g_value_init (&element, G_TYPE_UINT); + g_value_set_uint (&element, nm_ip6_address_get_prefix (addr)); + g_value_array_append (array, &element); + g_value_unset (&element); + + g_ptr_array_add (addresses, array); + } + + g_value_take_boxed (value, addresses); +} + +GSList * +nm_utils_ip6_routes_from_gvalue (const GValue *value) +{ + GPtrArray *routes; + int i; + GSList *list = NULL; + + routes = (GPtrArray *) g_value_get_boxed (value); + for (i = 0; routes && (i < routes->len); i++) { + GValueArray *route_values = (GValueArray *) g_ptr_array_index (routes, i); + GByteArray *dest, *next_hop; + guint prefix, metric; + NMIP6Route *route; + + if ( (route_values->n_values != 4) + || (G_VALUE_TYPE (g_value_array_get_nth (route_values, 0)) != DBUS_TYPE_G_UCHAR_ARRAY) + || (G_VALUE_TYPE (g_value_array_get_nth (route_values, 1)) != G_TYPE_UINT) + || (G_VALUE_TYPE (g_value_array_get_nth (route_values, 2)) != DBUS_TYPE_G_UCHAR_ARRAY) + || (G_VALUE_TYPE (g_value_array_get_nth (route_values, 3)) != G_TYPE_UINT)) { + nm_warning ("Ignoring invalid IP6 route"); + continue; + } - g_value_init (&element, DBUS_TYPE_G_IP6_ADDRESS); - g_value_take_boxed (&element, dbus_g_type_specialized_construct (DBUS_TYPE_G_IP6_ADDRESS)); + dest = g_value_get_boxed (g_value_array_get_nth (route_values, 0)); + if (dest->len != 16) { + nm_warning ("%s: ignoring invalid IP6 dest address of length %d", + __func__, dest->len); + continue; + } + + prefix = g_value_get_uint (g_value_array_get_nth (route_values, 1)); + + next_hop = g_value_get_boxed (g_value_array_get_nth (route_values, 2)); + if (next_hop->len != 16) { + nm_warning ("%s: ignoring invalid IP6 next_hop address of length %d", + __func__, next_hop->len); + continue; + } + + metric = g_value_get_uint (g_value_array_get_nth (route_values, 3)); + + route = nm_ip6_route_new (); + nm_ip6_route_set_dest (route, (struct in6_addr *)dest->data); + nm_ip6_route_set_prefix (route, prefix); + nm_ip6_route_set_next_hop (route, (struct in6_addr *)next_hop->data); + nm_ip6_route_set_metric (route, metric); + list = g_slist_prepend (list, route); + } + + return g_slist_reverse (list); +} + +void +nm_utils_ip6_routes_to_gvalue (GSList *list, GValue *value) +{ + GPtrArray *routes; + GSList *iter; - ba_addr = g_byte_array_sized_new (16); - g_byte_array_append (ba_addr, (guint8 *) nm_ip6_address_get_address (addr), 16); + routes = g_ptr_array_new (); + + for (iter = list; iter; iter = iter->next) { + NMIP6Route *route = (NMIP6Route *) iter->data; + GValueArray *array; + const struct in6_addr *addr; + GByteArray *ba; + GValue element = {0, }; + + array = g_value_array_new (4); + + g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY); + addr = nm_ip6_route_get_dest (route); + ba = g_byte_array_new (); + g_byte_array_append (ba, (guchar *)addr, sizeof (*addr)); + g_value_take_boxed (&element, ba); + g_value_array_append (array, &element); + g_value_unset (&element); - ba_gw = g_byte_array_sized_new (16); - g_byte_array_append (ba_gw, (guint8 *) nm_ip6_address_get_gateway (addr), 16); + g_value_init (&element, G_TYPE_UINT); + g_value_set_uint (&element, nm_ip6_route_get_prefix (route)); + g_value_array_append (array, &element); + g_value_unset (&element); - dbus_g_type_struct_set (&element, - 0, ba_addr, - 1, nm_ip6_address_get_prefix (addr), - 2, ba_gw, - G_MAXUINT); + g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY); + addr = nm_ip6_route_get_next_hop (route); + ba = g_byte_array_new (); + g_byte_array_append (ba, (guchar *)addr, sizeof (*addr)); + g_value_take_boxed (&element, ba); + g_value_array_append (array, &element); + g_value_unset (&element); - g_ptr_array_add (addresses, g_value_get_boxed (&element)); + g_value_init (&element, G_TYPE_UINT); + g_value_set_uint (&element, nm_ip6_route_get_metric (route)); + g_value_array_append (array, &element); g_value_unset (&element); + + g_ptr_array_add (routes, array); } - g_value_take_boxed (value, addresses); + g_value_take_boxed (value, routes); } GSList * diff --git a/libnm-util/nm-utils.h b/libnm-util/nm-utils.h index 629bc59fee..810c6e7e9d 100644 --- a/libnm-util/nm-utils.h +++ b/libnm-util/nm-utils.h @@ -193,6 +193,15 @@ void nm_utils_ip4_routes_to_gvalue (GSList *list, GValue *value); guint32 nm_utils_ip4_netmask_to_prefix (guint32 netmask); guint32 nm_utils_ip4_prefix_to_netmask (guint32 prefix); +GSList *nm_utils_ip6_addresses_from_gvalue (const GValue *value); +void nm_utils_ip6_addresses_to_gvalue (GSList *list, GValue *value); + +GSList *nm_utils_ip6_routes_from_gvalue (const GValue *value); +void nm_utils_ip6_routes_to_gvalue (GSList *list, GValue *value); + +GSList *nm_utils_ip6_dns_from_gvalue (const GValue *value); +void nm_utils_ip6_dns_to_gvalue (GSList *list, GValue *value); + char *nm_utils_uuid_generate (void); char *nm_utils_uuid_generate_from_string (const char *s); |