Commit 21c8a6b2 authored by Dan Winship's avatar Dan Winship

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.
parent 303e84e6
......@@ -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)
......
......@@ -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);
}
......
This diff is collapsed.
......@@ -29,11 +29,8 @@ 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);
NMIP4Address *nmc_parse_and_build_ip4_address (const char *ip_str, const char *gw_str, GError **error);
NMIP6Address *nmc_parse_and_build_ip6_address (const char *ip_str, const char *gw_str, GError **error);
NMIP4Route *nmc_parse_and_build_ip4_route (const char *first, const char *second, const char *third, GError **error);
NMIP6Route *nmc_parse_and_build_ip6_route (const char *first, const char *second, const char *third, GError **error);
NMIPAddress *nmc_parse_and_build_address (int family, const char *ip_str, const char *gw_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);
const char * nmc_device_reason_to_string (NMDeviceStateReason reason);
......
......@@ -2887,7 +2887,7 @@ check_and_convert_vlan_prio_maps (const char *prio_map,
}
static gboolean
add_ip4_address_to_connection (NMIP4Address *ip4addr, NMConnection *connection)
add_ip4_address_to_connection (NMIPAddress *ip4addr, NMConnection *connection)
{
NMSettingIP4Config *s_ip4;
gboolean ret;
......@@ -2904,13 +2904,13 @@ add_ip4_address_to_connection (NMIP4Address *ip4addr, NMConnection *connection)
NULL);
}
ret = nm_setting_ip4_config_add_address (s_ip4, ip4addr);
nm_ip4_address_unref (ip4addr);
nm_ip_address_unref (ip4addr);
return ret;
}
static gboolean
add_ip6_address_to_connection (NMIP6Address *ip6addr, NMConnection *connection)
add_ip6_address_to_connection (NMIPAddress *ip6addr, NMConnection *connection)
{
NMSettingIP6Config *s_ip6;
gboolean ret;
......@@ -2927,7 +2927,7 @@ add_ip6_address_to_connection (NMIP6Address *ip6addr, NMConnection *connection)
NULL);
}
ret = nm_setting_ip6_config_add_address (s_ip6, ip6addr);
nm_ip6_address_unref (ip6addr);
nm_ip_address_unref (ip6addr);
return ret;
}
......@@ -3841,9 +3841,9 @@ ask_for_ip_addresses (NMConnection *connection, int family)
char *str, *ip, *gw, *rest;
const char *prompt;
gboolean added;
gpointer ipaddr;
NMIPAddress *ipaddr;
if (family == 4)
if (family == AF_INET)
prompt =_("IPv4 address (IP[/plen] [gateway]) [none]: ");
else
prompt =_("IPv6 address (IP[/plen] [gateway]) [none]: ");
......@@ -3853,16 +3853,13 @@ ask_for_ip_addresses (NMConnection *connection, int family)
str = nmc_readline ("%s", prompt);
split_address (str, &ip, &gw, &rest);
if (ip) {
if (family == 4)
ipaddr = nmc_parse_and_build_ip4_address (ip, gw, &error);
else
ipaddr = nmc_parse_and_build_ip6_address (ip, gw, &error);
ipaddr = nmc_parse_and_build_address (family, ip, gw, &error);
if (ipaddr) {
if (family == 4)
added = add_ip4_address_to_connection ((NMIP4Address *) ipaddr, connection);
if (family == AF_INET)
added = add_ip4_address_to_connection (ipaddr, connection);
else
added = add_ip6_address_to_connection ((NMIP6Address *) ipaddr, connection);
gw = gw ? gw : (family == 4) ? "0.0.0.0" : "::";
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);
else
......@@ -3896,8 +3893,8 @@ do_questionnaire_ip (NMConnection *connection)
g_print (_("Press <Enter> to finish adding addresses.\n"));
ask_for_ip_addresses (connection, 4);
ask_for_ip_addresses (connection, 6);
ask_for_ip_addresses (connection, AF_INET);
ask_for_ip_addresses (connection, AF_INET6);
g_free (answer);
return;
......@@ -5151,8 +5148,7 @@ cleanup_olpc:
&& strcmp (con_type, "team-slave") != 0
&& strcmp (con_type, "bridge-slave") != 0) {
NMIP4Address *ip4addr = NULL;
NMIP6Address *ip6addr = NULL;
NMIPAddress *ip4addr = NULL, *ip6addr = NULL;
const char *ip4 = NULL, *gw4 = NULL, *ip6 = NULL, *gw6 = NULL;
nmc_arg_t exp_args[] = { {"ip4", TRUE, &ip4, FALSE}, {"gw4", TRUE, &gw4, FALSE},
{"ip6", TRUE, &ip6, FALSE}, {"gw6", TRUE, &gw6, FALSE},
......@@ -5172,7 +5168,7 @@ cleanup_olpc:
/* coverity[dead_error_begin] */
if (ip4) {
ip4addr = nmc_parse_and_build_ip4_address (ip4, gw4, error);
ip4addr = nmc_parse_and_build_address (AF_INET, ip4, gw4, error);
if (!ip4addr) {
g_prefix_error (error, _("Error: "));
return FALSE;
......@@ -5182,7 +5178,7 @@ cleanup_olpc:
/* coverity[dead_error_begin] */
if (ip6) {
ip6addr = nmc_parse_and_build_ip6_address (ip6, gw6, error);
ip6addr = nmc_parse_and_build_address (AF_INET6, ip6, gw6, error);
if (!ip6addr) {
g_prefix_error (error, _("Error: "));
return FALSE;
......
This diff is collapsed.
This diff is collapsed.
......@@ -25,49 +25,27 @@ G_BEGIN_DECLS
void nm_editor_bindings_init (void);
void nm_editor_bind_ip4_addresses_with_prefix_to_strv (gpointer source,
void nm_editor_bind_ip_addresses_with_prefix_to_strv (int family,
gpointer source,
const gchar *source_property,
gpointer target,
const gchar *target_property,
GBindingFlags flags);
void nm_editor_bind_ip4_addresses_to_strv (gpointer source,
void nm_editor_bind_ip_addresses_to_strv (int family,
gpointer source,
const gchar *source_property,
gpointer target,
const gchar *target_property,
GBindingFlags flags);
void nm_editor_bind_ip4_gateway_to_string (gpointer source,
void nm_editor_bind_ip_gateway_to_string (int family,
gpointer source,
const gchar *source_property,
gpointer target,
const gchar *target_property,
GBindingFlags flags);
void nm_editor_bind_ip4_route_to_strings (gpointer source,
const gchar *source_property,
gpointer dest_target,
const gchar *dest_target_property,
gpointer next_hop_target,
const gchar *next_hop_target_property,
gpointer metric_target,
const gchar *metric_target_property,
GBindingFlags flags);
void nm_editor_bind_ip6_addresses_with_prefix_to_strv (gpointer source,
const gchar *source_property,
gpointer target,
const gchar *target_property,
GBindingFlags flags);
void nm_editor_bind_ip6_addresses_to_strv (gpointer source,
const gchar *source_property,
gpointer target,
const gchar *target_property,
GBindingFlags flags);
void nm_editor_bind_ip6_gateway_to_string (gpointer source,
const gchar *source_property,
gpointer target,
const gchar *target_property,
GBindingFlags flags);
void nm_editor_bind_ip6_route_to_strings (gpointer source,
void nm_editor_bind_ip_route_to_strings (int family,
gpointer source,
const gchar *source_property,
gpointer dest_target,
const gchar *dest_target_property,
......
......@@ -138,21 +138,24 @@ nmt_page_ip4_constructed (GObject *object)
grid = NMT_PAGE_GRID (ip4);
widget = nmt_address_list_new (NMT_ADDRESS_LIST_IP4_WITH_PREFIX);
nm_editor_bind_ip4_addresses_with_prefix_to_strv (s_ip4, NM_SETTING_IP4_CONFIG_ADDRESSES,
widget, "strings",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nm_editor_bind_ip_addresses_with_prefix_to_strv (AF_INET,
s_ip4, NM_SETTING_IP4_CONFIG_ADDRESSES,
widget, "strings",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("Addresses"), widget, NULL);
widget = nmt_ip_entry_new (25, AF_INET, FALSE, TRUE);
nm_editor_bind_ip4_gateway_to_string (s_ip4, NM_SETTING_IP4_CONFIG_ADDRESSES,
widget, "text",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nm_editor_bind_ip_gateway_to_string (AF_INET,
s_ip4, NM_SETTING_IP4_CONFIG_ADDRESSES,
widget, "text",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("Gateway"), widget, NULL);
widget = nmt_address_list_new (NMT_ADDRESS_LIST_IP4);
nm_editor_bind_ip4_addresses_to_strv (s_ip4, NM_SETTING_IP4_CONFIG_DNS,
widget, "strings",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nm_editor_bind_ip_addresses_to_strv (AF_INET,
s_ip4, NM_SETTING_IP4_CONFIG_DNS,
widget, "strings",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("DNS servers"), widget, NULL);
widget = nmt_address_list_new (NMT_ADDRESS_LIST_HOSTNAME);
......
......@@ -138,21 +138,24 @@ nmt_page_ip6_constructed (GObject *object)
grid = NMT_PAGE_GRID (ip6);
widget = nmt_address_list_new (NMT_ADDRESS_LIST_IP6_WITH_PREFIX);
nm_editor_bind_ip6_addresses_with_prefix_to_strv (s_ip6, NM_SETTING_IP6_CONFIG_ADDRESSES,
widget, "strings",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nm_editor_bind_ip_addresses_with_prefix_to_strv (AF_INET6,
s_ip6, NM_SETTING_IP6_CONFIG_ADDRESSES,
widget, "strings",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("Addresses"), widget, NULL);
widget = nmt_ip_entry_new (25, AF_INET6, FALSE, TRUE);
nm_editor_bind_ip6_gateway_to_string (s_ip6, NM_SETTING_IP6_CONFIG_ADDRESSES,
widget, "text",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nm_editor_bind_ip_gateway_to_string (AF_INET6,
s_ip6, NM_SETTING_IP6_CONFIG_ADDRESSES,
widget, "text",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("Gateway"), widget, NULL);
widget = nmt_address_list_new (NMT_ADDRESS_LIST_IP6);
nm_editor_bind_ip6_addresses_to_strv (s_ip6, NM_SETTING_IP6_CONFIG_DNS,
widget, "strings",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nm_editor_bind_ip_addresses_to_strv (AF_INET6,
s_ip6, NM_SETTING_IP6_CONFIG_DNS,
widget, "strings",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("DNS servers"), widget, NULL);
widget = nmt_address_list_new (NMT_ADDRESS_LIST_HOSTNAME);
......
......@@ -109,12 +109,12 @@ nmt_route_editor_constructed (GObject *object)
if (NM_IS_SETTING_IP4_CONFIG (priv->edit_setting)) {
routes = nmt_route_table_new (AF_INET);
g_object_bind_property (priv->edit_setting, NM_SETTING_IP4_CONFIG_ROUTES,
routes, "ip4-routes",
routes, "routes",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
} else {
routes = nmt_route_table_new (AF_INET6);
g_object_bind_property (priv->edit_setting, NM_SETTING_IP6_CONFIG_ROUTES,
routes, "ip6-routes",
routes, "routes",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
}
......
......@@ -49,8 +49,7 @@ typedef struct {
int family;
int ip_entry_width, metric_entry_width;
NMIP4Route *ip4_route;
NMIP6Route *ip6_route;
NMIPRoute *route;
} NmtRouteEntryPrivate;
enum {
......@@ -58,8 +57,7 @@ enum {
PROP_FAMILY,
PROP_IP_ENTRY_WIDTH,
PROP_METRIC_ENTRY_WIDTH,
PROP_IP4_ROUTE,
PROP_IP6_ROUTE,
PROP_ROUTE,
LAST_PROP
};
......@@ -143,20 +141,12 @@ nmt_route_entry_constructed (GObject *object)
nmt_newt_grid_add (grid, priv->metric, 4, 0);
nmt_newt_widget_set_padding (priv->metric, 1, 0, 0, 0);
if (priv->family == AF_INET) {
nm_editor_bind_ip4_route_to_strings (object, "ip4-route",
priv->dest, "text",
priv->next_hop, "text",
priv->metric, "text",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
} else if (priv->family == AF_INET6) {
nm_editor_bind_ip6_route_to_strings (object, "ip6-route",
priv->dest, "text",
priv->next_hop, "text",
priv->metric, "text",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
} else
g_assert_not_reached ();
nm_editor_bind_ip_route_to_strings (priv->family,
object, "route",
priv->dest, "text",
priv->next_hop, "text",
priv->metric, "text",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
G_OBJECT_CLASS (nmt_route_entry_parent_class)->constructed (object);
}
......@@ -174,8 +164,7 @@ nmt_route_entry_finalize (GObject *object)
{
NmtRouteEntryPrivate *priv = NMT_ROUTE_ENTRY_GET_PRIVATE (object);
g_clear_pointer (&priv->ip4_route, nm_ip4_route_unref);
g_clear_pointer (&priv->ip6_route, nm_ip6_route_unref);
g_clear_pointer (&priv->route, nm_ip_route_unref);
G_OBJECT_CLASS (nmt_route_entry_parent_class)->finalize (object);
}
......@@ -198,17 +187,10 @@ nmt_route_entry_set_property (GObject *object,
case PROP_METRIC_ENTRY_WIDTH:
priv->metric_entry_width = g_value_get_int (value);
break;
case PROP_IP4_ROUTE:
g_return_if_fail (priv->family == AF_INET);
if (priv->ip4_route)
nm_ip4_route_unref (priv->ip4_route);
priv->ip4_route = g_value_dup_boxed (value);
break;
case PROP_IP6_ROUTE:
g_return_if_fail (priv->family == AF_INET6);
if (priv->ip6_route)
nm_ip6_route_unref (priv->ip6_route);
priv->ip6_route = g_value_dup_boxed (value);
case PROP_ROUTE:
if (priv->route)
nm_ip_route_unref (priv->route);
priv->route = g_value_dup_boxed (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -234,13 +216,8 @@ nmt_route_entry_get_property (GObject *object,
case PROP_METRIC_ENTRY_WIDTH:
g_value_set_int (value, priv->metric_entry_width);
break;
case PROP_IP4_ROUTE:
g_return_if_fail (priv->family == AF_INET);
g_value_set_boxed (value, priv->ip4_route);
break;
case PROP_IP6_ROUTE:
g_return_if_fail (priv->family == AF_INET6);
g_value_set_boxed (value, priv->ip6_route);
case PROP_ROUTE:
g_value_set_boxed (value, priv->route);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -301,27 +278,14 @@ nmt_route_entry_class_init (NmtRouteEntryClass *entry_class)
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
/**
* NmtRouteEntry:ip4-route:
*
* The contents of the entries, as an #NMIP4Route. Only valid
* if #NmtRouteEntry:family is %AF_INET.
*/
g_object_class_install_property
(object_class, PROP_IP4_ROUTE,
g_param_spec_boxed ("ip4-route", "", "",
nm_ip4_route_get_type (),
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NmtRouteEntry:ip6-route:
* NmtRouteEntry:route:
*
* The contents of the entries, as an #NMIP6Route. Only valid
* if #NmtRouteEntry:family is %AF_INET6.
* The contents of the entries, as an #NMIPRoute.
*/
g_object_class_install_property
(object_class, PROP_IP6_ROUTE,
g_param_spec_boxed ("ip6-route", "", "",
nm_ip6_route_get_type (),
(object_class, PROP_ROUTE,
g_param_spec_boxed ("route", "", "",
nm_ip_route_get_type (),
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
}
......@@ -54,8 +54,7 @@ typedef struct {
enum {
PROP_0,
PROP_FAMILY,
PROP_IP4_ROUTES,
PROP_IP6_ROUTES,
PROP_ROUTES,
LAST_PROP
};
......@@ -85,7 +84,7 @@ route_list_transform_to_route (GBinding *binding,
NmtRouteTable *table = NMT_ROUTE_TABLE (g_binding_get_source (binding));
NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE (table);
int n = GPOINTER_TO_INT (user_data);
gpointer route;
NMIPRoute *route;
if (n >= priv->routes->len)
return FALSE;
......@@ -105,24 +104,17 @@ route_list_transform_from_route (GBinding *binding,
NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE (table);
int n = GPOINTER_TO_INT (user_data);
GPtrArray *routes;
gpointer route;
NMIPRoute *route;
if (n >= priv->routes->len)
return FALSE;
route = priv->routes->pdata[n];
routes = priv->routes;
if (priv->family == AF_INET)
priv->routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip4_route_unref);
else
priv->routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip6_route_unref);
priv->routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref);
if (route) {
if (priv->family == AF_INET)
nm_ip4_route_unref (route);
else if (priv->family == AF_INET6)
nm_ip6_route_unref (route);
}
if (route)
nm_ip_route_unref (route);
routes->pdata[n] = g_value_dup_boxed (source_value);
g_value_take_boxed (target_value, routes);
......@@ -141,21 +133,12 @@ create_route_entry (NmtWidgetList *list,
priv->ip_entry_width,
priv->metric_entry_width);
if (priv->family == AF_INET) {
g_object_bind_property_full (table, "ip4-routes",
entry, "ip4-route",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
route_list_transform_to_route,
route_list_transform_from_route,
GINT_TO_POINTER (num), NULL);
} else {
g_object_bind_property_full (table, "ip6-routes",
entry, "ip6-route",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
route_list_transform_to_route,
route_list_transform_from_route,
GINT_TO_POINTER (num), NULL);
}
g_object_bind_property_full (table, "routes",
entry, "route"