summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-11-12 18:25:11 +0100
committerThomas Haller <thaller@redhat.com>2014-11-12 18:28:14 +0100
commit745fe126bdf551cb24111c5a7979cd73368ff8fc (patch)
treeba33bb05b9d636039ef72636c95a207669e6bbbb
parentf413ab16ddaffc4fca00ee10fbfb832e12ef25b3 (diff)
parentdd9bb5f376e1367a54b307c26bf4d888976c2d20 (diff)
downloadNetworkManager-745fe126bdf551cb24111c5a7979cd73368ff8fc.tar.gz
dhcp: merge master into systemd-dhcp
-rw-r--r--.gitignore2
-rw-r--r--callouts/nm-dispatcher-utils.c72
-rw-r--r--callouts/tests/test-dispatcher-envp.c81
-rw-r--r--clients/cli/Makefile.am17
-rw-r--r--clients/cli/agent.c251
-rw-r--r--clients/cli/agent.h29
-rw-r--r--clients/cli/common.c412
-rw-r--r--clients/cli/common.h15
-rw-r--r--clients/cli/connections.c413
-rw-r--r--clients/cli/devices.c26
-rw-r--r--clients/cli/general.c10
-rw-r--r--clients/cli/nmcli-completion14
-rw-r--r--clients/cli/nmcli.c30
-rw-r--r--clients/cli/nmcli.h13
-rw-r--r--clients/cli/polkit-agent.c166
-rw-r--r--clients/cli/polkit-agent.h30
-rw-r--r--clients/cli/settings.c822
-rw-r--r--clients/cli/settings.h4
-rw-r--r--clients/common/nm-polkit-listener.c415
-rw-r--r--clients/common/nm-polkit-listener.h104
-rw-r--r--clients/common/nm-secret-agent-simple.c (renamed from clients/tui/nmt-secret-agent.c)368
-rw-r--r--clients/common/nm-secret-agent-simple.h57
-rw-r--r--clients/tui/Makefile.am5
-rw-r--r--clients/tui/nm-editor-bindings.c866
-rw-r--r--clients/tui/nm-editor-bindings.h40
-rw-r--r--clients/tui/nm-editor-utils.c2
-rw-r--r--clients/tui/nmt-page-ip4.c42
-rw-r--r--clients/tui/nmt-page-ip6.c42
-rw-r--r--clients/tui/nmt-password-dialog.c14
-rw-r--r--clients/tui/nmt-route-editor.c36
-rw-r--r--clients/tui/nmt-route-entry.c76
-rw-r--r--clients/tui/nmt-route-table.c131
-rw-r--r--clients/tui/nmt-secret-agent.h57
-rw-r--r--clients/tui/nmtui-connect.c20
-rw-r--r--configure.ac20
-rw-r--r--contrib/fedora/rpm/NetworkManager.spec5
-rwxr-xr-xcontrib/fedora/rpm/build.sh13
-rwxr-xr-xcontrib/fedora/rpm/build_clean.sh4
-rw-r--r--docs/libnm/Makefile.am21
-rw-r--r--docs/libnm/libnm-docs.xml17
-rw-r--r--examples/C/glib/add-connection-gdbus.c2
-rw-r--r--examples/C/glib/add-connection-libnm.c2
-rw-r--r--include/nm-dbus-glib-types.h5
-rw-r--r--include/nm-glib-compat.h33
-rw-r--r--include/nm-test-utils.h12
-rw-r--r--include/nm-utils-internal.h15
-rw-r--r--introspection/nm-ip4-config.xml40
-rw-r--r--introspection/nm-ip6-config.xml31
-rw-r--r--libnm-core/Makefile.libnm-core2
-rw-r--r--libnm-core/nm-connection.c34
-rw-r--r--libnm-core/nm-connection.h11
-rw-r--r--libnm-core/nm-core-internal.h6
-rw-r--r--libnm-core/nm-core-types.h1
-rw-r--r--libnm-core/nm-dbus-interface.h2
-rw-r--r--libnm-core/nm-errors.h12
-rw-r--r--libnm-core/nm-setting-8021x.c57
-rw-r--r--libnm-core/nm-setting-8021x.h2
-rw-r--r--libnm-core/nm-setting-bluetooth.c3
-rw-r--r--libnm-core/nm-setting-ip-config.c2321
-rw-r--r--libnm-core/nm-setting-ip-config.h221
-rw-r--r--libnm-core/nm-setting-ip4-config.c1964
-rw-r--r--libnm-core/nm-setting-ip4-config.h111
-rw-r--r--libnm-core/nm-setting-ip6-config.c1707
-rw-r--r--libnm-core/nm-setting-ip6-config.h110
-rw-r--r--libnm-core/nm-setting-private.h4
-rw-r--r--libnm-core/nm-setting.c79
-rw-r--r--libnm-core/nm-utils-private.h23
-rw-r--r--libnm-core/nm-utils.c676
-rw-r--r--libnm-core/nm-utils.h26
-rw-r--r--libnm-core/tests/test-general.c634
-rw-r--r--libnm-core/tests/test-secrets.c4
-rwxr-xr-xlibnm-util/generate-setting-docs.py6
-rw-r--r--libnm-util/libnm-util.ver2
-rw-r--r--libnm-util/nm-setting-ip4-config.c50
-rw-r--r--libnm-util/nm-setting-ip4-config.h4
-rw-r--r--libnm-util/nm-setting-ip6-config.c50
-rw-r--r--libnm-util/nm-setting-ip6-config.h4
-rw-r--r--libnm-util/tests/test-general.c1
-rw-r--r--libnm/Makefile.am16
-rw-r--r--libnm/NetworkManager.h8
-rw-r--r--libnm/libnm.ver242
-rw-r--r--libnm/nm-active-connection.c62
-rw-r--r--libnm/nm-active-connection.h8
-rw-r--r--libnm/nm-client.c10
-rw-r--r--libnm/nm-device.c89
-rw-r--r--libnm/nm-device.h8
-rw-r--r--libnm/nm-dhcp-config.c217
-rw-r--r--libnm/nm-dhcp-config.h62
-rw-r--r--libnm/nm-dhcp4-config.c150
-rw-r--r--libnm/nm-dhcp4-config.h23
-rw-r--r--libnm/nm-dhcp6-config.c148
-rw-r--r--libnm/nm-dhcp6-config.h23
-rw-r--r--libnm/nm-ip-config.c498
-rw-r--r--libnm/nm-ip-config.h73
-rw-r--r--libnm/nm-ip4-config.c378
-rw-r--r--libnm/nm-ip4-config.h30
-rw-r--r--libnm/nm-ip6-config.c342
-rw-r--r--libnm/nm-ip6-config.h28
-rw-r--r--libnm/nm-manager.c24
-rw-r--r--libnm/nm-object.c21
-rw-r--r--libnm/nm-types.h6
-rw-r--r--libnm/nm-vpn-editor-plugin.c179
-rw-r--r--libnm/nm-vpn-editor-plugin.h189
-rw-r--r--libnm/nm-vpn-plugin-ui-interface.c244
-rw-r--r--libnm/nm-vpn-plugin-ui-interface.h206
-rw-r--r--libnm/nm-wimax-nsp.h9
-rw-r--r--libnm/tests/test-nm-client.c6
-rw-r--r--m4/compiler_warnings.m42
-rw-r--r--man/Makefile.am13
-rw-r--r--man/NetworkManager.conf.xml.in24
-rw-r--r--man/nmcli.1.in63
-rw-r--r--man/nmtui.1.in66
-rw-r--r--po/POTFILES.in8
-rw-r--r--po/POTFILES.skip1
-rw-r--r--src/Makefile.am183
-rw-r--r--src/NetworkManagerUtils.c115
-rw-r--r--src/NetworkManagerUtils.h6
-rw-r--r--src/devices/adsl/nm-atm-manager.c1
-rw-r--r--src/devices/bluetooth/nm-bluez-device.c27
-rw-r--r--src/devices/nm-device-gre.c1
-rw-r--r--src/devices/nm-device.c515
-rw-r--r--src/devices/nm-device.h9
-rw-r--r--src/devices/team/nm-device-team.c1
-rw-r--r--src/devices/wifi/nm-device-wifi.c16
-rw-r--r--src/devices/wwan/nm-modem-broadband.c1
-rw-r--r--src/devices/wwan/nm-modem.c11
-rw-r--r--src/dhcp-manager/nm-dhcp-client.c78
-rw-r--r--src/dhcp-manager/nm-dhcp-client.h35
-rw-r--r--src/dhcp-manager/nm-dhcp-dhclient-utils.c135
-rw-r--r--src/dhcp-manager/nm-dhcp-dhclient-utils.h7
-rw-r--r--src/dhcp-manager/nm-dhcp-dhclient.c86
-rw-r--r--src/dhcp-manager/nm-dhcp-dhclient.h6
-rw-r--r--src/dhcp-manager/nm-dhcp-dhcpcd.c32
-rw-r--r--src/dhcp-manager/nm-dhcp-dhcpcd.h2
-rw-r--r--src/dhcp-manager/nm-dhcp-listener.c289
-rw-r--r--src/dhcp-manager/nm-dhcp-listener.h39
-rw-r--r--src/dhcp-manager/nm-dhcp-manager.c392
-rw-r--r--src/dhcp-manager/nm-dhcp-manager.h8
-rw-r--r--src/dhcp-manager/nm-dhcp-systemd.c851
-rw-r--r--src/dhcp-manager/nm-dhcp-systemd.h45
-rw-r--r--src/dhcp-manager/nm-dhcp-utils.c49
-rw-r--r--src/dhcp-manager/nm-dhcp-utils.h2
-rw-r--r--src/dhcp-manager/systemd-dhcp/nm-sd-adapt.c208
-rw-r--r--src/dhcp-manager/systemd-dhcp/nm-sd-adapt.h109
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-internal.h2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-lease-internal.h8
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-network.c2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-option.c2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-packet.c2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-internal.h2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-lease-internal.h2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-network.c2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-option.c2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/network-internal.c10
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/network-internal.h4
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-client.c165
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-lease.c66
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp6-client.c52
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp6-lease.c2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/shared/fileio.c6
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/shared/macro.h8
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/shared/strv.c2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/shared/time-util.c15
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/shared/time-util.h2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/shared/utf8.c2
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/shared/util.c51
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/shared/util.h10
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/systemd/sd-dhcp-client.h5
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/systemd/sd-dhcp-lease.h5
-rw-r--r--src/dhcp-manager/systemd-dhcp/src/systemd/sd-dhcp6-client.h1
-rw-r--r--src/dhcp-manager/tests/Makefile.am16
-rw-r--r--src/dhcp-manager/tests/test-dhcp-dhclient.c125
-rw-r--r--src/dhcp-manager/tests/test-dhcp-utils.c (renamed from src/dhcp-manager/tests/test-dhcp-options.c)37
-rw-r--r--src/main-utils.c281
-rw-r--r--src/main-utils.h39
-rw-r--r--src/main.c253
-rw-r--r--src/nm-active-connection.c1
-rw-r--r--src/nm-config.c88
-rw-r--r--src/nm-config.h1
-rw-r--r--src/nm-default-route-manager.c997
-rw-r--r--src/nm-default-route-manager.h77
-rw-r--r--src/nm-iface-helper.c529
-rw-r--r--src/nm-ip4-config.c313
-rw-r--r--src/nm-ip4-config.h11
-rw-r--r--src/nm-ip6-config.c300
-rw-r--r--src/nm-ip6-config.h12
-rw-r--r--src/nm-manager.c29
-rw-r--r--src/nm-manager.h2
-rw-r--r--src/nm-policy.c451
-rw-r--r--src/nm-types.h45
-rw-r--r--src/platform/nm-fake-platform.c65
-rw-r--r--src/platform/nm-linux-platform.c59
-rw-r--r--src/platform/nm-platform.c56
-rw-r--r--src/platform/nm-platform.h87
-rw-r--r--src/platform/tests/dump.c4
-rw-r--r--src/platform/tests/platform.c5
-rw-r--r--src/platform/tests/test-cleanup.c8
-rw-r--r--src/platform/tests/test-route.c4
-rw-r--r--src/settings/nm-settings-connection.c1
-rw-r--r--src/settings/nm-settings.c1
-rw-r--r--src/settings/plugins/ibft/reader.c42
-rw-r--r--src/settings/plugins/ibft/tests/test-ibft.c46
-rw-r--r--src/settings/plugins/ifcfg-rh/reader.c573
-rw-r--r--src/settings/plugins/ifcfg-rh/shvar.c6
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am3
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-trailing-spaces11
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c2009
-rw-r--r--src/settings/plugins/ifcfg-rh/writer.c257
-rw-r--r--src/settings/plugins/ifnet/connection_parser.c391
-rw-r--r--src/settings/plugins/ifnet/net_utils.c120
-rw-r--r--src/settings/plugins/ifnet/net_utils.h22
-rw-r--r--src/settings/plugins/ifnet/tests/test_all.c38
-rw-r--r--src/settings/plugins/ifupdown/parser.c120
-rw-r--r--src/settings/plugins/ifupdown/tests/test-ifupdown.c172
-rw-r--r--src/settings/plugins/keyfile/reader.c222
-rw-r--r--src/settings/plugins/keyfile/tests/test-keyfile.c518
-rw-r--r--src/settings/plugins/keyfile/writer.c258
-rw-r--r--src/supplicant-manager/nm-supplicant-config.c34
-rw-r--r--src/supplicant-manager/tests/test-supplicant-config.c18
-rw-r--r--src/tests/test-general.c84
-rw-r--r--src/tests/test-resolvconf-capture.c1
-rw-r--r--src/vpn-manager/nm-vpn-connection.c113
-rw-r--r--src/vpn-manager/nm-vpn-connection.h11
223 files changed, 16825 insertions, 12335 deletions
diff --git a/.gitignore b/.gitignore
index 86209c29bc..8aa06cad5d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -230,7 +230,9 @@ valgrind-*.log
/src/dhcp-manager/nm-dhcp-helper
/src/dhcp-manager/tests/test-dhcp-dhclient
/src/dhcp-manager/tests/test-dhcp-options
+/src/dhcp-manager/tests/test-dhcp-utils
/src/dnsmasq-manager/tests/test-dnsmasq-utils
+/src/nm-iface-helper
/src/settings/plugins/ibft/tests/test-ibft
/src/settings/plugins/ifcfg-rh/tests/network-scripts/*-Test_Write_*
/src/settings/plugins/ifcfg-rh/tests/network-scripts/Test_Write_*
diff --git a/callouts/nm-dispatcher-utils.c b/callouts/nm-dispatcher-utils.c
index 66b6a07fd8..8d7274329c 100644
--- a/callouts/nm-dispatcher-utils.c
+++ b/callouts/nm-dispatcher-utils.c
@@ -92,11 +92,9 @@ 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;
- char str_addr[INET_ADDRSTRLEN];
- char str_gw[INET_ADDRSTRLEN];
int i;
if (ip4_config == NULL)
@@ -108,22 +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++) {
- NMIP4Address *addr = addresses->pdata[i];
- guint32 ip_prefix = nm_ip4_address_get_prefix (addr);
+ NMIPAddress *addr = addresses->pdata[i];
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);
-
- 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),
+ 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);
}
@@ -177,15 +177,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 %u", prefix, i,
+ nm_ip_route_get_dest (route),
+ nm_ip_route_get_prefix (route),
+ next_hop,
+ (guint32) MAX (0, 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));
@@ -222,11 +226,9 @@ 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;
- char str_addr[INET6_ADDRSTRLEN];
- char str_gw[INET6_ADDRSTRLEN];
int i;
if (ip6_config == NULL)
@@ -238,22 +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++) {
- NMIP6Address *addr = addresses->pdata[i];
- guint32 ip_prefix = nm_ip6_address_get_prefix (addr);
+ NMIPAddress *addr = addresses->pdata[i];
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);
-
- 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),
+ 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);
}
@@ -287,15 +291,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 %u", prefix, i,
+ nm_ip_route_get_dest (route),
+ nm_ip_route_get_prefix (route),
+ next_hop,
+ (guint32) MAX (0, 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..423d29fd83 100644
--- a/callouts/tests/test-dispatcher-envp.c
+++ b/callouts/tests/test-dispatcher-envp.c
@@ -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}"));
@@ -218,37 +219,36 @@ 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;
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);
+ if (addresses->len == 0) {
+ gateway = strchr (prefix, ' ');
+ g_assert (gateway);
+ gateway++;
+ }
+ addr = nm_ip_address_new (AF_INET, ip, (guint) atoi (prefix), error);
+ if (!addr) {
+ g_ptr_array_unref (addresses);
+ return FALSE;
+ }
g_ptr_array_add (addresses, addr);
}
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);
@@ -261,37 +261,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);
}
diff --git a/clients/cli/Makefile.am b/clients/cli/Makefile.am
index 94a249749e..0820aab045 100644
--- a/clients/cli/Makefile.am
+++ b/clients/cli/Makefile.am
@@ -9,12 +9,15 @@ AM_CPPFLAGS = \
-I${top_builddir}/libnm-core \
-I${top_srcdir}/libnm \
-I${top_builddir}/libnm \
+ -I${top_srcdir}/clients/common \
$(GLIB_CFLAGS) \
-DG_LOG_DOMAIN=\""nmcli"\" \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
-DNMCLI_LOCALEDIR=\"$(datadir)/locale\"
nmcli_SOURCES = \
+ agent.c \
+ agent.h \
common.c \
common.h \
connections.c \
@@ -28,13 +31,25 @@ nmcli_SOURCES = \
nmcli.c \
nmcli.h \
utils.c \
- utils.h
+ utils.h \
+ polkit-agent.c \
+ polkit-agent.h \
+ \
+ $(srcdir)/../common/nm-secret-agent-simple.c \
+ $(srcdir)/../common/nm-secret-agent-simple.h \
+ $(NULL)
nmcli_LDADD = \
$(GLIB_LIBS) \
$(READLINE_LIBS) \
$(top_builddir)/libnm/libnm.la
+if WITH_POLKIT_AGENT
+AM_CPPFLAGS += $(POLKIT_CFLAGS)
+nmcli_SOURCES += $(srcdir)/../common/nm-polkit-listener.c $(srcdir)/../common/nm-polkit-listener.h
+nmcli_LDADD += $(POLKIT_LIBS)
+endif
+
if BUILD_SETTING_DOCS
settings-docs.c: settings-docs.xsl $(top_builddir)/libnm-util/nm-setting-docs.xml
$(AM_V_GEN) xsltproc --output $@ $^
diff --git a/clients/cli/agent.c b/clients/cli/agent.c
new file mode 100644
index 0000000000..2b606a7fca
--- /dev/null
+++ b/clients/cli/agent.c
@@ -0,0 +1,251 @@
+/*
+ * nmcli - command-line tool for controlling NetworkManager
+ * Functions for running NM secret agent.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2014 Red Hat, Inc.
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include <readline/readline.h>
+#include <readline/history.h>
+
+#include "common.h"
+#include "utils.h"
+#include "nm-secret-agent-simple.h"
+#include "polkit-agent.h"
+#include "agent.h"
+
+static void
+usage (void)
+{
+ g_printerr (_("Usage: nmcli agent { COMMAND | help }\n\n"
+ "COMMAND := { secret | polkit | all }\n\n"
+ ));
+}
+
+static void
+usage_agent_secret (void)
+{
+ g_printerr (_("Usage: nmcli agent secret { help }\n"
+ "\n"
+ "Runs nmcli as NetworkManager secret agent. When NetworkManager requires\n"
+ "a password it asks registered agents for it. This command keeps nmcli running\n"
+ "and if a password is required asks the user for it.\n\n"));
+}
+
+static void
+usage_agent_polkit (void)
+{
+ g_printerr (_("Usage: nmcli agent polkit { help }\n"
+ "\n"
+ "Registers nmcli as a polkit action for the user session.\n"
+ "When a polkit daemon requires an authorization, nmcli asks the user and gives\n"
+ "the reponse back to polkit.\n\n"));
+}
+
+static void
+usage_agent_all (void)
+{
+ g_printerr (_("Usage: nmcli agent all { help }\n"
+ "\n"
+ "Runs nmcli as both NetworkManager secret and a polkit agent.\n\n"));
+}
+
+/* for pre-filling a string to readline prompt */
+static char *pre_input_deftext;
+static int
+set_deftext (void)
+{
+ if (pre_input_deftext && rl_startup_hook) {
+ rl_insert_text (pre_input_deftext);
+ g_free (pre_input_deftext);
+ pre_input_deftext = NULL;
+ rl_startup_hook = NULL;
+ }
+ return 0;
+}
+
+static gboolean
+get_secrets_from_user (const char *request_id,
+ const char *title,
+ const char *msg,
+ GPtrArray *secrets)
+{
+ int i;
+
+ for (i = 0; i < secrets->len; i++) {
+ NMSecretAgentSimpleSecret *secret = secrets->pdata[i];
+ char *pwd = NULL;
+
+ /* Ask user for the password */
+ g_print ("%s\n", msg);
+ if (secret->value) {
+ /* Prefill the password if we have it. */
+ rl_startup_hook = set_deftext;
+ pre_input_deftext = g_strdup (secret->value);
+ }
+ pwd = nmc_readline ("%s (%s): ", secret->name, secret->prop_name);
+
+ /* No password provided, cancel the secrets. */
+ if (!pwd)
+ return FALSE;
+ g_free (secret->value);
+ secret->value = pwd;
+ }
+ return TRUE;
+}
+
+static void
+secrets_requested (NMSecretAgentSimple *agent,
+ const char *request_id,
+ const char *title,
+ const char *msg,
+ GPtrArray *secrets,
+ gpointer user_data)
+{
+ NmCli *nmc = (NmCli *) user_data;
+ gboolean success = FALSE;
+
+ if (nmc->print_output == NMC_PRINT_PRETTY)
+ nmc_terminal_erase_line ();
+
+ success = get_secrets_from_user (request_id, title, msg, secrets);
+ if (success)
+ nm_secret_agent_simple_response (agent, request_id, secrets);
+ else
+ nm_secret_agent_simple_response (agent, request_id, NULL);
+}
+
+
+static NMCResultCode
+do_agent_secret (NmCli *nmc, int argc, char **argv)
+{
+ /* Create secret agent */
+ nmc->secret_agent = nm_secret_agent_simple_new ("nmcli-agent", NULL);
+ if (nmc->secret_agent) {
+ /* We keep running */
+ nmc->should_wait = TRUE;
+
+ g_signal_connect (nmc->secret_agent, "request-secrets", G_CALLBACK (secrets_requested), nmc);
+ g_print (_("nmcli successfully registered as a NetworkManager's secret agent.\n"));
+ } else {
+ g_string_printf (nmc->return_text, _("Error: secret agent initialization failed"));
+ nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
+ }
+
+ return nmc->return_value;
+}
+
+static NMCResultCode
+do_agent_polkit (NmCli *nmc, int argc, char **argv)
+{
+ GError *error = NULL;
+
+ /* Initialize polkit agent */
+ if (!nmc_polkit_agent_init (nmc, TRUE, &error)) {
+ g_dbus_error_strip_remote_error (error);
+ g_string_printf (nmc->return_text, _("Error: polkit agent initialization failed: %s"),
+ error->message);
+ nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
+ g_error_free (error);
+ } else {
+ /* We keep running */
+ nmc->should_wait = TRUE;
+
+ g_print (_("nmcli successfully registered as a polkit agent.\n"));
+ }
+
+ return nmc->return_value;
+}
+
+static NMCResultCode
+do_agent_all (NmCli *nmc, int argc, char **argv)
+{
+ NMCResultCode secret_res;
+
+ /* Run both secret and polkit agent */
+ secret_res = do_agent_secret (nmc, argc, argv);
+ if (secret_res != NMC_RESULT_SUCCESS)
+ g_printerr ("%s\n", nmc->return_text->str);
+
+ nmc->return_value = do_agent_polkit (nmc, argc, argv);
+
+ if (nmc->return_value == NMC_RESULT_SUCCESS && secret_res != NMC_RESULT_SUCCESS)
+ nmc->return_value = secret_res;
+
+ return nmc->return_value;
+}
+
+NMCResultCode
+do_agent (NmCli *nmc, int argc, char **argv)
+{
+ /* Get NMClient object */
+ nmc->get_client (nmc);
+
+ /* Check whether NetworkManager is running */
+ if (!nm_client_get_nm_running (nmc->client)) {
+ g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
+ nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
+ return nmc->return_value;
+ }
+ /* Compare NM and nmcli versions */
+ if (!nmc_versions_match (nmc))
+ return nmc->return_value;
+
+ if (argc == 0) {
+ nmc->return_value = do_agent_all (nmc, 0, NULL);
+ }
+
+ if (argc > 0) {
+ if (nmc_arg_is_help (*argv)) {
+ usage ();
+ goto usage_exit;
+ } else if (matches (*argv, "secret") == 0) {
+ if (nmc_arg_is_help (*(argv+1))) {
+ usage_agent_secret ();
+ goto usage_exit;
+ }
+ nmc->return_value = do_agent_secret (nmc, argc-1, argv+1);
+ } else if (matches (*argv, "polkit") == 0) {
+ if (nmc_arg_is_help (*(argv+1))) {
+ usage_agent_polkit ();
+ goto usage_exit;
+ }
+ nmc->return_value = do_agent_polkit (nmc, argc-1, argv+1);
+ } else if (matches (*argv, "all") == 0) {
+ if (nmc_arg_is_help (*(argv+1))) {
+ usage_agent_all ();
+ goto usage_exit;
+ }
+ nmc->return_value = do_agent_all (nmc, argc-1, argv+1);
+ } else {
+ usage ();
+ g_string_printf (nmc->return_text, _("Error: 'agent' command '%s' is not valid."), *argv);
+ nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
+ }
+ }
+
+usage_exit:
+ return nmc->return_value;
+}
diff --git a/clients/cli/agent.h b/clients/cli/agent.h
new file mode 100644
index 0000000000..70ea0d9b23
--- /dev/null
+++ b/clients/cli/agent.h
@@ -0,0 +1,29 @@
+/*
+ * nmcli - command-line tool for controlling NetworkManager
+ * Functions for running NM secret agent.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2014 Red Hat, Inc.
+ */
+
+#ifndef __NMC_AGENT_H__
+#define __NMC_AGENT_H__
+
+#include "nmcli.h"
+
+NMCResultCode do_agent (NmCli *nmc, int argc, char **argv);
+
+#endif /* __NMC_AGENT_H__ */
diff --git a/clients/cli/common.c b/clients/cli/common.c
index 0a7541c976..aa8f80610e 100644
--- a/clients/cli/common.c
+++ b/clients/cli/common.c
@@ -30,6 +30,8 @@
#include <readline/readline.h>
#include <readline/history.h>
+#include "nm-glib-compat.h"
+
#include "common.h"
#include "utils.h"
@@ -37,13 +39,14 @@
NmcOutputField nmc_fields_ip4_config[] = {
{"GROUP", N_("GROUP"), 15}, /* 0 */
{"ADDRESS", N_("ADDRESS"), 68}, /* 1 */
- {"ROUTE", N_("ROUTE"), 68}, /* 2 */
- {"DNS", N_("DNS"), 35}, /* 3 */
- {"DOMAIN", N_("DOMAIN"), 35}, /* 4 */
- {"WINS", N_("WINS"), 20}, /* 5 */
+ {"GATEWAY", N_("GATEWAY"), 0}, /* 2 */
+ {"ROUTE", N_("ROUTE"), 68}, /* 3 */
+ {"DNS", N_("DNS"), 35}, /* 4 */
+ {"DOMAIN", N_("DOMAIN"), 35}, /* 5 */
+ {"WINS", N_("WINS"), 20}, /* 6 */
{NULL, NULL, 0}
};
-#define NMC_FIELDS_IP4_CONFIG_ALL "GROUP,ADDRESS,ROUTE,DNS,DOMAIN,WINS"
+#define NMC_FIELDS_IP4_CONFIG_ALL "GROUP,ADDRESS,GATEWAY,ROUTE,DNS,DOMAIN,WINS"
/* Available fields for DHCPv4 group */
NmcOutputField nmc_fields_dhcp4_config[] = {
@@ -57,12 +60,13 @@ NmcOutputField nmc_fields_dhcp4_config[] = {
NmcOutputField nmc_fields_ip6_config[] = {
{"GROUP", N_("GROUP"), 15}, /* 0 */
{"ADDRESS", N_("ADDRESS"), 95}, /* 1 */
- {"ROUTE", N_("ROUTE"), 95}, /* 2 */
- {"DNS", N_("DNS"), 60}, /* 3 */
- {"DOMAIN", N_("DOMAIN"), 35}, /* 4 */
+ {"GATEWAY", N_("GATEWAY"), 0}, /* 2 */
+ {"ROUTE", N_("ROUTE"), 95}, /* 3 */
+ {"DNS", N_("DNS"), 60}, /* 4 */
+ {"DOMAIN", N_("DOMAIN"), 35}, /* 5 */
{NULL, NULL, 0}
};
-#define NMC_FIELDS_IP6_CONFIG_ALL "GROUP,ADDRESS,ROUTE,DNS,DOMAIN"
+#define NMC_FIELDS_IP6_CONFIG_ALL "GROUP,ADDRESS,GATEWAY,ROUTE,DNS,DOMAIN"
/* Available fields for DHCPv6 group */
NmcOutputField nmc_fields_dhcp6_config[] = {
@@ -74,7 +78,7 @@ NmcOutputField nmc_fields_dhcp6_config[] = {
gboolean
-print_ip4_config (NMIP4Config *cfg4,
+print_ip4_config (NMIPConfig *cfg4,
NmCli *nmc,
const char *group_prefix,
const char *one_field)
@@ -100,62 +104,58 @@ print_ip4_config (NMIP4Config *cfg4,
g_ptr_array_add (nmc->output_data, arr);
/* addresses */
- ptr_array = nm_ip4_config_get_addresses (cfg4);
+ ptr_array = nm_ip_config_get_addresses (cfg4);
if (ptr_array) {
addr_arr = g_new (char *, ptr_array->len + 1);
for (i = 0; i < ptr_array->len; i++) {
- NMIP4Address *addr = (NMIP4Address *) g_ptr_array_index (ptr_array, i);
- guint32 prefix;
- char *ip_str, *gw_str;
-
- ip_str = nmc_ip4_address_as_string (nm_ip4_address_get_address (addr), NULL);
- prefix = nm_ip4_address_get_prefix (addr);
- gw_str = nmc_ip4_address_as_string (nm_ip4_address_get_gateway (addr), NULL);
+ NMIPAddress *addr = (NMIPAddress *) g_ptr_array_index (ptr_array, i);
- addr_arr[i] = g_strdup_printf ("ip = %s/%u, gw = %s", ip_str, prefix, gw_str);
- g_free (ip_str);
- g_free (gw_str);
+ addr_arr[i] = g_strdup_printf ("%s/%u",
+ nm_ip_address_get_address (addr),
+ nm_ip_address_get_prefix (addr));
}
addr_arr[i] = NULL;
}
/* routes */
- ptr_array = nm_ip4_config_get_routes (cfg4);
+ ptr_array = nm_ip_config_get_routes (cfg4);
if (ptr_array) {
route_arr = g_new (char *, ptr_array->len + 1);
for (i = 0; i < ptr_array->len; i++) {
- NMIP4Route *route = (NMIP4Route *) g_ptr_array_index (ptr_array, i);
- guint32 prefix, metric;
- char *dest_str, *nexthop_str;
-
- dest_str = nmc_ip4_address_as_string (nm_ip4_route_get_dest (route), NULL);
- nexthop_str = nmc_ip4_address_as_string (nm_ip4_route_get_next_hop (route), NULL);
- prefix = nm_ip4_route_get_prefix (route);
- metric = nm_ip4_route_get_metric (route);
-
- route_arr[i] = g_strdup_printf ("dst = %s/%u, nh = %s, mt = %u", dest_str, prefix, nexthop_str, metric);
- g_free (dest_str);
- g_free (nexthop_str);
+ NMIPRoute *route = (NMIPRoute *) g_ptr_array_index (ptr_array, i);
+ const char *next_hop;
+
+ next_hop = nm_ip_route_get_next_hop (route);
+ if (!next_hop)
+ next_hop = "0.0.0.0";
+
+ route_arr[i] = g_strdup_printf ("dst = %s/%u, nh = %s%c mt = %u",
+ nm_ip_route_get_dest (route),
+ nm_ip_route_get_prefix (route),
+ next_hop,
+ nm_ip_route_get_metric (route) == -1 ? '\0' : ',',
+ (guint32) nm_ip_route_get_metric (route));
}
route_arr[i] = NULL;
}
/* DNS */
- dns_arr = g_strdupv ((char **) nm_ip4_config_get_nameservers (cfg4));
+ dns_arr = g_strdupv ((char **) nm_ip_config_get_nameservers (cfg4));
/* domains */
- domain_arr = g_strdupv ((char **) nm_ip4_config_get_domains (cfg4));
+ domain_arr = g_strdupv ((char **) nm_ip_config_get_domains (cfg4));
/* WINS */
- wins_arr = g_strdupv ((char **) nm_ip4_config_get_wins_servers (cfg4));
+ wins_arr = g_strdupv ((char **) nm_ip_config_get_wins_servers (cfg4));
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX);
set_val_strc (arr, 0, group_prefix);
set_val_arr (arr, 1, addr_arr);
- set_val_arr (arr, 2, route_arr);
- set_val_arr (arr, 3, dns_arr);
- set_val_arr (arr, 4, domain_arr);
- set_val_arr (arr, 5, wins_arr);
+ set_val_strc (arr, 2, nm_ip_config_get_gateway (cfg4));
+ set_val_arr (arr, 3, route_arr);
+ set_val_arr (arr, 4, dns_arr);
+ set_val_arr (arr, 5, domain_arr);
+ set_val_arr (arr, 6, wins_arr);
g_ptr_array_add (nmc->output_data, arr);
print_data (nmc); /* Print all data */
@@ -167,7 +167,7 @@ print_ip4_config (NMIP4Config *cfg4,
}
gboolean
-print_ip6_config (NMIP6Config *cfg6,
+print_ip6_config (NMIPConfig *cfg6,
NmCli *nmc,
const char *group_prefix,
const char *one_field)
@@ -192,58 +192,54 @@ print_ip6_config (NMIP6Config *cfg6,
g_ptr_array_add (nmc->output_data, arr);
/* addresses */
- ptr_array = nm_ip6_config_get_addresses (cfg6);
+ ptr_array = nm_ip_config_get_addresses (cfg6);
if (ptr_array) {
addr_arr = g_new (char *, ptr_array->len + 1);
for (i = 0; i < ptr_array->len; i++) {
- NMIP6Address *addr = (NMIP6Address *) g_ptr_array_index (ptr_array, i);
- guint32 prefix;
- char *ip_str, *gw_str;
-
- ip_str = nmc_ip6_address_as_string (nm_ip6_address_get_address (addr), NULL);
- prefix = nm_ip6_address_get_prefix (addr);
- gw_str = nmc_ip6_address_as_string (nm_ip6_address_get_gateway (addr), NULL);
+ NMIPAddress *addr = (NMIPAddress *) g_ptr_array_index (ptr_array, i);
- addr_arr[i] = g_strdup_printf ("ip = %s/%u, gw = %s", ip_str, prefix, gw_str);
- g_free (ip_str);
- g_free (gw_str);
+ addr_arr[i] = g_strdup_printf ("%s/%u",
+ nm_ip_address_get_address (addr),
+ nm_ip_address_get_prefix (addr));
}
addr_arr[i] = NULL;
}
/* routes */
- ptr_array = nm_ip6_config_get_routes (cfg6);
+ ptr_array = nm_ip_config_get_routes (cfg6);
if (ptr_array) {
route_arr = g_new (char *, ptr_array->len + 1);
for (i = 0; i < ptr_array->len; i++) {
- NMIP6Route *route = (NMIP6Route *) g_ptr_array_index (ptr_array, i);
- guint32 prefix, metric;
- char *dest_str, *nexthop_str;
-
- dest_str = nmc_ip6_address_as_string (nm_ip6_route_get_dest (route), NULL);
- nexthop_str = nmc_ip6_address_as_string (nm_ip6_route_get_next_hop (route), NULL);
- prefix = nm_ip6_route_get_prefix (route);
- metric = nm_ip6_route_get_metric (route);
-
- route_arr[i] = g_strdup_printf ("dst = %s/%u, nh = %s, mt = %u", dest_str, prefix, nexthop_str, metric);
- g_free (dest_str);
- g_free (nexthop_str);
+ NMIPRoute *route = (NMIPRoute *) g_ptr_array_index (ptr_array, i);
+ const char *next_hop;
+
+ next_hop = nm_ip_route_get_next_hop (route);
+ if (!next_hop)
+ next_hop = "::";
+
+ route_arr[i] = g_strdup_printf ("dst = %s/%u, nh = %s%c mt = %u",
+ nm_ip_route_get_dest (route),
+ nm_ip_route_get_prefix (route),
+ next_hop,
+ nm_ip_route_get_metric (route) == -1 ? '\0' : ',',
+ (guint32) nm_ip_route_get_metric (route));
}
route_arr[i] = NULL;
}
/* DNS */
- dns_arr = g_strdupv ((char **) nm_ip6_config_get_nameservers (cfg6));
+ dns_arr = g_strdupv ((char **) nm_ip_config_get_nameservers (cfg6));
/* domains */
- domain_arr = g_strdupv ((char **) nm_ip6_config_get_domains (cfg6));
+ domain_arr = g_strdupv ((char **) nm_ip_config_get_domains (cfg6));
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX);
set_val_strc (arr, 0, group_prefix);
set_val_arr (arr, 1, addr_arr);
- set_val_arr (arr, 2, route_arr);
- set_val_arr (arr, 3, dns_arr);
- set_val_arr (arr, 4, domain_arr);
+ set_val_strc (arr, 2, nm_ip_config_get_gateway (cfg6));
+ set_val_arr (arr, 3, route_arr);
+ set_val_arr (arr, 4, dns_arr);
+ set_val_arr (arr, 5, domain_arr);
g_ptr_array_add (nmc->output_data, arr);
print_data (nmc); /* Print all data */
@@ -255,7 +251,7 @@ print_ip6_config (NMIP6Config *cfg6,
}
gboolean
-print_dhcp4_config (NMDhcp4Config *dhcp4,
+print_dhcp4_config (NMDhcpConfig *dhcp4,
NmCli *nmc,
const char *group_prefix,
const char *one_field)
@@ -267,7 +263,7 @@ print_dhcp4_config (NMDhcp4Config *dhcp4,
if (dhcp4 == NULL)
return FALSE;
- table = nm_dhcp4_config_get_options (dhcp4);
+ table = nm_dhcp_config_get_options (dhcp4);
if (table) {
GHashTableIter table_iter;
gpointer key, value;
@@ -303,7 +299,7 @@ print_dhcp4_config (NMDhcp4Config *dhcp4,
}
gboolean
-print_dhcp6_config (NMDhcp6Config *dhcp6,
+print_dhcp6_config (NMDhcpConfig *dhcp6,
NmCli *nmc,
const char *group_prefix,
const char *one_field)
@@ -315,7 +311,7 @@ print_dhcp6_config (NMDhcp6Config *dhcp6,
if (dhcp6 == NULL)
return FALSE;
- table = nm_dhcp6_config_get_options (dhcp6);
+ table = nm_dhcp_config_get_options (dhcp6);
if (table) {
GHashTableIter table_iter;
gpointer key, value;
@@ -351,18 +347,19 @@ print_dhcp6_config (NMDhcp6Config *dhcp6,
}
/*
- * Parse IPv4 address from string to NMIP4Address stucture.
- * ip_str is the IPv4 address in the form address/prefix
- * gw_str is the gateway address (it is optional)
+ * Parse IP address from string to NMIPAddress stucture.
+ * ip_str is the IP address in the form address/prefix
*/
-NMIP4Address *
-nmc_parse_and_build_ip4_address (const char *ip_str, const char *gw_str, GError **error)
+NMIPAddress *
+nmc_parse_and_build_address (int family, const char *ip_str, GError **error)
{
- NMIP4Address *addr = NULL;
- guint32 ip4_addr, gw_addr;
+ int max_prefix = (family == AF_INET) ? 32 : 128;
+ NMIPAddress *addr = NULL;
+ const char *ip;
char *tmp;
char *plen;
long int prefix;
+ GError *local = NULL;
g_return_val_if_fail (ip_str != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
@@ -372,158 +369,71 @@ nmc_parse_and_build_ip4_address (const char *ip_str, const char *gw_str, GError
if (plen)
*plen++ = '\0';
- if (inet_pton (AF_INET, tmp, &ip4_addr) < 1) {
- g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
- _("invalid IPv4 address '%s'"), tmp);
- goto finish;
- }
+ ip = tmp;
- prefix = 32;
+ prefix = max_prefix;
if (plen) {
- if (!nmc_string_to_int (plen, TRUE, 1, 32, &prefix)) {
+ if (!nmc_string_to_int (plen, TRUE, 1, max_prefix, &prefix)) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
- _("invalid prefix '%s'; <1-32> allowed"), plen);
+ _("invalid prefix '%s'; <1-%d> allowed"), plen, max_prefix);
goto finish;
}
}
- if (inet_pton (AF_INET, gw_str ? gw_str : "0.0.0.0", &gw_addr) < 1) {
+ addr = nm_ip_address_new (family, ip, (guint32) prefix, &local);
+ if (!addr) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
- _("invalid gateway '%s'"), gw_str);
- goto finish;
+ _("invalid IP address: %s"), local->message);
+ g_clear_error (&local);
}
- addr = nm_ip4_address_new ();
- nm_ip4_address_set_address (addr, ip4_addr);
- nm_ip4_address_set_prefix (addr, (guint32) prefix);
- nm_ip4_address_set_gateway (addr, gw_addr);
-
finish:
g_free (tmp);
return addr;
}
/*
- * Parse IPv6 address from string to NMIP6Address stucture.
- * ip_str is the IPv6 address in the form address/prefix
- * gw_str is the gateway address (it is optional)
- */
-NMIP6Address *
-nmc_parse_and_build_ip6_address (const char *ip_str, const char *gw_str, GError **error)
-{
- NMIP6Address *addr = NULL;
- struct in6_addr ip_addr, gw_addr;
- char *tmp;
- char *plen;
- long int prefix;
-
- g_return_val_if_fail (ip_str != NULL, NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
-
- tmp = g_strdup (ip_str);
- plen = strchr (tmp, '/'); /* prefix delimiter */
- if (plen)
- *plen++ = '\0';
-
- if (inet_pton (AF_INET6, tmp, &ip_addr) < 1) {
- g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
- _("invalid IPv6 address '%s'"), tmp);
- goto finish;
- }
-
- prefix = 128;
- if (plen) {
- if (!nmc_string_to_int (plen, TRUE, 1, 128, &prefix)) {
- g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
- _("invalid prefix '%s'; <1-128> allowed"), plen);
- goto finish;
- }
- }
-
- if (inet_pton (AF_INET6, gw_str ? gw_str : "::", &gw_addr) < 1) {
- g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
- _("invalid gateway '%s'"), gw_str);
- goto finish;
- }
-
- addr = nm_ip6_address_new ();
- nm_ip6_address_set_address (addr, &ip_addr);
- nm_ip6_address_set_prefix (addr, (guint32) prefix);
- nm_ip6_address_set_gateway (addr, &gw_addr);
-
-finish:
- g_free (tmp);
- return addr;
-}
-
-typedef struct {
- long int prefix;
- long int metric;
- union _IpDest {
- guint32 ip4_dst;
- struct in6_addr ip6_dst;
- } dst;
- union _IpNextHop {
- guint32 ip4_nh;
- struct in6_addr ip6_nh;
- } nh;
-} ParsedRoute;
-
-/*
- * _parse_and_build_route:
+ * nmc_parse_and_build_route:
* @family: AF_INET or AF_INET6
* @first: the route destination in the form of "address/prefix"
(/prefix is optional)
* @second: (allow-none): next hop address, if third is not NULL. Otherwise it could be
either next hop address or metric. (It can be NULL when @third is NULL).
* @third: (allow-none): route metric
- * @out: (out): route struct to fill
* @error: location to store GError
*
- * Parse route from strings and fill @out parameter.
+ * Parse route from strings and return an #NMIPRoute
*
* Returns: %TRUE on success, %FALSE on failure
*/
-static gboolean
-_parse_and_build_route (int family,
- const char *first,
- const char *second,
- const char *third,
- ParsedRoute *out,
- GError **error)
+NMIPRoute *
+nmc_parse_and_build_route (int family,
+ const char *first,
+ const char *second,
+ const char *third,
+ GError **error)
{
- int max_prefix;
- char *tmp, *plen;
+ int max_prefix = (family == AF_INET) ? 32 : 128;
+ char *dest = NULL, *plen = NULL;
+ const char *next_hop = NULL;
+ const char *canon_dest;
+ long int prefix = max_prefix, metric = -1;
+ NMIPRoute *route = NULL;
gboolean success = FALSE;
+ GError *local = NULL;
g_return_val_if_fail (family == AF_INET || family == AF_INET6, FALSE);
g_return_val_if_fail (first != NULL, FALSE);
g_return_val_if_fail (second || !third, FALSE);
- g_return_val_if_fail (out, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- max_prefix = (family == AF_INET) ? 32 : 128;
- /* initialize default values */
- out->prefix = max_prefix;
- out->metric = 0;
- if (family == AF_INET)
- out->nh.ip4_nh = 0;
- else
- out->nh.ip6_nh = in6addr_any;
-
- tmp = g_strdup (first);
- plen = strchr (tmp, '/'); /* prefix delimiter */
+ dest = g_strdup (first);
+ plen = strchr (dest, '/'); /* prefix delimiter */
if (plen)
*plen++ = '\0';
- if (inet_pton (family, tmp, family == AF_INET ? (void *) &out->dst.ip4_dst : (void *) &out->dst.ip6_dst) < 1) {
- g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
- _("invalid route destination address '%s'"), tmp);
- goto finish;
- }
-
if (plen) {
- if (!nmc_string_to_int (plen, TRUE, 1, max_prefix, &out->prefix)) {
+ if (!nmc_string_to_int (plen, TRUE, 1, max_prefix, &prefix)) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("invalid prefix '%s'; <1-%d> allowed"),
plen, max_prefix);
@@ -532,113 +442,49 @@ _parse_and_build_route (int family,
}
if (second) {
- if (inet_pton (family, second, family == AF_INET ? (void *) &out->nh.ip4_nh : (void *) &out->nh.ip6_nh) < 1) {
- if (third) {
- g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
- _("invalid next hop address '%s'"), second);
+ if (third || nm_utils_ipaddr_valid (family, second))
+ next_hop = second;
+ else {
+ /* 'second' can be a metric */
+ if (!nmc_string_to_int (second, TRUE, 0, G_MAXUINT32, &metric)) {
+ g_set_error (error, 1, 0, _("the second component of route ('%s') is neither "
+ "a next hop address nor a metric"), second);
goto finish;
- } else {
- /* 'second' can be a metric */
- if (!nmc_string_to_int (second, TRUE, 0, G_MAXUINT32, &out->metric)) {
- g_set_error (error, 1, 0, _("the second component of route ('%s') is neither "
- "a next hop address nor a metric"), second);
- goto finish;
- }
}
}
}
if (third) {
- if (!nmc_string_to_int (third, TRUE, 0, G_MAXUINT32, &out->metric)) {
+ if (!nmc_string_to_int (third, TRUE, 0, G_MAXUINT32, &metric)) {
g_set_error (error, 1, 0, _("invalid metric '%s'"), third);
goto finish;
}
}
- /* We don't accept default routes as NetworkManager handles it itself */
- if ( (family == AF_INET && out->dst.ip4_dst == 0)
- || (family == AF_INET6 && IN6_IS_ADDR_UNSPECIFIED (&out->dst.ip6_dst))) {
+ route = nm_ip_route_new (family, dest, prefix, next_hop, metric, &local);
+ if (!route) {
+ g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
+ _("invalid route: %s"), local->message);
+ g_clear_error (&local);
+ goto finish;
+ }
+
+ /* We don't accept default routes as NetworkManager handles it
+ * itself. But we have to check this after @route has normalized the
+ * dest string.
+ */
+ canon_dest = nm_ip_route_get_dest (route);
+ if (!strcmp (canon_dest, "0.0.0.0") || !strcmp (canon_dest, "::")) {
g_set_error_literal (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("default route cannot be added (NetworkManager handles it by itself)"));
+ g_clear_pointer (&route, nm_ip_route_unref);
goto finish;
}
success = TRUE;
finish:
- g_free (tmp);
- return success;
-}
-
-/*
- * nmc_parse_and_build_ip4_route:
- * @first: the IPv4 route destination in the form of "address/prefix"
- (/prefix is optional)
- * @second: (allow-none): next hop address, if third is not NULL. Otherwise it could be
- either next hop address or metric. (It can be NULL when @third is NULL).
- * @third: (allow-none): route metric
- * @error: location to store GError
- *
- * Parse IPv4 route from strings to NMIP4Route stucture.
- *
- * Returns: route as a NMIP4Route object, or %NULL on failure
- */
-NMIP4Route *
-nmc_parse_and_build_ip4_route (const char *first,
- const char *second,
- const char *third,
- GError **error)
-{
- ParsedRoute tmp_route;
- NMIP4Route *route = NULL;
-
- g_return_val_if_fail (first != NULL, NULL);
- g_return_val_if_fail (second || !third, NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
-
- if (_parse_and_build_route (AF_INET, first, second, third, &tmp_route, error)) {
- route = nm_ip4_route_new ();
- nm_ip4_route_set_dest (route, tmp_route.dst.ip4_dst);
- nm_ip4_route_set_prefix (route, (guint32) tmp_route.prefix);
- nm_ip4_route_set_next_hop (route, tmp_route.nh.ip4_nh);
- nm_ip4_route_set_metric (route, (guint32) tmp_route.metric);
- }
- return route;
-}
-
-/*
- * nmc_parse_and_build_ip6_route:
- * @first: the IPv6 route destination in the form of "address/prefix"
- (/prefix is optional)
- * @second: (allow-none): next hop address, if third is not NULL. Otherwise it could be
- either next hop address or metric. (It can be NULL when @third is NULL).
- * @third: (allow-none): route metric
- * @error: location to store GError
- *
- * Parse IPv6 route from strings to NMIP6Route stucture.
- *
- * Returns: route as a NMIP6Route object, or %NULL on failure
- */
-NMIP6Route *
-nmc_parse_and_build_ip6_route (const char *first,
- const char *second,
- const char *third,
- GError **error)
-{
- ParsedRoute tmp_route;
- NMIP6Route *route = NULL;
-
- g_return_val_if_fail (first != NULL, NULL);
- g_return_val_if_fail (second || !third, NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
-
- if (_parse_and_build_route (AF_INET6, first, second, third, &tmp_route, error)) {
- route = nm_ip6_route_new ();
- nm_ip6_route_set_dest (route, &tmp_route.dst.ip6_dst);
- nm_ip6_route_set_prefix (route, (guint32) tmp_route.prefix);
- nm_ip6_route_set_next_hop (route, &tmp_route.nh.ip6_nh);
- nm_ip6_route_set_metric (route, (guint32) tmp_route.metric);
- }
+ g_free (dest);
return route;
}
diff --git a/clients/cli/common.h b/clients/cli/common.h
index 4f43674793..6ae74f4f4a 100644
--- a/clients/cli/common.h
+++ b/clients/cli/common.h
@@ -24,16 +24,13 @@
#include "nmcli.h"
-gboolean print_ip4_config (NMIP4Config *cfg4, NmCli *nmc, const char *group_prefix, const char *one_field);
-gboolean print_ip6_config (NMIP6Config *cfg6, NmCli *nmc, const char *group_prefix, const char *one_field);
-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);
+gboolean print_ip4_config (NMIPConfig *cfg4, NmCli *nmc, const char *group_prefix, const char *one_field);
+gboolean print_ip6_config (NMIPConfig *cfg6, NmCli *nmc, const char *group_prefix, const char *one_field);
+gboolean print_dhcp4_config (NMDhcpConfig *dhcp4, NmCli *nmc, const char *group_prefix, const char *one_field);
+gboolean print_dhcp6_config (NMDhcpConfig *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, 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);
diff --git a/clients/cli/connections.c b/clients/cli/connections.c
index 4d48e2fb60..ae1250aab2 100644
--- a/clients/cli/connections.c
+++ b/clients/cli/connections.c
@@ -35,6 +35,8 @@
#include "common.h"
#include "settings.h"
#include "connections.h"
+#include "nm-secret-agent-simple.h"
+#include "polkit-agent.h"
/* define some prompts for connection editor */
#define EDITOR_PROMPT_SETTING _("Setting name? ")
@@ -250,9 +252,9 @@ usage (void)
"COMMAND := { show | up | down | add | modify | edit | delete | reload | load }\n\n"
" show [--active] [[--show-secrets] [id | uuid | path | apath] <ID>] ...\n\n"
#if WITH_WIMAX
- " up [[id | uuid | path] <ID>] [ifname <ifname>] [ap <BSSID>] [nsp <name>]\n\n"
+ " up [[id | uuid | path] <ID>] [ifname <ifname>] [ap <BSSID>] [nsp <name>] [passwd-file <file with passwords>]\n\n"
#else
- " up [[id | uuid | path] <ID>] [ifname <ifname>] [ap <BSSID>]\n\n"
+ " up [[id | uuid | path] <ID>] [ifname <ifname>] [ap <BSSID>] [passwd-file <file with passwords>]\n\n"
#endif
" down [id | uuid | path | apath] <ID>\n\n"
" add COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS IP_OPTIONS\n\n"
@@ -290,19 +292,20 @@ usage_connection_up (void)
{
g_printerr (_("Usage: nmcli connection up { ARGUMENTS | help }\n"
"\n"
- "ARGUMENTS := [id | uuid | path] <ID> [ifname <ifname>] [ap <BSSID>] [nsp <name>]\n"
+ "ARGUMENTS := [id | uuid | path] <ID> [ifname <ifname>] [ap <BSSID>] [nsp <name>] [passwd-file <file with passwords>]\n"
"\n"
"Activate a connection on a device. The profile to activate is identified by its\n"
"name, UUID or D-Bus path.\n"
"\n"
- "ARGUMENTS := ifname <ifname> [ap <BSSID>] [nsp <name>]\n"
+ "ARGUMENTS := ifname <ifname> [ap <BSSID>] [nsp <name>] [passwd-file <file with passwords>]\n"
"\n"
"Activate a device with a connection. The connection profile is selected\n"
"automatically by NetworkManager.\n"
"\n"
- "ifname - specifies the device to active the connection on\n"
- "ap - specifies AP to connect to (only valid for Wi-Fi)\n"
- "nsp - specifies NSP to connect to (only valid for WiMAX)\n\n"));
+ "ifname - specifies the device to active the connection on\n"
+ "ap - specifies AP to connect to (only valid for Wi-Fi)\n"
+ "nsp - specifies NSP to connect to (only valid for WiMAX)\n"
+ "passwd-file - file with password(s) required to activate the connection\n\n"));
}
static void
@@ -507,6 +510,20 @@ quit (void)
g_main_loop_quit (loop); /* quit main loop */
}
+/* for pre-filling a string to readline prompt */
+static char *pre_input_deftext;
+static int
+set_deftext (void)
+{
+ if (pre_input_deftext && rl_startup_hook) {
+ rl_insert_text (pre_input_deftext);
+ g_free (pre_input_deftext);
+ pre_input_deftext = NULL;
+ rl_startup_hook = NULL;
+ }
+ return 0;
+}
+
static const char *
construct_header_name (const char *base, const char *spec)
{
@@ -1111,7 +1128,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc)
/* IP4 */
if (strcasecmp (nmc_fields_con_active_details_groups[group_idx].name, nmc_fields_con_active_details_groups[1].name) == 0) {
gboolean b1 = FALSE;
- NMIP4Config *cfg4 = nm_active_connection_get_ip4_config (acon);
+ NMIPConfig *cfg4 = nm_active_connection_get_ip4_config (acon);
b1 = print_ip4_config (cfg4, nmc, "IP4", group_fld);
was_output = was_output || b1;
@@ -1120,7 +1137,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc)
/* DHCP4 */
if (strcasecmp (nmc_fields_con_active_details_groups[group_idx].name, nmc_fields_con_active_details_groups[2].name) == 0) {
gboolean b1 = FALSE;
- NMDhcp4Config *dhcp4 = nm_active_connection_get_dhcp4_config (acon);
+ NMDhcpConfig *dhcp4 = nm_active_connection_get_dhcp4_config (acon);
b1 = print_dhcp4_config (dhcp4, nmc, "DHCP4", group_fld);
was_output = was_output || b1;
@@ -1129,7 +1146,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc)
/* IP6 */
if (strcasecmp (nmc_fields_con_active_details_groups[group_idx].name, nmc_fields_con_active_details_groups[3].name) == 0) {
gboolean b1 = FALSE;
- NMIP6Config *cfg6 = nm_active_connection_get_ip6_config (acon);
+ NMIPConfig *cfg6 = nm_active_connection_get_ip6_config (acon);
b1 = print_ip6_config (cfg6, nmc, "IP6", group_fld);
was_output = was_output || b1;
@@ -1138,7 +1155,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc)
/* DHCP6 */
if (strcasecmp (nmc_fields_con_active_details_groups[group_idx].name, nmc_fields_con_active_details_groups[4].name) == 0) {
gboolean b1 = FALSE;
- NMDhcp6Config *dhcp6 = nm_active_connection_get_dhcp6_config (acon);
+ NMDhcpConfig *dhcp6 = nm_active_connection_get_dhcp6_config (acon);
b1 = print_dhcp6_config (dhcp6, nmc, "DHCP6", group_fld);
was_output = was_output || b1;
@@ -1719,7 +1736,7 @@ device_state_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data)
g_print (_("Connection successfully activated (master waiting for slaves) (D-Bus active path: %s)\n"),
nm_object_get_path (NM_OBJECT (active)));
quit ();
- } else if (ac_state != NM_ACTIVE_CONNECTION_STATE_ACTIVATING) {
+ } else if (active && ac_state != NM_ACTIVE_CONNECTION_STATE_ACTIVATING) {
g_string_printf (nmc->return_text, _("Error: Connection activation failed."));
nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION;
quit ();
@@ -1926,16 +1943,174 @@ activate_connection_cb (GObject *client, GAsyncResult *result, gpointer user_dat
g_free (info);
}
+/**
+ * parse_passwords:
+ * @passwd_file: file with passwords to parse
+ * @error: location to store error, or %NULL
+ *
+ * Parse passwords given in @passwd_file and insert them into a hash table.
+ * Example of @passwd_file contents:
+ * wifi.psk:tajne heslo
+ * 802-1x.password:krakonos
+ * 802-11-wireless-security:leap-password:my leap password
+ *
+ * Returns: hash table with parsed passwords, or %NULL on an error
+ */
+static GHashTable *
+parse_passwords (const char *passwd_file, GError **error)
+{
+ GHashTable *pwds_hash;
+ char *contents = NULL;
+ gsize len = 0;
+ GError *local_err = NULL;
+ char **lines, **iter;
+ char *pwd_spec, *pwd, *prop;
+ const char *setting;
+
+ pwds_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+
+ if (!passwd_file)
+ return pwds_hash;
+
+ /* Read the passwords file */
+ if (!g_file_get_contents (passwd_file, &contents, &len, &local_err)) {
+ g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
+ _("failed to read passwd-file '%s': %s"),
+ passwd_file, local_err->message);
+ g_error_free (local_err);
+ g_hash_table_destroy (pwds_hash);
+ return NULL;
+ }
+
+ lines = nmc_strsplit_set (contents, "\r\n", -1);
+ for (iter = lines; *iter; iter++) {
+ pwd = strchr (*iter, ':');
+ if (!pwd) {
+ g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
+ _("missing colon in 'password' entry '%s'"), *iter);
+ goto failure;
+ }
+ *(pwd++) = '\0';
+
+ prop = strchr (*iter, '.');
+ if (!prop) {
+ g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
+ _("missing dot in 'password' entry '%s'"), *iter);
+ goto failure;
+ }
+ *(prop++) = '\0';
+
+ setting = *iter;
+ while (g_ascii_isspace (*setting))
+ setting++;
+ /* Accept wifi-sec or wifi instead of cumbersome '802-11-wireless-security' */
+ if (!strcmp (setting, "wifi-sec") || !strcmp (setting, "wifi"))
+ setting = NM_SETTING_WIRELESS_SECURITY_SETTING_NAME;
+ if (nm_setting_lookup_type (setting) == G_TYPE_INVALID) {
+ g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
+ _("invalid setting name in 'password' entry '%s'"), setting);
+ goto failure;
+ }
+
+ pwd_spec = g_strdup_printf ("%s.%s", setting, prop);
+ g_hash_table_insert (pwds_hash, pwd_spec, g_strdup (pwd));
+ }
+ g_strfreev (lines);
+ g_free (contents);
+ return pwds_hash;
+
+failure:
+ g_strfreev (lines);
+ g_free (contents);
+ g_hash_table_destroy (pwds_hash);
+ return NULL;
+}
+
+static gboolean
+get_secrets_from_user (const char *request_id,
+ const char *title,
+ const char *msg,
+ gboolean ask,
+ GHashTable *pwds_hash,
+ GPtrArray *secrets)
+{
+ int i;
+
+ for (i = 0; i < secrets->len; i++) {
+ NMSecretAgentSimpleSecret *secret = secrets->pdata[i];
+ char *pwd = NULL;
+
+ /* First try to find the password in provided passwords file,
+ * then ask user. */
+ if (pwds_hash && (pwd = g_hash_table_lookup (pwds_hash, secret->prop_name))) {
+ pwd = g_strdup (pwd);
+ } else {
+ g_print ("%s\n", msg);
+ if (ask) {
+ if (secret->value) {
+ /* Prefill the password if we have it. */
+ rl_startup_hook = set_deftext;
+ pre_input_deftext = g_strdup (secret->value);
+ }
+ pwd = nmc_readline ("%s (%s): ", secret->name, secret->prop_name);
+ if (!pwd)
+ pwd = g_strdup ("");
+ } else {
+ g_printerr (_("Warning: password for '%s' not given in 'passwd-file' "
+ "and nmcli cannot ask without '--ask' option.\n"),
+ secret->prop_name);
+ }
+ }
+ /* No password provided, cancel the secrets. */
+ if (!pwd)
+ return FALSE;
+ g_free (secret->value);
+ secret->value = pwd;
+ }
+ return TRUE;
+}
+
+static void
+secrets_requested (NMSecretAgentSimple *agent,
+ const char *request_id,
+ const char *title,
+ const char *msg,
+ GPtrArray *secrets,
+ gpointer user_data)
+{
+ NmCli *nmc = (NmCli *) user_data;
+ gboolean success = FALSE;
+
+ if (nmc->print_output == NMC_PRINT_PRETTY)
+ nmc_terminal_erase_line ();
+
+ success = get_secrets_from_user (request_id, title, msg, nmc->in_editor || nmc->ask,
+ nmc->pwds_hash, secrets);
+ if (success)
+ nm_secret_agent_simple_response (agent, request_id, secrets);
+ else {
+ /* Unregister our secret agent on failure, so that another agent
+ * may be tried */
+ if (nmc->secret_agent) {
+ nm_secret_agent_unregister (nmc->secret_agent, NULL, NULL);
+ g_clear_object (&nmc->secret_agent);
+ }
+ }
+}
+
static gboolean
nmc_activate_connection (NmCli *nmc,
NMConnection *connection,
const char *ifname,
const char *ap,
const char *nsp,
+ const char *pwds,
GAsyncReadyCallback callback,
GError **error)
{
ActivateConnectionInfo *info;
+
+ GHashTable *pwds_hash;
NMDevice *device = NULL;
const char *spec_object = NULL;
gboolean device_found;
@@ -1954,6 +2129,7 @@ nmc_activate_connection (NmCli *nmc,
g_clear_error (&local);
return FALSE;
}
+ g_clear_error (&local);
} else if (ifname) {
device = nm_client_get_device_by_iface (nmc->client, ifname);
if (!device) {
@@ -1967,6 +2143,21 @@ nmc_activate_connection (NmCli *nmc,
return FALSE;
}
+ /* Parse passwords given in passwords file */
+ pwds_hash = parse_passwords (pwds, &local);
+ if (local) {
+ g_propagate_error (error, local);
+ return FALSE;
+ }
+ if (nmc->pwds_hash)
+ g_hash_table_destroy (nmc->pwds_hash);
+ nmc->pwds_hash = pwds_hash;
+
+ /* Create secret agent */
+ nmc->secret_agent = nm_secret_agent_simple_new ("nmcli-connect", nm_object_get_path (NM_OBJECT (connection)));
+ if (nmc->secret_agent)
+ g_signal_connect (nmc->secret_agent, "request-secrets", G_CALLBACK (secrets_requested), nmc);
+
info = g_malloc0 (sizeof (ActivateConnectionInfo));
info->nmc = nmc;
info->device = device;
@@ -1988,6 +2179,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
const char *ifname = NULL;
const char *ap = NULL;
const char *nsp = NULL;
+ const char *pwds = NULL;
GError *error = NULL;
const char *selector = NULL;
const char *name = NULL;
@@ -2055,6 +2247,15 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
nsp = *argv;
}
#endif
+ else if (strcmp (*argv, "passwd-file") == 0) {
+ if (next_arg (&argc, &argv) != 0) {
+ g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
+ nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
+ goto error;
+ }
+
+ pwds = *argv;
+ }
else {
g_printerr (_("Unknown parameter: %s\n"), *argv);
}
@@ -2070,7 +2271,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
nmc->nowait_flag = (nmc->timeout == 0);
nmc->should_wait = TRUE;
- if (!nmc_activate_connection (nmc, connection, ifname, ap, nsp, activate_connection_cb, &error)) {
+ if (!nmc_activate_connection (nmc, connection, ifname, ap, nsp, pwds, activate_connection_cb, &error)) {
g_string_printf (nmc->return_text, _("Error: %s."),
error ? error->message : _("unknown error"));
nmc->return_value = error ? error->code : NMC_RESULT_ERROR_CON_ACTIVATION;
@@ -2688,9 +2889,9 @@ 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;
+ NMSettingIPConfig *s_ip4;
gboolean ret;
if (!ip4addr)
@@ -2698,22 +2899,22 @@ add_ip4_address_to_connection (NMIP4Address *ip4addr, NMConnection *connection)
s_ip4 = nm_connection_get_setting_ip4_config (connection);
if (!s_ip4) {
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
NULL);
}
- ret = nm_setting_ip4_config_add_address (s_ip4, ip4addr);
- nm_ip4_address_unref (ip4addr);
+ ret = nm_setting_ip_config_add_address (s_ip4, 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;
+ NMSettingIPConfig *s_ip6;
gboolean ret;
if (!ip6addr)
@@ -2721,14 +2922,14 @@ add_ip6_address_to_connection (NMIP6Address *ip6addr, NMConnection *connection)
s_ip6 = nm_connection_get_setting_ip6_config (connection);
if (!s_ip6) {
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL,
NULL);
}
- ret = nm_setting_ip6_config_add_address (s_ip6, ip6addr);
- nm_ip6_address_unref (ip6addr);
+ ret = nm_setting_ip_config_add_address (s_ip6, ip6addr);
+ nm_ip_address_unref (ip6addr);
return ret;
}
@@ -3612,24 +3813,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;
}
@@ -3639,35 +3837,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;
- gpointer ipaddr;
+ NMIPAddress *ipaddr;
- if (family == 4)
- prompt =_("IPv4 address (IP[/plen] [gateway]) [none]: ");
+ if (family == AF_INET)
+ 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) {
- 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, &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);
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 {
@@ -3683,6 +3877,45 @@ ask_for_ip_addresses (NMConnection *connection, int family)
}
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)
{
char *answer;
@@ -3694,14 +3927,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, 4);
- ask_for_ip_addresses (connection, 6);
-
- g_free (answer);
- return;
+ ask_for_ip_addresses (connection, AF_INET);
+ maybe_ask_for_gateway (connection, AF_INET);
+ ask_for_ip_addresses (connection, AF_INET6);
+ maybe_ask_for_gateway (connection, AF_INET6);
}
static gboolean
@@ -4952,8 +5185,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},
@@ -4973,7 +5205,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, error);
if (!ip4addr) {
g_prefix_error (error, _("Error: "));
return FALSE;
@@ -4981,15 +5213,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_ip6_address (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. */
@@ -5426,19 +5702,6 @@ uuid_display_hook (char **array, int len, int max_len)
rl_forced_update_display ();
}
-static char *pre_input_deftext;
-static int
-set_deftext (void)
-{
- if (pre_input_deftext && rl_startup_hook) {
- rl_insert_text (pre_input_deftext);
- g_free (pre_input_deftext);
- pre_input_deftext = NULL;
- rl_startup_hook = NULL;
- }
- return 0;
-}
-
static char *
gen_nmcli_cmds_menu (const char *text, int state)
{
@@ -7654,7 +7917,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
nmc->nowait_flag = FALSE;
nmc->should_wait = TRUE;
nmc->print_output = NMC_PRINT_PRETTY;
- if (!nmc_activate_connection (nmc, NM_CONNECTION (rem_con), ifname, ap_nsp, ap_nsp,
+ if (!nmc_activate_connection (nmc, NM_CONNECTION (rem_con), ifname, ap_nsp, ap_nsp, NULL,
activate_connection_editor_cb, &tmp_err)) {
g_print (_("Error: Cannot activate connection: %s.\n"), tmp_err->message);
g_clear_error (&tmp_err);
@@ -7925,8 +8188,7 @@ editor_init_new_connection (NmCli *nmc, NMConnection *connection)
static void
editor_init_existing_connection (NMConnection *connection)
{
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4, *s_ip6;
NMSettingWireless *s_wireless;
NMSettingConnection *s_con;
@@ -8611,6 +8873,9 @@ do_connections (NmCli *nmc, int argc, char **argv)
{
GError *error = NULL;
+ /* Register polkit agent */
+ nmc_start_polkit_agent_start_try (nmc);
+
/* Set completion function for 'nmcli con' */
rl_attempted_completion_function = (rl_completion_func_t *) nmcli_con_tab_completion;
diff --git a/clients/cli/devices.c b/clients/cli/devices.c
index 3d9598fb41..3703743957 100644
--- a/clients/cli/devices.c
+++ b/clients/cli/devices.c
@@ -28,6 +28,7 @@
#include <glib.h>
#include <glib/gi18n.h>
+#include "polkit-agent.h"
#include "utils.h"
#include "common.h"
#include "devices.h"
@@ -766,10 +767,8 @@ show_device_info (NMDevice *device, NmCli *nmc)
NmcOutputField *tmpl, *arr;
size_t tmpl_len;
gboolean was_output = FALSE;
- NMIP4Config *cfg4;
- NMIP6Config *cfg6;
- NMDhcp4Config *dhcp4;
- NMDhcp6Config *dhcp6;
+ NMIPConfig *cfg4, *cfg6;
+ NMDhcpConfig *dhcp4, *dhcp6;
const char *base_hdr = _("Device details");
GPtrArray *fields_in_section = NULL;
@@ -1599,18 +1598,29 @@ error:
static void
disconnect_state_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data)
{
- NmCli *nmc = (NmCli *) user_data;
NMDeviceState state;
state = nm_device_get_state (device);
if (state == NM_DEVICE_STATE_DISCONNECTED) {
- g_string_printf (nmc->return_text, _("Success: Device '%s' successfully disconnected."), nm_device_get_iface (device));
+ g_signal_handlers_disconnect_by_data (device, user_data);
+ g_print (_("Device '%s' successfully disconnected.\n"),
+ nm_device_get_iface (device));
quit ();
}
}
static void
+device_removed_cb (NMClient *client, NMDevice *device, gpointer user_data)
+{
+ /* Success: device has been removed. It happens when disconnecting a software device. */
+ g_signal_handlers_disconnect_by_data (client, user_data);
+ g_print (_("Device '%s' successfully disconnected.\n"),
+ nm_device_get_iface (device));
+ quit ();
+}
+
+static void
disconnect_device_cb (GObject *object, GAsyncResult *result, gpointer user_data)
{
NMDevice *device = NM_DEVICE (object);
@@ -1639,6 +1649,7 @@ disconnect_device_cb (GObject *object, GAsyncResult *result, gpointer user_data)
quit ();
} else {
g_signal_connect (device, "notify::state", G_CALLBACK (disconnect_state_cb), nmc);
+ g_signal_connect (nmc->client, NM_CLIENT_DEVICE_REMOVED, G_CALLBACK (device_removed_cb), nmc);
/* Start timer not to loop forever if "notify::state" signal is not issued */
g_timeout_add_seconds (nmc->timeout, timeout_cb, nmc);
}
@@ -2776,6 +2787,9 @@ do_devices (NmCli *nmc, int argc, char **argv)
{
GError *error = NULL;
+ /* Register polkit agent */
+ nmc_start_polkit_agent_start_try (nmc);
+
rl_attempted_completion_function = (rl_completion_func_t *) nmcli_device_tab_completion;
/* Get NMClient object early */
diff --git a/clients/cli/general.c b/clients/cli/general.c
index 531d4f7acd..44c63c356c 100644
--- a/clients/cli/general.c
+++ b/clients/cli/general.c
@@ -25,6 +25,7 @@
#include <glib.h>
#include <glib/gi18n.h>
+#include "polkit-agent.h"
#include "utils.h"
#include "general.h"
@@ -558,6 +559,9 @@ do_general (NmCli *nmc, int argc, char **argv)
{
GError *error = NULL;
+ /* Register polkit agent */
+ nmc_start_polkit_agent_start_try (nmc);
+
if (argc == 0) {
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error)) {
g_string_printf (nmc->return_text, _("Error: %s."), error->message);
@@ -726,6 +730,9 @@ do_networking (NmCli *nmc, int argc, char **argv)
{
gboolean enable_flag;
+ /* Register polkit agent */
+ nmc_start_polkit_agent_start_try (nmc);
+
if (argc == 0)
nmc_switch_show (nmc, NMC_FIELDS_NM_NETWORKING, _("Networking"));
else if (argc > 0) {
@@ -787,6 +794,9 @@ do_radio (NmCli *nmc, int argc, char **argv)
GError *error = NULL;
gboolean enable_flag;
+ /* Register polkit agent */
+ nmc_start_polkit_agent_start_try (nmc);
+
if (argc == 0) {
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error)) {
g_string_printf (nmc->return_text, _("Error: %s."), error->message);
diff --git a/clients/cli/nmcli-completion b/clients/cli/nmcli-completion
index a9dfc41774..72648d43cb 100644
--- a/clients/cli/nmcli-completion
+++ b/clients/cli/nmcli-completion
@@ -502,7 +502,8 @@ _nmcli_compl_ARGS()
user| \
username| \
service| \
- password)
+ password| \
+ passwd-file)
if [[ "${#words[@]}" -eq 2 ]]; then
return 0
fi
@@ -700,7 +701,7 @@ _nmcli()
# (if the current word starts with a dash) or the OBJECT list
# otherwise.
if [[ "${words[0]:0:1}" != '-' ]]; then
- OPTIONS=(help general networking radio connection device)
+ OPTIONS=(help general networking radio connection device agent)
elif [[ "${words[0]:1:1}" == '-' || "${words[0]}" == "-" ]]; then
OPTIONS=("${LONG_OPTIONS[@]/#/--}")
else
@@ -845,9 +846,9 @@ _nmcli()
_nmcli_compl_ARGS_CONNECTION && return 0
if [[ "$COMMAND_CONNECTION_TYPE" = "ifname" ]]; then
- OPTIONS=(ap nsp)
+ OPTIONS=(ap nsp passwd-file)
else
- OPTIONS=(ifname ap nsp)
+ OPTIONS=(ifname ap nsp passwd-file)
fi
_nmcli_compl_ARGS
fi
@@ -1267,6 +1268,11 @@ _nmcli()
esac
fi
;;
+ a|ag|age|agen|agent)
+ if [[ ${#words[@]} -eq 2 ]]; then
+ _nmcli_compl_COMMAND "$command" secret polkit all
+ fi
+ ;;
esac
return 0
diff --git a/clients/cli/nmcli.c b/clients/cli/nmcli.c
index b1a810ce7a..ade0a6bd4d 100644
--- a/clients/cli/nmcli.c
+++ b/clients/cli/nmcli.c
@@ -27,6 +27,8 @@
#include <stdlib.h>
#include <signal.h>
#include <pthread.h>
+#include <termios.h>
+#include <unistd.h>
#include <locale.h>
#include <readline/readline.h>
#include <readline/history.h>
@@ -34,12 +36,14 @@
#include <glib.h>
#include <glib/gi18n.h>
+#include "polkit-agent.h"
#include "nmcli.h"
#include "utils.h"
#include "common.h"
#include "connections.h"
#include "devices.h"
#include "general.h"
+#include "agent.h"
#if defined(NM_DIST_VERSION)
# define NMCLI_VERSION NM_DIST_VERSION
@@ -61,6 +65,7 @@ typedef struct {
/* --- Global variables --- */
GMainLoop *loop = NULL;
static sigset_t signal_set;
+struct termios termios_orig;
/* Get an error quark for use with GError */
@@ -98,6 +103,7 @@ usage (const char *prog_name)
" r[adio] NetworkManager radio switches\n"
" c[onnection] NetworkManager's connections\n"
" d[evice] devices managed by NetworkManager\n"
+ " a[gent] NetworkManager secret agent or polkit agent\n"
"\n"),
prog_name);
}
@@ -118,6 +124,7 @@ static const struct cmd {
{ "radio", do_radio },
{ "connection", do_connections },
{ "device", do_devices },
+ { "agent", do_agent },
{ "help", do_help },
{ 0 }
};
@@ -261,8 +268,10 @@ parse_command_line (NmCli *nmc, int argc, char **argv)
argv++;
}
- if (argc > 1)
+ if (argc > 1) {
+ /* Now run the requested command */
return do_cmd (nmc, argv[1], argc-1, argv+1);
+ }
usage (base);
return nmc->return_value;
@@ -332,6 +341,7 @@ signal_handling_thread (void *arg) {
pthread_mutex_unlock (&sigint_mutex);
} else {
/* We can quit nmcli */
+ tcsetattr (STDIN_FILENO, TCSADRAIN, &termios_orig);
nmc_cleanup_readline ();
g_print (_("\nError: nmcli terminated by signal %s (%d)\n"),
strsignal (signo), signo);
@@ -340,6 +350,7 @@ signal_handling_thread (void *arg) {
break;
case SIGQUIT:
case SIGTERM:
+ tcsetattr (STDIN_FILENO, TCSADRAIN, &termios_orig);
nmc_cleanup_readline ();
if (!nmcli_sigquit_internal)
g_print (_("\nError: nmcli terminated by signal %s (%d)\n"),
@@ -500,6 +511,10 @@ nmc_init (NmCli *nmc)
nmc->connections = NULL;
+ nmc->secret_agent = NULL;
+ nmc->pwds_hash = NULL;
+ nmc->pk_listener = NULL;
+
nmc->should_wait = FALSE;
nmc->nowait_flag = TRUE;
nmc->print_output = NMC_PRINT_NORMAL;
@@ -525,9 +540,19 @@ nmc_cleanup (NmCli *nmc)
g_string_free (nmc->return_text, TRUE);
+ if (nmc->secret_agent) {
+ /* Destroy secret agent if we have one. */
+ nm_secret_agent_unregister (nmc->secret_agent, NULL, NULL);
+ g_object_unref (nmc->secret_agent);
+ }
+ if (nmc->pwds_hash)
+ g_hash_table_destroy (nmc->pwds_hash);
+
g_free (nmc->required_fields);
nmc_empty_output_fields (nmc);
g_ptr_array_unref (nmc->output_data);
+
+ nmc_polkit_agent_fini (nmc);
}
static gboolean
@@ -565,6 +590,9 @@ main (int argc, char *argv[])
#if !GLIB_CHECK_VERSION (2, 35, 0)
g_type_init ();
#endif
+
+ /* Save terminal settings */
+ tcgetattr (STDIN_FILENO, &termios_orig);
/* readline init */
rl_event_hook = event_hook_for_readline;
diff --git a/clients/cli/nmcli.h b/clients/cli/nmcli.h
index 0a87bd9147..5cd7526a8d 100644
--- a/clients/cli/nmcli.h
+++ b/clients/cli/nmcli.h
@@ -20,8 +20,17 @@
#ifndef NMC_NMCLI_H
#define NMC_NMCLI_H
+#include "config.h"
+
#include <NetworkManager.h>
+#if WITH_POLKIT_AGENT
+#include "nm-polkit-listener.h"
+#else
+/* polkit agent is not available; define fake NMPolkitListener */
+typedef gpointer NMPolkitListener;
+#endif
+
/* nmcli exit codes */
typedef enum {
/* Indicates successful execution */
@@ -112,6 +121,10 @@ typedef struct _NmCli {
const GPtrArray *connections; /* List of connections */
+ NMSecretAgent *secret_agent; /* Secret agent */
+ GHashTable *pwds_hash; /* Hash table with passwords in passwd-file */
+ NMPolkitListener *pk_listener ; /* polkit agent listener */
+
gboolean should_wait; /* Indication that nmcli should not end yet */
gboolean nowait_flag; /* '--nowait' option; used for passing to callbacks */
NMCPrintOutput print_output; /* Output mode */
diff --git a/clients/cli/polkit-agent.c b/clients/cli/polkit-agent.c
new file mode 100644
index 0000000000..a163b824fa
--- /dev/null
+++ b/clients/cli/polkit-agent.c
@@ -0,0 +1,166 @@
+/* nmcli - command-line tool to control NetworkManager
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2014 Red Hat, Inc.
+ */
+
+#include "config.h"
+
+#if WITH_POLKIT_AGENT
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <termios.h>
+
+#include <glib.h>
+#include <glib/gi18n-lib.h>
+
+#include "polkit-agent.h"
+#include "nm-polkit-listener.h"
+#include "common.h"
+
+static char *
+polkit_request (const char *request,
+ const char *action_id,
+ const char *message,
+ const char *icon_name,
+ const char *user,
+ gboolean echo_on,
+ gpointer user_data)
+{
+ char *response, *tmp, *p;
+ struct termios termios_orig, termios_new;
+
+ g_print ("%s\n", message);
+ g_print ("(action_id: %s)\n", action_id);
+
+ if (!echo_on) {
+ tcgetattr (STDIN_FILENO, &termios_orig);
+ termios_new = termios_orig;
+ termios_new.c_lflag &= ~(ECHO);
+ tcsetattr (STDIN_FILENO, TCSADRAIN, &termios_new);
+ }
+
+ /* Ask user for polkit authorization password */
+ if (user) {
+ /* chop of ": " if present */
+ tmp = g_strdup (request);
+ p = strrchr (tmp, ':');
+ if (p && !strcmp (p, ": "))
+ *p = '\0';
+ response = nmc_readline ("%s (%s): ", tmp, user);
+ g_free (tmp);
+ } else
+ response = nmc_readline ("%s", request);
+ g_print ("\n");
+
+ /* Restore original terminal settings */
+ if (!echo_on)
+ tcsetattr (STDIN_FILENO, TCSADRAIN, &termios_orig);
+
+ return response;
+}
+
+static void
+polkit_show_info (const char *text)
+{
+ g_print (_("Authentication message: %s\n"), text);
+}
+
+static void
+polkit_show_error (const char *text)
+{
+ g_print (_("Authentication error: %s\n"), text);
+}
+
+static void
+polkit_completed (gboolean gained_authorization)
+{
+ /* We don't print anything here. The outcome will be evident from
+ * the operation result anyway. */
+}
+
+gboolean
+nmc_polkit_agent_init (NmCli* nmc, gboolean for_session, GError **error)
+{
+ PolkitAgentListener *listener;
+
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ listener = nm_polkit_listener_new (for_session, error);
+ if (!listener)
+ return FALSE;
+
+ nm_polkit_listener_set_request_callback (NM_POLKIT_LISTENER (listener), polkit_request, nmc);
+ nm_polkit_listener_set_show_info_callback (NM_POLKIT_LISTENER (listener), polkit_show_info);
+ nm_polkit_listener_set_show_error_callback (NM_POLKIT_LISTENER (listener), polkit_show_error);
+ nm_polkit_listener_set_completed_callback (NM_POLKIT_LISTENER (listener), polkit_completed);
+
+ nmc->pk_listener = NM_POLKIT_LISTENER (listener);
+ return TRUE;
+}
+
+void
+nmc_polkit_agent_fini (NmCli* nmc)
+{
+ g_clear_object (&nmc->pk_listener);
+}
+
+gboolean
+nmc_start_polkit_agent_start_try (NmCli *nmc)
+{
+ GError *error = NULL;
+
+ /* We don't register polkit agent at all when running non-interactively */
+ if (!nmc->ask)
+ return TRUE;
+
+ if (!nmc_polkit_agent_init (nmc, FALSE, &error)) {
+ g_printerr (_("Warning: polkit agent initialization failed: %s\n"),
+ error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+ return TRUE;
+}
+
+#else
+/* polkit agent is not avalable; implement stub functions. */
+
+#include <glib.h>
+#include "nmcli.h"
+#include "polkit-agent.h"
+
+gboolean
+nmc_polkit_agent_init (NmCli* nmc, gboolean for_session, GError **error)
+{
+ return TRUE;
+}
+
+void
+nmc_polkit_agent_fini (NmCli* nmc)
+{
+}
+
+gboolean
+nmc_start_polkit_agent_start_try (NmCli *nmc)
+{
+ return TRUE;
+}
+
+#endif /* #if WITH_POLKIT_AGENT */
diff --git a/clients/cli/polkit-agent.h b/clients/cli/polkit-agent.h
new file mode 100644
index 0000000000..e2902dc0b1
--- /dev/null
+++ b/clients/cli/polkit-agent.h
@@ -0,0 +1,30 @@
+/* nmcli - command-line tool to control NetworkManager
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2014 Red Hat, Inc.
+ */
+
+#ifndef __NMC_POLKIT_AGENT_H__
+#define __NMC_POLKIT_AGENT_H__
+
+#include "nmcli.h"
+
+gboolean nmc_polkit_agent_init (NmCli *nmc, gboolean for_session, GError **error);
+void nmc_polkit_agent_fini (NmCli* nmc);
+
+gboolean nmc_start_polkit_agent_start_try (NmCli *nmc);
+
+#endif /* __NMC_POLKIT_AGENT_H__ */
diff --git a/clients/cli/settings.c b/clients/cli/settings.c
index 136c818641..dcd4f1cc72 100644
--- a/clients/cli/settings.c
+++ b/clients/cli/settings.c
@@ -20,6 +20,7 @@
#include "config.h"
#include <stdlib.h>
+#include <arpa/inet.h>
#include <glib.h>
#include <glib/gi18n.h>
@@ -251,64 +252,74 @@ NmcOutputField nmc_fields_setting_wireless_security[] = {
/* Available fields for NM_SETTING_IP4_CONFIG_SETTING_NAME */
NmcOutputField nmc_fields_setting_ip4_config[] = {
- SETTING_FIELD ("name", 8), /* 0 */
- SETTING_FIELD (NM_SETTING_IP4_CONFIG_METHOD, 10), /* 1 */
- SETTING_FIELD (NM_SETTING_IP4_CONFIG_DNS, 20), /* 2 */
- SETTING_FIELD (NM_SETTING_IP4_CONFIG_DNS_SEARCH, 15), /* 3 */
- SETTING_FIELD (NM_SETTING_IP4_CONFIG_ADDRESSES, 20), /* 4 */
- SETTING_FIELD (NM_SETTING_IP4_CONFIG_ROUTES, 20), /* 5 */
- SETTING_FIELD (NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES, 19), /* 6 */
- SETTING_FIELD (NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, 16), /* 7 */
- SETTING_FIELD (NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, 15), /* 8 */
- SETTING_FIELD (NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME, 19), /* 9 */
- SETTING_FIELD (NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, 14), /* 10 */
- SETTING_FIELD (NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, 15), /* 11 */
- SETTING_FIELD (NM_SETTING_IP4_CONFIG_MAY_FAIL, 12), /* 12 */
+ SETTING_FIELD ("name", 8), /* 0 */
+ SETTING_FIELD (NM_SETTING_IP_CONFIG_METHOD, 10), /* 1 */
+ 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_GATEWAY, 20), /* 5 */
+ SETTING_FIELD (NM_SETTING_IP_CONFIG_ROUTES, 20), /* 6 */
+ SETTING_FIELD (NM_SETTING_IP_CONFIG_ROUTE_METRIC, 15), /* 7 */
+ SETTING_FIELD (NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, 19), /* 8 */
+ SETTING_FIELD (NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, 16), /* 9 */
+ SETTING_FIELD (NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, 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_NEVER_DEFAULT, 15), /* 13 */
+ SETTING_FIELD (NM_SETTING_IP_CONFIG_MAY_FAIL, 12), /* 14 */
{NULL, NULL, 0, NULL, FALSE, FALSE, 0}
};
#define NMC_FIELDS_SETTING_IP4_CONFIG_ALL "name"","\
- NM_SETTING_IP4_CONFIG_METHOD","\
- NM_SETTING_IP4_CONFIG_DNS","\
- NM_SETTING_IP4_CONFIG_DNS_SEARCH","\
- NM_SETTING_IP4_CONFIG_ADDRESSES","\
- NM_SETTING_IP4_CONFIG_ROUTES","\
- NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES","\
- NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS","\
+ NM_SETTING_IP_CONFIG_METHOD","\
+ 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_ROUTE_METRIC","\
+ NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES","\
+ NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS","\
NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID","\
- NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME","\
- NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME","\
- NM_SETTING_IP4_CONFIG_NEVER_DEFAULT","\
- NM_SETTING_IP4_CONFIG_MAY_FAIL
+ NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME","\
+ NM_SETTING_IP_CONFIG_DHCP_HOSTNAME","\
+ NM_SETTING_IP_CONFIG_NEVER_DEFAULT","\
+ NM_SETTING_IP_CONFIG_MAY_FAIL
#define NMC_FIELDS_SETTING_IP4_CONFIG_COMMON NMC_FIELDS_SETTING_IP4_CONFIG_ALL
/* Available fields for NM_SETTING_IP6_CONFIG_SETTING_NAME */
NmcOutputField nmc_fields_setting_ip6_config[] = {
- SETTING_FIELD ("name", 8), /* 0 */
- SETTING_FIELD (NM_SETTING_IP6_CONFIG_METHOD, 10), /* 1 */
- SETTING_FIELD (NM_SETTING_IP6_CONFIG_DNS, 20), /* 2 */
- SETTING_FIELD (NM_SETTING_IP6_CONFIG_DNS_SEARCH, 15), /* 3 */
- SETTING_FIELD (NM_SETTING_IP6_CONFIG_ADDRESSES, 20), /* 4 */
- SETTING_FIELD (NM_SETTING_IP6_CONFIG_ROUTES, 20), /* 5 */
- SETTING_FIELD (NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES, 19), /* 6 */
- SETTING_FIELD (NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS, 16), /* 7 */
- SETTING_FIELD (NM_SETTING_IP6_CONFIG_NEVER_DEFAULT, 15), /* 8 */
- SETTING_FIELD (NM_SETTING_IP6_CONFIG_MAY_FAIL, 12), /* 9 */
- SETTING_FIELD (NM_SETTING_IP6_CONFIG_IP6_PRIVACY, 15), /* 10 */
- SETTING_FIELD (NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME, 14), /* 11 */
+ SETTING_FIELD ("name", 8), /* 0 */
+ SETTING_FIELD (NM_SETTING_IP_CONFIG_METHOD, 10), /* 1 */
+ 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_GATEWAY, 20), /* 5 */
+ SETTING_FIELD (NM_SETTING_IP_CONFIG_ROUTES, 20), /* 6 */
+ SETTING_FIELD (NM_SETTING_IP_CONFIG_ROUTE_METRIC, 15), /* 7 */
+ SETTING_FIELD (NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, 19), /* 8 */
+ SETTING_FIELD (NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, 16), /* 9 */
+ SETTING_FIELD (NM_SETTING_IP_CONFIG_NEVER_DEFAULT, 15), /* 10 */
+ SETTING_FIELD (NM_SETTING_IP_CONFIG_MAY_FAIL, 12), /* 11 */
+ SETTING_FIELD (NM_SETTING_IP6_CONFIG_IP6_PRIVACY, 15), /* 12 */
+ SETTING_FIELD (NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, 19), /* 13 */
+ SETTING_FIELD (NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, 14), /* 14 */
{NULL, NULL, 0, NULL, FALSE, FALSE, 0}
};
#define NMC_FIELDS_SETTING_IP6_CONFIG_ALL "name"","\
- NM_SETTING_IP6_CONFIG_METHOD","\
- NM_SETTING_IP6_CONFIG_DNS","\
- NM_SETTING_IP6_CONFIG_DNS_SEARCH","\
- NM_SETTING_IP6_CONFIG_ADDRESSES","\
- NM_SETTING_IP6_CONFIG_ROUTES","\
- NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES","\
- NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS","\
- NM_SETTING_IP6_CONFIG_NEVER_DEFAULT","\
- NM_SETTING_IP6_CONFIG_MAY_FAIL","\
+ NM_SETTING_IP_CONFIG_METHOD","\
+ 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_ROUTE_METRIC","\
+ NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES","\
+ NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS","\
+ NM_SETTING_IP_CONFIG_NEVER_DEFAULT","\
+ NM_SETTING_IP_CONFIG_MAY_FAIL","\
NM_SETTING_IP6_CONFIG_IP6_PRIVACY","\
- NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME
+ NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME","\
+ NM_SETTING_IP_CONFIG_DHCP_HOSTNAME
#define NMC_FIELDS_SETTING_IP6_CONFIG_COMMON NMC_FIELDS_SETTING_IP4_CONFIG_ALL
/* Available fields for NM_SETTING_SERIAL_SETTING_NAME */
@@ -1199,41 +1210,30 @@ nmc_property_ib_get_p_key (NMSetting *setting)
DEFINE_GETTER (nmc_property_ib_get_parent, NM_SETTING_INFINIBAND_PARENT)
/* --- NM_SETTING_IP4_CONFIG_SETTING_NAME property get functions --- */
-DEFINE_GETTER (nmc_property_ipv4_get_method, NM_SETTING_IP4_CONFIG_METHOD)
-DEFINE_GETTER (nmc_property_ipv4_get_dns, NM_SETTING_IP4_CONFIG_DNS)
-DEFINE_GETTER (nmc_property_ipv4_get_dns_search, NM_SETTING_IP4_CONFIG_DNS_SEARCH)
+DEFINE_GETTER (nmc_property_ipv4_get_method, NM_SETTING_IP_CONFIG_METHOD)
+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)
{
- NMSettingIP4Config *s_ip4 = NM_SETTING_IP4_CONFIG (setting);
+ NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG (setting);
GString *printable;
guint32 num_addresses, i;
- NMIP4Address *addr;
- char buf[INET_ADDRSTRLEN];
+ NMIPAddress *addr;
printable = g_string_new (NULL);
- num_addresses = nm_setting_ip4_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_ip4_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, "{ ");
-
- nm_utils_inet4_ntop (nm_ip4_address_get_address (addr), buf);
- g_string_append_printf (printable, "ip = %s", buf);
-
- g_string_append_printf (printable, "/%u", nm_ip4_address_get_prefix (addr));
-
- if (nm_ip4_address_get_gateway (addr)) {
- nm_utils_inet4_ntop (nm_ip4_address_get_gateway (addr), buf);
- g_string_append_printf (printable, ", gw = %s", buf);
- }
+ g_string_append (printable, ", ");
- g_string_append (printable, " }");
+ g_string_append_printf (printable, "%s/%u",
+ nm_ip_address_get_address (addr),
+ nm_ip_address_get_prefix (addr));
}
return g_string_free (printable, FALSE);
@@ -1242,35 +1242,33 @@ nmc_property_ipv4_get_addresses (NMSetting *setting)
static char *
nmc_property_ipv4_get_routes (NMSetting *setting)
{
- NMSettingIP4Config *s_ip4 = NM_SETTING_IP4_CONFIG (setting);
+ NMSettingIPConfig *s_ip4 = NM_SETTING_IP_CONFIG (setting);
GString *printable;
guint32 num_routes, i;
- NMIP4Route *route;
- char buf[INET_ADDRSTRLEN];
+ NMIPRoute *route;
printable = g_string_new (NULL);
- num_routes = nm_setting_ip4_config_get_num_routes (s_ip4);
+ num_routes = nm_setting_ip_config_get_num_routes (s_ip4);
for (i = 0; i < num_routes; i++) {
- route = nm_setting_ip4_config_get_route (s_ip4, i);
+ route = nm_setting_ip_config_get_route (s_ip4, i);
if (printable->len > 0)
g_string_append (printable, "; ");
g_string_append (printable, "{ ");
- nm_utils_inet4_ntop (nm_ip4_route_get_dest (route), buf);
- g_string_append_printf (printable, "ip = %s", buf);
-
- g_string_append_printf (printable, "/%u", nm_ip4_route_get_prefix (route));
+ g_string_append_printf (printable, "ip = %s/%u",
+ nm_ip_route_get_dest (route),
+ nm_ip_route_get_prefix (route));
- if (nm_ip4_route_get_next_hop (route)) {
- nm_utils_inet4_ntop (nm_ip4_route_get_next_hop (route), buf);
- g_string_append_printf (printable, ", nh = %s", buf);
+ if (nm_ip_route_get_next_hop (route)) {
+ g_string_append_printf (printable, ", nh = %s",
+ nm_ip_route_get_next_hop (route));
}
- if (nm_ip4_route_get_metric (route))
- g_string_append_printf (printable, ", mt = %u", nm_ip4_route_get_metric (route));
+ if (nm_ip_route_get_metric (route) != -1)
+ g_string_append_printf (printable, ", mt = %u", (guint32) nm_ip_route_get_metric (route));
g_string_append (printable, " }");
}
@@ -1278,87 +1276,51 @@ nmc_property_ipv4_get_routes (NMSetting *setting)
return g_string_free (printable, FALSE);
}
-DEFINE_GETTER (nmc_property_ipv4_get_ignore_auto_routes, NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES)
-DEFINE_GETTER (nmc_property_ipv4_get_ignore_auto_dns, NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS)
+DEFINE_GETTER (nmc_property_ipv4_get_gateway, NM_SETTING_IP_CONFIG_GATEWAY)
+DEFINE_GETTER (nmc_property_ipv4_get_route_metric, NM_SETTING_IP_CONFIG_ROUTE_METRIC)
+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)
-DEFINE_GETTER (nmc_property_ipv4_get_dhcp_send_hostname, NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME)
-DEFINE_GETTER (nmc_property_ipv4_get_dhcp_hostname, NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME)
-DEFINE_GETTER (nmc_property_ipv4_get_never_default, NM_SETTING_IP4_CONFIG_NEVER_DEFAULT)
-DEFINE_GETTER (nmc_property_ipv4_get_may_fail, NM_SETTING_IP4_CONFIG_MAY_FAIL)
+DEFINE_GETTER (nmc_property_ipv4_get_dhcp_send_hostname, NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME)
+DEFINE_GETTER (nmc_property_ipv4_get_dhcp_hostname, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME)
+DEFINE_GETTER (nmc_property_ipv4_get_never_default, NM_SETTING_IP_CONFIG_NEVER_DEFAULT)
+DEFINE_GETTER (nmc_property_ipv4_get_may_fail, NM_SETTING_IP_CONFIG_MAY_FAIL)
/* --- NM_SETTING_IP6_CONFIG_SETTING_NAME property get functions --- */
-DEFINE_GETTER (nmc_property_ipv6_get_method, NM_SETTING_IP6_CONFIG_METHOD)
-DEFINE_GETTER (nmc_property_ipv6_get_dns, NM_SETTING_IP6_CONFIG_DNS)
-DEFINE_GETTER (nmc_property_ipv6_get_dns_search, NM_SETTING_IP6_CONFIG_DNS_SEARCH)
-
-static char *
-nmc_property_ipv6_get_addresses (NMSetting *setting)
-{
- NMSettingIP6Config *s_ip6 = NM_SETTING_IP6_CONFIG (setting);
- GString *printable;
- guint32 num_addresses, i;
- NMIP6Address *addr;
- char buf[INET6_ADDRSTRLEN];
-
- printable = g_string_new (NULL);
-
- num_addresses = nm_setting_ip6_config_get_num_addresses (s_ip6);
- for (i = 0; i < num_addresses; i++) {
- addr = nm_setting_ip6_config_get_address (s_ip6, i);
-
- if (printable->len > 0)
- g_string_append (printable, "; ");
-
- g_string_append (printable, "{ ");
-
- nm_utils_inet6_ntop (nm_ip6_address_get_address (addr), buf);
- g_string_append_printf (printable, "ip = %s", buf);
-
- g_string_append_printf (printable, "/%u", nm_ip6_address_get_prefix (addr));
-
- if (nm_ip6_address_get_gateway (addr)) {
- nm_utils_inet6_ntop (nm_ip6_address_get_gateway (addr), buf);
- g_string_append_printf (printable, ", gw = %s", buf);
- }
-
- g_string_append (printable, " }");
- }
-
- return g_string_free (printable, FALSE);
-}
+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_routes (NMSetting *setting)
{
- NMSettingIP6Config *s_ip6 = NM_SETTING_IP6_CONFIG (setting);
+ NMSettingIPConfig *s_ip6 = NM_SETTING_IP_CONFIG (setting);
GString *printable;
guint32 num_routes, i;
- NMIP6Route *route;
- char buf[INET6_ADDRSTRLEN];
+ NMIPRoute *route;
printable = g_string_new (NULL);
- num_routes = nm_setting_ip6_config_get_num_routes (s_ip6);
+ num_routes = nm_setting_ip_config_get_num_routes (s_ip6);
for (i = 0; i < num_routes; i++) {
- route = nm_setting_ip6_config_get_route (s_ip6, i);
+ route = nm_setting_ip_config_get_route (s_ip6, i);
if (printable->len > 0)
g_string_append (printable, "; ");
g_string_append (printable, "{ ");
- nm_utils_inet6_ntop (nm_ip6_route_get_dest (route), buf);
- g_string_append_printf (printable, "ip = %s", buf);
-
- g_string_append_printf (printable, "/%u", nm_ip6_route_get_prefix (route));
+ g_string_append_printf (printable, "ip = %s/%u",
+ nm_ip_route_get_dest (route),
+ nm_ip_route_get_prefix (route));
- if (nm_ip6_route_get_next_hop (route)) {
- nm_utils_inet6_ntop (nm_ip6_route_get_next_hop (route), buf);
- g_string_append_printf (printable, ", nh = %s", buf);
+ if (nm_ip_route_get_next_hop (route)) {
+ g_string_append_printf (printable, ", nh = %s",
+ nm_ip_route_get_next_hop (route));
}
- if (nm_ip6_route_get_metric (route))
- g_string_append_printf (printable, ", mt = %u", nm_ip6_route_get_metric (route));
+ if (nm_ip_route_get_metric (route) != -1)
+ g_string_append_printf (printable, ", mt = %u", (guint32) nm_ip_route_get_metric (route));
g_string_append (printable, " }");
}
@@ -1366,11 +1328,14 @@ nmc_property_ipv6_get_routes (NMSetting *setting)
return g_string_free (printable, FALSE);
}
-DEFINE_GETTER (nmc_property_ipv6_get_ignore_auto_routes, NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES)
-DEFINE_GETTER (nmc_property_ipv6_get_ignore_auto_dns, NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS)
-DEFINE_GETTER (nmc_property_ipv6_get_never_default, NM_SETTING_IP6_CONFIG_NEVER_DEFAULT)
-DEFINE_GETTER (nmc_property_ipv6_get_may_fail, NM_SETTING_IP6_CONFIG_MAY_FAIL)
-DEFINE_GETTER (nmc_property_ipv6_get_dhcp_hostname, NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME)
+DEFINE_GETTER (nmc_property_ipv6_get_gateway, NM_SETTING_IP_CONFIG_GATEWAY)
+DEFINE_GETTER (nmc_property_ipv6_get_route_metric, NM_SETTING_IP_CONFIG_ROUTE_METRIC)
+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)
+DEFINE_GETTER (nmc_property_ipv6_get_may_fail, NM_SETTING_IP_CONFIG_MAY_FAIL)
+DEFINE_GETTER (nmc_property_ipv6_get_dhcp_send_hostname, NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME)
+DEFINE_GETTER (nmc_property_ipv6_get_dhcp_hostname, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME)
static char *
nmc_property_ipv6_get_ip6_privacy (NMSetting *setting)
@@ -1704,19 +1669,19 @@ ipv4_addresses_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_dat
/* If we have some IP addresses set method to 'manual'.
* Else if the method was 'manual', change it back to 'auto'.
*/
- if (nm_setting_ip4_config_get_num_addresses (NM_SETTING_IP4_CONFIG (object))) {
- if (g_strcmp0 (nm_setting_ip4_config_get_method (NM_SETTING_IP4_CONFIG (object)), NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) {
+ if (nm_setting_ip_config_get_num_addresses (NM_SETTING_IP_CONFIG (object))) {
+ if (g_strcmp0 (nm_setting_ip_config_get_method (NM_SETTING_IP_CONFIG (object)), NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) {
if (!answered) {
answered = TRUE;
answer = get_answer ("ipv4.method", "manual");
}
if (answer)
- g_object_set (object, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, NULL);
+ g_object_set (object, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, NULL);
}
} else {
answered = FALSE;
- if (!g_strcmp0 (nm_setting_ip4_config_get_method (NM_SETTING_IP4_CONFIG (object)), NM_SETTING_IP4_CONFIG_METHOD_MANUAL))
- g_object_set (object, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ if (!g_strcmp0 (nm_setting_ip_config_get_method (NM_SETTING_IP_CONFIG (object)), NM_SETTING_IP4_CONFIG_METHOD_MANUAL))
+ g_object_set (object, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
}
g_signal_handlers_unblock_by_func (object, G_CALLBACK (ipv4_method_changed_cb), NULL);
@@ -1732,8 +1697,8 @@ ipv4_method_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_data)
g_signal_handlers_block_by_func (object, G_CALLBACK (ipv4_addresses_changed_cb), NULL);
/* If method != manual, remove addresses (save them for restoring them later when method becomes 'manual' */
- if (g_strcmp0 (nm_setting_ip4_config_get_method (NM_SETTING_IP4_CONFIG (object)), NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) {
- if (nm_setting_ip4_config_get_num_addresses (NM_SETTING_IP4_CONFIG (object))) {
+ if (g_strcmp0 (nm_setting_ip_config_get_method (NM_SETTING_IP_CONFIG (object)), NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) {
+ if (nm_setting_ip_config_get_num_addresses (NM_SETTING_IP_CONFIG (object))) {
if (!answered) {
answered = TRUE;
answer = get_answer ("ipv4.addresses", NULL);
@@ -1741,14 +1706,14 @@ ipv4_method_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_data)
if (answer) {
if (G_IS_VALUE (&value))
g_value_unset (&value);
- nmc_property_get_gvalue (NM_SETTING (object), NM_SETTING_IP4_CONFIG_ADDRESSES, &value);
- g_object_set (object, NM_SETTING_IP4_CONFIG_ADDRESSES, NULL, NULL);
+ nmc_property_get_gvalue (NM_SETTING (object), NM_SETTING_IP_CONFIG_ADDRESSES, &value);
+ g_object_set (object, NM_SETTING_IP_CONFIG_ADDRESSES, NULL, NULL);
}
}
} else {
answered = FALSE;
if (G_IS_VALUE (&value)) {
- nmc_property_set_gvalue (NM_SETTING (object), NM_SETTING_IP4_CONFIG_ADDRESSES, &value);
+ nmc_property_set_gvalue (NM_SETTING (object), NM_SETTING_IP_CONFIG_ADDRESSES, &value);
g_value_unset (&value);
}
}
@@ -1767,19 +1732,19 @@ ipv6_addresses_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_dat
/* If we have some IP addresses set method to 'manual'.
* Else if the method was 'manual', change it back to 'auto'.
*/
- if (nm_setting_ip6_config_get_num_addresses (NM_SETTING_IP6_CONFIG (object))) {
- if (g_strcmp0 (nm_setting_ip6_config_get_method (NM_SETTING_IP6_CONFIG (object)), NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) {
+ if (nm_setting_ip_config_get_num_addresses (NM_SETTING_IP_CONFIG (object))) {
+ if (g_strcmp0 (nm_setting_ip_config_get_method (NM_SETTING_IP_CONFIG (object)), NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) {
if (!answered) {
answered = TRUE;
answer = get_answer ("ipv6.method", "manual");
}
if (answer)
- g_object_set (object, NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, NULL);
+ g_object_set (object, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, NULL);
}
} else {
answered = FALSE;
- if (!g_strcmp0 (nm_setting_ip6_config_get_method (NM_SETTING_IP6_CONFIG (object)), NM_SETTING_IP6_CONFIG_METHOD_MANUAL))
- g_object_set (object, NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL);
+ if (!g_strcmp0 (nm_setting_ip_config_get_method (NM_SETTING_IP_CONFIG (object)), NM_SETTING_IP6_CONFIG_METHOD_MANUAL))
+ g_object_set (object, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL);
}
g_signal_handlers_unblock_by_func (object, G_CALLBACK (ipv6_method_changed_cb), NULL);
@@ -1795,8 +1760,8 @@ ipv6_method_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_data)
g_signal_handlers_block_by_func (object, G_CALLBACK (ipv6_addresses_changed_cb), NULL);
/* If method != manual, remove addresses (save them for restoring them later when method becomes 'manual' */
- if (g_strcmp0 (nm_setting_ip6_config_get_method (NM_SETTING_IP6_CONFIG (object)), NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) {
- if (nm_setting_ip6_config_get_num_addresses (NM_SETTING_IP6_CONFIG (object))) {
+ if (g_strcmp0 (nm_setting_ip_config_get_method (NM_SETTING_IP_CONFIG (object)), NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) {
+ if (nm_setting_ip_config_get_num_addresses (NM_SETTING_IP_CONFIG (object))) {
if (!answered) {
answered = TRUE;
answer = get_answer ("ipv6.addresses", NULL);
@@ -1804,14 +1769,14 @@ ipv6_method_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_data)
if (answer) {
if (G_IS_VALUE (&value))
g_value_unset (&value);
- nmc_property_get_gvalue (NM_SETTING (object), NM_SETTING_IP6_CONFIG_ADDRESSES, &value);
- g_object_set (object, NM_SETTING_IP6_CONFIG_ADDRESSES, NULL, NULL);
+ nmc_property_get_gvalue (NM_SETTING (object), NM_SETTING_IP_CONFIG_ADDRESSES, &value);
+ g_object_set (object, NM_SETTING_IP_CONFIG_ADDRESSES, NULL, NULL);
}
}
} else {
answered = FALSE;
if (G_IS_VALUE (&value)) {
- nmc_property_set_gvalue (NM_SETTING (object), NM_SETTING_IP6_CONFIG_ADDRESSES, &value);
+ nmc_property_set_gvalue (NM_SETTING (object), NM_SETTING_IP_CONFIG_ADDRESSES, &value);
g_value_unset (&value);
}
}
@@ -1875,24 +1840,24 @@ connection_master_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_
}
void
-nmc_setting_ip4_connect_handlers (NMSettingIP4Config *setting)
+nmc_setting_ip4_connect_handlers (NMSettingIPConfig *setting)
{
g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
- g_signal_connect (setting, "notify::" NM_SETTING_IP4_CONFIG_ADDRESSES,
+ g_signal_connect (setting, "notify::" NM_SETTING_IP_CONFIG_ADDRESSES,
G_CALLBACK (ipv4_addresses_changed_cb), NULL);
- g_signal_connect (setting, "notify::" NM_SETTING_IP4_CONFIG_METHOD,
+ g_signal_connect (setting, "notify::" NM_SETTING_IP_CONFIG_METHOD,
G_CALLBACK (ipv4_method_changed_cb), NULL);
}
void
-nmc_setting_ip6_connect_handlers (NMSettingIP6Config *setting)
+nmc_setting_ip6_connect_handlers (NMSettingIPConfig *setting)
{
g_return_if_fail (NM_IS_SETTING_IP6_CONFIG (setting));
- g_signal_connect (setting, "notify::" NM_SETTING_IP6_CONFIG_ADDRESSES,
+ g_signal_connect (setting, "notify::" NM_SETTING_IP_CONFIG_ADDRESSES,
G_CALLBACK (ipv6_addresses_changed_cb), NULL);
- g_signal_connect (setting, "notify::" NM_SETTING_IP6_CONFIG_METHOD,
+ g_signal_connect (setting, "notify::" NM_SETTING_IP_CONFIG_METHOD,
G_CALLBACK (ipv6_method_changed_cb), NULL);
}
@@ -1926,15 +1891,15 @@ nmc_setting_custom_init (NMSetting *setting)
g_return_if_fail (NM_IS_SETTING (setting));
if (NM_IS_SETTING_IP4_CONFIG (setting)) {
- g_object_set (NM_SETTING_IP4_CONFIG (setting),
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ g_object_set (NM_SETTING_IP_CONFIG (setting),
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
NULL);
- nmc_setting_ip4_connect_handlers (NM_SETTING_IP4_CONFIG (setting));
+ nmc_setting_ip4_connect_handlers (NM_SETTING_IP_CONFIG (setting));
} else if (NM_IS_SETTING_IP6_CONFIG (setting)) {
- g_object_set (NM_SETTING_IP6_CONFIG (setting),
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
+ g_object_set (NM_SETTING_IP_CONFIG (setting),
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
NULL);
- nmc_setting_ip6_connect_handlers (NM_SETTING_IP6_CONFIG (setting));
+ nmc_setting_ip6_connect_handlers (NM_SETTING_IP_CONFIG (setting));
} else if (NM_IS_SETTING_WIRELESS (setting)) {
g_object_set (NM_SETTING_WIRELESS (setting),
NM_SETTING_WIRELESS_MODE, NM_SETTING_WIRELESS_MODE_INFRA,
@@ -1990,6 +1955,27 @@ validate_int (NMSetting *setting, const char* prop, gint val, GError **error)
return success;
}
+static gboolean
+validate_int64 (NMSetting *setting, const char* prop, gint64 val, GError **error)
+{
+ GParamSpec *pspec;
+ GValue value = G_VALUE_INIT;
+ gboolean success = TRUE;
+
+ g_value_init (&value, G_TYPE_INT64);
+ g_value_set_int64 (&value, val);
+ pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (setting)), prop);
+ g_assert (G_IS_PARAM_SPEC (pspec));
+ if (g_param_value_validate (pspec, &value)) {
+ GParamSpecInt64 *pspec_int = (GParamSpecInt64 *) pspec;
+ g_set_error (error, 1, 0, _("'%"G_GINT64_FORMAT"' is not valid; use <%"G_GINT64_FORMAT"-%"G_GINT64_FORMAT">"),
+ val, pspec_int->minimum, pspec_int->maximum);
+ success = FALSE;
+ }
+ g_value_unset (&value);
+ return success;
+}
+
/* Validate 'val' number against to uint property spec */
static gboolean
validate_uint (NMSetting *setting, const char* prop, guint val, GError **error)
@@ -2218,6 +2204,26 @@ nmc_property_set_int (NMSetting *setting, const char *prop, const char *val, GEr
}
static gboolean
+nmc_property_set_int64 (NMSetting *setting, const char *prop, const char *val, GError **error)
+{
+ long val_int;
+
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ if (!nmc_string_to_int (val, FALSE, 0, 0, &val_int)) {
+ g_set_error (error, 1, 0, _("'%s' is not a valid number (or out of range)"), val);
+ return FALSE;
+ }
+
+ /* Validate the number according to the property spec */
+ if (!validate_int64 (setting, prop, (gint64) val_int, error))
+ return FALSE;
+
+ g_object_set (setting, prop, (gint64) val_int, NULL);
+ return TRUE;
+}
+
+static gboolean
nmc_property_set_bool (NMSetting *setting, const char *prop, const char *val, GError **error)
{
gboolean val_bool;
@@ -2337,7 +2343,7 @@ nmc_property_set_byte_array (NMSetting *setting, const char *prop, const char *v
char *val_strip;
const char *delimiters = " \t,";
long int val_int;
- char *bin;
+ GBytes *bytes;
GByteArray *array = NULL;
gboolean success = TRUE;
@@ -2346,11 +2352,9 @@ nmc_property_set_byte_array (NMSetting *setting, const char *prop, const char *v
val_strip = g_strstrip (g_strdup (val));
/* First try hex string in the format of AAbbCCDd */
- bin = nm_utils_hexstr2bin (val_strip, strlen (val_strip));
- if (bin) {
- array = g_byte_array_sized_new (strlen (val_strip)/2);
- g_byte_array_append (array, (const guint8 *) bin, strlen (val_strip)/2);
- g_free (bin);
+ bytes = nm_utils_hexstr2bin (val_strip);
+ if (bytes) {
+ array = g_bytes_unref_to_array (bytes);
goto done;
}
@@ -3074,6 +3078,41 @@ nmc_property_ib_set_p_key (NMSetting *setting, const char *prop, const char *val
return TRUE;
}
+/* --- IP4 / IP6 shared functions --- */
+static NMIPAddress *
+_parse_ip_address (int family, const char *address, GError **error)
+{
+ char *value = g_strdup (address);
+ NMIPAddress *ipaddr;
+
+ ipaddr = nmc_parse_and_build_address (family, g_strstrip (value), error);
+ g_free (value);
+ return ipaddr;
+}
+
+static NMIPRoute *
+_parse_ip_route (int family, const char *route, GError **error)
+{
+ char *value = g_strdup (route);
+ char **routev;
+ guint len;
+ NMIPRoute *iproute = NULL;
+
+ routev = nmc_strsplit_set (g_strstrip (value), " \t", 0);
+ len = g_strv_length (routev);
+ if (len < 1 || len > 3) {
+ g_set_error (error, 1, 0, _("'%s' is not valid (the format is: ip[/prefix] [next-hop] [metric])"),
+ route);
+ goto finish;
+ }
+ iproute = nmc_parse_and_build_route (family, routev[0], routev[1], len >= 2 ? routev[2] : NULL, error);
+
+finish:
+ g_free (value);
+ g_strfreev (routev);
+ return iproute;
+}
+
/* --- NM_SETTING_IP4_CONFIG_SETTING_NAME property setter functions --- */
/* 'method' */
static const char *ipv4_valid_methods[] = {
@@ -3114,14 +3153,14 @@ nmc_property_ipv4_set_dns (NMSetting *setting, const char *prop, const char *val
g_strfreev (strv);
return FALSE;
}
- nm_setting_ip4_config_add_dns (NM_SETTING_IP4_CONFIG (setting), addr);
+ nm_setting_ip_config_add_dns (NM_SETTING_IP_CONFIG (setting), addr);
}
g_strfreev (strv);
return TRUE;
}
static gboolean
-_validate_and_remove_ipv4_dns (NMSettingIP4Config *setting,
+_validate_and_remove_ipv4_dns (NMSettingIPConfig *setting,
const char *dns,
GError **error)
{
@@ -3133,15 +3172,15 @@ _validate_and_remove_ipv4_dns (NMSettingIP4Config *setting,
return FALSE;
}
- ret = nm_setting_ip4_config_remove_dns_by_value (setting, dns);
+ ret = nm_setting_ip_config_remove_dns_by_value (setting, dns);
if (!ret)
g_set_error (error, 1, 0, _("the property doesn't contain DNS server '%s'"), dns);
return ret;
}
DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_ipv4_remove_dns,
- NM_SETTING_IP4_CONFIG,
- nm_setting_ip4_config_get_num_dns,
- nm_setting_ip4_config_remove_dns,
+ NM_SETTING_IP_CONFIG,
+ nm_setting_ip_config_get_num_dns,
+ nm_setting_ip_config_remove_dns,
_validate_and_remove_ipv4_dns)
static const char *
@@ -3167,20 +3206,20 @@ nmc_property_ipv4_set_dns_search (NMSetting *setting, const char *prop, const ch
}
while (strv && strv[i])
- nm_setting_ip4_config_add_dns_search (NM_SETTING_IP4_CONFIG (setting), strv[i++]);
+ nm_setting_ip_config_add_dns_search (NM_SETTING_IP_CONFIG (setting), strv[i++]);
g_strfreev (strv);
return TRUE;
}
static gboolean
-_validate_and_remove_ipv4_dns_search (NMSettingIP4Config *setting,
+_validate_and_remove_ipv4_dns_search (NMSettingIPConfig *setting,
const char *dns_search,
GError **error)
{
gboolean ret;
- ret = nm_setting_ip4_config_remove_dns_search_by_value (setting, dns_search);
+ ret = nm_setting_ip_config_remove_dns_search_by_value (setting, dns_search);
if (!ret)
g_set_error (error, 1, 0,
_("the property doesn't contain DNS search domain '%s'"),
@@ -3188,38 +3227,23 @@ _validate_and_remove_ipv4_dns_search (NMSettingIP4Config *setting,
return ret;
}
DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_ipv4_remove_dns_search,
- NM_SETTING_IP4_CONFIG,
- nm_setting_ip4_config_get_num_dns_searches,
- nm_setting_ip4_config_remove_dns_search,
+ NM_SETTING_IP_CONFIG,
+ nm_setting_ip_config_get_num_dns_searches,
+ nm_setting_ip_config_remove_dns_search,
_validate_and_remove_ipv4_dns_search)
/* 'addresses' */
-static NMIP4Address *
+static NMIPAddress *
_parse_ipv4_address (const char *address, GError **error)
{
- char *value = g_strdup (address);
- char **addrv;
- NMIP4Address *ip4addr;
-
- 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;
- }
- ip4addr = nmc_parse_and_build_ip4_address (addrv[0], addrv[1], error);
- g_free (value);
- g_strfreev (addrv);
- return ip4addr;
+ return _parse_ip_address (AF_INET, address, error);
}
static gboolean
nmc_property_ipv4_set_addresses (NMSetting *setting, const char *prop, const char *val, GError **error)
{
char **strv = NULL, **iter;
- NMIP4Address *ip4addr;
+ NMIPAddress *ip4addr;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
@@ -3230,111 +3254,81 @@ nmc_property_ipv4_set_addresses (NMSetting *setting, const char *prop, const cha
g_strfreev (strv);
return FALSE;
}
- nm_setting_ip4_config_add_address (NM_SETTING_IP4_CONFIG (setting), ip4addr);
- nm_ip4_address_unref (ip4addr);
+ nm_setting_ip_config_add_address (NM_SETTING_IP_CONFIG (setting), ip4addr);
+ nm_ip_address_unref (ip4addr);
}
g_strfreev (strv);
return TRUE;
}
static gboolean
-_validate_and_remove_ipv4_address (NMSettingIP4Config *setting,
+_validate_and_remove_ipv4_address (NMSettingIPConfig *setting,
const char *address,
GError **error)
{
- NMIP4Address *ip4addr;
+ NMIPAddress *ip4addr;
gboolean ret;
ip4addr = _parse_ipv4_address (address, error);
if (!ip4addr)
return FALSE;
- ret = nm_setting_ip4_config_remove_address_by_value (setting, ip4addr);
+ ret = nm_setting_ip_config_remove_address_by_value (setting, ip4addr);
if (!ret)
g_set_error (error, 1, 0,
_("the property doesn't contain IP address '%s'"), address);
- nm_ip4_address_unref (ip4addr);
+ nm_ip_address_unref (ip4addr);
return ret;
}
DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_ipv4_remove_addresses,
- NM_SETTING_IP4_CONFIG,
- nm_setting_ip4_config_get_num_addresses,
- nm_setting_ip4_config_remove_address,
+ NM_SETTING_IP_CONFIG,
+ nm_setting_ip_config_get_num_addresses,
+ nm_setting_ip_config_remove_address,
_validate_and_remove_ipv4_address)
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;
- GString *str;
- char **strv;
- int i;
+ NMIPAddress *ip4addr;
- str = g_string_sized_new (128);
- regex = g_regex_new ("\\{ ip = ([^/]+)/([^,]+), gw = ([^ ]+) \\}", 0, 0, NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- strv = g_regex_split (regex, out_format, 0);
- for (i = 1; strv && strv[i] && strv[i+1] && strv[i+2]; i=i+4) {
- g_string_append (str, strv[i]); /* IP */
- g_string_append_c (str, '/');
- g_string_append (str, strv[i+1]); /* prefix */
- g_string_append_c (str, ' ');
- g_string_append (str, strv[i+2]); /* gateway */
- g_string_append (str, ", ");
+ if (strchr (val, '/')) {
+ g_set_error (error, 1, 0,
+ _("invalid gateway address '%s'"), val);
+ return FALSE;
}
- if (str->len > 0)
- g_string_truncate (str, str->len - 2);
-
- g_strfreev (strv);
- g_regex_unref (regex);
+ ip4addr = _parse_ipv4_address (val, error);
+ if (!ip4addr)
+ return FALSE;
- return g_string_free (str, FALSE);
+ g_object_set (setting, prop, val, NULL);
+ nm_ip_address_unref (ip4addr);
+ return TRUE;
}
/* 'routes' */
-static NMIP4Route *
+static NMIPRoute *
_parse_ipv4_route (const char *route, GError **error)
{
- char *value = g_strdup (route);
- char **routev;
- guint len;
- NMIP4Route *ip4route = NULL;
-
- routev = nmc_strsplit_set (g_strstrip (value), " \t", 0);
- len = g_strv_length (routev);
- if (len < 1 || len > 3) {
- g_set_error (error, 1, 0, _("'%s' is not valid (the format is: ip[/prefix] [next-hop] [metric])"),
- route);
- goto finish;
- }
- ip4route = nmc_parse_and_build_ip4_route (routev[0], routev[1], len >= 2 ? routev[2] : NULL, error);
-
-finish:
- g_free (value);
- g_strfreev (routev);
- return ip4route;
+ return _parse_ip_route (AF_INET, route, error);
}
static gboolean
nmc_property_ipv4_set_routes (NMSetting *setting, const char *prop, const char *val, GError **error)
{
char **strv = NULL, **iter;
- NMIP4Route *ip4route;
+ NMIPRoute *ip4route;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
@@ -3345,35 +3339,35 @@ nmc_property_ipv4_set_routes (NMSetting *setting, const char *prop, const char *
g_strfreev (strv);
return FALSE;
}
- nm_setting_ip4_config_add_route (NM_SETTING_IP4_CONFIG (setting), ip4route);
- nm_ip4_route_unref (ip4route);
+ nm_setting_ip_config_add_route (NM_SETTING_IP_CONFIG (setting), ip4route);
+ nm_ip_route_unref (ip4route);
}
g_strfreev (strv);
return TRUE;
}
static gboolean
-_validate_and_remove_ipv4_route (NMSettingIP4Config *setting,
+_validate_and_remove_ipv4_route (NMSettingIPConfig *setting,
const char *route,
GError **error)
{
- NMIP4Route *ip4route;
+ NMIPRoute *ip4route;
gboolean ret;
ip4route = _parse_ipv4_route (route, error);
if (!ip4route)
return FALSE;
- ret = nm_setting_ip4_config_remove_route_by_value (setting, ip4route);
+ ret = nm_setting_ip_config_remove_route_by_value (setting, ip4route);
if (!ret)
g_set_error (error, 1, 0, _("the property doesn't contain route '%s'"), route);
- nm_ip4_route_unref (ip4route);
+ nm_ip_route_unref (ip4route);
return ret;
}
DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_ipv4_remove_routes,
- NM_SETTING_IP4_CONFIG,
- nm_setting_ip4_config_get_num_routes,
- nm_setting_ip4_config_remove_route,
+ NM_SETTING_IP_CONFIG,
+ nm_setting_ip_config_get_num_routes,
+ nm_setting_ip_config_remove_route,
_validate_and_remove_ipv4_route)
static const char *
@@ -3383,7 +3377,7 @@ nmc_property_ipv4_describe_routes (NMSetting *setting, const char *prop)
" ip[/prefix] [next-hop] [metric],...\n\n"
"Missing prefix is regarded as a prefix of 32.\n"
"Missing next-hop is regarded as 0.0.0.0.\n"
- "Missing metric or 0 means a default metric (NM/kernel will set a default value).\n\n"
+ "Missing metric means default (NM/kernel will set a default value).\n\n"
"Examples: 192.168.2.0/24 192.168.2.1 3, 10.1.0.0/16 10.0.0.254\n"
" 10.1.2.0/24\n");
}
@@ -3460,14 +3454,14 @@ nmc_property_ipv6_set_dns (NMSetting *setting, const char *prop, const char *val
g_strfreev (strv);
return FALSE;
}
- nm_setting_ip6_config_add_dns (NM_SETTING_IP6_CONFIG (setting), addr);
+ nm_setting_ip_config_add_dns (NM_SETTING_IP_CONFIG (setting), addr);
}
g_strfreev (strv);
return TRUE;
}
static gboolean
-_validate_and_remove_ipv6_dns (NMSettingIP6Config *setting,
+_validate_and_remove_ipv6_dns (NMSettingIPConfig *setting,
const char *dns,
GError **error)
{
@@ -3479,15 +3473,15 @@ _validate_and_remove_ipv6_dns (NMSettingIP6Config *setting,
return FALSE;
}
- ret = nm_setting_ip6_config_remove_dns_by_value (setting, dns);
+ ret = nm_setting_ip_config_remove_dns_by_value (setting, dns);
if (!ret)
g_set_error (error, 1, 0, _("the property doesn't contain DNS server '%s'"), dns);
return ret;
}
DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_ipv6_remove_dns,
- NM_SETTING_IP6_CONFIG,
- nm_setting_ip6_config_get_num_dns,
- nm_setting_ip6_config_remove_dns,
+ NM_SETTING_IP_CONFIG,
+ nm_setting_ip_config_get_num_dns,
+ nm_setting_ip_config_remove_dns,
_validate_and_remove_ipv6_dns)
static const char *
@@ -3519,20 +3513,20 @@ nmc_property_ipv6_set_dns_search (NMSetting *setting, const char *prop, const ch
}
while (strv && strv[i])
- nm_setting_ip6_config_add_dns_search (NM_SETTING_IP6_CONFIG (setting), strv[i++]);
+ nm_setting_ip_config_add_dns_search (NM_SETTING_IP_CONFIG (setting), strv[i++]);
g_strfreev (strv);
return TRUE;
}
static gboolean
-_validate_and_remove_ipv6_dns_search (NMSettingIP6Config *setting,
+_validate_and_remove_ipv6_dns_search (NMSettingIPConfig *setting,
const char *dns_search,
GError **error)
{
gboolean ret;
- ret = nm_setting_ip6_config_remove_dns_search_by_value (setting, dns_search);
+ ret = nm_setting_ip_config_remove_dns_search_by_value (setting, dns_search);
if (!ret)
g_set_error (error, 1, 0,
_("the property doesn't contain DNS search domain '%s'"),
@@ -3540,38 +3534,23 @@ _validate_and_remove_ipv6_dns_search (NMSettingIP6Config *setting,
return ret;
}
DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_ipv6_remove_dns_search,
- NM_SETTING_IP6_CONFIG,
- nm_setting_ip6_config_get_num_dns_searches,
- nm_setting_ip6_config_remove_dns_search,
+ NM_SETTING_IP_CONFIG,
+ nm_setting_ip_config_get_num_dns_searches,
+ nm_setting_ip_config_remove_dns_search,
_validate_and_remove_ipv6_dns_search)
/* 'addresses' */
-static NMIP6Address *
+static NMIPAddress *
_parse_ipv6_address (const char *address, GError **error)
{
- char *value = g_strstrip (g_strdup (address));
- char **addrv;
- NMIP6Address *ip6addr;
-
- 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;
- }
- ip6addr = nmc_parse_and_build_ip6_address (addrv[0], addrv[1], error);
- g_free (value);
- g_strfreev (addrv);
- return ip6addr;
+ return _parse_ip_address (AF_INET6, address, error);
}
static gboolean
nmc_property_ipv6_set_addresses (NMSetting *setting, const char *prop, const char *val, GError **error)
{
char **strv = NULL, **iter;
- NMIP6Address *ip6addr;
+ NMIPAddress *ip6addr;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
@@ -3582,75 +3561,80 @@ nmc_property_ipv6_set_addresses (NMSetting *setting, const char *prop, const cha
g_strfreev (strv);
return FALSE;
}
- nm_setting_ip6_config_add_address (NM_SETTING_IP6_CONFIG (setting), ip6addr);
- nm_ip6_address_unref (ip6addr);
+ nm_setting_ip_config_add_address (NM_SETTING_IP_CONFIG (setting), ip6addr);
+ nm_ip_address_unref (ip6addr);
}
g_strfreev (strv);
return TRUE;
}
static gboolean
-_validate_and_remove_ipv6_address (NMSettingIP6Config *setting,
+_validate_and_remove_ipv6_address (NMSettingIPConfig *setting,
const char *address,
GError **error)
{
- NMIP6Address *ip6addr;
+ NMIPAddress *ip6addr;
gboolean ret;
ip6addr = _parse_ipv6_address (address, error);
if (!ip6addr)
return FALSE;
- ret = nm_setting_ip6_config_remove_address_by_value (setting, ip6addr);
+ ret = nm_setting_ip_config_remove_address_by_value (setting, ip6addr);
if (!ret)
g_set_error (error, 1, 0, _("the property doesn't contain IP address '%s'"), address);
- nm_ip6_address_unref (ip6addr);
+ nm_ip_address_unref (ip6addr);
return ret;
}
DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_ipv6_remove_addresses,
- NM_SETTING_IP6_CONFIG,
- nm_setting_ip6_config_get_num_addresses,
- nm_setting_ip6_config_remove_address,
+ NM_SETTING_IP_CONFIG,
+ nm_setting_ip_config_get_num_addresses,
+ nm_setting_ip_config_remove_address,
_validate_and_remove_ipv6_address)
static const char *
nmc_property_ipv6_describe_addresses (NMSetting *setting, const char *prop)
{
return _("Enter a list of IPv6 addresses formatted as:\n"
- " ip[/prefix] [gateway], ip[/prefix] [gateway],...\n"
+ " ip[/prefix], ip[/prefix],...\n"
"Missing prefix is regarded as prefix of 128.\n\n"
- "Example: 2607:f0d0:1002:51::4/64 2607:f0d0:1002:51::1, 1050:0:0:0:5:600:300c:326b\n");
+ "Example: 2607:f0d0:1002:51::4/64, 1050:0:0:0:5:600:300c:326b\n");
}
-/* 'routes' */
-static NMIP6Route *
-_parse_ipv6_route (const char *route, GError **error)
+/* 'gateway' */
+static gboolean
+nmc_property_ipv6_set_gateway (NMSetting *setting, const char *prop, const char *val, GError **error)
{
- char *value = g_strdup (route);
- char **routev;
- guint len;
- NMIP6Route *ip6route = NULL;
+ NMIPAddress *ip6addr;
- routev = nmc_strsplit_set (g_strstrip (value), " \t", 0);
- len = g_strv_length (routev);
- if (len < 1 || len > 3) {
- g_set_error (error, 1, 0, _("'%s' is not valid (the format is: ip[/prefix] [next-hop] [metric])"),
- route);
- goto finish;
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ if (strchr (val, '/')) {
+ g_set_error (error, 1, 0,
+ _("invalid gateway address '%s'"), val);
+ return FALSE;
}
- ip6route = nmc_parse_and_build_ip6_route (routev[0], routev[1], len >= 2 ? routev[2] : NULL, error);
+ ip6addr = _parse_ipv6_address (val, error);
+ if (!ip6addr)
+ return FALSE;
-finish:
- g_free (value);
- g_strfreev (routev);
- return ip6route;
+ g_object_set (setting, prop, val, NULL);
+ nm_ip_address_unref (ip6addr);
+ return TRUE;
+}
+
+/* 'routes' */
+static NMIPRoute *
+_parse_ipv6_route (const char *route, GError **error)
+{
+ return _parse_ip_route (AF_INET6, route, error);
}
static gboolean
nmc_property_ipv6_set_routes (NMSetting *setting, const char *prop, const char *val, GError **error)
{
char **strv = NULL, **iter;
- NMIP6Route *ip6route;
+ NMIPRoute *ip6route;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
@@ -3661,35 +3645,35 @@ nmc_property_ipv6_set_routes (NMSetting *setting, const char *prop, const char *
g_strfreev (strv);
return FALSE;
}
- nm_setting_ip6_config_add_route (NM_SETTING_IP6_CONFIG (setting), ip6route);
- nm_ip6_route_unref (ip6route);
+ nm_setting_ip_config_add_route (NM_SETTING_IP_CONFIG (setting), ip6route);
+ nm_ip_route_unref (ip6route);
}
g_strfreev (strv);
return TRUE;
}
static gboolean
-_validate_and_remove_ipv6_route (NMSettingIP6Config *setting,
+_validate_and_remove_ipv6_route (NMSettingIPConfig *setting,
const char *route,
GError **error)
{
- NMIP6Route *ip6route;
+ NMIPRoute *ip6route;
gboolean ret;
ip6route = _parse_ipv6_route (route, error);
if (!ip6route)
return FALSE;
- ret = nm_setting_ip6_config_remove_route_by_value (setting, ip6route);
+ ret = nm_setting_ip_config_remove_route_by_value (setting, ip6route);
if (!ret)
g_set_error (error, 1, 0, _("the property doesn't contain route '%s'"), route);
- nm_ip6_route_unref (ip6route);
+ nm_ip_route_unref (ip6route);
return ret;
}
DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_ipv6_remove_routes,
- NM_SETTING_IP6_CONFIG,
- nm_setting_ip6_config_get_num_routes,
- nm_setting_ip6_config_remove_route,
+ NM_SETTING_IP_CONFIG,
+ nm_setting_ip_config_get_num_routes,
+ nm_setting_ip_config_remove_route,
_validate_and_remove_ipv6_route)
static const char *
@@ -3699,7 +3683,7 @@ nmc_property_ipv6_describe_routes (NMSetting *setting, const char *prop)
" ip[/prefix] [next-hop] [metric],...\n\n"
"Missing prefix is regarded as a prefix of 128.\n"
"Missing next-hop is regarded as \"::\".\n"
- "Missing metric or 0 means a default metric (NM/kernel will set a default value).\n\n"
+ "Missing metric means default (NM/kernel will set a default value).\n\n"
"Examples: 2001:db8:beef:2::/64 2001:db8:beef::2, 2001:db8:beef:3::/64 2001:db8:beef::3 2\n"
" abbe::/64 55\n");
}
@@ -4722,6 +4706,8 @@ nmc_add_prop_funcs (char *key,
/* concatenate setting name and property name */
#define GLUE(A,B) (g_strconcat ((NM_SETTING_##A##_SETTING_NAME),(NM_SETTING_##A##_##B), NULL))
+#define GLUE_IP(A,B) (g_strconcat ((NM_SETTING_IP##A##_CONFIG_SETTING_NAME),(NM_SETTING_IP_CONFIG_##B), NULL))
+
void
nmc_properties_init (void)
{
@@ -5447,49 +5433,63 @@ nmc_properties_init (void)
NULL);
/* Add editable properties for NM_SETTING_IP4_CONFIG_SETTING_NAME */
- nmc_add_prop_funcs (GLUE (IP4_CONFIG, METHOD),
+ nmc_add_prop_funcs (GLUE_IP (4, METHOD),
nmc_property_ipv4_get_method,
nmc_property_ipv4_set_method,
NULL,
NULL,
nmc_property_ipv4_allowed_method,
NULL);
- nmc_add_prop_funcs (GLUE (IP4_CONFIG, DNS),
+ nmc_add_prop_funcs (GLUE_IP (4, DNS),
nmc_property_ipv4_get_dns,
nmc_property_ipv4_set_dns,
nmc_property_ipv4_remove_dns,
nmc_property_ipv4_describe_dns,
NULL,
NULL);
- nmc_add_prop_funcs (GLUE (IP4_CONFIG, DNS_SEARCH),
+ nmc_add_prop_funcs (GLUE_IP (4, DNS_SEARCH),
nmc_property_ipv4_get_dns_search,
nmc_property_ipv4_set_dns_search,
nmc_property_ipv4_remove_dns_search,
NULL,
NULL,
NULL);
- nmc_add_prop_funcs (GLUE (IP4_CONFIG, ADDRESSES),
- nmc_property_ipv4_get_addresses,
+ nmc_add_prop_funcs (GLUE_IP (4, ADDRESSES),
+ nmc_property_ip_get_addresses,
nmc_property_ipv4_set_addresses,
nmc_property_ipv4_remove_addresses,
nmc_property_ipv4_describe_addresses,
NULL,
- nmc_property_out2in_addresses);
- nmc_add_prop_funcs (GLUE (IP4_CONFIG, ROUTES),
+ NULL);
+ nmc_add_prop_funcs (GLUE_IP (4, GATEWAY),
+ nmc_property_ipv4_get_gateway,
+ nmc_property_ipv4_set_gateway,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+ nmc_add_prop_funcs (GLUE_IP (4, ROUTES),
nmc_property_ipv4_get_routes,
nmc_property_ipv4_set_routes,
nmc_property_ipv4_remove_routes,
nmc_property_ipv4_describe_routes,
NULL,
nmc_property_out2in_routes);
- nmc_add_prop_funcs (GLUE (IP4_CONFIG, IGNORE_AUTO_ROUTES),
+ nmc_add_prop_funcs (GLUE_IP (4, ROUTE_METRIC),
+ nmc_property_ipv4_get_route_metric,
+ nmc_property_set_int64,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+ nmc_add_prop_funcs (GLUE_IP (4, IGNORE_AUTO_ROUTES),
nmc_property_ipv4_get_ignore_auto_routes,
nmc_property_set_bool,
NULL,
NULL,
NULL,
NULL);
- nmc_add_prop_funcs (GLUE (IP4_CONFIG, IGNORE_AUTO_DNS),
+ nmc_add_prop_funcs (GLUE_IP (4, IGNORE_AUTO_DNS),
nmc_property_ipv4_get_ignore_auto_dns,
nmc_property_set_bool,
NULL,
@@ -5503,28 +5503,28 @@ nmc_properties_init (void)
NULL,
NULL,
NULL);
- nmc_add_prop_funcs (GLUE (IP4_CONFIG, DHCP_SEND_HOSTNAME),
+ nmc_add_prop_funcs (GLUE_IP (4, DHCP_SEND_HOSTNAME),
nmc_property_ipv4_get_dhcp_send_hostname,
nmc_property_set_bool,
NULL,
NULL,
NULL,
NULL);
- nmc_add_prop_funcs (GLUE (IP4_CONFIG, DHCP_HOSTNAME),
+ nmc_add_prop_funcs (GLUE_IP (4, DHCP_HOSTNAME),
nmc_property_ipv4_get_dhcp_hostname,
nmc_property_set_string,
NULL,
NULL,
NULL,
NULL);
- nmc_add_prop_funcs (GLUE (IP4_CONFIG, NEVER_DEFAULT),
+ nmc_add_prop_funcs (GLUE_IP (4, NEVER_DEFAULT),
nmc_property_ipv4_get_never_default,
nmc_property_set_bool,
NULL,
NULL,
NULL,
NULL);
- nmc_add_prop_funcs (GLUE (IP4_CONFIG, MAY_FAIL),
+ nmc_add_prop_funcs (GLUE_IP (4, MAY_FAIL),
nmc_property_ipv4_get_may_fail,
nmc_property_set_bool,
NULL,
@@ -5533,63 +5533,77 @@ nmc_properties_init (void)
NULL);
/* Add editable properties for NM_SETTING_IP6_CONFIG_SETTING_NAME */
- nmc_add_prop_funcs (GLUE (IP6_CONFIG, METHOD),
+ nmc_add_prop_funcs (GLUE_IP (6, METHOD),
nmc_property_ipv6_get_method,
nmc_property_ipv6_set_method,
NULL,
NULL,
nmc_property_ipv6_allowed_method,
NULL);
- nmc_add_prop_funcs (GLUE (IP6_CONFIG, DNS),
+ nmc_add_prop_funcs (GLUE_IP (6, DNS),
nmc_property_ipv6_get_dns,
nmc_property_ipv6_set_dns,
nmc_property_ipv6_remove_dns,
nmc_property_ipv6_describe_dns,
NULL,
NULL);
- nmc_add_prop_funcs (GLUE (IP6_CONFIG, DNS_SEARCH),
+ nmc_add_prop_funcs (GLUE_IP (6, DNS_SEARCH),
nmc_property_ipv6_get_dns_search,
nmc_property_ipv6_set_dns_search,
nmc_property_ipv6_remove_dns_search,
NULL,
NULL,
NULL);
- nmc_add_prop_funcs (GLUE (IP6_CONFIG, ADDRESSES),
- nmc_property_ipv6_get_addresses,
+ nmc_add_prop_funcs (GLUE_IP (6, ADDRESSES),
+ nmc_property_ip_get_addresses,
nmc_property_ipv6_set_addresses,
nmc_property_ipv6_remove_addresses,
nmc_property_ipv6_describe_addresses,
NULL,
- nmc_property_out2in_addresses);
- nmc_add_prop_funcs (GLUE (IP6_CONFIG, ROUTES),
+ NULL);
+ nmc_add_prop_funcs (GLUE_IP (6, GATEWAY),
+ nmc_property_ipv6_get_gateway,
+ nmc_property_ipv6_set_gateway,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+ nmc_add_prop_funcs (GLUE_IP (6, ROUTES),
nmc_property_ipv6_get_routes,
nmc_property_ipv6_set_routes,
nmc_property_ipv6_remove_routes,
nmc_property_ipv6_describe_routes,
NULL,
nmc_property_out2in_routes);
- nmc_add_prop_funcs (GLUE (IP6_CONFIG, IGNORE_AUTO_ROUTES),
+ nmc_add_prop_funcs (GLUE_IP (6, ROUTE_METRIC),
+ nmc_property_ipv6_get_route_metric,
+ nmc_property_set_int64,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+ nmc_add_prop_funcs (GLUE_IP (6, IGNORE_AUTO_ROUTES),
nmc_property_ipv6_get_ignore_auto_routes,
nmc_property_set_bool,
NULL,
NULL,
NULL,
NULL);
- nmc_add_prop_funcs (GLUE (IP6_CONFIG, IGNORE_AUTO_DNS),
+ nmc_add_prop_funcs (GLUE_IP (6, IGNORE_AUTO_DNS),
nmc_property_ipv6_get_ignore_auto_dns,
nmc_property_set_bool,
NULL,
NULL,
NULL,
NULL);
- nmc_add_prop_funcs (GLUE (IP6_CONFIG, NEVER_DEFAULT),
+ nmc_add_prop_funcs (GLUE_IP (6, NEVER_DEFAULT),
nmc_property_ipv6_get_never_default,
nmc_property_set_bool,
NULL,
NULL,
NULL,
NULL);
- nmc_add_prop_funcs (GLUE (IP6_CONFIG, MAY_FAIL),
+ nmc_add_prop_funcs (GLUE_IP (6, MAY_FAIL),
nmc_property_ipv6_get_may_fail,
nmc_property_set_bool,
NULL,
@@ -5603,7 +5617,14 @@ nmc_properties_init (void)
NULL,
NULL,
nmc_property_out2in_cut_paren);
- nmc_add_prop_funcs (GLUE (IP6_CONFIG, DHCP_HOSTNAME),
+ nmc_add_prop_funcs (GLUE_IP (6, DHCP_SEND_HOSTNAME),
+ nmc_property_ipv6_get_dhcp_send_hostname,
+ nmc_property_set_bool,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+ nmc_add_prop_funcs (GLUE_IP (6, DHCP_HOSTNAME),
nmc_property_ipv6_get_dhcp_hostname,
nmc_property_set_string,
NULL,
@@ -6742,7 +6763,7 @@ setting_wireless_security_details (NMSetting *setting, NmCli *nmc, const char *o
static gboolean
setting_ip4_config_details (NMSetting *setting, NmCli *nmc, const char *one_prop, gboolean secrets)
{
- NMSettingIP4Config *s_ip4 = NM_SETTING_IP4_CONFIG (setting);
+ NMSettingIPConfig *s_ip4 = NM_SETTING_IP_CONFIG (setting);
NmcOutputField *tmpl, *arr;
size_t tmpl_len;
@@ -6760,15 +6781,17 @@ setting_ip4_config_details (NMSetting *setting, NmCli *nmc, const char *one_pro
set_val_str (arr, 1, nmc_property_ipv4_get_method (setting));
set_val_str (arr, 2, nmc_property_ipv4_get_dns (setting));
set_val_str (arr, 3, nmc_property_ipv4_get_dns_search (setting));
- set_val_str (arr, 4, nmc_property_ipv4_get_addresses (setting));
- set_val_str (arr, 5, nmc_property_ipv4_get_routes (setting));
- set_val_str (arr, 6, nmc_property_ipv4_get_ignore_auto_routes (setting));
- set_val_str (arr, 7, nmc_property_ipv4_get_ignore_auto_dns (setting));
- set_val_str (arr, 8, nmc_property_ipv4_get_dhcp_client_id (setting));
- set_val_str (arr, 9, nmc_property_ipv4_get_dhcp_send_hostname (setting));
- set_val_str (arr, 10, nmc_property_ipv4_get_dhcp_hostname (setting));
- set_val_str (arr, 11, nmc_property_ipv4_get_never_default (setting));
- set_val_str (arr, 12, nmc_property_ipv4_get_may_fail (setting));
+ set_val_str (arr, 4, nmc_property_ip_get_addresses (setting));
+ set_val_str (arr, 5, nmc_property_ipv4_get_gateway (setting));
+ set_val_str (arr, 6, nmc_property_ipv4_get_routes (setting));
+ set_val_str (arr, 7, nmc_property_ipv4_get_route_metric (setting));
+ set_val_str (arr, 8, nmc_property_ipv4_get_ignore_auto_routes (setting));
+ set_val_str (arr, 9, nmc_property_ipv4_get_ignore_auto_dns (setting));
+ set_val_str (arr, 10, nmc_property_ipv4_get_dhcp_client_id (setting));
+ set_val_str (arr, 11, nmc_property_ipv4_get_dhcp_send_hostname (setting));
+ set_val_str (arr, 12, nmc_property_ipv4_get_dhcp_hostname (setting));
+ set_val_str (arr, 13, nmc_property_ipv4_get_never_default (setting));
+ set_val_str (arr, 14, nmc_property_ipv4_get_may_fail (setting));
g_ptr_array_add (nmc->output_data, arr);
print_data (nmc); /* Print all data */
@@ -6779,7 +6802,7 @@ setting_ip4_config_details (NMSetting *setting, NmCli *nmc, const char *one_pro
static gboolean
setting_ip6_config_details (NMSetting *setting, NmCli *nmc, const char *one_prop, gboolean secrets)
{
- NMSettingIP6Config *s_ip6 = NM_SETTING_IP6_CONFIG (setting);
+ NMSettingIPConfig *s_ip6 = NM_SETTING_IP_CONFIG (setting);
NmcOutputField *tmpl, *arr;
size_t tmpl_len;
@@ -6797,14 +6820,17 @@ setting_ip6_config_details (NMSetting *setting, NmCli *nmc, const char *one_pro
set_val_str (arr, 1, nmc_property_ipv6_get_method (setting));
set_val_str (arr, 2, nmc_property_ipv6_get_dns (setting));
set_val_str (arr, 3, nmc_property_ipv6_get_dns_search (setting));
- set_val_str (arr, 4, nmc_property_ipv6_get_addresses (setting));
- set_val_str (arr, 5, nmc_property_ipv6_get_routes (setting));
- set_val_str (arr, 6, nmc_property_ipv6_get_ignore_auto_routes (setting));
- set_val_str (arr, 7, nmc_property_ipv6_get_ignore_auto_dns (setting));
- set_val_str (arr, 8, nmc_property_ipv6_get_never_default (setting));
- set_val_str (arr, 9, nmc_property_ipv6_get_may_fail (setting));
- set_val_str (arr, 10, nmc_property_ipv6_get_ip6_privacy (setting));
- set_val_str (arr, 11, nmc_property_ipv6_get_dhcp_hostname (setting));
+ set_val_str (arr, 4, nmc_property_ip_get_addresses (setting));
+ set_val_str (arr, 5, nmc_property_ipv6_get_gateway (setting));
+ set_val_str (arr, 6, nmc_property_ipv6_get_routes (setting));
+ set_val_str (arr, 7, nmc_property_ipv6_get_route_metric (setting));
+ set_val_str (arr, 8, nmc_property_ipv6_get_ignore_auto_routes (setting));
+ set_val_str (arr, 9, nmc_property_ipv6_get_ignore_auto_dns (setting));
+ set_val_str (arr, 10, nmc_property_ipv6_get_never_default (setting));
+ set_val_str (arr, 11, nmc_property_ipv6_get_may_fail (setting));
+ set_val_str (arr, 12, nmc_property_ipv6_get_ip6_privacy (setting));
+ set_val_str (arr, 13, nmc_property_ipv6_get_dhcp_send_hostname (setting));
+ set_val_str (arr, 14, nmc_property_ipv6_get_dhcp_hostname (setting));
g_ptr_array_add (nmc->output_data, arr);
print_data (nmc); /* Print all data */
diff --git a/clients/cli/settings.h b/clients/cli/settings.h
index ad74fc9053..3c4c814fd2 100644
--- a/clients/cli/settings.h
+++ b/clients/cli/settings.h
@@ -30,8 +30,8 @@ void nmc_properties_cleanup (void);
NMSetting *nmc_setting_new_for_name (const char *name);
void nmc_setting_custom_init (NMSetting *setting);
-void nmc_setting_ip4_connect_handlers (NMSettingIP4Config *setting);
-void nmc_setting_ip6_connect_handlers (NMSettingIP6Config *setting);
+void nmc_setting_ip4_connect_handlers (NMSettingIPConfig *setting);
+void nmc_setting_ip6_connect_handlers (NMSettingIPConfig *setting);
void nmc_setting_wireless_connect_handlers (NMSettingWireless *setting);
void nmc_setting_connection_connect_handlers (NMSettingConnection *setting, NMConnection *connection);
diff --git a/clients/common/nm-polkit-listener.c b/clients/common/nm-polkit-listener.c
new file mode 100644
index 0000000000..82df1b2de2
--- /dev/null
+++ b/clients/common/nm-polkit-listener.c
@@ -0,0 +1,415 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2014 Red Hat, Inc.
+ */
+
+/**
+ * SECTION:nm-polkit-listener
+ * @short_description: A polkit agent listener
+ *
+ * #NMPolkitListener is the polkit agent listener used by nmcli and nmtui.
+ * http://www.freedesktop.org/software/polkit/docs/latest/index.html
+ *
+ * For an example polkit agent you can look at polkit source tree:
+ * http://cgit.freedesktop.org/polkit/tree/src/polkitagent/polkitagenttextlistener.c
+ * http://cgit.freedesktop.org/polkit/tree/src/programs/pkttyagent.c
+ * or LXDE polkit agent:
+ * http://git.lxde.org/gitweb/?p=debian/lxpolkit.git;a=blob;f=src/lxpolkit-listener.c
+ * https://github.com/lxde/lxqt-policykit/tree/master/src
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <glib/gi18n-lib.h>
+
+#include "nm-glib-compat.h"
+#include "nm-polkit-listener.h"
+
+G_DEFINE_TYPE (NMPolkitListener, nm_polkit_listener, POLKIT_AGENT_TYPE_LISTENER)
+
+#define NM_POLKIT_LISTENER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_POLKIT_LISTENER, NMPolkitListenerPrivate))
+
+typedef struct {
+ gpointer reg_handle; /* handle of polkit agent registration */
+
+ GSimpleAsyncResult *simple;
+ PolkitAgentSession *active_session;
+ gulong cancel_id;
+ GCancellable *cancellable;
+
+ char *action_id;
+ char *message;
+ char *icon_name;
+ char *identity;
+
+ /* callbacks */
+ NMPolkitListenerOnRequestFunc on_request_callback;
+ NMPolkitListenerOnShowInfoFunc on_show_info_callback;
+ NMPolkitListenerOnShowErrorFunc on_show_error_callback;
+ NMPolkitListenerOnCompletedFunc on_completed_callback;
+ gpointer request_callback_data;
+} NMPolkitListenerPrivate;
+
+
+static void
+on_request (PolkitAgentSession *session,
+ const char *request,
+ gboolean echo_on,
+ gpointer user_data)
+{
+ NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (user_data);
+ char *response = NULL;
+
+ if (priv->on_request_callback) {
+ response = priv->on_request_callback (request, priv->action_id,
+ priv->message, priv->icon_name,
+ priv->identity, echo_on,
+ priv->request_callback_data);
+ }
+
+ if (response) {
+ polkit_agent_session_response (session, response);
+ g_free (response);
+ } else {
+ //FIXME: polkit_agent_session_cancel() should emit "completed", but it doesn't work for me ???
+ //polkit_agent_session_cancel (session);
+ polkit_agent_session_response (session, "");
+ }
+}
+
+static void
+on_show_info (PolkitAgentSession *session,
+ const char *text,
+ gpointer user_data)
+{
+ NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (user_data);
+
+ if (priv->on_show_info_callback)
+ priv->on_show_info_callback (text);
+}
+
+static void
+on_show_error (PolkitAgentSession *session,
+ const char *text,
+ gpointer user_data)
+{
+ NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (user_data);
+
+ if (priv->on_show_error_callback)
+ priv->on_show_error_callback (text);
+}
+
+static void
+on_completed (PolkitAgentSession *session,
+ gboolean gained_authorization,
+ gpointer user_data)
+{
+ NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (user_data);
+
+ if (priv->on_completed_callback)
+ priv->on_completed_callback (gained_authorization);
+
+ g_simple_async_result_complete_in_idle (priv->simple);
+
+ g_object_unref (priv->simple);
+ g_object_unref (priv->active_session);
+ if (priv->cancellable) {
+ g_cancellable_disconnect (priv->cancellable, priv->cancel_id);
+ g_object_unref (priv->cancellable);
+ }
+
+ priv->simple = NULL;
+ priv->active_session = NULL;
+ priv->cancel_id = 0;
+
+ g_clear_pointer (&priv->action_id, g_free);
+ g_clear_pointer (&priv->message, g_free);
+ g_clear_pointer (&priv->icon_name, g_free);
+ g_clear_pointer (&priv->identity, g_free);
+}
+
+static void
+on_cancelled (GCancellable *cancellable, gpointer user_data)
+{
+ NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (user_data);
+
+ polkit_agent_session_cancel (priv->active_session);
+}
+
+static gint
+compare_users (gconstpointer a, gconstpointer b)
+{
+ char *user;
+ int ret;
+
+ if (POLKIT_IS_UNIX_USER (a))
+ user = g_strdup (polkit_unix_user_get_name (POLKIT_UNIX_USER (a)));
+ else
+ user = polkit_identity_to_string (POLKIT_IDENTITY (a));
+
+ ret = g_strcmp0 ((const char *) user, (const char *) b);
+ g_free (user);
+ return ret;
+}
+
+static PolkitIdentity *
+choose_identity (GList *identities)
+{
+ const char *user;
+ GList *elem;
+
+ /* Choose identity. First try current user, then root, and else
+ * take the firts one */
+ user = getenv("USER");
+ elem = g_list_find_custom (identities, user, (GCompareFunc) compare_users);
+ if (!elem) {
+ elem = g_list_find_custom (identities, "root", (GCompareFunc) compare_users);
+ if (!elem)
+ elem = identities;
+ }
+
+ return elem->data;
+}
+
+static void
+initiate_authentication (PolkitAgentListener *listener,
+ const char *action_id,
+ const char *message,
+ const char *icon_name,
+ PolkitDetails *details,
+ const char *cookie,
+ GList *identities,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (listener);
+ GSimpleAsyncResult *simple;
+ PolkitIdentity *identity;
+
+ simple = g_simple_async_result_new (G_OBJECT (listener),
+ callback,
+ user_data,
+ initiate_authentication);
+ if (priv->active_session != NULL) {
+ g_simple_async_result_set_error (simple,
+ POLKIT_ERROR,
+ POLKIT_ERROR_FAILED,
+ _("An authentication session is already underway."));
+ g_simple_async_result_complete_in_idle (simple);
+ g_object_unref (simple);
+ return;
+ }
+
+ /* Choose identity */
+ identity = choose_identity (identities);
+
+ priv->active_session = polkit_agent_session_new (identity, cookie);
+ g_signal_connect (priv->active_session,
+ "completed",
+ G_CALLBACK (on_completed),
+ listener);
+ g_signal_connect (priv->active_session,
+ "request",
+ G_CALLBACK (on_request),
+ listener);
+ g_signal_connect (priv->active_session,
+ "show-info",
+ G_CALLBACK (on_show_info),
+ listener);
+ g_signal_connect (priv->active_session,
+ "show-error",
+ G_CALLBACK (on_show_error),
+ listener);
+
+ priv->action_id = g_strdup (action_id);
+ priv->message = g_strdup (message);
+ priv->icon_name = g_strdup (icon_name);
+ if (POLKIT_IS_UNIX_USER (identity))
+ priv->identity = g_strdup (polkit_unix_user_get_name (POLKIT_UNIX_USER (identity)));
+ else
+ priv->identity = polkit_identity_to_string (identity);
+
+ priv->simple = simple;
+ priv->cancellable = g_object_ref (cancellable);
+ priv->cancel_id = g_cancellable_connect (cancellable,
+ G_CALLBACK (on_cancelled),
+ listener,
+ NULL);
+
+ polkit_agent_session_initiate (priv->active_session);
+}
+
+static gboolean
+initiate_authentication_finish (PolkitAgentListener *listener,
+ GAsyncResult *result,
+ GError **error)
+{
+ return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error);
+}
+
+
+static void
+nm_polkit_listener_init (NMPolkitListener *agent)
+{
+}
+
+static void
+nm_polkit_listener_finalize (GObject *object)
+{
+ NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (object);
+
+ if (priv->reg_handle)
+ polkit_agent_listener_unregister (priv->reg_handle);
+
+ g_free (priv->action_id);
+ g_free (priv->message);
+ g_free (priv->icon_name);
+ g_free (priv->identity);
+
+ G_OBJECT_CLASS (nm_polkit_listener_parent_class)->finalize (object);
+}
+
+static void
+nm_polkit_listener_class_init (NMPolkitListenerClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ PolkitAgentListenerClass *pkal_class = POLKIT_AGENT_LISTENER_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (NMPolkitListenerPrivate));
+
+ gobject_class->finalize = nm_polkit_listener_finalize;
+
+ pkal_class->initiate_authentication = initiate_authentication;
+ pkal_class->initiate_authentication_finish = initiate_authentication_finish;
+}
+
+/**
+ * nm_polkit_listener_new:
+ * @for_session: %TRUE for registering the polkit agent for the user session,
+ * %FALSE for registering it for the running process
+ * @error: location to store error, or %NULL
+ *
+ * Creates a new #NMPolkitListener and registers it as a polkit agent.
+ *
+ * Returns: a new #NMPolkitListener
+ */
+PolkitAgentListener *
+nm_polkit_listener_new (gboolean for_session, GError **error)
+{
+ PolkitAgentListener *listener;
+ PolkitSubject* session;
+ NMPolkitListenerPrivate *priv;
+
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ listener = g_object_new (NM_TYPE_POLKIT_LISTENER, NULL);
+ priv = NM_POLKIT_LISTENER_GET_PRIVATE (listener);
+
+ if (for_session)
+ session = polkit_unix_session_new_for_process_sync (getpid (), NULL, NULL);
+ else
+ session = polkit_unix_process_new_for_owner (getpid (), 0, getuid ());
+
+ priv->reg_handle = polkit_agent_listener_register (listener, POLKIT_AGENT_REGISTER_FLAGS_NONE,
+ session, NULL, NULL, error);
+ if (!priv->reg_handle) {
+ g_object_unref (listener);
+ g_object_unref (session);
+ return NULL;
+ }
+
+ return listener;
+}
+
+/**
+ * nm_polkit_listener_set_request_callback:
+ * @self: a #NMPolkitListener object
+ * @request_callback: callback to install for polkit requests
+ * @request_callback_data: usaer data passed to request_callback when it is called
+ *
+ * Set a callback for "request" signal. The callback will be invoked when polkit
+ * requests an authorization.
+ */
+void
+nm_polkit_listener_set_request_callback (NMPolkitListener *self,
+ NMPolkitListenerOnRequestFunc request_callback,
+ gpointer request_callback_data)
+{
+ NMPolkitListenerPrivate *priv;
+
+ g_return_if_fail (NM_IS_POLKIT_LISTENER (self));
+
+ priv = NM_POLKIT_LISTENER_GET_PRIVATE (self);
+
+ priv->on_request_callback = request_callback;
+ priv->request_callback_data = request_callback_data;
+}
+
+/**
+ * nm_polkit_listener_set_show_info_callback:
+ * @self: a #NMPolkitListener object
+ * @show_info_callback: callback to install for polkit show info trigger
+ *
+ * Set a callback for "show-info" signal. The callback will be invoked when polkit
+ * has an info text to display.
+ */
+void
+nm_polkit_listener_set_show_info_callback (NMPolkitListener *self,
+ NMPolkitListenerOnShowInfoFunc show_info_callback)
+{
+ g_return_if_fail (NM_IS_POLKIT_LISTENER (self));
+
+ NM_POLKIT_LISTENER_GET_PRIVATE (self)->on_show_info_callback = show_info_callback;
+}
+
+/**
+ * nm_polkit_listener_set_show_error_callback:
+ * @self: a #NMPolkitListener object
+ * @show_error_callback: callback to install for polkit show error trigger
+ *
+ * Set a callback for "show-error" signal. The callback will be invoked when polkit
+ * has an error text to display.
+ */
+void
+nm_polkit_listener_set_show_error_callback (NMPolkitListener *self,
+ NMPolkitListenerOnShowErrorFunc show_error_callback)
+{
+ g_return_if_fail (NM_IS_POLKIT_LISTENER (self));
+
+ NM_POLKIT_LISTENER_GET_PRIVATE (self)->on_show_error_callback = show_error_callback;
+}
+
+/**
+ * nm_polkit_listener_set_completed_callback:
+ * @self: a #NMPolkitListener object
+ * @completed_callback: callback to install for polkit completing authorization
+ *
+ * Set a callback for "completed" signal. The callback will be invoked when polkit
+ * completed the request.
+ */
+void
+nm_polkit_listener_set_completed_callback (NMPolkitListener *self,
+ NMPolkitListenerOnCompletedFunc completed_callback)
+{
+ g_return_if_fail (NM_IS_POLKIT_LISTENER (self));
+
+ NM_POLKIT_LISTENER_GET_PRIVATE (self)->on_completed_callback = completed_callback;
+}
diff --git a/clients/common/nm-polkit-listener.h b/clients/common/nm-polkit-listener.h
new file mode 100644
index 0000000000..3cd7501924
--- /dev/null
+++ b/clients/common/nm-polkit-listener.h
@@ -0,0 +1,104 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2014 Red Hat, Inc.
+ */
+
+#ifndef __NM_POLKIT_LISTENER_H__
+#define __NM_POLKIT_LISTENER_H__
+
+#include <glib.h>
+
+#define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE
+#include <polkitagent/polkitagent.h>
+
+G_BEGIN_DECLS
+
+#define NM_TYPE_POLKIT_LISTENER (nm_polkit_listener_get_type ())
+#define NM_POLKIT_LISTENER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_POLKIT_LISTENER, NMPolkitListener))
+#define NM_POLKIT_LISTENER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_POLKIT_LISTENER, NMPolkitListenerClass))
+#define NM_IS_POLKIT_LISTENER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_POLKIT_LISTENER))
+#define NM_IS_POLKIT_LISTENER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_POLKIT_LISTENER))
+#define NM_POLKIT_LISTENER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_POLKIT_LISTENER, NMPolkitListenerClass))
+
+/**
+ * NMPolkitListenerOnRequestFunc:
+ * @request: the request asked by polkit agent
+ * @action_id: the action_id of the polkit request
+ * @message: the message of the polkit request
+ * @icon_name: the icon name of the polkit request
+ * @user: user name
+ * @echo_on: whether the response to the request should be echoed to the screen
+ * @user_data: user data for the callback
+ *
+ * Called as a result of a request by polkit. The function should obtain response
+ * to the request from user, i.e. get the password required.
+ */
+typedef char * (*NMPolkitListenerOnRequestFunc) (const char *request,
+ const char *action_id,
+ const char *message,
+ const char *icon_name,
+ const char *user,
+ gboolean echo_on,
+ gpointer user_data);
+/**
+ * NMPolkitListenerOnShowInfoFunc:
+ * @text: the info text from polkit
+ *
+ * Called as a result of show-info signal by polkit.
+ */
+typedef void (*NMPolkitListenerOnShowInfoFunc) (const char *text);
+/**
+ * NMPolkitListenerOnShowErrorFunc:
+ * @text: the error text from polkit
+ *
+ * Called as a result of show-error signal by polkit.
+ */
+typedef void (*NMPolkitListenerOnShowErrorFunc) (const char *text);
+/**
+ * NMPolkitListenerCompletedFunc:
+ * @gained_authorization: whether the autorization was successful
+ *
+ * Called as a result of completed signal by polkit.
+ */
+typedef void (*NMPolkitListenerOnCompletedFunc) (gboolean gained_authorization);
+
+
+typedef struct {
+ PolkitAgentListener parent;
+
+} NMPolkitListener;
+
+typedef struct {
+ PolkitAgentListenerClass parent;
+
+} NMPolkitListenerClass;
+
+GType nm_polkit_listener_get_type (void);
+
+PolkitAgentListener* nm_polkit_listener_new (gboolean for_session, GError **error);
+void nm_polkit_listener_set_request_callback (NMPolkitListener *self,
+ NMPolkitListenerOnRequestFunc request_callback,
+ gpointer request_callback_data);
+void nm_polkit_listener_set_show_info_callback (NMPolkitListener *self,
+ NMPolkitListenerOnShowInfoFunc show_info_callback);
+void nm_polkit_listener_set_show_error_callback (NMPolkitListener *self,
+ NMPolkitListenerOnShowErrorFunc show_error_callback);
+void nm_polkit_listener_set_completed_callback (NMPolkitListener *self,
+ NMPolkitListenerOnCompletedFunc completed_callback);
+
+G_END_DECLS
+
+#endif /* __NM_POLKIT_LISTENER_H__ */
diff --git a/clients/tui/nmt-secret-agent.c b/clients/common/nm-secret-agent-simple.c
index 40ab9c14cb..3848bf9302 100644
--- a/clients/tui/nmt-secret-agent.c
+++ b/clients/common/nm-secret-agent-simple.c
@@ -18,10 +18,10 @@
*/
/**
- * SECTION:nmt-secret-agent
- * @short_description: A secret agent
+ * SECTION:nm-secret-agent-simple
+ * @short_description: A simple secret agent for NetworkManager
*
- * #NmtSecretAgent is the secret agent used by nmtui-connect.
+ * #NMSecretAgentSimple is the secret agent used by nmtui-connect and nmcli.
*
* This is a stripped-down version of gnome-shell's ShellNetworkAgent,
* with bits of the corresponding JavaScript code squished down into
@@ -34,12 +34,11 @@
#include <string.h>
#include <glib/gi18n-lib.h>
-#include "nmt-secret-agent.h"
-#include "nmt-newt.h"
+#include "nm-secret-agent-simple.h"
-G_DEFINE_TYPE (NmtSecretAgent, nmt_secret_agent, NM_TYPE_SECRET_AGENT)
+G_DEFINE_TYPE (NMSecretAgentSimple, nm_secret_agent_simple, NM_TYPE_SECRET_AGENT)
-#define NMT_SECRET_AGENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_SECRET_AGENT, NmtSecretAgentPrivate))
+#define NM_SECRET_AGENT_SIMPLE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimplePrivate))
enum {
REQUEST_SECRETS,
@@ -50,45 +49,47 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
typedef struct {
- NmtSecretAgent *self;
+ NMSecretAgentSimple *self;
gchar *request_id;
NMConnection *connection;
gchar **hints;
NMSecretAgentGetSecretsFunc callback;
gpointer callback_data;
-} NmtSecretAgentRequest;
+} NMSecretAgentSimpleRequest;
typedef struct {
- /* <char *request_id, NmtSecretAgentRequest *request> */
+ /* <char *request_id, NMSecretAgentSimpleRequest *request> */
GHashTable *requests;
-} NmtSecretAgentPrivate;
+
+ char *path;
+} NMSecretAgentSimplePrivate;
static void
-nmt_secret_agent_request_free (gpointer data)
+nm_secret_agent_simple_request_free (gpointer data)
{
- NmtSecretAgentRequest *request = data;
+ NMSecretAgentSimpleRequest *request = data;
g_object_unref (request->self);
g_object_unref (request->connection);
g_strfreev (request->hints);
- g_slice_free (NmtSecretAgentRequest, request);
+ g_slice_free (NMSecretAgentSimpleRequest, request);
}
static void
-nmt_secret_agent_init (NmtSecretAgent *agent)
+nm_secret_agent_simple_init (NMSecretAgentSimple *agent)
{
- NmtSecretAgentPrivate *priv = NMT_SECRET_AGENT_GET_PRIVATE (agent);
+ NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (agent);
priv->requests = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, nmt_secret_agent_request_free);
+ g_free, nm_secret_agent_simple_request_free);
}
static void
-nmt_secret_agent_finalize (GObject *object)
+nm_secret_agent_simple_finalize (GObject *object)
{
- NmtSecretAgentPrivate *priv = NMT_SECRET_AGENT_GET_PRIVATE (object);
+ NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (object);
GError *error;
GHashTableIter iter;
gpointer key;
@@ -100,7 +101,7 @@ nmt_secret_agent_finalize (GObject *object)
g_hash_table_iter_init (&iter, priv->requests);
while (g_hash_table_iter_next (&iter, &key, &value)) {
- NmtSecretAgentRequest *request = value;
+ NMSecretAgentSimpleRequest *request = value;
request->callback (NM_SECRET_AGENT (object),
request->connection,
@@ -111,7 +112,9 @@ nmt_secret_agent_finalize (GObject *object)
g_hash_table_destroy (priv->requests);
g_error_free (error);
- G_OBJECT_CLASS (nmt_secret_agent_parent_class)->finalize (object);
+ g_free (priv->path);
+
+ G_OBJECT_CLASS (nm_secret_agent_simple_parent_class)->finalize (object);
}
static gboolean
@@ -129,7 +132,7 @@ strv_has (gchar **haystack,
}
/**
- * NmtSecretAgentSecret:
+ * NMSecretAgentSimpleSecret:
* @name: the user-visible name of the secret. Eg, "WEP Passphrase".
* @value: the value of the secret
* @password: %TRUE if this secret represents a password, %FALSE
@@ -139,38 +142,37 @@ strv_has (gchar **haystack,
*/
typedef struct {
- NmtSecretAgentSecret base;
+ NMSecretAgentSimpleSecret base;
NMSetting *setting;
char *property;
-
- NmtNewtEntryValidator validator;
- gpointer validator_data;
-} NmtSecretAgentSecretReal;
+} NMSecretAgentSimpleSecretReal;
static void
-nmt_secret_agent_secret_free (NmtSecretAgentSecret *secret)
+nm_secret_agent_simple_secret_free (NMSecretAgentSimpleSecret *secret)
{
- NmtSecretAgentSecretReal *real = (NmtSecretAgentSecretReal *)secret;
+ NMSecretAgentSimpleSecretReal *real = (NMSecretAgentSimpleSecretReal *)secret;
g_free (secret->name);
+ g_free (secret->prop_name);
g_free (secret->value);
g_free (real->property);
g_clear_object (&real->setting);
- g_slice_free (NmtSecretAgentSecretReal, real);
+ g_slice_free (NMSecretAgentSimpleSecretReal, real);
}
-static NmtSecretAgentSecret *
-nmt_secret_agent_secret_new (const char *name,
- NMSetting *setting,
- const char *property,
- gboolean password)
+static NMSecretAgentSimpleSecret *
+nm_secret_agent_simple_secret_new (const char *name,
+ NMSetting *setting,
+ const char *property,
+ gboolean password)
{
- NmtSecretAgentSecretReal *real;
+ NMSecretAgentSimpleSecretReal *real;
- real = g_slice_new0 (NmtSecretAgentSecretReal);
+ real = g_slice_new0 (NMSecretAgentSimpleSecretReal);
real->base.name = g_strdup (name);
+ real->base.prop_name = g_strdup_printf ("%s.%s", nm_setting_get_name (setting), property);
real->base.password = password;
if (setting) {
@@ -184,12 +186,12 @@ nmt_secret_agent_secret_new (const char *name,
}
static gboolean
-add_8021x_secrets (NmtSecretAgentRequest *request,
- GPtrArray *secrets)
+add_8021x_secrets (NMSecretAgentSimpleRequest *request,
+ GPtrArray *secrets)
{
NMSetting8021x *s_8021x = nm_connection_get_setting_802_1x (request->connection);
const char *eap_method;
- NmtSecretAgentSecret *secret;
+ NMSecretAgentSimpleSecret *secret;
eap_method = nm_setting_802_1x_get_eap_method (s_8021x, 0);
if (!eap_method)
@@ -203,29 +205,29 @@ add_8021x_secrets (NmtSecretAgentRequest *request,
* is not visible here since we only care about phase2 authentication
* (and don't even care of which one)
*/
- secret = nmt_secret_agent_secret_new (_("Username"),
- NM_SETTING (s_8021x),
- NM_SETTING_802_1X_IDENTITY,
- FALSE);
+ secret = nm_secret_agent_simple_secret_new (_("Username"),
+ NM_SETTING (s_8021x),
+ NM_SETTING_802_1X_IDENTITY,
+ FALSE);
g_ptr_array_add (secrets, secret);
- secret = nmt_secret_agent_secret_new (_("Password"),
- NM_SETTING (s_8021x),
- NM_SETTING_802_1X_PASSWORD,
- TRUE);
+ secret = nm_secret_agent_simple_secret_new (_("Password"),
+ NM_SETTING (s_8021x),
+ NM_SETTING_802_1X_PASSWORD,
+ TRUE);
g_ptr_array_add (secrets, secret);
return TRUE;
}
if (!strcmp (eap_method, "tls")) {
- secret = nmt_secret_agent_secret_new (_("Identity"),
- NM_SETTING (s_8021x),
- NM_SETTING_802_1X_IDENTITY,
- FALSE);
+ secret = nm_secret_agent_simple_secret_new (_("Identity"),
+ NM_SETTING (s_8021x),
+ NM_SETTING_802_1X_IDENTITY,
+ FALSE);
g_ptr_array_add (secrets, secret);
- secret = nmt_secret_agent_secret_new (_("Private key password"),
- NM_SETTING (s_8021x),
- NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD,
- TRUE);
+ secret = nm_secret_agent_simple_secret_new (_("Private key password"),
+ NM_SETTING (s_8021x),
+ NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD,
+ TRUE);
g_ptr_array_add (secrets, secret);
return TRUE;
}
@@ -234,21 +236,21 @@ add_8021x_secrets (NmtSecretAgentRequest *request,
}
static gboolean
-add_wireless_secrets (NmtSecretAgentRequest *request,
- GPtrArray *secrets)
+add_wireless_secrets (NMSecretAgentSimpleRequest *request,
+ GPtrArray *secrets)
{
NMSettingWirelessSecurity *s_wsec = nm_connection_get_setting_wireless_security (request->connection);
const char *key_mgmt = nm_setting_wireless_security_get_key_mgmt (s_wsec);
- NmtSecretAgentSecret *secret;
+ NMSecretAgentSimpleSecret *secret;
if (!key_mgmt)
return FALSE;
if (!strcmp (key_mgmt, "wpa-none") || !strcmp (key_mgmt, "wpa-psk")) {
- secret = nmt_secret_agent_secret_new (_("Password"),
- NM_SETTING (s_wsec),
- NM_SETTING_WIRELESS_SECURITY_PSK,
- TRUE);
+ secret = nm_secret_agent_simple_secret_new (_("Password"),
+ NM_SETTING (s_wsec),
+ NM_SETTING_WIRELESS_SECURITY_PSK,
+ TRUE);
g_ptr_array_add (secrets, secret);
return TRUE;
}
@@ -259,26 +261,22 @@ add_wireless_secrets (NmtSecretAgentRequest *request,
index = nm_setting_wireless_security_get_wep_tx_keyidx (s_wsec);
key = g_strdup_printf ("wep-key%d", index);
- secret = nmt_secret_agent_secret_new (_("Key"),
- NM_SETTING (s_wsec),
- key,
- TRUE);
+ secret = nm_secret_agent_simple_secret_new (_("Key"),
+ NM_SETTING (s_wsec),
+ key,
+ TRUE);
g_free (key);
-#if 0
- nmt_secret_agent_secret_set_validator (secret, static_wep_key_validate,
- nm_setting_wireless_security_get_wep_key_type (s_wsec));
-#endif
g_ptr_array_add (secrets, secret);
return TRUE;
}
if (!strcmp (key_mgmt, "iee8021x")) {
if (!g_strcmp0 (nm_setting_wireless_security_get_auth_alg (s_wsec), "leap")) {
- secret = nmt_secret_agent_secret_new (_("Password"),
- NM_SETTING (s_wsec),
- NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD,
- TRUE);
+ secret = nm_secret_agent_simple_secret_new (_("Password"),
+ NM_SETTING (s_wsec),
+ NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD,
+ TRUE);
g_ptr_array_add (secrets, secret);
return TRUE;
} else
@@ -292,40 +290,40 @@ add_wireless_secrets (NmtSecretAgentRequest *request,
}
static gboolean
-add_pppoe_secrets (NmtSecretAgentRequest *request,
- GPtrArray *secrets)
+add_pppoe_secrets (NMSecretAgentSimpleRequest *request,
+ GPtrArray *secrets)
{
NMSettingPppoe *s_pppoe = nm_connection_get_setting_pppoe (request->connection);
- NmtSecretAgentSecret *secret;
+ NMSecretAgentSimpleSecret *secret;
- secret = nmt_secret_agent_secret_new (_("Username"),
- NM_SETTING (s_pppoe),
- NM_SETTING_PPPOE_USERNAME,
- FALSE);
+ secret = nm_secret_agent_simple_secret_new (_("Username"),
+ NM_SETTING (s_pppoe),
+ NM_SETTING_PPPOE_USERNAME,
+ FALSE);
g_ptr_array_add (secrets, secret);
- secret = nmt_secret_agent_secret_new (_("Service"),
- NM_SETTING (s_pppoe),
- NM_SETTING_PPPOE_SERVICE,
- FALSE);
+ secret = nm_secret_agent_simple_secret_new (_("Service"),
+ NM_SETTING (s_pppoe),
+ NM_SETTING_PPPOE_SERVICE,
+ FALSE);
g_ptr_array_add (secrets, secret);
- secret = nmt_secret_agent_secret_new (_("Password"),
- NM_SETTING (s_pppoe),
- NM_SETTING_PPPOE_PASSWORD,
- TRUE);
+ secret = nm_secret_agent_simple_secret_new (_("Password"),
+ NM_SETTING (s_pppoe),
+ NM_SETTING_PPPOE_PASSWORD,
+ TRUE);
g_ptr_array_add (secrets, secret);
return TRUE;
}
static void
-request_secrets_from_ui (NmtSecretAgentRequest *request)
+request_secrets_from_ui (NMSecretAgentSimpleRequest *request)
{
GPtrArray *secrets;
- NmtSecretAgentSecret *secret;
+ NMSecretAgentSimpleSecret *secret;
const char *title;
char *msg;
gboolean ok = TRUE;
- secrets = g_ptr_array_new_with_free_func ((GDestroyNotify) nmt_secret_agent_secret_free);
+ secrets = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_secret_agent_simple_secret_free);
if (nm_connection_is_type (request->connection, NM_SETTING_WIRELESS_SETTING_NAME)) {
NMSettingWireless *s_wireless;
@@ -349,10 +347,10 @@ request_secrets_from_ui (NmtSecretAgentRequest *request)
title = _("Wired 802.1X authentication");
msg = NULL;
- secret = nmt_secret_agent_secret_new (_("Network name"),
- NM_SETTING (s_con),
- NM_SETTING_CONNECTION_ID,
- FALSE);
+ secret = nm_secret_agent_simple_secret_new (_("Network name"),
+ NM_SETTING (s_con),
+ NM_SETTING_CONNECTION_ID,
+ FALSE);
g_ptr_array_add (secrets, secret);
ok = add_8021x_secrets (request, secrets);
} else if (nm_connection_is_type (request->connection, NM_SETTING_PPPOE_SETTING_NAME)) {
@@ -367,20 +365,20 @@ request_secrets_from_ui (NmtSecretAgentRequest *request)
title = _("PIN code required");
msg = g_strdup (_("PIN code is needed for the mobile broadband device"));
- secret = nmt_secret_agent_secret_new (_("PIN"),
- NM_SETTING (s_gsm),
- NM_SETTING_GSM_PIN,
- FALSE);
+ secret = nm_secret_agent_simple_secret_new (_("PIN"),
+ NM_SETTING (s_gsm),
+ NM_SETTING_GSM_PIN,
+ FALSE);
g_ptr_array_add (secrets, secret);
} else {
title = _("Mobile broadband network password");
msg = g_strdup_printf (_("A password is required to connect to '%s'."),
nm_connection_get_id (request->connection));
- secret = nmt_secret_agent_secret_new (_("Password"),
- NM_SETTING (s_gsm),
- NM_SETTING_GSM_PASSWORD,
- TRUE);
+ secret = nm_secret_agent_simple_secret_new (_("Password"),
+ NM_SETTING (s_gsm),
+ NM_SETTING_GSM_PASSWORD,
+ TRUE);
g_ptr_array_add (secrets, secret);
}
} else if (nm_connection_is_type (request->connection, NM_SETTING_CDMA_SETTING_NAME)) {
@@ -390,10 +388,10 @@ request_secrets_from_ui (NmtSecretAgentRequest *request)
msg = g_strdup_printf (_("A password is required to connect to '%s'."),
nm_connection_get_id (request->connection));
- secret = nmt_secret_agent_secret_new (_("Password"),
- NM_SETTING (s_cdma),
- NM_SETTING_CDMA_PASSWORD,
- TRUE);
+ secret = nm_secret_agent_simple_secret_new (_("Password"),
+ NM_SETTING (s_cdma),
+ NM_SETTING_CDMA_PASSWORD,
+ TRUE);
g_ptr_array_add (secrets, secret);
} else if (nm_connection_is_type (request->connection, NM_SETTING_BLUETOOTH_SETTING_NAME)) {
NMSetting *setting;
@@ -406,10 +404,10 @@ request_secrets_from_ui (NmtSecretAgentRequest *request)
msg = g_strdup_printf (_("A password is required to connect to '%s'."),
nm_connection_get_id (request->connection));
- secret = nmt_secret_agent_secret_new (_("Password"),
- setting,
- "password",
- TRUE);
+ secret = nm_secret_agent_simple_secret_new (_("Password"),
+ setting,
+ "password",
+ TRUE);
g_ptr_array_add (secrets, secret);
} else
ok = FALSE;
@@ -424,18 +422,18 @@ request_secrets_from_ui (NmtSecretAgentRequest *request)
}
static void
-nmt_secret_agent_get_secrets (NMSecretAgent *agent,
- NMConnection *connection,
- const gchar *connection_path,
- const gchar *setting_name,
- const gchar **hints,
- NMSecretAgentGetSecretsFlags flags,
- NMSecretAgentGetSecretsFunc callback,
- gpointer callback_data)
+nm_secret_agent_simple_get_secrets (NMSecretAgent *agent,
+ NMConnection *connection,
+ const gchar *connection_path,
+ const gchar *setting_name,
+ const gchar **hints,
+ NMSecretAgentGetSecretsFlags flags,
+ NMSecretAgentGetSecretsFunc callback,
+ gpointer callback_data)
{
- NmtSecretAgent *self = NMT_SECRET_AGENT (agent);
- NmtSecretAgentPrivate *priv = NMT_SECRET_AGENT_GET_PRIVATE (self);
- NmtSecretAgentRequest *request;
+ NMSecretAgentSimple *self = NM_SECRET_AGENT_SIMPLE (agent);
+ NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (self);
+ NMSecretAgentSimpleRequest *request;
NMSettingConnection *s_con;
const char *connection_type;
char *request_id;
@@ -453,6 +451,14 @@ nmt_secret_agent_get_secrets (NMSecretAgent *agent,
return;
}
+ if (priv->path && g_strcmp0 (priv->path, connection_path) != 0) {
+ /* We only handle requests for connection with @path if set. */
+ error = g_error_new (NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_FAILED,
+ "Request for %s secrets doesn't match path %s",
+ request_id, priv->path);
+ goto nope;
+ }
+
s_con = nm_connection_get_setting_connection (connection);
connection_type = nm_setting_connection_get_connection_type (s_con);
@@ -470,7 +476,7 @@ nmt_secret_agent_get_secrets (NMSecretAgent *agent,
goto nope;
}
- request = g_slice_new (NmtSecretAgentRequest);
+ request = g_slice_new (NMSecretAgentSimpleRequest);
request->self = g_object_ref (self);
request->connection = g_object_ref (connection);
request->hints = g_strdupv ((gchar **)hints);
@@ -483,33 +489,33 @@ nmt_secret_agent_get_secrets (NMSecretAgent *agent,
}
/**
- * nmt_secret_agent_response:
- * @self: the #NmtSecretAgent
+ * nm_secret_agent_simple_response:
+ * @self: the #NMSecretAgentSimple
* @request_id: the request ID being responded to
* @secrets: (allow-none): the array of secrets, or %NULL
*
- * Response to a #NmtSecretAgent::get-secrets signal.
+ * Response to a #NMSecretAgentSimple::get-secrets signal.
*
* If the user provided secrets, the caller should set the
* corresponding <literal>value</literal> fields in the
- * #NmtSecretAgentSecrets (freeing any initial values they had), and
- * pass the array to nmt_secret_agent_response(). If the user
+ * #NMSecretAgentSimpleSecrets (freeing any initial values they had), and
+ * pass the array to nm_secret_agent_simple_response(). If the user
* cancelled the request, @secrets should be NULL.
*/
void
-nmt_secret_agent_response (NmtSecretAgent *self,
- const char *request_id,
- GPtrArray *secrets)
+nm_secret_agent_simple_response (NMSecretAgentSimple *self,
+ const char *request_id,
+ GPtrArray *secrets)
{
- NmtSecretAgentPrivate *priv;
- NmtSecretAgentRequest *request;
+ NMSecretAgentSimplePrivate *priv;
+ NMSecretAgentSimpleRequest *request;
GVariant *dict = NULL;
GError *error = NULL;
int i;
- g_return_if_fail (NMT_IS_SECRET_AGENT (self));
+ g_return_if_fail (NM_IS_SECRET_AGENT_SIMPLE (self));
- priv = NMT_SECRET_AGENT_GET_PRIVATE (self);
+ priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (self);
request = g_hash_table_lookup (priv->requests, request_id);
g_return_if_fail (request != NULL);
@@ -521,7 +527,7 @@ nmt_secret_agent_response (NmtSecretAgent *self,
settings = g_hash_table_new (g_str_hash, g_str_equal);
for (i = 0; i < secrets->len; i++) {
- NmtSecretAgentSecretReal *secret = secrets->pdata[i];
+ NMSecretAgentSimpleSecretReal *secret = secrets->pdata[i];
setting_builder = g_hash_table_lookup (settings, nm_setting_get_name (secret->setting));
if (!setting_builder) {
@@ -553,69 +559,71 @@ nmt_secret_agent_response (NmtSecretAgent *self,
}
static void
-nmt_secret_agent_cancel_get_secrets (NMSecretAgent *agent,
- const gchar *connection_path,
- const gchar *setting_name)
+nm_secret_agent_simple_cancel_get_secrets (NMSecretAgent *agent,
+ const gchar *connection_path,
+ const gchar *setting_name)
{
/* We don't support cancellation. Sorry! */
}
static void
-nmt_secret_agent_save_secrets (NMSecretAgent *agent,
- NMConnection *connection,
- const gchar *connection_path,
- NMSecretAgentSaveSecretsFunc callback,
- gpointer callback_data)
+nm_secret_agent_simple_save_secrets (NMSecretAgent *agent,
+ NMConnection *connection,
+ const gchar *connection_path,
+ NMSecretAgentSaveSecretsFunc callback,
+ gpointer callback_data)
{
/* We don't support secret storage */
- callback (agent, connection, NULL, callback_data);}
+ callback (agent, connection, NULL, callback_data);
+}
static void
-nmt_secret_agent_delete_secrets (NMSecretAgent *agent,
- NMConnection *connection,
- const gchar *connection_path,
- NMSecretAgentDeleteSecretsFunc callback,
- gpointer callback_data)
+nm_secret_agent_simple_delete_secrets (NMSecretAgent *agent,
+ NMConnection *connection,
+ const gchar *connection_path,
+ NMSecretAgentDeleteSecretsFunc callback,
+ gpointer callback_data)
{
/* We don't support secret storage, so there's nothing to delete. */
callback (agent, connection, NULL, callback_data);
}
void
-nmt_secret_agent_class_init (NmtSecretAgentClass *klass)
+nm_secret_agent_simple_class_init (NMSecretAgentSimpleClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
NMSecretAgentClass *agent_class = NM_SECRET_AGENT_CLASS (klass);
- g_type_class_add_private (klass, sizeof (NmtSecretAgentPrivate));
+ g_type_class_add_private (klass, sizeof (NMSecretAgentSimplePrivate));
- gobject_class->finalize = nmt_secret_agent_finalize;
+ gobject_class->finalize = nm_secret_agent_simple_finalize;
- agent_class->get_secrets = nmt_secret_agent_get_secrets;
- agent_class->cancel_get_secrets = nmt_secret_agent_cancel_get_secrets;
- agent_class->save_secrets = nmt_secret_agent_save_secrets;
- agent_class->delete_secrets = nmt_secret_agent_delete_secrets;
+ agent_class->get_secrets = nm_secret_agent_simple_get_secrets;
+ agent_class->cancel_get_secrets = nm_secret_agent_simple_cancel_get_secrets;
+ agent_class->save_secrets = nm_secret_agent_simple_save_secrets;
+ agent_class->delete_secrets = nm_secret_agent_simple_delete_secrets;
/**
- * NmtSecretAgent::request-secrets:
- * @agent: the #NmtSecretAgent
+ * NMSecretAgentSimple::request-secrets:
+ * @agent: the #NMSecretAgentSimple
* @request_id: request ID, to eventually pass to
- * nmt_secret_agent_response().
+ * nm_secret_agent_simple_response().
* @title: a title for the password dialog
* @prompt: a prompt message for the password dialog
- * @secrets: (element-type #NmtSecretAgentSecret): array of secrets
+ * @secrets: (element-type #NMSecretAgentSimpleSecret): array of secrets
* being requested.
*
* Emitted when the agent requires secrets from the user.
*
- * The application should create a password dialog (eg,
- * #NmtPasswordDialog) with the given title and prompt, and an
- * entry for each element of @secrets. If any of the secrets
- * already have a <literal>value</literal> filled in, the
- * corresponding entry should be initialized to that value.
+ * The application should ask user for the secrets. For example,
+ * nmtui should create a password dialog (#NmtPasswordDialog)
+ * with the given title and prompt, and an entry for each
+ * element of @secrets. If any of the secrets already have a
+ * <literal>value</literal> filled in, the corresponding entry
+ * should be initialized to that value.
*
* When the dialog is complete, the app must call
- * nmt_secret_agent_response() with the results.
+ * nm_secret_agent_simple_response() with the results.
*/
signals[REQUEST_SECRETS] = g_signal_new ("request-secrets",
G_TYPE_FROM_CLASS (klass),
@@ -629,16 +637,24 @@ nmt_secret_agent_class_init (NmtSecretAgentClass *klass)
}
/**
- * nmt_secret_agent_new:
+ * nm_secret_agent_simple_new:
+ * @name: the identifier of secret agent
+ * @path: (allow-none): the path of the connection the agent handle secrets for,
+ * or %NULL to handle requests for all connections
*
- * Creates a new #NmtSecretAgent.
+ * Creates a new #NMSecretAgentSimple.
*
- * Returns: a new #NmtSecretAgent
+ * Returns: a new #NMSecretAgentSimple
*/
NMSecretAgent *
-nmt_secret_agent_new (void)
+nm_secret_agent_simple_new (const char *name, const char *path)
{
- return g_initable_new (NMT_TYPE_SECRET_AGENT, NULL, NULL,
- NM_SECRET_AGENT_IDENTIFIER, "nmtui",
- NULL);
+ NMSecretAgent *agent;
+
+ agent = g_initable_new (NM_TYPE_SECRET_AGENT_SIMPLE, NULL, NULL,
+ NM_SECRET_AGENT_IDENTIFIER, name,
+ NULL);
+ NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (agent)->path = g_strdup (path);
+
+ return agent;
}
diff --git a/clients/common/nm-secret-agent-simple.h b/clients/common/nm-secret-agent-simple.h
new file mode 100644
index 0000000000..b1cc304492
--- /dev/null
+++ b/clients/common/nm-secret-agent-simple.h
@@ -0,0 +1,57 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2013 - 2014 Red Hat, Inc.
+ */
+
+#ifndef __NM_SECRET_AGENT_SIMPLE_H__
+#define __NM_SECRET_AGENT_SIMPLE_H__
+
+#include <NetworkManager.h>
+
+G_BEGIN_DECLS
+
+#define NM_TYPE_SECRET_AGENT_SIMPLE (nm_secret_agent_simple_get_type ())
+#define NM_SECRET_AGENT_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SECRET_AGENT, NMSecretAgentSimple))
+#define NM_SECRET_AGENT_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SECRET_AGENT, NMSecretAgentSimpleClass))
+#define NM_IS_SECRET_AGENT_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SECRET_AGENT))
+#define NM_IS_SECRET_AGENT_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SECRET_AGENT))
+#define NM_SECRET_AGENT_SIMPLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SECRET_AGENT, NMSecretAgentSimpleClass))
+
+typedef struct {
+ NMSecretAgent parent;
+
+} NMSecretAgentSimple;
+
+typedef struct {
+ NMSecretAgentClass parent;
+
+} NMSecretAgentSimpleClass;
+
+typedef struct {
+ char *name, *prop_name, *value;
+ gboolean password;
+} NMSecretAgentSimpleSecret;
+
+GType nm_secret_agent_simple_get_type (void);
+
+NMSecretAgent *nm_secret_agent_simple_new (const char *name, const char *path);
+void nm_secret_agent_simple_response (NMSecretAgentSimple *self,
+ const char *request_id,
+ GPtrArray *secrets);
+
+G_END_DECLS
+
+#endif /* __NM_SECRET_AGENT_SIMPLE_H__ */
diff --git a/clients/tui/Makefile.am b/clients/tui/Makefile.am
index fb5ad8fcf0..290ef155a3 100644
--- a/clients/tui/Makefile.am
+++ b/clients/tui/Makefile.am
@@ -10,6 +10,7 @@ AM_CPPFLAGS= \
-I$(top_srcdir)/libnm \
-I$(top_builddir)/libnm \
-I$(srcdir)/newt \
+ -I$(top_srcdir)/clients/common \
$(GLIB_CFLAGS) \
$(NEWT_CFLAGS) \
$(GUDEV_CFLAGS) \
@@ -106,14 +107,14 @@ nmtui_SOURCES = \
nmt-route-entry.h \
nmt-route-table.c \
nmt-route-table.h \
- nmt-secret-agent.c \
- nmt-secret-agent.h \
nmt-slave-list.c \
nmt-slave-list.h \
nmt-utils.c \
nmt-utils.h \
nmt-widget-list.c \
nmt-widget-list.h \
+ $(srcdir)/../common/nm-secret-agent-simple.c \
+ $(srcdir)/../common/nm-secret-agent-simple.h \
$(NULL)
nmtui_LDADD = \
diff --git a/clients/tui/nm-editor-bindings.c b/clients/tui/nm-editor-bindings.c
index e3b210dec6..5560f83ca6 100644
--- a/clients/tui/nm-editor-bindings.c
+++ b/clients/tui/nm-editor-bindings.c
@@ -72,10 +72,10 @@ nm_editor_bindings_init (void)
}
static gboolean
-ip_string_parse (const char *text,
- int family,
- gpointer addr,
- guint32 *prefix)
+parse_addr_prefix (const char *text,
+ int family,
+ char **addr,
+ guint32 *prefix)
{
const char *slash;
char *addrstr, *end;
@@ -83,17 +83,11 @@ ip_string_parse (const char *text,
slash = strchr (text, '/');
- if (slash) {
- if (!prefix)
- return FALSE;
+ if (slash)
addrstr = g_strndup (text, slash - text);
- } else
+ else
addrstr = g_strdup (text);
- valid = (inet_pton (family, addrstr, addr) == 1);
- g_free (addrstr);
-
- if (!valid)
- return FALSE;
+ valid = nm_utils_ipaddr_valid (family, addrstr);
if (slash) {
*prefix = strtoul (slash + 1, &end, 10);
@@ -109,19 +103,24 @@ ip_string_parse (const char *text,
*prefix = 128;
}
+ if (addr && valid)
+ *addr = addrstr;
+ else
+ g_free (addrstr);
return valid;
}
static gboolean
-ip4_addresses_with_prefix_to_strv (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
+ip_addresses_with_prefix_to_strv (GBinding *binding,
+ const GValue *source_value,
+ GValue *target_value,
+ gpointer user_data)
{
GPtrArray *addrs;
- NMIP4Address *addr;
- guint32 addrbytes, prefix;
- char buf[INET_ADDRSTRLEN], **strings;
+ NMIPAddress *addr;
+ const char *addrstr;
+ guint32 prefix;
+ char **strings;
int i;
addrs = g_value_get_boxed (source_value);
@@ -129,14 +128,12 @@ ip4_addresses_with_prefix_to_strv (GBinding *binding,
for (i = 0; i < addrs->len; i++) {
addr = addrs->pdata[i];
- addrbytes = nm_ip4_address_get_address (addr);
- prefix = nm_ip4_address_get_prefix (addr);
+ addrstr = nm_ip_address_get_address (addr);
+ prefix = nm_ip_address_get_prefix (addr);
- if (addrbytes) {
- strings[i] = g_strdup_printf ("%s/%d",
- inet_ntop (AF_INET, &addrbytes, buf, sizeof (buf)),
- (int) prefix);
- } else
+ if (addrstr)
+ strings[i] = g_strdup_printf ("%s/%d", addrstr, (int) prefix);
+ else
strings[i] = g_strdup ("");
}
@@ -145,38 +142,43 @@ ip4_addresses_with_prefix_to_strv (GBinding *binding,
}
static gboolean
-ip4_addresses_with_prefix_from_strv (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
+ip_addresses_with_prefix_from_strv (GBinding *binding,
+ const GValue *source_value,
+ GValue *target_value,
+ gpointer user_data)
{
+ int family = GPOINTER_TO_INT (user_data);
char **strings;
GPtrArray *addrs;
- NMIP4Address *addr;
- guint32 addrbytes, prefix;
+ NMIPAddress *addr;
+ char *addrstr;
+ guint32 prefix;
int i;
strings = g_value_get_boxed (source_value);
- /* Fetch the original property value, so as to preserve the gateway elements */
+ /* Fetch the original property value, so as to preserve their extra attributes */
g_object_get (g_binding_get_source (binding),
g_binding_get_source_property (binding), &addrs,
NULL);
for (i = 0; strings[i]; i++) {
if (i >= addrs->len) {
- addr = nm_ip4_address_new ();
- nm_ip4_address_set_prefix (addr, 32);
+ if (family == AF_INET)
+ addr = nm_ip_address_new (AF_INET, "0.0.0.0", 32, NULL);
+ else
+ addr = nm_ip_address_new (AF_INET6, "::", 128, NULL);
g_ptr_array_add (addrs, addr);
} else
addr = addrs->pdata[i];
- if (!ip_string_parse (strings[i], AF_INET, &addrbytes, &prefix)) {
+ if (!parse_addr_prefix (strings[i], family, &addrstr, &prefix)) {
g_ptr_array_unref (addrs);
return FALSE;
}
- nm_ip4_address_set_address (addr, addrbytes);
- nm_ip4_address_set_prefix (addr, prefix);
+ nm_ip_address_set_address (addr, addrstr);
+ nm_ip_address_set_prefix (addr, prefix);
+ g_free (addrstr);
}
g_ptr_array_set_size (addrs, i);
@@ -185,7 +187,8 @@ ip4_addresses_with_prefix_from_strv (GBinding *binding,
}
/**
- * nm_editor_bind_ip4_addresses_with_prefix_to_strv:
+ * nm_editor_bind_ip_addresses_with_prefix_to_strv:
+ * @family: the IP address family
* @source: the source object (eg, an #NMSettingIP4Config)
* @source_property: the property on @source to bind (eg,
* %NM_SETTING_IP4_CONFIG_ADDRESSES)
@@ -194,44 +197,43 @@ ip4_addresses_with_prefix_from_strv (GBinding *binding,
* (eg, "strings")
* @flags: %GBindingFlags
*
- * Binds the #GPtrArray-of-#NMIP4Address property @source_property on @source to
+ * Binds the #GPtrArray-of-#NMIPAddress property @source_property on @source to
* the %G_TYPE_STRV property @target_property on @target.
*
- * Each #NMIP4Address in @source_property will be converted to a string of the
- * form "ip.ad.dr.ess/prefix" in @target_property (and vice versa if
- * %G_BINDING_BIDIRECTIONAL) is specified. The "gateway" fields in
- * @source_property are ignored when converting to strings, and unmodified when
- * converting from strings.
+ * Each #NMIPAddress in @source_property will be converted to a string of the
+ * form "ip.ad.dr.ess/prefix" or "ip:ad:dr:ess/prefix" in @target_property (and
+ * vice versa if %G_BINDING_BIDIRECTIONAL) is specified.
*/
void
-nm_editor_bind_ip4_addresses_with_prefix_to_strv (gpointer source,
- const gchar *source_property,
- gpointer target,
- const gchar *target_property,
- GBindingFlags flags)
+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)
{
g_object_bind_property_full (source, source_property,
target, target_property,
flags,
- ip4_addresses_with_prefix_to_strv,
- ip4_addresses_with_prefix_from_strv,
- NULL, NULL);
+ ip_addresses_with_prefix_to_strv,
+ ip_addresses_with_prefix_from_strv,
+ GINT_TO_POINTER (family), NULL);
}
static gboolean
-ip4_addresses_check_and_copy (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
+ip_addresses_check_and_copy (GBinding *binding,
+ const GValue *source_value,
+ GValue *target_value,
+ gpointer user_data)
{
+ int family = GPOINTER_TO_INT (user_data);
char **strings;
- guint32 addr;
int i;
strings = g_value_get_boxed (source_value);
for (i = 0; strings[i]; i++) {
- if (!ip_string_parse (strings[i], AF_INET, &addr, NULL))
+ if (!nm_utils_ipaddr_valid (family, strings[i]))
return FALSE;
}
@@ -240,7 +242,8 @@ ip4_addresses_check_and_copy (GBinding *binding,
}
/**
- * nm_editor_bind_ip4_addresses_to_strv:
+ * nm_editor_bind_ip_addresses_to_strv:
+ * @family: the IP address family
* @source: the source object (eg, an #NMSettingIP4Config)
* @source_property: the property on @source to bind (eg,
* %NM_SETTING_IP4_CONFIG_DNS)
@@ -251,599 +254,42 @@ ip4_addresses_check_and_copy (GBinding *binding,
*
* Binds the %G_TYPE_STRV property @source_property on @source to the
* %G_TYPE_STRV property @target_property on @target, verifying that
- * each string is a valid IPv4 address when copying.
+ * each string is a valid address of type @family when copying.
*/
void
-nm_editor_bind_ip4_addresses_to_strv (gpointer source,
- const gchar *source_property,
- gpointer target,
- const gchar *target_property,
- GBindingFlags flags)
-{
- g_object_bind_property_full (source, source_property,
- target, target_property,
- flags,
- ip4_addresses_check_and_copy,
- ip4_addresses_check_and_copy,
- NULL, NULL);
-}
-
-static gboolean
-ip4_gateway_to_string (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
-{
- GPtrArray *addrs;
- NMIP4Address *addr;
- guint32 gateway = 0;
- const char *str;
- char buf[INET_ADDRSTRLEN];
- int i;
-
- addrs = g_value_get_boxed (source_value);
- for (i = 0; i < addrs->len; i++) {
- addr = addrs->pdata[i];
- gateway = nm_ip4_address_get_gateway (addr);
- if (gateway)
- break;
- }
-
- if (gateway)
- str = inet_ntop (AF_INET, &gateway, buf, sizeof (buf));
- else
- str = "";
- g_value_set_string (target_value, str);
- return TRUE;
-}
-
-static gboolean
-ip4_gateway_from_string (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
-{
- const char *text;
- GPtrArray *addrs;
- NMIP4Address *addr;
- guint32 addrbytes;
- int i;
-
- text = g_value_get_string (source_value);
- if (!ip_string_parse (text, AF_INET, &addrbytes, NULL))
- return FALSE;
-
- /* Fetch the original property value, so as to preserve the IP address elements */
- g_object_get (g_binding_get_source (binding),
- g_binding_get_source_property (binding), &addrs,
- NULL);
- if (!addrs->len) {
- g_ptr_array_unref (addrs);
- return FALSE;
- }
- addr = addrs->pdata[0];
- if (addrbytes == nm_ip4_address_get_gateway (addr)) {
- g_ptr_array_unref (addrs);
- return FALSE;
- }
- nm_ip4_address_set_gateway (addr, addrbytes);
-
- for (i = 1; i < addrs->len; i++) {
- addr = addrs->pdata[i];
- nm_ip4_address_set_gateway (addr, 0);
- }
-
- g_value_take_boxed (target_value, addrs);
- return TRUE;
-}
-
-/**
- * nm_editor_bind_ip4_gateway_to_string:
- * @source: the source object (eg, an #NMSettingIP4Config)
- * @source_property: the property on @source to bind (eg,
- * %NM_SETTING_IP4_CONFIG_ADDRESSES)
- * @target: the target object (eg, an #NmtNewtEntry)
- * @target_property: the property on @target to bind
- * (eg, "text")
- * @flags: %GBindingFlags
- *
- * Binds the #GPtrArray-of-#NMIP4Route property @source_property on @source to
- * the %G_TYPE_STRING property @target_property on @target.
- *
- * Specifically, this binds the "gateway" field of the first address in
- * @source_property; all other addresses in @source_property are ignored, and
- * its "address" and "prefix" fields are unmodified.
- */
-void
-nm_editor_bind_ip4_gateway_to_string (gpointer source,
- const gchar *source_property,
- gpointer target,
- const gchar *target_property,
- GBindingFlags flags)
-{
- g_object_bind_property_full (source, source_property,
- target, target_property,
- flags,
- ip4_gateway_to_string,
- ip4_gateway_from_string,
- NULL, NULL);
-}
-
-static gboolean
-ip4_route_transform_to_dest_string (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
-{
- NMIP4Route *route;
- char buf[INET_ADDRSTRLEN], *string;
- guint32 addrbytes;
-
- route = g_value_get_boxed (source_value);
- if (route)
- addrbytes = nm_ip4_route_get_dest (route);
- else
- addrbytes = 0;
-
- if (addrbytes) {
- string = g_strdup_printf ("%s/%d",
- inet_ntop (AF_INET, &addrbytes, buf, sizeof (buf)),
- (int) nm_ip4_route_get_prefix (route));
- g_value_take_string (target_value, string);
- } else
- g_value_set_string (target_value, "");
- return TRUE;
-}
-
-static gboolean
-ip4_route_transform_to_next_hop_string (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
-{
- NMIP4Route *route;
- char buf[INET_ADDRSTRLEN];
- guint32 addrbytes;
-
- route = g_value_get_boxed (source_value);
- if (route)
- addrbytes = nm_ip4_route_get_next_hop (route);
- else
- addrbytes = 0;
-
- if (addrbytes)
- inet_ntop (AF_INET, &addrbytes, buf, sizeof (buf));
- else
- buf[0] = '\0';
- g_value_set_string (target_value, buf);
- return TRUE;
-}
-
-static gboolean
-ip4_route_transform_to_metric_string (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
-{
- NMIP4Route *route;
- char *string;
-
- route = g_value_get_boxed (source_value);
- if (route && nm_ip4_route_get_dest (route)) {
- string = g_strdup_printf ("%lu", (gulong) nm_ip4_route_get_metric (route));
- g_value_take_string (target_value, string);
- } else
- g_value_set_string (target_value, "");
- return TRUE;
-}
-
-static gboolean
-ip4_route_transform_from_dest_string (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
-{
- NMIP4Route *route;
- const char *text;
- guint32 addrbytes, prefix;
-
- text = g_value_get_string (source_value);
- if (!ip_string_parse (text, AF_INET, &addrbytes, &prefix))
- return FALSE;
-
- /* Fetch the original property value */
- g_object_get (g_binding_get_source (binding),
- g_binding_get_source_property (binding), &route,
- NULL);
-
- nm_ip4_route_set_dest (route, addrbytes);
- nm_ip4_route_set_prefix (route, prefix);
-
- g_value_take_boxed (target_value, route);
- return TRUE;
-}
-
-static gboolean
-ip4_route_transform_from_next_hop_string (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
-{
- NMIP4Route *route;
- const char *text;
- guint32 addrbytes;
-
- text = g_value_get_string (source_value);
- if (*text) {
- if (!ip_string_parse (text, AF_INET, &addrbytes, NULL))
- return FALSE;
- } else
- addrbytes = 0;
-
- /* Fetch the original property value */
- g_object_get (g_binding_get_source (binding),
- g_binding_get_source_property (binding), &route,
- NULL);
-
- nm_ip4_route_set_next_hop (route, addrbytes);
-
- g_value_take_boxed (target_value, route);
- return TRUE;
-}
-
-static gboolean
-ip4_route_transform_from_metric_string (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
-{
- NMIP4Route *route;
- const char *text;
- guint32 metric;
-
- text = g_value_get_string (source_value);
- metric = strtoul (text, NULL, 10);
-
- /* Fetch the original property value */
- g_object_get (g_binding_get_source (binding),
- g_binding_get_source_property (binding), &route,
- NULL);
-
- nm_ip4_route_set_metric (route, metric);
-
- g_value_take_boxed (target_value, route);
- return TRUE;
-}
-
-/**
- * nm_editor_bind_ip4_route_to_strings:
- * @source: the source object
- * @source_property: the source property
- * @dest_target: the target object for the route's destionation
- * @dest_target_property: the property on @dest_target
- * @next_hop_target: the target object for the route's next hop
- * @next_hop_target_property: the property on @next_hop_target
- * @metric_target: the target object for the route's metric
- * @metric_target_property: the property on @metric_target
- * @flags: %GBindingFlags
- *
- * Binds the #NMIP4Route-valued property @source_property on @source to the
- * three indicated string-valued target properties (and vice versa if
- * %G_BINDING_BIDIRECTIONAL is specified).
- *
- * @dest_target_property should be an "address/prefix" string, as with
- * nm_editor_bind_ip4_addresses_with_prefix_to_strv(). @next_hop_target_property
- * is a plain IP address, and @metric_target_property is a number.
- */
-void
-nm_editor_bind_ip4_route_to_strings (gpointer source,
+nm_editor_bind_ip_addresses_to_strv (int family,
+ 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,
+ gpointer target,
+ const gchar *target_property,
GBindingFlags flags)
{
g_object_bind_property_full (source, source_property,
- dest_target, dest_target_property,
- flags,
- ip4_route_transform_to_dest_string,
- ip4_route_transform_from_dest_string,
- NULL, NULL);
- g_object_bind_property_full (source, source_property,
- next_hop_target, next_hop_target_property,
- flags,
- ip4_route_transform_to_next_hop_string,
- ip4_route_transform_from_next_hop_string,
- NULL, NULL);
- g_object_bind_property_full (source, source_property,
- metric_target, metric_target_property,
+ target, target_property,
flags,
- ip4_route_transform_to_metric_string,
- ip4_route_transform_from_metric_string,
- NULL, NULL);
+ ip_addresses_check_and_copy,
+ ip_addresses_check_and_copy,
+ GINT_TO_POINTER (family), NULL);
}
-#define IP6_ADDRESS_SET(addr) ( addr \
- && memcmp (addr, &in6addr_any, sizeof (struct in6_addr)) != 0)
-
static gboolean
-ip6_addresses_with_prefix_to_strv (GBinding *binding,
+ip_route_transform_to_dest_string (GBinding *binding,
const GValue *source_value,
GValue *target_value,
gpointer user_data)
{
- GPtrArray *addrs;
- NMIP6Address *addr;
- const struct in6_addr *addrbytes;
- guint prefix;
- char **strings, buf[INET6_ADDRSTRLEN];
- int i;
-
- addrs = g_value_get_boxed (source_value);
- strings = g_new0 (char *, addrs->len + 1);
-
- for (i = 0; i < addrs->len; i++) {
- addr = addrs->pdata[i];
- addrbytes = nm_ip6_address_get_address (addr);
- prefix = nm_ip6_address_get_prefix (addr);
-
- if (IP6_ADDRESS_SET (addrbytes)) {
- strings[i] = g_strdup_printf ("%s/%d",
- inet_ntop (AF_INET6, addrbytes, buf, sizeof (buf)),
- prefix);
- } else
- strings[i] = g_strdup ("");
- }
-
- g_value_take_boxed (target_value, strings);
- return TRUE;
-}
-
-static gboolean
-ip6_addresses_with_prefix_from_strv (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
-{
- char **strings;
- GPtrArray *addrs;
- NMIP6Address *addr;
- struct in6_addr addrbytes;
- guint32 prefix;
- int i;
-
- strings = g_value_get_boxed (source_value);
-
- /* Fetch the original property value, so as to preserve the gateway elements */
- g_object_get (g_binding_get_source (binding),
- g_binding_get_source_property (binding), &addrs,
- NULL);
-
- for (i = 0; strings[i]; i++) {
- if (i >= addrs->len) {
- addr = nm_ip6_address_new ();
- nm_ip6_address_set_prefix (addr, 128);
- g_ptr_array_add (addrs, addr);
- } else
- addr = addrs->pdata[i];
-
- if (!ip_string_parse (strings[i], AF_INET6, &addrbytes, &prefix)) {
- g_ptr_array_unref (addrs);
- return FALSE;
- }
-
- nm_ip6_address_set_address (addr, &addrbytes);
- nm_ip6_address_set_prefix (addr, prefix);
- }
-
- g_ptr_array_set_size (addrs, i);
- g_value_set_boxed (target_value, addrs);
- return TRUE;
-}
-
-/**
- * nm_editor_bind_ip6_addresses_with_prefix_to_strv:
- * @source: the source object (eg, an #NMSettingIP6Config)
- * @source_property: the property on @source to bind (eg,
- * %NM_SETTING_IP6_CONFIG_ADDRESSES)
- * @target: the target object (eg, an #NmtAddressList)
- * @target_property: the property on @target to bind
- * (eg, "strings")
- * @flags: %GBindingFlags
- *
- * Binds the #GPtrArray-of-#NMIP6Address property @source_property on @source to
- * the %G_TYPE_STRV property @target_property on @target.
- *
- * Each #NMIP6Address in triplet in @source_property will be converted to a
- * string of the form "ip::ad:dr:ess/prefix" in @target_property (and vice versa
- * if %G_BINDING_BIDIRECTIONAL) is specified. The "gateway" fields in
- * @source_property are ignored when converting to strings, and unmodified when
- * converting from strings.
- */
-void
-nm_editor_bind_ip6_addresses_with_prefix_to_strv (gpointer source,
- const gchar *source_property,
- gpointer target,
- const gchar *target_property,
- GBindingFlags flags)
-{
- g_object_bind_property_full (source, source_property,
- target, target_property,
- flags,
- ip6_addresses_with_prefix_to_strv,
- ip6_addresses_with_prefix_from_strv,
- NULL, NULL);
-}
-
-static gboolean
-ip6_addresses_check_and_copy (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
-{
- char **strings;
- struct in6_addr addr;
- int i;
-
- strings = g_value_get_boxed (source_value);
-
- for (i = 0; strings[i]; i++) {
- if (!ip_string_parse (strings[i], AF_INET6, &addr, NULL))
- return FALSE;
- }
-
- g_value_set_boxed (target_value, strings);
- return TRUE;
-}
-
-/**
- * nm_editor_bind_ip6_addresses_to_strv:
- * @source: the source object (eg, an #NMSettingIP6Config)
- * @source_property: the property on @source to bind (eg,
- * %NM_SETTING_IP6_CONFIG_DNS)
- * @target: the target object (eg, an #NmtAddressList)
- * @target_property: the property on @target to bind
- * (eg, "strings")
- * @flags: %GBindingFlags
- *
- * Binds the %G_TYPE_STRV property @source_property on @source to the
- * %G_TYPE_STRV property @target_property on @target, verifying that
- * each string is a valid IPv6 address when copying.
- */
-void
-nm_editor_bind_ip6_addresses_to_strv (gpointer source,
- const gchar *source_property,
- gpointer target,
- const gchar *target_property,
- GBindingFlags flags)
-{
- g_object_bind_property_full (source, source_property,
- target, target_property,
- flags,
- ip6_addresses_check_and_copy,
- ip6_addresses_check_and_copy,
- NULL, NULL);
-}
-
-static gboolean
-ip6_gateway_to_string (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
-{
- GPtrArray *addrs;
- NMIP6Address *addr;
- const struct in6_addr *gateway;
- char buf[INET6_ADDRSTRLEN];
- const char *str;
-
- addrs = g_value_get_boxed (source_value);
- if (addrs->len == 0)
- return FALSE;
-
- addr = addrs->pdata[0];
- gateway = nm_ip6_address_get_gateway (addr);
-
- if (IP6_ADDRESS_SET (gateway))
- str = inet_ntop (AF_INET6, gateway, buf, sizeof (buf));
- else
- str = "";
- g_value_set_string (target_value, str);
- return TRUE;
-}
-
-static gboolean
-ip6_gateway_from_string (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
-{
- GPtrArray *addrs;
- const char *text;
- NMIP6Address *addr;
- struct in6_addr gateway;
- int i;
-
- text = g_value_get_string (source_value);
- if (!ip_string_parse (text, AF_INET6, &gateway, NULL))
- return FALSE;
-
- /* Fetch the original property value, so as to preserve the IP address elements */
- g_object_get (g_binding_get_source (binding),
- g_binding_get_source_property (binding), &addrs,
- NULL);
- if (!addrs->len) {
- g_ptr_array_unref (addrs);
- return FALSE;
- }
-
- addr = addrs->pdata[0];
- nm_ip6_address_set_gateway (addr, &gateway);
-
- for (i = 1; i < addrs->len; i++) {
- addr = addrs->pdata[i];
- nm_ip6_address_set_gateway (addr, &in6addr_any);
- }
-
- g_value_take_boxed (target_value, addrs);
- return TRUE;
-}
-
-/**
- * nm_editor_bind_ip6_gateway_to_string:
- * @source: the source object (eg, an #NMSettingIP6Config)
- * @source_property: the property on @source to bind (eg,
- * %NM_SETTING_IP6_CONFIG_ADDRESSES)
- * @target: the target object (eg, an #NmtNewtEntry)
- * @target_property: the property on @target to bind
- * (eg, "text")
- * @flags: %GBindingFlags
- *
- * Binds the #GPtrArray-of-#NMIP6Address property @source_property on @source to
- * the %G_TYPE_STRING property @target_property on @target.
- *
- * Specifically, this binds the "gateway" field of the first address in
- * @source_property; all other addresses in @source_property are ignored, and
- * its "address" and "prefix" fields are unmodified.
- */
-void
-nm_editor_bind_ip6_gateway_to_string (gpointer source,
- const gchar *source_property,
- gpointer target,
- const gchar *target_property,
- GBindingFlags flags)
-{
- g_object_bind_property_full (source, source_property,
- target, target_property,
- flags,
- ip6_gateway_to_string,
- ip6_gateway_from_string,
- NULL, NULL);
-}
-
-static gboolean
-ip6_route_transform_to_dest_string (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
-{
- NMIP6Route *route;
- char buf[INET6_ADDRSTRLEN], *string;
- const struct in6_addr *addrbytes;
+ NMIPRoute *route;
+ const char *addrstr;
+ char *string;
route = g_value_get_boxed (source_value);
if (route)
- addrbytes = nm_ip6_route_get_dest (route);
+ addrstr = nm_ip_route_get_dest (route);
else
- addrbytes = &in6addr_any;
+ addrstr = NULL;
- if (IP6_ADDRESS_SET (addrbytes)) {
- string = g_strdup_printf ("%s/%d",
- inet_ntop (AF_INET6, addrbytes, buf, sizeof (buf)),
- (int) nm_ip6_route_get_prefix (route));
+ if (addrstr) {
+ string = g_strdup_printf ("%s/%d", addrstr, (int) nm_ip_route_get_prefix (route));
g_value_take_string (target_value, string);
} else
g_value_set_string (target_value, "");
@@ -851,41 +297,38 @@ ip6_route_transform_to_dest_string (GBinding *binding,
}
static gboolean
-ip6_route_transform_to_next_hop_string (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
+ip_route_transform_to_next_hop_string (GBinding *binding,
+ const GValue *source_value,
+ GValue *target_value,
+ gpointer user_data)
{
- NMIP6Route *route;
- char buf[INET6_ADDRSTRLEN];
- const struct in6_addr *addrbytes;
+ NMIPRoute *route;
+ const char *addrstr;
route = g_value_get_boxed (source_value);
- if (route)
- addrbytes = nm_ip6_route_get_next_hop (route);
- else
- addrbytes = &in6addr_any;
+ if (route) {
+ addrstr = nm_ip_route_get_next_hop (route);
+ if (!addrstr)
+ addrstr = "";
+ } else
+ addrstr = "";
- if (IP6_ADDRESS_SET (addrbytes))
- inet_ntop (AF_INET6, addrbytes, buf, sizeof (buf));
- else
- buf[0] = '\0';
- g_value_set_string (target_value, buf);
+ g_value_set_string (target_value, addrstr);
return TRUE;
}
static gboolean
-ip6_route_transform_to_metric_string (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
+ip_route_transform_to_metric_string (GBinding *binding,
+ const GValue *source_value,
+ GValue *target_value,
+ gpointer user_data)
{
- NMIP6Route *route;
+ NMIPRoute *route;
char *string;
route = g_value_get_boxed (source_value);
- if (route && IP6_ADDRESS_SET (nm_ip6_route_get_dest (route))) {
- string = g_strdup_printf ("%lu", (gulong) nm_ip6_route_get_metric (route));
+ if (route && nm_ip_route_get_dest (route) && nm_ip_route_get_metric (route) != -1) {
+ string = g_strdup_printf ("%lu", (gulong) nm_ip_route_get_metric (route));
g_value_take_string (target_value, string);
} else
g_value_set_string (target_value, "");
@@ -893,18 +336,19 @@ ip6_route_transform_to_metric_string (GBinding *binding,
}
static gboolean
-ip6_route_transform_from_dest_string (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
+ip_route_transform_from_dest_string (GBinding *binding,
+ const GValue *source_value,
+ GValue *target_value,
+ gpointer user_data)
{
- NMIP6Route *route;
+ int family = GPOINTER_TO_INT (user_data);
+ NMIPRoute *route;
const char *text;
- struct in6_addr addrbytes;
+ char *addrstr;
guint32 prefix;
text = g_value_get_string (source_value);
- if (!ip_string_parse (text, AF_INET6, &addrbytes, &prefix))
+ if (!parse_addr_prefix (text, family, &addrstr, &prefix))
return FALSE;
/* Fetch the original property value */
@@ -912,67 +356,72 @@ ip6_route_transform_from_dest_string (GBinding *binding,
g_binding_get_source_property (binding), &route,
NULL);
- nm_ip6_route_set_dest (route, &addrbytes);
- nm_ip6_route_set_prefix (route, prefix);
+ nm_ip_route_set_dest (route, addrstr);
+ nm_ip_route_set_prefix (route, prefix);
+ g_free (addrstr);
g_value_take_boxed (target_value, route);
return TRUE;
}
static gboolean
-ip6_route_transform_from_next_hop_string (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
+ip_route_transform_from_next_hop_string (GBinding *binding,
+ const GValue *source_value,
+ GValue *target_value,
+ gpointer user_data)
{
- NMIP6Route *route;
+ int family = GPOINTER_TO_INT (user_data);
+ NMIPRoute *route;
const char *text;
- struct in6_addr addrbytes;
text = g_value_get_string (source_value);
if (*text) {
- if (!ip_string_parse (text, AF_INET6, &addrbytes, NULL))
+ if (!nm_utils_ipaddr_valid (family, text))
return FALSE;
} else
- addrbytes = in6addr_any;
+ text = NULL;
/* Fetch the original property value */
g_object_get (g_binding_get_source (binding),
g_binding_get_source_property (binding), &route,
NULL);
- nm_ip6_route_set_next_hop (route, &addrbytes);
+ nm_ip_route_set_next_hop (route, text);
g_value_take_boxed (target_value, route);
return TRUE;
}
static gboolean
-ip6_route_transform_from_metric_string (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
+ip_route_transform_from_metric_string (GBinding *binding,
+ const GValue *source_value,
+ GValue *target_value,
+ gpointer user_data)
{
- NMIP6Route *route;
+ NMIPRoute *route;
const char *text;
- guint32 metric;
+ gint64 metric;
text = g_value_get_string (source_value);
- metric = strtoul (text, NULL, 10);
+ if (*text)
+ metric = strtoul (text, NULL, 10);
+ else
+ metric = -1;
/* Fetch the original property value */
g_object_get (g_binding_get_source (binding),
g_binding_get_source_property (binding), &route,
NULL);
- nm_ip6_route_set_metric (route, metric);
+ nm_ip_route_set_metric (route, metric);
g_value_take_boxed (target_value, route);
return TRUE;
}
/**
- * nm_editor_bind_ip6_route_to_strings:
+ * nm_editor_bind_ip_route_to_strings:
+ * @family: the IP address family
* @source: the source object
* @source_property: the source property
* @dest_target: the target object for the route's destionation
@@ -983,43 +432,44 @@ ip6_route_transform_from_metric_string (GBinding *binding,
* @metric_target_property: the property on @metric_target
* @flags: %GBindingFlags
*
- * Binds the #NMIP6Route-valued property @source_property on @source
- * to the three indicated string-valued target properties (and vice
- * versa if %G_BINDING_BIDIRECTIONAL is specified).
+ * Binds the #NMIPRoute-valued property @source_property on @source to the
+ * three indicated string-valued target properties (and vice versa if
+ * %G_BINDING_BIDIRECTIONAL is specified).
*
* @dest_target_property should be an "address/prefix" string, as with
- * nm_editor_bind_ip6_addresses_with_prefix_to_strv(). @next_hop_target
- * is a plain IP address, and @metric_target is a number.
+ * nm_editor_bind_ip4_addresses_with_prefix_to_strv(). @next_hop_target_property
+ * is a plain IP address, and @metric_target_property is a number.
*/
void
-nm_editor_bind_ip6_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)
+nm_editor_bind_ip_route_to_strings (int family,
+ 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)
{
g_object_bind_property_full (source, source_property,
dest_target, dest_target_property,
flags,
- ip6_route_transform_to_dest_string,
- ip6_route_transform_from_dest_string,
- NULL, NULL);
+ ip_route_transform_to_dest_string,
+ ip_route_transform_from_dest_string,
+ GINT_TO_POINTER (family), NULL);
g_object_bind_property_full (source, source_property,
next_hop_target, next_hop_target_property,
flags,
- ip6_route_transform_to_next_hop_string,
- ip6_route_transform_from_next_hop_string,
- NULL, NULL);
+ ip_route_transform_to_next_hop_string,
+ ip_route_transform_from_next_hop_string,
+ GINT_TO_POINTER (family), NULL);
g_object_bind_property_full (source, source_property,
metric_target, metric_target_property,
flags,
- ip6_route_transform_to_metric_string,
- ip6_route_transform_from_metric_string,
- NULL, NULL);
+ ip_route_transform_to_metric_string,
+ ip_route_transform_from_metric_string,
+ GINT_TO_POINTER (family), NULL);
}
/* Wireless security method binding */
diff --git a/clients/tui/nm-editor-bindings.h b/clients/tui/nm-editor-bindings.h
index b595ef03c1..19a172f344 100644
--- a/clients/tui/nm-editor-bindings.h
+++ b/clients/tui/nm-editor-bindings.h
@@ -25,49 +25,21 @@ 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,
- const gchar *source_property,
- gpointer target,
- const gchar *target_property,
- GBindingFlags flags);
-void nm_editor_bind_ip4_gateway_to_string (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,
+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_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,
diff --git a/clients/tui/nm-editor-utils.c b/clients/tui/nm-editor-utils.c
index a98278bc09..f936c95943 100644
--- a/clients/tui/nm-editor-utils.c
+++ b/clients/tui/nm-editor-utils.c
@@ -272,7 +272,7 @@ get_available_connection_name (const char *format,
}
/* Find the next available unique connection name */
- while (!cname && (i++ < 10000)) {
+ for (i = 1; !cname && i < 10000; i++) {
char *temp;
gboolean found = FALSE;
diff --git a/clients/tui/nmt-page-ip4.c b/clients/tui/nmt-page-ip4.c
index 8d10b4aa7f..b365cc41a2 100644
--- a/clients/tui/nmt-page-ip4.c
+++ b/clients/tui/nmt-page-ip4.c
@@ -59,12 +59,12 @@ static gboolean
nmt_page_ip4_show_by_default (NmtEditorPage *page)
{
NMConnection *conn;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
conn = nmt_editor_page_get_connection (page);
s_ip4 = nm_connection_get_setting_ip4_config (conn);
- if ( !g_strcmp0 (nm_setting_ip4_config_get_method (s_ip4), NM_SETTING_IP4_CONFIG_METHOD_MANUAL)
- || nm_setting_ip4_config_get_num_addresses (s_ip4))
+ if ( !g_strcmp0 (nm_setting_ip_config_get_method (s_ip4), NM_SETTING_IP4_CONFIG_METHOD_MANUAL)
+ || nm_setting_ip_config_get_num_addresses (s_ip4))
return TRUE;
return FALSE;
}
@@ -115,22 +115,22 @@ nmt_page_ip4_constructed (GObject *object)
{
NmtPageIP4 *ip4 = NMT_PAGE_IP4 (object);
NmtPageGrid *grid;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
NmtNewtWidget *widget, *button;
NMConnection *conn;
conn = nmt_editor_page_get_connection (NMT_EDITOR_PAGE (ip4));
s_ip4 = nm_connection_get_setting_ip4_config (conn);
if (!s_ip4) {
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
g_object_set (G_OBJECT (s_ip4),
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
NULL);
nm_connection_add_setting (conn, (NMSetting *) s_ip4);
}
widget = nmt_newt_popup_new (ip4methods);
- g_object_bind_property (s_ip4, NM_SETTING_IP4_CONFIG_METHOD,
+ g_object_bind_property (s_ip4, NM_SETTING_IP_CONFIG_METHOD,
widget, "active-id",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_editor_page_set_header_widget (NMT_EDITOR_PAGE (ip4), widget);
@@ -138,25 +138,27 @@ 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_IP_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);
+ g_object_bind_property (s_ip4, NM_SETTING_IP_CONFIG_GATEWAY,
+ 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_IP_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);
- g_object_bind_property (s_ip4, NM_SETTING_IP4_CONFIG_DNS_SEARCH,
+ g_object_bind_property (s_ip4, NM_SETTING_IP_CONFIG_DNS_SEARCH,
widget, "strings",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("Search domains"), widget, NULL);
@@ -167,7 +169,7 @@ nmt_page_ip4_constructed (GObject *object)
"text", "",
"style", NMT_NEWT_LABEL_PLAIN,
NULL);
- g_object_bind_property_full (s_ip4, NM_SETTING_IP4_CONFIG_ROUTES,
+ g_object_bind_property_full (s_ip4, NM_SETTING_IP_CONFIG_ROUTES,
widget, "text",
G_BINDING_SYNC_CREATE,
ip4_routes_transform_to_description,
@@ -177,7 +179,7 @@ nmt_page_ip4_constructed (GObject *object)
nmt_page_grid_append (grid, _("Routing"), widget, button);
widget = nmt_newt_checkbox_new (_("Never use this network for default route"));
- g_object_bind_property (s_ip4, NM_SETTING_IP4_CONFIG_NEVER_DEFAULT,
+ g_object_bind_property (s_ip4, NM_SETTING_IP_CONFIG_NEVER_DEFAULT,
widget, "active",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
nmt_page_grid_append (grid, NULL, widget, NULL);
@@ -185,7 +187,7 @@ nmt_page_ip4_constructed (GObject *object)
nmt_page_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
widget = nmt_newt_checkbox_new (_("Require IPv4 addressing for this connection"));
- g_object_bind_property (s_ip4, NM_SETTING_IP4_CONFIG_MAY_FAIL,
+ g_object_bind_property (s_ip4, NM_SETTING_IP_CONFIG_MAY_FAIL,
widget, "active",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL |
G_BINDING_INVERT_BOOLEAN);
diff --git a/clients/tui/nmt-page-ip6.c b/clients/tui/nmt-page-ip6.c
index 7d3ef548fd..1003c1a8aa 100644
--- a/clients/tui/nmt-page-ip6.c
+++ b/clients/tui/nmt-page-ip6.c
@@ -59,12 +59,12 @@ static gboolean
nmt_page_ip6_show_by_default (NmtEditorPage *page)
{
NMConnection *conn;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip6;
conn = nmt_editor_page_get_connection (page);
s_ip6 = nm_connection_get_setting_ip6_config (conn);
- if ( !g_strcmp0 (nm_setting_ip6_config_get_method (s_ip6), NM_SETTING_IP6_CONFIG_METHOD_MANUAL)
- || nm_setting_ip6_config_get_num_addresses (s_ip6))
+ if ( !g_strcmp0 (nm_setting_ip_config_get_method (s_ip6), NM_SETTING_IP6_CONFIG_METHOD_MANUAL)
+ || nm_setting_ip_config_get_num_addresses (s_ip6))
return TRUE;
return FALSE;
}
@@ -115,22 +115,22 @@ nmt_page_ip6_constructed (GObject *object)
{
NmtPageIP6 *ip6 = NMT_PAGE_IP6 (object);
NmtPageGrid *grid;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip6;
NmtNewtWidget *widget, *button;
NMConnection *conn;
conn = nmt_editor_page_get_connection (NMT_EDITOR_PAGE (ip6));
s_ip6 = nm_connection_get_setting_ip6_config (conn);
if (!s_ip6) {
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
g_object_set (G_OBJECT (s_ip6),
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
NULL);
nm_connection_add_setting (conn, (NMSetting *) s_ip6);
}
widget = nmt_newt_popup_new (ip6methods);
- g_object_bind_property (s_ip6, NM_SETTING_IP6_CONFIG_METHOD,
+ g_object_bind_property (s_ip6, NM_SETTING_IP_CONFIG_METHOD,
widget, "active-id",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_editor_page_set_header_widget (NMT_EDITOR_PAGE (ip6), widget);
@@ -138,25 +138,27 @@ 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_IP_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);
+ g_object_bind_property (s_ip6, NM_SETTING_IP_CONFIG_GATEWAY,
+ 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_IP_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);
- g_object_bind_property (s_ip6, NM_SETTING_IP6_CONFIG_DNS_SEARCH,
+ g_object_bind_property (s_ip6, NM_SETTING_IP_CONFIG_DNS_SEARCH,
widget, "strings",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("Search domains"), widget, NULL);
@@ -165,7 +167,7 @@ nmt_page_ip6_constructed (GObject *object)
"text", "",
"style", NMT_NEWT_LABEL_PLAIN,
NULL);
- g_object_bind_property_full (s_ip6, NM_SETTING_IP6_CONFIG_ROUTES,
+ g_object_bind_property_full (s_ip6, NM_SETTING_IP_CONFIG_ROUTES,
widget, "text",
G_BINDING_SYNC_CREATE,
ip6_routes_transform_to_description,
@@ -175,7 +177,7 @@ nmt_page_ip6_constructed (GObject *object)
nmt_page_grid_append (grid, _("Routing"), widget, button);
widget = nmt_newt_checkbox_new (_("Never use this network for default route"));
- g_object_bind_property (s_ip6, NM_SETTING_IP6_CONFIG_NEVER_DEFAULT,
+ g_object_bind_property (s_ip6, NM_SETTING_IP_CONFIG_NEVER_DEFAULT,
widget, "active",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
nmt_page_grid_append (grid, NULL, widget, NULL);
@@ -183,7 +185,7 @@ nmt_page_ip6_constructed (GObject *object)
nmt_page_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
widget = nmt_newt_checkbox_new (_("Require IPv6 addressing for this connection"));
- g_object_bind_property (s_ip6, NM_SETTING_IP6_CONFIG_MAY_FAIL,
+ g_object_bind_property (s_ip6, NM_SETTING_IP_CONFIG_MAY_FAIL,
widget, "active",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL |
G_BINDING_INVERT_BOOLEAN);
diff --git a/clients/tui/nmt-password-dialog.c b/clients/tui/nmt-password-dialog.c
index 22ba85d2c5..aeece1211f 100644
--- a/clients/tui/nmt-password-dialog.c
+++ b/clients/tui/nmt-password-dialog.c
@@ -29,7 +29,7 @@
#include <glib/gi18n-lib.h>
#include "nmt-password-dialog.h"
-#include "nmt-secret-agent.h"
+#include "nm-secret-agent-simple.h"
#include "nmtui.h"
G_DEFINE_TYPE (NmtPasswordDialog, nmt_password_dialog, NMT_TYPE_NEWT_FORM)
@@ -60,10 +60,10 @@ enum {
/**
* nmt_password_dialog_new:
- * @request_id: the request ID from the #NmtSecretAgent
+ * @request_id: the request ID from the #NMSecretAgentSimple
* @title: the dialog title
* @prompt: the prompt text to display
- * @secrets: (element-type #NmtSecretAgentSecret): the secrets requested
+ * @secrets: (element-type #NMSecretAgentSimpleSecret): the secrets requested
*
* Creates a new #NmtPasswordDialog to request passwords from
* the user.
@@ -109,7 +109,7 @@ maybe_save_input_and_exit (NmtNewtWidget *widget,
priv->succeeded = TRUE;
for (i = 0; i < priv->secrets->len; i++) {
- NmtSecretAgentSecret *secret = priv->secrets->pdata[i];
+ NMSecretAgentSimpleSecret *secret = priv->secrets->pdata[i];
g_free (secret->value);
g_object_get (priv->entries->pdata[i], "text", &secret->value, NULL);
@@ -143,7 +143,7 @@ nmt_password_dialog_constructed (GObject *object)
secret_grid = NMT_NEWT_GRID (widget);
for (i = 0; i < priv->secrets->len; i++) {
- NmtSecretAgentSecret *secret = priv->secrets->pdata[i];
+ NMSecretAgentSimpleSecret *secret = priv->secrets->pdata[i];
NmtNewtEntryFlags flags;
widget = nmt_newt_label_new (secret->name);
@@ -258,7 +258,7 @@ nmt_password_dialog_class_init (NmtPasswordDialogClass *dialog_class)
/**
* NmtPasswordDialog:request-id:
*
- * The request ID from the #NmtSecretAgent
+ * The request ID from the #NMSecretAgentSimple
*/
g_object_class_install_property
(object_class, PROP_REQUEST_ID,
@@ -284,7 +284,7 @@ nmt_password_dialog_class_init (NmtPasswordDialogClass *dialog_class)
*
* The array of request secrets
*
- * Element-Type: #NmtSecretAgentSecret.
+ * Element-Type: #NMSecretAgentSimpleSecret.
*/
g_object_class_install_property
(object_class, PROP_SECRETS,
diff --git a/clients/tui/nmt-route-editor.c b/clients/tui/nmt-route-editor.c
index 98fd9ccbb6..77bbec76de 100644
--- a/clients/tui/nmt-route-editor.c
+++ b/clients/tui/nmt-route-editor.c
@@ -77,21 +77,15 @@ save_routes_and_exit (NmtNewtButton *button,
{
NmtRouteEditor *editor = user_data;
NmtRouteEditorPrivate *priv = NMT_ROUTE_EDITOR_GET_PRIVATE (editor);
- const char *property;
- GBinding *binding;
+ GPtrArray *routes;
- if (NM_IS_SETTING_IP4_CONFIG (priv->edit_setting))
- property = NM_SETTING_IP4_CONFIG_ROUTES;
- else
- property = NM_SETTING_IP6_CONFIG_ROUTES;
-
- /* Because of the complicated dbus-glib GTypes, it's easier to cheat
- * and use GBinding to do this than it is to copy the value by hand.
- */
- binding = g_object_bind_property (priv->edit_setting, property,
- priv->orig_setting, property,
- G_BINDING_SYNC_CREATE);
- g_object_unref (binding);
+ g_object_get (priv->edit_setting,
+ NM_SETTING_IP_CONFIG_ROUTES, &routes,
+ NULL);
+ g_object_set (priv->orig_setting,
+ NM_SETTING_IP_CONFIG_ROUTES, routes,
+ NULL);
+ g_ptr_array_unref (routes);
nmt_newt_form_quit (NMT_NEWT_FORM (editor));
}
@@ -106,17 +100,13 @@ nmt_route_editor_constructed (GObject *object)
if (G_OBJECT_CLASS (nmt_route_editor_parent_class)->constructed)
G_OBJECT_CLASS (nmt_route_editor_parent_class)->constructed (object);
- if (NM_IS_SETTING_IP4_CONFIG (priv->edit_setting)) {
+ 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",
- G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
- } else {
+ else
routes = nmt_route_table_new (AF_INET6);
- g_object_bind_property (priv->edit_setting, NM_SETTING_IP6_CONFIG_ROUTES,
- routes, "ip6-routes",
- G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
- }
+ g_object_bind_property (priv->edit_setting, NM_SETTING_IP_CONFIG_ROUTES,
+ routes, "routes",
+ G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
vbox = nmt_newt_grid_new ();
nmt_newt_grid_add (NMT_NEWT_GRID (vbox), routes, 0, 0);
diff --git a/clients/tui/nmt-route-entry.c b/clients/tui/nmt-route-entry.c
index 9b22f389dc..3a87552089 100644
--- a/clients/tui/nmt-route-entry.c
+++ b/clients/tui/nmt-route-entry.c
@@ -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));
}
diff --git a/clients/tui/nmt-route-table.c b/clients/tui/nmt-route-table.c
index 023928c34f..523d8ee32a 100644
--- a/clients/tui/nmt-route-table.c
+++ b/clients/tui/nmt-route-table.c
@@ -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",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
+ route_list_transform_to_route,
+ route_list_transform_from_route,
+ GINT_TO_POINTER (num), NULL);
return entry;
}
@@ -164,24 +147,15 @@ add_route (NmtWidgetList *list,
gpointer table)
{
NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE (table);
+ NMIPRoute *route;
- if (priv->family == AF_INET) {
- NMIP4Route *route;
-
- route = nm_ip4_route_new ();
- nm_ip4_route_set_prefix (route, 32);
- g_ptr_array_add (priv->routes, route);
- nmt_widget_list_set_length (list, priv->routes->len);
- g_object_notify (table, "ip4-routes");
- } else {
- NMIP6Route *route;
-
- route = nm_ip6_route_new ();
- nm_ip6_route_set_prefix (route, 128);
- g_ptr_array_add (priv->routes, route);
- nmt_widget_list_set_length (list, priv->routes->len);
- g_object_notify (table, "ip6-routes");
- }
+ if (priv->family == AF_INET)
+ route = nm_ip_route_new (AF_INET, "0.0.0.0", 32, NULL, 0, NULL);
+ else
+ route = nm_ip_route_new (AF_INET6, "::", 128, NULL, 0, NULL);
+ g_ptr_array_add (priv->routes, route);
+ nmt_widget_list_set_length (list, priv->routes->len);
+ g_object_notify (table, "routes");
}
static void
@@ -190,7 +164,7 @@ remove_route (NmtWidgetList *list,
gpointer table)
{
NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE (table);
- gpointer route;
+ NMIPRoute *route;
if (num >= priv->routes->len)
return;
@@ -199,10 +173,7 @@ remove_route (NmtWidgetList *list,
g_ptr_array_remove_index (priv->routes, num);
nmt_widget_list_set_length (list, priv->routes->len);
- if (priv->family == AF_INET)
- g_object_notify (table, "ip4-routes");
- else
- g_object_notify (table, "ip6-routes");
+ g_object_notify (table, "routes");
}
static void
@@ -214,6 +185,8 @@ nmt_route_table_init (NmtRouteTable *table)
int dest_prefix_width, next_hop_width, metric_width;
char *text;
+ priv->routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref);
+
header = nmt_newt_grid_new ();
text = g_strdup_printf ("%s/%s", _("Destination"), _("Prefix"));
@@ -283,27 +256,12 @@ nmt_route_table_set_property (GObject *object,
switch (prop_id) {
case PROP_FAMILY:
priv->family = g_value_get_int (value);
- 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);
- break;
- case PROP_IP4_ROUTES:
- g_return_if_fail (priv->family == AF_INET);
- array = g_value_get_boxed (value);
- g_ptr_array_set_size (priv->routes, 0);
- for (i = 0; i < array->len; i++) {
- nm_ip4_route_ref (array->pdata[i]);
- g_ptr_array_add (priv->routes, array->pdata[i]);
- }
- nmt_widget_list_set_length (NMT_WIDGET_LIST (priv->list), priv->routes->len);
break;
- case PROP_IP6_ROUTES:
- g_return_if_fail (priv->family == AF_INET6);
+ case PROP_ROUTES:
array = g_value_get_boxed (value);
g_ptr_array_set_size (priv->routes, 0);
for (i = 0; i < array->len; i++) {
- nm_ip6_route_ref (array->pdata[i]);
+ nm_ip_route_ref (array->pdata[i]);
g_ptr_array_add (priv->routes, array->pdata[i]);
}
nmt_widget_list_set_length (NMT_WIDGET_LIST (priv->list), priv->routes->len);
@@ -326,12 +284,7 @@ nmt_route_table_get_property (GObject *object,
case PROP_FAMILY:
g_value_set_int (value, priv->family);
break;
- case PROP_IP4_ROUTES:
- g_return_if_fail (priv->family == AF_INET);
- g_value_set_boxed (value, priv->routes);
- break;
- case PROP_IP6_ROUTES:
- g_return_if_fail (priv->family == AF_INET6);
+ case PROP_ROUTES:
g_value_set_boxed (value, priv->routes);
break;
default:
@@ -365,34 +318,16 @@ nmt_route_table_class_init (NmtRouteTableClass *table_class)
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
/**
- * NmtRouteTable:ip4-routes:
- *
- * The array of routes, suitable for binding to
- * #NMSettingIP4Config:routes.
- *
- * Only valid if #NmtRouteTable:family is %AF_INET
- *
- * Element-type: NMIP4Route
- */
- g_object_class_install_property
- (object_class, PROP_IP4_ROUTES,
- g_param_spec_boxed ("ip4-routes", "", "",
- G_TYPE_PTR_ARRAY,
- G_PARAM_READWRITE |
- G_PARAM_STATIC_STRINGS));
- /**
- * NmtRouteTable:ip6-routes:
- *
- * The array of routes, suitable for binding to
- * #NMSettingIP6Config:routes.
+ * NmtRouteTable:routes:
*
- * Only valid if #NmtRouteTable:family is %AF_INET6
+ * The array of routes, suitable for binding to #NMSettingIP4Config:routes
+ * or #NMSettingIP6Config:routes.
*
- * Element-type: NMIP6Route
+ * Element-type: NMIPRoute
*/
g_object_class_install_property
- (object_class, PROP_IP6_ROUTES,
- g_param_spec_boxed ("ip6-routes", "", "",
+ (object_class, PROP_ROUTES,
+ g_param_spec_boxed ("routes", "", "",
G_TYPE_PTR_ARRAY,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
diff --git a/clients/tui/nmt-secret-agent.h b/clients/tui/nmt-secret-agent.h
deleted file mode 100644
index e7f6ef846b..0000000000
--- a/clients/tui/nmt-secret-agent.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * Copyright 2013 Red Hat, Inc.
- */
-
-#ifndef NMT_SECRET_AGENT_H
-#define NMT_SECRET_AGENT_H
-
-#include <NetworkManager.h>
-
-G_BEGIN_DECLS
-
-#define NMT_TYPE_SECRET_AGENT (nmt_secret_agent_get_type ())
-#define NMT_SECRET_AGENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_SECRET_AGENT, NmtSecretAgent))
-#define NMT_SECRET_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_SECRET_AGENT, NmtSecretAgentClass))
-#define NMT_IS_SECRET_AGENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_SECRET_AGENT))
-#define NMT_IS_SECRET_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_SECRET_AGENT))
-#define NMT_SECRET_AGENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_SECRET_AGENT, NmtSecretAgentClass))
-
-typedef struct {
- NMSecretAgent parent;
-
-} NmtSecretAgent;
-
-typedef struct {
- NMSecretAgentClass parent;
-
-} NmtSecretAgentClass;
-
-typedef struct {
- char *name, *value;
- gboolean password;
-} NmtSecretAgentSecret;
-
-GType nmt_secret_agent_get_type (void);
-
-NMSecretAgent *nmt_secret_agent_new (void);
-void nmt_secret_agent_response (NmtSecretAgent *self,
- const char *request_id,
- GPtrArray *secrets);
-
-G_END_DECLS
-
-#endif /* NMT_SECRET_AGENT_H */
diff --git a/clients/tui/nmtui-connect.c b/clients/tui/nmtui-connect.c
index be03796986..26f7296a66 100644
--- a/clients/tui/nmtui-connect.c
+++ b/clients/tui/nmtui-connect.c
@@ -36,16 +36,16 @@
#include "nmtui-connect.h"
#include "nmt-connect-connection-list.h"
#include "nmt-password-dialog.h"
-#include "nmt-secret-agent.h"
+#include "nm-secret-agent-simple.h"
#include "nmt-utils.h"
static void
-secrets_requested (NmtSecretAgent *agent,
- const char *request_id,
- const char *title,
- const char *msg,
- GPtrArray *secrets,
- gpointer user_data)
+secrets_requested (NMSecretAgentSimple *agent,
+ const char *request_id,
+ const char *title,
+ const char *msg,
+ GPtrArray *secrets,
+ gpointer user_data)
{
NmtNewtForm *form;
@@ -53,9 +53,9 @@ secrets_requested (NmtSecretAgent *agent,
nmt_newt_form_run_sync (form);
if (nmt_password_dialog_succeeded (NMT_PASSWORD_DIALOG (form)))
- nmt_secret_agent_response (agent, request_id, secrets);
+ nm_secret_agent_simple_response (agent, request_id, secrets);
else
- nmt_secret_agent_response (agent, request_id, NULL);
+ nm_secret_agent_simple_response (agent, request_id, NULL);
g_object_unref (form);
}
@@ -145,7 +145,7 @@ activate_connection (NMConnection *connection,
label = nmt_newt_label_new (_("Connecting..."));
nmt_newt_form_set_content (form, label);
- agent = nmt_secret_agent_new ();
+ agent = nm_secret_agent_simple_new ("nmtui", nm_object_get_path (NM_OBJECT (connection)));
g_signal_connect (agent, "request-secrets", G_CALLBACK (secrets_requested), NULL);
specific_object_path = specific_object ? nm_object_get_path (specific_object) : NULL;
diff --git a/configure.ac b/configure.ac
index f14fb8e0b5..b5dbc0d250 100644
--- a/configure.ac
+++ b/configure.ac
@@ -498,6 +498,22 @@ else
fi
AC_SUBST(NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT)
+PKG_CHECK_MODULES(POLKIT, [polkit-agent-1 >= 0.97], [have_pk_agent=yes],[have_pk_agent=no])
+AC_ARG_ENABLE(polkit-agent, AS_HELP_STRING([--enable-polkit-agent], [enable polkit agent for clients]),
+ [enable_polkit_agent=${enableval}], [enable_polkit_agent=${have_pk_agent}])
+if (test "${enable_polkit_agent}" = "yes"); then
+ if test x"$have_pk_agent" = x"no"; then
+ AC_MSG_ERROR(Polkit agent is required)
+ fi
+
+ AC_SUBST(POLKIT_CFLAGS)
+ AC_SUBST(POLKIT_LIBS)
+ AC_DEFINE(WITH_POLKIT_AGENT, 1, [Define if you have polkit agent])
+else
+ AC_DEFINE(WITH_POLKIT_AGENT, 0, [Define if you have polkit agent])
+fi
+AM_CONDITIONAL(WITH_POLKIT_AGENT, test "${enable_polkit_agent}" = "yes")
+
AC_ARG_ENABLE(modify-system,
AS_HELP_STRING([--enable-modify-system], [Allow users to modify system connections]))
if test "${enable_modify_system}" = "yes"; then
@@ -642,7 +658,7 @@ if (test "${enable_bluez5_dun}" = "yes"); then
fi
AC_DEFINE(WITH_BLUEZ5_DUN, 1, [Define if you have Bluez 5 libraries])
else
- AC_DEFINE(HAVE_BLUEZ5_DUN, 0, [Define if you have Bluez 5 libraries])
+ AC_DEFINE(WITH_BLUEZ5_DUN, 0, [Define if you have Bluez 5 libraries])
fi
AM_CONDITIONAL(WITH_BLUEZ5_DUN, test "${enable_bluez5_dun}" = "yes")
@@ -959,6 +975,7 @@ man/NetworkManager.conf.xml
man/nm-system-settings.conf.5
man/nm-online.1
man/nmcli.1
+man/nmtui.1
po/Makefile.in
policy/Makefile
policy/org.freedesktop.NetworkManager.policy.in
@@ -1013,6 +1030,7 @@ if test "${enable_polkit}" = "yes"; then
else
echo " policykit: no"
fi
+echo " polkit agent: ${enable_polkit_agent}"
echo " selinux: $have_selinux"
echo
diff --git a/contrib/fedora/rpm/NetworkManager.spec b/contrib/fedora/rpm/NetworkManager.spec
index 20d1a43a0a..b19159bde8 100644
--- a/contrib/fedora/rpm/NetworkManager.spec
+++ b/contrib/fedora/rpm/NetworkManager.spec
@@ -518,8 +518,12 @@ fi
%{_libexecdir}/nm-dhcp-helper
%{_libexecdir}/nm-avahi-autoipd.action
%{_libexecdir}/nm-dispatcher
+%{_libexecdir}/nm-iface-helper
%dir %{_libdir}/NetworkManager
%{_libdir}/NetworkManager/libnm-settings-plugin*.so
+%if 0%{?with_nmtui}
+%exclude %{_mandir}/man1/nmtui*
+%endif
%{_mandir}/man1/*
%{_mandir}/man5/*
%{_mandir}/man8/*
@@ -650,6 +654,7 @@ fi
%{_bindir}/nmtui-edit
%{_bindir}/nmtui-connect
%{_bindir}/nmtui-hostname
+%{_mandir}/man1/nmtui*
%endif
%changelog
diff --git a/contrib/fedora/rpm/build.sh b/contrib/fedora/rpm/build.sh
index e70eb21491..e3c7cd5c10 100755
--- a/contrib/fedora/rpm/build.sh
+++ b/contrib/fedora/rpm/build.sh
@@ -116,7 +116,16 @@ sed -e "/^__CHANGELOG__$/ \
d
}" > "$TEMPSPEC" || die "Error reading spec file"
-rpmbuild --define "_topdir $TEMP" -ba "$TEMPSPEC" || die "ERROR: rpmbuild FAILED"
+case "$BUILDTYPE" in
+ "SRPM")
+ RPM_BUILD_OPTION=-bs
+ ;;
+ *)
+ RPM_BUILD_OPTION=-ba
+ ;;
+esac
+
+rpmbuild --define "_topdir $TEMP" $RPM_BUILD_OPTION "$TEMPSPEC" || die "ERROR: rpmbuild FAILED"
ln -snf "$TEMPBASE" ./latest
TEMP_LATEST="$(readlink -f .)"/latest
@@ -128,6 +137,6 @@ LOG
LOG "See \"$TEMP_LATEST/\" which symlinks to \"$TEMPBASE\""
LOG
LOG "Result:"
-ls -dla "$TEMP_LATEST" "$(dirname "$TEMP_LATEST")/$TEMPBASE/" "$TEMP_LATEST"/RPMS/*/ "$TEMP_LATEST"/RPMS/*/*.rpm "$TEMP_LATEST"/SRPMS/ "$TEMP_LATEST"/SRPMS/*.rpm | sed 's/^/ /'
+ls -dla "$TEMP_LATEST" "$(dirname "$TEMP_LATEST")/$TEMPBASE/" "$TEMP_LATEST"/RPMS/*/ "$TEMP_LATEST"/RPMS/*/*.rpm "$TEMP_LATEST"/SRPMS/ "$TEMP_LATEST"/SRPMS/*.rpm 2>/dev/null | sed 's/^/ /'
diff --git a/contrib/fedora/rpm/build_clean.sh b/contrib/fedora/rpm/build_clean.sh
index 433bd59d5a..c624d2a1d5 100755
--- a/contrib/fedora/rpm/build_clean.sh
+++ b/contrib/fedora/rpm/build_clean.sh
@@ -15,6 +15,7 @@ usage() {
echo " --force: force build, even if working directory is not clean and has local modifications"
echo " --clean: run \`git-clean -fdx :/\` before build"
echo " --quick: only run \`make dist\` instead of \`make distcheck\`"
+ echo " --srpm: only build the SRPM"
}
@@ -46,6 +47,9 @@ for A; do
-Q|--quick)
QUICK=1
;;
+ -S|--srpm)
+ BUILDTYPE=SRPM
+ ;;
*)
usage
die "Unexpected argument \"$A\""
diff --git a/docs/libnm/Makefile.am b/docs/libnm/Makefile.am
index 1e1e9ae276..28938f89ff 100644
--- a/docs/libnm/Makefile.am
+++ b/docs/libnm/Makefile.am
@@ -10,7 +10,11 @@ DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.xml
# The directory containing the source code. Relative to $(srcdir).
# gtk-doc will search all .c & .h files beneath here for inline comments
# documenting functions and macros.
-DOC_SOURCE_DIR=$(top_srcdir)/libnm-core $(top_srcdir)/libnm
+DOC_SOURCE_DIR= \
+ $(top_srcdir)/libnm-core \
+ $(top_builddir)/libnm-core \
+ $(top_srcdir)/libnm \
+ $(top_builddir)/libnm
# Extra options to supply to gtkdoc-scan.
SCAN_OPTIONS=--rebuild-types --rebuild-sections
@@ -30,19 +34,26 @@ CFILE_GLOB=$(top_srcdir)/libnm-core/*.c $(top_srcdir)/libnm/*.c
# Header files to ignore when scanning.
IGNORE_HFILES= \
+ common.h \
crypto.h \
- nm-dbus-helpers-private.h \
+ nm-dbus-helpers.h \
nm-core-internal.h \
+ nm-core-types.h \
nm-device-private.h \
+ nm-dhcp4-config.h \
+ nm-dhcp6-config.h \
+ nm-ip4-config.h \
+ nm-ip6-config.h \
nm-manager.h \
nm-object-cache.h \
nm-object-private.h \
- nm-param-spec-dbus.h \
+ nm-property-compare.h \
nm-remote-connection-private.h \
nm-remote-settings.h \
nm-setting-private.h \
- nm-types-private.h \
- nm-utils-private.h
+ nm-types.h \
+ nm-utils-private.h \
+ nm-vpn-plugin-old.h
# Images to copy into HTML directory.
HTML_IMAGES = libnm.png
diff --git a/docs/libnm/libnm-docs.xml b/docs/libnm/libnm-docs.xml
index 007cbe4108..2bb9f37521 100644
--- a/docs/libnm/libnm-docs.xml
+++ b/docs/libnm/libnm-docs.xml
@@ -68,11 +68,14 @@
<xi:include href="xml/nm-client.xml"/>
<xi:include href="xml/nm-secret-agent.xml"/>
<xi:include href="xml/nm-object.xml"/>
+ <xi:include href="xml/nm-errors.xml"/>
+ <xi:include href="xml/nm-dbus-interface.xml"/>
</chapter>
<chapter>
<title>Connection and Setting API Reference</title>
<xi:include href="xml/nm-connection.xml"/>
+ <xi:include href="xml/nm-simple-connection.xml"/>
<xi:include href="xml/nm-setting.xml"/>
<xi:include href="xml/nm-setting-connection.xml"/>
<!-- begin alphabetical -->
@@ -87,6 +90,7 @@
<xi:include href="xml/nm-setting-generic.xml"/>
<xi:include href="xml/nm-setting-gsm.xml"/>
<xi:include href="xml/nm-setting-infiniband.xml"/>
+ <xi:include href="xml/nm-setting-ip-config.xml"/>
<xi:include href="xml/nm-setting-ip4-config.xml"/>
<xi:include href="xml/nm-setting-ip6-config.xml"/>
<xi:include href="xml/nm-setting-olpc-mesh.xml"/>
@@ -127,15 +131,20 @@
<xi:include href="xml/nm-remote-connection.xml"/>
<xi:include href="xml/nm-access-point.xml"/>
<xi:include href="xml/nm-wimax-nsp.xml"/>
- <xi:include href="xml/nm-ip4-config.xml"/>
- <xi:include href="xml/nm-ip6-config.xml"/>
- <xi:include href="xml/nm-dhcp4-config.xml"/>
- <xi:include href="xml/nm-dhcp6-config.xml"/>
+ <xi:include href="xml/nm-ip-config.xml"/>
+ <xi:include href="xml/nm-dhcp-config.xml"/>
</chapter>
<chapter>
<title>Utility API Reference</title>
<xi:include href="xml/nm-utils.xml"/>
+ <xi:include href="xml/nm-version.xml"/>
+ </chapter>
+
+ <chapter>
+ <title>VPN Plugin API Reference</title>
+ <xi:include href="xml/nm-vpn-dbus-interface.xml"/>
+ <xi:include href="xml/nm-vpn-editor-plugin.xml"/>
</chapter>
<chapter id="object-tree">
diff --git a/examples/C/glib/add-connection-gdbus.c b/examples/C/glib/add-connection-gdbus.c
index a7874fc51f..7a4d593945 100644
--- a/examples/C/glib/add-connection-gdbus.c
+++ b/examples/C/glib/add-connection-gdbus.c
@@ -86,7 +86,7 @@ add_connection (GDBusProxy *proxy, const char *con_name)
/* Build up the 'ipv4' Setting */
g_variant_builder_init (&setting_builder, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&setting_builder, "{sv}",
- NM_SETTING_IP4_CONFIG_METHOD,
+ NM_SETTING_IP_CONFIG_METHOD,
g_variant_new_string (NM_SETTING_IP4_CONFIG_METHOD_AUTO));
g_variant_builder_add (&connection_builder, "{sa{sv}}",
NM_SETTING_IP4_CONFIG_SETTING_NAME,
diff --git a/examples/C/glib/add-connection-libnm.c b/examples/C/glib/add-connection-libnm.c
index 1288e79c51..f206340e0c 100644
--- a/examples/C/glib/add-connection-libnm.c
+++ b/examples/C/glib/add-connection-libnm.c
@@ -86,7 +86,7 @@ add_connection (NMClient *client, GMainLoop *loop, const char *con_name)
/* Build up the 'ipv4' Setting */
s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
g_object_set (G_OBJECT (s_ip4),
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
NULL);
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
diff --git a/include/nm-dbus-glib-types.h b/include/nm-dbus-glib-types.h
index 66f45685a7..ad11ab6812 100644
--- a/include/nm-dbus-glib-types.h
+++ b/include/nm-dbus-glib-types.h
@@ -37,4 +37,9 @@
#define DBUS_TYPE_G_IP6_ROUTE (dbus_g_type_get_struct ("GValueArray", DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT, DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT, G_TYPE_INVALID))
#define DBUS_TYPE_G_ARRAY_OF_IP6_ROUTE (dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_IP6_ROUTE))
+#define DBUS_TYPE_NM_IP_ADDRESS DBUS_TYPE_G_MAP_OF_VARIANT
+#define DBUS_TYPE_NM_IP_ADDRESSES (dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_NM_IP_ADDRESS))
+#define DBUS_TYPE_NM_IP_ROUTE DBUS_TYPE_G_MAP_OF_VARIANT
+#define DBUS_TYPE_NM_IP_ROUTES (dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_NM_IP_ROUTE))
+
#endif /* __NM_DBUS_GLIB_TYPES_H__ */
diff --git a/include/nm-glib-compat.h b/include/nm-glib-compat.h
index 7a9bb3160a..1dc939feac 100644
--- a/include/nm-glib-compat.h
+++ b/include/nm-glib-compat.h
@@ -59,23 +59,22 @@ __g_type_ensure (GType type)
#if !GLIB_CHECK_VERSION(2,34,0)
-#define g_clear_pointer(pp, destroy) \
- G_STMT_START { \
- G_STATIC_ASSERT (sizeof *(pp) == sizeof (gpointer)); \
- /* Only one access, please */ \
- gpointer *_pp = (gpointer *) (pp); \
- gpointer _p; \
- /* This assignment is needed to avoid a gcc warning */ \
- GDestroyNotify _destroy = (GDestroyNotify) (destroy); \
- \
- (void) (0 ? (gpointer) *(pp) : 0); \
- do \
- _p = g_atomic_pointer_get (_pp); \
- while G_UNLIKELY (!g_atomic_pointer_compare_and_exchange (_pp, _p, NULL)); \
- \
- if (_p) \
- _destroy (_p); \
- } G_STMT_END
+#define g_clear_pointer(pp, destroy) \
+ G_STMT_START { \
+ G_STATIC_ASSERT (sizeof *(pp) == sizeof (gpointer)); \
+ /* Only one access, please */ \
+ gpointer *_pp = (gpointer *) (pp); \
+ gpointer _p; \
+ /* This assignment is needed to avoid a gcc warning */ \
+ GDestroyNotify _destroy = (GDestroyNotify) (destroy); \
+ \
+ _p = *_pp; \
+ if (_p) \
+ { \
+ *_pp = NULL; \
+ _destroy (_p); \
+ } \
+ } G_STMT_END
/* These are used to clean up the output of test programs; we can just let
* them no-op in older glib.
diff --git a/include/nm-test-utils.h b/include/nm-test-utils.h
index 11ffd33033..ca6d97d598 100644
--- a/include/nm-test-utils.h
+++ b/include/nm-test-utils.h
@@ -952,18 +952,6 @@ nmtst_assert_connection_unnormalizable (NMConnection *con,
#endif
-static inline void
-nmtst_assert_ip4_address_equals (guint32 addr, const char *expected, const char *loc)
-{
- guint32 addr2 = nmtst_inet4_from_string (expected);
-
- if (addr != addr2)
- g_error ("assert: %s: ip4 address '%s' expected, but got %s",
- loc, expected ? expected : "any", nm_utils_inet4_ntop (addr, NULL));
-}
-#define nmtst_assert_ip4_address_equals(addr, expected) \
- nmtst_assert_ip4_address_equals (addr, expected, G_STRLOC)
-
#ifdef __NM_UTILS_H__
static inline void
nmtst_assert_hwaddr_equals (gconstpointer hwaddr1, gssize hwaddr1_len, const char *expected, const char *loc)
diff --git a/include/nm-utils-internal.h b/include/nm-utils-internal.h
index 4f5850aace..69ab8391be 100644
--- a/include/nm-utils-internal.h
+++ b/include/nm-utils-internal.h
@@ -82,4 +82,19 @@
/********************************************************/
+#define NM_IN_SET(x, y, ...) \
+ ({ \
+ const typeof(y) _y = (y); \
+ typeof(_y) _x = (x); \
+ unsigned _i; \
+ gboolean _found = FALSE; \
+ for (_i = 0; _i < 1 + sizeof((typeof(_x)[]) { __VA_ARGS__ })/sizeof(typeof(_x)); _i++) { \
+ if (((typeof(_x)[]) { _y, __VA_ARGS__ })[_i] == _x) { \
+ _found = TRUE; \
+ break; \
+ } \
+ } \
+ _found; \
+ })
+
#endif
diff --git a/introspection/nm-ip4-config.xml b/introspection/nm-ip4-config.xml
index 6a8750b7f6..9807653495 100644
--- a/introspection/nm-ip4-config.xml
+++ b/introspection/nm-ip4-config.xml
@@ -2,20 +2,42 @@
<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
<interface name="org.freedesktop.NetworkManager.IP4Config">
+ <property name="Addresses" type="aau" access="read">
+ <tp:docstring>
+ Array of arrays of IPv4 address/prefix/gateway. All 3
+ elements of each array are in network byte order. Essentially:
+ [(addr, prefix, gateway), (addr, prefix, gateway), ...]
+
+ Deprecated: use AddressData and Gateway
+ </tp:docstring>
+ </property>
+ <property name="AddressData" type="aa{sv}" access="read">
+ <tp:docstring>
+ Array of IP address data objects. All addresses will include
+ "address" (an IP address string), and "prefix" (a uint). Some
+ addresses may include additional attributes.
+ </tp:docstring>
+ </property>
<property name="Gateway" type="s" access="read">
<tp:docstring>The gateway in use.</tp:docstring>
</property>
- <property name="Addresses" type="aau" access="read">
- <tp:docstring>Array of tuples of IPv4 address/prefix/gateway. All 3
- elements of each tuple are in network byte order. Essentially:
- [(addr, prefix, gateway), (addr, prefix, gateway), ...]
+ <property name="Routes" type="aau" access="read">
+ <tp:docstring>
+ Arrays of IPv4 route/prefix/next-hop/metric. All 4 elements of
+ each tuple are in network byte order. 'route' and 'next hop'
+ are IPv4 addresses, while prefix and metric are simple
+ unsigned integers. Essentially: [(route, prefix, next-hop,
+ metric), (route, prefix, next-hop, metric), ...]
+
+ Deprecated: use RouteData
</tp:docstring>
</property>
- <property name="Routes" type="aau" access="read">
- <tp:docstring>Tuples of IPv4 route/prefix/next-hop/metric. All 4 elements
- of each tuple are in network byte order. 'route' and 'next hop' are IPv4
- addresses, while prefix and metric are simple unsigned integers. Essentially:
- [(route, prefix, next-hop, metric), (route, prefix, next-hop, metric), ...]
+ <property name="RouteData" type="aa{sv}" access="read">
+ <tp:docstring>
+ Array of IP route data objects. All routes will include "dest"
+ (an IP address string) and "prefix" (a uint). Some routes may
+ include "next-hop" (an IP address string), "metric" (a uint),
+ and additional attributes.
</tp:docstring>
</property>
<property name="Nameservers" type="au" access="read">
diff --git a/introspection/nm-ip6-config.xml b/introspection/nm-ip6-config.xml
index 55c519e701..985dd2e331 100644
--- a/introspection/nm-ip6-config.xml
+++ b/introspection/nm-ip6-config.xml
@@ -2,14 +2,37 @@
<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
<interface name="org.freedesktop.NetworkManager.IP6Config">
+ <property name="Addresses" type="a(ayuay)" access="read">
+ <tp:docstring>
+ Array of tuples of IPv6 address/prefix/gateway.
+
+ Deprecated: use AddressData and Gateway.
+ </tp:docstring>
+ </property>
+ <property name="AddressData" type="aa{sv}" access="read">
+ <tp:docstring>
+ Array of IP address data objects. All addresses will include
+ "address" (an IP address string), and "prefix" (a uint). Some
+ addresses may include additional attributes.
+ </tp:docstring>
+ </property>
<property name="Gateway" type="s" access="read">
<tp:docstring>The gateway in use.</tp:docstring>
</property>
- <property name="Addresses" type="a(ayuay)" access="read">
- <tp:docstring>Tuples of IPv6 address/prefix/gateway.</tp:docstring>
- </property>
<property name="Routes" type="a(ayuayu)" access="read">
- <tp:docstring>Tuples of IPv6 route/prefix/next-hop/metric.</tp:docstring>
+ <tp:docstring>
+ Tuples of IPv6 route/prefix/next-hop/metric.
+
+ Deprecated: use RouteData
+ </tp:docstring>
+ </property>
+ <property name="RouteData" type="aa{sv}" access="read">
+ <tp:docstring>
+ Array of IP route data objects. All routes will include "dest"
+ (an IP address string) and "prefix" (a uint). Some routes may
+ include "next-hop" (an IP address string), "metric" (a uint),
+ and additional attributes.
+ </tp:docstring>
</property>
<property name="Nameservers" type="aay" access="read">
<tp:docstring>The nameservers in use.</tp:docstring>
diff --git a/libnm-core/Makefile.libnm-core b/libnm-core/Makefile.libnm-core
index 481fc806ac..fc6d779b5e 100644
--- a/libnm-core/Makefile.libnm-core
+++ b/libnm-core/Makefile.libnm-core
@@ -24,6 +24,7 @@ libnm_core_headers = \
$(core)/nm-setting-generic.h \
$(core)/nm-setting-gsm.h \
$(core)/nm-setting-infiniband.h \
+ $(core)/nm-setting-ip-config.h \
$(core)/nm-setting-ip4-config.h \
$(core)/nm-setting-ip6-config.h \
$(core)/nm-setting-olpc-mesh.h \
@@ -69,6 +70,7 @@ libnm_core_sources = \
$(core)/nm-setting-generic.c \
$(core)/nm-setting-gsm.c \
$(core)/nm-setting-infiniband.c \
+ $(core)/nm-setting-ip-config.c \
$(core)/nm-setting-ip4-config.c \
$(core)/nm-setting-ip6-config.c \
$(core)/nm-setting-olpc-mesh.c \
diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c
index a6789b3195..e2c06c1765 100644
--- a/libnm-core/nm-connection.c
+++ b/libnm-core/nm-connection.c
@@ -631,8 +631,7 @@ _normalize_ip_config (NMConnection *self, GHashTable *parameters)
NMSettingConnection *s_con = nm_connection_get_setting_connection (self);
const char *default_ip4_method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
const char *default_ip6_method = NULL;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4, *s_ip6;
NMSetting *setting;
if (parameters)
@@ -663,7 +662,7 @@ _normalize_ip_config (NMConnection *self, GHashTable *parameters)
setting = nm_setting_ip4_config_new ();
g_object_set (setting,
- NM_SETTING_IP4_CONFIG_METHOD, default_ip4_method,
+ NM_SETTING_IP_CONFIG_METHOD, default_ip4_method,
NULL);
nm_connection_add_setting (self, setting);
}
@@ -671,8 +670,8 @@ _normalize_ip_config (NMConnection *self, GHashTable *parameters)
setting = nm_setting_ip6_config_new ();
g_object_set (setting,
- NM_SETTING_IP6_CONFIG_METHOD, default_ip6_method,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, default_ip6_method,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
nm_connection_add_setting (self, setting);
}
@@ -740,8 +739,7 @@ _nm_connection_verify (NMConnection *connection, GError **error)
{
NMConnectionPrivate *priv;
NMSettingConnection *s_con;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4, *s_ip6;
GHashTableIter iter;
gpointer value;
GSList *all_settings = NULL, *setting_i;
@@ -1739,14 +1737,19 @@ nm_connection_get_setting_infiniband (NMConnection *connection)
*
* A shortcut to return any #NMSettingIP4Config the connection might contain.
*
- * Returns: (transfer none): an #NMSettingIP4Config if the connection contains one, otherwise %NULL
+ * Note that it returns the value as type #NMSettingIPConfig, since the vast
+ * majority of IPv4-setting-related methods are on that type, not
+ * #NMSettingIP4Config.
+ *
+ * Returns: (type NMSettingIP4Config) (transfer none): an #NMSettingIP4Config if the
+ * connection contains one, otherwise %NULL
**/
-NMSettingIP4Config *
+NMSettingIPConfig *
nm_connection_get_setting_ip4_config (NMConnection *connection)
{
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
- return (NMSettingIP4Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG);
+ return (NMSettingIPConfig *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG);
}
/**
@@ -1755,14 +1758,19 @@ nm_connection_get_setting_ip4_config (NMConnection *connection)
*
* A shortcut to return any #NMSettingIP6Config the connection might contain.
*
- * Returns: (transfer none): an #NMSettingIP6Config if the connection contains one, otherwise %NULL
+ * Note that it returns the value as type #NMSettingIPConfig, since the vast
+ * majority of IPv6-setting-related methods are on that type, not
+ * #NMSettingIP6Config.
+ *
+ * Returns: (type NMSettingIP6Config) (transfer none): an #NMSettingIP6Config if the
+ * connection contains one, otherwise %NULL
**/
-NMSettingIP6Config *
+NMSettingIPConfig *
nm_connection_get_setting_ip6_config (NMConnection *connection)
{
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
- return (NMSettingIP6Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP6_CONFIG);
+ return (NMSettingIPConfig *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP6_CONFIG);
}
/**
diff --git a/libnm-core/nm-connection.h b/libnm-core/nm-connection.h
index ec5db7fa2b..c76ad60768 100644
--- a/libnm-core/nm-connection.h
+++ b/libnm-core/nm-connection.h
@@ -57,6 +57,13 @@ G_BEGIN_DECLS
* client side, and #NMSettingsConnection on the daemon side.
*/
+/**
+ * NMConnectionInterface:
+ * @parent: the parent interace struct
+ * @secrets_updated: emitted when the connection's secrets are updated
+ * @secrets_cleared: emitted when the connection's secrets are cleared
+ * @changed: emitted when any change to the connection's settings occurs
+ */
typedef struct {
GTypeInterface parent;
@@ -193,8 +200,8 @@ NMSettingDcb * nm_connection_get_setting_dcb (NMConnec
NMSettingGeneric * nm_connection_get_setting_generic (NMConnection *connection);
NMSettingGsm * nm_connection_get_setting_gsm (NMConnection *connection);
NMSettingInfiniband * nm_connection_get_setting_infiniband (NMConnection *connection);
-NMSettingIP4Config * nm_connection_get_setting_ip4_config (NMConnection *connection);
-NMSettingIP6Config * nm_connection_get_setting_ip6_config (NMConnection *connection);
+NMSettingIPConfig * nm_connection_get_setting_ip4_config (NMConnection *connection);
+NMSettingIPConfig * nm_connection_get_setting_ip6_config (NMConnection *connection);
NMSettingOlpcMesh * nm_connection_get_setting_olpc_mesh (NMConnection *connection);
NMSettingPpp * nm_connection_get_setting_ppp (NMConnection *connection);
NMSettingPppoe * nm_connection_get_setting_pppoe (NMConnection *connection);
diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h
index fced4ffe3d..407d189e3c 100644
--- a/libnm-core/nm-core-internal.h
+++ b/libnm-core/nm-core-internal.h
@@ -74,12 +74,6 @@
g_clear_object (&c); \
}
-const char *_nm_setting_ip4_config_get_address_label (NMSettingIP4Config *setting,
- guint32 i);
-gboolean _nm_setting_ip4_config_add_address_with_label (NMSettingIP4Config *setting,
- NMIP4Address *address,
- const char *label);
-
/* NM_SETTING_COMPARE_FLAG_INFERRABLE: check whether a device-generated
* connection can be replaced by a already-defined connection. This flag only
* takes into account properties marked with the %NM_SETTING_PARAM_INFERRABLE
diff --git a/libnm-core/nm-core-types.h b/libnm-core/nm-core-types.h
index a6fc529fae..524d6396c5 100644
--- a/libnm-core/nm-core-types.h
+++ b/libnm-core/nm-core-types.h
@@ -40,6 +40,7 @@ typedef struct _NMSettingDcb NMSettingDcb;
typedef struct _NMSettingGeneric NMSettingGeneric;
typedef struct _NMSettingGsm NMSettingGsm;
typedef struct _NMSettingInfiniband NMSettingInfiniband;
+typedef struct _NMSettingIPConfig NMSettingIPConfig;
typedef struct _NMSettingIP4Config NMSettingIP4Config;
typedef struct _NMSettingIP6Config NMSettingIP6Config;
typedef struct _NMSettingOlpcMesh NMSettingOlpcMesh;
diff --git a/libnm-core/nm-dbus-interface.h b/libnm-core/nm-dbus-interface.h
index b4cbd1793e..ccf21ee14a 100644
--- a/libnm-core/nm-dbus-interface.h
+++ b/libnm-core/nm-dbus-interface.h
@@ -526,8 +526,6 @@ typedef enum {
NM_DEVICE_STATE_REASON_MODEM_FAILED = 57,
NM_DEVICE_STATE_REASON_MODEM_AVAILABLE = 58,
NM_DEVICE_STATE_REASON_SIM_PIN_INCORRECT = 59,
-
- NM_DEVICE_STATE_REASON_LAST = 0xFFFF
} NMDeviceStateReason;
diff --git a/libnm-core/nm-errors.h b/libnm-core/nm-errors.h
index fa6919c569..a9857445b7 100644
--- a/libnm-core/nm-errors.h
+++ b/libnm-core/nm-errors.h
@@ -63,21 +63,21 @@ GQuark nm_agent_manager_error_quark (void);
* was attempted on a non-secret property
* @NM_CONNECTION_ERROR_MISSING_SETTING: the #NMConnection object is missing an
* #NMSetting which is required for its configuration. The error message will
- * always be prefixed with "<setting-name>: ", where "<setting-name>" is the
+ * always be prefixed with "&lt;setting-name>: ", where "&lt;setting-name>" is the
* name of the setting that is missing.
* @NM_CONNECTION_ERROR_INVALID_SETTING: the #NMConnection object contains an
* invalid or inappropriate #NMSetting. The error message will always be
- * prefixed with "<setting-name>: ", where "<setting-name>" is the name of the
+ * prefixed with "&lt;setting-name>: ", where "&lt;setting-name>" is the name of the
* setting that is invalid.
* @NM_CONNECTION_ERROR_MISSING_PROPERTY: the #NMConnection object is invalid
* because it is missing a required property. The error message will always be
- * prefixed with "<setting-name>.<property-name>: ", where "<setting-name>" is
- * the name of the setting with the missing property, and "<property-name>" is
+ * prefixed with "&lt;setting-name>.&lt;property-name>: ", where "&lt;setting-name>" is
+ * the name of the setting with the missing property, and "&lt;property-name>" is
* the property that is missing.
* @NM_CONNECTION_ERROR_INVALID_PROPERTY: the #NMConnection object is invalid
* because a property has an invalid value. The error message will always be
- * prefixed with "<setting-name>.<property-name>: ", where "<setting-name>" is
- * the name of the setting with the invalid property, and "<property-name>" is
+ * prefixed with "&lt;setting-name>.&lt;property-name>: ", where "&lt;setting-name>" is
+ * the name of the setting with the invalid property, and "&lt;property-name>" is
* the property that is invalid.
*
* Describes errors that may result from operations involving a #NMConnection
diff --git a/libnm-core/nm-setting-8021x.c b/libnm-core/nm-setting-8021x.c
index a1019060d1..6b202dd4ff 100644
--- a/libnm-core/nm-setting-8021x.c
+++ b/libnm-core/nm-setting-8021x.c
@@ -820,7 +820,7 @@ nm_setting_802_1x_get_client_cert_path (NMSetting8021x *setting)
* @setting: the #NMSetting8021x
* @cert_path: when @scheme is set to either %NM_SETTING_802_1X_CK_SCHEME_PATH
* or %NM_SETTING_802_1X_CK_SCHEME_BLOB, pass the path of the client
- * certificate file (PEM, DER, or PKCS#12 format). The path must be UTF-8
+ * certificate file (PEM, DER, or PKCS#<!-- -->12 format). The path must be UTF-8
* encoded; use g_filename_to_utf8() to convert if needed. Passing %NULL with
* any @scheme clears the client certificate.
* @scheme: desired storage scheme for the certificate
@@ -1403,7 +1403,7 @@ nm_setting_802_1x_get_phase2_client_cert_path (NMSetting8021x *setting)
* @setting: the #NMSetting8021x
* @cert_path: when @scheme is set to either %NM_SETTING_802_1X_CK_SCHEME_PATH
* or %NM_SETTING_802_1X_CK_SCHEME_BLOB, pass the path of the "phase2" client
- * certificate file (PEM, DER, or PKCS#12 format). The path must be UTF-8
+ * certificate file (PEM, DER, or PKCS#<!-- -->12 format). The path must be UTF-8
* encoded; use g_filename_to_utf8() to convert if needed. Passing %NULL with
* any @scheme clears the "phase2" client certificate.
* @scheme: desired storage scheme for the certificate
@@ -1687,7 +1687,7 @@ file_to_secure_bytes (const char *filename)
* @setting: the #NMSetting8021x
* @key_path: when @scheme is set to either %NM_SETTING_802_1X_CK_SCHEME_PATH or
* %NM_SETTING_802_1X_CK_SCHEME_BLOB, pass the path of the private key file
- * (PEM, DER, or PKCS#12 format). The path must be UTF-8 encoded; use
+ * (PEM, DER, or PKCS#<!-- -->12 format). The path must be UTF-8 encoded; use
* g_filename_to_utf8() to convert if needed. Passing %NULL with any @scheme
* clears the private key.
* @password: password used to decrypt the private key, or %NULL if the password
@@ -1997,7 +1997,7 @@ nm_setting_802_1x_get_phase2_private_key_path (NMSetting8021x *setting)
* @setting: the #NMSetting8021x
* @key_path: when @scheme is set to either %NM_SETTING_802_1X_CK_SCHEME_PATH or
* %NM_SETTING_802_1X_CK_SCHEME_BLOB, pass the path of the "phase2" private
- * key file (PEM, DER, or PKCS#12 format). The path must be UTF-8 encoded;
+ * key file (PEM, DER, or PKCS#<!-- -->12 format). The path must be UTF-8 encoded;
* use g_filename_to_utf8() to convert if needed. Passing %NULL with any
* @scheme clears the private key.
* @password: password used to decrypt the private key, or %NULL if the password
@@ -3502,15 +3502,16 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *setting_class)
* should be set to the key's encrypted PEM encoded data. When using private
* keys with the path scheme, this property should be set to the full UTF-8
* encoded path of the key, prefixed with the string "file://" and ending
- * with a terminating NUL byte. When using PKCS#12 format private keys and
- * the blob scheme, this property should be set to the PKCS#12 data and the
- * #NMSetting8021x:private-key-password property must be set to password
- * used to decrypt the PKCS#12 certificate and key. When using PKCS#12 files
- * and the path scheme, this property should be set to the full UTF-8
- * encoded path of the key, prefixed with the string "file://" and and
- * ending with a terminating NUL byte, and as with the blob scheme the
- * "private-key-password" property must be set to the password used to
- * decode the PKCS#12 private key and certificate.
+ * with a terminating NUL byte. When using PKCS#<!-- -->12 format private
+ * keys and the blob scheme, this property should be set to the
+ * PKCS#<!-- -->12 data and the #NMSetting8021x:private-key-password
+ * property must be set to password used to decrypt the PKCS#<!-- -->12
+ * certificate and key. When using PKCS#<!-- -->12 files and the path
+ * scheme, this property should be set to the full UTF-8 encoded path of the
+ * key, prefixed with the string "file://" and and ending with a terminating
+ * NUL byte, and as with the blob scheme the "private-key-password" property
+ * must be set to the password used to decode the PKCS#<!-- -->12 private
+ * key and certificate.
*
* Setting this property directly is discouraged; use the
* nm_setting_802_1x_set_private_key() function instead.
@@ -3537,7 +3538,7 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *setting_class)
*
* The password used to decrypt the private key specified in the
* #NMSetting8021x:private-key property when the private key either uses the
- * path scheme, or if the private key is a PKCS#12 format key. Setting this
+ * path scheme, or if the private key is a PKCS#<!-- -->12 format key. Setting this
* property directly is not generally necessary except when returning
* secrets to NetworkManager; it is generally set automatically when setting
* the private key by the nm_setting_802_1x_set_private_key() function.
@@ -3576,15 +3577,16 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *setting_class)
* should be set to the key's encrypted PEM encoded data. When using private
* keys with the path scheme, this property should be set to the full UTF-8
* encoded path of the key, prefixed with the string "file://" and ending
- * with a terminating NUL byte. When using PKCS#12 format private keys and
- * the blob scheme, this property should be set to the PKCS#12 data and the
- * #NMSetting8021x:phase2-private-key-password property must be set to
- * password used to decrypt the PKCS#12 certificate and key. When using
- * PKCS#12 files and the path scheme, this property should be set to the
- * full UTF-8 encoded path of the key, prefixed with the string "file://"
- * and and ending with a terminating NUL byte, and as with the blob scheme
- * the #NMSetting8021x:phase2-private-key-password property must be set to
- * the password used to decode the PKCS#12 private key and certificate.
+ * with a terminating NUL byte. When using PKCS#<!-- -->12 format private
+ * keys and the blob scheme, this property should be set to the
+ * PKCS#<!-- -->12 data and the #NMSetting8021x:phase2-private-key-password
+ * property must be set to password used to decrypt the PKCS#<!-- -->12
+ * certificate and key. When using PKCS#<!-- -->12 files and the path
+ * scheme, this property should be set to the full UTF-8 encoded path of the
+ * key, prefixed with the string "file://" and and ending with a terminating
+ * NUL byte, and as with the blob scheme the
+ * #NMSetting8021x:phase2-private-key-password property must be set to the
+ * password used to decode the PKCS#<!-- -->12 private key and certificate.
*
* Setting this property directly is discouraged; use the
* nm_setting_802_1x_set_phase2_private_key() function instead.
@@ -3605,10 +3607,11 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *setting_class)
*
* The password used to decrypt the "phase 2" private key specified in the
* #NMSetting8021x:phase2-private-key property when the private key either
- * uses the path scheme, or is a PKCS#12 format key. Setting this property
- * directly is not generally necessary except when returning secrets to
- * NetworkManager; it is generally set automatically when setting the
- * private key by the nm_setting_802_1x_set_phase2_private_key() function.
+ * uses the path scheme, or is a PKCS#<!-- -->12 format key. Setting this
+ * property directly is not generally necessary except when returning
+ * secrets to NetworkManager; it is generally set automatically when setting
+ * the private key by the nm_setting_802_1x_set_phase2_private_key()
+ * function.
**/
g_object_class_install_property
(object_class, PROP_PHASE2_PRIVATE_KEY_PASSWORD,
diff --git a/libnm-core/nm-setting-8021x.h b/libnm-core/nm-setting-8021x.h
index 10338de998..43885daaa3 100644
--- a/libnm-core/nm-setting-8021x.h
+++ b/libnm-core/nm-setting-8021x.h
@@ -37,7 +37,7 @@ G_BEGIN_DECLS
* @NM_SETTING_802_1X_CK_FORMAT_X509: file contains an X.509 format certificate
* @NM_SETTING_802_1X_CK_FORMAT_RAW_KEY: file contains an old-style OpenSSL PEM
* or DER private key
- * @NM_SETTING_802_1X_CK_FORMAT_PKCS12: file contains a PKCS#12 certificate
+ * @NM_SETTING_802_1X_CK_FORMAT_PKCS12: file contains a PKCS#<!-- -->12 certificate
* and private key
*
* #NMSetting8021xCKFormat values indicate the general type of a certificate
diff --git a/libnm-core/nm-setting-bluetooth.c b/libnm-core/nm-setting-bluetooth.c
index 952dd61b51..6b169301ba 100644
--- a/libnm-core/nm-setting-bluetooth.c
+++ b/libnm-core/nm-setting-bluetooth.c
@@ -79,7 +79,8 @@ NMSetting *nm_setting_bluetooth_new (void)
* Returns the connection method for communicating with the remote device (i.e.
* either DUN to a DUN-capable device or PANU to a NAP-capable device).
*
- * Returns: the type, either %NM_SETTING_BLUETOOTH_PANU or %NM_SETTING_BLUETOOTH_DUN
+ * Returns: the type, either %NM_SETTING_BLUETOOTH_TYPE_PANU or
+ * %NM_SETTING_BLUETOOTH_TYPE_DUN
**/
const char *
nm_setting_bluetooth_get_connection_type (NMSettingBluetooth *setting)
diff --git a/libnm-core/nm-setting-ip-config.c b/libnm-core/nm-setting-ip-config.c
new file mode 100644
index 0000000000..8db1d603c0
--- /dev/null
+++ b/libnm-core/nm-setting-ip-config.c
@@ -0,0 +1,2321 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2007 - 2014 Red Hat, Inc.
+ * Copyright 2007 - 2008 Novell, Inc.
+ */
+
+#include <string.h>
+#include <arpa/inet.h>
+#include <glib/gi18n.h>
+
+#include "nm-setting-ip-config.h"
+#include "nm-setting-ip4-config.h"
+#include "nm-setting-ip6-config.h"
+#include "nm-utils.h"
+#include "nm-glib-compat.h"
+#include "nm-setting-private.h"
+#include "nm-utils-private.h"
+
+/**
+ * SECTION:nm-setting-ip-config
+ * @short_description: Abstract base class for IPv4 and IPv6
+ * addressing, routing, and name service properties
+ * @include: nm-setting-ip-config.h
+ * @see_also: #NMSettingIP4Config, #NMSettingIP6Config
+ *
+ * #NMSettingIPConfig is the abstract base class of
+ * #NMSettingIP4Config and #NMSettingIP6Config, providing properties
+ * related to IP addressing, routing, and Domain Name Service.
+ **/
+
+static char *
+canonicalize_ip (int family, const char *ip, gboolean null_any)
+{
+ guint8 addr_bytes[sizeof (struct in6_addr)];
+ char addr_str[NM_UTILS_INET_ADDRSTRLEN];
+ int ret;
+
+ if (!ip) {
+ g_return_val_if_fail (null_any == TRUE, NULL);
+ return NULL;
+ }
+
+ ret = inet_pton (family, ip, addr_bytes);
+ g_return_val_if_fail (ret == 1, NULL);
+
+ if (null_any) {
+ int addrlen = (family == AF_INET ? sizeof (struct in_addr) : sizeof (struct in6_addr));
+
+ if (!memcmp (addr_bytes, &in6addr_any, addrlen))
+ return NULL;
+ }
+
+ return g_strdup (inet_ntop (family, addr_bytes, addr_str, sizeof (addr_str)));
+}
+
+static gboolean
+valid_ip (int family, const char *ip, GError **error)
+{
+ if (!nm_utils_ipaddr_valid (family, ip)) {
+ g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED,
+ family == AF_INET ? _("Invalid IPv4 address '%s'") : _("Invalid IPv6 address '%s"),
+ ip);
+ return FALSE;
+ } else
+ return TRUE;
+}
+
+static gboolean
+valid_prefix (int family, guint prefix, GError **error)
+{
+ if ( (family == AF_INET && prefix > 32)
+ || (family == AF_INET6 && prefix > 128)
+ || prefix == 0) {
+ g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED,
+ family == AF_INET ? _("Invalid IPv4 address prefix '%u'") : _("Invalid IPv6 address prefix '%u"),
+ prefix);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean
+valid_metric (gint64 metric, GError **error)
+{
+ if (metric < -1 || metric > G_MAXUINT32) {
+ if (error) {
+ char buf[64];
+
+ /* We can't concatenate G_GINT64_FORMAT into a translatable string */
+ g_snprintf (buf, sizeof (buf), "%" G_GINT64_FORMAT, metric);
+ g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED,
+ _("Invalid routing metric '%s'"), buf);
+ }
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+G_DEFINE_BOXED_TYPE (NMIPAddress, nm_ip_address, nm_ip_address_dup, nm_ip_address_unref)
+
+struct NMIPAddress {
+ guint refcount;
+
+ char *address;
+ int prefix, family;
+
+ GHashTable *attributes;
+};
+
+/**
+ * nm_ip_address_new:
+ * @family: the IP address family (%AF_INET or %AF_INET6)
+ * @addr: the IP address
+ * @prefix: the address prefix length
+ * @error: location to store error, or %NULL
+ *
+ * Creates a new #NMIPAddress object.
+ *
+ * Returns: (transfer full): the new #NMIPAddress object, or %NULL on error
+ **/
+NMIPAddress *
+nm_ip_address_new (int family,
+ const char *addr, guint prefix,
+ GError **error)
+{
+ NMIPAddress *address;
+
+ g_return_val_if_fail (family == AF_INET || family == AF_INET6, NULL);
+ g_return_val_if_fail (addr != NULL, NULL);
+
+ if (!valid_ip (family, addr, error))
+ return NULL;
+ if (!valid_prefix (family, prefix, error))
+ return NULL;
+
+ address = g_slice_new0 (NMIPAddress);
+ address->refcount = 1;
+
+ address->family = family;
+ address->address = canonicalize_ip (family, addr, FALSE);
+ address->prefix = prefix;
+
+ return address;
+}
+
+/**
+ * nm_ip_address_new_binary:
+ * @family: the IP address family (%AF_INET or %AF_INET6)
+ * @addr: the IP address
+ * @prefix: the address prefix length
+ * @error: location to store error, or %NULL
+ *
+ * Creates a new #NMIPAddress object. @addr must point to a buffer of the
+ * correct size for @family.
+ *
+ * Returns: (transfer full): the new #NMIPAddress object, or %NULL on error
+ **/
+NMIPAddress *
+nm_ip_address_new_binary (int family,
+ gconstpointer addr, guint prefix,
+ GError **error)
+{
+ NMIPAddress *address;
+ char string[NM_UTILS_INET_ADDRSTRLEN];
+
+ g_return_val_if_fail (family == AF_INET || family == AF_INET6, NULL);
+ g_return_val_if_fail (addr != NULL, NULL);
+
+ if (!valid_prefix (family, prefix, error))
+ return NULL;
+
+ address = g_slice_new0 (NMIPAddress);
+ address->refcount = 1;
+
+ address->family = family;
+ address->address = g_strdup (inet_ntop (family, addr, string, sizeof (string)));
+ address->prefix = prefix;
+
+ return address;
+}
+
+/**
+ * nm_ip_address_ref:
+ * @address: the #NMIPAddress
+ *
+ * Increases the reference count of the object.
+ **/
+void
+nm_ip_address_ref (NMIPAddress *address)
+{
+ g_return_if_fail (address != NULL);
+ g_return_if_fail (address->refcount > 0);
+
+ address->refcount++;
+}
+
+/**
+ * nm_ip_address_unref:
+ * @address: the #NMIPAddress
+ *
+ * Decreases the reference count of the object. If the reference count
+ * reaches zero, the object will be destroyed.
+ **/
+void
+nm_ip_address_unref (NMIPAddress *address)
+{
+ g_return_if_fail (address != NULL);
+ g_return_if_fail (address->refcount > 0);
+
+ address->refcount--;
+ if (address->refcount == 0) {
+ g_free (address->address);
+ if (address->attributes)
+ g_hash_table_unref (address->attributes);
+ g_slice_free (NMIPAddress, address);
+ }
+}
+
+/**
+ * nm_ip_address_equal:
+ * @address: the #NMIPAddress
+ * @other: the #NMIPAddress to compare @address to.
+ *
+ * Determines if two #NMIPAddress objects contain the same address and prefix
+ * (attributes are not compared).
+ *
+ * Returns: %TRUE if the objects contain the same values, %FALSE if they do not.
+ **/
+gboolean
+nm_ip_address_equal (NMIPAddress *address, NMIPAddress *other)
+{
+ g_return_val_if_fail (address != NULL, FALSE);
+ g_return_val_if_fail (address->refcount > 0, FALSE);
+
+ g_return_val_if_fail (other != NULL, FALSE);
+ g_return_val_if_fail (other->refcount > 0, FALSE);
+
+ if ( address->family != other->family
+ || address->prefix != other->prefix
+ || strcmp (address->address, other->address) != 0)
+ return FALSE;
+ return TRUE;
+}
+
+/**
+ * nm_ip_address_dup:
+ * @address: the #NMIPAddress
+ *
+ * Creates a copy of @address
+ *
+ * Returns: (transfer full): a copy of @address
+ **/
+NMIPAddress *
+nm_ip_address_dup (NMIPAddress *address)
+{
+ NMIPAddress *copy;
+
+ g_return_val_if_fail (address != NULL, NULL);
+ g_return_val_if_fail (address->refcount > 0, NULL);
+
+ copy = nm_ip_address_new (address->family,
+ address->address, address->prefix,
+ NULL);
+ if (address->attributes) {
+ GHashTableIter iter;
+ const char *key;
+ GVariant *value;
+
+ g_hash_table_iter_init (&iter, address->attributes);
+ while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &value))
+ nm_ip_address_set_attribute (copy, key, value);
+ }
+
+ return copy;
+}
+
+/**
+ * nm_ip_address_get_family:
+ * @address: the #NMIPAddress
+ *
+ * Gets the IP address family (eg, AF_INET) property of this address
+ * object.
+ *
+ * Returns: the IP address family
+ **/
+int
+nm_ip_address_get_family (NMIPAddress *address)
+{
+ g_return_val_if_fail (address != NULL, 0);
+ g_return_val_if_fail (address->refcount > 0, 0);
+
+ return address->family;
+}
+
+/**
+ * nm_ip_address_get_address:
+ * @address: the #NMIPAddress
+ *
+ * Gets the IP address property of this address object.
+ *
+ * Returns: the IP address
+ **/
+const char *
+nm_ip_address_get_address (NMIPAddress *address)
+{
+ g_return_val_if_fail (address != NULL, NULL);
+ g_return_val_if_fail (address->refcount > 0, NULL);
+
+ return address->address;
+}
+
+/**
+ * nm_ip_address_set_address:
+ * @address: the #NMIPAddress
+ * @addr: the IP address, as a string
+ *
+ * Sets the IP address property of this address object.
+ *
+ * @addr must be a valid address of @address's family. If you aren't sure you
+ * have a valid address, use nm_utils_ipaddr_valid() to check it.
+ **/
+void
+nm_ip_address_set_address (NMIPAddress *address,
+ const char *addr)
+{
+ g_return_if_fail (address != NULL);
+ g_return_if_fail (addr != NULL);
+ g_return_if_fail (nm_utils_ipaddr_valid (address->family, addr));
+
+ g_free (address->address);
+ address->address = canonicalize_ip (address->family, addr, FALSE);
+}
+
+/**
+ * nm_ip_address_get_address_binary: (skip)
+ * @address: the #NMIPAddress
+ * @addr: a buffer in which to store the address in binary format.
+ *
+ * Gets the IP address property of this address object.
+ *
+ * @addr must point to a buffer that is the correct size for @address's family.
+ **/
+void
+nm_ip_address_get_address_binary (NMIPAddress *address,
+ gpointer addr)
+{
+ g_return_if_fail (address != NULL);
+ g_return_if_fail (addr != NULL);
+
+ inet_pton (address->family, address->address, addr);
+}
+
+/**
+ * nm_ip_address_set_address_binary: (skip)
+ * @address: the #NMIPAddress
+ * @addr: the address, in binary format
+ *
+ * Sets the IP address property of this address object.
+ *
+ * @addr must point to a buffer that is the correct size for @address's family.
+ **/
+void
+nm_ip_address_set_address_binary (NMIPAddress *address,
+ gconstpointer addr)
+{
+ char string[NM_UTILS_INET_ADDRSTRLEN];
+
+ g_return_if_fail (address != NULL);
+ g_return_if_fail (addr != NULL);
+
+ g_free (address->address);
+ address->address = g_strdup (inet_ntop (address->family, addr, string, sizeof (string)));
+}
+
+/**
+ * nm_ip_address_get_prefix:
+ * @address: the #NMIPAddress
+ *
+ * Gets the IP address prefix (ie "24" or "30" etc) property of this address
+ * object.
+ *
+ * Returns: the IP address prefix
+ **/
+guint
+nm_ip_address_get_prefix (NMIPAddress *address)
+{
+ g_return_val_if_fail (address != NULL, 0);
+ g_return_val_if_fail (address->refcount > 0, 0);
+
+ return address->prefix;
+}
+
+/**
+ * nm_ip_address_set_prefix:
+ * @address: the #NMIPAddress
+ * @prefix: the IP address prefix
+ *
+ * Sets the IP address prefix property of this address object.
+ **/
+void
+nm_ip_address_set_prefix (NMIPAddress *address,
+ guint prefix)
+{
+ g_return_if_fail (address != NULL);
+ g_return_if_fail (valid_prefix (address->family, prefix, NULL));
+
+ address->prefix = prefix;
+}
+
+/**
+ * nm_ip_address_get_attribute_names:
+ * @address: the #NMIPAddress
+ *
+ * Gets an array of attribute names defined on @address.
+ *
+ * Returns: (transfer full): a %NULL-terminated array of attribute names,
+ **/
+char **
+nm_ip_address_get_attribute_names (NMIPAddress *address)
+{
+ GHashTableIter iter;
+ const char *key;
+ GPtrArray *names;
+
+ g_return_val_if_fail (address != NULL, NULL);
+
+ names = g_ptr_array_new ();
+
+ if (address->attributes) {
+ g_hash_table_iter_init (&iter, address->attributes);
+ while (g_hash_table_iter_next (&iter, (gpointer *) &key, NULL))
+ g_ptr_array_add (names, g_strdup (key));
+ }
+ g_ptr_array_add (names, NULL);
+
+ return (char **) g_ptr_array_free (names, FALSE);
+}
+
+/**
+ * nm_ip_address_get_attribute:
+ * @address: the #NMIPAddress
+ * @name: the name of an address attribute
+ *
+ * Gets the value of the attribute with name @name on @address
+ *
+ * Returns: (transfer none): the value of the attribute with name @name on
+ * @address, or %NULL if @address has no such attribute.
+ **/
+GVariant *
+nm_ip_address_get_attribute (NMIPAddress *address, const char *name)
+{
+ g_return_val_if_fail (address != NULL, NULL);
+ g_return_val_if_fail (name != NULL && *name != '\0', NULL);
+
+ if (address->attributes)
+ return g_hash_table_lookup (address->attributes, name);
+ else
+ return NULL;
+}
+
+/**
+ * nm_ip_address_set_attribute:
+ * @address: the #NMIPAddress
+ * @name: the name of an address attribute
+ * @value: (transfer none) (allow-none): the value
+ *
+ * Sets or clears the named attribute on @address to the given value.
+ **/
+void
+nm_ip_address_set_attribute (NMIPAddress *address, const char *name, GVariant *value)
+{
+ g_return_if_fail (address != NULL);
+ g_return_if_fail (name != NULL && *name != '\0');
+ g_return_if_fail (strcmp (name, "address") != 0 && strcmp (name, "prefix") != 0);
+
+ if (!address->attributes) {
+ address->attributes = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, (GDestroyNotify) g_variant_unref);
+ }
+
+ if (value)
+ g_hash_table_insert (address->attributes, g_strdup (name), g_variant_ref_sink (value));
+ else
+ g_hash_table_remove (address->attributes, name);
+}
+
+
+G_DEFINE_BOXED_TYPE (NMIPRoute, nm_ip_route, nm_ip_route_dup, nm_ip_route_unref)
+
+struct NMIPRoute {
+ guint refcount;
+
+ int family;
+ char *dest;
+ guint prefix;
+ char *next_hop;
+ gint64 metric;
+
+ GHashTable *attributes;
+};
+
+/**
+ * nm_ip_route_new:
+ * @family: the IP address family (%AF_INET or %AF_INET6)
+ * @dest: the IP address of the route's destination
+ * @prefix: the address prefix length
+ * @next_hop: (allow-none): the IP address of the next hop (or %NULL)
+ * @metric: the route metric (or -1 for "default")
+ * @error: location to store error, or %NULL
+ *
+ * Creates a new #NMIPRoute object.
+ *
+ * Returns: (transfer full): the new #NMIPRoute object, or %NULL on error
+ **/
+NMIPRoute *
+nm_ip_route_new (int family,
+ const char *dest,
+ guint prefix,
+ const char *next_hop,
+ gint64 metric,
+ GError **error)
+{
+ NMIPRoute *route;
+
+ g_return_val_if_fail (family == AF_INET || family == AF_INET6, NULL);
+
+ if (!valid_ip (family, dest, error))
+ return NULL;
+ if (!valid_prefix (family, prefix, error))
+ return NULL;
+ if (next_hop && !valid_ip (family, next_hop, error))
+ return NULL;
+ if (!valid_metric (metric, error))
+ return NULL;
+
+ route = g_slice_new0 (NMIPRoute);
+ route->refcount = 1;
+
+ route->family = family;
+ route->dest = canonicalize_ip (family, dest, FALSE);
+ route->prefix = prefix;
+ route->next_hop = canonicalize_ip (family, next_hop, TRUE);
+ route->metric = metric;
+
+ return route;
+}
+
+/**
+ * nm_ip_route_new_binary:
+ * @family: the IP address family (%AF_INET or %AF_INET6)
+ * @dest: the IP address of the route's destination
+ * @prefix: the address prefix length
+ * @next_hop: (allow-none): the IP address of the next hop (or %NULL)
+ * @metric: the route metric (or -1 for "default")
+ * @error: location to store error, or %NULL
+ *
+ * Creates a new #NMIPRoute object. @dest and @next_hop (if non-%NULL) must
+ * point to buffers of the correct size for @family.
+ *
+ * Returns: (transfer full): the new #NMIPRoute object, or %NULL on error
+ **/
+NMIPRoute *
+nm_ip_route_new_binary (int family,
+ gconstpointer dest,
+ guint prefix,
+ gconstpointer next_hop,
+ gint64 metric,
+ GError **error)
+{
+ NMIPRoute *route;
+ char string[NM_UTILS_INET_ADDRSTRLEN];
+
+ g_return_val_if_fail (family == AF_INET || family == AF_INET6, NULL);
+
+ if (!valid_prefix (family, prefix, error))
+ return NULL;
+ if (!valid_metric (metric, error))
+ return NULL;
+
+ route = g_slice_new0 (NMIPRoute);
+ route->refcount = 1;
+
+ route->family = family;
+ route->dest = g_strdup (inet_ntop (family, dest, string, sizeof (string)));
+ route->prefix = prefix;
+ if (next_hop)
+ route->next_hop = g_strdup (inet_ntop (family, next_hop, string, sizeof (string)));
+ route->metric = metric;
+
+ return route;
+}
+
+/**
+ * nm_ip_route_ref:
+ * @route: the #NMIPRoute
+ *
+ * Increases the reference count of the object.
+ **/
+void
+nm_ip_route_ref (NMIPRoute *route)
+{
+ g_return_if_fail (route != NULL);
+ g_return_if_fail (route->refcount > 0);
+
+ route->refcount++;
+}
+
+/**
+ * nm_ip_route_unref:
+ * @route: the #NMIPRoute
+ *
+ * Decreases the reference count of the object. If the reference count
+ * reaches zero, the object will be destroyed.
+ **/
+void
+nm_ip_route_unref (NMIPRoute *route)
+{
+ g_return_if_fail (route != NULL);
+ g_return_if_fail (route->refcount > 0);
+
+ route->refcount--;
+ if (route->refcount == 0) {
+ g_free (route->dest);
+ g_free (route->next_hop);
+ if (route->attributes)
+ g_hash_table_unref (route->attributes);
+ g_slice_free (NMIPRoute, route);
+ }
+}
+
+/**
+ * nm_ip_route_equal:
+ * @route: the #NMIPRoute
+ * @other: the #NMIPRoute to compare @route to.
+ *
+ * Determines if two #NMIPRoute objects contain the same destination, prefix,
+ * next hop, and metric. (Attributes are not compared.)
+ *
+ * Returns: %TRUE if the objects contain the same values, %FALSE if they do not.
+ **/
+gboolean
+nm_ip_route_equal (NMIPRoute *route, NMIPRoute *other)
+{
+ g_return_val_if_fail (route != NULL, FALSE);
+ g_return_val_if_fail (route->refcount > 0, FALSE);
+
+ g_return_val_if_fail (other != NULL, FALSE);
+ g_return_val_if_fail (other->refcount > 0, FALSE);
+
+ if ( route->prefix != other->prefix
+ || route->metric != other->metric
+ || strcmp (route->dest, other->dest) != 0
+ || g_strcmp0 (route->next_hop, other->next_hop) != 0)
+ return FALSE;
+ return TRUE;
+}
+
+/**
+ * nm_ip_route_dup:
+ * @route: the #NMIPRoute
+ *
+ * Creates a copy of @route
+ *
+ * Returns: (transfer full): a copy of @route
+ **/
+NMIPRoute *
+nm_ip_route_dup (NMIPRoute *route)
+{
+ NMIPRoute *copy;
+
+ g_return_val_if_fail (route != NULL, NULL);
+ g_return_val_if_fail (route->refcount > 0, NULL);
+
+ copy = nm_ip_route_new (route->family,
+ route->dest, route->prefix,
+ route->next_hop, route->metric,
+ NULL);
+ if (route->attributes) {
+ GHashTableIter iter;
+ const char *key;
+ GVariant *value;
+
+ g_hash_table_iter_init (&iter, route->attributes);
+ while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &value))
+ nm_ip_route_set_attribute (copy, key, value);
+ }
+
+ return copy;
+}
+
+/**
+ * nm_ip_route_get_family:
+ * @route: the #NMIPRoute
+ *
+ * Gets the IP address family (eg, AF_INET) property of this route
+ * object.
+ *
+ * Returns: the IP address family
+ **/
+int
+nm_ip_route_get_family (NMIPRoute *route)
+{
+ g_return_val_if_fail (route != NULL, 0);
+ g_return_val_if_fail (route->refcount > 0, 0);
+
+ return route->family;
+}
+
+/**
+ * nm_ip_route_get_dest:
+ * @route: the #NMIPRoute
+ *
+ * Gets the IP destination address property of this route object.
+ *
+ * Returns: the IP address of the route's destination
+ **/
+const char *
+nm_ip_route_get_dest (NMIPRoute *route)
+{
+ g_return_val_if_fail (route != NULL, NULL);
+ g_return_val_if_fail (route->refcount > 0, NULL);
+
+ return route->dest;
+}
+
+/**
+ * nm_ip_route_set_dest:
+ * @route: the #NMIPRoute
+ * @dest: the route's destination, as a string
+ *
+ * Sets the destination property of this route object.
+ *
+ * @dest must be a valid address of @route's family. If you aren't sure you
+ * have a valid address, use nm_utils_ipaddr_valid() to check it.
+ **/
+void
+nm_ip_route_set_dest (NMIPRoute *route,
+ const char *dest)
+{
+ g_return_if_fail (route != NULL);
+ g_return_if_fail (dest != NULL);
+ g_return_if_fail (nm_utils_ipaddr_valid (route->family, dest));
+
+ g_free (route->dest);
+ route->dest = canonicalize_ip (route->family, dest, FALSE);
+}
+
+/**
+ * nm_ip_route_get_dest_binary: (skip)
+ * @route: the #NMIPRoute
+ * @dest: a buffer in which to store the destination in binary format.
+ *
+ * Gets the destination property of this route object.
+ *
+ * @dest must point to a buffer that is the correct size for @route's family.
+ **/
+void
+nm_ip_route_get_dest_binary (NMIPRoute *route,
+ gpointer dest)
+{
+ g_return_if_fail (route != NULL);
+ g_return_if_fail (dest != NULL);
+
+ inet_pton (route->family, route->dest, dest);
+}
+
+/**
+ * nm_ip_route_set_dest_binary: (skip)
+ * @route: the #NMIPRoute
+ * @dest: the route's destination, in binary format
+ *
+ * Sets the destination property of this route object.
+ *
+ * @dest must point to a buffer that is the correct size for @route's family.
+ **/
+void
+nm_ip_route_set_dest_binary (NMIPRoute *route,
+ gconstpointer dest)
+{
+ char string[NM_UTILS_INET_ADDRSTRLEN];
+
+ g_return_if_fail (route != NULL);
+ g_return_if_fail (dest != NULL);
+
+ g_free (route->dest);
+ route->dest = g_strdup (inet_ntop (route->family, dest, string, sizeof (string)));
+}
+
+/**
+ * nm_ip_route_get_prefix:
+ * @route: the #NMIPRoute
+ *
+ * Gets the IP prefix (ie "24" or "30" etc) of this route.
+ *
+ * Returns: the IP prefix
+ **/
+guint
+nm_ip_route_get_prefix (NMIPRoute *route)
+{
+ g_return_val_if_fail (route != NULL, 0);
+ g_return_val_if_fail (route->refcount > 0, 0);
+
+ return route->prefix;
+}
+
+/**
+ * nm_ip_route_set_prefix:
+ * @route: the #NMIPRoute
+ * @prefix: the route prefix
+ *
+ * Sets the prefix property of this route object.
+ **/
+void
+nm_ip_route_set_prefix (NMIPRoute *route,
+ guint prefix)
+{
+ g_return_if_fail (route != NULL);
+ g_return_if_fail (valid_prefix (route->family, prefix, NULL));
+
+ route->prefix = prefix;
+}
+
+/**
+ * nm_ip_route_get_next_hop:
+ * @route: the #NMIPRoute
+ *
+ * Gets the IP address of the next hop of this route; this will be %NULL if the
+ * route has no next hop.
+ *
+ * Returns: the IP address of the next hop, or %NULL if this is a device route.
+ **/
+const char *
+nm_ip_route_get_next_hop (NMIPRoute *route)
+{
+ g_return_val_if_fail (route != NULL, NULL);
+ g_return_val_if_fail (route->refcount > 0, NULL);
+
+ return route->next_hop;
+}
+
+/**
+ * nm_ip_route_set_next_hop:
+ * @route: the #NMIPRoute
+ * @next_hop: (allow-none): the route's next hop, as a string
+ *
+ * Sets the next-hop property of this route object.
+ *
+ * @next_hop (if non-%NULL) must be a valid address of @route's family. If you
+ * aren't sure you have a valid address, use nm_utils_ipaddr_valid() to check
+ * it.
+ **/
+void
+nm_ip_route_set_next_hop (NMIPRoute *route,
+ const char *next_hop)
+{
+ g_return_if_fail (route != NULL);
+ g_return_if_fail (!next_hop || nm_utils_ipaddr_valid (route->family, next_hop));
+
+ g_free (route->next_hop);
+ route->next_hop = canonicalize_ip (route->family, next_hop, TRUE);
+}
+
+/**
+ * nm_ip_route_get_next_hop_binary: (skip)
+ * @route: the #NMIPRoute
+ * @next_hop: a buffer in which to store the next hop in binary format.
+ *
+ * Gets the next hop property of this route object.
+ *
+ * @next_hop must point to a buffer that is the correct size for @route's family.
+ *
+ * Returns: %TRUE if @route has a next hop, %FALSE if not (in which case
+ * @next_hop will be zeroed out)
+ **/
+gboolean
+nm_ip_route_get_next_hop_binary (NMIPRoute *route,
+ gpointer next_hop)
+{
+ g_return_val_if_fail (route != NULL, FALSE);
+ g_return_val_if_fail (next_hop != NULL, FALSE);
+
+ if (route->next_hop) {
+ inet_pton (route->family, route->next_hop, next_hop);
+ return TRUE;
+ } else {
+ memset (next_hop, 0,
+ route->family == AF_INET ? sizeof (struct in_addr) : sizeof (struct in6_addr));
+ return FALSE;
+ }
+}
+
+/**
+ * nm_ip_route_set_next_hop_binary: (skip)
+ * @route: the #NMIPRoute
+ * @next_hop: the route's next hop, in binary format
+ *
+ * Sets the destination property of this route object.
+ *
+ * @next_hop (if non-%NULL) must point to a buffer that is the correct size for
+ * @route's family.
+ **/
+void
+nm_ip_route_set_next_hop_binary (NMIPRoute *route,
+ gconstpointer next_hop)
+{
+ char string[NM_UTILS_INET_ADDRSTRLEN];
+
+ g_return_if_fail (route != NULL);
+
+ g_free (route->next_hop);
+ if (next_hop)
+ route->next_hop = g_strdup (inet_ntop (route->family, next_hop, string, sizeof (string)));
+ else
+ route->next_hop = NULL;
+}
+
+/**
+ * nm_ip_route_get_metric:
+ * @route: the #NMIPRoute
+ *
+ * Gets the route metric property of this route object; lower values
+ * indicate "better" or more preferred routes; -1 indicates "default"
+ * (meaning NetworkManager will set it appropriately).
+ *
+ * Returns: the route metric
+ **/
+gint64
+nm_ip_route_get_metric (NMIPRoute *route)
+{
+ g_return_val_if_fail (route != NULL, 0);
+ g_return_val_if_fail (route->refcount > 0, 0);
+
+ return route->metric;
+}
+
+/**
+ * nm_ip_route_set_metric:
+ * @route: the #NMIPRoute
+ * @metric: the route metric (or -1 for "default")
+ *
+ * Sets the metric property of this route object.
+ **/
+void
+nm_ip_route_set_metric (NMIPRoute *route,
+ gint64 metric)
+{
+ g_return_if_fail (route != NULL);
+ g_return_if_fail (valid_metric (metric, NULL));
+
+ route->metric = metric;
+}
+
+/**
+ * nm_ip_route_get_attribute_names:
+ * @route: the #NMIPRoute
+ *
+ * Gets an array of attribute names defined on @route.
+ *
+ * Returns: (transfer full): a %NULL-terminated array of attribute names
+ **/
+char **
+nm_ip_route_get_attribute_names (NMIPRoute *route)
+{
+ GHashTableIter iter;
+ const char *key;
+ GPtrArray *names;
+
+ g_return_val_if_fail (route != NULL, NULL);
+
+ names = g_ptr_array_new ();
+
+ if (route->attributes) {
+ g_hash_table_iter_init (&iter, route->attributes);
+ while (g_hash_table_iter_next (&iter, (gpointer *) &key, NULL))
+ g_ptr_array_add (names, g_strdup (key));
+ }
+ g_ptr_array_add (names, NULL);
+
+ return (char **) g_ptr_array_free (names, FALSE);
+}
+
+/**
+ * nm_ip_route_get_attribute:
+ * @route: the #NMIPRoute
+ * @name: the name of an route attribute
+ *
+ * Gets the value of the attribute with name @name on @route
+ *
+ * Returns: (transfer none): the value of the attribute with name @name on
+ * @route, or %NULL if @route has no such attribute.
+ **/
+GVariant *
+nm_ip_route_get_attribute (NMIPRoute *route, const char *name)
+{
+ g_return_val_if_fail (route != NULL, NULL);
+ g_return_val_if_fail (name != NULL && *name != '\0', NULL);
+
+ if (route->attributes)
+ return g_hash_table_lookup (route->attributes, name);
+ else
+ return NULL;
+}
+
+/**
+ * nm_ip_route_set_attribute:
+ * @route: the #NMIPRoute
+ * @name: the name of a route attribute
+ * @value: (transfer none) (allow-none): the value
+ *
+ * Sets the named attribute on @route to the given value.
+ **/
+void
+nm_ip_route_set_attribute (NMIPRoute *route, const char *name, GVariant *value)
+{
+ g_return_if_fail (route != NULL);
+ g_return_if_fail (name != NULL && *name != '\0');
+ g_return_if_fail ( strcmp (name, "dest") != 0 && strcmp (name, "prefix") != 0
+ && strcmp (name, "next-hop") != 0 && strcmp (name, "metric") != 0);
+
+ if (!route->attributes) {
+ route->attributes = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, (GDestroyNotify) g_variant_unref);
+ }
+
+ if (value)
+ g_hash_table_insert (route->attributes, g_strdup (name), g_variant_ref_sink (value));
+ else
+ g_hash_table_remove (route->attributes, name);
+}
+
+
+G_DEFINE_ABSTRACT_TYPE (NMSettingIPConfig, nm_setting_ip_config, NM_TYPE_SETTING)
+
+#define NM_SETTING_IP_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_IP_CONFIG, NMSettingIPConfigPrivate))
+
+typedef struct {
+ char *method;
+ GPtrArray *dns; /* array of IP address strings */
+ GPtrArray *dns_search; /* array of domain name strings */
+ GPtrArray *addresses; /* array of NMIPAddress */
+ GPtrArray *routes; /* array of NMIPRoute */
+ gint64 route_metric;
+ char *gateway;
+ gboolean ignore_auto_routes;
+ gboolean ignore_auto_dns;
+ char *dhcp_hostname;
+ gboolean dhcp_send_hostname;
+ gboolean never_default;
+ gboolean may_fail;
+} NMSettingIPConfigPrivate;
+
+enum {
+ PROP_0,
+ PROP_METHOD,
+ PROP_DNS,
+ PROP_DNS_SEARCH,
+ PROP_ADDRESSES,
+ PROP_GATEWAY,
+ PROP_ROUTES,
+ PROP_ROUTE_METRIC,
+ PROP_IGNORE_AUTO_ROUTES,
+ PROP_IGNORE_AUTO_DNS,
+ PROP_DHCP_HOSTNAME,
+ PROP_DHCP_SEND_HOSTNAME,
+ PROP_NEVER_DEFAULT,
+ PROP_MAY_FAIL,
+
+ LAST_PROP
+};
+
+#define NM_SETTING_IP_CONFIG_GET_FAMILY(setting) (NM_IS_SETTING_IP4_CONFIG (setting) ? AF_INET : AF_INET6)
+
+/**
+ * nm_setting_ip_config_get_method:
+ * @setting: the #NMSettingIPConfig
+ *
+ * Returns: the #NMSettingIPConfig:method property of the setting; see
+ * #NMSettingIP4Config and #NMSettingIP6Config for details of the
+ * methods available with each type.
+ **/
+const char *
+nm_setting_ip_config_get_method (NMSettingIPConfig *setting)
+{
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), NULL);
+
+ return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->method;
+}
+
+/**
+ * nm_setting_ip_config_get_num_dns:
+ * @setting: the #NMSettingIPConfig
+ *
+ * Returns: the number of configured DNS servers
+ **/
+guint
+nm_setting_ip_config_get_num_dns (NMSettingIPConfig *setting)
+{
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), 0);
+
+ return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->dns->len;
+}
+
+/**
+ * nm_setting_ip_config_get_dns:
+ * @setting: the #NMSettingIPConfig
+ * @i: index number of the DNS server to return
+ *
+ * Returns: the IP address of the DNS server at index @i
+ **/
+const char *
+nm_setting_ip_config_get_dns (NMSettingIPConfig *setting, int i)
+{
+ NMSettingIPConfigPrivate *priv;
+
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), NULL);
+
+ priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
+ g_return_val_if_fail (i < priv->dns->len, NULL);
+
+ return priv->dns->pdata[i];
+}
+
+/**
+ * nm_setting_ip_config_add_dns:
+ * @setting: the #NMSettingIPConfig
+ * @dns: the IP address of the DNS server to add
+ *
+ * Adds a new DNS server to the setting.
+ *
+ * Returns: %TRUE if the DNS server was added; %FALSE if the server was already
+ * known
+ **/
+gboolean
+nm_setting_ip_config_add_dns (NMSettingIPConfig *setting, const char *dns)
+{
+ NMSettingIPConfigPrivate *priv;
+ char *dns_canonical;
+ int i;
+
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
+ g_return_val_if_fail (dns != NULL, FALSE);
+ g_return_val_if_fail (nm_utils_ipaddr_valid (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), dns), FALSE);
+
+ priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
+
+ dns_canonical = canonicalize_ip (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), dns, FALSE);
+ for (i = 0; i < priv->dns->len; i++) {
+ if (!strcmp (dns_canonical, priv->dns->pdata[i])) {
+ g_free (dns_canonical);
+ return FALSE;
+ }
+ }
+
+ g_ptr_array_add (priv->dns, dns_canonical);
+ g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_DNS);
+ return TRUE;
+}
+
+/**
+ * nm_setting_ip_config_remove_dns:
+ * @setting: the #NMSettingIPConfig
+ * @i: index number of the DNS server to remove
+ *
+ * Removes the DNS server at index @i.
+ **/
+void
+nm_setting_ip_config_remove_dns (NMSettingIPConfig *setting, int i)
+{
+ NMSettingIPConfigPrivate *priv;
+
+ g_return_if_fail (NM_IS_SETTING_IP_CONFIG (setting));
+
+ priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
+ g_return_if_fail (i < priv->dns->len);
+
+ g_ptr_array_remove_index (priv->dns, i);
+ g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_DNS);
+}
+
+/**
+ * nm_setting_ip_config_remove_dns_by_value:
+ * @setting: the #NMSettingIPConfig
+ * @dns: the DNS server to remove
+ *
+ * Removes the DNS server @dns.
+ *
+ * Returns: %TRUE if the DNS server was found and removed; %FALSE if it was not.
+ **/
+gboolean
+nm_setting_ip_config_remove_dns_by_value (NMSettingIPConfig *setting, const char *dns)
+{
+ NMSettingIPConfigPrivate *priv;
+ char *dns_canonical;
+ int i;
+
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
+ g_return_val_if_fail (dns != NULL, FALSE);
+ g_return_val_if_fail (nm_utils_ipaddr_valid (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), dns), FALSE);
+
+ priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
+
+ dns_canonical = canonicalize_ip (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), dns, FALSE);
+ for (i = 0; i < priv->dns->len; i++) {
+ if (!strcmp (dns_canonical, priv->dns->pdata[i])) {
+ g_ptr_array_remove_index (priv->dns, i);
+ g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_DNS);
+ g_free (dns_canonical);
+ return TRUE;
+ }
+ }
+ g_free (dns_canonical);
+ return FALSE;
+}
+
+/**
+ * nm_setting_ip_config_clear_dns:
+ * @setting: the #NMSettingIPConfig
+ *
+ * Removes all configured DNS servers.
+ **/
+void
+nm_setting_ip_config_clear_dns (NMSettingIPConfig *setting)
+{
+ NMSettingIPConfigPrivate *priv;
+
+ g_return_if_fail (NM_IS_SETTING_IP_CONFIG (setting));
+
+ priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
+ g_ptr_array_set_size (priv->dns, 0);
+ g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_DNS);
+}
+
+/**
+ * nm_setting_ip_config_get_num_dns_searches:
+ * @setting: the #NMSettingIPConfig
+ *
+ * Returns: the number of configured DNS search domains
+ **/
+guint
+nm_setting_ip_config_get_num_dns_searches (NMSettingIPConfig *setting)
+{
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), 0);
+
+ return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->dns_search->len;
+}
+
+/**
+ * nm_setting_ip_config_get_dns_search:
+ * @setting: the #NMSettingIPConfig
+ * @i: index number of the DNS search domain to return
+ *
+ * Returns: the DNS search domain at index @i
+ **/
+const char *
+nm_setting_ip_config_get_dns_search (NMSettingIPConfig *setting, int i)
+{
+ NMSettingIPConfigPrivate *priv;
+
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), NULL);
+
+ priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
+ g_return_val_if_fail (i < priv->dns_search->len, NULL);
+
+ return priv->dns_search->pdata[i];
+}
+
+/**
+ * nm_setting_ip_config_add_dns_search:
+ * @setting: the #NMSettingIPConfig
+ * @dns_search: the search domain to add
+ *
+ * Adds a new DNS search domain to the setting.
+ *
+ * Returns: %TRUE if the DNS search domain was added; %FALSE if the search
+ * domain was already known
+ **/
+gboolean
+nm_setting_ip_config_add_dns_search (NMSettingIPConfig *setting,
+ const char *dns_search)
+{
+ NMSettingIPConfigPrivate *priv;
+ int i;
+
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
+ g_return_val_if_fail (dns_search != NULL, FALSE);
+ g_return_val_if_fail (dns_search[0] != '\0', FALSE);
+
+ priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
+ for (i = 0; i < priv->dns_search->len; i++) {
+ if (!strcmp (dns_search, priv->dns_search->pdata[i]))
+ return FALSE;
+ }
+
+ g_ptr_array_add (priv->dns_search, g_strdup (dns_search));
+ g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_DNS_SEARCH);
+ return TRUE;
+}
+
+/**
+ * nm_setting_ip_config_remove_dns_search:
+ * @setting: the #NMSettingIPConfig
+ * @i: index number of the DNS search domain
+ *
+ * Removes the DNS search domain at index @i.
+ **/
+void
+nm_setting_ip_config_remove_dns_search (NMSettingIPConfig *setting, int i)
+{
+ NMSettingIPConfigPrivate *priv;
+
+ g_return_if_fail (NM_IS_SETTING_IP_CONFIG (setting));
+
+ priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
+ g_return_if_fail (i < priv->dns_search->len);
+
+ g_ptr_array_remove_index (priv->dns_search, i);
+ g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_DNS_SEARCH);
+}
+
+/**
+ * nm_setting_ip_config_remove_dns_search_by_value:
+ * @setting: the #NMSettingIPConfig
+ * @dns_search: the search domain to remove
+ *
+ * Removes the DNS search domain @dns_search.
+ *
+ * Returns: %TRUE if the DNS search domain was found and removed; %FALSE if it was not.
+ *
+ * Since 0.9.10
+ **/
+gboolean
+nm_setting_ip_config_remove_dns_search_by_value (NMSettingIPConfig *setting,
+ const char *dns_search)
+{
+ NMSettingIPConfigPrivate *priv;
+ int i;
+
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
+ g_return_val_if_fail (dns_search != NULL, FALSE);
+ g_return_val_if_fail (dns_search[0] != '\0', FALSE);
+
+ priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
+ for (i = 0; i < priv->dns_search->len; i++) {
+ if (!strcmp (dns_search, priv->dns_search->pdata[i])) {
+ g_ptr_array_remove_index (priv->dns_search, i);
+ g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_DNS_SEARCH);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/**
+ * nm_setting_ip_config_clear_dns_searches:
+ * @setting: the #NMSettingIPConfig
+ *
+ * Removes all configured DNS search domains.
+ **/
+void
+nm_setting_ip_config_clear_dns_searches (NMSettingIPConfig *setting)
+{
+ NMSettingIPConfigPrivate *priv;
+
+ g_return_if_fail (NM_IS_SETTING_IP_CONFIG (setting));
+
+ priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
+ g_ptr_array_set_size (priv->dns_search, 0);
+ g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_DNS_SEARCH);
+}
+
+/**
+ * nm_setting_ip_config_get_num_addresses:
+ * @setting: the #NMSettingIPConfig
+ *
+ * Returns: the number of configured addresses
+ **/
+guint
+nm_setting_ip_config_get_num_addresses (NMSettingIPConfig *setting)
+{
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), 0);
+
+ return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->addresses->len;
+}
+
+/**
+ * nm_setting_ip_config_get_address:
+ * @setting: the #NMSettingIPConfig
+ * @i: index number of the address to return
+ *
+ * Returns: the address at index @i
+ **/
+NMIPAddress *
+nm_setting_ip_config_get_address (NMSettingIPConfig *setting, int i)
+{
+ NMSettingIPConfigPrivate *priv;
+
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), NULL);
+
+ priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
+ g_return_val_if_fail (i < priv->addresses->len, NULL);
+
+ return priv->addresses->pdata[i];
+}
+
+/**
+ * nm_setting_ip_config_add_address:
+ * @setting: the #NMSettingIPConfig
+ * @address: the new address to add
+ *
+ * Adds a new IP address and associated information to the setting. The
+ * given address is duplicated internally and is not changed by this function.
+ *
+ * Returns: %TRUE if the address was added; %FALSE if the address was already
+ * known.
+ **/
+gboolean
+nm_setting_ip_config_add_address (NMSettingIPConfig *setting,
+ NMIPAddress *address)
+{
+ NMSettingIPConfigPrivate *priv;
+ int i;
+
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
+ g_return_val_if_fail (address != NULL, FALSE);
+ g_return_val_if_fail (address->family == NM_SETTING_IP_CONFIG_GET_FAMILY (setting), FALSE);
+
+ priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
+ for (i = 0; i < priv->addresses->len; i++) {
+ if (nm_ip_address_equal (priv->addresses->pdata[i], address))
+ return FALSE;
+ }
+
+ g_ptr_array_add (priv->addresses, nm_ip_address_dup (address));
+
+ g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_ADDRESSES);
+ return TRUE;
+}
+
+/**
+ * nm_setting_ip_config_remove_address:
+ * @setting: the #NMSettingIPConfig
+ * @i: index number of the address to remove
+ *
+ * Removes the address at index @i.
+ **/
+void
+nm_setting_ip_config_remove_address (NMSettingIPConfig *setting, int i)
+{
+ NMSettingIPConfigPrivate *priv;
+
+ g_return_if_fail (NM_IS_SETTING_IP_CONFIG (setting));
+
+ priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
+ g_return_if_fail (i < priv->addresses->len);
+
+ g_ptr_array_remove_index (priv->addresses, i);
+
+ g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_ADDRESSES);
+}
+
+/**
+ * nm_setting_ip_config_remove_address_by_value:
+ * @setting: the #NMSettingIPConfig
+ * @address: the IP address to remove
+ *
+ * Removes the address @address.
+ *
+ * Returns: %TRUE if the address was found and removed; %FALSE if it was not.
+ **/
+gboolean
+nm_setting_ip_config_remove_address_by_value (NMSettingIPConfig *setting,
+ NMIPAddress *address)
+{
+ NMSettingIPConfigPrivate *priv;
+ int i;
+
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
+ g_return_val_if_fail (address != NULL, FALSE);
+
+ priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
+ for (i = 0; i < priv->addresses->len; i++) {
+ if (nm_ip_address_equal (priv->addresses->pdata[i], address)) {
+ g_ptr_array_remove_index (priv->addresses, i);
+ g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_ADDRESSES);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/**
+ * nm_setting_ip_config_clear_addresses:
+ * @setting: the #NMSettingIPConfig
+ *
+ * Removes all configured addresses.
+ **/
+void
+nm_setting_ip_config_clear_addresses (NMSettingIPConfig *setting)
+{
+ NMSettingIPConfigPrivate *priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
+
+ g_return_if_fail (NM_IS_SETTING_IP_CONFIG (setting));
+
+ g_ptr_array_set_size (priv->addresses, 0);
+ g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_ADDRESSES);
+}
+
+/**
+ * nm_setting_ip_config_get_gateway:
+ * @setting: the #NMSettingIPConfig
+ *
+ * Returns: the IP address of the gateway associated with this configuration, or
+ * %NULL.
+ **/
+const char *
+nm_setting_ip_config_get_gateway (NMSettingIPConfig *setting)
+{
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), NULL);
+
+ return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->gateway;
+}
+
+/**
+ * nm_setting_ip_config_get_num_routes:
+ * @setting: the #NMSettingIPConfig
+ *
+ * Returns: the number of configured routes
+ **/
+guint
+nm_setting_ip_config_get_num_routes (NMSettingIPConfig *setting)
+{
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), 0);
+
+ return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->routes->len;
+}
+
+/**
+ * nm_setting_ip_config_get_route:
+ * @setting: the #NMSettingIPConfig
+ * @i: index number of the route to return
+ *
+ * Returns: the route at index @i
+ **/
+NMIPRoute *
+nm_setting_ip_config_get_route (NMSettingIPConfig *setting, int i)
+{
+ NMSettingIPConfigPrivate *priv;
+
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), NULL);
+
+ priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
+ g_return_val_if_fail (i < priv->routes->len, NULL);
+
+ return priv->routes->pdata[i];
+}
+
+/**
+ * nm_setting_ip_config_add_route:
+ * @setting: the #NMSettingIPConfig
+ * @route: the route to add
+ *
+ * Adds a new route and associated information to the setting. The
+ * given route is duplicated internally and is not changed by this function.
+ *
+ * Returns: %TRUE if the route was added; %FALSE if the route was already known.
+ **/
+gboolean
+nm_setting_ip_config_add_route (NMSettingIPConfig *setting,
+ NMIPRoute *route)
+{
+ NMSettingIPConfigPrivate *priv;
+ int i;
+
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
+ g_return_val_if_fail (route != NULL, FALSE);
+ g_return_val_if_fail (route->family == NM_SETTING_IP_CONFIG_GET_FAMILY (setting), FALSE);
+
+ priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
+ for (i = 0; i < priv->routes->len; i++) {
+ if (nm_ip_route_equal (priv->routes->pdata[i], route))
+ return FALSE;
+ }
+
+ g_ptr_array_add (priv->routes, nm_ip_route_dup (route));
+ g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_ROUTES);
+ return TRUE;
+}
+
+/**
+ * nm_setting_ip_config_remove_route:
+ * @setting: the #NMSettingIPConfig
+ * @i: index number of the route
+ *
+ * Removes the route at index @i.
+ **/
+void
+nm_setting_ip_config_remove_route (NMSettingIPConfig *setting, int i)
+{
+ NMSettingIPConfigPrivate *priv;
+
+ g_return_if_fail (NM_IS_SETTING_IP_CONFIG (setting));
+
+ priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
+ g_return_if_fail (i < priv->routes->len);
+
+ g_ptr_array_remove_index (priv->routes, i);
+ g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_ROUTES);
+}
+
+/**
+ * nm_setting_ip_config_remove_route_by_value:
+ * @setting: the #NMSettingIPConfig
+ * @route: the route to remove
+ *
+ * Removes the route @route.
+ *
+ * Returns: %TRUE if the route was found and removed; %FALSE if it was not.
+ **/
+gboolean
+nm_setting_ip_config_remove_route_by_value (NMSettingIPConfig *setting,
+ NMIPRoute *route)
+{
+ NMSettingIPConfigPrivate *priv;
+ int i;
+
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
+ g_return_val_if_fail (route != NULL, FALSE);
+
+ priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
+ for (i = 0; i < priv->routes->len; i++) {
+ if (nm_ip_route_equal (priv->routes->pdata[i], route)) {
+ g_ptr_array_remove_index (priv->routes, i);
+ g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_ROUTES);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/**
+ * nm_setting_ip_config_clear_routes:
+ * @setting: the #NMSettingIPConfig
+ *
+ * Removes all configured routes.
+ **/
+void
+nm_setting_ip_config_clear_routes (NMSettingIPConfig *setting)
+{
+ NMSettingIPConfigPrivate *priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
+
+ g_return_if_fail (NM_IS_SETTING_IP_CONFIG (setting));
+
+ g_ptr_array_set_size (priv->routes, 0);
+ g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_ROUTES);
+}
+
+/**
+ * nm_setting_ip_config_get_route_metric:
+ * @setting: the #NMSettingIPConfig
+ *
+ * Returns the value contained in the #NMSettingIPConfig:route-metric
+ * property.
+ *
+ * Returns: the route metric that is used for routes that don't explicitly
+ * specify a metric. See #NMSettingIPConfig:route-metric for more details.
+ **/
+gint64
+nm_setting_ip_config_get_route_metric (NMSettingIPConfig *setting)
+{
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), -1);
+
+ return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->route_metric;
+}
+
+
+/**
+ * nm_setting_ip_config_get_ignore_auto_routes:
+ * @setting: the #NMSettingIPConfig
+ *
+ * Returns the value contained in the #NMSettingIPConfig:ignore-auto-routes
+ * property.
+ *
+ * Returns: %TRUE if automatically configured (ie via DHCP) routes should be
+ * ignored.
+ **/
+gboolean
+nm_setting_ip_config_get_ignore_auto_routes (NMSettingIPConfig *setting)
+{
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
+
+ return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->ignore_auto_routes;
+}
+
+/**
+ * nm_setting_ip_config_get_ignore_auto_dns:
+ * @setting: the #NMSettingIPConfig
+ *
+ * Returns the value contained in the #NMSettingIPConfig:ignore-auto-dns
+ * property.
+ *
+ * Returns: %TRUE if automatically configured (ie via DHCP) DNS information
+ * should be ignored.
+ **/
+gboolean
+nm_setting_ip_config_get_ignore_auto_dns (NMSettingIPConfig *setting)
+{
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
+
+ return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->ignore_auto_dns;
+}
+
+/**
+ * nm_setting_ip_config_get_dhcp_hostname:
+ * @setting: the #NMSettingIPConfig
+ *
+ * Returns the value contained in the #NMSettingIPConfig:dhcp-hostname
+ * property.
+ *
+ * Returns: the configured hostname to send to the DHCP server
+ **/
+const char *
+nm_setting_ip_config_get_dhcp_hostname (NMSettingIPConfig *setting)
+{
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), NULL);
+
+ return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->dhcp_hostname;
+}
+
+/**
+ * nm_setting_ip_config_get_dhcp_send_hostname:
+ * @setting: the #NMSettingIPConfig
+ *
+ * Returns the value contained in the #NMSettingIPConfig:dhcp-send-hostname
+ * property.
+ *
+ * Returns: %TRUE if NetworkManager should send the machine hostname to the
+ * DHCP server when requesting addresses to allow the server to automatically
+ * update DNS information for this machine.
+ **/
+gboolean
+nm_setting_ip_config_get_dhcp_send_hostname (NMSettingIPConfig *setting)
+{
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
+
+ return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->dhcp_send_hostname;
+}
+
+/**
+ * nm_setting_ip_config_get_never_default:
+ * @setting: the #NMSettingIPConfig
+ *
+ * Returns the value contained in the #NMSettingIPConfig:never-default
+ * property.
+ *
+ * Returns: %TRUE if this connection should never be the default
+ * connection
+ **/
+gboolean
+nm_setting_ip_config_get_never_default (NMSettingIPConfig *setting)
+{
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
+
+ return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->never_default;
+}
+
+/**
+ * nm_setting_ip_config_get_may_fail:
+ * @setting: the #NMSettingIPConfig
+ *
+ * Returns the value contained in the #NMSettingIPConfig:may-fail
+ * property.
+ *
+ * Returns: %TRUE if this connection doesn't require this type of IP
+ * addressing to complete for the connection to succeed.
+ **/
+gboolean
+nm_setting_ip_config_get_may_fail (NMSettingIPConfig *setting)
+{
+ g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE);
+
+ return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->may_fail;
+}
+
+static gboolean
+verify_label (const char *label)
+{
+ const char *p;
+ char *iface;
+
+ p = strchr (label, ':');
+ if (!p)
+ return FALSE;
+ iface = g_strndup (label, p - label);
+ if (!nm_utils_iface_valid_name (iface)) {
+ g_free (iface);
+ return FALSE;
+ }
+ g_free (iface);
+
+ for (p++; *p; p++) {
+ if (!g_ascii_isalnum (*p) && *p != '_')
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean
+verify (NMSetting *setting, NMConnection *connection, GError **error)
+{
+ NMSettingIPConfigPrivate *priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
+ int i;
+
+ if (!priv->method) {
+ g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_MISSING_PROPERTY,
+ _("property is missing"));
+ g_prefix_error (error, "%s.%s: ", nm_setting_get_name (setting), NM_SETTING_IP_CONFIG_METHOD);
+ return FALSE;
+ }
+
+ if (priv->dhcp_hostname && !*priv->dhcp_hostname) {
+ g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY,
+ _("property is empty"));
+ g_prefix_error (error, "%s.%s: ", nm_setting_get_name (setting), NM_SETTING_IP_CONFIG_DHCP_HOSTNAME);
+ return FALSE;
+ }
+
+ /* Validate DNS */
+ for (i = 0; i < priv->dns->len; i++) {
+ const char *dns = priv->dns->pdata[i];
+
+ if (!nm_utils_ipaddr_valid (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), dns)) {
+ g_set_error (error,
+ NM_CONNECTION_ERROR,
+ NM_CONNECTION_ERROR_INVALID_PROPERTY,
+ _("%d. DNS server address is invalid"),
+ i+1);
+ g_prefix_error (error, "%s.%s: ", nm_setting_get_name (setting), NM_SETTING_IP_CONFIG_DNS);
+ return FALSE;
+ }
+ }
+
+ /* Validate addresses */
+ for (i = 0; i < priv->addresses->len; i++) {
+ NMIPAddress *addr = (NMIPAddress *) priv->addresses->pdata[i];
+ GVariant *label;
+
+ if (nm_ip_address_get_family (addr) != NM_SETTING_IP_CONFIG_GET_FAMILY (setting)) {
+ g_set_error (error,
+ NM_CONNECTION_ERROR,
+ NM_CONNECTION_ERROR_INVALID_PROPERTY,
+ _("%d. IP address is invalid"),
+ i+1);
+ g_prefix_error (error, "%s.%s: ", nm_setting_get_name (setting), NM_SETTING_IP_CONFIG_ADDRESSES);
+ return FALSE;
+ }
+
+ label = nm_ip_address_get_attribute (addr, "label");
+ if (label) {
+ if (!g_variant_is_of_type (label, G_VARIANT_TYPE_STRING)) {
+ g_set_error (error,
+ NM_CONNECTION_ERROR,
+ NM_CONNECTION_ERROR_INVALID_PROPERTY,
+ _("%d. IP address has 'label' property with invalid type"),
+ i+1);
+ g_prefix_error (error, "%s.%s: ", nm_setting_get_name (setting), NM_SETTING_IP_CONFIG_ADDRESSES);
+ return FALSE;
+ }
+ if (!verify_label (g_variant_get_string (label, NULL))) {
+ g_set_error (error,
+ NM_CONNECTION_ERROR,
+ NM_CONNECTION_ERROR_INVALID_PROPERTY,
+ _("%d. IP address has invalid label '%s'"),
+ i+1, g_variant_get_string (label, NULL));
+ g_prefix_error (error, "%s.%s: ", nm_setting_get_name (setting), NM_SETTING_IP_CONFIG_ADDRESSES);
+ return FALSE;
+ }
+ }
+ }
+
+ /* Validate gateway */
+ if (priv->gateway) {
+ if (!priv->addresses->len) {
+ g_set_error_literal (error,
+ NM_CONNECTION_ERROR,
+ NM_CONNECTION_ERROR_INVALID_PROPERTY,
+ _("gateway cannot be set if there are no addresses configured"));
+ g_prefix_error (error, "%s.%s: ", nm_setting_get_name (setting), NM_SETTING_IP_CONFIG_GATEWAY);
+ return FALSE;
+ }
+
+ if (!nm_utils_ipaddr_valid (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), priv->gateway)) {
+ g_set_error_literal (error,
+ NM_CONNECTION_ERROR,
+ NM_CONNECTION_ERROR_INVALID_PROPERTY,
+ _("gateway is invalid"));
+ g_prefix_error (error, "%s.%s: ", nm_setting_get_name (setting), NM_SETTING_IP_CONFIG_GATEWAY);
+ return FALSE;
+ }
+ }
+
+ /* Validate routes */
+ for (i = 0; i < priv->routes->len; i++) {
+ NMIPRoute *route = (NMIPRoute *) priv->routes->pdata[i];
+
+ if (nm_ip_route_get_family (route) != NM_SETTING_IP_CONFIG_GET_FAMILY (setting)) {
+ g_set_error (error,
+ NM_CONNECTION_ERROR,
+ NM_CONNECTION_ERROR_INVALID_PROPERTY,
+ _("%d. route is invalid"),
+ i+1);
+ g_prefix_error (error, "%s.%s: ", nm_setting_get_name (setting), NM_SETTING_IP_CONFIG_ROUTES);
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+
+static void
+nm_setting_ip_config_init (NMSettingIPConfig *setting)
+{
+ NMSettingIPConfigPrivate *priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
+
+ priv->dns = g_ptr_array_new_with_free_func (g_free);
+ priv->dns_search = g_ptr_array_new_with_free_func (g_free);
+ priv->addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref);
+ priv->routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref);
+}
+
+static void
+finalize (GObject *object)
+{
+ NMSettingIPConfig *self = NM_SETTING_IP_CONFIG (object);
+ NMSettingIPConfigPrivate *priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (self);
+
+ g_free (priv->method);
+ g_free (priv->gateway);
+ g_free (priv->dhcp_hostname);
+
+ g_ptr_array_unref (priv->dns);
+ g_ptr_array_unref (priv->dns_search);
+ g_ptr_array_unref (priv->addresses);
+ g_ptr_array_unref (priv->routes);
+
+ G_OBJECT_CLASS (nm_setting_ip_config_parent_class)->finalize (object);
+}
+
+static void
+set_property (GObject *object, guint prop_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ NMSettingIPConfig *setting = NM_SETTING_IP_CONFIG (object);
+ NMSettingIPConfigPrivate *priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
+ const char *gateway;
+
+ switch (prop_id) {
+ case PROP_METHOD:
+ g_free (priv->method);
+ priv->method = g_value_dup_string (value);
+ break;
+ case PROP_DNS:
+ g_ptr_array_unref (priv->dns);
+ priv->dns = _nm_utils_strv_to_ptrarray (g_value_get_boxed (value));
+ break;
+ case PROP_DNS_SEARCH:
+ g_ptr_array_unref (priv->dns_search);
+ priv->dns_search = _nm_utils_strv_to_ptrarray (g_value_get_boxed (value));
+ break;
+ case PROP_ADDRESSES:
+ g_ptr_array_unref (priv->addresses);
+ priv->addresses = _nm_utils_copy_array (g_value_get_boxed (value),
+ (NMUtilsCopyFunc) nm_ip_address_dup,
+ (GDestroyNotify) nm_ip_address_unref);
+ break;
+ case PROP_GATEWAY:
+ gateway = g_value_get_string (value);
+ g_return_if_fail (!gateway || nm_utils_ipaddr_valid (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), gateway));
+ g_free (priv->gateway);
+ priv->gateway = canonicalize_ip (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), gateway, TRUE);
+ break;
+ case PROP_ROUTES:
+ g_ptr_array_unref (priv->routes);
+ priv->routes = _nm_utils_copy_array (g_value_get_boxed (value),
+ (NMUtilsCopyFunc) nm_ip_route_dup,
+ (GDestroyNotify) nm_ip_route_unref);
+ break;
+ case PROP_ROUTE_METRIC:
+ priv->route_metric = g_value_get_int64 (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_DHCP_HOSTNAME:
+ g_free (priv->dhcp_hostname);
+ priv->dhcp_hostname = g_value_dup_string (value);
+ break;
+ case PROP_DHCP_SEND_HOSTNAME:
+ priv->dhcp_send_hostname = g_value_get_boolean (value);
+ break;
+ case PROP_NEVER_DEFAULT:
+ priv->never_default = g_value_get_boolean (value);
+ break;
+ case PROP_MAY_FAIL:
+ priv->may_fail = g_value_get_boolean (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+get_property (GObject *object, guint prop_id,
+ GValue *value, GParamSpec *pspec)
+{
+ NMSettingIPConfig *setting = NM_SETTING_IP_CONFIG (object);
+ NMSettingIPConfigPrivate *priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
+
+ switch (prop_id) {
+ case PROP_METHOD:
+ g_value_set_string (value, nm_setting_ip_config_get_method (setting));
+ break;
+ case PROP_DNS:
+ g_value_take_boxed (value, _nm_utils_ptrarray_to_strv (priv->dns));
+ break;
+ case PROP_DNS_SEARCH:
+ g_value_take_boxed (value, _nm_utils_ptrarray_to_strv (priv->dns_search));
+ break;
+ case PROP_ADDRESSES:
+ g_value_take_boxed (value, _nm_utils_copy_array (priv->addresses,
+ (NMUtilsCopyFunc) nm_ip_address_dup,
+ (GDestroyNotify) nm_ip_address_unref));
+ break;
+ case PROP_GATEWAY:
+ g_value_set_string (value, nm_setting_ip_config_get_gateway (setting));
+ break;
+ case PROP_ROUTES:
+ g_value_take_boxed (value, _nm_utils_copy_array (priv->routes,
+ (NMUtilsCopyFunc) nm_ip_route_dup,
+ (GDestroyNotify) nm_ip_route_unref));
+ break;
+ case PROP_ROUTE_METRIC:
+ g_value_set_int64 (value, priv->route_metric);
+ break;
+ case PROP_IGNORE_AUTO_ROUTES:
+ g_value_set_boolean (value, nm_setting_ip_config_get_ignore_auto_routes (setting));
+ break;
+ case PROP_IGNORE_AUTO_DNS:
+ g_value_set_boolean (value, nm_setting_ip_config_get_ignore_auto_dns (setting));
+ break;
+ case PROP_DHCP_HOSTNAME:
+ g_value_set_string (value, nm_setting_ip_config_get_dhcp_hostname (setting));
+ break;
+ case PROP_DHCP_SEND_HOSTNAME:
+ g_value_set_boolean (value, nm_setting_ip_config_get_dhcp_send_hostname (setting));
+ break;
+ case PROP_NEVER_DEFAULT:
+ g_value_set_boolean (value, priv->never_default);
+ break;
+ case PROP_MAY_FAIL:
+ g_value_set_boolean (value, priv->may_fail);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+nm_setting_ip_config_class_init (NMSettingIPConfigClass *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 (NMSettingIPConfigPrivate));
+
+ /* virtual methods */
+ object_class->set_property = set_property;
+ object_class->get_property = get_property;
+ object_class->finalize = finalize;
+ parent_class->verify = verify;
+
+ /* Properties */
+
+ /**
+ * NMSettingIPConfig:method:
+ *
+ * IP configuration method.
+ *
+ * #NMSettingIP4Config and #NMSettingIP6Config both support "auto",
+ * "manual", and "link-local". See the subclass-specific documentation for
+ * other values.
+ *
+ * In general, for the "auto" method, properties such as
+ * #NMSettingIPConfig:dns and #NMSettingIPConfig:routes specify information
+ * that is added on to the information returned from automatic
+ * configuration. The #NMSettingIPConfig:ignore-auto-routes and
+ * #NMSettingIPConfig:ignore-auto-dns properties modify this behavior.
+ *
+ * For methods that imply no upstream network, such as "shared" or
+ * "link-local", these properties must be empty.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_METHOD,
+ g_param_spec_string (NM_SETTING_IP_CONFIG_METHOD, "", "",
+ NULL,
+ G_PARAM_READWRITE |
+ NM_SETTING_PARAM_INFERRABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * NMSettingIPConfig:dns:
+ *
+ * Array of IP addresses of DNS servers.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_DNS,
+ g_param_spec_boxed (NM_SETTING_IP_CONFIG_DNS, "", "",
+ G_TYPE_STRV,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * NMSettingIPConfig:dns-search:
+ *
+ * Array of DNS search domains.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_DNS_SEARCH,
+ g_param_spec_boxed (NM_SETTING_IP_CONFIG_DNS_SEARCH, "", "",
+ G_TYPE_STRV,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * NMSettingIPConfig:addresses:
+ *
+ * Array of IP addresses.
+ *
+ * Element-Type: NMIPAddress
+ **/
+ g_object_class_install_property
+ (object_class, PROP_ADDRESSES,
+ g_param_spec_boxed (NM_SETTING_IP_CONFIG_ADDRESSES, "", "",
+ G_TYPE_PTR_ARRAY,
+ G_PARAM_READWRITE |
+ NM_SETTING_PARAM_INFERRABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * NMSettingIPConfig:gateway:
+ *
+ * The gateway associated with this configuration. This is only meaningful
+ * if #NMSettingIPConfig:addresses is also set.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_GATEWAY,
+ g_param_spec_string (NM_SETTING_IP_CONFIG_GATEWAY, "", "",
+ NULL,
+ G_PARAM_READWRITE |
+ NM_SETTING_PARAM_INFERRABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * NMSettingIPConfig:routes:
+ *
+ * Array of IP routes.
+ *
+ * Element-Type: NMIPRoute
+ **/
+ g_object_class_install_property
+ (object_class, PROP_ROUTES,
+ g_param_spec_boxed (NM_SETTING_IP_CONFIG_ROUTES, "", "",
+ G_TYPE_PTR_ARRAY,
+ G_PARAM_READWRITE |
+ NM_SETTING_PARAM_INFERRABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * NMSettingIPConfig:route-metric:
+ *
+ * The default metric for routes that don't explicitly specify a metric.
+ * The default value -1 means that the metric is choosen automatically
+ * based on the device type.
+ * The metric applies to dynamic routes, manual (static) routes that
+ * don't have an explicit metric setting, address prefix routes, and
+ * the default route.
+ * Note that for IPv6, the kernel accepts zero (0) but coerces it to
+ * 1024 (user default). Hence, setting this property to zero effectively
+ * mean setting it to 1024.
+ * For IPv4, zero is a regular value for the metric.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_ROUTE_METRIC,
+ g_param_spec_int64 (NM_SETTING_IP_CONFIG_ROUTE_METRIC, "", "",
+ -1, G_MAXUINT32, -1,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * NMSettingIPConfig:ignore-auto-routes:
+ *
+ * When #NMSettingIPConfig:method is set to "auto" and this property to
+ * %TRUE, automatically configured routes are ignored and only routes
+ * specified in the #NMSettingIPConfig:routes property, if any, are used.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_IGNORE_AUTO_ROUTES,
+ g_param_spec_boolean (NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, "", "",
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * NMSettingIPConfig:ignore-auto-dns:
+ *
+ * When #NMSettingIPConfig:method is set to "auto" and this property to
+ * %TRUE, automatically configured nameservers and search domains are
+ * ignored and only nameservers and search domains specified in the
+ * #NMSettingIPConfig:dns and #NMSettingIPConfig:dns-search properties, if
+ * any, are used.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_IGNORE_AUTO_DNS,
+ g_param_spec_boolean (NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, "", "",
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * NMSettingIPConfig:dhcp-hostname:
+ *
+ * If the #NMSettingIPConfig:dhcp-send-hostname property is %TRUE, then the
+ * specified name will be sent to the DHCP server when acquiring a lease.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_DHCP_HOSTNAME,
+ g_param_spec_string (NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, "", "",
+ NULL,
+ G_PARAM_READWRITE |
+ NM_SETTING_PARAM_INFERRABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * NMSettingIPConfig:dhcp-send-hostname:
+ *
+ * If %TRUE, a hostname is sent to the DHCP server when acquiring a lease.
+ * Some DHCP servers use this hostname to update DNS databases, essentially
+ * providing a static hostname for the computer. If the
+ * #NMSettingIPConfig:dhcp-hostname property is %NULL and this property is
+ * %TRUE, the current persistent hostname of the computer is sent.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_DHCP_SEND_HOSTNAME,
+ g_param_spec_boolean (NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, "", "",
+ TRUE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * NMSettingIPConfig:never-default:
+ *
+ * If %TRUE, this connection will never be the default connection for this
+ * IP type, meaning it will never be assigned the default route by
+ * NetworkManager.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_NEVER_DEFAULT,
+ g_param_spec_boolean (NM_SETTING_IP_CONFIG_NEVER_DEFAULT, "", "",
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * NMSettingIPConfig:may-fail:
+ *
+ * If %TRUE, allow overall network configuration to proceed even if the
+ * configuration specified by this property times out. Note that at least
+ * one IP configuration must succeed or overall network configuration will
+ * still fail. For example, in IPv6-only networks, setting this property to
+ * %TRUE on the #NMSettingIP4Config allows the overall network configuration
+ * to succeed if IPv4 configuration fails but IPv6 configuration completes
+ * successfully.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_MAY_FAIL,
+ g_param_spec_boolean (NM_SETTING_IP_CONFIG_MAY_FAIL, "", "",
+ TRUE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+}
diff --git a/libnm-core/nm-setting-ip-config.h b/libnm-core/nm-setting-ip-config.h
new file mode 100644
index 0000000000..12763fa857
--- /dev/null
+++ b/libnm-core/nm-setting-ip-config.h
@@ -0,0 +1,221 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2007 - 2014 Red Hat, Inc.
+ * Copyright 2007 - 2008 Novell, Inc.
+ */
+
+#ifndef NM_SETTING_IP_CONFIG_H
+#define NM_SETTING_IP_CONFIG_H
+
+#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION)
+#error "Only <NetworkManager.h> can be included directly."
+#endif
+
+#include "nm-setting.h"
+
+G_BEGIN_DECLS
+
+typedef struct NMIPAddress NMIPAddress;
+
+GType nm_ip_address_get_type (void);
+
+NMIPAddress *nm_ip_address_new (int family,
+ const char *addr,
+ guint prefix,
+ GError **error);
+NMIPAddress *nm_ip_address_new_binary (int family,
+ gconstpointer addr,
+ guint prefix,
+ GError **error);
+
+void nm_ip_address_ref (NMIPAddress *address);
+void nm_ip_address_unref (NMIPAddress *address);
+gboolean nm_ip_address_equal (NMIPAddress *address,
+ NMIPAddress *other);
+NMIPAddress *nm_ip_address_dup (NMIPAddress *address);
+
+int nm_ip_address_get_family (NMIPAddress *address);
+const char *nm_ip_address_get_address (NMIPAddress *address);
+void nm_ip_address_set_address (NMIPAddress *address,
+ const char *addr);
+void nm_ip_address_get_address_binary (NMIPAddress *address,
+ gpointer addr);
+void nm_ip_address_set_address_binary (NMIPAddress *address,
+ gconstpointer addr);
+guint nm_ip_address_get_prefix (NMIPAddress *address);
+void nm_ip_address_set_prefix (NMIPAddress *address,
+ guint prefix);
+
+char **nm_ip_address_get_attribute_names (NMIPAddress *address);
+GVariant *nm_ip_address_get_attribute (NMIPAddress *address,
+ const char *name);
+void nm_ip_address_set_attribute (NMIPAddress *address,
+ const char *name,
+ GVariant *value);
+
+
+typedef struct NMIPRoute NMIPRoute;
+
+GType nm_ip_route_get_type (void);
+
+NMIPRoute *nm_ip_route_new (int family,
+ const char *dest,
+ guint prefix,
+ const char *next_hop,
+ gint64 metric,
+ GError **error);
+NMIPRoute *nm_ip_route_new_binary (int family,
+ gconstpointer dest,
+ guint prefix,
+ gconstpointer next_hop,
+ gint64 metric,
+ GError **error);
+
+void nm_ip_route_ref (NMIPRoute *route);
+void nm_ip_route_unref (NMIPRoute *route);
+gboolean nm_ip_route_equal (NMIPRoute *route,
+ NMIPRoute *other);
+NMIPRoute *nm_ip_route_dup (NMIPRoute *route);
+
+int nm_ip_route_get_family (NMIPRoute *route);
+const char *nm_ip_route_get_dest (NMIPRoute *route);
+void nm_ip_route_set_dest (NMIPRoute *route,
+ const char *dest);
+void nm_ip_route_get_dest_binary (NMIPRoute *route,
+ gpointer dest);
+void nm_ip_route_set_dest_binary (NMIPRoute *route,
+ gconstpointer dest);
+guint nm_ip_route_get_prefix (NMIPRoute *route);
+void nm_ip_route_set_prefix (NMIPRoute *route,
+ guint prefix);
+const char *nm_ip_route_get_next_hop (NMIPRoute *route);
+void nm_ip_route_set_next_hop (NMIPRoute *route,
+ const char *next_hop);
+gboolean nm_ip_route_get_next_hop_binary (NMIPRoute *route,
+ gpointer next_hop);
+void nm_ip_route_set_next_hop_binary (NMIPRoute *route,
+ gconstpointer next_hop);
+gint64 nm_ip_route_get_metric (NMIPRoute *route);
+void nm_ip_route_set_metric (NMIPRoute *route,
+ gint64 metric);
+
+char **nm_ip_route_get_attribute_names (NMIPRoute *route);
+GVariant *nm_ip_route_get_attribute (NMIPRoute *route,
+ const char *name);
+void nm_ip_route_set_attribute (NMIPRoute *route,
+ const char *name,
+ GVariant *value);
+
+
+#define NM_TYPE_SETTING_IP_CONFIG (nm_setting_ip_config_get_type ())
+#define NM_SETTING_IP_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_IP_CONFIG, NMSettingIPConfig))
+#define NM_SETTING_IP_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_IPCONFIG, NMSettingIPConfigClass))
+#define NM_IS_SETTING_IP_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_IP_CONFIG))
+#define NM_IS_SETTING_IP_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_IP_CONFIG))
+#define NM_SETTING_IP_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_IP_CONFIG, NMSettingIPConfigClass))
+
+#define NM_SETTING_IP_CONFIG_METHOD "method"
+#define NM_SETTING_IP_CONFIG_DNS "dns"
+#define NM_SETTING_IP_CONFIG_DNS_SEARCH "dns-search"
+#define NM_SETTING_IP_CONFIG_ADDRESSES "addresses"
+#define NM_SETTING_IP_CONFIG_GATEWAY "gateway"
+#define NM_SETTING_IP_CONFIG_ROUTES "routes"
+#define NM_SETTING_IP_CONFIG_ROUTE_METRIC "route-metric"
+#define NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES "ignore-auto-routes"
+#define NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS "ignore-auto-dns"
+#define NM_SETTING_IP_CONFIG_DHCP_HOSTNAME "dhcp-hostname"
+#define NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME "dhcp-send-hostname"
+#define NM_SETTING_IP_CONFIG_NEVER_DEFAULT "never-default"
+#define NM_SETTING_IP_CONFIG_MAY_FAIL "may-fail"
+
+struct _NMSettingIPConfig {
+ NMSetting parent;
+};
+
+typedef struct {
+ NMSettingClass parent;
+
+ /* Padding for future expansion */
+ gpointer padding[8];
+} NMSettingIPConfigClass;
+
+GType nm_setting_ip_config_get_type (void);
+
+const char *nm_setting_ip_config_get_method (NMSettingIPConfig *setting);
+
+guint nm_setting_ip_config_get_num_dns (NMSettingIPConfig *setting);
+const char *nm_setting_ip_config_get_dns (NMSettingIPConfig *setting,
+ int i);
+gboolean nm_setting_ip_config_add_dns (NMSettingIPConfig *setting,
+ const char *dns);
+void nm_setting_ip_config_remove_dns (NMSettingIPConfig *setting,
+ int i);
+gboolean nm_setting_ip_config_remove_dns_by_value (NMSettingIPConfig *setting,
+ const char *dns);
+void nm_setting_ip_config_clear_dns (NMSettingIPConfig *setting);
+
+guint nm_setting_ip_config_get_num_dns_searches (NMSettingIPConfig *setting);
+const char *nm_setting_ip_config_get_dns_search (NMSettingIPConfig *setting,
+ int i);
+gboolean nm_setting_ip_config_add_dns_search (NMSettingIPConfig *setting,
+ const char *dns_search);
+void nm_setting_ip_config_remove_dns_search (NMSettingIPConfig *setting,
+ int i);
+gboolean nm_setting_ip_config_remove_dns_search_by_value (NMSettingIPConfig *setting,
+ const char *dns_search);
+void nm_setting_ip_config_clear_dns_searches (NMSettingIPConfig *setting);
+
+guint nm_setting_ip_config_get_num_addresses (NMSettingIPConfig *setting);
+NMIPAddress *nm_setting_ip_config_get_address (NMSettingIPConfig *setting,
+ int i);
+gboolean nm_setting_ip_config_add_address (NMSettingIPConfig *setting,
+ NMIPAddress *address);
+void nm_setting_ip_config_remove_address (NMSettingIPConfig *setting,
+ int i);
+gboolean nm_setting_ip_config_remove_address_by_value (NMSettingIPConfig *setting,
+ NMIPAddress *address);
+void nm_setting_ip_config_clear_addresses (NMSettingIPConfig *setting);
+
+const char *nm_setting_ip_config_get_gateway (NMSettingIPConfig *setting);
+
+guint nm_setting_ip_config_get_num_routes (NMSettingIPConfig *setting);
+NMIPRoute *nm_setting_ip_config_get_route (NMSettingIPConfig *setting,
+ int i);
+gboolean nm_setting_ip_config_add_route (NMSettingIPConfig *setting,
+ NMIPRoute *route);
+void nm_setting_ip_config_remove_route (NMSettingIPConfig *setting,
+ int i);
+gboolean nm_setting_ip_config_remove_route_by_value (NMSettingIPConfig *setting,
+ NMIPRoute *route);
+void nm_setting_ip_config_clear_routes (NMSettingIPConfig *setting);
+
+gint64 nm_setting_ip_config_get_route_metric (NMSettingIPConfig *setting);
+
+gboolean nm_setting_ip_config_get_ignore_auto_routes (NMSettingIPConfig *setting);
+gboolean nm_setting_ip_config_get_ignore_auto_dns (NMSettingIPConfig *setting);
+
+const char *nm_setting_ip_config_get_dhcp_hostname (NMSettingIPConfig *setting);
+gboolean nm_setting_ip_config_get_dhcp_send_hostname (NMSettingIPConfig *setting);
+
+gboolean nm_setting_ip_config_get_never_default (NMSettingIPConfig *setting);
+gboolean nm_setting_ip_config_get_may_fail (NMSettingIPConfig *setting);
+
+G_END_DECLS
+
+#endif /* NM_SETTING_IP_CONFIG_H */
diff --git a/libnm-core/nm-setting-ip4-config.c b/libnm-core/nm-setting-ip4-config.c
index 00f2df502e..6d897b56de 100644
--- a/libnm-core/nm-setting-ip4-config.c
+++ b/libnm-core/nm-setting-ip4-config.c
@@ -16,69 +16,52 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
- * Copyright 2007 - 2014 Red Hat, Inc.
- * Copyright 2007 - 2008 Novell, Inc.
+ * Copyright 2014 Red Hat, Inc.
*/
#include <string.h>
#include <glib/gi18n.h>
-#include <arpa/inet.h>
#include "nm-setting-ip4-config.h"
-#include "nm-utils.h"
-#include "nm-glib-compat.h"
#include "nm-setting-private.h"
-#include "nm-core-internal.h"
-#include "nm-utils-private.h"
/**
* SECTION:nm-setting-ip4-config
* @short_description: Describes IPv4 addressing, routing, and name service properties
*
* The #NMSettingIP4Config object is a #NMSetting subclass that describes
- * properties related to IPv4 addressing, routing, and Domain Name Service
- **/
-
-G_DEFINE_BOXED_TYPE (NMIP4Address, nm_ip4_address, nm_ip4_address_dup, nm_ip4_address_unref)
-G_DEFINE_BOXED_TYPE (NMIP4Route, nm_ip4_route, nm_ip4_route_dup, nm_ip4_route_unref)
-
-G_DEFINE_TYPE_WITH_CODE (NMSettingIP4Config, nm_setting_ip4_config, NM_TYPE_SETTING,
+ * properties related to IPv4 addressing, routing, and Domain Name Service.
+ *
+ * #NMSettingIP4Config has few properties or methods of its own; it inherits
+ * almost everything from #NMSettingIPConfig.
+ *
+ * NetworkManager supports 5 values for the #NMSettingIPConfig:method property
+ * for IPv4. If "auto" is specified then the appropriate automatic method
+ * (DHCP, PPP, etc) is used for the interface and most other properties can be
+ * left unset. If "link-local" is specified, then a link-local address in the
+ * 169.254/16 range will be assigned to the interface. If "manual" is
+ * specified, static IP addressing is used and at least one IP address must be
+ * given in the "addresses" property. If "shared" is specified (indicating that
+ * this connection will provide network access to other computers) then the
+ * interface is assigned an address in the 10.42.x.1/24 range and a DHCP and
+ * forwarding DNS server are started, and the interface is NAT-ed to the current
+ * default network connection. "disabled" means IPv4 will not be used on this
+ * connection.
+ **/
+
+G_DEFINE_TYPE_WITH_CODE (NMSettingIP4Config, nm_setting_ip4_config, NM_TYPE_SETTING_IP_CONFIG,
_nm_register_setting (IP4_CONFIG, 4))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_IP4_CONFIG)
#define NM_SETTING_IP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_IP4_CONFIG, NMSettingIP4ConfigPrivate))
typedef struct {
- char *method;
- GSList *dns; /* list of IP address strings */
- GSList *dns_search; /* list of strings */
- GSList *addresses; /* array of NMIP4Address */
- GSList *address_labels; /* list of strings */
- GSList *routes; /* array of NMIP4Route */
- gboolean ignore_auto_routes;
- gboolean ignore_auto_dns;
char *dhcp_client_id;
- gboolean dhcp_send_hostname;
- char *dhcp_hostname;
- gboolean never_default;
- gboolean may_fail;
} NMSettingIP4ConfigPrivate;
enum {
PROP_0,
- PROP_METHOD,
- PROP_DNS,
- PROP_DNS_SEARCH,
- PROP_ADDRESSES,
- PROP_ADDRESS_LABELS,
- PROP_ROUTES,
- PROP_IGNORE_AUTO_ROUTES,
- PROP_IGNORE_AUTO_DNS,
PROP_DHCP_CLIENT_ID,
- PROP_DHCP_SEND_HOSTNAME,
- PROP_DHCP_HOSTNAME,
- PROP_NEVER_DEFAULT,
- PROP_MAY_FAIL,
LAST_PROP
};
@@ -97,660 +80,6 @@ nm_setting_ip4_config_new (void)
}
/**
- * nm_setting_ip4_config_get_method:
- * @setting: the #NMSettingIP4Config
- *
- * Returns: the #NMSettingIP4Config:method property of the setting
- **/
-const char *
-nm_setting_ip4_config_get_method (NMSettingIP4Config *setting)
-{
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);
-
- return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->method;
-}
-
-/**
- * nm_setting_ip4_config_get_num_dns:
- * @setting: the #NMSettingIP4Config
- *
- * Returns: the number of configured DNS servers
- **/
-guint32
-nm_setting_ip4_config_get_num_dns (NMSettingIP4Config *setting)
-{
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 0);
-
- return g_slist_length (NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns);
-}
-
-/**
- * nm_setting_ip4_config_get_dns:
- * @setting: the #NMSettingIP4Config
- * @i: index number of the DNS server to return
- *
- * Returns: the IPv4 address of the DNS server at index @i
- **/
-const char *
-nm_setting_ip4_config_get_dns (NMSettingIP4Config *setting, guint32 i)
-{
- NMSettingIP4ConfigPrivate *priv;
-
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);
-
- priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- g_return_val_if_fail (i < g_slist_length (priv->dns), NULL);
-
- return (const char *) g_slist_nth_data (priv->dns, i);
-}
-
-static const char *
-canonicalize_ip (const char *ip)
-{
- in_addr_t addr;
- int ret;
-
- ret = inet_pton (AF_INET, ip, &addr);
- g_return_val_if_fail (ret == 1, NULL);
- return nm_utils_inet4_ntop (addr, NULL);
-}
-
-/**
- * nm_setting_ip4_config_add_dns:
- * @setting: the #NMSettingIP4Config
- * @dns: the IPv4 address of the DNS server to add
- *
- * Adds a new DNS server to the setting.
- *
- * Returns: %TRUE if the DNS server was added; %FALSE if the server was already
- * known
- **/
-gboolean
-nm_setting_ip4_config_add_dns (NMSettingIP4Config *setting, const char *dns)
-{
- NMSettingIP4ConfigPrivate *priv;
- const char *dns_canonical;
- GSList *iter;
-
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
- g_return_val_if_fail (dns != NULL, FALSE);
- g_return_val_if_fail (dns[0] != '\0', FALSE);
-
- priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
-
- dns_canonical = canonicalize_ip (dns);
- g_return_val_if_fail (dns_canonical != NULL, FALSE);
-
- for (iter = priv->dns; iter; iter = g_slist_next (iter)) {
- if (!strcmp (dns_canonical, (char *) iter->data))
- return FALSE;
- }
-
- priv->dns = g_slist_append (priv->dns, g_strdup (dns_canonical));
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS);
- return TRUE;
-}
-
-/**
- * nm_setting_ip4_config_remove_dns:
- * @setting: the #NMSettingIP4Config
- * @i: index number of the DNS server to remove
- *
- * Removes the DNS server at index @i.
- **/
-void
-nm_setting_ip4_config_remove_dns (NMSettingIP4Config *setting, guint32 i)
-{
- NMSettingIP4ConfigPrivate *priv;
- GSList *elt;
-
- g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
-
- priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- elt = g_slist_nth (priv->dns, i);
- g_return_if_fail (elt != NULL);
-
- g_free (elt->data);
- priv->dns = g_slist_delete_link (priv->dns, elt);
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS);
-}
-
-/**
- * nm_setting_ip4_config_remove_dns_by_value:
- * @setting: the #NMSettingIP4Config
- * @dns: the DNS server to remove
- *
- * Removes the DNS server @dns.
- *
- * Returns: %TRUE if the DNS server was found and removed; %FALSE if it was not.
- **/
-gboolean
-nm_setting_ip4_config_remove_dns_by_value (NMSettingIP4Config *setting, const char *dns)
-{
- NMSettingIP4ConfigPrivate *priv;
- const char *dns_canonical;
- GSList *iter;
-
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
- g_return_val_if_fail (dns != NULL, FALSE);
- g_return_val_if_fail (dns[0] != '\0', FALSE);
-
- priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
-
- dns_canonical = canonicalize_ip (dns);
- g_return_val_if_fail (dns_canonical != NULL, FALSE);
-
- for (iter = priv->dns; iter; iter = g_slist_next (iter)) {
- if (!strcmp (dns_canonical, (char *) iter->data)) {
- priv->dns = g_slist_delete_link (priv->dns, iter);
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS);
- return TRUE;
- }
- }
- return FALSE;
-}
-
-/**
- * nm_setting_ip4_config_clear_dns:
- * @setting: the #NMSettingIP4Config
- *
- * Removes all configured DNS servers.
- **/
-void
-nm_setting_ip4_config_clear_dns (NMSettingIP4Config *setting)
-{
- g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
-
- g_slist_free_full (NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns, g_free);
- NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns = NULL;
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS);
-}
-
-/**
- * nm_setting_ip4_config_get_num_dns_searches:
- * @setting: the #NMSettingIP4Config
- *
- * Returns: the number of configured DNS search domains
- **/
-guint32
-nm_setting_ip4_config_get_num_dns_searches (NMSettingIP4Config *setting)
-{
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 0);
-
- return g_slist_length (NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns_search);
-}
-
-/**
- * nm_setting_ip4_config_get_dns_search:
- * @setting: the #NMSettingIP4Config
- * @i: index number of the DNS search domain to return
- *
- * Returns: the DNS search domain at index @i
- **/
-const char *
-nm_setting_ip4_config_get_dns_search (NMSettingIP4Config *setting, guint32 i)
-{
- NMSettingIP4ConfigPrivate *priv;
-
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);
-
- priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- g_return_val_if_fail (i < g_slist_length (priv->dns_search), NULL);
-
- return (const char *) g_slist_nth_data (priv->dns_search, i);
-}
-
-/**
- * nm_setting_ip4_config_add_dns_search:
- * @setting: the #NMSettingIP4Config
- * @dns_search: the search domain to add
- *
- * Adds a new DNS search domain to the setting.
- *
- * Returns: %TRUE if the DNS search domain was added; %FALSE if the search
- * domain was already known
- **/
-gboolean
-nm_setting_ip4_config_add_dns_search (NMSettingIP4Config *setting,
- const char *dns_search)
-{
- NMSettingIP4ConfigPrivate *priv;
- GSList *iter;
-
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
- g_return_val_if_fail (dns_search != NULL, FALSE);
- g_return_val_if_fail (dns_search[0] != '\0', FALSE);
-
- priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- for (iter = priv->dns_search; iter; iter = g_slist_next (iter)) {
- if (!strcmp (dns_search, (char *) iter->data))
- return FALSE;
- }
-
- priv->dns_search = g_slist_append (priv->dns_search, g_strdup (dns_search));
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS_SEARCH);
- return TRUE;
-}
-
-/**
- * nm_setting_ip4_config_remove_dns_search:
- * @setting: the #NMSettingIP4Config
- * @i: index number of the DNS search domain
- *
- * Removes the DNS search domain at index @i.
- **/
-void
-nm_setting_ip4_config_remove_dns_search (NMSettingIP4Config *setting, guint32 i)
-{
- NMSettingIP4ConfigPrivate *priv;
- GSList *elt;
-
- g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
-
- priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- elt = g_slist_nth (priv->dns_search, i);
- g_return_if_fail (elt != NULL);
-
- g_free (elt->data);
- priv->dns_search = g_slist_delete_link (priv->dns_search, elt);
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS_SEARCH);
-}
-
-/**
- * nm_setting_ip4_config_remove_dns_search_by_value:
- * @setting: the #NMSettingIP4Config
- * @dns_search: the search domain to remove
- *
- * Removes the DNS search domain @dns_search.
- *
- * Returns: %TRUE if the DNS search domain was found and removed; %FALSE if it was not.
- **/
-gboolean
-nm_setting_ip4_config_remove_dns_search_by_value (NMSettingIP4Config *setting,
- const char *dns_search)
-{
- NMSettingIP4ConfigPrivate *priv;
- GSList *iter;
-
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
- g_return_val_if_fail (dns_search != NULL, FALSE);
- g_return_val_if_fail (dns_search[0] != '\0', FALSE);
-
- priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- for (iter = priv->dns_search; iter; iter = g_slist_next (iter)) {
- if (!strcmp (dns_search, (char *) iter->data)) {
- priv->dns_search = g_slist_delete_link (priv->dns_search, iter);
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS_SEARCH);
- return TRUE;
- }
- }
- return FALSE;
-}
-
-/**
- * nm_setting_ip4_config_clear_dns_searches:
- * @setting: the #NMSettingIP4Config
- *
- * Removes all configured DNS search domains.
- **/
-void
-nm_setting_ip4_config_clear_dns_searches (NMSettingIP4Config *setting)
-{
- g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
-
- g_slist_free_full (NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns_search, g_free);
- NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns_search = NULL;
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS_SEARCH);
-}
-
-/**
- * nm_setting_ip4_config_get_num_addresses:
- * @setting: the #NMSettingIP4Config
- *
- * Returns: the number of configured addresses
- **/
-guint32
-nm_setting_ip4_config_get_num_addresses (NMSettingIP4Config *setting)
-{
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 0);
-
- return g_slist_length (NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->addresses);
-}
-
-/**
- * nm_setting_ip4_config_get_address:
- * @setting: the #NMSettingIP4Config
- * @i: index number of the address to return
- *
- * Returns: the address at index @i
- **/
-NMIP4Address *
-nm_setting_ip4_config_get_address (NMSettingIP4Config *setting, guint32 i)
-{
- NMSettingIP4ConfigPrivate *priv;
-
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);
-
- priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- g_return_val_if_fail (i < g_slist_length (priv->addresses), NULL);
-
- return (NMIP4Address *) g_slist_nth_data (priv->addresses, i);
-}
-
-const char *
-_nm_setting_ip4_config_get_address_label (NMSettingIP4Config *setting, guint32 i)
-{
- NMSettingIP4ConfigPrivate *priv;
-
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);
-
- priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- g_return_val_if_fail (i < g_slist_length (priv->address_labels), NULL);
-
- return (const char *) g_slist_nth_data (priv->address_labels, i);
-}
-
-/**
- * nm_setting_ip4_config_add_address:
- * @setting: the #NMSettingIP4Config
- * @address: the new address to add
- *
- * Adds a new IPv4 address and associated information to the setting. The
- * given address is duplicated internally and is not changed by this function.
- *
- * Returns: %TRUE if the address was added; %FALSE if the address was already
- * known.
- **/
-gboolean
-nm_setting_ip4_config_add_address (NMSettingIP4Config *setting,
- NMIP4Address *address)
-{
- return _nm_setting_ip4_config_add_address_with_label (setting, address, "");
-}
-
-gboolean
-_nm_setting_ip4_config_add_address_with_label (NMSettingIP4Config *setting,
- NMIP4Address *address,
- const char *label)
-{
- NMSettingIP4ConfigPrivate *priv;
- NMIP4Address *copy;
- GSList *iter;
-
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
- g_return_val_if_fail (address != NULL, FALSE);
- g_return_val_if_fail (label != NULL, FALSE);
-
- priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- for (iter = priv->addresses; iter; iter = g_slist_next (iter)) {
- if (nm_ip4_address_compare ((NMIP4Address *) iter->data, address))
- return FALSE;
- }
-
- copy = nm_ip4_address_dup (address);
- priv->addresses = g_slist_append (priv->addresses, copy);
- priv->address_labels = g_slist_append (priv->address_labels, g_strdup (label));
-
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ADDRESSES);
- return TRUE;
-}
-
-/**
- * nm_setting_ip4_config_remove_address:
- * @setting: the #NMSettingIP4Config
- * @i: index number of the address to remove
- *
- * Removes the address at index @i.
- **/
-void
-nm_setting_ip4_config_remove_address (NMSettingIP4Config *setting, guint32 i)
-{
- NMSettingIP4ConfigPrivate *priv;
- GSList *addr, *label;
-
- g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
-
- priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- addr = g_slist_nth (priv->addresses, i);
- label = g_slist_nth (priv->address_labels, i);
- g_return_if_fail (addr != NULL && label != NULL);
-
- nm_ip4_address_unref ((NMIP4Address *) addr->data);
- priv->addresses = g_slist_delete_link (priv->addresses, addr);
- g_free (label->data);
- priv->address_labels = g_slist_delete_link (priv->address_labels, label);
-
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ADDRESSES);
-}
-
-/**
- * nm_setting_ip4_config_remove_address_by_value:
- * @setting: the #NMSettingIP4Config
- * @address: the IP address to remove
- *
- * Removes the address @address.
- *
- * Returns: %TRUE if the address was found and removed; %FALSE if it was not.
- **/
-gboolean
-nm_setting_ip4_config_remove_address_by_value (NMSettingIP4Config *setting,
- NMIP4Address *address)
-{
- NMSettingIP4ConfigPrivate *priv;
- GSList *iter;
-
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
- g_return_val_if_fail (address != NULL, FALSE);
-
- priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- for (iter = priv->addresses; iter; iter = g_slist_next (iter)) {
- if (nm_ip4_address_compare ((NMIP4Address *) iter->data, address)) {
- nm_ip4_address_unref ((NMIP4Address *) iter->data);
- priv->addresses = g_slist_delete_link (priv->addresses, iter);
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ADDRESSES);
- return TRUE;
- }
- }
- return FALSE;
-}
-
-/**
- * nm_setting_ip4_config_clear_addresses:
- * @setting: the #NMSettingIP4Config
- *
- * Removes all configured addresses.
- **/
-void
-nm_setting_ip4_config_clear_addresses (NMSettingIP4Config *setting)
-{
- NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
-
- g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
-
- g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
- priv->addresses = NULL;
- g_slist_free_full (priv->address_labels, g_free);
- priv->address_labels = NULL;
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ADDRESSES);
-}
-
-/**
- * nm_setting_ip4_config_get_num_routes:
- * @setting: the #NMSettingIP4Config
- *
- * Returns: the number of configured routes
- **/
-guint32
-nm_setting_ip4_config_get_num_routes (NMSettingIP4Config *setting)
-{
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 0);
-
- return g_slist_length (NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->routes);
-}
-
-/**
- * nm_setting_ip4_config_get_route:
- * @setting: the #NMSettingIP4Config
- * @i: index number of the route to return
- *
- * Returns: the route at index @i
- **/
-NMIP4Route *
-nm_setting_ip4_config_get_route (NMSettingIP4Config *setting, guint32 i)
-{
- NMSettingIP4ConfigPrivate *priv;
-
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);
-
- priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- g_return_val_if_fail (i < g_slist_length (priv->routes), NULL);
-
- return (NMIP4Route *) g_slist_nth_data (priv->routes, i);
-}
-
-/**
- * nm_setting_ip4_config_add_route:
- * @setting: the #NMSettingIP4Config
- * @route: the route to add
- *
- * Adds a new IPv4 route and associated information to the setting. The
- * given route is duplicated internally and is not changed by this function.
- *
- * Returns: %TRUE if the route was added; %FALSE if the route was already known.
- **/
-gboolean
-nm_setting_ip4_config_add_route (NMSettingIP4Config *setting,
- NMIP4Route *route)
-{
- NMSettingIP4ConfigPrivate *priv;
- NMIP4Route *copy;
- GSList *iter;
-
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
- g_return_val_if_fail (route != NULL, FALSE);
-
- priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- for (iter = priv->routes; iter; iter = g_slist_next (iter)) {
- if (nm_ip4_route_compare ((NMIP4Route *) iter->data, route))
- return FALSE;
- }
-
- copy = nm_ip4_route_dup (route);
- priv->routes = g_slist_append (priv->routes, copy);
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ROUTES);
- return TRUE;
-}
-
-/**
- * nm_setting_ip4_config_remove_route:
- * @setting: the #NMSettingIP4Config
- * @i: index number of the route
- *
- * Removes the route at index @i.
- **/
-void
-nm_setting_ip4_config_remove_route (NMSettingIP4Config *setting, guint32 i)
-{
- NMSettingIP4ConfigPrivate *priv;
- GSList *elt;
-
- g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
-
- priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- elt = g_slist_nth (priv->routes, i);
- g_return_if_fail (elt != NULL);
-
- nm_ip4_route_unref ((NMIP4Route *) elt->data);
- priv->routes = g_slist_delete_link (priv->routes, elt);
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ROUTES);
-}
-
-/**
- * nm_setting_ip4_config_remove_route_by_value:
- * @setting: the #NMSettingIP4Config
- * @route: the route to remove
- *
- * Removes the route @route.
- *
- * Returns: %TRUE if the route was found and removed; %FALSE if it was not.
- **/
-gboolean
-nm_setting_ip4_config_remove_route_by_value (NMSettingIP4Config *setting,
- NMIP4Route *route)
-{
- NMSettingIP4ConfigPrivate *priv;
- GSList *iter;
-
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
- g_return_val_if_fail (route != NULL, FALSE);
-
- priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- for (iter = priv->routes; iter; iter = g_slist_next (iter)) {
- if (nm_ip4_route_compare ((NMIP4Route *) iter->data, route)) {
- nm_ip4_route_unref ((NMIP4Route *) iter->data);
- priv->routes = g_slist_delete_link (priv->routes, iter);
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ROUTES);
- return TRUE;
- }
- }
- return FALSE;
-}
-
-/**
- * nm_setting_ip4_config_clear_routes:
- * @setting: the #NMSettingIP4Config
- *
- * Removes all configured routes.
- **/
-void
-nm_setting_ip4_config_clear_routes (NMSettingIP4Config *setting)
-{
- NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
-
- g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
-
- g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
- priv->routes = NULL;
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ROUTES);
-}
-
-/**
- * nm_setting_ip4_config_get_ignore_auto_routes:
- * @setting: the #NMSettingIP4Config
- *
- * Returns the value contained in the #NMSettingIP4Config:ignore-auto-routes
- * property.
- *
- * Returns: %TRUE if automatically configured (ie via DHCP) routes should be
- * ignored.
- **/
-gboolean
-nm_setting_ip4_config_get_ignore_auto_routes (NMSettingIP4Config *setting)
-{
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
-
- return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->ignore_auto_routes;
-}
-
-/**
- * nm_setting_ip4_config_get_ignore_auto_dns:
- * @setting: the #NMSettingIP4Config
- *
- * Returns the value contained in the #NMSettingIP4Config:ignore-auto-dns
- * property.
- *
- * Returns: %TRUE if automatically configured (ie via DHCP) DNS information
- * should be ignored.
- **/
-gboolean
-nm_setting_ip4_config_get_ignore_auto_dns (NMSettingIP4Config *setting)
-{
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
-
- return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->ignore_auto_dns;
-}
-
-/**
* nm_setting_ip4_config_get_dhcp_client_id:
* @setting: the #NMSettingIP4Config
*
@@ -768,174 +97,75 @@ nm_setting_ip4_config_get_dhcp_client_id (NMSettingIP4Config *setting)
return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dhcp_client_id;
}
-/**
- * nm_setting_ip4_config_get_dhcp_send_hostname:
- * @setting: the #NMSettingIP4Config
- *
- * Returns the value contained in the #NMSettingIP4Config:dhcp-send-hostname
- * property.
- *
- * Returns: %TRUE if NetworkManager should send the machine hostname to the
- * DHCP server when requesting addresses to allow the server to automatically
- * update DNS information for this machine.
- **/
-gboolean
-nm_setting_ip4_config_get_dhcp_send_hostname (NMSettingIP4Config *setting)
-{
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
-
- return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dhcp_send_hostname;
-}
-
-/**
- * nm_setting_ip4_config_get_dhcp_hostname:
- * @setting: the #NMSettingIP4Config
- *
- * Returns the value contained in the #NMSettingIP4Config:dhcp-hostname
- * property.
- *
- * Returns: the configured hostname to send to the DHCP server
- **/
-const char *
-nm_setting_ip4_config_get_dhcp_hostname (NMSettingIP4Config *setting)
-{
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);
-
- return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dhcp_hostname;
-}
-
-/**
- * nm_setting_ip4_config_get_never_default:
- * @setting: the #NMSettingIP4Config
- *
- * Returns the value contained in the #NMSettingIP4Config:never-default
- * property.
- *
- * Returns: %TRUE if this connection should never be the default connection
- * for IPv4 addressing
- **/
-gboolean
-nm_setting_ip4_config_get_never_default (NMSettingIP4Config *setting)
-{
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
-
- return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->never_default;
-}
-
-/**
- * nm_setting_ip4_config_get_may_fail:
- * @setting: the #NMSettingIP4Config
- *
- * Returns the value contained in the #NMSettingIP4Config:may-fail
- * property.
- *
- * Returns: %TRUE if this connection doesn't require IPv4 addressing to complete
- * for the connection to succeed.
- **/
-gboolean
-nm_setting_ip4_config_get_may_fail (NMSettingIP4Config *setting)
-{
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
-
- return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->may_fail;
-}
-
-static gboolean
-verify_label (const char *label)
-{
- const char *p;
- char *iface;
-
- if (!*label)
- return TRUE;
-
- p = strchr (label, ':');
- if (!p)
- return FALSE;
- iface = g_strndup (label, p - label);
- if (!nm_utils_iface_valid_name (iface)) {
- g_free (iface);
- return FALSE;
- }
- g_free (iface);
-
- for (p++; *p; p++) {
- if (!g_ascii_isalnum (*p) && *p != '_')
- return FALSE;
- }
-
- return TRUE;
-}
-
static gboolean
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- GSList *iter, *l_iter;
- int i;
+ NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG (setting);
+ NMSettingVerifyResult ret;
+ const char *method;
- if (!priv->method) {
- g_set_error_literal (error,
- NM_CONNECTION_ERROR,
- NM_CONNECTION_ERROR_MISSING_PROPERTY,
- _("property is missing"));
- g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_METHOD);
- return FALSE;
- }
+ ret = NM_SETTING_CLASS (nm_setting_ip4_config_parent_class)->verify (setting, connection, error);
+ if (ret != NM_SETTING_VERIFY_SUCCESS)
+ return ret;
+
+ method = nm_setting_ip_config_get_method (s_ip);
+ /* Base class already checked that it exists */
+ g_assert (method);
- if (!strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) {
- if (!priv->addresses) {
+ if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) {
+ if (nm_setting_ip_config_get_num_addresses (s_ip) == 0) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_MISSING_PROPERTY,
_("this property cannot be empty for '%s=%s'"),
- NM_SETTING_IP4_CONFIG_METHOD, priv->method);
- g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_ADDRESSES);
+ NM_SETTING_IP_CONFIG_METHOD, method);
+ g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP_CONFIG_ADDRESSES);
return FALSE;
}
- } else if ( !strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)
- || !strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)
- || !strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) {
- if (priv->dns) {
+ } else if ( !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)
+ || !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)
+ || !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) {
+ if (nm_setting_ip_config_get_num_dns (s_ip) > 0) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("this property is not allowed for '%s=%s'"),
- NM_SETTING_IP4_CONFIG_METHOD, priv->method);
- g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_METHOD, method);
+ g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP_CONFIG_DNS);
return FALSE;
}
- if (priv->dns_search) {
+ if (nm_setting_ip_config_get_num_dns_searches (s_ip) > 0) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("this property is not allowed for '%s=%s'"),
- NM_SETTING_IP4_CONFIG_METHOD, priv->method);
- g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_DNS_SEARCH);
+ NM_SETTING_IP_CONFIG_METHOD, method);
+ g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP_CONFIG_DNS_SEARCH);
return FALSE;
}
/* Shared allows IP addresses; link-local and disabled do not */
- if (strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_SHARED) != 0) {
- if (priv->addresses) {
+ if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED) != 0) {
+ if (nm_setting_ip_config_get_num_addresses (s_ip) > 0) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("this property is not allowed for '%s=%s'"),
- NM_SETTING_IP4_CONFIG_METHOD, priv->method);
- g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_ADDRESSES);
+ NM_SETTING_IP_CONFIG_METHOD, method);
+ g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP_CONFIG_ADDRESSES);
return FALSE;
}
}
- } else if (!strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) {
+ } else if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) {
/* nothing to do */
} else {
g_set_error_literal (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("property is invalid"));
- g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_METHOD);
+ g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP_CONFIG_METHOD);
return FALSE;
}
@@ -948,111 +178,9 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
return FALSE;
}
- if (priv->dhcp_hostname && !strlen (priv->dhcp_hostname)) {
- g_set_error_literal (error,
- NM_CONNECTION_ERROR,
- NM_CONNECTION_ERROR_INVALID_PROPERTY,
- _("property is empty"));
- g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME);
- return FALSE;
- }
-
- /* Validate addresses */
- for (iter = priv->addresses, l_iter = priv->address_labels, i = 0;
- iter && l_iter;
- iter = g_slist_next (iter), l_iter = g_slist_next (l_iter), i++) {
- NMIP4Address *addr = (NMIP4Address *) iter->data;
- const char *label = (const char *) l_iter->data;
- guint32 prefix = nm_ip4_address_get_prefix (addr);
-
- if (!nm_ip4_address_get_address (addr)) {
- g_set_error (error,
- NM_CONNECTION_ERROR,
- NM_CONNECTION_ERROR_INVALID_PROPERTY,
- _("%d. IPv4 address is invalid"),
- i+1);
- g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_ADDRESSES);
- return FALSE;
- }
-
- if (!prefix || prefix > 32) {
- g_set_error (error,
- NM_CONNECTION_ERROR,
- NM_CONNECTION_ERROR_INVALID_PROPERTY,
- _("%d. IPv4 address has invalid prefix"),
- i+1);
- g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_ADDRESSES);
- return FALSE;
- }
-
- if (!verify_label (label)) {
- g_set_error (error,
- NM_CONNECTION_ERROR,
- NM_CONNECTION_ERROR_INVALID_PROPERTY,
- _("%d. IPv4 address has invalid label '%s'"),
- i+1, label);
- g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, "address-labels");
- return FALSE;
- }
- }
-
- if (iter || l_iter) {
- g_set_error (error,
- NM_CONNECTION_ERROR,
- NM_CONNECTION_ERROR_INVALID_PROPERTY,
- _("IPv4 address / label count mismatch (%d vs %d)"),
- g_slist_length (priv->addresses),
- g_slist_length (priv->address_labels));
- g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, "address-labels");
- return FALSE;
- }
-
- /* Validate routes */
- for (iter = priv->routes, i = 0; iter; iter = g_slist_next (iter), i++) {
- NMIP4Route *route = (NMIP4Route *) iter->data;
- guint32 prefix = nm_ip4_route_get_prefix (route);
-
- if (!nm_ip4_route_get_dest (route)) {
- g_set_error (error,
- NM_CONNECTION_ERROR,
- NM_CONNECTION_ERROR_INVALID_PROPERTY,
- _("%d. route is invalid"),
- i+1);
- g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_ROUTES);
- return FALSE;
- }
-
- if (!prefix || prefix > 32) {
- g_set_error (error,
- NM_CONNECTION_ERROR,
- NM_CONNECTION_ERROR_INVALID_PROPERTY,
- _("%d. route has invalid prefix"),
- i+1);
- g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_ROUTES);
- return FALSE;
- }
- }
-
- /* Validate DNS */
- for (iter = priv->dns, i = 0; iter; iter = g_slist_next (iter), i++) {
- const char *dns = (const char *) iter->data;
- in_addr_t addr;
-
- if (inet_pton (AF_INET, dns, &addr) != 1) {
- g_set_error (error,
- NM_CONNECTION_ERROR,
- NM_CONNECTION_ERROR_INVALID_PROPERTY,
- _("%d. DNS server address is invalid"),
- i+1);
- g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_DNS);
- return FALSE;
- }
- }
-
return TRUE;
}
-
static void
nm_setting_ip4_config_init (NMSettingIP4Config *setting)
{
@@ -1061,126 +189,24 @@ nm_setting_ip4_config_init (NMSettingIP4Config *setting)
static void
finalize (GObject *object)
{
- NMSettingIP4Config *self = NM_SETTING_IP4_CONFIG (object);
- NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (self);
+ NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (object);
- g_free (priv->method);
- g_free (priv->dhcp_hostname);
g_free (priv->dhcp_client_id);
- g_slist_free_full (priv->dns, g_free);
- g_slist_free_full (priv->dns_search, g_free);
- g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
- g_slist_free_full (priv->address_labels, g_free);
- g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
-
G_OBJECT_CLASS (nm_setting_ip4_config_parent_class)->finalize (object);
}
-static GVariant *
-ip4_dns_to_dbus (const GValue *prop_value)
-{
- return nm_utils_ip4_dns_to_variant (g_value_get_boxed (prop_value));
-}
-
-static void
-ip4_dns_from_dbus (GVariant *dbus_value,
- GValue *prop_value)
-{
- g_value_take_boxed (prop_value, nm_utils_ip4_dns_from_variant (dbus_value));
-}
-
-static GVariant *
-ip4_addresses_to_dbus (const GValue *prop_value)
-{
- return nm_utils_ip4_addresses_to_variant (g_value_get_boxed (prop_value));
-}
-
-static void
-ip4_addresses_from_dbus (GVariant *dbus_value,
- GValue *prop_value)
-{
- g_value_take_boxed (prop_value, nm_utils_ip4_addresses_from_variant (dbus_value));
-}
-
-static GVariant *
-ip4_routes_to_dbus (const GValue *prop_value)
-{
- return nm_utils_ip4_routes_to_variant (g_value_get_boxed (prop_value));
-}
-
-static void
-ip4_routes_from_dbus (GVariant *dbus_value,
- GValue *prop_value)
-{
- g_value_take_boxed (prop_value, nm_utils_ip4_routes_from_variant (dbus_value));
-}
-
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
- NMSettingIP4Config *setting = NM_SETTING_IP4_CONFIG (object);
- NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- GSList *iter;
+ NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (object);
switch (prop_id) {
- case PROP_METHOD:
- g_free (priv->method);
- priv->method = g_value_dup_string (value);
- break;
- case PROP_DNS:
- g_slist_free_full (priv->dns, g_free);
- priv->dns = _nm_utils_strv_to_slist (g_value_get_boxed (value));
- break;
- case PROP_DNS_SEARCH:
- g_slist_free_full (priv->dns_search, g_free);
- priv->dns_search = _nm_utils_strv_to_slist (g_value_get_boxed (value));
- break;
- case PROP_ADDRESSES:
- g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
- priv->addresses = _nm_utils_copy_array_to_slist (g_value_get_boxed (value),
- (NMUtilsCopyFunc) nm_ip4_address_dup);
-
- if (g_slist_length (priv->addresses) != g_slist_length (priv->address_labels)) {
- g_slist_free_full (priv->address_labels, g_free);
- priv->address_labels = NULL;
- for (iter = priv->addresses; iter; iter = iter->next)
- priv->address_labels = g_slist_prepend (priv->address_labels, g_strdup (""));
- }
- break;
- case PROP_ADDRESS_LABELS:
- g_slist_free_full (priv->address_labels, g_free);
- priv->address_labels = _nm_utils_strv_to_slist (g_value_get_boxed (value));
- break;
- case PROP_ROUTES:
- g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
- priv->routes = _nm_utils_copy_array_to_slist (g_value_get_boxed (value),
- (NMUtilsCopyFunc) nm_ip4_route_dup);
- 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_DHCP_CLIENT_ID:
g_free (priv->dhcp_client_id);
priv->dhcp_client_id = g_value_dup_string (value);
break;
- case PROP_DHCP_SEND_HOSTNAME:
- priv->dhcp_send_hostname = g_value_get_boolean (value);
- break;
- case PROP_DHCP_HOSTNAME:
- g_free (priv->dhcp_hostname);
- priv->dhcp_hostname = g_value_dup_string (value);
- break;
- case PROP_NEVER_DEFAULT:
- priv->never_default = g_value_get_boolean (value);
- break;
- case PROP_MAY_FAIL:
- priv->may_fail = g_value_get_boolean (value);
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -1191,48 +217,11 @@ static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
- NMSettingIP4Config *setting = NM_SETTING_IP4_CONFIG (object);
- NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
+ NMSettingIP4Config *s_ip4 = NM_SETTING_IP4_CONFIG (object);
switch (prop_id) {
- case PROP_METHOD:
- g_value_set_string (value, nm_setting_ip4_config_get_method (setting));
- break;
- case PROP_DNS:
- g_value_take_boxed (value, _nm_utils_slist_to_strv (priv->dns));
- break;
- case PROP_DNS_SEARCH:
- g_value_take_boxed (value, _nm_utils_slist_to_strv (priv->dns_search));
- break;
- case PROP_ADDRESSES:
- g_value_take_boxed (value, _nm_utils_copy_slist_to_array (priv->addresses, (NMUtilsCopyFunc) nm_ip4_address_dup, (GDestroyNotify) nm_ip4_address_unref));
- break;
- case PROP_ADDRESS_LABELS:
- g_value_take_boxed (value, _nm_utils_slist_to_strv (priv->address_labels));
- break;
- case PROP_ROUTES:
- g_value_take_boxed (value, _nm_utils_copy_slist_to_array (priv->routes, (NMUtilsCopyFunc) nm_ip4_route_dup, (GDestroyNotify) nm_ip4_route_unref));
- break;
- case PROP_IGNORE_AUTO_ROUTES:
- g_value_set_boolean (value, nm_setting_ip4_config_get_ignore_auto_routes (setting));
- break;
- case PROP_IGNORE_AUTO_DNS:
- g_value_set_boolean (value, nm_setting_ip4_config_get_ignore_auto_dns (setting));
- break;
case PROP_DHCP_CLIENT_ID:
- g_value_set_string (value, nm_setting_ip4_config_get_dhcp_client_id (setting));
- break;
- case PROP_DHCP_SEND_HOSTNAME:
- g_value_set_boolean (value, nm_setting_ip4_config_get_dhcp_send_hostname (setting));
- break;
- case PROP_DHCP_HOSTNAME:
- g_value_set_string (value, nm_setting_ip4_config_get_dhcp_hostname (setting));
- break;
- case PROP_NEVER_DEFAULT:
- g_value_set_boolean (value, priv->never_default);
- break;
- case PROP_MAY_FAIL:
- g_value_set_boolean (value, priv->may_fail);
+ g_value_set_string (value, nm_setting_ip4_config_get_dhcp_client_id (s_ip4));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -1240,705 +229,272 @@ get_property (GObject *object, guint prop_id,
}
}
-static void
-nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *setting_class)
+static GVariant *
+ip4_dns_to_dbus (const GValue *prop_value)
{
- GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
- NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
-
- g_type_class_add_private (setting_class, sizeof (NMSettingIP4ConfigPrivate));
-
- /* virtual methods */
- object_class->set_property = set_property;
- object_class->get_property = get_property;
- object_class->finalize = finalize;
- parent_class->verify = verify;
-
- /* Properties */
- /**
- * NMSettingIP4Config:method:
- *
- * IPv4 configuration method. If "auto" is specified then the appropriate
- * automatic method (DHCP, PPP, etc) is used for the interface and most
- * other properties can be left unset. If "link-local" is specified, then a
- * link-local address in the 169.254/16 range will be assigned to the
- * interface. If "manual" is specified, static IP addressing is used and at
- * least one IP address must be given in the "addresses" property. If
- * "shared" is specified (indicating that this connection will provide
- * network access to other computers) then the interface is assigned an
- * address in the 10.42.x.1/24 range and a DHCP and forwarding DNS server
- * are started, and the interface is NAT-ed to the current default network
- * connection. "disabled" means IPv4 will not be used on this connection.
- * This property must be set.
- **/
- g_object_class_install_property
- (object_class, PROP_METHOD,
- g_param_spec_string (NM_SETTING_IP4_CONFIG_METHOD, "", "",
- NULL,
- G_PARAM_READWRITE |
- NM_SETTING_PARAM_INFERRABLE |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMSettingIP4Config:dns:
- *
- * Array of IPv4 addresses of DNS servers. For the 'auto' method, these
- * DNS servers are appended to those (if any) returned by automatic
- * configuration. DNS servers cannot be used with the "shared",
- * "link-local", or "disabled" methods as there is no upstream network. In
- * all other methods, these DNS servers are used as the only DNS servers for
- * this connection.
- **/
- g_object_class_install_property
- (object_class, PROP_DNS,
- g_param_spec_boxed (NM_SETTING_IP4_CONFIG_DNS, "", "",
- G_TYPE_STRV,
- G_PARAM_READWRITE |
- G_PARAM_STATIC_STRINGS));
- _nm_setting_class_transform_property (parent_class, NM_SETTING_IP4_CONFIG_DNS,
- G_VARIANT_TYPE ("au"),
- ip4_dns_to_dbus,
- ip4_dns_from_dbus);
-
- /**
- * NMSettingIP4Config:dns-search:
- *
- * List of DNS search domains. For the "auto" method, these search domains
- * are appended to those returned by automatic configuration. Search domains
- * cannot be used with the "shared", "link-local", or "disabled" methods as
- * there is no upstream network. In all other methods, these search domains
- * are used as the only search domains for this connection.
- **/
- g_object_class_install_property
- (object_class, PROP_DNS_SEARCH,
- g_param_spec_boxed (NM_SETTING_IP4_CONFIG_DNS_SEARCH, "", "",
- G_TYPE_STRV,
- G_PARAM_READWRITE |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMSettingIP4Config:addresses:
- *
- * Array of IPv4 addresses. The gateway may be left as 0 if no gateway exists
- * for that subnet. For the 'auto' method, given IP addresses are appended
- * to those returned by automatic configuration. Addresses cannot be used
- * with the "shared", "link-local", or "disabled" methods as addressing is
- * either automatic or disabled with these methods.
- *
- * Element-Type: NMIP4Address
- **/
- g_object_class_install_property
- (object_class, PROP_ADDRESSES,
- g_param_spec_boxed (NM_SETTING_IP4_CONFIG_ADDRESSES, "", "",
- G_TYPE_PTR_ARRAY,
- G_PARAM_READWRITE |
- NM_SETTING_PARAM_INFERRABLE |
- G_PARAM_STATIC_STRINGS));
- _nm_setting_class_transform_property (parent_class, NM_SETTING_IP4_CONFIG_ADDRESSES,
- G_VARIANT_TYPE ("aau"),
- ip4_addresses_to_dbus,
- ip4_addresses_from_dbus);
-
- /**
- * NMSettingIP4Config:address-labels:
- *
- * Internal use only.
- **/
- g_object_class_install_property
- (object_class, PROP_ADDRESS_LABELS,
- g_param_spec_boxed ("address-labels", "", "",
- G_TYPE_STRV,
- G_PARAM_READWRITE |
- NM_SETTING_PARAM_INFERRABLE |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMSettingIP4Config:routes:
- *
- * Array of IPv4 routes. For the 'auto' method, given IP routes are appended
- * to those returned by automatic configuration. Routes cannot be used with
- * the 'shared', 'link-local', or 'disabled' methods because there is no
- * upstream network.
- *
- * Element-Type: NMIP4Route
- **/
- g_object_class_install_property
- (object_class, PROP_ROUTES,
- g_param_spec_boxed (NM_SETTING_IP4_CONFIG_ROUTES, "", "",
- G_TYPE_PTR_ARRAY,
- G_PARAM_READWRITE |
- NM_SETTING_PARAM_INFERRABLE |
- G_PARAM_STATIC_STRINGS));
- _nm_setting_class_transform_property (parent_class, NM_SETTING_IP4_CONFIG_ROUTES,
- G_VARIANT_TYPE ("aau"),
- ip4_routes_to_dbus,
- ip4_routes_from_dbus);
-
- /**
- * NMSettingIP4Config:ignore-auto-routes:
- *
- * When the method is set to "auto" and this property to %TRUE,
- * automatically configured routes are ignored and only routes specified in
- * the #NMSettingIP4Config:routes property, if any, are used.
- **/
- g_object_class_install_property
- (object_class, PROP_IGNORE_AUTO_ROUTES,
- g_param_spec_boolean (NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES, "", "",
- FALSE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMSettingIP4Config:ignore-auto-dns:
- *
- * When the method is set to "auto" and this property to %TRUE,
- * automatically configured nameservers and search domains are ignored and
- * only nameservers and search domains specified in the
- * #NMSettingIP4Config:dns and #NMSettingIP4Config:dns-search properties, if
- * any, are used.
- **/
- g_object_class_install_property
- (object_class, PROP_IGNORE_AUTO_DNS,
- g_param_spec_boolean (NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, "", "",
- FALSE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMSettingIP4Config:dhcp-client-id:
- *
- * A string sent to the DHCP server to identify the local machine which the
- * DHCP server may use to customize the DHCP lease and options.
- **/
- g_object_class_install_property
- (object_class, PROP_DHCP_CLIENT_ID,
- g_param_spec_string (NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, "", "",
- NULL,
- G_PARAM_READWRITE |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMSettingIP4Config:dhcp-send-hostname:
- *
- * If %TRUE, a hostname is sent to the DHCP server when acquiring a lease.
- * Some DHCP servers use this hostname to update DNS databases, essentially
- * providing a static hostname for the computer. If the
- * #NMSettingIP4Config:dhcp-hostname property is empty and this property is
- * %TRUE, the current persistent hostname of the computer is sent.
- **/
- g_object_class_install_property
- (object_class, PROP_DHCP_SEND_HOSTNAME,
- g_param_spec_boolean (NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME, "", "",
- TRUE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMSettingIP4Config:dhcp-hostname:
- *
- * If the #NMSettingIP4Config:dhcp-send-hostname property is %TRUE, then the
- * specified name will be sent to the DHCP server when acquiring a lease.
- **/
- g_object_class_install_property
- (object_class, PROP_DHCP_HOSTNAME,
- g_param_spec_string (NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, "", "",
- NULL,
- G_PARAM_READWRITE |
- NM_SETTING_PARAM_INFERRABLE |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMSettingIP4Config:never-default:
- *
- * If %TRUE, this connection will never be the default IPv4 connection,
- * meaning it will never be assigned the default route by NetworkManager.
- **/
- g_object_class_install_property
- (object_class, PROP_NEVER_DEFAULT,
- g_param_spec_boolean (NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, "", "",
- FALSE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMSettingIP4Config:may-fail:
- *
- * If %TRUE, allow overall network configuration to proceed even if IPv4
- * configuration times out. Note that at least one IP configuration must
- * succeed or overall network configuration will still fail. For example,
- * in IPv6-only networks, setting this property to %TRUE allows the overall
- * network configuration to succeed if IPv4 configuration fails but IPv6
- * configuration completes successfully.
- **/
- g_object_class_install_property
- (object_class, PROP_MAY_FAIL,
- g_param_spec_boolean (NM_SETTING_IP4_CONFIG_MAY_FAIL, "", "",
- TRUE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS));
+ return nm_utils_ip4_dns_to_variant (g_value_get_boxed (prop_value));
}
-
-struct NMIP4Address {
- guint32 refcount;
- guint32 address; /* network byte order */
- guint32 prefix;
- guint32 gateway; /* network byte order */
-};
-
-/**
- * nm_ip4_address_new:
- *
- * Creates and returns a new #NMIP4Address object.
- *
- * Returns: (transfer full): the new empty #NMIP4Address object
- **/
-NMIP4Address *
-nm_ip4_address_new (void)
+static void
+ip4_dns_from_dbus (GVariant *dbus_value,
+ GValue *prop_value)
{
- NMIP4Address *address;
-
- address = g_malloc0 (sizeof (NMIP4Address));
- address->refcount = 1;
- return address;
+ g_value_take_boxed (prop_value, nm_utils_ip4_dns_from_variant (dbus_value));
}
-/**
- * nm_ip4_address_dup:
- * @source: the #NMIP4Address object to copy
- *
- * Copies a given #NMIP4Address object and returns the copy.
- *
- * Returns: (transfer full): the copy of the given #NMIP4Address copy
- **/
-NMIP4Address *
-nm_ip4_address_dup (NMIP4Address *source)
+static GVariant *
+ip4_addresses_get (NMSetting *setting,
+ const char *property)
{
- NMIP4Address *address;
-
- g_return_val_if_fail (source != NULL, NULL);
- g_return_val_if_fail (source->refcount > 0, NULL);
-
- address = nm_ip4_address_new ();
- address->address = source->address;
- address->prefix = source->prefix;
- address->gateway = source->gateway;
-
- return address;
-}
+ GPtrArray *addrs;
+ const char *gateway;
+ GVariant *ret;
-/**
- * nm_ip4_address_ref:
- * @address: the #NMIP4Address
- *
- * Increases the reference count of the object.
- **/
-void
-nm_ip4_address_ref (NMIP4Address *address)
-{
- g_return_if_fail (address != NULL);
- g_return_if_fail (address->refcount > 0);
+ g_object_get (setting, property, &addrs, NULL);
+ gateway = nm_setting_ip_config_get_gateway (NM_SETTING_IP_CONFIG (setting));
+ ret = nm_utils_ip4_addresses_to_variant (addrs, gateway);
+ g_ptr_array_unref (addrs);
- address->refcount++;
+ return ret;
}
-/**
- * nm_ip4_address_unref:
- * @address: the #NMIP4Address
- *
- * Decreases the reference count of the object. If the reference count
- * reaches zero, the object will be destroyed.
- **/
-void
-nm_ip4_address_unref (NMIP4Address *address)
-{
- g_return_if_fail (address != NULL);
- g_return_if_fail (address->refcount > 0);
+static void
+ip4_addresses_set (NMSetting *setting,
+ GVariant *connection_dict,
+ const char *property,
+ GVariant *value)
+{
+ GPtrArray *addrs;
+ GVariant *s_ip4;
+ char **labels, *gateway = NULL;
+ int i;
- address->refcount--;
- if (address->refcount == 0) {
- memset (address, 0, sizeof (NMIP4Address));
- g_free (address);
+ s_ip4 = g_variant_lookup_value (connection_dict, NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_VARIANT_TYPE_SETTING);
+ /* If 'address-data' is set then ignore 'addresses' */
+ if (g_variant_lookup (s_ip4, "address-data", "aa{sv}", NULL)) {
+ g_variant_unref (s_ip4);
+ return;
}
-}
-/**
- * nm_ip4_address_compare:
- * @address: the #NMIP4Address
- * @other: the #NMIP4Address to compare @address to.
- *
- * Determines if two #NMIP4Address objects contain the same values.
- *
- * Returns: %TRUE if the objects contain the same values, %FALSE if they do not.
- **/
-gboolean
-nm_ip4_address_compare (NMIP4Address *address, NMIP4Address *other)
-{
- g_return_val_if_fail (address != NULL, FALSE);
- g_return_val_if_fail (address->refcount > 0, FALSE);
+ addrs = nm_utils_ip4_addresses_from_variant (value, &gateway);
- g_return_val_if_fail (other != NULL, FALSE);
- g_return_val_if_fail (other->refcount > 0, FALSE);
+ if (g_variant_lookup (s_ip4, "address-labels", "^as", &labels)) {
+ for (i = 0; i < addrs->len && labels[i]; i++)
+ if (*labels[i])
+ nm_ip_address_set_attribute (addrs->pdata[i], "label", g_variant_new_string (labels[i]));
+ g_strfreev (labels);
+ }
- if ( address->address != other->address
- || address->prefix != other->prefix
- || address->gateway != other->gateway)
- return FALSE;
- return TRUE;
-}
+ if (gateway && !g_variant_lookup (s_ip4, "gateway", "s", NULL)) {
+ g_object_set (setting,
+ NM_SETTING_IP_CONFIG_GATEWAY, gateway,
+ NULL);
+ }
+ g_free (gateway);
-/**
- * nm_ip4_address_get_address:
- * @address: the #NMIP4Address
- *
- * Gets the IPv4 address property of this address object.
- *
- * Returns: the IPv4 address in network byte order
- **/
-guint32
-nm_ip4_address_get_address (NMIP4Address *address)
-{
- g_return_val_if_fail (address != NULL, 0);
- g_return_val_if_fail (address->refcount > 0, 0);
+ g_variant_unref (s_ip4);
- return address->address;
+ g_object_set (setting, property, addrs, NULL);
+ g_ptr_array_unref (addrs);
}
-/**
- * nm_ip4_address_set_address:
- * @address: the #NMIP4Address
- * @addr: the IPv4 address in network byte order
- *
- * Sets the IPv4 address property of this object.
- **/
-void
-nm_ip4_address_set_address (NMIP4Address *address, guint32 addr)
-{
- g_return_if_fail (address != NULL);
- g_return_if_fail (address->refcount > 0);
-
- address->address = addr;
-}
+static GVariant *
+ip4_address_labels_get (NMSetting *setting,
+ NMConnection *connection,
+ const char *property)
+{
+ NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG (setting);
+ gboolean have_labels = FALSE;
+ GPtrArray *labels;
+ GVariant *ret;
+ int num_addrs, i;
+
+ num_addrs = nm_setting_ip_config_get_num_addresses (s_ip);
+ for (i = 0; i < num_addrs; i++) {
+ NMIPAddress *addr = nm_setting_ip_config_get_address (s_ip, i);
+ GVariant *label = nm_ip_address_get_attribute (addr, "label");
+
+ if (label) {
+ have_labels = TRUE;
+ break;
+ }
+ }
+ if (!have_labels)
+ return NULL;
-/**
- * nm_ip4_address_get_prefix:
- * @address: the #NMIP4Address
- *
- * Gets the IPv4 address prefix (ie "24" or "30" etc) property of this address
- * object.
- *
- * Returns: the IPv4 address prefix
- **/
-guint32
-nm_ip4_address_get_prefix (NMIP4Address *address)
-{
- g_return_val_if_fail (address != NULL, 0);
- g_return_val_if_fail (address->refcount > 0, 0);
+ labels = g_ptr_array_sized_new (num_addrs);
+ for (i = 0; i < num_addrs; i++) {
+ NMIPAddress *addr = nm_setting_ip_config_get_address (s_ip, i);
+ GVariant *label = nm_ip_address_get_attribute (addr, "label");
- return address->prefix;
-}
+ g_ptr_array_add (labels, (char *) (label ? g_variant_get_string (label, NULL) : ""));
+ }
-/**
- * nm_ip4_address_set_prefix:
- * @address: the #NMIP4Address
- * @prefix: the address prefix, a number between 1 and 32 inclusive
- *
- * Sets the IPv4 address prefix.
- **/
-void
-nm_ip4_address_set_prefix (NMIP4Address *address, guint32 prefix)
-{
- g_return_if_fail (address != NULL);
- g_return_if_fail (address->refcount > 0);
- g_return_if_fail (prefix <= 32);
- g_return_if_fail (prefix > 0);
+ ret = g_variant_new_strv ((const char * const *) labels->pdata, labels->len);
+ g_ptr_array_unref (labels);
- address->prefix = prefix;
+ return ret;
}
-/**
- * nm_ip4_address_get_gateway:
- * @address: the #NMIP4Address
- *
- * Gets the IPv4 default gateway property of this address object.
- *
- * Returns: the IPv4 gateway address in network byte order
- **/
-guint32
-nm_ip4_address_get_gateway (NMIP4Address *address)
+static GVariant *
+ip4_address_data_get (NMSetting *setting,
+ NMConnection *connection,
+ const char *property)
{
- g_return_val_if_fail (address != NULL, 0);
- g_return_val_if_fail (address->refcount > 0, 0);
+ GPtrArray *addrs;
+ GVariant *ret;
- return address->gateway;
-}
+ g_object_get (setting, NM_SETTING_IP_CONFIG_ADDRESSES, &addrs, NULL);
+ ret = nm_utils_ip_addresses_to_variant (addrs);
+ g_ptr_array_unref (addrs);
-/**
- * nm_ip4_address_set_gateway:
- * @address: the #NMIP4Address
- * @gateway: the IPv4 default gateway in network byte order
- *
- * Sets the IPv4 default gateway property of this address object.
- **/
-void
-nm_ip4_address_set_gateway (NMIP4Address *address, guint32 gateway)
-{
- g_return_if_fail (address != NULL);
- g_return_if_fail (address->refcount > 0);
-
- address->gateway = gateway;
+ return ret;
}
-
-struct NMIP4Route {
- guint32 refcount;
-
- guint32 dest; /* network byte order */
- guint32 prefix;
- guint32 next_hop; /* network byte order */
- guint32 metric; /* lower metric == more preferred */
-};
-
-/**
- * nm_ip4_route_new:
- *
- * Creates and returns a new #NMIP4Route object.
- *
- * Returns: (transfer full): the new empty #NMIP4Route object
- **/
-NMIP4Route *
-nm_ip4_route_new (void)
+static void
+ip4_address_data_set (NMSetting *setting,
+ GVariant *connection_dict,
+ const char *property,
+ GVariant *value)
{
- NMIP4Route *route;
+ GPtrArray *addrs;
- route = g_malloc0 (sizeof (NMIP4Route));
- route->refcount = 1;
- return route;
+ addrs = nm_utils_ip_addresses_from_variant (value, AF_INET);
+ g_object_set (setting, NM_SETTING_IP_CONFIG_ADDRESSES, addrs, NULL);
+ g_ptr_array_unref (addrs);
}
-/**
- * nm_ip4_route_dup:
- * @source: the #NMIP4Route object to copy
- *
- * Copies a given #NMIP4Route object and returns the copy.
- *
- * Returns: (transfer full): the copy of the given #NMIP4Route copy
- **/
-NMIP4Route *
-nm_ip4_route_dup (NMIP4Route *source)
+static GVariant *
+ip4_routes_get (NMSetting *setting,
+ const char *property)
{
- NMIP4Route *route;
-
- g_return_val_if_fail (source != NULL, NULL);
- g_return_val_if_fail (source->refcount > 0, NULL);
-
- route = nm_ip4_route_new ();
- route->dest = source->dest;
- route->prefix = source->prefix;
- route->next_hop = source->next_hop;
- route->metric = source->metric;
+ GPtrArray *routes;
+ GVariant *ret;
- return route;
-}
-
-/**
- * nm_ip4_route_ref:
- * @route: the #NMIP4Route
- *
- * Increases the reference count of the object.
- **/
-void
-nm_ip4_route_ref (NMIP4Route *route)
-{
- g_return_if_fail (route != NULL);
- g_return_if_fail (route->refcount > 0);
+ g_object_get (setting, property, &routes, NULL);
+ ret = nm_utils_ip4_routes_to_variant (routes);
+ g_ptr_array_unref (routes);
- route->refcount++;
+ return ret;
}
-/**
- * nm_ip4_route_unref:
- * @route: the #NMIP4Route
- *
- * Decreases the reference count of the object. If the reference count
- * reaches zero, the object will be destroyed.
- **/
-void
-nm_ip4_route_unref (NMIP4Route *route)
-{
- g_return_if_fail (route != NULL);
- g_return_if_fail (route->refcount > 0);
-
- route->refcount--;
- if (route->refcount == 0) {
- memset (route, 0, sizeof (NMIP4Route));
- g_free (route);
+static void
+ip4_routes_set (NMSetting *setting,
+ GVariant *connection_dict,
+ const char *property,
+ GVariant *value)
+{
+ GPtrArray *routes;
+ GVariant *s_ip4;
+
+ s_ip4 = g_variant_lookup_value (connection_dict, NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_VARIANT_TYPE_SETTING);
+ /* If 'route-data' is set then ignore 'routes' */
+ if (g_variant_lookup (s_ip4, "route-data", "aa{sv}", NULL)) {
+ g_variant_unref (s_ip4);
+ return;
}
-}
+ g_variant_unref (s_ip4);
-/**
- * nm_ip4_route_compare:
- * @route: the #NMIP4Route
- * @other: the #NMIP4Route to compare @route to.
- *
- * Determines if two #NMIP4Route objects contain the same values.
- *
- * Returns: %TRUE if the objects contain the same values, %FALSE if they do not.
- **/
-gboolean
-nm_ip4_route_compare (NMIP4Route *route, NMIP4Route *other)
-{
- g_return_val_if_fail (route != NULL, FALSE);
- g_return_val_if_fail (route->refcount > 0, FALSE);
-
- g_return_val_if_fail (other != NULL, FALSE);
- g_return_val_if_fail (other->refcount > 0, FALSE);
-
- if ( route->dest != other->dest
- || route->prefix != other->prefix
- || route->next_hop != other->next_hop
- || route->metric != other->metric)
- return FALSE;
- return TRUE;
+ routes = nm_utils_ip4_routes_from_variant (value);
+ g_object_set (setting, property, routes, NULL);
+ g_ptr_array_unref (routes);
}
-/**
- * nm_ip4_route_get_dest:
- * @route: the #NMIP4Route
- *
- * Gets the IPv4 destination address property of this route object.
- *
- * Returns: the IPv4 address in network byte order
- **/
-guint32
-nm_ip4_route_get_dest (NMIP4Route *route)
+static GVariant *
+ip4_route_data_get (NMSetting *setting,
+ NMConnection *connection,
+ const char *property)
{
- g_return_val_if_fail (route != NULL, 0);
- g_return_val_if_fail (route->refcount > 0, 0);
+ GPtrArray *routes;
+ GVariant *ret;
- return route->dest;
-}
-
-/**
- * nm_ip4_route_set_dest:
- * @route: the #NMIP4Route
- * @dest: the destination address in network byte order
- *
- * Sets the IPv4 destination address property of this route object.
- **/
-void
-nm_ip4_route_set_dest (NMIP4Route *route, guint32 dest)
-{
- g_return_if_fail (route != NULL);
- g_return_if_fail (route->refcount > 0);
+ g_object_get (setting, NM_SETTING_IP_CONFIG_ROUTES, &routes, NULL);
+ ret = nm_utils_ip_routes_to_variant (routes);
+ g_ptr_array_unref (routes);
- route->dest = dest;
+ return ret;
}
-/**
- * nm_ip4_route_get_prefix:
- * @route: the #NMIP4Route
- *
- * Gets the IPv4 prefix (ie "24" or "30" etc) of this route.
- *
- * Returns: the IPv4 prefix
- **/
-guint32
-nm_ip4_route_get_prefix (NMIP4Route *route)
+static void
+ip4_route_data_set (NMSetting *setting,
+ GVariant *connection_dict,
+ const char *property,
+ GVariant *value)
{
- g_return_val_if_fail (route != NULL, 0);
- g_return_val_if_fail (route->refcount > 0, 0);
+ GPtrArray *routes;
- return route->prefix;
+ routes = nm_utils_ip_routes_from_variant (value, AF_INET);
+ g_object_set (setting, NM_SETTING_IP_CONFIG_ROUTES, routes, NULL);
+ g_ptr_array_unref (routes);
}
-/**
- * nm_ip4_route_set_prefix:
- * @route: the #NMIP4Route
- * @prefix: the prefix, a number between 1 and 32 inclusive
- *
- * Sets the IPv4 prefix of this route.
- **/
-void
-nm_ip4_route_set_prefix (NMIP4Route *route, guint32 prefix)
-{
- g_return_if_fail (route != NULL);
- g_return_if_fail (route->refcount > 0);
- g_return_if_fail (prefix <= 32);
- g_return_if_fail (prefix > 0);
-
- route->prefix = prefix;
-}
-/**
- * nm_ip4_route_get_next_hop:
- * @route: the #NMIP4Route
- *
- * Gets the IPv4 address of the next hop of this route.
- *
- * Returns: the IPv4 address in network byte order
- **/
-guint32
-nm_ip4_route_get_next_hop (NMIP4Route *route)
+static void
+nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *ip4_class)
{
- g_return_val_if_fail (route != NULL, 0);
- g_return_val_if_fail (route->refcount > 0, 0);
+ NMSettingClass *setting_class = NM_SETTING_CLASS (ip4_class);
+ GObjectClass *object_class = G_OBJECT_CLASS (ip4_class);
- return route->next_hop;
-}
+ g_type_class_add_private (setting_class, sizeof (NMSettingIP4ConfigPrivate));
-/**
- * nm_ip4_route_set_next_hop:
- * @route: the #NMIP4Route
- * @next_hop: the IPv4 address of the next hop in network byte order
- *
- * Sets the IPv4 address of the next hop of this route.
- **/
-void
-nm_ip4_route_set_next_hop (NMIP4Route *route, guint32 next_hop)
-{
- g_return_if_fail (route != NULL);
- g_return_if_fail (route->refcount > 0);
+ /* virtual methods */
+ object_class->set_property = set_property;
+ object_class->get_property = get_property;
+ object_class->finalize = finalize;
+ setting_class->verify = verify;
- route->next_hop = next_hop;
-}
+ /* properties */
-/**
- * nm_ip4_route_get_metric:
- * @route: the #NMIP4Route
- *
- * Gets the route metric property of this route object; lower values indicate
- * "better" or more preferred routes.
- *
- * Returns: the route metric
- **/
-guint32
-nm_ip4_route_get_metric (NMIP4Route *route)
-{
- g_return_val_if_fail (route != NULL, 0);
- g_return_val_if_fail (route->refcount > 0, 0);
+ /**
+ * NMSettingIP4Config:dhcp-client-id:
+ *
+ * A string sent to the DHCP server to identify the local machine which the
+ * DHCP server may use to customize the DHCP lease and options.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_DHCP_CLIENT_ID,
+ g_param_spec_string (NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, "", "",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
- return route->metric;
-}
+ /* IP4-specific property overrides */
+ _nm_setting_class_transform_property (setting_class,
+ NM_SETTING_IP_CONFIG_DNS,
+ G_VARIANT_TYPE ("au"),
+ ip4_dns_to_dbus,
+ ip4_dns_from_dbus);
-/**
- * nm_ip4_route_set_metric:
- * @route: the #NMIP4Route
- * @metric: the route metric
- *
- * Sets the route metric property of this route object; lower values indicate
- * "better" or more preferred routes.
- **/
-void
-nm_ip4_route_set_metric (NMIP4Route *route, guint32 metric)
-{
- g_return_if_fail (route != NULL);
- g_return_if_fail (route->refcount > 0);
+ _nm_setting_class_override_property (setting_class,
+ NM_SETTING_IP_CONFIG_ADDRESSES,
+ G_VARIANT_TYPE ("aau"),
+ ip4_addresses_get,
+ ip4_addresses_set,
+ NULL);
+
+ _nm_setting_class_add_dbus_only_property (setting_class,
+ "address-labels",
+ G_VARIANT_TYPE_STRING_ARRAY,
+ ip4_address_labels_get,
+ NULL);
+
+ _nm_setting_class_add_dbus_only_property (setting_class,
+ "address-data",
+ G_VARIANT_TYPE ("aa{sv}"),
+ ip4_address_data_get,
+ ip4_address_data_set);
+
+ _nm_setting_class_override_property (setting_class,
+ NM_SETTING_IP_CONFIG_ROUTES,
+ G_VARIANT_TYPE ("aau"),
+ ip4_routes_get,
+ ip4_routes_set,
+ NULL);
+
+ _nm_setting_class_add_dbus_only_property (setting_class,
+ "route-data",
+ G_VARIANT_TYPE ("aa{sv}"),
+ ip4_route_data_get,
+ ip4_route_data_set);
- route->metric = metric;
}
diff --git a/libnm-core/nm-setting-ip4-config.h b/libnm-core/nm-setting-ip4-config.h
index 369e1d46d2..e944dfe391 100644
--- a/libnm-core/nm-setting-ip4-config.h
+++ b/libnm-core/nm-setting-ip4-config.h
@@ -27,7 +27,7 @@
#error "Only <NetworkManager.h> can be included directly."
#endif
-#include "nm-setting.h"
+#include "nm-setting-ip-config.h"
G_BEGIN_DECLS
@@ -40,18 +40,7 @@ G_BEGIN_DECLS
#define NM_SETTING_IP4_CONFIG_SETTING_NAME "ipv4"
-#define NM_SETTING_IP4_CONFIG_METHOD "method"
-#define NM_SETTING_IP4_CONFIG_DNS "dns"
-#define NM_SETTING_IP4_CONFIG_DNS_SEARCH "dns-search"
-#define NM_SETTING_IP4_CONFIG_ADDRESSES "addresses"
-#define NM_SETTING_IP4_CONFIG_ROUTES "routes"
-#define NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES "ignore-auto-routes"
-#define NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS "ignore-auto-dns"
#define NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID "dhcp-client-id"
-#define NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME "dhcp-send-hostname"
-#define NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME "dhcp-hostname"
-#define NM_SETTING_IP4_CONFIG_NEVER_DEFAULT "never-default"
-#define NM_SETTING_IP4_CONFIG_MAY_FAIL "may-fail"
/**
* NM_SETTING_IP4_CONFIG_METHOD_AUTO:
@@ -97,63 +86,12 @@ G_BEGIN_DECLS
*/
#define NM_SETTING_IP4_CONFIG_METHOD_DISABLED "disabled"
-typedef struct NMIP4Address NMIP4Address;
-
-GType nm_ip4_address_get_type (void);
-
-NMIP4Address * nm_ip4_address_new (void);
-NMIP4Address * nm_ip4_address_dup (NMIP4Address *source);
-void nm_ip4_address_ref (NMIP4Address *address);
-void nm_ip4_address_unref (NMIP4Address *address);
-/* Return TRUE if addresses are identical */
-gboolean nm_ip4_address_compare (NMIP4Address *address, NMIP4Address *other);
-
-guint32 nm_ip4_address_get_address (NMIP4Address *address);
-void nm_ip4_address_set_address (NMIP4Address *address,
- guint32 addr); /* network byte order */
-
-guint32 nm_ip4_address_get_prefix (NMIP4Address *address);
-void nm_ip4_address_set_prefix (NMIP4Address *address,
- guint32 prefix);
-
-guint32 nm_ip4_address_get_gateway (NMIP4Address *address);
-void nm_ip4_address_set_gateway (NMIP4Address *address,
- guint32 gateway); /* network byte order */
-
-typedef struct NMIP4Route NMIP4Route;
-
-GType nm_ip4_route_get_type (void);
-
-NMIP4Route * nm_ip4_route_new (void);
-NMIP4Route * nm_ip4_route_dup (NMIP4Route *source);
-void nm_ip4_route_ref (NMIP4Route *route);
-void nm_ip4_route_unref (NMIP4Route *route);
-/* Return TRUE if routes are identical */
-gboolean nm_ip4_route_compare (NMIP4Route *route, NMIP4Route *other);
-
-guint32 nm_ip4_route_get_dest (NMIP4Route *route);
-void nm_ip4_route_set_dest (NMIP4Route *route,
- guint32 dest); /* network byte order */
-
-guint32 nm_ip4_route_get_prefix (NMIP4Route *route);
-void nm_ip4_route_set_prefix (NMIP4Route *route,
- guint32 prefix);
-
-guint32 nm_ip4_route_get_next_hop (NMIP4Route *route);
-void nm_ip4_route_set_next_hop (NMIP4Route *route,
- guint32 next_hop); /* network byte order */
-
-guint32 nm_ip4_route_get_metric (NMIP4Route *route);
-void nm_ip4_route_set_metric (NMIP4Route *route,
- guint32 metric);
-
-
struct _NMSettingIP4Config {
- NMSetting parent;
+ NMSettingIPConfig parent;
};
typedef struct {
- NMSettingClass parent;
+ NMSettingIPConfigClass parent;
/*< private >*/
gpointer padding[4];
@@ -161,46 +99,9 @@ typedef struct {
GType nm_setting_ip4_config_get_type (void);
-NMSetting * nm_setting_ip4_config_new (void);
-const char * nm_setting_ip4_config_get_method (NMSettingIP4Config *setting);
-
-guint32 nm_setting_ip4_config_get_num_dns (NMSettingIP4Config *setting);
-const char * nm_setting_ip4_config_get_dns (NMSettingIP4Config *setting, guint32 i);
-gboolean nm_setting_ip4_config_add_dns (NMSettingIP4Config *setting, const char *dns);
-void nm_setting_ip4_config_remove_dns (NMSettingIP4Config *setting, guint32 i);
-gboolean nm_setting_ip4_config_remove_dns_by_value (NMSettingIP4Config *setting, const char *dns);
-void nm_setting_ip4_config_clear_dns (NMSettingIP4Config *setting);
-
-guint32 nm_setting_ip4_config_get_num_dns_searches (NMSettingIP4Config *setting);
-const char * nm_setting_ip4_config_get_dns_search (NMSettingIP4Config *setting, guint32 i);
-gboolean nm_setting_ip4_config_add_dns_search (NMSettingIP4Config *setting, const char *dns_search);
-void nm_setting_ip4_config_remove_dns_search (NMSettingIP4Config *setting, guint32 i);
-gboolean nm_setting_ip4_config_remove_dns_search_by_value (NMSettingIP4Config *setting, const char *dns_search);
-void nm_setting_ip4_config_clear_dns_searches (NMSettingIP4Config *setting);
-
-guint32 nm_setting_ip4_config_get_num_addresses (NMSettingIP4Config *setting);
-NMIP4Address *nm_setting_ip4_config_get_address (NMSettingIP4Config *setting, guint32 i);
-gboolean nm_setting_ip4_config_add_address (NMSettingIP4Config *setting, NMIP4Address *address);
-void nm_setting_ip4_config_remove_address (NMSettingIP4Config *setting, guint32 i);
-gboolean nm_setting_ip4_config_remove_address_by_value (NMSettingIP4Config *setting, NMIP4Address *address);
-void nm_setting_ip4_config_clear_addresses (NMSettingIP4Config *setting);
-
-guint32 nm_setting_ip4_config_get_num_routes (NMSettingIP4Config *setting);
-NMIP4Route * nm_setting_ip4_config_get_route (NMSettingIP4Config *setting, guint32 i);
-gboolean nm_setting_ip4_config_add_route (NMSettingIP4Config *setting, NMIP4Route *route);
-void nm_setting_ip4_config_remove_route (NMSettingIP4Config *setting, guint32 i);
-gboolean nm_setting_ip4_config_remove_route_by_value (NMSettingIP4Config *setting, NMIP4Route *route);
-void nm_setting_ip4_config_clear_routes (NMSettingIP4Config *setting);
-
-gboolean nm_setting_ip4_config_get_ignore_auto_routes (NMSettingIP4Config *setting);
-gboolean nm_setting_ip4_config_get_ignore_auto_dns (NMSettingIP4Config *setting);
-const char * nm_setting_ip4_config_get_dhcp_client_id (NMSettingIP4Config *setting);
-gboolean nm_setting_ip4_config_get_dhcp_send_hostname (NMSettingIP4Config *setting);
-const char * nm_setting_ip4_config_get_dhcp_hostname (NMSettingIP4Config *setting);
-
-gboolean nm_setting_ip4_config_get_never_default (NMSettingIP4Config *setting);
-
-gboolean nm_setting_ip4_config_get_may_fail (NMSettingIP4Config *setting);
+NMSetting *nm_setting_ip4_config_new (void);
+
+const char *nm_setting_ip4_config_get_dhcp_client_id (NMSettingIP4Config *setting);
G_END_DECLS
diff --git a/libnm-core/nm-setting-ip6-config.c b/libnm-core/nm-setting-ip6-config.c
index cbc5e2c8be..6e3ff6164e 100644
--- a/libnm-core/nm-setting-ip6-config.c
+++ b/libnm-core/nm-setting-ip6-config.c
@@ -23,9 +23,6 @@
#include <glib/gi18n.h>
#include "nm-setting-ip6-config.h"
-#include "nm-utils.h"
-#include "nm-utils-private.h"
-#include "nm-glib-compat.h"
#include "nm-setting-private.h"
#include "nm-core-enum-types.h"
@@ -35,44 +32,35 @@
*
* The #NMSettingIP6Config object is a #NMSetting subclass that describes
* properties related to IPv6 addressing, routing, and Domain Name Service
+ *
+ * #NMSettingIP6Config has few properties or methods of its own; it inherits
+ * almost everything from #NMSettingIPConfig.
+ *
+ * NetworkManager supports 6 values for the #NMSettingIPConfig:method property
+ * for IPv6. If "auto" is specified then the appropriate automatic method (PPP,
+ * router advertisement, etc) is used for the device and most other properties
+ * can be left unset. To force the use of DHCP only, specify "dhcp"; this
+ * method is only valid for Ethernet- based hardware. If "link-local" is
+ * specified, then an IPv6 link-local address will be assigned to the interface.
+ * If "manual" is specified, static IP addressing is used and at least one IP
+ * address must be given in the "addresses" property. If "ignore" is specified,
+ * IPv6 configuration is not done. Note: the "shared" method is not yet
+ * supported.
**/
-G_DEFINE_BOXED_TYPE (NMIP6Address, nm_ip6_address, nm_ip6_address_dup, nm_ip6_address_unref)
-G_DEFINE_BOXED_TYPE (NMIP6Route, nm_ip6_route, nm_ip6_route_dup, nm_ip6_route_unref)
-
-G_DEFINE_TYPE_WITH_CODE (NMSettingIP6Config, nm_setting_ip6_config, NM_TYPE_SETTING,
+G_DEFINE_TYPE_WITH_CODE (NMSettingIP6Config, nm_setting_ip6_config, NM_TYPE_SETTING_IP_CONFIG,
_nm_register_setting (IP6_CONFIG, 4))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_IP6_CONFIG)
#define NM_SETTING_IP6_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_IP6_CONFIG, NMSettingIP6ConfigPrivate))
typedef struct {
- char *method;
- char *dhcp_hostname;
- GSList *dns; /* array of struct in6_addr */
- 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 never_default;
- gboolean may_fail;
NMSettingIP6ConfigPrivacy ip6_privacy;
} NMSettingIP6ConfigPrivate;
enum {
PROP_0,
- PROP_METHOD,
- PROP_DHCP_HOSTNAME,
- PROP_DNS,
- PROP_DNS_SEARCH,
- PROP_ADDRESSES,
- PROP_ROUTES,
- PROP_IGNORE_AUTO_ROUTES,
- PROP_IGNORE_AUTO_DNS,
- PROP_NEVER_DEFAULT,
- PROP_MAY_FAIL,
PROP_IP6_PRIVACY,
LAST_PROP
@@ -92,683 +80,6 @@ nm_setting_ip6_config_new (void)
}
/**
- * nm_setting_ip6_config_get_method:
- * @setting: the #NMSettingIP6Config
- *
- * Returns: the #NMSettingIP6Config:method property of the setting
- **/
-const char *
-nm_setting_ip6_config_get_method (NMSettingIP6Config *setting)
-{
- g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), NULL);
-
- return NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->method;
-}
-
-/**
- * nm_setting_ip6_config_get_dhcp_hostname:
- * @setting: the #NMSettingIP6Config
- *
- * Returns the value contained in the #NMSettingIP6Config:dhcp-hostname
- * property.
- *
- * Returns: the configured hostname to send to the DHCP server
- **/
-const char *
-nm_setting_ip6_config_get_dhcp_hostname (NMSettingIP6Config *setting)
-{
- g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), NULL);
-
- return NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->dhcp_hostname;
-}
-
-/**
- * nm_setting_ip6_config_get_num_dns:
- * @setting: the #NMSettingIP6Config
- *
- * Returns: the number of configured DNS servers
- **/
-guint32
-nm_setting_ip6_config_get_num_dns (NMSettingIP6Config *setting)
-{
- g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), 0);
-
- return g_slist_length (NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->dns);
-}
-
-/**
- * nm_setting_ip6_config_get_dns:
- * @setting: the #NMSettingIP6Config
- * @i: index number of the DNS server to return
- *
- * Returns: (transfer none): the IPv6 address of the DNS server at index @i
- **/
-const char *
-nm_setting_ip6_config_get_dns (NMSettingIP6Config *setting, guint32 i)
-{
- NMSettingIP6ConfigPrivate *priv;
-
- g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), NULL);
-
- priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
- g_return_val_if_fail (i < g_slist_length (priv->dns), NULL);
-
- return (const char *) g_slist_nth_data (priv->dns, i);
-}
-
-static const char *
-canonicalize_ip (const char *ip)
-{
- struct in6_addr addr;
- int ret;
-
- ret = inet_pton (AF_INET6, ip, &addr);
- g_return_val_if_fail (ret == 1, NULL);
- return nm_utils_inet6_ntop (&addr, NULL);
-}
-
-/**
- * nm_setting_ip6_config_add_dns:
- * @setting: the #NMSettingIP6Config
- * @dns: the IPv6 address of the DNS server to add
- *
- * Adds a new DNS server to the setting.
- *
- * Returns: %TRUE if the DNS server was added; %FALSE if the server was already
- * known
- **/
-gboolean
-nm_setting_ip6_config_add_dns (NMSettingIP6Config *setting, const char *dns)
-{
- NMSettingIP6ConfigPrivate *priv;
- const char *dns_canonical;
- GSList *iter;
-
- g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
- g_return_val_if_fail (dns != NULL, FALSE);
- g_return_val_if_fail (dns[0] != '\0', FALSE);
-
- priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
-
- dns_canonical = canonicalize_ip (dns);
- g_return_val_if_fail (dns_canonical != NULL, FALSE);
-
- for (iter = priv->dns; iter; iter = g_slist_next (iter)) {
- if (!strcmp (dns_canonical, (char *) iter->data))
- return FALSE;
- }
-
- priv->dns = g_slist_append (priv->dns, g_strdup (dns_canonical));
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_DNS);
- return TRUE;
-}
-
-/**
- * nm_setting_ip6_config_remove_dns:
- * @setting: the #NMSettingIP6Config
- * @i: index number of the DNS server to remove
- *
- * Removes the DNS server at index @i.
- **/
-void
-nm_setting_ip6_config_remove_dns (NMSettingIP6Config *setting, guint32 i)
-{
- NMSettingIP6ConfigPrivate *priv;
- GSList *elt;
-
- g_return_if_fail (NM_IS_SETTING_IP6_CONFIG (setting));
-
- priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
- elt = g_slist_nth (priv->dns, i);
- g_return_if_fail (elt != NULL);
-
- g_free (elt->data);
- priv->dns = g_slist_delete_link (priv->dns, elt);
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_DNS);
-}
-
-/**
- * nm_setting_ip6_config_remove_dns_by_value:
- * @setting: the #NMSettingIP6Config
- * @dns: the IPv6 address of the DNS server to remove
- *
- * Removes the DNS server at index @i.
- *
- * Returns: %TRUE if the DNS server was found and removed; %FALSE if it was not.
- **/
-gboolean
-nm_setting_ip6_config_remove_dns_by_value (NMSettingIP6Config *setting,
- const char *dns)
-{
- NMSettingIP6ConfigPrivate *priv;
- const char *dns_canonical;
- GSList *iter;
-
- g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
- g_return_val_if_fail (dns != NULL, FALSE);
- g_return_val_if_fail (dns[0] != '\0', FALSE);
-
- priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
-
- dns_canonical = canonicalize_ip (dns);
- g_return_val_if_fail (dns_canonical != NULL, FALSE);
-
- for (iter = priv->dns; iter; iter = g_slist_next (iter)) {
- if (!strcmp (dns_canonical, (char *) iter->data)) {
- priv->dns = g_slist_delete_link (priv->dns, iter);
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_DNS);
- return TRUE;
- }
- }
- return FALSE;
-}
-
-/**
- * nm_setting_ip6_config_clear_dns:
- * @setting: the #NMSettingIP6Config
- *
- * Removes all configured DNS servers.
- **/
-void
-nm_setting_ip6_config_clear_dns (NMSettingIP6Config *setting)
-{
- g_return_if_fail (NM_IS_SETTING_IP6_CONFIG (setting));
-
- g_slist_free_full (NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->dns, g_free);
- NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->dns = NULL;
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_DNS);
-}
-
-/**
- * nm_setting_ip6_config_get_num_dns_searches:
- * @setting: the #NMSettingIP6Config
- *
- * Returns: the number of configured DNS search domains
- **/
-guint32
-nm_setting_ip6_config_get_num_dns_searches (NMSettingIP6Config *setting)
-{
- g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), 0);
-
- return g_slist_length (NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->dns_search);
-}
-
-/**
- * nm_setting_ip6_config_get_dns_search:
- * @setting: the #NMSettingIP6Config
- * @i: index number of the DNS search domain to return
- *
- * Returns: the DNS search domain at index @i
- **/
-const char *
-nm_setting_ip6_config_get_dns_search (NMSettingIP6Config *setting, guint32 i)
-{
- NMSettingIP6ConfigPrivate *priv;
-
- g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), NULL);
-
- priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
- g_return_val_if_fail (i < g_slist_length (priv->dns_search), NULL);
-
- return (const char *) g_slist_nth_data (priv->dns_search, i);
-}
-
-/**
- * nm_setting_ip6_config_add_dns_search:
- * @setting: the #NMSettingIP6Config
- * @dns_search: the search domain to add
- *
- * Adds a new DNS search domain to the setting.
- *
- * Returns: %TRUE if the DNS search domain was added; %FALSE if the search
- * domain was already known
- **/
-gboolean
-nm_setting_ip6_config_add_dns_search (NMSettingIP6Config *setting,
- const char *dns_search)
-{
- NMSettingIP6ConfigPrivate *priv;
- GSList *iter;
-
- g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
- g_return_val_if_fail (dns_search != NULL, FALSE);
- g_return_val_if_fail (dns_search[0] != '\0', FALSE);
-
- priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
- for (iter = priv->dns_search; iter; iter = g_slist_next (iter)) {
- if (!strcmp (dns_search, (char *) iter->data))
- return FALSE;
- }
-
- priv->dns_search = g_slist_append (priv->dns_search, g_strdup (dns_search));
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_DNS_SEARCH);
- return TRUE;
-}
-
-/**
- * nm_setting_ip6_config_remove_dns_search:
- * @setting: the #NMSettingIP6Config
- * @i: index number of the DNS search domain
- *
- * Removes the DNS search domain at index @i.
- **/
-void
-nm_setting_ip6_config_remove_dns_search (NMSettingIP6Config *setting, guint32 i)
-{
- NMSettingIP6ConfigPrivate *priv;
- GSList *elt;
-
- g_return_if_fail (NM_IS_SETTING_IP6_CONFIG (setting));
-
- priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
- elt = g_slist_nth (priv->dns_search, i);
- g_return_if_fail (elt != NULL);
-
- g_free (elt->data);
- priv->dns_search = g_slist_delete_link (priv->dns_search, elt);
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_DNS_SEARCH);
-}
-
-/**
- * nm_setting_ip6_config_remove_dns_search_by_value:
- * @setting: the #NMSettingIP6Config
- * @dns_search: the search domain to remove
- *
- * Removes the DNS search domain @dns_search.
- *
- * Returns: %TRUE if the DNS search domain was found and removed; %FALSE if it was not.
- **/
-gboolean
-nm_setting_ip6_config_remove_dns_search_by_value (NMSettingIP6Config *setting,
- const char *dns_search)
-{
- NMSettingIP6ConfigPrivate *priv;
- GSList *iter;
-
- g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
- g_return_val_if_fail (dns_search != NULL, FALSE);
- g_return_val_if_fail (dns_search[0] != '\0', FALSE);
-
- priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
- for (iter = priv->dns_search; iter; iter = g_slist_next (iter)) {
- if (!strcmp (dns_search, (char *) iter->data)) {
- priv->dns_search = g_slist_delete_link (priv->dns_search, iter);
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_DNS_SEARCH);
- return TRUE;
- }
- }
- return FALSE;
-}
-
-/**
- * nm_setting_ip6_config_clear_dns_searches:
- * @setting: the #NMSettingIP6Config
- *
- * Removes all configured DNS search domains.
- **/
-void
-nm_setting_ip6_config_clear_dns_searches (NMSettingIP6Config *setting)
-{
- g_return_if_fail (NM_IS_SETTING_IP6_CONFIG (setting));
-
- g_slist_free_full (NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->dns_search, g_free);
- NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->dns_search = NULL;
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_DNS_SEARCH);
-}
-
-/**
- * nm_setting_ip6_config_get_num_addresses:
- * @setting: the #NMSettingIP6Config
- *
- * Returns: the number of configured addresses
- **/
-guint32
-nm_setting_ip6_config_get_num_addresses (NMSettingIP6Config *setting)
-{
- g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), 0);
-
- return g_slist_length (NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->addresses);
-}
-
-/**
- * nm_setting_ip6_config_get_address:
- * @setting: the #NMSettingIP6Config
- * @i: index number of the address to return
- *
- * Returns: the address at index @i
- **/
-NMIP6Address *
-nm_setting_ip6_config_get_address (NMSettingIP6Config *setting, guint32 i)
-{
- NMSettingIP6ConfigPrivate *priv;
-
- g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), NULL);
-
- priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
- g_return_val_if_fail (i < g_slist_length (priv->addresses), NULL);
-
- return (NMIP6Address *) g_slist_nth_data (priv->addresses, i);
-}
-
-/**
- * nm_setting_ip6_config_add_address:
- * @setting: the #NMSettingIP6Config
- * @address: the new address to add
- *
- * Adds a new IPv6 address and associated information to the setting. The
- * given address is duplicated internally and is not changed by this function.
- *
- * Returns: %TRUE if the address was added; %FALSE if the address was already
- * known.
- **/
-gboolean
-nm_setting_ip6_config_add_address (NMSettingIP6Config *setting,
- NMIP6Address *address)
-{
- NMSettingIP6ConfigPrivate *priv;
- NMIP6Address *copy;
- GSList *iter;
-
- g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
- g_return_val_if_fail (address != NULL, FALSE);
-
- priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
- for (iter = priv->addresses; iter; iter = g_slist_next (iter)) {
- if (nm_ip6_address_compare ((NMIP6Address *) iter->data, address))
- return FALSE;
- }
-
- copy = nm_ip6_address_dup (address);
- priv->addresses = g_slist_append (priv->addresses, copy);
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ADDRESSES);
- return TRUE;
-}
-
-/**
- * nm_setting_ip6_config_remove_address:
- * @setting: the #NMSettingIP6Config
- * @i: index number of the address to remove
- *
- * Removes the address at index @i.
- **/
-void
-nm_setting_ip6_config_remove_address (NMSettingIP6Config *setting, guint32 i)
-{
- NMSettingIP6ConfigPrivate *priv;
- GSList *elt;
-
- g_return_if_fail (NM_IS_SETTING_IP6_CONFIG (setting));
-
- priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
- elt = g_slist_nth (priv->addresses, i);
- g_return_if_fail (elt != NULL);
-
- nm_ip6_address_unref ((NMIP6Address *) elt->data);
- priv->addresses = g_slist_delete_link (priv->addresses, elt);
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ADDRESSES);
-}
-
-/**
- * nm_setting_ip6_config_remove_address_by_value:
- * @setting: the #NMSettingIP6Config
- * @address: the address to remove
- *
- * Removes the address @address.
- *
- * Returns: %TRUE if the address was found and removed; %FALSE if it was not.
- **/
-gboolean
-nm_setting_ip6_config_remove_address_by_value (NMSettingIP6Config *setting,
- NMIP6Address *address)
-{
- NMSettingIP6ConfigPrivate *priv;
- GSList *iter;
-
- g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
- g_return_val_if_fail (address != NULL, FALSE);
-
- priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
- for (iter = priv->addresses; iter; iter = g_slist_next (iter)) {
- if (nm_ip6_address_compare ((NMIP6Address *) iter->data, address)) {
- priv->addresses = g_slist_delete_link (priv->addresses, iter);
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ADDRESSES);
- return TRUE;
- }
- }
- return FALSE;
-}
-
-/**
- * nm_setting_ip6_config_clear_addresses:
- * @setting: the #NMSettingIP6Config
- *
- * Removes all configured addresses.
- **/
-void
-nm_setting_ip6_config_clear_addresses (NMSettingIP6Config *setting)
-{
- NMSettingIP6ConfigPrivate *priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
-
- g_return_if_fail (NM_IS_SETTING_IP6_CONFIG (setting));
-
- g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip6_address_unref);
- priv->addresses = NULL;
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ADDRESSES);
-}
-
-/**
- * nm_setting_ip6_config_get_num_routes:
- * @setting: the #NMSettingIP6Config
- *
- * Returns: the number of configured routes
- **/
-guint32
-nm_setting_ip6_config_get_num_routes (NMSettingIP6Config *setting)
-{
- g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), 0);
-
- return g_slist_length (NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->routes);
-}
-
-/**
- * nm_setting_ip6_config_get_route:
- * @setting: the #NMSettingIP6Config
- * @i: index number of the route to return
- *
- * Returns: the route at index @i
- **/
-NMIP6Route *
-nm_setting_ip6_config_get_route (NMSettingIP6Config *setting, guint32 i)
-{
- NMSettingIP6ConfigPrivate *priv;
-
- g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), NULL);
-
- priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
- g_return_val_if_fail (i < g_slist_length (priv->routes), NULL);
-
- return (NMIP6Route *) g_slist_nth_data (priv->routes, i);
-}
-
-/**
- * nm_setting_ip6_config_add_route:
- * @setting: the #NMSettingIP6Config
- * @route: the route to add
- *
- * Adds a new IPv6 route and associated information to the setting. The
- * given route is duplicated internally and is not changed by this function.
- *
- * Returns: %TRUE if the route was added; %FALSE if the route was already known.
- **/
-gboolean
-nm_setting_ip6_config_add_route (NMSettingIP6Config *setting,
- NMIP6Route *route)
-{
- NMSettingIP6ConfigPrivate *priv;
- NMIP6Route *copy;
- GSList *iter;
-
- g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
- g_return_val_if_fail (route != NULL, FALSE);
-
- priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
- for (iter = priv->routes; iter; iter = g_slist_next (iter)) {
- if (nm_ip6_route_compare ((NMIP6Route *) iter->data, route))
- return FALSE;
- }
-
- copy = nm_ip6_route_dup (route);
- priv->routes = g_slist_append (priv->routes, copy);
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ROUTES);
- return TRUE;
-}
-
-/**
- * nm_setting_ip6_config_remove_route:
- * @setting: the #NMSettingIP6Config
- * @i: index number of the route
- *
- * Removes the route at index @i.
- **/
-void
-nm_setting_ip6_config_remove_route (NMSettingIP6Config *setting, guint32 i)
-{
- NMSettingIP6ConfigPrivate *priv;
- GSList *elt;
-
- g_return_if_fail (NM_IS_SETTING_IP6_CONFIG (setting));
-
- priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
- elt = g_slist_nth (priv->routes, i);
- g_return_if_fail (elt != NULL);
-
- nm_ip6_route_unref ((NMIP6Route *) elt->data);
- priv->routes = g_slist_delete_link (priv->routes, elt);
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ROUTES);
-}
-
-/**
- * nm_setting_ip6_config_remove_route_by_value:
- * @setting: the #NMSettingIP6Config
- * @route: the route to remove
- *
- * Removes the route @route.
- *
- * Returns: %TRUE if the route was found and removed; %FALSE if it was not.
- **/
-gboolean
-nm_setting_ip6_config_remove_route_by_value (NMSettingIP6Config *setting,
- NMIP6Route *route)
-{
- NMSettingIP6ConfigPrivate *priv;
- GSList *iter;
-
- g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
- g_return_val_if_fail (route != NULL, FALSE);
-
- priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
- for (iter = priv->routes; iter; iter = g_slist_next (iter)) {
- if (nm_ip6_route_compare ((NMIP6Route *) iter->data, route)) {
- nm_ip6_route_unref ((NMIP6Route *) iter->data);
- priv->routes = g_slist_delete_link (priv->routes, iter);
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ROUTES);
- return TRUE;
- }
- }
- return FALSE;
-}
-
-/**
- * nm_setting_ip6_config_clear_routes:
- * @setting: the #NMSettingIP6Config
- *
- * Removes all configured routes.
- **/
-void
-nm_setting_ip6_config_clear_routes (NMSettingIP6Config *setting)
-{
- NMSettingIP6ConfigPrivate *priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
-
- g_return_if_fail (NM_IS_SETTING_IP6_CONFIG (setting));
-
- g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_route_unref);
- priv->routes = NULL;
- g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ROUTES);
-}
-
-/**
- * nm_setting_ip6_config_get_ignore_auto_routes:
- * @setting: the #NMSettingIP6Config
- *
- * Returns the value contained in the #NMSettingIP6Config:ignore-auto-routes
- * property.
- *
- * Returns: %TRUE if automatically configured (ie via DHCP) routes should be
- * ignored.
- **/
-gboolean
-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_routes;
-}
-
-/**
- * nm_setting_ip6_config_get_ignore_auto_dns:
- * @setting: the #NMSettingIP6Config
- *
- * Returns the value contained in the #NMSettingIP6Config:ignore-auto-dns
- * property.
- *
- * Returns: %TRUE if automatically configured (ie via DHCP or router
- * advertisements) DNS information should be ignored.
- **/
-gboolean
-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_auto_dns;
-}
-
-/**
- * nm_setting_ip6_config_get_never_default:
- * @setting: the #NMSettingIP6Config
- *
- * Returns the value contained in the #NMSettingIP6Config:never-default
- * property.
- *
- * Returns: %TRUE if this connection should never be the default connection
- * for IPv6 addressing
- **/
-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)->never_default;
-}
-
-/**
- * nm_setting_ip6_config_get_may_fail:
- * @setting: the #NMSettingIP6Config
- *
- * Returns the value contained in the #NMSettingIP6Config:may-fail
- * property.
- *
- * Returns: %TRUE if this connection doesn't require IPv6 addressing to complete
- * for the connection to succeed.
- **/
-gboolean
-nm_setting_ip6_config_get_may_fail (NMSettingIP6Config *setting)
-{
- g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
-
- return NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->may_fail;
-}
-
-/**
* nm_setting_ip6_config_get_ip6_privacy:
* @setting: the #NMSettingIP6Config
*
@@ -788,98 +99,73 @@ nm_setting_ip6_config_get_ip6_privacy (NMSettingIP6Config *setting)
static gboolean
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
- NMSettingIP6ConfigPrivate *priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
- GSList *iter;
- int i;
+ NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG (setting);
+ NMSettingVerifyResult ret;
+ const char *method;
- if (!priv->method) {
- g_set_error_literal (error,
- NM_CONNECTION_ERROR,
- NM_CONNECTION_ERROR_MISSING_PROPERTY,
- _("property is missing"));
- g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP6_CONFIG_METHOD);
- return FALSE;
- }
+ ret = NM_SETTING_CLASS (nm_setting_ip6_config_parent_class)->verify (setting, connection, error);
+ if (ret != NM_SETTING_VERIFY_SUCCESS)
+ return ret;
+
+ method = nm_setting_ip_config_get_method (s_ip);
+ /* Base class already checked that it exists */
+ g_assert (method);
- if (!strcmp (priv->method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) {
- if (!priv->addresses) {
+ if (!strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) {
+ if (nm_setting_ip_config_get_num_addresses (s_ip) == 0) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_MISSING_PROPERTY,
_("this property cannot be empty for '%s=%s'"),
- NM_SETTING_IP6_CONFIG_METHOD, priv->method);
- g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP6_CONFIG_ADDRESSES);
+ NM_SETTING_IP_CONFIG_METHOD, method);
+ g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP_CONFIG_ADDRESSES);
return FALSE;
}
- } else if ( !strcmp (priv->method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)
- || !strcmp (priv->method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL)
- || !strcmp (priv->method, NM_SETTING_IP6_CONFIG_METHOD_SHARED)) {
- if (priv->dns) {
+ } else if ( !strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)
+ || !strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL)
+ || !strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_SHARED)) {
+ if (nm_setting_ip_config_get_num_dns (s_ip) > 0) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("'%s' not allowed for %s=%s"),
_("this property is not allowed for '%s=%s'"),
- NM_SETTING_IP6_CONFIG_METHOD, priv->method);
- g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP6_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_METHOD, method);
+ g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP_CONFIG_DNS);
return FALSE;
}
- if (priv->dns_search) {
+ if (nm_setting_ip_config_get_num_dns_searches (s_ip) > 0) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("this property is not allowed for '%s=%s'"),
- NM_SETTING_IP6_CONFIG_METHOD, priv->method);
- g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP6_CONFIG_DNS_SEARCH);
+ NM_SETTING_IP_CONFIG_METHOD, method);
+ g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP_CONFIG_DNS_SEARCH);
return FALSE;
}
- if (priv->addresses) {
+ if (nm_setting_ip_config_get_num_addresses (s_ip) > 0) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("this property is not allowed for '%s=%s'"),
- NM_SETTING_IP6_CONFIG_METHOD, priv->method);
- g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP6_CONFIG_ADDRESSES);
+ NM_SETTING_IP_CONFIG_METHOD, method);
+ g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP_CONFIG_ADDRESSES);
return FALSE;
}
- } else if ( !strcmp (priv->method, NM_SETTING_IP6_CONFIG_METHOD_AUTO)
- || !strcmp (priv->method, NM_SETTING_IP6_CONFIG_METHOD_DHCP)) {
+ } else if ( !strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO)
+ || !strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP)) {
/* nothing to do */
} else {
g_set_error_literal (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("property is invalid"));
- g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP6_CONFIG_METHOD);
- return FALSE;
- }
-
- if (priv->dhcp_hostname && !strlen (priv->dhcp_hostname)) {
- g_set_error_literal (error,
- NM_CONNECTION_ERROR,
- NM_CONNECTION_ERROR_INVALID_PROPERTY,
- _("property is missing"));
- g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME);
+ g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP_CONFIG_METHOD);
return FALSE;
}
- for (iter = priv->dns, i = 0; iter; iter = g_slist_next (iter), i++) {
- const char *dns = (const char *) iter->data;
- struct in6_addr addr;
-
- if (inet_pton (AF_INET6, dns, &addr) != 1) {
- g_set_error (error,
- NM_CONNECTION_ERROR,
- NM_CONNECTION_ERROR_INVALID_PROPERTY,
- _("%d. DNS server address is invalid"),
- i+1);
- g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP6_CONFIG_DNS);
- return FALSE;
- }
- }
-
return TRUE;
}
@@ -889,59 +175,157 @@ nm_setting_ip6_config_init (NMSettingIP6Config *setting)
{
}
+static GVariant *
+ip6_dns_to_dbus (const GValue *prop_value)
+{
+ return nm_utils_ip6_dns_to_variant (g_value_get_boxed (prop_value));
+}
+
static void
-finalize (GObject *object)
+ip6_dns_from_dbus (GVariant *dbus_value,
+ GValue *prop_value)
{
- NMSettingIP6ConfigPrivate *priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (object);
+ g_value_take_boxed (prop_value, nm_utils_ip6_dns_from_variant (dbus_value));
+}
+
+static GVariant *
+ip6_addresses_get (NMSetting *setting,
+ const char *property)
+{
+ GPtrArray *addrs;
+ const char *gateway;
+ GVariant *ret;
+
+ g_object_get (setting, property, &addrs, NULL);
+ gateway = nm_setting_ip_config_get_gateway (NM_SETTING_IP_CONFIG (setting));
+ ret = nm_utils_ip6_addresses_to_variant (addrs, gateway);
+ g_ptr_array_unref (addrs);
+
+ return ret;
+}
+
+static void
+ip6_addresses_set (NMSetting *setting,
+ GVariant *connection_dict,
+ const char *property,
+ GVariant *value)
+{
+ GPtrArray *addrs;
+ GVariant *s_ip6;
+ char *gateway = NULL;
+
+ s_ip6 = g_variant_lookup_value (connection_dict, NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_VARIANT_TYPE_SETTING);
+ /* If 'address-data' is set then ignore 'addresses' */
+ if (g_variant_lookup (s_ip6, "address-data", "aa{sv}", NULL)) {
+ g_variant_unref (s_ip6);
+ return;
+ }
+
+ addrs = nm_utils_ip6_addresses_from_variant (value, &gateway);
- g_free (priv->method);
- g_free (priv->dhcp_hostname);
+ if (gateway && !g_variant_lookup (s_ip6, "gateway", "s", NULL)) {
+ g_object_set (setting,
+ NM_SETTING_IP_CONFIG_GATEWAY, gateway,
+ NULL);
+ }
+ g_free (gateway);
- g_slist_free_full (priv->dns, g_free);
- g_slist_free_full (priv->dns_search, g_free);
- g_slist_free_full (priv->addresses, g_free);
- g_slist_free_full (priv->routes, g_free);
+ g_variant_unref (s_ip6);
- G_OBJECT_CLASS (nm_setting_ip6_config_parent_class)->finalize (object);
+ g_object_set (setting, property, addrs, NULL);
+ g_ptr_array_unref (addrs);
}
static GVariant *
-ip6_dns_to_dbus (const GValue *prop_value)
+ip6_address_data_get (NMSetting *setting,
+ NMConnection *connection,
+ const char *property)
{
- return nm_utils_ip6_dns_to_variant (g_value_get_boxed (prop_value));
+ GPtrArray *addrs;
+ GVariant *ret;
+
+ g_object_get (setting, NM_SETTING_IP_CONFIG_ADDRESSES, &addrs, NULL);
+ ret = nm_utils_ip_addresses_to_variant (addrs);
+ g_ptr_array_unref (addrs);
+
+ return ret;
}
static void
-ip6_dns_from_dbus (GVariant *dbus_value,
- GValue *prop_value)
+ip6_address_data_set (NMSetting *setting,
+ GVariant *connection_dict,
+ const char *property,
+ GVariant *value)
{
- g_value_take_boxed (prop_value, nm_utils_ip6_dns_from_variant (dbus_value));
+ GPtrArray *addrs;
+
+ addrs = nm_utils_ip_addresses_from_variant (value, AF_INET6);
+ g_object_set (setting, NM_SETTING_IP_CONFIG_ADDRESSES, addrs, NULL);
+ g_ptr_array_unref (addrs);
}
static GVariant *
-ip6_addresses_to_dbus (const GValue *prop_value)
+ip6_routes_get (NMSetting *setting,
+ const char *property)
{
- return nm_utils_ip6_addresses_to_variant (g_value_get_boxed (prop_value));
+ GPtrArray *routes;
+ GVariant *ret;
+
+ g_object_get (setting, property, &routes, NULL);
+ ret = nm_utils_ip6_routes_to_variant (routes);
+ g_ptr_array_unref (routes);
+
+ return ret;
}
static void
-ip6_addresses_from_dbus (GVariant *dbus_value,
- GValue *prop_value)
-{
- g_value_take_boxed (prop_value, nm_utils_ip6_addresses_from_variant (dbus_value));
+ip6_routes_set (NMSetting *setting,
+ GVariant *connection_dict,
+ const char *property,
+ GVariant *value)
+{
+ GPtrArray *routes;
+ GVariant *s_ip6;
+
+ s_ip6 = g_variant_lookup_value (connection_dict, NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_VARIANT_TYPE_SETTING);
+ /* If 'route-data' is set then ignore 'routes' */
+ if (g_variant_lookup (s_ip6, "route-data", "aa{sv}", NULL)) {
+ g_variant_unref (s_ip6);
+ return;
+ }
+ g_variant_unref (s_ip6);
+
+ routes = nm_utils_ip6_routes_from_variant (value);
+ g_object_set (setting, property, routes, NULL);
+ g_ptr_array_unref (routes);
}
static GVariant *
-ip6_routes_to_dbus (const GValue *prop_value)
+ip6_route_data_get (NMSetting *setting,
+ NMConnection *connection,
+ const char *property)
{
- return nm_utils_ip6_routes_to_variant (g_value_get_boxed (prop_value));
+ GPtrArray *routes;
+ GVariant *ret;
+
+ g_object_get (setting, NM_SETTING_IP_CONFIG_ROUTES, &routes, NULL);
+ ret = nm_utils_ip_routes_to_variant (routes);
+ g_ptr_array_unref (routes);
+
+ return ret;
}
static void
-ip6_routes_from_dbus (GVariant *dbus_value,
- GValue *prop_value)
+ip6_route_data_set (NMSetting *setting,
+ GVariant *connection_dict,
+ const char *property,
+ GVariant *value)
{
- g_value_take_boxed (prop_value, nm_utils_ip6_routes_from_variant (dbus_value));
+ GPtrArray *routes;
+
+ routes = nm_utils_ip_routes_from_variant (value, AF_INET6);
+ g_object_set (setting, NM_SETTING_IP_CONFIG_ROUTES, routes, NULL);
+ g_ptr_array_unref (routes);
}
static void
@@ -951,44 +335,6 @@ set_property (GObject *object, guint prop_id,
NMSettingIP6ConfigPrivate *priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (object);
switch (prop_id) {
- case PROP_METHOD:
- g_free (priv->method);
- priv->method = g_value_dup_string (value);
- break;
- case PROP_DNS:
- g_slist_free_full (priv->dns, g_free);
- priv->dns = _nm_utils_strv_to_slist (g_value_get_boxed (value));
- break;
- case PROP_DNS_SEARCH:
- g_slist_free_full (priv->dns_search, g_free);
- priv->dns_search = _nm_utils_strv_to_slist (g_value_get_boxed (value));
- break;
- case PROP_ADDRESSES:
- g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_address_unref);
- priv->addresses = _nm_utils_copy_array_to_slist (g_value_get_boxed (value),
- (NMUtilsCopyFunc) nm_ip6_address_dup);
- break;
- case PROP_ROUTES:
- g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_route_unref);
- priv->routes = _nm_utils_copy_array_to_slist (g_value_get_boxed (value),
- (NMUtilsCopyFunc) nm_ip6_route_dup);
- 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_DHCP_HOSTNAME:
- g_free (priv->dhcp_hostname);
- priv->dhcp_hostname = g_value_dup_string (value);
- break;
- case PROP_NEVER_DEFAULT:
- priv->never_default = g_value_get_boolean (value);
- break;
- case PROP_MAY_FAIL:
- priv->may_fail = g_value_get_boolean (value);
- break;
case PROP_IP6_PRIVACY:
priv->ip6_privacy = g_value_get_enum (value);
break;
@@ -1005,36 +351,6 @@ get_property (GObject *object, guint prop_id,
NMSettingIP6ConfigPrivate *priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (object);
switch (prop_id) {
- case PROP_METHOD:
- g_value_set_string (value, priv->method);
- break;
- case PROP_DNS:
- g_value_take_boxed (value, _nm_utils_slist_to_strv (priv->dns));
- break;
- case PROP_DNS_SEARCH:
- g_value_take_boxed (value, _nm_utils_slist_to_strv (priv->dns_search));
- break;
- case PROP_ADDRESSES:
- g_value_take_boxed (value, _nm_utils_copy_slist_to_array (priv->addresses, (NMUtilsCopyFunc) nm_ip6_address_dup, (GDestroyNotify) nm_ip6_address_unref));
- break;
- case PROP_ROUTES:
- g_value_take_boxed (value, _nm_utils_copy_slist_to_array (priv->routes, (NMUtilsCopyFunc) nm_ip6_route_dup, (GDestroyNotify) nm_ip6_route_unref));
- 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_DHCP_HOSTNAME:
- g_value_set_string (value, priv->dhcp_hostname);
- break;
- case PROP_NEVER_DEFAULT:
- g_value_set_boolean (value, priv->never_default);
- break;
- case PROP_MAY_FAIL:
- g_value_set_boolean (value, priv->may_fail);
- break;
case PROP_IP6_PRIVACY:
g_value_set_enum (value, priv->ip6_privacy);
break;
@@ -1045,201 +361,20 @@ get_property (GObject *object, guint prop_id,
}
static void
-nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *setting_class)
+nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *ip6_class)
{
- GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
- NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
+ GObjectClass *object_class = G_OBJECT_CLASS (ip6_class);
+ NMSettingClass *setting_class = NM_SETTING_CLASS (ip6_class);
- g_type_class_add_private (setting_class, sizeof (NMSettingIP6ConfigPrivate));
+ g_type_class_add_private (ip6_class, sizeof (NMSettingIP6ConfigPrivate));
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
- object_class->finalize = finalize;
- parent_class->verify = verify;
+ setting_class->verify = verify;
/* Properties */
/**
- * NMSettingIP6Config:method:
- *
- * IPv6 configuration method. If "auto" is specified then the appropriate
- * automatic method (PPP, router advertisement, etc) is used for the device
- * and most other properties can be left unset. To force the use of DHCP
- * only, specify "dhcp"; this method is only valid for Ethernet- based
- * hardware. If "link-local" is specified, then an IPv6 link-local address
- * will be assigned to the interface. If "manual" is specified, static IP
- * addressing is used and at least one IP address must be given in the
- * "addresses" property. If "ignore" is specified, IPv6 configuration is
- * not done. This property must be set. Note: the "shared" method is not
- * yet supported.
- **/
- g_object_class_install_property
- (object_class, PROP_METHOD,
- g_param_spec_string (NM_SETTING_IP6_CONFIG_METHOD, "", "",
- NULL,
- G_PARAM_READWRITE |
- NM_SETTING_PARAM_INFERRABLE |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMSettingIP6Config:dhcp-hostname:
- *
- * The specified name will be sent to the DHCP server when acquiring a
- * lease.
- **/
- g_object_class_install_property
- (object_class, PROP_DHCP_HOSTNAME,
- g_param_spec_string (NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME, "", "",
- NULL,
- G_PARAM_READWRITE |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMSettingIP6Config:dns:
- *
- * Array of IPv6 addresses of DNS servers. For the "auto" method, these DNS
- * servers are appended to those (if any) returned by automatic
- * configuration. DNS servers cannot be used with the "shared" or
- * "link-local" methods as there is no usptream network. In all other
- * methods, these DNS servers are used as the only DNS servers for this
- * connection.
- **/
- g_object_class_install_property
- (object_class, PROP_DNS,
- g_param_spec_boxed (NM_SETTING_IP6_CONFIG_DNS, "", "",
- G_TYPE_STRV,
- G_PARAM_READWRITE |
- G_PARAM_STATIC_STRINGS));
- _nm_setting_class_transform_property (parent_class, NM_SETTING_IP6_CONFIG_DNS,
- G_VARIANT_TYPE ("aay"),
- ip6_dns_to_dbus,
- ip6_dns_from_dbus);
-
- /**
- * NMSettingIP6Config:dns-search:
- *
- * List of DNS search domains. For the "auto" method, these search domains
- * are appended to those returned by automatic configuration. Search domains
- * cannot be used with the "shared" or "link-local" methods as there is no
- * upstream network. In all other methods, these search domains are used as
- * the only search domains for this connection.
- **/
- g_object_class_install_property
- (object_class, PROP_DNS_SEARCH,
- g_param_spec_boxed (NM_SETTING_IP6_CONFIG_DNS_SEARCH, "", "",
- G_TYPE_STRV,
- G_PARAM_READWRITE |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMSettingIP6Config:addresses:
- *
- * Array of IPv6 addresses. For the 'auto' method, given IP addresses are
- * appended to those returned by automatic configuration. Addresses cannot
- * be used with the 'shared' or 'link-local' methods as the interface is
- * automatically assigned an address with these methods.
- *
- * Element-Type: NMIP6Address
- **/
- g_object_class_install_property
- (object_class, PROP_ADDRESSES,
- g_param_spec_boxed (NM_SETTING_IP6_CONFIG_ADDRESSES, "", "",
- G_TYPE_PTR_ARRAY,
- G_PARAM_READWRITE |
- NM_SETTING_PARAM_INFERRABLE |
- G_PARAM_STATIC_STRINGS));
- _nm_setting_class_transform_property (parent_class, NM_SETTING_IP6_CONFIG_ADDRESSES,
- G_VARIANT_TYPE ("a(ayuay)"),
- ip6_addresses_to_dbus,
- ip6_addresses_from_dbus);
-
- /**
- * NMSettingIP6Config:routes:
- *
- * Array of IPv6 routes. For the 'auto' method, given IP routes are appended
- * to those returned by automatic configuration. Routes cannot be used with
- * the 'shared' or 'link-local' methods because there is no upstream network.
- *
- * Element-Type: NMIP6Route
- **/
- g_object_class_install_property
- (object_class, PROP_ROUTES,
- g_param_spec_boxed (NM_SETTING_IP6_CONFIG_ROUTES, "", "",
- G_TYPE_PTR_ARRAY,
- G_PARAM_READWRITE |
- NM_SETTING_PARAM_INFERRABLE |
- G_PARAM_STATIC_STRINGS));
- _nm_setting_class_transform_property (parent_class, NM_SETTING_IP6_CONFIG_ROUTES,
- G_VARIANT_TYPE ("a(ayuayu)"),
- ip6_routes_to_dbus,
- ip6_routes_from_dbus);
-
- /**
- * NMSettingIP6Config:ignore-auto-routes:
- *
- * When the method is set to "auto" or "dhcp" and this property is set to
- * %TRUE, automatically configured routes are ignored and only routes
- * specified in the #NMSettingIP6Config:routes property, if any, are used.
- **/
- g_object_class_install_property
- (object_class, PROP_IGNORE_AUTO_ROUTES,
- g_param_spec_boolean (NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES, "", "",
- FALSE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMSettingIP6Config:ignore-auto-dns:
- *
- * When the method is set to "auto" or "dhcp" and this property is set to
- * %TRUE, automatically configured nameservers and search domains are
- * ignored and only nameservers and search domains specified in the
- * #NMSettingIP6Config:dns and #NMSettingIP6Config:dns-search properties, if
- * any, are used.
- **/
- g_object_class_install_property
- (object_class, PROP_IGNORE_AUTO_DNS,
- g_param_spec_boolean (NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS, "", "",
- FALSE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMSettingIP6Config:never-default:
- *
- * If %TRUE, this connection will never be the default IPv6 connection,
- * meaning it will never be assigned the default IPv6 route by
- * NetworkManager.
- **/
- g_object_class_install_property
- (object_class, PROP_NEVER_DEFAULT,
- g_param_spec_boolean (NM_SETTING_IP6_CONFIG_NEVER_DEFAULT, "", "",
- FALSE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMSettingIP6Config:may-fail:
- *
- * If %TRUE, allow overall network configuration to proceed even if IPv6
- * configuration times out. Note that at least one IP configuration must
- * succeed or overall network configuration will still fail. For example,
- * in IPv4-only networks, setting this property to %TRUE allows the overall
- * network configuration to succeed if IPv6 configuration fails but IPv4
- * configuration completes successfully.
- **/
- g_object_class_install_property
- (object_class, PROP_MAY_FAIL,
- g_param_spec_boolean (NM_SETTING_IP6_CONFIG_MAY_FAIL, "", "",
- TRUE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS));
-
- /**
* NMSettingIP6Config:ip6-privacy:
*
* Configure IPv6 Privacy Extensions for SLAAC, described in RFC4941. If
@@ -1258,473 +393,37 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *setting_class)
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
-}
-
-/********************************************************************/
-
-struct NMIP6Address {
- guint32 refcount;
- struct in6_addr address;
- guint32 prefix;
- struct in6_addr gateway;
-};
-
-/**
- * nm_ip6_address_new:
- *
- * Creates and returns a new #NMIP6Address object.
- *
- * Returns: (transfer full): the new empty #NMIP6Address object
- **/
-NMIP6Address *
-nm_ip6_address_new (void)
-{
- NMIP6Address *address;
-
- address = g_malloc0 (sizeof (NMIP6Address));
- address->refcount = 1;
- return address;
-}
-
-/**
- * nm_ip6_address_dup:
- * @source: the #NMIP6Address object to copy
- *
- * Copies a given #NMIP6Address object and returns the copy.
- *
- * Returns: (transfer full): the copy of the given #NMIP6Address copy
- **/
-NMIP6Address *
-nm_ip6_address_dup (NMIP6Address *source)
-{
- NMIP6Address *address;
-
- g_return_val_if_fail (source != NULL, NULL);
- g_return_val_if_fail (source->refcount > 0, NULL);
-
- address = nm_ip6_address_new ();
- address->prefix = source->prefix;
- memcpy (&address->address, &source->address, sizeof (struct in6_addr));
- memcpy (&address->gateway, &source->gateway, sizeof (struct in6_addr));
-
- return address;
-}
-
-/**
- * nm_ip6_address_ref:
- * @address: the #NMIP6Address
- *
- * Increases the reference count of the object.
- **/
-void
-nm_ip6_address_ref (NMIP6Address *address)
-{
- g_return_if_fail (address != NULL);
- g_return_if_fail (address->refcount > 0);
-
- address->refcount++;
-}
-
-/**
- * nm_ip6_address_unref:
- * @address: the #NMIP6Address
- *
- * Decreases the reference count of the object. If the reference count
- * reaches zero, the object will be destroyed.
- **/
-void
-nm_ip6_address_unref (NMIP6Address *address)
-{
- g_return_if_fail (address != NULL);
- g_return_if_fail (address->refcount > 0);
-
- address->refcount--;
- if (address->refcount == 0) {
- memset (address, 0, sizeof (NMIP6Address));
- g_free (address);
- }
-}
-
-/**
- * nm_ip6_address_compare:
- * @address: the #NMIP6Address
- * @other: the #NMIP6Address to compare @address to.
- *
- * Determines if two #NMIP6Address objects contain the same values.
- *
- * Returns: %TRUE if the objects contain the same values, %FALSE if they do not.
- **/
-gboolean
-nm_ip6_address_compare (NMIP6Address *address, NMIP6Address *other)
-{
- g_return_val_if_fail (address != NULL, FALSE);
- g_return_val_if_fail (address->refcount > 0, FALSE);
-
- 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)))
- return FALSE;
- return TRUE;
-}
-
-/**
- * nm_ip6_address_get_address:
- * @address: the #NMIP6Address
- *
- * Gets the IPv6 address property of this address object.
- *
- * Returns: (array fixed-size=16) (element-type guint8) (transfer none):
- * the IPv6 address
- **/
-const struct in6_addr *
-nm_ip6_address_get_address (NMIP6Address *address)
-{
- g_return_val_if_fail (address != NULL, NULL);
- g_return_val_if_fail (address->refcount > 0, NULL);
-
- return &address->address;
-}
-
-/**
- * nm_ip6_address_set_address:
- * @address: the #NMIP6Address
- * @addr: the IPv6 address
- *
- * Sets the IPv6 address property of this object.
- **/
-void
-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);
-
- memcpy (&address->address, addr, sizeof (struct in6_addr));
-}
-
-/**
- * nm_ip6_address_get_prefix:
- * @address: the #NMIP6Address
- *
- * Gets the IPv6 address prefix property of this address object.
- *
- * Returns: the IPv6 address prefix
- **/
-guint32
-nm_ip6_address_get_prefix (NMIP6Address *address)
-{
- g_return_val_if_fail (address != NULL, 0);
- g_return_val_if_fail (address->refcount > 0, 0);
-
- return address->prefix;
-}
-
-/**
- * nm_ip6_address_set_prefix:
- * @address: the #NMIP6Address
- * @prefix: the address prefix, a number between 0 and 128 inclusive
- *
- * Sets the IPv6 address prefix.
- **/
-void
-nm_ip6_address_set_prefix (NMIP6Address *address, guint32 prefix)
-{
- g_return_if_fail (address != NULL);
- g_return_if_fail (address->refcount > 0);
- g_return_if_fail (prefix <= 128);
- g_return_if_fail (prefix > 0);
-
- address->prefix = prefix;
-}
-
-/**
- * nm_ip6_address_get_gateway:
- * @address: the #NMIP6Address
- *
- * Gets the IPv6 default gateway property of this address object.
- *
- * Returns: (array fixed-size=16) (element-type guint8) (transfer none):
- * the IPv6 gateway address
- **/
-const struct in6_addr *
-nm_ip6_address_get_gateway (NMIP6Address *address)
-{
- g_return_val_if_fail (address != NULL, NULL);
- g_return_val_if_fail (address->refcount > 0, NULL);
-
- return &address->gateway;
-}
-
-/**
- * nm_ip6_address_set_gateway:
- * @address: the #NMIP6Address
- * @gateway: the IPv6 default gateway
- *
- * Sets the IPv6 default gateway property of this address object.
- **/
-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_return_if_fail (gateway != NULL);
-
- memcpy (&address->gateway, gateway, sizeof (struct in6_addr));
-}
-
-/********************************************************************/
-
-struct NMIP6Route {
- guint32 refcount;
-
- struct in6_addr dest;
- guint32 prefix;
- struct in6_addr next_hop;
- guint32 metric; /* lower metric == more preferred */
-};
-
-/**
- * nm_ip6_route_new:
- *
- * Creates and returns a new #NMIP6Route object.
- *
- * Returns: (transfer full): the new empty #NMIP6Route object
- **/
-NMIP6Route *
-nm_ip6_route_new (void)
-{
- NMIP6Route *route;
-
- route = g_malloc0 (sizeof (NMIP6Route));
- route->refcount = 1;
- return route;
-}
-
-/**
- * nm_ip6_route_dup:
- * @source: the #NMIP6Route object to copy
- *
- * Copies a given #NMIP6Route object and returns the copy.
- *
- * Returns: (transfer full): the copy of the given #NMIP6Route copy
- **/
-NMIP6Route *
-nm_ip6_route_dup (NMIP6Route *source)
-{
- NMIP6Route *route;
-
- g_return_val_if_fail (source != NULL, NULL);
- g_return_val_if_fail (source->refcount > 0, NULL);
-
- route = nm_ip6_route_new ();
- route->prefix = source->prefix;
- route->metric = source->metric;
- memcpy (&route->dest, &source->dest, sizeof (struct in6_addr));
- memcpy (&route->next_hop, &source->next_hop, sizeof (struct in6_addr));
-
- return route;
-}
-
-/**
- * nm_ip6_route_ref:
- * @route: the #NMIP6Route
- *
- * Increases the reference count of the object.
- **/
-void
-nm_ip6_route_ref (NMIP6Route *route)
-{
- g_return_if_fail (route != NULL);
- g_return_if_fail (route->refcount > 0);
- route->refcount++;
-}
-
-/**
- * nm_ip6_route_unref:
- * @route: the #NMIP6Route
- *
- * Decreases the reference count of the object. If the reference count
- * reaches zero, the object will be destroyed.
- **/
-void
-nm_ip6_route_unref (NMIP6Route *route)
-{
- g_return_if_fail (route != NULL);
- g_return_if_fail (route->refcount > 0);
-
- route->refcount--;
- if (route->refcount == 0) {
- memset (route, 0, sizeof (NMIP6Route));
- g_free (route);
- }
-}
-
-/**
- * nm_ip6_route_compare:
- * @route: the #NMIP6Route
- * @other: the #NMIP6Route to compare @route to.
- *
- * Determines if two #NMIP6Route objects contain the same values.
- *
- * Returns: %TRUE if the objects contain the same values, %FALSE if they do not.
- **/
-gboolean
-nm_ip6_route_compare (NMIP6Route *route, NMIP6Route *other)
-{
- g_return_val_if_fail (route != NULL, FALSE);
- g_return_val_if_fail (route->refcount > 0, FALSE);
-
- 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))
- || route->prefix != other->prefix
- || memcmp (&route->next_hop, &other->next_hop, sizeof (struct in6_addr))
- || route->metric != other->metric)
- return FALSE;
- return TRUE;
-}
-
-/**
- * nm_ip6_route_get_dest:
- * @route: the #NMIP6Route
- *
- * Gets the IPv6 destination address property of this route object.
- *
- * Returns: (array fixed-size=16) (element-type guint8) (transfer none):
- * the IPv6 address of destination
- **/
-const struct in6_addr *
-nm_ip6_route_get_dest (NMIP6Route *route)
-{
- g_return_val_if_fail (route != NULL, NULL);
- g_return_val_if_fail (route->refcount > 0, NULL);
-
- return &route->dest;
-}
-
-/**
- * nm_ip6_route_set_dest:
- * @route: the #NMIP6Route
- * @dest: the destination address
- *
- * Sets the IPv6 destination address property of this route object.
- **/
-void
-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);
-
- memcpy (&route->dest, dest, sizeof (struct in6_addr));
-}
-
-/**
- * nm_ip6_route_get_prefix:
- * @route: the #NMIP6Route
- *
- * Gets the IPv6 prefix (ie "32" or "64" etc) of this route.
- *
- * Returns: the IPv6 prefix
- **/
-guint32
-nm_ip6_route_get_prefix (NMIP6Route *route)
-{
- g_return_val_if_fail (route != NULL, 0);
- g_return_val_if_fail (route->refcount > 0, 0);
-
- return route->prefix;
-}
-
-/**
- * nm_ip6_route_set_prefix:
- * @route: the #NMIP6Route
- * @prefix: the prefix, a number between 1 and 128 inclusive
- *
- * Sets the IPv6 prefix of this route.
- **/
-void
-nm_ip6_route_set_prefix (NMIP6Route *route, guint32 prefix)
-{
- g_return_if_fail (route != NULL);
- g_return_if_fail (route->refcount > 0);
- g_return_if_fail (prefix <= 128);
- g_return_if_fail (prefix > 0);
-
- route->prefix = prefix;
-}
-
-/**
- * nm_ip6_route_get_next_hop:
- * @route: the #NMIP6Route
- *
- * Gets the IPv6 address of the next hop of this route.
- *
- * Returns: (array fixed-size=16) (element-type guint8) (transfer none):
- * the IPv6 address of next hop
- **/
-const struct in6_addr *
-nm_ip6_route_get_next_hop (NMIP6Route *route)
-{
- g_return_val_if_fail (route != NULL, NULL);
- g_return_val_if_fail (route->refcount > 0, NULL);
-
- return &route->next_hop;
-}
-
-/**
- * nm_ip6_route_set_next_hop:
- * @route: the #NMIP6Route
- * @next_hop: the IPv6 address of the next hop
- *
- * Sets the IPv6 address of the next hop of this route.
- **/
-void
-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);
-
- memcpy (&route->next_hop, next_hop, sizeof (struct in6_addr));
-}
-
-/**
- * nm_ip6_route_get_metric:
- * @route: the #NMIP6Route
- *
- * Gets the route metric property of this route object; lower values indicate
- * "better" or more preferred routes.
- *
- * Returns: the route metric
- **/
-guint32
-nm_ip6_route_get_metric (NMIP6Route *route)
-{
- g_return_val_if_fail (route != NULL, 0);
- g_return_val_if_fail (route->refcount > 0, 0);
-
- return route->metric;
-}
-
-/**
- * nm_ip6_route_set_metric:
- * @route: the #NMIP6Route
- * @metric: the route metric
- *
- * Sets the route metric property of this route object; lower values indicate
- * "better" or more preferred routes.
- **/
-void
-nm_ip6_route_set_metric (NMIP6Route *route, guint32 metric)
-{
- g_return_if_fail (route != NULL);
- g_return_if_fail (route->refcount > 0);
+ /* IP6-specific property overrides */
+ _nm_setting_class_transform_property (setting_class,
+ NM_SETTING_IP_CONFIG_DNS,
+ G_VARIANT_TYPE ("aay"),
+ ip6_dns_to_dbus,
+ ip6_dns_from_dbus);
- route->metric = metric;
+ _nm_setting_class_override_property (setting_class,
+ NM_SETTING_IP_CONFIG_ADDRESSES,
+ G_VARIANT_TYPE ("a(ayuay)"),
+ ip6_addresses_get,
+ ip6_addresses_set,
+ NULL);
+
+ _nm_setting_class_add_dbus_only_property (setting_class,
+ "address-data",
+ G_VARIANT_TYPE ("aa{sv}"),
+ ip6_address_data_get,
+ ip6_address_data_set);
+
+ _nm_setting_class_override_property (setting_class,
+ NM_SETTING_IP_CONFIG_ROUTES,
+ G_VARIANT_TYPE ("a(ayuayu)"),
+ ip6_routes_get,
+ ip6_routes_set,
+ NULL);
+
+ _nm_setting_class_add_dbus_only_property (setting_class,
+ "route-data",
+ G_VARIANT_TYPE ("aa{sv}"),
+ ip6_route_data_get,
+ ip6_route_data_set);
}
diff --git a/libnm-core/nm-setting-ip6-config.h b/libnm-core/nm-setting-ip6-config.h
index 831f212bb6..b791e937b4 100644
--- a/libnm-core/nm-setting-ip6-config.h
+++ b/libnm-core/nm-setting-ip6-config.h
@@ -26,9 +26,7 @@
#error "Only <NetworkManager.h> can be included directly."
#endif
-#include <arpa/inet.h>
-
-#include "nm-setting.h"
+#include "nm-setting-ip-config.h"
G_BEGIN_DECLS
@@ -41,18 +39,7 @@ G_BEGIN_DECLS
#define NM_SETTING_IP6_CONFIG_SETTING_NAME "ipv6"
-#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_MAY_FAIL "may-fail"
-#define NM_SETTING_IP6_CONFIG_IP6_PRIVACY "ip6-privacy"
-#define NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME "dhcp-hostname"
-
+#define NM_SETTING_IP6_CONFIG_IP6_PRIVACY "ip6-privacy"
/**
* NM_SETTING_IP6_CONFIG_METHOD_IGNORE:
@@ -127,63 +114,12 @@ typedef enum {
NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR = 2
} NMSettingIP6ConfigPrivacy;
-
-typedef struct NMIP6Address NMIP6Address;
-
-GType nm_ip6_address_get_type (void);
-
-NMIP6Address * nm_ip6_address_new (void);
-NMIP6Address * nm_ip6_address_dup (NMIP6Address *source);
-void nm_ip6_address_ref (NMIP6Address *address);
-void nm_ip6_address_unref (NMIP6Address *address);
-/* Return TRUE if addresses are identical */
-gboolean nm_ip6_address_compare (NMIP6Address *address, NMIP6Address *other);
-
-const struct in6_addr *nm_ip6_address_get_address (NMIP6Address *address);
-void nm_ip6_address_set_address (NMIP6Address *address,
- 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 *gateway);
-
-typedef struct NMIP6Route NMIP6Route;
-
-GType nm_ip6_route_get_type (void);
-
-NMIP6Route * nm_ip6_route_new (void);
-NMIP6Route * nm_ip6_route_dup (NMIP6Route *source);
-void nm_ip6_route_ref (NMIP6Route *route);
-void nm_ip6_route_unref (NMIP6Route *route);
-/* Return TRUE if routes are identical */
-gboolean nm_ip6_route_compare (NMIP6Route *route, NMIP6Route *other);
-
-const struct in6_addr *nm_ip6_route_get_dest (NMIP6Route *route);
-void nm_ip6_route_set_dest (NMIP6Route *route,
- const struct in6_addr *dest);
-
-guint32 nm_ip6_route_get_prefix (NMIP6Route *route);
-void nm_ip6_route_set_prefix (NMIP6Route *route,
- guint32 prefix);
-
-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);
-
-guint32 nm_ip6_route_get_metric (NMIP6Route *route);
-void nm_ip6_route_set_metric (NMIP6Route *route,
- guint32 metric);
-
struct _NMSettingIP6Config {
- NMSetting parent;
+ NMSettingIPConfig parent;
};
typedef struct {
- NMSettingClass parent;
+ NMSettingIPConfigClass parent;
/*< private >*/
gpointer padding[4];
@@ -191,42 +127,8 @@ typedef struct {
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 char * nm_setting_ip6_config_get_dns (NMSettingIP6Config *setting, guint32 i);
-gboolean nm_setting_ip6_config_add_dns (NMSettingIP6Config *setting, const char *dns);
-void nm_setting_ip6_config_remove_dns (NMSettingIP6Config *setting, guint32 i);
-gboolean nm_setting_ip6_config_remove_dns_by_value (NMSettingIP6Config *setting, const char *dns);
-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);
-gboolean nm_setting_ip6_config_remove_dns_search_by_value (NMSettingIP6Config *setting, const char *dns_search);
-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);
-gboolean nm_setting_ip6_config_remove_address_by_value (NMSettingIP6Config *setting, NMIP6Address *address);
-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);
-gboolean nm_setting_ip6_config_remove_route_by_value (NMSettingIP6Config *setting, NMIP6Route *route);
-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);
-const char * nm_setting_ip6_config_get_dhcp_hostname (NMSettingIP6Config *setting);
-gboolean nm_setting_ip6_config_get_never_default (NMSettingIP6Config *setting);
-gboolean nm_setting_ip6_config_get_may_fail (NMSettingIP6Config *setting);
+NMSetting *nm_setting_ip6_config_new (void);
+
NMSettingIP6ConfigPrivacy nm_setting_ip6_config_get_ip6_privacy (NMSettingIP6Config *setting);
G_END_DECLS
diff --git a/libnm-core/nm-setting-private.h b/libnm-core/nm-setting-private.h
index 56c4f46c48..bb9f1d8ee1 100644
--- a/libnm-core/nm-setting-private.h
+++ b/libnm-core/nm-setting-private.h
@@ -111,6 +111,8 @@ NMSetting *_nm_setting_new_from_dbus (GType setting_type,
GError **error);
typedef GVariant * (*NMSettingPropertyGetFunc) (NMSetting *setting,
+ const char *property);
+typedef GVariant * (*NMSettingPropertySynthFunc) (NMSetting *setting,
NMConnection *connection,
const char *property);
typedef void (*NMSettingPropertySetFunc) (NMSetting *setting,
@@ -124,7 +126,7 @@ typedef void (*NMSettingPropertyNotSetFunc) (NMSetting *setting,
void _nm_setting_class_add_dbus_only_property (NMSettingClass *setting_class,
const char *property_name,
const GVariantType *dbus_type,
- NMSettingPropertyGetFunc get_func,
+ NMSettingPropertySynthFunc synth_func,
NMSettingPropertySetFunc set_func);
void _nm_setting_class_override_property (NMSettingClass *setting_class,
diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c
index 645d8d3a8f..f8fb3e95ef 100644
--- a/libnm-core/nm-setting.c
+++ b/libnm-core/nm-setting.c
@@ -291,6 +291,7 @@ typedef struct {
const GVariantType *dbus_type;
NMSettingPropertyGetFunc get_func;
+ NMSettingPropertySynthFunc synth_func;
NMSettingPropertySetFunc set_func;
NMSettingPropertyNotSetFunc not_set_func;
@@ -325,6 +326,7 @@ add_property_override (NMSettingClass *setting_class,
GParamSpec *param_spec,
const GVariantType *dbus_type,
NMSettingPropertyGetFunc get_func,
+ NMSettingPropertySynthFunc synth_func,
NMSettingPropertySetFunc set_func,
NMSettingPropertyNotSetFunc not_set_func,
NMSettingPropertyTransformToFunc to_dbus,
@@ -341,6 +343,7 @@ add_property_override (NMSettingClass *setting_class,
override.param_spec = param_spec;
override.dbus_type = dbus_type;
override.get_func = get_func;
+ override.synth_func = synth_func;
override.set_func = set_func;
override.not_set_func = not_set_func;
override.to_dbus = to_dbus;
@@ -361,30 +364,27 @@ add_property_override (NMSettingClass *setting_class,
* @setting_class: the setting class
* @property_name: the name of the property to override
* @dbus_type: the type of the property (in its D-Bus representation)
- * @get_func: (allow-none): function to call to get the value of the property
+ * @synth_func: (allow-none): function to call to synthesize a value for the property
* @set_func: (allow-none): function to call to set the value of the property
*
* Registers a property named @property_name, which will be used in the D-Bus
* serialization of objects of @setting_class, but which does not correspond to
* a #GObject property.
*
- * When serializing a setting to D-Bus, @get_func will be called to get the
- * property's value. (If it returns %NULL, no value will be added to the
- * serialization. If @get_func is %NULL, the property will always be omitted in
- * the serialization.)
+ * When serializing a setting to D-Bus, @synth_func will be called to synthesize
+ * a value for the property. (If it returns %NULL, no value will be added to the
+ * serialization. If @synth_func is %NULL, the property will always be omitted
+ * in the serialization.)
*
* When deserializing a D-Bus representation into a setting, if @property_name
- * is present, then @set_func will be called to set (and/or verify) it. If it
- * returns %TRUE, the value is considered to have been successfully set; if it
- * returns %FALSE then the deserializing operation as a whole will fail with the
- * returned #GError. (If @set_func is %NULL then the property will be ignored
- * when deserializing.)
+ * is present, then @set_func will be called to set it. (If @set_func is %NULL
+ * then the property will be ignored when deserializing.)
*/
void
_nm_setting_class_add_dbus_only_property (NMSettingClass *setting_class,
const char *property_name,
const GVariantType *dbus_type,
- NMSettingPropertyGetFunc get_func,
+ NMSettingPropertySynthFunc synth_func,
NMSettingPropertySetFunc set_func)
{
g_return_if_fail (NM_IS_SETTING_CLASS (setting_class));
@@ -395,7 +395,7 @@ _nm_setting_class_add_dbus_only_property (NMSettingClass *setting_class,
add_property_override (setting_class,
property_name, NULL, dbus_type,
- get_func, set_func, NULL,
+ NULL, synth_func, set_func, NULL,
NULL, NULL);
}
@@ -412,17 +412,15 @@ _nm_setting_class_add_dbus_only_property (NMSettingClass *setting_class,
* @property_name on @setting_class.
*
* When serializing a setting to D-Bus, if @get_func is non-%NULL, then it will
- * be called to get the property's value. If it returns %TRUE, the value will be
- * added to the hash, and if %FALSE, it will not. (If @get_func is %NULL, the
- * property will be read normally with g_object_get_property(), and added to the
- * hash if it is not the default value.)
+ * be called to get the property's value. If it returns a #GVariant, the
+ * property will be added to the hash, and if it returns %NULL, the property
+ * will be omitted. (If @get_func is %NULL, the property will be read normally
+ * with g_object_get_property(), and added to the hash if it is not the default
+ * value.)
*
* When deserializing a D-Bus representation into a setting, if @property_name
- * is present, then @set_func will be called to set (and/or verify) it. If it
- * returns %TRUE, the value is considered to have been successfully set; if it
- * returns %FALSE then the deserializing operation as a whole will fail with the
- * returned #GError. (If @set_func is %NULL then the property will be set normally
- * with g_object_set_property().)
+ * is present, then @set_func will be called to set it. (If @set_func is %NULL
+ * then the property will be set normally with g_object_set_property().)
*
* If @not_set_func is non-%NULL, then it will be called when deserializing a
* representation that does NOT contain @property_name. This can be used, eg, if
@@ -444,7 +442,7 @@ _nm_setting_class_override_property (NMSettingClass *setting_class,
add_property_override (setting_class,
property_name, param_spec, dbus_type,
- get_func, set_func, not_set_func,
+ get_func, NULL, set_func, not_set_func,
NULL, NULL);
}
@@ -478,7 +476,7 @@ _nm_setting_class_transform_property (NMSettingClass *setting_class,
add_property_override (setting_class,
property, param_spec, dbus_type,
- NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
to_dbus, from_dbus);
}
@@ -588,7 +586,10 @@ get_property_for_dbus (NMSetting *setting,
GValue prop_value = { 0, };
GVariant *dbus_value;
- g_return_val_if_fail (property->param_spec != NULL, NULL);
+ if (property->get_func)
+ return property->get_func (setting, property->name);
+ else
+ g_return_val_if_fail (property->param_spec != NULL, NULL);
g_value_init (&prop_value, property->param_spec->value_type);
g_object_get_property (G_OBJECT (setting), property->param_spec->name, &prop_value);
@@ -656,8 +657,8 @@ _nm_setting_to_dbus (NMSetting *setting, NMConnection *connection, NMConnectionS
const NMSettingProperty *property = &properties[i];
GParamSpec *prop_spec = property->param_spec;
- if (!prop_spec && !property->get_func) {
- /* Override property with no get_func, so we skip it. */
+ if (!prop_spec && !property->synth_func) {
+ /* D-Bus-only property with no synth_func, so we skip it. */
continue;
}
@@ -672,12 +673,10 @@ _nm_setting_to_dbus (NMSetting *setting, NMConnection *connection, NMConnectionS
&& !(prop_spec && (prop_spec->flags & NM_SETTING_PARAM_SECRET)))
continue;
- if (property->get_func)
- dbus_value = property->get_func (setting, connection, property->name);
- else if (prop_spec)
- dbus_value = get_property_for_dbus (setting, property, TRUE);
+ if (property->synth_func)
+ dbus_value = property->synth_func (setting, connection, property->name);
else
- g_assert_not_reached ();
+ dbus_value = get_property_for_dbus (setting, property, TRUE);
if (dbus_value) {
/* Allow dbus_value to be either floating or not. */
g_variant_take_ref (dbus_value);
@@ -717,8 +716,6 @@ _nm_setting_new_from_dbus (GType setting_type,
{
NMSettingClass *class;
NMSetting *setting;
- GVariantIter iter;
- const char *prop_name;
const NMSettingProperty *properties;
guint n_properties;
guint i;
@@ -737,17 +734,11 @@ _nm_setting_new_from_dbus (GType setting_type,
*/
class = g_type_class_ref (setting_type);
- /* Check for invalid properties first. */
- g_variant_iter_init (&iter, setting_dict);
- while (g_variant_iter_next (&iter, "{&sv}", &prop_name, NULL)) {
- if (!nm_setting_class_find_property (class, prop_name)) {
- /* Oh, we're so nice and only warn, maybe it should be a fatal error? */
- g_warning ("Ignoring invalid property '%s'", prop_name);
- continue;
- }
- }
-
- /* Now build the setting object from the legitimate properties */
+ /* Build the setting object from the properties we know about; we assume
+ * that any propreties in @setting_dict that we don't know about can
+ * either be ignored or else has a backward-compatibility equivalent
+ * that we do know about.
+ */
setting = (NMSetting *) g_object_new (setting_type, NULL);
properties = nm_setting_class_get_properties (class, &n_properties);
diff --git a/libnm-core/nm-utils-private.h b/libnm-core/nm-utils-private.h
index bc42921514..4a4e82e0d9 100644
--- a/libnm-core/nm-utils-private.h
+++ b/libnm-core/nm-utils-private.h
@@ -40,29 +40,12 @@ GVariant * _nm_utils_bytes_to_dbus (const GValue *prop_value);
void _nm_utils_bytes_from_dbus (GVariant *dbus_value,
GValue *prop_value);
-GVariant * _nm_utils_ip4_dns_to_dbus (const GValue *prop_value);
-void _nm_utils_ip4_dns_from_dbus (GVariant *dbus_value,
- GValue *prop_value);
-GVariant * _nm_utils_ip4_addresses_to_dbus (const GValue *prop_value);
-void _nm_utils_ip4_addresses_from_dbus (GVariant *dbus_value,
- GValue *prop_value);
-GVariant * _nm_utils_ip4_routes_to_dbus (const GValue *prop_value);
-void _nm_utils_ip4_routes_from_dbus (GVariant *dbus_value,
- GValue *prop_value);
-
-GVariant * _nm_utils_ip6_dns_to_dbus (const GValue *prop_value);
-void _nm_utils_ip6_dns_from_dbus (GVariant *dbus_value,
- GValue *prop_value);
-GVariant * _nm_utils_ip6_addresses_to_dbus (const GValue *prop_value);
-void _nm_utils_ip6_addresses_from_dbus (GVariant *dbus_value,
- GValue *prop_value);
-GVariant * _nm_utils_ip6_routes_to_dbus (const GValue *prop_value);
-void _nm_utils_ip6_routes_from_dbus (GVariant *dbus_value,
- GValue *prop_value);
-
GSList * _nm_utils_strv_to_slist (char **strv);
char ** _nm_utils_slist_to_strv (GSList *slist);
+GPtrArray * _nm_utils_strv_to_ptrarray (char **strv);
+char ** _nm_utils_ptrarray_to_strv (GPtrArray *ptrarray);
+
char ** _nm_utils_strsplit_set (const char *str,
const char *delimiters,
int max_tokens);
diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c
index dfa0d7cf81..37f9ca0cf4 100644
--- a/libnm-core/nm-utils.c
+++ b/libnm-core/nm-utils.c
@@ -24,6 +24,7 @@
#include <string.h>
#include <stdlib.h>
#include <netinet/ether.h>
+#include <arpa/inet.h>
#include <uuid/uuid.h>
#include <gmodule.h>
@@ -32,6 +33,7 @@
#include "nm-glib-compat.h"
#include "nm-setting-private.h"
#include "crypto.h"
+#include "gsystem-local-alloc.h"
#include "nm-setting-bond.h"
#include "nm-setting-bridge.h"
@@ -662,7 +664,7 @@ _nm_utils_slist_to_strv (GSList *slist)
{
GSList *iter;
char **strv;
- int len, i = 0;
+ int len, i;
len = g_slist_length (slist);
strv = g_new (char *, len + 1);
@@ -674,6 +676,40 @@ _nm_utils_slist_to_strv (GSList *slist)
return strv;
}
+GPtrArray *
+_nm_utils_strv_to_ptrarray (char **strv)
+{
+ GPtrArray *ptrarray;
+ int i;
+
+ ptrarray = g_ptr_array_new_with_free_func (g_free);
+
+ if (strv) {
+ for (i = 0; strv[i]; i++)
+ g_ptr_array_add (ptrarray, g_strdup (strv[i]));
+ }
+
+ return ptrarray;
+}
+
+char **
+_nm_utils_ptrarray_to_strv (GPtrArray *ptrarray)
+{
+ char **strv;
+ int i;
+
+ if (!ptrarray)
+ return g_new0 (char *, 1);
+
+ strv = g_new (char *, ptrarray->len + 1);
+
+ for (i = 0; i < ptrarray->len; i++)
+ strv[i] = g_strdup (ptrarray->pdata[i]);
+ strv[i] = NULL;
+
+ return strv;
+}
+
/**
* _nm_utils_strsplit_set:
* @str: string to split
@@ -1100,16 +1136,19 @@ nm_utils_ip4_dns_from_variant (GVariant *value)
/**
* nm_utils_ip4_addresses_to_variant:
- * @addresses: (element-type NMIP4Address): an array of #NMIP4Address objects
+ * @addresses: (element-type NMIPAddress): an array of #NMIPAddress objects
+ * @gateway: (allow-none): the gateway IP address
*
- * Utility function to convert a #GPtrArray of #NMIP4Address objects into a
- * #GVariant of type 'aau' representing an array of NetworkManager IPv4
- * addresses (which are tuples of address, prefix, and gateway).
+ * Utility function to convert a #GPtrArray of #NMIPAddress objects representing
+ * IPv4 addresses into a #GVariant of type 'aau' representing an array of
+ * NetworkManager IPv4 addresses (which are tuples of address, prefix, and
+ * gateway). The "gateway" field of the first address will get the value of
+ * @gateway (if non-%NULL). In all of the other addresses, that field will be 0.
*
* Returns: (transfer none): a new floating #GVariant representing @addresses.
**/
GVariant *
-nm_utils_ip4_addresses_to_variant (GPtrArray *addresses)
+nm_utils_ip4_addresses_to_variant (GPtrArray *addresses, const char *gateway)
{
GVariantBuilder builder;
int i;
@@ -1118,12 +1157,18 @@ nm_utils_ip4_addresses_to_variant (GPtrArray *addresses)
if (addresses) {
for (i = 0; i < addresses->len; i++) {
- NMIP4Address *addr = addresses->pdata[i];
+ NMIPAddress *addr = addresses->pdata[i];
guint32 array[3];
- array[0] = nm_ip4_address_get_address (addr);
- array[1] = nm_ip4_address_get_prefix (addr);
- array[2] = nm_ip4_address_get_gateway (addr);
+ if (nm_ip_address_get_family (addr) != AF_INET)
+ continue;
+
+ nm_ip_address_get_address_binary (addr, &array[0]);
+ array[1] = nm_ip_address_get_prefix (addr);
+ if (i == 0 && gateway)
+ inet_pton (AF_INET, gateway, &array[2]);
+ else
+ array[2] = 0;
g_variant_builder_add (&builder, "@au",
g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32,
@@ -1137,16 +1182,19 @@ nm_utils_ip4_addresses_to_variant (GPtrArray *addresses)
/**
* nm_utils_ip4_addresses_from_variant:
* @value: a #GVariant of type 'aau'
+ * @out_gateway: (out) (allow-none) (transfer full): on return, will contain the IP gateway
*
* Utility function to convert a #GVariant of type 'aau' representing a list of
* NetworkManager IPv4 addresses (which are tuples of address, prefix, and
- * gateway) into a #GPtrArray of #NMIP4Address objects.
+ * gateway) into a #GPtrArray of #NMIPAddress objects. The "gateway" field of
+ * the first address (if set) will be returned in @out_gateway; the "gateway" fields
+ * of the other addresses are ignored.
*
- * Returns: (transfer full) (element-type NMIP4Address): a newly allocated
- * #GPtrArray of #NMIP4Address objects
+ * Returns: (transfer full) (element-type NMIPAddress): a newly allocated
+ * #GPtrArray of #NMIPAddress objects
**/
GPtrArray *
-nm_utils_ip4_addresses_from_variant (GVariant *value)
+nm_utils_ip4_addresses_from_variant (GVariant *value, char **out_gateway)
{
GPtrArray *addresses;
GVariantIter iter;
@@ -1154,13 +1202,17 @@ nm_utils_ip4_addresses_from_variant (GVariant *value)
g_return_val_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE ("aau")), NULL);
+ if (out_gateway)
+ *out_gateway = NULL;
+
g_variant_iter_init (&iter, value);
- 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);
while (g_variant_iter_next (&iter, "@au", &addr_var)) {
const guint32 *addr_array;
gsize length;
- NMIP4Address *addr;
+ NMIPAddress *addr;
+ GError *error = NULL;
addr_array = g_variant_get_fixed_array (addr_var, &length, sizeof (guint32));
if (length < 3) {
@@ -1169,12 +1221,19 @@ nm_utils_ip4_addresses_from_variant (GVariant *value)
continue;
}
- addr = nm_ip4_address_new ();
- nm_ip4_address_set_address (addr, addr_array[0]);
- nm_ip4_address_set_prefix (addr, addr_array[1]);
- nm_ip4_address_set_gateway (addr, addr_array[2]);
+ addr = nm_ip_address_new_binary (AF_INET, &addr_array[0], addr_array[1], &error);
+ if (addresses->len == 0 && out_gateway) {
+ if (addr_array[2])
+ *out_gateway = g_strdup (nm_utils_inet4_ntop (addr_array[2], NULL));
+ }
+
+ if (addr)
+ g_ptr_array_add (addresses, addr);
+ else {
+ g_warning ("Ignoring invalid IP4 address: %s", error->message);
+ g_clear_error (&error);
+ }
- g_ptr_array_add (addresses, addr);
g_variant_unref (addr_var);
}
@@ -1183,11 +1242,12 @@ nm_utils_ip4_addresses_from_variant (GVariant *value)
/**
* nm_utils_ip4_routes_to_variant:
- * @routes: (element-type NMIP4Route): an array of #NMIP4Route objects
+ * @routes: (element-type NMIPRoute): an array of #NMIP4Route objects
*
- * Utility function to convert a #GPtrArray of #NMIP4Route objects into a
- * #GVariant of type 'aau' representing an array of NetworkManager IPv4 routes
- * (which are tuples of route, prefix, next hop, and metric).
+ * Utility function to convert a #GPtrArray of #NMIPRoute objects representing
+ * IPv4 routes into a #GVariant of type 'aau' representing an array of
+ * NetworkManager IPv4 routes (which are tuples of route, prefix, next hop, and
+ * metric).
*
* Returns: (transfer none): a new floating #GVariant representing @routes.
**/
@@ -1201,13 +1261,17 @@ nm_utils_ip4_routes_to_variant (GPtrArray *routes)
if (routes) {
for (i = 0; i < routes->len; i++) {
- NMIP4Route *route = routes->pdata[i];
+ NMIPRoute *route = routes->pdata[i];
guint32 array[4];
- array[0] = nm_ip4_route_get_dest (route);
- array[1] = nm_ip4_route_get_prefix (route);
- array[2] = nm_ip4_route_get_next_hop (route);
- array[3] = nm_ip4_route_get_metric (route);
+ if (nm_ip_route_get_family (route) != AF_INET)
+ continue;
+
+ nm_ip_route_get_dest_binary (route, &array[0]);
+ array[1] = nm_ip_route_get_prefix (route);
+ nm_ip_route_get_next_hop_binary (route, &array[2]);
+ /* The old routes format uses "0" for default, not "-1" */
+ array[3] = MAX (0, nm_ip_route_get_metric (route));
g_variant_builder_add (&builder, "@au",
g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32,
@@ -1224,10 +1288,10 @@ nm_utils_ip4_routes_to_variant (GPtrArray *routes)
*
* Utility function to convert a #GVariant of type 'aau' representing an array
* of NetworkManager IPv4 routes (which are tuples of route, prefix, next hop,
- * and metric) into a #GPtrArray of #NMIP4Route objects.
+ * and metric) into a #GPtrArray of #NMIPRoute objects.
*
- * Returns: (transfer full) (element-type NMIP4Route): a newly allocated
- * #GPtrArray of #NMIP4Route objects
+ * Returns: (transfer full) (element-type NMIPRoute): a newly allocated
+ * #GPtrArray of #NMIPRoute objects
**/
GPtrArray *
nm_utils_ip4_routes_from_variant (GVariant *value)
@@ -1239,12 +1303,13 @@ nm_utils_ip4_routes_from_variant (GVariant *value)
g_return_val_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE ("aau")), NULL);
g_variant_iter_init (&iter, value);
- 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);
while (g_variant_iter_next (&iter, "@au", &route_var)) {
const guint32 *route_array;
gsize length;
- NMIP4Route *route;
+ NMIPRoute *route;
+ GError *error = NULL;
route_array = g_variant_get_fixed_array (route_var, &length, sizeof (guint32));
if (length < 4) {
@@ -1253,13 +1318,19 @@ nm_utils_ip4_routes_from_variant (GVariant *value)
continue;
}
- route = nm_ip4_route_new ();
- nm_ip4_route_set_dest (route, route_array[0]);
- nm_ip4_route_set_prefix (route, route_array[1]);
- nm_ip4_route_set_next_hop (route, route_array[2]);
- nm_ip4_route_set_metric (route, route_array[3]);
-
- g_ptr_array_add (routes, route);
+ route = nm_ip_route_new_binary (AF_INET,
+ &route_array[0],
+ route_array[1],
+ &route_array[2],
+ /* The old routes format uses "0" for default, not "-1" */
+ route_array[3] ? (gint64) route_array[3] : -1,
+ &error);
+ if (route)
+ g_ptr_array_add (routes, route);
+ else {
+ g_warning ("Ignoring invalid IP4 route: %s", error->message);
+ g_clear_error (&error);
+ }
g_variant_unref (route_var);
}
@@ -1412,16 +1483,20 @@ nm_utils_ip6_dns_from_variant (GVariant *value)
/**
* nm_utils_ip6_addresses_to_variant:
- * @addresses: (element-type NMIP6Address): an array of #NMIP6Address objects
+ * @addresses: (element-type NMIPAddress): an array of #NMIPAddress objects
+ * @gateway: (allow-none): the gateway IP address
*
- * Utility function to convert a #GPtrArray of #NMIP6Address objects into a
- * #GVariant of type 'a(ayuay)' representing an array of NetworkManager IPv6
- * addresses (which are tuples of address, prefix, and gateway).
+ * Utility function to convert a #GPtrArray of #NMIPAddress objects representing
+ * IPv6 addresses into a #GVariant of type 'a(ayuay)' representing an array of
+ * NetworkManager IPv6 addresses (which are tuples of address, prefix, and
+ * gateway). The "gateway" field of the first address will get the value of
+ * @gateway (if non-%NULL). In all of the other addresses, that field will be
+ * all 0s.
*
* Returns: (transfer none): a new floating #GVariant representing @addresses.
**/
GVariant *
-nm_utils_ip6_addresses_to_variant (GPtrArray *addresses)
+nm_utils_ip6_addresses_to_variant (GPtrArray *addresses, const char *gateway)
{
GVariantBuilder builder;
int i;
@@ -1430,19 +1505,26 @@ nm_utils_ip6_addresses_to_variant (GPtrArray *addresses)
if (addresses) {
for (i = 0; i < addresses->len; i++) {
- NMIP6Address *addr = addresses->pdata[i];
- GVariant *ip, *gateway;
+ NMIPAddress *addr = addresses->pdata[i];
+ struct in6_addr ip_bytes, gateway_bytes;
+ GVariant *ip_var, *gateway_var;
guint32 prefix;
- ip = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
- nm_ip6_address_get_address (addr),
- 16, 1);
- prefix = nm_ip6_address_get_prefix (addr);
- gateway = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
- nm_ip6_address_get_gateway (addr),
- 16, 1);
+ if (nm_ip_address_get_family (addr) != AF_INET6)
+ continue;
+
+ nm_ip_address_get_address_binary (addr, &ip_bytes);
+ ip_var = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, &ip_bytes, 16, 1);
- g_variant_builder_add (&builder, "(@ayu@ay)", ip, prefix, gateway);
+ prefix = nm_ip_address_get_prefix (addr);
+
+ if (i == 0 && gateway)
+ inet_pton (AF_INET6, gateway, &gateway_bytes);
+ else
+ memset (&gateway_bytes, 0, sizeof (gateway_bytes));
+ gateway_var = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, &gateway_bytes, 16, 1);
+
+ g_variant_builder_add (&builder, "(@ayu@ay)", ip_var, prefix, gateway_var);
}
}
@@ -1452,16 +1534,19 @@ nm_utils_ip6_addresses_to_variant (GPtrArray *addresses)
/**
* nm_utils_ip6_addresses_from_variant:
* @value: a #GVariant of type 'a(ayuay)'
+ * @out_gateway: (out) (allow-none) (transfer full): on return, will contain the IP gateway
*
* Utility function to convert a #GVariant of type 'a(ayuay)' representing a
* list of NetworkManager IPv6 addresses (which are tuples of address, prefix,
- * and gateway) into a #GPtrArray of #NMIP6Address objects.
+ * and gateway) into a #GPtrArray of #NMIPAddress objects. The "gateway" field
+ * of the first address (if set) will be returned in @out_gateway; the "gateway"
+ * fields of the other addresses are ignored.
*
- * Returns: (transfer full) (element-type NMIP6Address): a newly allocated
- * #GPtrArray of #NMIP6Address objects
+ * Returns: (transfer full) (element-type NMIPAddress): a newly allocated
+ * #GPtrArray of #NMIPAddress objects
**/
GPtrArray *
-nm_utils_ip6_addresses_from_variant (GVariant *value)
+nm_utils_ip6_addresses_from_variant (GVariant *value, char **out_gateway)
{
GVariantIter iter;
GVariant *addr_var, *gateway_var;
@@ -1470,13 +1555,17 @@ nm_utils_ip6_addresses_from_variant (GVariant *value)
g_return_val_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE ("a(ayuay)")), NULL);
+ if (out_gateway)
+ *out_gateway = NULL;
+
g_variant_iter_init (&iter, value);
- addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip6_address_unref);
+ addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref);
while (g_variant_iter_next (&iter, "(@ayu@ay)", &addr_var, &prefix, &gateway_var)) {
- NMIP6Address *addr;
+ NMIPAddress *addr;
const struct in6_addr *addr_bytes, *gateway_bytes;
gsize addr_len, gateway_len;
+ GError *error = NULL;
if ( !g_variant_is_of_type (addr_var, G_VARIANT_TYPE_BYTESTRING)
|| !g_variant_is_of_type (gateway_var, G_VARIANT_TYPE_BYTESTRING)) {
@@ -1490,23 +1579,25 @@ nm_utils_ip6_addresses_from_variant (GVariant *value)
__func__, (int) addr_len);
goto next;
}
- if (prefix > 128) {
- g_warning ("%s: ignoring invalid IP6 prefix %d",
- __func__, prefix);
- goto next;
- }
- gateway_bytes = g_variant_get_fixed_array (gateway_var, &gateway_len, 1);
- if (gateway_len != 16) {
- g_warning ("%s: ignoring invalid IP6 address of length %d",
- __func__, (int) gateway_len);
- goto next;
+
+ if (addresses->len == 0 && out_gateway) {
+ gateway_bytes = g_variant_get_fixed_array (gateway_var, &gateway_len, 1);
+ if (gateway_len != 16) {
+ g_warning ("%s: ignoring invalid IP6 address of length %d",
+ __func__, (int) gateway_len);
+ goto next;
+ }
+ if (!IN6_IS_ADDR_UNSPECIFIED (gateway_bytes))
+ *out_gateway = g_strdup (nm_utils_inet6_ntop (gateway_bytes, NULL));
}
- addr = nm_ip6_address_new ();
- nm_ip6_address_set_address (addr, addr_bytes);
- nm_ip6_address_set_prefix (addr, prefix);
- nm_ip6_address_set_gateway (addr, gateway_bytes);
- g_ptr_array_add (addresses, addr);
+ addr = nm_ip_address_new_binary (AF_INET6, addr_bytes, prefix, &error);
+ if (addr)
+ g_ptr_array_add (addresses, addr);
+ else {
+ g_warning ("Ignoring invalid IP4 address: %s", error->message);
+ g_clear_error (&error);
+ }
next:
g_variant_unref (addr_var);
@@ -1518,11 +1609,12 @@ nm_utils_ip6_addresses_from_variant (GVariant *value)
/**
* nm_utils_ip6_routes_to_variant:
- * @routes: (element-type NMIP6Route): an array of #NMIP6Route objects
+ * @routes: (element-type NMIPRoute): an array of #NMIPRoute objects
*
- * Utility function to convert a #GPtrArray of #NMIP6Route objects into a
- * #GVariant of type 'a(ayuayu)' representing an array of NetworkManager IPv6
- * routes (which are tuples of route, prefix, next hop, and metric).
+ * Utility function to convert a #GPtrArray of #NMIPRoute objects representing
+ * IPv6 routes into a #GVariant of type 'a(ayuayu)' representing an array of
+ * NetworkManager IPv6 routes (which are tuples of route, prefix, next hop, and
+ * metric).
*
* Returns: (transfer none): a new floating #GVariant representing @routes.
**/
@@ -1536,18 +1628,21 @@ nm_utils_ip6_routes_to_variant (GPtrArray *routes)
if (routes) {
for (i = 0; i < routes->len; i++) {
- NMIP6Route *route = routes->pdata[i];
+ NMIPRoute *route = routes->pdata[i];
+ struct in6_addr dest_bytes, next_hop_bytes;
GVariant *dest, *next_hop;
guint32 prefix, metric;
- dest = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
- nm_ip6_route_get_dest (route),
- 16, 1);
- prefix = nm_ip6_route_get_prefix (route);
- next_hop = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
- nm_ip6_route_get_next_hop (route),
- 16, 1);
- metric = nm_ip6_route_get_metric (route);
+ if (nm_ip_route_get_family (route) != AF_INET6)
+ continue;
+
+ nm_ip_route_get_dest_binary (route, &dest_bytes);
+ dest = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, &dest_bytes, 16, 1);
+ prefix = nm_ip_route_get_prefix (route);
+ nm_ip_route_get_next_hop_binary (route, &next_hop_bytes);
+ next_hop = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, &next_hop_bytes, 16, 1);
+ /* The old routes format uses "0" for default, not "-1" */
+ metric = MAX (0, nm_ip_route_get_metric (route));
g_variant_builder_add (&builder, "(@ayu@ayu)", dest, prefix, next_hop, metric);
}
@@ -1562,10 +1657,10 @@ nm_utils_ip6_routes_to_variant (GPtrArray *routes)
*
* Utility function to convert a #GVariant of type 'a(ayuayu)' representing an
* array of NetworkManager IPv6 routes (which are tuples of route, prefix, next
- * hop, and metric) into a #GPtrArray of #NMIP6Route objects.
+ * hop, and metric) into a #GPtrArray of #NMIPRoute objects.
*
- * Returns: (transfer full) (element-type NMIP6Route): a newly allocated
- * #GPtrArray of #NMIP6Route objects
+ * Returns: (transfer full) (element-type NMIPRoute): a newly allocated
+ * #GPtrArray of #NMIPRoute objects
**/
GPtrArray *
nm_utils_ip6_routes_from_variant (GVariant *value)
@@ -1579,11 +1674,12 @@ nm_utils_ip6_routes_from_variant (GVariant *value)
g_return_val_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE ("a(ayuayu)")), NULL);
- routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip6_route_unref);
+ routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref);
g_variant_iter_init (&iter, value);
while (g_variant_iter_next (&iter, "(@ayu@ayu)", &dest_var, &prefix, &next_hop_var, &metric)) {
- NMIP6Route *route;
+ NMIPRoute *route;
+ GError *error = NULL;
if ( !g_variant_is_of_type (dest_var, G_VARIANT_TYPE_BYTESTRING)
|| !g_variant_is_of_type (next_hop_var, G_VARIANT_TYPE_BYTESTRING)) {
@@ -1597,6 +1693,7 @@ nm_utils_ip6_routes_from_variant (GVariant *value)
__func__, (int) dest_len);
goto next;
}
+
next_hop = g_variant_get_fixed_array (next_hop_var, &next_hop_len, 1);
if (next_hop_len != 16) {
g_warning ("%s: ignoring invalid IP6 address of length %d",
@@ -1604,12 +1701,15 @@ nm_utils_ip6_routes_from_variant (GVariant *value)
goto next;
}
- route = nm_ip6_route_new ();
- nm_ip6_route_set_dest (route, dest);
- nm_ip6_route_set_prefix (route, prefix);
- nm_ip6_route_set_next_hop (route, next_hop);
- nm_ip6_route_set_metric (route, metric);
- g_ptr_array_add (routes, route);
+ route = nm_ip_route_new_binary (AF_INET6, dest, prefix, next_hop,
+ metric ? (gint64) metric : -1,
+ &error);
+ if (route)
+ g_ptr_array_add (routes, route);
+ else {
+ g_warning ("Ignoring invalid IP6 route: %s", error->message);
+ g_clear_error (&error);
+ }
next:
g_variant_unref (dest_var);
@@ -1620,6 +1720,248 @@ nm_utils_ip6_routes_from_variant (GVariant *value)
}
/**
+ * nm_utils_ip_addresses_to_variant:
+ * @addresses: (element-type NMIPAddress): an array of #NMIPAddress objects
+ *
+ * Utility function to convert a #GPtrArray of #NMIPAddress objects representing
+ * IPv4 or IPv6 addresses into a #GVariant of type 'aa{sv}' representing an
+ * array of new-style NetworkManager IP addresses. All addresses will include
+ * "address" (an IP address string), and "prefix" (a uint). Some addresses may
+ * include additional attributes.
+ *
+ * Returns: (transfer none): a new floating #GVariant representing @addresses.
+ **/
+GVariant *
+nm_utils_ip_addresses_to_variant (GPtrArray *addresses)
+{
+ GVariantBuilder builder;
+ int i;
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("aa{sv}"));
+
+ if (addresses) {
+ for (i = 0; i < addresses->len; i++) {
+ NMIPAddress *addr = addresses->pdata[i];
+ GVariantBuilder addr_builder;
+ char **names;
+ int n;
+
+ g_variant_builder_init (&addr_builder, G_VARIANT_TYPE ("a{sv}"));
+ g_variant_builder_add (&addr_builder, "{sv}",
+ "address",
+ g_variant_new_string (nm_ip_address_get_address (addr)));
+ g_variant_builder_add (&addr_builder, "{sv}",
+ "prefix",
+ g_variant_new_uint32 (nm_ip_address_get_prefix (addr)));
+
+ names = nm_ip_address_get_attribute_names (addr);
+ for (n = 0; names[n]; n++) {
+ g_variant_builder_add (&addr_builder, "{sv}",
+ names[n],
+ nm_ip_address_get_attribute (addr, names[n]));
+ }
+ g_strfreev (names);
+
+ g_variant_builder_add (&builder, "a{sv}", &addr_builder);
+ }
+ }
+
+ return g_variant_builder_end (&builder);
+}
+
+/**
+ * nm_utils_ip_addresses_from_variant:
+ * @value: a #GVariant of type 'aa{sv}'
+ * @family: an IP address family
+ *
+ * Utility function to convert a #GVariant representing a list of new-style
+ * NetworkManager IPv4 or IPv6 addresses (as described in the documentation for
+ * nm_utils_ip_addresses_to_variant()) into a #GPtrArray of #NMIPAddress
+ * objects.
+ *
+ * Returns: (transfer full) (element-type NMIPAddress): a newly allocated
+ * #GPtrArray of #NMIPAddress objects
+ **/
+GPtrArray *
+nm_utils_ip_addresses_from_variant (GVariant *value,
+ int family)
+{
+ GPtrArray *addresses;
+ GVariantIter iter, attrs_iter;
+ GVariant *addr_var;
+ const char *ip;
+ guint32 prefix;
+ const char *attr_name;
+ GVariant *attr_val;
+ NMIPAddress *addr;
+ GError *error = NULL;
+
+ g_return_val_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE ("aa{sv}")), NULL);
+
+ g_variant_iter_init (&iter, value);
+ addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref);
+
+ while (g_variant_iter_next (&iter, "@a{sv}", &addr_var)) {
+ if ( !g_variant_lookup (addr_var, "address", "&s", &ip)
+ || !g_variant_lookup (addr_var, "prefix", "u", &prefix)) {
+ g_warning ("Ignoring invalid address");
+ g_variant_unref (addr_var);
+ continue;
+ }
+
+ addr = nm_ip_address_new (family, ip, prefix, &error);
+ if (!addr) {
+ g_warning ("Ignoring invalid address: %s", error->message);
+ g_clear_error (&error);
+ g_variant_unref (addr_var);
+ continue;
+ }
+
+ g_variant_iter_init (&attrs_iter, addr_var);
+ while (g_variant_iter_next (&attrs_iter, "{&sv}", &attr_name, &attr_val)) {
+ if ( strcmp (attr_name, "address") != 0
+ && strcmp (attr_name, "prefix") != 0)
+ nm_ip_address_set_attribute (addr, attr_name, attr_val);
+ g_variant_unref (attr_val);
+ }
+
+ g_ptr_array_add (addresses, addr);
+ }
+
+ return addresses;
+}
+
+/**
+ * nm_utils_ip_routes_to_variant:
+ * @routes: (element-type NMIPRoute): an array of #NMIPRoute objects
+ *
+ * Utility function to convert a #GPtrArray of #NMIPRoute objects representing
+ * IPv4 or IPv6 routes into a #GVariant of type 'aa{sv}' representing an array
+ * of new-style NetworkManager IP routes (which are tuples of destination,
+ * prefix, next hop, metric, and additional attributes).
+ *
+ * Returns: (transfer none): a new floating #GVariant representing @routes.
+ **/
+GVariant *
+nm_utils_ip_routes_to_variant (GPtrArray *routes)
+{
+ GVariantBuilder builder;
+ int i;
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("aa{sv}"));
+
+ if (routes) {
+ for (i = 0; i < routes->len; i++) {
+ NMIPRoute *route = routes->pdata[i];
+ GVariantBuilder route_builder;
+ char **names;
+ int n;
+
+ g_variant_builder_init (&route_builder, G_VARIANT_TYPE ("a{sv}"));
+ g_variant_builder_add (&route_builder, "{sv}",
+ "dest",
+ g_variant_new_string (nm_ip_route_get_dest (route)));
+ g_variant_builder_add (&route_builder, "{sv}",
+ "prefix",
+ g_variant_new_uint32 (nm_ip_route_get_prefix (route)));
+ if (nm_ip_route_get_next_hop (route)) {
+ g_variant_builder_add (&route_builder, "{sv}",
+ "next-hop",
+ g_variant_new_string (nm_ip_route_get_next_hop (route)));
+ }
+ if (nm_ip_route_get_metric (route) != -1) {
+ g_variant_builder_add (&route_builder, "{sv}",
+ "metric",
+ g_variant_new_uint32 ((guint32) nm_ip_route_get_metric (route)));
+ }
+
+ names = nm_ip_route_get_attribute_names (route);
+ for (n = 0; names[n]; n++) {
+ g_variant_builder_add (&route_builder, "{sv}",
+ names[n],
+ nm_ip_route_get_attribute (route, names[n]));
+ }
+ g_strfreev (names);
+
+ g_variant_builder_add (&builder, "a{sv}", &route_builder);
+ }
+ }
+
+ return g_variant_builder_end (&builder);
+}
+
+/**
+ * nm_utils_ip_routes_from_variant:
+ * @value: a #GVariant of type 'aa{sv}'
+ * @family: an IP address family
+ *
+ * Utility function to convert a #GVariant representing a list of new-style
+ * NetworkManager IPv4 or IPv6 addresses (which are tuples of destination,
+ * prefix, next hop, metric, and additional attributes) into a #GPtrArray of
+ * #NMIPRoute objects.
+ *
+ * Returns: (transfer full) (element-type NMIPRoute): a newly allocated
+ * #GPtrArray of #NMIPRoute objects
+ **/
+GPtrArray *
+nm_utils_ip_routes_from_variant (GVariant *value,
+ int family)
+{
+ GPtrArray *routes;
+ GVariantIter iter, attrs_iter;
+ GVariant *route_var;
+ const char *dest, *next_hop;
+ guint32 prefix, metric32;
+ gint64 metric;
+ const char *attr_name;
+ GVariant *attr_val;
+ NMIPRoute *route;
+ GError *error = NULL;
+
+ g_return_val_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE ("aa{sv}")), NULL);
+
+ g_variant_iter_init (&iter, value);
+ routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref);
+
+ while (g_variant_iter_next (&iter, "@a{sv}", &route_var)) {
+ if ( !g_variant_lookup (route_var, "dest", "&s", &dest)
+ || !g_variant_lookup (route_var, "prefix", "u", &prefix)) {
+ g_warning ("Ignoring invalid address");
+ g_variant_unref (route_var);
+ continue;
+ }
+ if (!g_variant_lookup (route_var, "next-hop", "&s", &next_hop))
+ next_hop = NULL;
+ if (g_variant_lookup (route_var, "metric", "u", &metric32))
+ metric = metric32;
+ else
+ metric = -1;
+
+ route = nm_ip_route_new (family, dest, prefix, next_hop, metric, &error);
+ if (!route) {
+ g_warning ("Ignoring invalid route: %s", error->message);
+ g_clear_error (&error);
+ g_variant_unref (route_var);
+ continue;
+ }
+
+ g_variant_iter_init (&attrs_iter, route_var);
+ while (g_variant_iter_next (&attrs_iter, "{&sv}", &attr_name, &attr_val)) {
+ if ( strcmp (attr_name, "dest") != 0
+ && strcmp (attr_name, "prefix") != 0
+ && strcmp (attr_name, "next-hop") != 0
+ && strcmp (attr_name, "metric") != 0)
+ nm_ip_route_set_attribute (route, attr_name, attr_val);
+ g_variant_unref (attr_val);
+ }
+
+ g_ptr_array_add (routes, route);
+ }
+
+ return routes;
+}
+
+/**
* nm_utils_uuid_generate:
*
* Returns: a newly allocated UUID suitable for use as the #NMSettingConnection
@@ -1759,7 +2101,7 @@ nm_utils_rsa_key_encrypt_helper (const char *cipher,
if (!in_password) {
if (!crypto_randomize (pw_buf, sizeof (pw_buf), error))
return NULL;
- in_password = tmp_password = nm_utils_bin2hexstr ((const char *) pw_buf, sizeof (pw_buf), -1);
+ in_password = tmp_password = nm_utils_bin2hexstr (pw_buf, sizeof (pw_buf), -1);
}
if (g_strcmp0 (cipher, CIPHER_AES_CBC) == 0)
@@ -1783,7 +2125,7 @@ nm_utils_rsa_key_encrypt_helper (const char *cipher,
g_string_append (pem, "Proc-Type: 4,ENCRYPTED\n");
/* Convert the salt to a hex string */
- tmp = nm_utils_bin2hexstr ((const char *) salt, salt_len, salt_len * 2);
+ tmp = nm_utils_bin2hexstr (salt, salt_len, salt_len * 2);
g_string_append_printf (pem, "DEK-Info: %s,%s\n\n", cipher, tmp);
g_free (tmp);
@@ -1892,9 +2234,9 @@ nm_utils_rsa_key_encrypt_aes (const guint8 *data,
* nm_utils_file_is_pkcs12:
* @filename: name of the file to test
*
- * Utility function to find out if the @filename is in PKCS#12 format.
+ * Utility function to find out if the @filename is in PKCS#<!-- -->12 format.
*
- * Returns: %TRUE if the file is PKCS#12, %FALSE if it is not
+ * Returns: %TRUE if the file is PKCS#<!-- -->12, %FALSE if it is not
**/
gboolean
nm_utils_file_is_pkcs12 (const char *filename)
@@ -2535,13 +2877,13 @@ _nm_utils_hwaddr_from_dbus (GVariant *dbus_value,
/**
* nm_utils_bin2hexstr:
- * @bytes: an array of bytes
+ * @src: an array of bytes
* @len: the length of the @bytes array
* @final_len: an index where to cut off the returned string, or -1
*
- * Converts a byte-array @bytes into a hexadecimal string.
- * If @final_len is greater than -1, the returned string is terminated at
- * that index (returned_string[final_len] == '\0'),
+ * Converts the byte array @src into a hexadecimal string. If @final_len is
+ * greater than -1, the returned string is terminated at that index
+ * (returned_string[final_len] == '\0'),
*
* Return value: (transfer full): the textual form of @bytes
*/
@@ -2550,9 +2892,10 @@ _nm_utils_hwaddr_from_dbus (GVariant *dbus_value,
* copyright Red Hat, Inc. under terms of the LGPL.
*/
char *
-nm_utils_bin2hexstr (const char *bytes, int len, int final_len)
+nm_utils_bin2hexstr (gconstpointer src, gsize len, int final_len)
{
static char hex_digits[] = "0123456789abcdef";
+ const guint8 *bytes = src;
char *result;
int i;
gsize buflen = (len * 2) + 1;
@@ -2577,64 +2920,61 @@ nm_utils_bin2hexstr (const char *bytes, int len, int final_len)
return result;
}
-/* From hostap, Copyright (c) 2002-2005, Jouni Malinen <jkmaline@cc.hut.fi> */
/**
- * nm_utils_hex2byte:
- * @hex: a string representing a hex byte
+ * nm_utils_hexstr2bin:
+ * @hex: a string of hexadecimal characters with optional ':' separators
*
- * Converts a hex string (2 characters) into its byte representation.
+ * Converts a hexadecimal string @hex into an array of bytes. The optional
+ * separator ':' may be used between single or pairs of hexadecimal characters,
+ * eg "00:11" or "0:1". Any "0x" at the beginning of @hex is ignored. @hex
+ * may not start or end with ':'.
*
- * Return value: a byte, or -1 if @hex doesn't represent a hex byte
+ * Return value: (transfer full): the converted bytes, or %NULL on error
*/
-int
-nm_utils_hex2byte (const char *hex)
+GBytes *
+nm_utils_hexstr2bin (const char *hex)
{
+ guint i = 0, x = 0;
+ gs_free guint8 *c = NULL;
int a, b;
- a = g_ascii_xdigit_value (*hex++);
- if (a < 0)
- return -1;
- b = g_ascii_xdigit_value (*hex++);
- if (b < 0)
- return -1;
- return (a << 4) | b;
-}
+ gboolean found_colon = FALSE;
-/**
- * nm_utils_hexstr2bin:
- * @hex: an hex string
- * @len: the length of the @hex string (it has to be even)
- *
- * Converts a hexadecimal string @hex into a byte-array. The returned array
- * length is @len/2.
- *
- * Return value: (transfer full): a array of bytes, or %NULL on error
- */
-char *
-nm_utils_hexstr2bin (const char *hex, size_t len)
-{
- size_t i;
- int a;
- const char * ipos = hex;
- char * buf = NULL;
- char * opos;
+ g_return_val_if_fail (hex != NULL, NULL);
- /* Length must be a multiple of 2 */
- if ((len % 2) != 0)
- return NULL;
+ if (strncasecmp (hex, "0x", 2) == 0)
+ hex += 2;
+ found_colon = !!strchr (hex, ':');
+
+ c = g_malloc (strlen (hex) / 2 + 1);
+ for (;;) {
+ a = g_ascii_xdigit_value (hex[i++]);
+ if (a < 0)
+ return NULL;
- opos = buf = g_malloc0 ((len / 2) + 1);
- for (i = 0; i < len; i += 2) {
- a = nm_utils_hex2byte (ipos);
- if (a < 0) {
- g_free (buf);
+ if (hex[i] && hex[i] != ':') {
+ b = g_ascii_xdigit_value (hex[i++]);
+ if (b < 0)
+ return NULL;
+ c[x++] = ((guint) a << 4) | ((guint) b);
+ } else
+ c[x++] = (guint) a;
+
+ if (!hex[i])
+ break;
+ if (hex[i] == ':') {
+ if (!hex[i + 1]) {
+ /* trailing ':' is invalid */
+ return NULL;
+ }
+ i++;
+ } else if (found_colon) {
+ /* If colons exist, they must delimit 1 or 2 hex chars */
return NULL;
}
- *opos++ = a;
- ipos += 2;
}
- return buf;
+
+ return g_bytes_new (c, x);
}
-/* End from hostap */
/**
* nm_utils_iface_valid_name:
@@ -2751,6 +3091,28 @@ nm_utils_inet6_ntop (const struct in6_addr *in6addr, char *dst)
}
/**
+ * nm_utils_ipaddr_valid:
+ * @family: %AF_INET or %AF_INET6, or %AF_UNSPEC to accept either
+ * @ip: an IP address
+ *
+ * Checks if @ip contains a valid IP address of the given family.
+ *
+ * Return value: %TRUE or %FALSE
+ */
+gboolean
+nm_utils_ipaddr_valid (int family, const char *ip)
+{
+ guint8 buf[sizeof (struct in6_addr)];
+
+ g_return_val_if_fail (family == AF_INET || family == AF_INET6 || family == AF_UNSPEC, FALSE);
+
+ if (family == AF_UNSPEC)
+ family = strchr (ip, ':') ? AF_INET6 : AF_INET;
+
+ return inet_pton (family, ip, buf) == 1;
+}
+
+/**
* nm_utils_check_virtual_device_compatibility:
* @virtual_type: a virtual connection type
* @other_type: a connection type to test against @virtual_type
@@ -2809,5 +3171,3 @@ nm_utils_check_virtual_device_compatibility (GType virtual_type, GType other_typ
return FALSE;
}
}
-
-
diff --git a/libnm-core/nm-utils.h b/libnm-core/nm-utils.h
index 5dd3a84342..a4253927be 100644
--- a/libnm-core/nm-utils.h
+++ b/libnm-core/nm-utils.h
@@ -97,8 +97,10 @@ gboolean nm_utils_wpa_psk_valid (const char *psk);
GVariant *nm_utils_ip4_dns_to_variant (char **dns);
char **nm_utils_ip4_dns_from_variant (GVariant *value);
-GVariant *nm_utils_ip4_addresses_to_variant (GPtrArray *addresses);
-GPtrArray *nm_utils_ip4_addresses_from_variant (GVariant *value);
+GVariant *nm_utils_ip4_addresses_to_variant (GPtrArray *addresses,
+ const char *gateway);
+GPtrArray *nm_utils_ip4_addresses_from_variant (GVariant *value,
+ char **out_gateway);
GVariant *nm_utils_ip4_routes_to_variant (GPtrArray *routes);
GPtrArray *nm_utils_ip4_routes_from_variant (GVariant *value);
@@ -108,11 +110,20 @@ guint32 nm_utils_ip4_get_default_prefix (guint32 ip);
GVariant *nm_utils_ip6_dns_to_variant (char **dns);
char **nm_utils_ip6_dns_from_variant (GVariant *value);
-GVariant *nm_utils_ip6_addresses_to_variant (GPtrArray *addresses);
-GPtrArray *nm_utils_ip6_addresses_from_variant (GVariant *value);
+GVariant *nm_utils_ip6_addresses_to_variant (GPtrArray *addresses,
+ const char *gateway);
+GPtrArray *nm_utils_ip6_addresses_from_variant (GVariant *value,
+ char **out_gateway);
GVariant *nm_utils_ip6_routes_to_variant (GPtrArray *routes);
GPtrArray *nm_utils_ip6_routes_from_variant (GVariant *value);
+GVariant *nm_utils_ip_addresses_to_variant (GPtrArray *addresses);
+GPtrArray *nm_utils_ip_addresses_from_variant (GVariant *value,
+ int family);
+GVariant *nm_utils_ip_routes_to_variant (GPtrArray *routes);
+GPtrArray *nm_utils_ip_routes_from_variant (GVariant *value,
+ int family);
+
char *nm_utils_uuid_generate (void);
char *nm_utils_uuid_generate_from_string (const char *s);
@@ -156,9 +167,8 @@ gboolean nm_utils_hwaddr_matches (gconstpointer hwaddr1,
gconstpointer hwaddr2,
gssize hwaddr2_len);
-char *nm_utils_bin2hexstr (const char *bytes, int len, int final_len);
-int nm_utils_hex2byte (const char *hex);
-char *nm_utils_hexstr2bin (const char *hex, size_t len);
+char *nm_utils_bin2hexstr (gconstpointer src, gsize len, int final_len);
+GBytes *nm_utils_hexstr2bin (const char *hex);
gboolean nm_utils_iface_valid_name(const char *name);
@@ -174,6 +184,8 @@ gboolean nm_utils_is_uuid (const char *str);
const char *nm_utils_inet4_ntop (in_addr_t inaddr, char *dst);
const char *nm_utils_inet6_ntop (const struct in6_addr *in6addr, char *dst);
+gboolean nm_utils_ipaddr_valid (int family, const char *ip);
+
gboolean nm_utils_check_virtual_device_compatibility (GType virtual_type, GType other_type);
G_END_DECLS
diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c
index a71238929f..522c6eb15f 100644
--- a/libnm-core/tests/test-general.c
+++ b/libnm-core/tests/test-general.c
@@ -323,153 +323,209 @@ test_setting_vpn_modify_during_foreach (void)
static void
test_setting_ip4_config_labels (void)
{
- NMSettingIP4Config *s_ip4;
- NMIP4Address *addr;
- const char *label;
+ NMSettingIPConfig *s_ip4;
+ NMIPAddress *addr;
+ GVariant *label;
GPtrArray *addrs;
char **labels;
+ NMConnection *conn;
+ GVariant *dict, *dict2, *setting_dict, *value;
GError *error = NULL;
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
g_object_set (G_OBJECT (s_ip4),
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
NULL);
/* addr 1 */
- addr = nm_ip4_address_new ();
- nm_ip4_address_set_address (addr, 0x01010101);
- nm_ip4_address_set_prefix (addr, 24);
+ addr = nm_ip_address_new (AF_INET, "1.1.1.1", 24, &error);
+ g_assert_no_error (error);
- nm_setting_ip4_config_add_address (s_ip4, addr);
- nm_ip4_address_unref (addr);
+ nm_setting_ip_config_add_address (s_ip4, addr);
+ nm_ip_address_unref (addr);
nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
g_assert_no_error (error);
- label = _nm_setting_ip4_config_get_address_label (s_ip4, 0);
- g_assert_cmpstr (label, ==, "");
+ addr = nm_setting_ip_config_get_address (s_ip4, 0);
+ label = nm_ip_address_get_attribute (addr, "label");
+ g_assert (label == NULL);
+
+ /* The 'address-labels' property should be omitted from the serialization if
+ * there are no non-NULL labels.
+ */
+ conn = nmtst_create_minimal_connection ("label test", NULL, NM_SETTING_WIRED_SETTING_NAME, NULL);
+ nm_connection_add_setting (conn, nm_setting_duplicate (NM_SETTING (s_ip4)));
+ dict = nm_connection_to_dbus (conn, NM_CONNECTION_SERIALIZE_ALL);
+ g_object_unref (conn);
+
+ setting_dict = g_variant_lookup_value (dict, NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_VARIANT_TYPE_SETTING);
+ g_assert (setting_dict != NULL);
+
+ value = g_variant_lookup_value (setting_dict, "address-labels", NULL);
+ g_assert (value == NULL);
+
+ g_variant_unref (setting_dict);
+ g_variant_unref (dict);
+
+ /* Now back to constructing the original s_ip4... */
/* addr 2 */
- addr = nm_ip4_address_new ();
- nm_ip4_address_set_address (addr, 0x02020202);
- nm_ip4_address_set_prefix (addr, 24);
+ addr = nm_ip_address_new (AF_INET, "2.2.2.2", 24, &error);
+ g_assert_no_error (error);
+ nm_ip_address_set_attribute (addr, "label", g_variant_new_string ("eth0:1"));
- _nm_setting_ip4_config_add_address_with_label (s_ip4, addr, "eth0:1");
- nm_ip4_address_unref (addr);
+ nm_setting_ip_config_add_address (s_ip4, addr);
+ nm_ip_address_unref (addr);
nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
g_assert_no_error (error);
- label = _nm_setting_ip4_config_get_address_label (s_ip4, 1);
- g_assert_cmpstr (label, ==, "eth0:1");
+ addr = nm_setting_ip_config_get_address (s_ip4, 1);
+ label = nm_ip_address_get_attribute (addr, "label");
+ g_assert (label != NULL);
+ g_assert_cmpstr (g_variant_get_string (label, NULL), ==, "eth0:1");
/* addr 3 */
- addr = nm_ip4_address_new ();
- nm_ip4_address_set_address (addr, 0x03030303);
- nm_ip4_address_set_prefix (addr, 24);
+ addr = nm_ip_address_new (AF_INET, "3.3.3.3", 24, &error);
+ g_assert_no_error (error);
+ nm_ip_address_set_attribute (addr, "label", NULL);
- _nm_setting_ip4_config_add_address_with_label (s_ip4, addr, "");
- nm_ip4_address_unref (addr);
+ nm_setting_ip_config_add_address (s_ip4, addr);
+ nm_ip_address_unref (addr);
nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
g_assert_no_error (error);
- label = _nm_setting_ip4_config_get_address_label (s_ip4, 2);
- g_assert_cmpstr (label, ==, "");
+ addr = nm_setting_ip_config_get_address (s_ip4, 2);
+ label = nm_ip_address_get_attribute (addr, "label");
+ g_assert (label == NULL);
/* Remove addr 1 and re-verify remaining addresses */
- nm_setting_ip4_config_remove_address (s_ip4, 0);
+ nm_setting_ip_config_remove_address (s_ip4, 0);
nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
g_assert_no_error (error);
- addr = nm_setting_ip4_config_get_address (s_ip4, 0);
- g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x02020202);
- label = _nm_setting_ip4_config_get_address_label (s_ip4, 0);
- g_assert_cmpstr (label, ==, "eth0:1");
+ addr = nm_setting_ip_config_get_address (s_ip4, 0);
+ g_assert_cmpstr (nm_ip_address_get_address (addr), ==, "2.2.2.2");
+ label = nm_ip_address_get_attribute (addr, "label");
+ g_assert (label != NULL);
+ g_assert_cmpstr (g_variant_get_string (label, NULL), ==, "eth0:1");
- addr = nm_setting_ip4_config_get_address (s_ip4, 1);
- g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x03030303);
- label = _nm_setting_ip4_config_get_address_label (s_ip4, 1);
- g_assert_cmpstr (label, ==, "");
+ addr = nm_setting_ip_config_get_address (s_ip4, 1);
+ g_assert_cmpstr (nm_ip_address_get_address (addr), ==, "3.3.3.3");
+ label = nm_ip_address_get_attribute (addr, "label");
+ g_assert (label == NULL);
+ /* The labels should appear in the D-Bus serialization under both
+ * 'address-labels' and 'address-data'.
+ */
+ conn = nmtst_create_minimal_connection ("label test", NULL, NM_SETTING_WIRED_SETTING_NAME, NULL);
+ nm_connection_add_setting (conn, NM_SETTING (s_ip4));
+ dict = nm_connection_to_dbus (conn, NM_CONNECTION_SERIALIZE_ALL);
+ g_object_unref (conn);
- /* Test explicit property assignment */
- g_object_get (G_OBJECT (s_ip4),
- NM_SETTING_IP4_CONFIG_ADDRESSES, &addrs,
- "address-labels", &labels,
- NULL);
+ setting_dict = g_variant_lookup_value (dict, NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_VARIANT_TYPE_SETTING);
+ g_assert (setting_dict != NULL);
- nm_setting_ip4_config_clear_addresses (s_ip4);
- g_assert_cmpint (nm_setting_ip4_config_get_num_addresses (s_ip4), ==, 0);
+ value = g_variant_lookup_value (setting_dict, "address-labels", G_VARIANT_TYPE_STRING_ARRAY);
+ g_assert (value != NULL);
+ g_variant_get (value, "^as", &labels);
+ g_assert_cmpint (g_strv_length (labels), ==, 2);
+ g_assert_cmpstr (labels[0], ==, "eth0:1");
+ g_assert_cmpstr (labels[1], ==, "");
+ g_variant_unref (value);
+ g_strfreev (labels);
- /* Setting addrs but not labels will result in empty labels */
- g_object_set (G_OBJECT (s_ip4),
- NM_SETTING_IP4_CONFIG_ADDRESSES, addrs,
- NULL);
+ value = g_variant_lookup_value (setting_dict, "address-data", G_VARIANT_TYPE ("aa{sv}"));
+ addrs = nm_utils_ip_addresses_from_variant (value, AF_INET);
+ g_variant_unref (value);
+ g_assert (addrs != NULL);
+ g_assert_cmpint (addrs->len, ==, 2);
+ addr = addrs->pdata[0];
+ label = nm_ip_address_get_attribute (addr, "label");
+ g_assert (label != NULL);
+ g_assert_cmpstr (g_variant_get_string (label, NULL), ==, "eth0:1");
+ addr = addrs->pdata[1];
+ label = nm_ip_address_get_attribute (addr, "label");
+ g_assert (label == NULL);
g_ptr_array_unref (addrs);
- nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
+
+ g_variant_unref (setting_dict);
+
+ /* We should be able to deserialize the labels from either 'address-labels'
+ * or 'address-data'.
+ */
+ dict2 = g_variant_ref (dict);
+
+ NMTST_VARIANT_EDITOR (dict,
+ NMTST_VARIANT_DROP_PROPERTY (NM_SETTING_IP4_CONFIG_SETTING_NAME,
+ "address-data");
+ );
+ conn = nm_simple_connection_new_from_dbus (dict, &error);
g_assert_no_error (error);
- g_assert_cmpint (nm_setting_ip4_config_get_num_addresses (s_ip4), ==, 2);
+ g_variant_unref (dict);
- addr = nm_setting_ip4_config_get_address (s_ip4, 0);
- g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x02020202);
- label = _nm_setting_ip4_config_get_address_label (s_ip4, 0);
- g_assert_cmpstr (label, ==, "");
+ s_ip4 = nm_connection_get_setting_ip4_config (conn);
- addr = nm_setting_ip4_config_get_address (s_ip4, 1);
- g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x03030303);
- label = _nm_setting_ip4_config_get_address_label (s_ip4, 1);
- g_assert_cmpstr (label, ==, "");
+ addr = nm_setting_ip_config_get_address (s_ip4, 0);
+ g_assert_cmpstr (nm_ip_address_get_address (addr), ==, "2.2.2.2");
+ label = nm_ip_address_get_attribute (addr, "label");
+ g_assert (label != NULL);
+ g_assert_cmpstr (g_variant_get_string (label, NULL), ==, "eth0:1");
- /* Setting labels now will leave addresses untouched */
- g_object_set (G_OBJECT (s_ip4),
- "address-labels", labels,
- NULL);
- g_strfreev (labels);
- nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
+ addr = nm_setting_ip_config_get_address (s_ip4, 1);
+ g_assert_cmpstr (nm_ip_address_get_address (addr), ==, "3.3.3.3");
+ label = nm_ip_address_get_attribute (addr, "label");
+ g_assert (label == NULL);
+
+ g_object_unref (conn);
+
+ NMTST_VARIANT_EDITOR (dict2,
+ NMTST_VARIANT_DROP_PROPERTY (NM_SETTING_IP4_CONFIG_SETTING_NAME,
+ "address-labels");
+ );
+ conn = nm_simple_connection_new_from_dbus (dict2, &error);
g_assert_no_error (error);
- g_assert_cmpint (nm_setting_ip4_config_get_num_addresses (s_ip4), ==, 2);
+ g_variant_unref (dict2);
- addr = nm_setting_ip4_config_get_address (s_ip4, 0);
- g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x02020202);
- label = _nm_setting_ip4_config_get_address_label (s_ip4, 0);
- g_assert_cmpstr (label, ==, "eth0:1");
+ s_ip4 = nm_connection_get_setting_ip4_config (conn);
- addr = nm_setting_ip4_config_get_address (s_ip4, 1);
- g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x03030303);
- label = _nm_setting_ip4_config_get_address_label (s_ip4, 1);
- g_assert_cmpstr (label, ==, "");
+ addr = nm_setting_ip_config_get_address (s_ip4, 0);
+ g_assert_cmpstr (nm_ip_address_get_address (addr), ==, "2.2.2.2");
+ label = nm_ip_address_get_attribute (addr, "label");
+ g_assert_cmpstr (g_variant_get_string (label, NULL), ==, "eth0:1");
- /* Setting labels to a value that's too short or too long will result in
- * the setting not verifying.
- */
- labels = g_strsplit ("eth0:2", ",", -1);
- g_object_set (G_OBJECT (s_ip4),
- "address-labels", labels,
+ addr = nm_setting_ip_config_get_address (s_ip4, 1);
+ g_assert_cmpstr (nm_ip_address_get_address (addr), ==, "3.3.3.3");
+ label = nm_ip_address_get_attribute (addr, "label");
+ g_assert (label == NULL);
+
+ /* Test explicit property assignment */
+ g_object_get (G_OBJECT (s_ip4),
+ NM_SETTING_IP_CONFIG_ADDRESSES, &addrs,
NULL);
- g_strfreev (labels);
- nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
- g_assert_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY);
- g_assert (g_str_has_prefix (error->message, "ipv4.address-labels:"));
- g_clear_error (&error);
+ nm_setting_ip_config_clear_addresses (s_ip4);
+ g_assert_cmpint (nm_setting_ip_config_get_num_addresses (s_ip4), ==, 0);
- labels = g_strsplit ("eth0:2,eth0:3", ",", -1);
g_object_set (G_OBJECT (s_ip4),
- "address-labels", labels,
+ NM_SETTING_IP_CONFIG_ADDRESSES, addrs,
NULL);
- g_strfreev (labels);
+ g_ptr_array_unref (addrs);
nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
g_assert_no_error (error);
+ g_assert_cmpint (nm_setting_ip_config_get_num_addresses (s_ip4), ==, 2);
- labels = g_strsplit ("eth0:2,eth0:3,eth0:4", ",", -1);
- g_object_set (G_OBJECT (s_ip4),
- "address-labels", labels,
- NULL);
- g_strfreev (labels);
- nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
- g_assert_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY);
- g_assert (g_str_has_prefix (error->message, "ipv4.address-labels:"));
- g_clear_error (&error);
+ addr = nm_setting_ip_config_get_address (s_ip4, 0);
+ g_assert_cmpstr (nm_ip_address_get_address (addr), ==, "2.2.2.2");
+ label = nm_ip_address_get_attribute (addr, "label");
+ g_assert (label != NULL);
+ g_assert_cmpstr (g_variant_get_string (label, NULL), ==, "eth0:1");
- g_object_unref (s_ip4);
+ addr = nm_setting_ip_config_get_address (s_ip4, 1);
+ g_assert_cmpstr (nm_ip_address_get_address (addr), ==, "3.3.3.3");
+ label = nm_ip_address_get_attribute (addr, "label");
+ g_assert (label == NULL);
+
+ g_object_unref (conn);
}
static void
@@ -1005,8 +1061,8 @@ new_test_connection (void)
setting = nm_setting_ip4_config_new ();
g_object_set (G_OBJECT (setting),
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
- NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, "eyeofthetiger",
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, "eyeofthetiger",
NULL);
nm_connection_add_setting (connection, setting);
@@ -1054,7 +1110,7 @@ new_connection_dict (char **out_uuid,
/* IP6 */
g_variant_builder_init (&setting_builder, NM_VARIANT_TYPE_SETTING);
g_variant_builder_add (&setting_builder, "{sv}",
- NM_SETTING_IP6_CONFIG_METHOD,
+ NM_SETTING_IP_CONFIG_METHOD,
g_variant_new_string (*out_expected_ip6_method));
g_variant_builder_add (&conn_builder, "{sa{sv}}",
NM_SETTING_IP6_CONFIG_SETTING_NAME,
@@ -1071,7 +1127,7 @@ test_connection_replace_settings (void)
GError *error = NULL;
gboolean success;
NMSettingConnection *s_con;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip6;
char *uuid = NULL;
const char *expected_id = NULL, *expected_method = NULL;
@@ -1095,7 +1151,7 @@ test_connection_replace_settings (void)
s_ip6 = nm_connection_get_setting_ip6_config (connection);
g_assert (s_ip6);
- g_assert_cmpstr (nm_setting_ip6_config_get_method (s_ip6), ==, expected_method);
+ g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, expected_method);
g_free (uuid);
g_variant_unref (new_settings);
@@ -1226,7 +1282,7 @@ test_connection_new_from_dbus (void)
GVariant *new_settings;
GError *error = NULL;
NMSettingConnection *s_con;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip6;
char *uuid = NULL;
const char *expected_id = NULL, *expected_method = NULL;
@@ -1248,7 +1304,7 @@ test_connection_new_from_dbus (void)
s_ip6 = nm_connection_get_setting_ip6_config (connection);
g_assert (s_ip6);
- g_assert_cmpstr (nm_setting_ip6_config_get_method (s_ip6), ==, expected_method);
+ g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, expected_method);
g_free (uuid);
g_variant_unref (new_settings);
@@ -1639,19 +1695,20 @@ test_connection_diff_a_only (void)
{ NULL, NM_SETTING_DIFF_RESULT_UNKNOWN },
} },
{ NM_SETTING_IP4_CONFIG_SETTING_NAME, {
- { NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_DIFF_RESULT_IN_A },
- { NM_SETTING_IP4_CONFIG_DNS, NM_SETTING_DIFF_RESULT_IN_A },
- { NM_SETTING_IP4_CONFIG_DNS_SEARCH, NM_SETTING_DIFF_RESULT_IN_A },
- { NM_SETTING_IP4_CONFIG_ADDRESSES, NM_SETTING_DIFF_RESULT_IN_A },
- { "address-labels", NM_SETTING_DIFF_RESULT_IN_A },
- { NM_SETTING_IP4_CONFIG_ROUTES, NM_SETTING_DIFF_RESULT_IN_A },
- { NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES, NM_SETTING_DIFF_RESULT_IN_A },
- { NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, NM_SETTING_DIFF_RESULT_IN_A },
- { NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, NM_SETTING_DIFF_RESULT_IN_A },
- { NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME, NM_SETTING_DIFF_RESULT_IN_A },
- { NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, NM_SETTING_DIFF_RESULT_IN_A },
- { NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, NM_SETTING_DIFF_RESULT_IN_A },
- { NM_SETTING_IP4_CONFIG_MAY_FAIL, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_IP_CONFIG_DNS, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_IP_CONFIG_DNS_SEARCH, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_IP_CONFIG_ADDRESSES, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_IP_CONFIG_GATEWAY, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_IP_CONFIG_ROUTES, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_IP_CONFIG_ROUTE_METRIC, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_IP_CONFIG_NEVER_DEFAULT, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_IP_CONFIG_MAY_FAIL, NM_SETTING_DIFF_RESULT_IN_A },
{ NULL, NM_SETTING_DIFF_RESULT_UNKNOWN },
} },
};
@@ -1691,11 +1748,11 @@ test_connection_diff_different (void)
{
NMConnection *a, *b;
GHashTable *out_diffs = NULL;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
gboolean same;
const DiffSetting settings[] = {
{ NM_SETTING_IP4_CONFIG_SETTING_NAME, {
- { NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_DIFF_RESULT_IN_A | NM_SETTING_DIFF_RESULT_IN_B },
+ { NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_DIFF_RESULT_IN_A | NM_SETTING_DIFF_RESULT_IN_B },
{ NULL, NM_SETTING_DIFF_RESULT_UNKNOWN },
} },
};
@@ -1705,7 +1762,7 @@ test_connection_diff_different (void)
s_ip4 = nm_connection_get_setting_ip4_config (a);
g_assert (s_ip4);
g_object_set (G_OBJECT (s_ip4),
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
NULL);
same = nm_connection_diff (a, b, NM_SETTING_COMPARE_FLAG_EXACT, &out_diffs);
@@ -1776,7 +1833,7 @@ test_connection_diff_inferrable (void)
gboolean same;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
char *uuid;
const DiffSetting settings[] = {
{ NM_SETTING_CONNECTION_SETTING_NAME, {
@@ -1804,7 +1861,7 @@ test_connection_diff_inferrable (void)
s_ip4 = nm_connection_get_setting_ip4_config (a);
g_assert (s_ip4);
- g_object_set (G_OBJECT (s_ip4), NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, TRUE, NULL);
+ g_object_set (G_OBJECT (s_ip4), NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, TRUE, NULL);
/* Make sure the diff returns no results as secrets are ignored */
same = nm_connection_diff (a, b, NM_SETTING_COMPARE_FLAG_INFERRABLE, &out_diffs);
@@ -1846,11 +1903,11 @@ add_generic_settings (NMConnection *connection, const char *ctype)
g_free (uuid);
setting = nm_setting_ip4_config_new ();
- g_object_set (setting, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (setting, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
nm_connection_add_setting (connection, setting);
setting = nm_setting_ip6_config_new ();
- g_object_set (setting, NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (setting, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL);
nm_connection_add_setting (connection, setting);
}
@@ -2456,9 +2513,10 @@ test_setting_ip4_changed_signal (void)
{
NMConnection *connection;
gboolean changed = FALSE;
- NMSettingIP4Config *s_ip4;
- NMIP4Address *addr;
- NMIP4Route *route;
+ NMSettingIPConfig *s_ip4;
+ NMIPAddress *addr;
+ NMIPRoute *route;
+ GError *error = NULL;
connection = nm_simple_connection_new ();
g_signal_connect (connection,
@@ -2466,58 +2524,56 @@ test_setting_ip4_changed_signal (void)
(GCallback) test_connection_changed_cb,
&changed);
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- ASSERT_CHANGED (nm_setting_ip4_config_add_dns (s_ip4, "11.22.0.0"));
- ASSERT_CHANGED (nm_setting_ip4_config_remove_dns (s_ip4, 0));
+ ASSERT_CHANGED (nm_setting_ip_config_add_dns (s_ip4, "11.22.0.0"));
+ ASSERT_CHANGED (nm_setting_ip_config_remove_dns (s_ip4, 0));
- g_test_expect_message ("libnm", G_LOG_LEVEL_CRITICAL, "*elt != NULL*");
- ASSERT_UNCHANGED (nm_setting_ip4_config_remove_dns (s_ip4, 1));
+ g_test_expect_message ("libnm", G_LOG_LEVEL_CRITICAL, "*i < priv->dns->len*");
+ ASSERT_UNCHANGED (nm_setting_ip_config_remove_dns (s_ip4, 1));
g_test_assert_expected_messages ();
- nm_setting_ip4_config_add_dns (s_ip4, "33.44.0.0");
- ASSERT_CHANGED (nm_setting_ip4_config_clear_dns (s_ip4));
+ nm_setting_ip_config_add_dns (s_ip4, "33.44.0.0");
+ ASSERT_CHANGED (nm_setting_ip_config_clear_dns (s_ip4));
- ASSERT_CHANGED (nm_setting_ip4_config_add_dns_search (s_ip4, "foobar.com"));
- ASSERT_CHANGED (nm_setting_ip4_config_remove_dns_search (s_ip4, 0));
+ ASSERT_CHANGED (nm_setting_ip_config_add_dns_search (s_ip4, "foobar.com"));
+ ASSERT_CHANGED (nm_setting_ip_config_remove_dns_search (s_ip4, 0));
- g_test_expect_message ("libnm", G_LOG_LEVEL_CRITICAL, "*elt != NULL*");
- ASSERT_UNCHANGED (nm_setting_ip4_config_remove_dns_search (s_ip4, 1));
+ g_test_expect_message ("libnm", G_LOG_LEVEL_CRITICAL, "*i < priv->dns_search->len*");
+ ASSERT_UNCHANGED (nm_setting_ip_config_remove_dns_search (s_ip4, 1));
g_test_assert_expected_messages ();
- ASSERT_CHANGED (nm_setting_ip4_config_add_dns_search (s_ip4, "foobar.com"));
- ASSERT_CHANGED (nm_setting_ip4_config_clear_dns_searches (s_ip4));
+ ASSERT_CHANGED (nm_setting_ip_config_add_dns_search (s_ip4, "foobar.com"));
+ ASSERT_CHANGED (nm_setting_ip_config_clear_dns_searches (s_ip4));
- addr = nm_ip4_address_new ();
- nm_ip4_address_set_address (addr, 0x2233);
- nm_ip4_address_set_prefix (addr, 24);
- ASSERT_CHANGED (nm_setting_ip4_config_add_address (s_ip4, addr));
- ASSERT_CHANGED (nm_setting_ip4_config_remove_address (s_ip4, 0));
+ addr = nm_ip_address_new (AF_INET, "22.33.0.0", 24, &error);
+ g_assert_no_error (error);
+ ASSERT_CHANGED (nm_setting_ip_config_add_address (s_ip4, addr));
+ ASSERT_CHANGED (nm_setting_ip_config_remove_address (s_ip4, 0));
- g_test_expect_message ("libnm", G_LOG_LEVEL_CRITICAL, "*addr != NULL && label != NULL*");
- ASSERT_UNCHANGED (nm_setting_ip4_config_remove_address (s_ip4, 1));
+ g_test_expect_message ("libnm", G_LOG_LEVEL_CRITICAL, "*i < priv->addresses->len*");
+ ASSERT_UNCHANGED (nm_setting_ip_config_remove_address (s_ip4, 1));
g_test_assert_expected_messages ();
- nm_setting_ip4_config_add_address (s_ip4, addr);
- ASSERT_CHANGED (nm_setting_ip4_config_clear_addresses (s_ip4));
+ nm_setting_ip_config_add_address (s_ip4, addr);
+ ASSERT_CHANGED (nm_setting_ip_config_clear_addresses (s_ip4));
- route = nm_ip4_route_new ();
- nm_ip4_route_set_dest (route, 0x2233);
- nm_ip4_route_set_prefix (route, 24);
+ route = nm_ip_route_new (AF_INET, "22.33.0.0", 24, NULL, 0, &error);
+ g_assert_no_error (error);
- ASSERT_CHANGED (nm_setting_ip4_config_add_route (s_ip4, route));
- ASSERT_CHANGED (nm_setting_ip4_config_remove_route (s_ip4, 0));
+ ASSERT_CHANGED (nm_setting_ip_config_add_route (s_ip4, route));
+ ASSERT_CHANGED (nm_setting_ip_config_remove_route (s_ip4, 0));
- g_test_expect_message ("libnm", G_LOG_LEVEL_CRITICAL, "*elt != NULL*");
- ASSERT_UNCHANGED (nm_setting_ip4_config_remove_route (s_ip4, 1));
+ g_test_expect_message ("libnm", G_LOG_LEVEL_CRITICAL, "*i < priv->routes->len*");
+ ASSERT_UNCHANGED (nm_setting_ip_config_remove_route (s_ip4, 1));
g_test_assert_expected_messages ();
- nm_setting_ip4_config_add_route (s_ip4, route);
- ASSERT_CHANGED (nm_setting_ip4_config_clear_routes (s_ip4));
+ nm_setting_ip_config_add_route (s_ip4, route);
+ ASSERT_CHANGED (nm_setting_ip_config_clear_routes (s_ip4));
- nm_ip4_address_unref (addr);
- nm_ip4_route_unref (route);
+ nm_ip_address_unref (addr);
+ nm_ip_route_unref (route);
g_object_unref (connection);
}
@@ -2526,10 +2582,10 @@ test_setting_ip6_changed_signal (void)
{
NMConnection *connection;
gboolean changed = FALSE;
- NMSettingIP6Config *s_ip6;
- NMIP6Address *addr;
- NMIP6Route *route;
- const struct in6_addr t = { { { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 } } };
+ NMSettingIPConfig *s_ip6;
+ NMIPAddress *addr;
+ NMIPRoute *route;
+ GError *error = NULL;
connection = nm_simple_connection_new ();
g_signal_connect (connection,
@@ -2537,59 +2593,57 @@ test_setting_ip6_changed_signal (void)
(GCallback) test_connection_changed_cb,
&changed);
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
- ASSERT_CHANGED (nm_setting_ip6_config_add_dns (s_ip6, "1:2:3::4:5:6"));
- ASSERT_CHANGED (nm_setting_ip6_config_remove_dns (s_ip6, 0));
+ ASSERT_CHANGED (nm_setting_ip_config_add_dns (s_ip6, "1:2:3::4:5:6"));
+ ASSERT_CHANGED (nm_setting_ip_config_remove_dns (s_ip6, 0));
- g_test_expect_message ("libnm", G_LOG_LEVEL_CRITICAL, "*elt != NULL*");
- ASSERT_UNCHANGED (nm_setting_ip6_config_remove_dns (s_ip6, 1));
+ g_test_expect_message ("libnm", G_LOG_LEVEL_CRITICAL, "*i < priv->dns->len*");
+ ASSERT_UNCHANGED (nm_setting_ip_config_remove_dns (s_ip6, 1));
g_test_assert_expected_messages ();
- nm_setting_ip6_config_add_dns (s_ip6, "1:2:3::4:5:6");
- ASSERT_CHANGED (nm_setting_ip6_config_clear_dns (s_ip6));
+ nm_setting_ip_config_add_dns (s_ip6, "1:2:3::4:5:6");
+ ASSERT_CHANGED (nm_setting_ip_config_clear_dns (s_ip6));
- ASSERT_CHANGED (nm_setting_ip6_config_add_dns_search (s_ip6, "foobar.com"));
- ASSERT_CHANGED (nm_setting_ip6_config_remove_dns_search (s_ip6, 0));
+ ASSERT_CHANGED (nm_setting_ip_config_add_dns_search (s_ip6, "foobar.com"));
+ ASSERT_CHANGED (nm_setting_ip_config_remove_dns_search (s_ip6, 0));
- g_test_expect_message ("libnm", G_LOG_LEVEL_CRITICAL, "*elt != NULL*");
- ASSERT_UNCHANGED (nm_setting_ip6_config_remove_dns_search (s_ip6, 1));
+ g_test_expect_message ("libnm", G_LOG_LEVEL_CRITICAL, "*i < priv->dns_search->len*");
+ ASSERT_UNCHANGED (nm_setting_ip_config_remove_dns_search (s_ip6, 1));
g_test_assert_expected_messages ();
- nm_setting_ip6_config_add_dns_search (s_ip6, "foobar.com");
- ASSERT_CHANGED (nm_setting_ip6_config_clear_dns_searches (s_ip6));
+ nm_setting_ip_config_add_dns_search (s_ip6, "foobar.com");
+ ASSERT_CHANGED (nm_setting_ip_config_clear_dns_searches (s_ip6));
- addr = nm_ip6_address_new ();
- nm_ip6_address_set_address (addr, &t);
- nm_ip6_address_set_prefix (addr, 64);
+ addr = nm_ip_address_new (AF_INET6, "1:2:3::4:5:6", 64, &error);
+ g_assert_no_error (error);
- ASSERT_CHANGED (nm_setting_ip6_config_add_address (s_ip6, addr));
- ASSERT_CHANGED (nm_setting_ip6_config_remove_address (s_ip6, 0));
+ ASSERT_CHANGED (nm_setting_ip_config_add_address (s_ip6, addr));
+ ASSERT_CHANGED (nm_setting_ip_config_remove_address (s_ip6, 0));
- g_test_expect_message ("libnm", G_LOG_LEVEL_CRITICAL, "*elt != NULL*");
- ASSERT_UNCHANGED (nm_setting_ip6_config_remove_address (s_ip6, 1));
+ g_test_expect_message ("libnm", G_LOG_LEVEL_CRITICAL, "*i < priv->addresses->len*");
+ ASSERT_UNCHANGED (nm_setting_ip_config_remove_address (s_ip6, 1));
g_test_assert_expected_messages ();
- nm_setting_ip6_config_add_address (s_ip6, addr);
- ASSERT_CHANGED (nm_setting_ip6_config_clear_addresses (s_ip6));
+ nm_setting_ip_config_add_address (s_ip6, addr);
+ ASSERT_CHANGED (nm_setting_ip_config_clear_addresses (s_ip6));
- route = nm_ip6_route_new ();
- nm_ip6_route_set_dest (route, &t);
- nm_ip6_route_set_prefix (route, 128);
+ route = nm_ip_route_new (AF_INET6, "1:2:3::4:5:6", 128, NULL, 0, &error);
+ g_assert_no_error (error);
- ASSERT_CHANGED (nm_setting_ip6_config_add_route (s_ip6, route));
- ASSERT_CHANGED (nm_setting_ip6_config_remove_route (s_ip6, 0));
+ ASSERT_CHANGED (nm_setting_ip_config_add_route (s_ip6, route));
+ ASSERT_CHANGED (nm_setting_ip_config_remove_route (s_ip6, 0));
- g_test_expect_message ("libnm", G_LOG_LEVEL_CRITICAL, "*elt != NULL*");
- ASSERT_UNCHANGED (nm_setting_ip6_config_remove_route (s_ip6, 1));
+ g_test_expect_message ("libnm", G_LOG_LEVEL_CRITICAL, "*i < priv->routes->len*");
+ ASSERT_UNCHANGED (nm_setting_ip_config_remove_route (s_ip6, 1));
g_test_assert_expected_messages ();
- nm_setting_ip6_config_add_route (s_ip6, route);
- ASSERT_CHANGED (nm_setting_ip6_config_clear_routes (s_ip6));
+ nm_setting_ip_config_add_route (s_ip6, route);
+ ASSERT_CHANGED (nm_setting_ip_config_clear_routes (s_ip6));
- nm_ip6_address_unref (addr);
- nm_ip6_route_unref (route);
+ nm_ip_address_unref (addr);
+ nm_ip_route_unref (route);
g_object_unref (connection);
}
@@ -2847,12 +2901,12 @@ test_connection_normalize_virtual_iface_name (void)
nm_connection_add_setting (con,
g_object_new (NM_TYPE_SETTING_IP4_CONFIG,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
NULL));
nm_connection_add_setting (con,
g_object_new (NM_TYPE_SETTING_IP6_CONFIG,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
NULL));
s_vlan = nm_connection_get_setting_vlan (con);
@@ -3349,6 +3403,188 @@ test_connection_normalize_infiniband_mtu (void)
g_assert_cmpint (65520, ==, nm_setting_infiniband_get_mtu (s_infini));
}
+static void
+test_setting_ip4_gateway (void)
+{
+ NMConnection *conn;
+ NMSettingIPConfig *s_ip4;
+ NMIPAddress *addr;
+ GVariant *conn_dict, *ip4_dict, *value;
+ GVariantIter iter;
+ GVariant *addr_var;
+ GError *error = NULL;
+
+ /* When serializing, ipv4.gateway is copied to the first entry of ipv4.addresses */
+ conn = nmtst_create_minimal_connection ("test_setting_ip4_gateway", NULL,
+ NM_SETTING_WIRED_SETTING_NAME, NULL);
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
+ g_object_set (s_ip4,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_GATEWAY, "192.168.1.1",
+ NULL);
+ nm_connection_add_setting (conn, NM_SETTING (s_ip4));
+
+ addr = nm_ip_address_new (AF_INET, "192.168.1.10", 24, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_address (s_ip4, addr);
+ nm_ip_address_unref (addr);
+
+ conn_dict = nm_connection_to_dbus (conn, NM_CONNECTION_SERIALIZE_ALL);
+ g_object_unref (conn);
+
+ ip4_dict = g_variant_lookup_value (conn_dict, NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_VARIANT_TYPE_SETTING);
+ g_assert (ip4_dict != NULL);
+
+ value = g_variant_lookup_value (ip4_dict, NM_SETTING_IP_CONFIG_GATEWAY, G_VARIANT_TYPE_STRING);
+ g_assert (value != NULL);
+ g_assert_cmpstr (g_variant_get_string (value, NULL), ==, "192.168.1.1");
+ g_variant_unref (value);
+
+ value = g_variant_lookup_value (ip4_dict, NM_SETTING_IP_CONFIG_ADDRESSES, G_VARIANT_TYPE ("aau"));
+ g_assert (value != NULL);
+
+ g_variant_iter_init (&iter, value);
+ while (g_variant_iter_next (&iter, "@au", &addr_var)) {
+ const guint32 *addr_array;
+ gsize length;
+
+ addr_array = g_variant_get_fixed_array (addr_var, &length, sizeof (guint32));
+ g_assert_cmpint (length, ==, 3);
+ g_assert_cmpstr (nm_utils_inet4_ntop (addr_array[2], NULL), ==, "192.168.1.1");
+ g_variant_unref (addr_var);
+ }
+ g_variant_unref (value);
+
+ g_variant_unref (ip4_dict);
+
+ /* When deserializing an old-style connection, the gateway from the first address
+ * is copied to :gateway.
+ */
+ NMTST_VARIANT_EDITOR (conn_dict,
+ NMTST_VARIANT_DROP_PROPERTY (NM_SETTING_IP4_CONFIG_SETTING_NAME,
+ NM_SETTING_IP_CONFIG_GATEWAY);
+ NMTST_VARIANT_DROP_PROPERTY (NM_SETTING_IP4_CONFIG_SETTING_NAME,
+ "address-data");
+ );
+
+ conn = nm_simple_connection_new_from_dbus (conn_dict, &error);
+ g_variant_unref (conn_dict);
+ g_assert_no_error (error);
+
+ s_ip4 = (NMSettingIPConfig *) nm_connection_get_setting_ip4_config (conn);
+ g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, "192.168.1.1");
+
+ g_object_unref (conn);
+}
+
+static void
+test_setting_ip6_gateway (void)
+{
+ NMConnection *conn;
+ NMSettingIPConfig *s_ip6;
+ NMIPAddress *addr;
+ GVariant *conn_dict, *ip6_dict, *value;
+ GVariantIter iter;
+ GVariant *gateway_var;
+ GError *error = NULL;
+
+ /* When serializing, ipv6.gateway is copied to the first entry of ipv6.addresses */
+ conn = nmtst_create_minimal_connection ("test_setting_ip6_gateway", NULL,
+ NM_SETTING_WIRED_SETTING_NAME, NULL);
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
+ g_object_set (s_ip6,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_GATEWAY, "abcd::1",
+ NULL);
+ nm_connection_add_setting (conn, NM_SETTING (s_ip6));
+
+ addr = nm_ip_address_new (AF_INET6, "abcd::10", 64, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_address (s_ip6, addr);
+ nm_ip_address_unref (addr);
+
+ conn_dict = nm_connection_to_dbus (conn, NM_CONNECTION_SERIALIZE_ALL);
+ g_object_unref (conn);
+
+ ip6_dict = g_variant_lookup_value (conn_dict, NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_VARIANT_TYPE_SETTING);
+ g_assert (ip6_dict != NULL);
+
+ value = g_variant_lookup_value (ip6_dict, NM_SETTING_IP_CONFIG_GATEWAY, G_VARIANT_TYPE_STRING);
+ g_assert (value != NULL);
+ g_assert_cmpstr (g_variant_get_string (value, NULL), ==, "abcd::1");
+
+ value = g_variant_lookup_value (ip6_dict, NM_SETTING_IP_CONFIG_ADDRESSES, G_VARIANT_TYPE ("a(ayuay)"));
+ g_assert (value != NULL);
+
+ g_variant_iter_init (&iter, value);
+ while (g_variant_iter_next (&iter, "(@ayu@ay)", NULL, NULL, &gateway_var)) {
+ const guint8 *gateway_bytes;
+ gsize length;
+
+ gateway_bytes = g_variant_get_fixed_array (gateway_var, &length, 1);
+ g_assert_cmpint (length, ==, 16);
+ g_assert_cmpstr (nm_utils_inet6_ntop ((struct in6_addr *) gateway_bytes, NULL), ==, "abcd::1");
+ g_variant_unref (gateway_var);
+ }
+ g_variant_unref (value);
+
+ g_variant_unref (ip6_dict);
+
+ /* When deserializing an old-style connection, the gateway from the first address
+ * is copied to :gateway.
+ */
+ NMTST_VARIANT_EDITOR (conn_dict,
+ NMTST_VARIANT_DROP_PROPERTY (NM_SETTING_IP6_CONFIG_SETTING_NAME,
+ NM_SETTING_IP_CONFIG_GATEWAY);
+ NMTST_VARIANT_DROP_PROPERTY (NM_SETTING_IP6_CONFIG_SETTING_NAME,
+ "address-data");
+ );
+
+ conn = nm_simple_connection_new_from_dbus (conn_dict, &error);
+ g_variant_unref (conn_dict);
+ g_assert_no_error (error);
+
+ s_ip6 = (NMSettingIPConfig *) nm_connection_get_setting_ip6_config (conn);
+ g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip6), ==, "abcd::1");
+
+ g_object_unref (conn);
+}
+
+typedef struct {
+ const char *str;
+ const guint8 expected[20];
+ const guint expected_len;
+} HexItem;
+
+static void
+test_hexstr2bin (void)
+{
+ static const HexItem items[] = {
+ { "aaBBCCddDD10496a", { 0xaa, 0xbb, 0xcc, 0xdd, 0xdd, 0x10, 0x49, 0x6a }, 8 },
+ { "aa:bb:cc:dd:10:49:6a", { 0xaa, 0xbb, 0xcc, 0xdd, 0x10, 0x49, 0x6a }, 7 },
+ { "0xccddeeff", { 0xcc, 0xdd, 0xee, 0xff }, 4 },
+ { "1:2:66:77:80", { 0x01, 0x02, 0x66, 0x77, 0x80 }, 5 },
+ { "e", { 0x0e }, 1 },
+ { "aabb1199:" },
+ { ":aabb1199" },
+ { "aabb$$dd" },
+ { "aab:ccc:ddd" },
+ { "aab::ccc:ddd" },
+ };
+ GBytes *b;
+ guint i;
+
+ for (i = 0; i < G_N_ELEMENTS (items); i++) {
+ b = nm_utils_hexstr2bin (items[i].str);
+ if (items[i].expected_len) {
+ g_assert (b);
+ g_assert_cmpint (g_bytes_get_size (b), ==, items[i].expected_len);
+ g_assert (memcmp (g_bytes_get_data (b, NULL), items[i].expected, g_bytes_get_size (b)) == 0);
+ } else
+ g_assert (b == NULL);
+ }
+}
+
NMTST_DEFINE ();
int main (int argc, char **argv)
@@ -3437,6 +3673,10 @@ int main (int argc, char **argv)
g_test_add_func ("/core/general/test_setting_wireless_changed_signal", test_setting_wireless_changed_signal);
g_test_add_func ("/core/general/test_setting_wireless_security_changed_signal", test_setting_wireless_security_changed_signal);
g_test_add_func ("/core/general/test_setting_802_1x_changed_signal", test_setting_802_1x_changed_signal);
+ g_test_add_func ("/core/general/test_setting_ip4_gateway", test_setting_ip4_gateway);
+ g_test_add_func ("/core/general/test_setting_ip6_gateway", test_setting_ip6_gateway);
+
+ g_test_add_func ("/core/general/hexstr2bin", test_hexstr2bin);
return g_test_run ();
}
diff --git a/libnm-core/tests/test-secrets.c b/libnm-core/tests/test-secrets.c
index b93a1ba155..bb4b4daea5 100644
--- a/libnm-core/tests/test-secrets.c
+++ b/libnm-core/tests/test-secrets.c
@@ -125,7 +125,7 @@ make_tls_connection (const char *detail, NMSetting8021xCKScheme scheme)
s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
detail, "failed to verify connection: %s",
@@ -293,7 +293,7 @@ make_tls_phase2_connection (const char *detail, NMSetting8021xCKScheme scheme)
s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
detail, "failed to verify connection: %s",
diff --git a/libnm-util/generate-setting-docs.py b/libnm-util/generate-setting-docs.py
index 69b115a7e1..463d0f2ec7 100755
--- a/libnm-util/generate-setting-docs.py
+++ b/libnm-util/generate-setting-docs.py
@@ -48,7 +48,11 @@ identifier_key = '{%s}identifier' % ns_map['c']
nick_key = '{%s}nick' % ns_map['glib']
symbol_prefix_key = '{%s}symbol-prefix' % ns_map['c']
-constants = { 'TRUE': 'TRUE', 'FALSE': 'FALSE', 'NULL': 'NULL' }
+constants = {
+ 'TRUE': 'TRUE',
+ 'FALSE': 'FALSE',
+ 'G_MAXUINT32': 'G_MAXUINT32',
+ 'NULL': 'NULL' }
setting_names = {}
def init_constants(girxml):
diff --git a/libnm-util/libnm-util.ver b/libnm-util/libnm-util.ver
index c6fc0d7f69..794cc87f43 100644
--- a/libnm-util/libnm-util.ver
+++ b/libnm-util/libnm-util.ver
@@ -367,6 +367,7 @@ global:
nm_setting_ip4_config_get_num_dns_searches;
nm_setting_ip4_config_get_num_routes;
nm_setting_ip4_config_get_route;
+ nm_setting_ip4_config_get_route_metric;
nm_setting_ip4_config_get_type;
nm_setting_ip4_config_new;
nm_setting_ip4_config_remove_address;
@@ -402,6 +403,7 @@ global:
nm_setting_ip6_config_get_num_dns_searches;
nm_setting_ip6_config_get_num_routes;
nm_setting_ip6_config_get_route;
+ nm_setting_ip6_config_get_route_metric;
nm_setting_ip6_config_get_type;
nm_setting_ip6_config_new;
nm_setting_ip6_config_privacy_get_type;
diff --git a/libnm-util/nm-setting-ip4-config.c b/libnm-util/nm-setting-ip4-config.c
index f7f709ec54..c7a730769c 100644
--- a/libnm-util/nm-setting-ip4-config.c
+++ b/libnm-util/nm-setting-ip4-config.c
@@ -76,6 +76,7 @@ typedef struct {
GSList *dns_search; /* list of strings */
GSList *addresses; /* array of NMIP4Address */
GSList *routes; /* array of NMIP4Route */
+ gint64 route_metric;
gboolean ignore_auto_routes;
gboolean ignore_auto_dns;
char *dhcp_client_id;
@@ -92,6 +93,7 @@ enum {
PROP_DNS_SEARCH,
PROP_ADDRESSES,
PROP_ROUTES,
+ PROP_ROUTE_METRIC,
PROP_IGNORE_AUTO_ROUTES,
PROP_IGNORE_AUTO_DNS,
PROP_DHCP_CLIENT_ID,
@@ -689,6 +691,26 @@ nm_setting_ip4_config_clear_routes (NMSettingIP4Config *setting)
}
/**
+ * nm_setting_ip4_config_get_route_metric:
+ * @setting: the #NMSettingIP4Config
+ *
+ * Returns the value contained in the #NMSettingIP4Config:route-metric
+ * property.
+ *
+ * Returns: the route metric that is used for IPv4 routes that don't explicitly
+ * specify a metric. See #NMSettingIP4Config:route-metric for more details.
+ *
+ * Since: 1.0
+ **/
+gint64
+nm_setting_ip4_config_get_route_metric (NMSettingIP4Config *setting)
+{
+ g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), -1);
+
+ return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->route_metric;
+}
+
+/**
* nm_setting_ip4_config_get_ignore_auto_routes:
* @setting: the #NMSettingIP4Config
*
@@ -1018,6 +1040,9 @@ set_property (GObject *object, guint prop_id,
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
priv->routes = nm_utils_ip4_routes_from_gvalue (value);
break;
+ case PROP_ROUTE_METRIC:
+ priv->route_metric = g_value_get_int64 (value);
+ break;
case PROP_IGNORE_AUTO_ROUTES:
priv->ignore_auto_routes = g_value_get_boolean (value);
break;
@@ -1070,6 +1095,9 @@ get_property (GObject *object, guint prop_id,
case PROP_ROUTES:
nm_utils_ip4_routes_to_gvalue (priv->routes, value);
break;
+ case PROP_ROUTE_METRIC:
+ g_value_set_int64 (value, priv->route_metric);
+ break;
case PROP_IGNORE_AUTO_ROUTES:
g_value_set_boolean (value, nm_setting_ip4_config_get_ignore_auto_routes (setting));
break;
@@ -1276,6 +1304,28 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *setting_class)
G_PARAM_STATIC_STRINGS));
/**
+ * NMSettingIP4Config:route-metric:
+ *
+ * The default metric for routes that don't explicitly specify a metric.
+ * The default value -1 means that the metric is choosen automatically
+ * based on the device type.
+ * The metric applies to dynamic routes, manual (static) routes that
+ * don't have an explicit metric setting, address prefix routes, and
+ * the default route.
+ * As the linux kernel accepts zero (0) as a valid metric, zero is
+ * a valid value.
+ *
+ * Since: 1.0
+ **/
+ g_object_class_install_property
+ (object_class, PROP_ROUTE_METRIC,
+ g_param_spec_int64 (NM_SETTING_IP4_CONFIG_ROUTE_METRIC, "", "",
+ -1, G_MAXUINT32, -1,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
* NMSettingIP4Config:ignore-auto-routes:
*
* When the method is set to "auto" and this property to %TRUE,
diff --git a/libnm-util/nm-setting-ip4-config.h b/libnm-util/nm-setting-ip4-config.h
index 1b7c23072d..6e9a9a227a 100644
--- a/libnm-util/nm-setting-ip4-config.h
+++ b/libnm-util/nm-setting-ip4-config.h
@@ -60,6 +60,7 @@ GQuark nm_setting_ip4_config_error_quark (void);
#define NM_SETTING_IP4_CONFIG_DNS_SEARCH "dns-search"
#define NM_SETTING_IP4_CONFIG_ADDRESSES "addresses"
#define NM_SETTING_IP4_CONFIG_ROUTES "routes"
+#define NM_SETTING_IP4_CONFIG_ROUTE_METRIC "route-metric"
#define NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES "ignore-auto-routes"
#define NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS "ignore-auto-dns"
#define NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID "dhcp-client-id"
@@ -214,6 +215,9 @@ NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_ip4_config_remove_route_by_value (NMSettingIP4Config *setting, NMIP4Route *route);
void nm_setting_ip4_config_clear_routes (NMSettingIP4Config *setting);
+NM_AVAILABLE_IN_1_0
+gint64 nm_setting_ip4_config_get_route_metric (NMSettingIP4Config *setting);
+
gboolean nm_setting_ip4_config_get_ignore_auto_routes (NMSettingIP4Config *setting);
gboolean nm_setting_ip4_config_get_ignore_auto_dns (NMSettingIP4Config *setting);
const char * nm_setting_ip4_config_get_dhcp_client_id (NMSettingIP4Config *setting);
diff --git a/libnm-util/nm-setting-ip6-config.c b/libnm-util/nm-setting-ip6-config.c
index ec90fd2bd7..64a81136a9 100644
--- a/libnm-util/nm-setting-ip6-config.c
+++ b/libnm-util/nm-setting-ip6-config.c
@@ -75,6 +75,7 @@ typedef struct {
GSList *dns_search; /* list of strings */
GSList *addresses; /* array of NMIP6Address */
GSList *routes; /* array of NMIP6Route */
+ gint64 route_metric;
gboolean ignore_auto_routes;
gboolean ignore_auto_dns;
gboolean never_default;
@@ -91,6 +92,7 @@ enum {
PROP_DNS_SEARCH,
PROP_ADDRESSES,
PROP_ROUTES,
+ PROP_ROUTE_METRIC,
PROP_IGNORE_AUTO_ROUTES,
PROP_IGNORE_AUTO_DNS,
PROP_NEVER_DEFAULT,
@@ -709,6 +711,26 @@ nm_setting_ip6_config_clear_routes (NMSettingIP6Config *setting)
}
/**
+ * nm_setting_ip6_config_get_route_metric:
+ * @setting: the #NMSettingIP4Config
+ *
+ * Returns the value contained in the #NMSettingIP6Config:route-metric
+ * property.
+ *
+ * Returns: the route metric that is used for IPv6 routes that don't explicitly
+ * specify a metric. See #NMSettingIP6Config:route-metric for more details.
+ *
+ * Since: 1.0
+ **/
+gint64
+nm_setting_ip6_config_get_route_metric (NMSettingIP6Config *setting)
+{
+ g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), -1);
+
+ return NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->route_metric;
+}
+
+/**
* nm_setting_ip6_config_get_ignore_auto_routes:
* @setting: the #NMSettingIP6Config
*
@@ -927,6 +949,9 @@ set_property (GObject *object, guint prop_id,
g_slist_free_full (priv->routes, g_free);
priv->routes = nm_utils_ip6_routes_from_gvalue (value);
break;
+ case PROP_ROUTE_METRIC:
+ priv->route_metric = g_value_get_int64 (value);
+ break;
case PROP_IGNORE_AUTO_ROUTES:
priv->ignore_auto_routes = g_value_get_boolean (value);
break;
@@ -974,6 +999,9 @@ get_property (GObject *object, guint prop_id,
case PROP_ROUTES:
nm_utils_ip6_routes_to_gvalue (priv->routes, value);
break;
+ case PROP_ROUTE_METRIC:
+ g_value_set_int64 (value, priv->route_metric);
+ break;
case PROP_IGNORE_AUTO_ROUTES:
g_value_set_boolean (value, priv->ignore_auto_routes);
break;
@@ -1187,6 +1215,28 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *setting_class)
G_PARAM_STATIC_STRINGS));
/**
+ * NMSettingIP6Config:route-metric:
+ *
+ * The default metric for routes that don't explicitly specify a metric.
+ * The default value -1 means that the metric is choosen automatically
+ * based on the device type.
+ * The metric applies to dynamic routes, manual (static) routes that
+ * don't have an explicit metric setting, address prefix routes, and
+ * the default route.
+ * As the linux kernel replaces zero (0) by 1024 (user-default), setting
+ * this property to 0 means effectively setting it to 1024.
+ *
+ * Since: 1.0
+ **/
+ g_object_class_install_property
+ (object_class, PROP_ROUTE_METRIC,
+ g_param_spec_int64 (NM_SETTING_IP6_CONFIG_ROUTE_METRIC, "", "",
+ -1, G_MAXUINT32, -1,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
* NMSettingIP6Config:ignore-auto-routes:
*
* When the method is set to "auto" or "dhcp" and this property is set to
diff --git a/libnm-util/nm-setting-ip6-config.h b/libnm-util/nm-setting-ip6-config.h
index 4486a40e26..0a2f00ddcc 100644
--- a/libnm-util/nm-setting-ip6-config.h
+++ b/libnm-util/nm-setting-ip6-config.h
@@ -61,6 +61,7 @@ GQuark nm_setting_ip6_config_error_quark (void);
#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_ROUTE_METRIC "route-metric"
#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"
@@ -245,6 +246,9 @@ gboolean nm_setting_ip6_config_remove_route_by_value (NMSettingIP
void nm_setting_ip6_config_clear_routes (NMSettingIP6Config *setting);
gboolean nm_setting_ip6_config_get_ignore_auto_routes (NMSettingIP6Config *setting);
+NM_AVAILABLE_IN_1_0
+gint64 nm_setting_ip6_config_get_route_metric (NMSettingIP6Config *setting);
+
gboolean nm_setting_ip6_config_get_ignore_auto_dns (NMSettingIP6Config *setting);
const char * nm_setting_ip6_config_get_dhcp_hostname (NMSettingIP6Config *setting);
gboolean nm_setting_ip6_config_get_never_default (NMSettingIP6Config *setting);
diff --git a/libnm-util/tests/test-general.c b/libnm-util/tests/test-general.c
index bdec7e1354..eea22b5f3b 100644
--- a/libnm-util/tests/test-general.c
+++ b/libnm-util/tests/test-general.c
@@ -1268,6 +1268,7 @@ test_connection_diff_a_only (void)
{ NM_SETTING_IP4_CONFIG_DNS_SEARCH, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP4_CONFIG_ADDRESSES, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP4_CONFIG_ROUTES, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_IP4_CONFIG_ROUTE_METRIC, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, NM_SETTING_DIFF_RESULT_IN_A },
diff --git a/libnm/Makefile.am b/libnm/Makefile.am
index e14dc83a3f..f911d86e66 100644
--- a/libnm/Makefile.am
+++ b/libnm/Makefile.am
@@ -43,17 +43,15 @@ libnminclude_hfiles = \
nm-device-wifi.h \
nm-device-wimax.h \
nm-device.h \
- nm-dhcp4-config.h \
- nm-dhcp6-config.h \
+ nm-dhcp-config.h \
nm-enum-types.h \
- nm-ip4-config.h \
- nm-ip6-config.h \
+ nm-ip-config.h \
nm-object.h \
nm-remote-connection.h \
nm-secret-agent.h \
nm-types.h \
nm-vpn-connection.h \
- nm-vpn-plugin-ui-interface.h \
+ nm-vpn-editor-plugin.h \
nm-wimax-nsp.h
libnminclude_nointrospect_hfiles = \
@@ -66,6 +64,10 @@ libnminclude_HEADERS = \
libnm_la_private_headers = \
nm-dbus-helpers.h \
nm-device-private.h \
+ nm-dhcp4-config.h \
+ nm-dhcp6-config.h \
+ nm-ip4-config.h \
+ nm-ip6-config.h \
nm-manager.h \
nm-object-cache.h \
nm-object-private.h \
@@ -91,9 +93,11 @@ libnm_la_csources = \
nm-device-wifi.c \
nm-device-wimax.c \
nm-device.c \
+ nm-dhcp-config.c \
nm-dhcp4-config.c \
nm-dhcp6-config.c \
nm-enum-types.c \
+ nm-ip-config.c \
nm-ip4-config.c \
nm-ip6-config.c \
nm-manager.c \
@@ -104,7 +108,7 @@ libnm_la_csources = \
nm-secret-agent.c \
nm-vpn-connection.c \
nm-vpn-plugin-old.c \
- nm-vpn-plugin-ui-interface.c \
+ nm-vpn-editor-plugin.c \
nm-wimax-nsp.c
libnm_la_SOURCES = \
diff --git a/libnm/NetworkManager.h b/libnm/NetworkManager.h
index ce7bec74c2..3a31c5fa07 100644
--- a/libnm/NetworkManager.h
+++ b/libnm/NetworkManager.h
@@ -43,11 +43,9 @@
#include <nm-device-wifi.h>
#include <nm-device-wimax.h>
#include <nm-device.h>
-#include <nm-dhcp4-config.h>
-#include <nm-dhcp6-config.h>
+#include <nm-dhcp-config.h>
#include <nm-enum-types.h>
-#include <nm-ip4-config.h>
-#include <nm-ip6-config.h>
+#include <nm-ip-config.h>
#include <nm-object.h>
#include <nm-remote-connection.h>
#include <nm-secret-agent.h>
@@ -63,6 +61,7 @@
#include <nm-setting-generic.h>
#include <nm-setting-gsm.h>
#include <nm-setting-infiniband.h>
+#include <nm-setting-ip-config.h>
#include <nm-setting-ip4-config.h>
#include <nm-setting-ip6-config.h>
#include <nm-setting-olpc-mesh.h>
@@ -83,6 +82,7 @@
#include <nm-version.h>
#include <nm-vpn-connection.h>
#include <nm-vpn-dbus-interface.h>
+#include <nm-vpn-editor-plugin.h>
#include <nm-wimax-nsp.h>
#undef __NETWORKMANAGER_H_INSIDE__
diff --git a/libnm/libnm.ver b/libnm/libnm.ver
index d735a30e38..d1957ececc 100644
--- a/libnm/libnm.ver
+++ b/libnm/libnm.ver
@@ -262,79 +262,57 @@ global:
nm_device_wimax_get_rssi;
nm_device_wimax_get_tx_power;
nm_device_wimax_get_type;
- nm_dhcp4_config_get_one_option;
- nm_dhcp4_config_get_options;
- nm_dhcp4_config_get_type;
- nm_dhcp6_config_get_one_option;
- nm_dhcp6_config_get_options;
- nm_dhcp6_config_get_type;
- nm_ip4_address_compare;
- nm_ip4_address_dup;
- nm_ip4_address_get_address;
- nm_ip4_address_get_gateway;
- nm_ip4_address_get_prefix;
- nm_ip4_address_get_type;
- nm_ip4_address_new;
- nm_ip4_address_ref;
- nm_ip4_address_set_address;
- nm_ip4_address_set_gateway;
- nm_ip4_address_set_prefix;
- nm_ip4_address_unref;
- nm_ip4_config_get_addresses;
- nm_ip4_config_get_domains;
- nm_ip4_config_get_gateway;
- nm_ip4_config_get_nameservers;
- nm_ip4_config_get_routes;
- nm_ip4_config_get_searches;
- nm_ip4_config_get_type;
- nm_ip4_config_get_wins_servers;
- nm_ip4_route_compare;
- nm_ip4_route_dup;
- nm_ip4_route_get_dest;
- nm_ip4_route_get_metric;
- nm_ip4_route_get_next_hop;
- nm_ip4_route_get_prefix;
- nm_ip4_route_get_type;
- nm_ip4_route_new;
- nm_ip4_route_ref;
- nm_ip4_route_set_dest;
- nm_ip4_route_set_metric;
- nm_ip4_route_set_next_hop;
- nm_ip4_route_set_prefix;
- nm_ip4_route_unref;
- nm_ip6_address_compare;
- nm_ip6_address_dup;
- nm_ip6_address_get_address;
- nm_ip6_address_get_gateway;
- nm_ip6_address_get_prefix;
- nm_ip6_address_get_type;
- nm_ip6_address_new;
- nm_ip6_address_ref;
- nm_ip6_address_set_address;
- nm_ip6_address_set_gateway;
- nm_ip6_address_set_prefix;
- nm_ip6_address_unref;
- nm_ip6_config_get_addresses;
- nm_ip6_config_get_domains;
- nm_ip6_config_get_gateway;
- nm_ip6_config_get_nameservers;
- nm_ip6_config_get_routes;
- nm_ip6_config_get_searches;
- nm_ip6_config_get_type;
- nm_ip6_route_compare;
- nm_ip6_route_dup;
- nm_ip6_route_get_dest;
- nm_ip6_route_get_metric;
- nm_ip6_route_get_next_hop;
- nm_ip6_route_get_prefix;
- nm_ip6_route_get_type;
- nm_ip6_route_new;
- nm_ip6_route_ref;
- nm_ip6_route_set_dest;
- nm_ip6_route_set_metric;
- nm_ip6_route_set_next_hop;
- nm_ip6_route_set_prefix;
- nm_ip6_route_unref;
+ nm_dhcp_config_get_family;
+ nm_dhcp_config_get_one_option;
+ nm_dhcp_config_get_options;
+ nm_dhcp_config_get_type;
+ nm_ip_address_equal;
+ nm_ip_address_get_address;
+ nm_ip_address_get_address_binary;
+ nm_ip_address_get_attribute;
+ nm_ip_address_get_attribute_names;
+ nm_ip_address_get_family;
+ nm_ip_address_get_prefix;
+ nm_ip_address_get_type;
+ nm_ip_address_new;
+ nm_ip_address_new_binary;
+ nm_ip_address_ref;
+ nm_ip_address_set_address;
+ nm_ip_address_set_address_binary;
+ nm_ip_address_set_attribute;
+ nm_ip_address_set_prefix;
+ nm_ip_address_unref;
+ nm_ip_config_get_addresses;
+ nm_ip_config_get_domains;
+ nm_ip_config_get_family;
+ nm_ip_config_get_gateway;
+ nm_ip_config_get_nameservers;
+ nm_ip_config_get_routes;
+ nm_ip_config_get_searches;
+ nm_ip_config_get_type;
+ nm_ip_config_get_wins_servers;
+ nm_ip_route_equal;
+ nm_ip_route_get_attribute;
+ nm_ip_route_get_attribute_names;
+ nm_ip_route_get_dest;
+ nm_ip_route_get_dest_binary;
+ nm_ip_route_get_family;
+ nm_ip_route_get_metric;
+ nm_ip_route_get_next_hop;
+ nm_ip_route_get_next_hop_binary;
+ nm_ip_route_get_prefix;
+ nm_ip_route_get_type;
+ nm_ip_route_new;
+ nm_ip_route_new_binary;
+ nm_ip_route_ref;
+ nm_ip_route_set_attribute;
+ nm_ip_route_set_dest;
+ nm_ip_route_set_dest_binary;
+ nm_ip_route_set_metric;
+ nm_ip_route_set_next_hop;
+ nm_ip_route_set_next_hop_binary;
+ nm_ip_route_set_prefix;
+ nm_ip_route_unref;
nm_manager_error_get_type;
nm_manager_error_quark;
nm_object_get_path;
@@ -563,74 +541,47 @@ global:
nm_setting_infiniband_get_type;
nm_setting_infiniband_get_virtual_interface_name;
nm_setting_infiniband_new;
- nm_setting_ip4_config_add_address;
- nm_setting_ip4_config_add_dns;
- nm_setting_ip4_config_add_dns_search;
- nm_setting_ip4_config_add_route;
- nm_setting_ip4_config_clear_addresses;
- nm_setting_ip4_config_clear_dns;
- nm_setting_ip4_config_clear_dns_searches;
- nm_setting_ip4_config_clear_routes;
- nm_setting_ip4_config_get_address;
nm_setting_ip4_config_get_dhcp_client_id;
- nm_setting_ip4_config_get_dhcp_hostname;
- nm_setting_ip4_config_get_dhcp_send_hostname;
- nm_setting_ip4_config_get_dns;
- nm_setting_ip4_config_get_dns_search;
- nm_setting_ip4_config_get_ignore_auto_dns;
- nm_setting_ip4_config_get_ignore_auto_routes;
- nm_setting_ip4_config_get_may_fail;
- nm_setting_ip4_config_get_method;
- nm_setting_ip4_config_get_never_default;
- nm_setting_ip4_config_get_num_addresses;
- nm_setting_ip4_config_get_num_dns;
- nm_setting_ip4_config_get_num_dns_searches;
- nm_setting_ip4_config_get_num_routes;
- nm_setting_ip4_config_get_route;
nm_setting_ip4_config_get_type;
nm_setting_ip4_config_new;
- nm_setting_ip4_config_remove_address;
- nm_setting_ip4_config_remove_address_by_value;
- nm_setting_ip4_config_remove_dns;
- nm_setting_ip4_config_remove_dns_by_value;
- nm_setting_ip4_config_remove_dns_search;
- nm_setting_ip4_config_remove_dns_search_by_value;
- nm_setting_ip4_config_remove_route;
- nm_setting_ip4_config_remove_route_by_value;
- nm_setting_ip6_config_add_address;
- nm_setting_ip6_config_add_dns;
- nm_setting_ip6_config_add_dns_search;
- nm_setting_ip6_config_add_route;
- nm_setting_ip6_config_clear_addresses;
- nm_setting_ip6_config_clear_dns;
- nm_setting_ip6_config_clear_dns_searches;
- nm_setting_ip6_config_clear_routes;
- nm_setting_ip6_config_get_address;
- nm_setting_ip6_config_get_dhcp_hostname;
- nm_setting_ip6_config_get_dns;
- nm_setting_ip6_config_get_dns_search;
- nm_setting_ip6_config_get_ignore_auto_dns;
- nm_setting_ip6_config_get_ignore_auto_routes;
nm_setting_ip6_config_get_ip6_privacy;
- nm_setting_ip6_config_get_may_fail;
- nm_setting_ip6_config_get_method;
- nm_setting_ip6_config_get_never_default;
- nm_setting_ip6_config_get_num_addresses;
- nm_setting_ip6_config_get_num_dns;
- nm_setting_ip6_config_get_num_dns_searches;
- nm_setting_ip6_config_get_num_routes;
- nm_setting_ip6_config_get_route;
nm_setting_ip6_config_get_type;
nm_setting_ip6_config_new;
nm_setting_ip6_config_privacy_get_type;
- nm_setting_ip6_config_remove_address;
- nm_setting_ip6_config_remove_address_by_value;
- nm_setting_ip6_config_remove_dns;
- nm_setting_ip6_config_remove_dns_by_value;
- nm_setting_ip6_config_remove_dns_search;
- nm_setting_ip6_config_remove_dns_search_by_value;
- nm_setting_ip6_config_remove_route;
- nm_setting_ip6_config_remove_route_by_value;
+ nm_setting_ip_config_add_address;
+ nm_setting_ip_config_add_dns;
+ nm_setting_ip_config_add_dns_search;
+ nm_setting_ip_config_add_route;
+ nm_setting_ip_config_clear_addresses;
+ nm_setting_ip_config_clear_dns;
+ nm_setting_ip_config_clear_dns_searches;
+ nm_setting_ip_config_clear_routes;
+ nm_setting_ip_config_get_address;
+ nm_setting_ip_config_get_dhcp_hostname;
+ nm_setting_ip_config_get_dhcp_send_hostname;
+ nm_setting_ip_config_get_dns;
+ nm_setting_ip_config_get_dns_search;
+ nm_setting_ip_config_get_gateway;
+ nm_setting_ip_config_get_ignore_auto_dns;
+ nm_setting_ip_config_get_ignore_auto_routes;
+ nm_setting_ip_config_get_may_fail;
+ nm_setting_ip_config_get_method;
+ nm_setting_ip_config_get_never_default;
+ nm_setting_ip_config_get_num_addresses;
+ nm_setting_ip_config_get_num_dns;
+ nm_setting_ip_config_get_num_dns_searches;
+ nm_setting_ip_config_get_num_routes;
+ nm_setting_ip_config_get_route;
+ nm_setting_ip_config_get_route_metric;
+ nm_setting_ip_config_get_type;
+ nm_setting_ip_config_remove_address;
+ nm_setting_ip_config_remove_address_by_value;
+ nm_setting_ip_config_remove_dns;
+ nm_setting_ip_config_remove_dns_by_value;
+ nm_setting_ip_config_remove_dns_search;
+ nm_setting_ip_config_remove_dns_search_by_value;
+ nm_setting_ip_config_remove_route;
+ nm_setting_ip_config_remove_route_by_value;
nm_setting_lookup_type;
nm_setting_olpc_mesh_get_channel;
nm_setting_olpc_mesh_get_dhcp_anycast_address;
@@ -805,7 +756,6 @@ global:
nm_utils_deinit;
nm_utils_escape_ssid;
nm_utils_file_is_pkcs12;
- nm_utils_hex2byte;
nm_utils_hexstr2bin;
nm_utils_hwaddr_atoba;
nm_utils_hwaddr_aton;
@@ -833,6 +783,7 @@ global:
nm_utils_ip6_dns_to_variant;
nm_utils_ip6_routes_from_variant;
nm_utils_ip6_routes_to_variant;
+ nm_utils_ipaddr_valid;
nm_utils_is_empty_ssid;
nm_utils_is_uuid;
nm_utils_rsa_key_encrypt;
@@ -857,6 +808,16 @@ global:
nm_vpn_connection_get_vpn_state;
nm_vpn_connection_state_get_type;
nm_vpn_connection_state_reason_get_type;
+ nm_vpn_editor_get_type;
+ nm_vpn_editor_get_widget;
+ nm_vpn_editor_plugin_capability_get_type;
+ nm_vpn_editor_plugin_export;
+ nm_vpn_editor_plugin_get_capabilities;
+ nm_vpn_editor_plugin_get_editor;
+ nm_vpn_editor_plugin_get_suggested_filename;
+ nm_vpn_editor_plugin_get_type;
+ nm_vpn_editor_plugin_import;
+ nm_vpn_editor_update_connection;
nm_vpn_plugin_error_get_type;
nm_vpn_plugin_error_quark;
nm_vpn_plugin_failure_get_type;
@@ -871,17 +832,6 @@ global:
nm_vpn_plugin_old_set_ip4_config;
nm_vpn_plugin_old_set_login_banner;
nm_vpn_plugin_old_set_state;
- nm_vpn_plugin_ui_capability_get_type;
- nm_vpn_plugin_ui_interface_export;
- nm_vpn_plugin_ui_interface_get_capabilities;
- nm_vpn_plugin_ui_interface_get_suggested_name;
- nm_vpn_plugin_ui_interface_get_type;
- nm_vpn_plugin_ui_interface_import;
- nm_vpn_plugin_ui_interface_prop_get_type;
- nm_vpn_plugin_ui_interface_ui_factory;
- nm_vpn_plugin_ui_widget_interface_get_type;
- nm_vpn_plugin_ui_widget_interface_get_widget;
- nm_vpn_plugin_ui_widget_interface_update_connection;
nm_vpn_service_state_get_type;
nm_wep_key_type_get_type;
nm_wimax_nsp_connection_valid;
diff --git a/libnm/nm-active-connection.c b/libnm/nm-active-connection.c
index 742b270cc6..6988f44c67 100644
--- a/libnm/nm-active-connection.c
+++ b/libnm/nm-active-connection.c
@@ -57,11 +57,11 @@ typedef struct {
GPtrArray *devices;
NMActiveConnectionState state;
gboolean is_default;
- NMIP4Config *ip4_config;
- NMDhcp4Config *dhcp4_config;
+ NMIPConfig *ip4_config;
+ NMDhcpConfig *dhcp4_config;
gboolean is_default6;
- NMIP6Config *ip6_config;
- NMDhcp6Config *dhcp6_config;
+ NMIPConfig *ip6_config;
+ NMDhcpConfig *dhcp6_config;
gboolean is_vpn;
NMDevice *master;
} NMActiveConnectionPrivate;
@@ -242,13 +242,12 @@ nm_active_connection_get_default (NMActiveConnection *connection)
* nm_active_connection_get_ip4_config:
* @connection: an #NMActiveConnection
*
- * Gets the current #NMIP4Config associated with the #NMActiveConnection.
+ * Gets the current IPv4 #NMIPConfig associated with the #NMActiveConnection.
*
- * Returns: (transfer none): the #NMIP4Config, or %NULL if the
- * connection is not in the %NM_ACTIVE_CONNECTION_STATE_ACTIVATED
- * state.
+ * Returns: (transfer none): the IPv4 #NMIPConfig, or %NULL if the connection is
+ * not in the %NM_ACTIVE_CONNECTION_STATE_ACTIVATED state.
**/
-NMIP4Config *
+NMIPConfig *
nm_active_connection_get_ip4_config (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
@@ -260,14 +259,14 @@ nm_active_connection_get_ip4_config (NMActiveConnection *connection)
* nm_active_connection_get_dhcp4_config:
* @connection: an #NMActiveConnection
*
- * Gets the current #NMDhcp4Config (if any) associated with the
+ * Gets the current IPv4 #NMDhcpConfig (if any) associated with the
* #NMActiveConnection.
*
- * Returns: (transfer none): the #NMDhcp4Config, or %NULL if the
- * connection does not use DHCP, or is not in the
- * %NM_ACTIVE_CONNECTION_STATE_ACTIVATED state.
+ * Returns: (transfer none): the IPv4 #NMDhcpConfig, or %NULL if the connection
+ * does not use DHCP, or is not in the %NM_ACTIVE_CONNECTION_STATE_ACTIVATED
+ * state.
**/
-NMDhcp4Config *
+NMDhcpConfig *
nm_active_connection_get_dhcp4_config (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
@@ -296,13 +295,12 @@ nm_active_connection_get_default6 (NMActiveConnection *connection)
* nm_active_connection_get_ip6_config:
* @connection: an #NMActiveConnection
*
- * Gets the current #NMIP6Config associated with the #NMActiveConnection.
+ * Gets the current IPv6 #NMIPConfig associated with the #NMActiveConnection.
*
- * Returns: (transfer none): the #NMIP6Config, or %NULL if the
- * connection is not in the %NM_ACTIVE_CONNECTION_STATE_ACTIVATED
- * state.
+ * Returns: (transfer none): the IPv6 #NMIPConfig, or %NULL if the connection is
+ * not in the %NM_ACTIVE_CONNECTION_STATE_ACTIVATED state.
**/
-NMIP6Config *
+NMIPConfig *
nm_active_connection_get_ip6_config (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
@@ -314,14 +312,14 @@ nm_active_connection_get_ip6_config (NMActiveConnection *connection)
* nm_active_connection_get_dhcp6_config:
* @connection: an #NMActiveConnection
*
- * Gets the current #NMDhcp6Config (if any) associated with the
+ * Gets the current IPv6 #NMDhcpConfig (if any) associated with the
* #NMActiveConnection.
*
- * Returns: (transfer none): the #NMDhcp6Config, or %NULL if the
- * connection does not use DHCPv6, or is not in the
- * %NM_ACTIVE_CONNECTION_STATE_ACTIVATED state.
+ * Returns: (transfer none): the IPv6 #NMDhcpConfig, or %NULL if the connection
+ * does not use DHCPv6, or is not in the %NM_ACTIVE_CONNECTION_STATE_ACTIVATED
+ * state.
**/
-NMDhcp6Config *
+NMDhcpConfig *
nm_active_connection_get_dhcp6_config (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
@@ -631,24 +629,24 @@ nm_active_connection_class_init (NMActiveConnectionClass *ap_class)
/**
* NMActiveConnection:ip4-config:
*
- * The #NMIP4Config of the connection.
+ * The IPv4 #NMIPConfig of the connection.
**/
g_object_class_install_property
(object_class, PROP_IP4_CONFIG,
g_param_spec_object (NM_ACTIVE_CONNECTION_IP4_CONFIG, "", "",
- NM_TYPE_IP4_CONFIG,
+ NM_TYPE_IP_CONFIG,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMActiveConnection:dhcp4-config:
*
- * The #NMDhcp4Config of the connection.
+ * The IPv4 #NMDhcpConfig of the connection.
**/
g_object_class_install_property
(object_class, PROP_DHCP4_CONFIG,
g_param_spec_object (NM_ACTIVE_CONNECTION_DHCP4_CONFIG, "", "",
- NM_TYPE_DHCP4_CONFIG,
+ NM_TYPE_DHCP_CONFIG,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
@@ -667,24 +665,24 @@ nm_active_connection_class_init (NMActiveConnectionClass *ap_class)
/**
* NMActiveConnection:ip6-config:
*
- * The #NMIP6Config of the connection.
+ * The IPv6 #NMIPConfig of the connection.
**/
g_object_class_install_property
(object_class, PROP_IP6_CONFIG,
g_param_spec_object (NM_ACTIVE_CONNECTION_IP6_CONFIG, "", "",
- NM_TYPE_IP6_CONFIG,
+ NM_TYPE_IP_CONFIG,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMActiveConnection:dhcp6-config:
*
- * The #NMDhcp6Config of the connection.
+ * The IPv6 #NMDhcpConfig of the connection.
**/
g_object_class_install_property
(object_class, PROP_DHCP6_CONFIG,
g_param_spec_object (NM_ACTIVE_CONNECTION_DHCP6_CONFIG, "", "",
- NM_TYPE_DHCP6_CONFIG,
+ NM_TYPE_DHCP_CONFIG,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
diff --git a/libnm/nm-active-connection.h b/libnm/nm-active-connection.h
index ef8dd1980b..4bc8414828 100644
--- a/libnm/nm-active-connection.h
+++ b/libnm/nm-active-connection.h
@@ -75,11 +75,11 @@ const GPtrArray *nm_active_connection_get_devices (NMActive
NMActiveConnectionState nm_active_connection_get_state (NMActiveConnection *connection);
NMDevice *nm_active_connection_get_master (NMActiveConnection *connection);
gboolean nm_active_connection_get_default (NMActiveConnection *connection);
-NMIP4Config *nm_active_connection_get_ip4_config (NMActiveConnection *connection);
-NMDhcp4Config *nm_active_connection_get_dhcp4_config (NMActiveConnection *connection);
+NMIPConfig *nm_active_connection_get_ip4_config (NMActiveConnection *connection);
+NMDhcpConfig *nm_active_connection_get_dhcp4_config (NMActiveConnection *connection);
gboolean nm_active_connection_get_default6 (NMActiveConnection *connection);
-NMIP6Config *nm_active_connection_get_ip6_config (NMActiveConnection *connection);
-NMDhcp6Config *nm_active_connection_get_dhcp6_config (NMActiveConnection *connection);
+NMIPConfig *nm_active_connection_get_ip6_config (NMActiveConnection *connection);
+NMDhcpConfig *nm_active_connection_get_dhcp6_config (NMActiveConnection *connection);
gboolean nm_active_connection_get_vpn (NMActiveConnection *connection);
G_END_DECLS
diff --git a/libnm/nm-client.c b/libnm/nm-client.c
index f6a2256709..4e4f194f5c 100644
--- a/libnm/nm-client.c
+++ b/libnm/nm-client.c
@@ -1825,8 +1825,14 @@ dispose (GObject *object)
{
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (object);
- g_clear_object (&priv->manager);
- g_clear_object (&priv->settings);
+ if (priv->manager) {
+ g_signal_handlers_disconnect_by_data (priv->manager, object);
+ g_clear_object (&priv->manager);
+ }
+ if (priv->settings) {
+ g_signal_handlers_disconnect_by_data (priv->settings, object);
+ g_clear_object (&priv->settings);
+ }
G_OBJECT_CLASS (nm_client_parent_class)->dispose (object);
}
diff --git a/libnm/nm-device.c b/libnm/nm-device.c
index 5a1caf6d9f..a6d5fe3067 100644
--- a/libnm/nm-device.c
+++ b/libnm/nm-device.c
@@ -83,10 +83,10 @@ typedef struct {
gboolean managed;
gboolean firmware_missing;
gboolean autoconnect;
- NMIP4Config *ip4_config;
- NMDhcp4Config *dhcp4_config;
- NMIP6Config *ip6_config;
- NMDhcp6Config *dhcp6_config;
+ NMIPConfig *ip4_config;
+ NMDhcpConfig *dhcp4_config;
+ NMIPConfig *ip6_config;
+ NMDhcpConfig *dhcp6_config;
NMDeviceState state;
NMDeviceState last_seen_state;
NMDeviceStateReason reason;
@@ -651,43 +651,43 @@ nm_device_class_init (NMDeviceClass *device_class)
g_object_class_install_property
(object_class, PROP_IP4_CONFIG,
g_param_spec_object (NM_DEVICE_IP4_CONFIG, "", "",
- NM_TYPE_IP4_CONFIG,
+ NM_TYPE_IP_CONFIG,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMDevice:dhcp4-config:
*
- * The #NMDhcp4Config of the device.
+ * The IPv4 #NMDhcpConfig of the device.
**/
g_object_class_install_property
(object_class, PROP_DHCP4_CONFIG,
g_param_spec_object (NM_DEVICE_DHCP4_CONFIG, "", "",
- NM_TYPE_DHCP4_CONFIG,
+ NM_TYPE_DHCP_CONFIG,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMDevice:ip6-config:
*
- * The #NMIP6Config of the device.
+ * The IPv6 #NMIPConfig of the device.
**/
g_object_class_install_property
(object_class, PROP_IP6_CONFIG,
g_param_spec_object (NM_DEVICE_IP6_CONFIG, "", "",
- NM_TYPE_IP6_CONFIG,
+ NM_TYPE_IP_CONFIG,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMDevice:dhcp6-config:
*
- * The #NMDhcp6Config of the device.
+ * The IPv6 #NMDhcpConfig of the device.
**/
g_object_class_install_property
(object_class, PROP_DHCP6_CONFIG,
g_param_spec_object (NM_DEVICE_DHCP6_CONFIG, "", "",
- NM_TYPE_DHCP6_CONFIG,
+ NM_TYPE_DHCP_CONFIG,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
@@ -1106,15 +1106,15 @@ nm_device_get_firmware_missing (NMDevice *device)
* nm_device_get_ip4_config:
* @device: a #NMDevice
*
- * Gets the current #NMIP4Config associated with the #NMDevice.
+ * Gets the current IPv4 #NMIPConfig associated with the #NMDevice.
*
- * Note that as of NetworkManager 0.9.10, you can alternatively use
- * nm_active_connection_get_ip4_config(), which also works with VPN
- * connections.
+ * You can alternatively use nm_active_connection_get_ip4_config(), which also
+ * works with VPN connections.
*
- * Returns: (transfer none): the #NMIP4Config or %NULL if the device is not activated.
+ * Returns: (transfer none): the IPv4 #NMIPConfig, or %NULL if the device is not
+ * activated.
**/
-NMIP4Config *
+NMIPConfig *
nm_device_get_ip4_config (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
@@ -1126,16 +1126,15 @@ nm_device_get_ip4_config (NMDevice *device)
* nm_device_get_dhcp4_config:
* @device: a #NMDevice
*
- * Gets the current #NMDhcp4Config associated with the #NMDevice.
+ * Gets the current IPv4 #NMDhcpConfig associated with the #NMDevice.
*
- * Note that as of NetworkManager 0.9.10, you can alternatively use
- * nm_active_connection_get_dhcp4_config(), which also works with VPN
- * connections.
+ * You can alternatively use nm_active_connection_get_dhcp4_config(), which also
+ * works with VPN connections.
*
- * Returns: (transfer none): the #NMDhcp4Config or %NULL if the device is not activated or not
- * using DHCP.
+ * Returns: (transfer none): the IPv4 #NMDhcpConfig, or %NULL if the device is
+ * not activated or not using DHCP.
**/
-NMDhcp4Config *
+NMDhcpConfig *
nm_device_get_dhcp4_config (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
@@ -1147,15 +1146,14 @@ nm_device_get_dhcp4_config (NMDevice *device)
* nm_device_get_ip6_config:
* @device: a #NMDevice
*
- * Gets the current #NMIP6Config associated with the #NMDevice.
+ * Gets the current IPv6 #NMIPConfig associated with the #NMDevice.
*
- * Note that as of NetworkManager 0.9.10, you can alternatively use
- * nm_active_connection_get_ip6_config(), which also works with VPN
- * connections.
+ * You can alternatively use nm_active_connection_get_ip6_config(), which also
+ * works with VPN connections.
*
- * Returns: (transfer none): the #NMIP6Config or %NULL if the device is not activated.
+ * Returns: (transfer none): the IPv6 #NMIPConfig or %NULL if the device is not activated.
**/
-NMIP6Config *
+NMIPConfig *
nm_device_get_ip6_config (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
@@ -1167,16 +1165,15 @@ nm_device_get_ip6_config (NMDevice *device)
* nm_device_get_dhcp6_config:
* @device: a #NMDevice
*
- * Gets the current #NMDhcp6Config associated with the #NMDevice.
+ * Gets the current IPv6 #NMDhcpConfig associated with the #NMDevice.
*
- * Note that as of NetworkManager 0.9.10, you can alternatively use
- * nm_active_connection_get_dhcp6_config(), which also works with VPN
- * connections.
+ * You can alternatively use nm_active_connection_get_dhcp6_config(), which also
+ * works with VPN connections.
*
- * Returns: (transfer none): the #NMDhcp6Config or %NULL if the device is not activated or not
- * using DHCP.
+ * Returns: (transfer none): the IPv6 #NMDhcpConfig, or %NULL if the device is
+ * not activated or not using DHCPv6.
**/
-NMDhcp6Config *
+NMDhcpConfig *
nm_device_get_dhcp6_config (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
@@ -1252,6 +1249,19 @@ nm_device_get_available_connections (NMDevice *device)
return NM_DEVICE_GET_PRIVATE (device)->available_connections;
}
+static inline guint8
+hex2byte (const char *hex)
+{
+ int a, b;
+ a = g_ascii_xdigit_value (*hex++);
+ if (a < 0)
+ return -1;
+ b = g_ascii_xdigit_value (*hex++);
+ if (b < 0)
+ return -1;
+ return (a << 4) | b;
+}
+
static char *
get_decoded_property (GUdevDevice *device, const char *property)
{
@@ -1267,7 +1277,7 @@ get_decoded_property (GUdevDevice *device, const char *property)
n = unescaped = g_malloc0 (len + 1);
while (*p) {
if ((len >= 4) && (*p == '\\') && (*(p+1) == 'x')) {
- *n++ = (char) nm_utils_hex2byte (p + 2);
+ *n++ = (char) hex2byte (p + 2);
p += 4;
len -= 4;
} else {
@@ -1571,8 +1581,7 @@ get_short_vendor (NMDevice *device)
* nm_device_get_description:
* @device: an #NMDevice
*
- * Gets a description of @device, incorporating the results of
- * nm_device_get_short_vendor() and nm_device_get_short_product().
+ * Gets a description of @device, based on its vendor and product names.
*
* Returns: a description of @device. If either the vendor or the
* product name is unknown, this returns the interface name.
diff --git a/libnm/nm-device.h b/libnm/nm-device.h
index 412dff3f96..5cc3735695 100644
--- a/libnm/nm-device.h
+++ b/libnm/nm-device.h
@@ -104,10 +104,10 @@ gboolean nm_device_get_managed (NMDevice *device);
gboolean nm_device_get_autoconnect (NMDevice *device);
void nm_device_set_autoconnect (NMDevice *device, gboolean autoconnect);
gboolean nm_device_get_firmware_missing (NMDevice *device);
-NMIP4Config * nm_device_get_ip4_config (NMDevice *device);
-NMDhcp4Config * nm_device_get_dhcp4_config (NMDevice *device);
-NMIP6Config * nm_device_get_ip6_config (NMDevice *device);
-NMDhcp6Config * nm_device_get_dhcp6_config (NMDevice *device);
+NMIPConfig * nm_device_get_ip4_config (NMDevice *device);
+NMDhcpConfig * nm_device_get_dhcp4_config (NMDevice *device);
+NMIPConfig * nm_device_get_ip6_config (NMDevice *device);
+NMDhcpConfig * nm_device_get_dhcp6_config (NMDevice *device);
NMDeviceState nm_device_get_state (NMDevice *device);
NMDeviceStateReason nm_device_get_state_reason (NMDevice *device);
NMActiveConnection * nm_device_get_active_connection(NMDevice *device);
diff --git a/libnm/nm-dhcp-config.c b/libnm/nm-dhcp-config.c
new file mode 100644
index 0000000000..5b72fbc10f
--- /dev/null
+++ b/libnm/nm-dhcp-config.c
@@ -0,0 +1,217 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2008 - 2014 Red Hat, Inc.
+ * Copyright 2008 Novell, Inc.
+ */
+
+#include <string.h>
+
+#include "nm-dhcp-config.h"
+#include "nm-dhcp4-config.h"
+#include "nm-dhcp6-config.h"
+#include "nm-dbus-interface.h"
+#include "nm-object-private.h"
+#include "nm-utils.h"
+
+G_DEFINE_ABSTRACT_TYPE (NMDhcpConfig, nm_dhcp_config, NM_TYPE_OBJECT)
+
+#define NM_DHCP_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP_CONFIG, NMDhcpConfigPrivate))
+
+typedef struct {
+ GHashTable *options;
+} NMDhcpConfigPrivate;
+
+enum {
+ PROP_0,
+ PROP_FAMILY,
+ PROP_OPTIONS,
+
+ LAST_PROP
+};
+
+static void
+nm_dhcp_config_init (NMDhcpConfig *config)
+{
+ NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE (config);
+
+ priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+}
+
+static gboolean
+demarshal_dhcp_options (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
+{
+ NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE (object);
+ GVariantIter iter;
+ const char *key;
+ GVariant *opt;
+
+ g_hash_table_remove_all (priv->options);
+
+ g_variant_iter_init (&iter, value);
+ while (g_variant_iter_next (&iter, "{&sv}", &key, &opt)) {
+ g_hash_table_insert (priv->options, g_strdup (key), g_variant_dup_string (opt, NULL));
+ g_variant_unref (opt);
+ }
+
+ _nm_object_queue_notify (object, NM_DHCP_CONFIG_OPTIONS);
+ return TRUE;
+}
+
+static void
+init_dbus (NMObject *object)
+{
+ NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE (object);
+ const NMPropertiesInfo property_info[] = {
+ { NM_DHCP_CONFIG_OPTIONS, &priv->options, demarshal_dhcp_options },
+ { NULL },
+ };
+
+ NM_OBJECT_CLASS (nm_dhcp_config_parent_class)->init_dbus (object);
+
+ _nm_object_register_properties (object,
+ (NM_IS_DHCP4_CONFIG (object) ?
+ NM_DBUS_INTERFACE_DHCP4_CONFIG :
+ NM_DBUS_INTERFACE_DHCP6_CONFIG),
+ property_info);
+}
+
+static void
+finalize (GObject *object)
+{
+ NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE (object);
+
+ if (priv->options)
+ g_hash_table_destroy (priv->options);
+
+ G_OBJECT_CLASS (nm_dhcp_config_parent_class)->finalize (object);
+}
+
+static void
+get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ NMDhcpConfig *self = NM_DHCP_CONFIG (object);
+
+ switch (prop_id) {
+ case PROP_FAMILY:
+ g_value_set_int (value, nm_dhcp_config_get_family (self));
+ case PROP_OPTIONS:
+ g_value_set_boxed (value, nm_dhcp_config_get_options (self));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+nm_dhcp_config_class_init (NMDhcpConfigClass *config_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (config_class);
+ NMObjectClass *nm_object_class = NM_OBJECT_CLASS (config_class);
+
+ g_type_class_add_private (config_class, sizeof (NMDhcpConfigPrivate));
+
+ /* virtual methods */
+ object_class->get_property = get_property;
+ object_class->finalize = finalize;
+
+ nm_object_class->init_dbus = init_dbus;
+
+ /* properties */
+
+ /**
+ * NMDhcpConfig:family:
+ *
+ * The IP address family of the configuration; either %AF_INET or %AF_INET6.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_FAMILY,
+ g_param_spec_int (NM_DHCP_CONFIG_FAMILY, "", "",
+ 0, 255, AF_UNSPEC,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * NMDhcpConfig:options:
+ *
+ * The #GHashTable containing options of the configuration.
+ *
+ * Type: GLib.HashTable(utf8,utf8)
+ **/
+ g_object_class_install_property
+ (object_class, PROP_OPTIONS,
+ g_param_spec_boxed (NM_DHCP_CONFIG_OPTIONS, "", "",
+ G_TYPE_HASH_TABLE,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+}
+
+/**
+ * nm_dhcp_config_get_family:
+ * @config: a #NMDhcpConfig
+ *
+ * Gets the IP address family of the configuration
+ *
+ * Returns: the IP address family; either %AF_INET or %AF_INET6
+ **/
+int
+nm_dhcp_config_get_family (NMDhcpConfig *config)
+{
+ g_return_val_if_fail (NM_IS_DHCP_CONFIG (config), AF_UNSPEC);
+
+ return NM_IS_DHCP4_CONFIG (config) ? AF_INET : AF_INET6;
+}
+
+/**
+ * nm_dhcp_config_get_options:
+ * @config: a #NMDhcpConfig
+ *
+ * Gets all the options contained in the configuration.
+ *
+ * Returns: (transfer none) (element-type utf8 utf8): the #GHashTable containing
+ * strings for keys and values. This is the internal copy used by the
+ * configuration, and must not be modified.
+ **/
+GHashTable *
+nm_dhcp_config_get_options (NMDhcpConfig *config)
+{
+ g_return_val_if_fail (NM_IS_DHCP_CONFIG (config), NULL);
+
+ return NM_DHCP_CONFIG_GET_PRIVATE (config)->options;
+}
+
+/**
+ * nm_dhcp_config_get_one_option:
+ * @config: a #NMDhcpConfig
+ * @option: the option to retrieve
+ *
+ * Gets one option by option name.
+ *
+ * Returns: the configuration option's value. This is the internal string used by the
+ * configuration, and must not be modified.
+ **/
+const char *
+nm_dhcp_config_get_one_option (NMDhcpConfig *config, const char *option)
+{
+ g_return_val_if_fail (NM_IS_DHCP_CONFIG (config), NULL);
+
+ return g_hash_table_lookup (nm_dhcp_config_get_options (config), option);
+}
diff --git a/libnm/nm-dhcp-config.h b/libnm/nm-dhcp-config.h
new file mode 100644
index 0000000000..85aa3bd2c1
--- /dev/null
+++ b/libnm/nm-dhcp-config.h
@@ -0,0 +1,62 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2008 Red Hat, Inc.
+ * Copyright 2008 Novell, Inc.
+ */
+
+#ifndef __NM_DHCP_CONFIG_H__
+#define __NM_DHCP_CONFIG_H__
+
+#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION)
+#error "Only <NetworkManager.h> can be included directly."
+#endif
+
+#include <nm-object.h>
+
+G_BEGIN_DECLS
+
+#define NM_TYPE_DHCP_CONFIG (nm_dhcp_config_get_type ())
+#define NM_DHCP_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DHCP_CONFIG, NMDhcpConfig))
+#define NM_DHCP_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DHCP_CONFIG, NMDhcpConfigClass))
+#define NM_IS_DHCP_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DHCP_CONFIG))
+#define NM_IS_DHCP_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DHCP_CONFIG))
+
+struct _NMDhcpConfig {
+ NMObject parent;
+};
+
+typedef struct {
+ NMObjectClass parent;
+
+ /*< private >*/
+ gpointer padding[8];
+} NMDhcpConfigClass;
+
+#define NM_DHCP_CONFIG_FAMILY "family"
+#define NM_DHCP_CONFIG_OPTIONS "options"
+
+GType nm_dhcp_config_get_type (void);
+
+int nm_dhcp_config_get_family (NMDhcpConfig *config);
+
+GHashTable *nm_dhcp_config_get_options (NMDhcpConfig *config);
+const char *nm_dhcp_config_get_one_option (NMDhcpConfig *config, const char *option);
+
+G_END_DECLS
+
+#endif /* __NM_DHCP_CONFIG_H__ */
diff --git a/libnm/nm-dhcp4-config.c b/libnm/nm-dhcp4-config.c
index 2bf84fa408..6bbd8d6b54 100644
--- a/libnm/nm-dhcp4-config.c
+++ b/libnm/nm-dhcp4-config.c
@@ -15,169 +15,23 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
- * Copyright 2008 - 2011 Red Hat, Inc.
- * Copyright 2008 Novell, Inc.
+ * Copyright 2014 Red Hat, Inc.
*/
-#include <string.h>
-
#include "nm-dhcp4-config.h"
-#include "nm-dbus-interface.h"
#include "nm-object-private.h"
-#include "nm-utils.h"
-
-G_DEFINE_TYPE (NMDhcp4Config, nm_dhcp4_config, NM_TYPE_OBJECT)
-
-#define NM_DHCP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP4_CONFIG, NMDhcp4ConfigPrivate))
-typedef struct {
- GHashTable *options;
-} NMDhcp4ConfigPrivate;
-
-enum {
- PROP_0,
- PROP_OPTIONS,
-
- LAST_PROP
-};
+G_DEFINE_TYPE (NMDhcp4Config, nm_dhcp4_config, NM_TYPE_DHCP_CONFIG)
static void
nm_dhcp4_config_init (NMDhcp4Config *config)
{
- NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (config);
-
- priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
-}
-
-static gboolean
-demarshal_dhcp4_options (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
-{
- NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object);
- GVariantIter iter;
- const char *key;
- GVariant *opt;
-
- g_hash_table_remove_all (priv->options);
-
- g_variant_iter_init (&iter, value);
- while (g_variant_iter_next (&iter, "{&sv}", &key, &opt)) {
- g_hash_table_insert (priv->options, g_strdup (key), g_variant_dup_string (opt, NULL));
- g_variant_unref (opt);
- }
-
- _nm_object_queue_notify (object, NM_DHCP4_CONFIG_OPTIONS);
- return TRUE;
-}
-
-static void
-init_dbus (NMObject *object)
-{
- NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object);
- const NMPropertiesInfo property_info[] = {
- { NM_DHCP4_CONFIG_OPTIONS, &priv->options, demarshal_dhcp4_options },
- { NULL },
- };
-
- NM_OBJECT_CLASS (nm_dhcp4_config_parent_class)->init_dbus (object);
-
- _nm_object_register_properties (object,
- NM_DBUS_INTERFACE_DHCP4_CONFIG,
- property_info);
-}
-
-static void
-finalize (GObject *object)
-{
- NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object);
-
- if (priv->options)
- g_hash_table_destroy (priv->options);
-
- G_OBJECT_CLASS (nm_dhcp4_config_parent_class)->finalize (object);
-}
-
-static void
-get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- NMDhcp4Config *self = NM_DHCP4_CONFIG (object);
-
- switch (prop_id) {
- case PROP_OPTIONS:
- g_value_set_boxed (value, nm_dhcp4_config_get_options (self));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
}
static void
nm_dhcp4_config_class_init (NMDhcp4ConfigClass *config_class)
{
- GObjectClass *object_class = G_OBJECT_CLASS (config_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (config_class);
- g_type_class_add_private (config_class, sizeof (NMDhcp4ConfigPrivate));
-
_nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DHCP4_CONFIG);
-
- /* virtual methods */
- object_class->get_property = get_property;
- object_class->finalize = finalize;
-
- nm_object_class->init_dbus = init_dbus;
-
- /* properties */
-
- /**
- * NMDhcp4Config:options:
- *
- * The #GHashTable containing options of the configuration.
- *
- * Type: GLib.HashTable(utf8,utf8)
- **/
- g_object_class_install_property
- (object_class, PROP_OPTIONS,
- g_param_spec_boxed (NM_DHCP4_CONFIG_OPTIONS, "", "",
- G_TYPE_HASH_TABLE,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-}
-
-/**
- * nm_dhcp4_config_get_options:
- * @config: a #NMDhcp4Config
- *
- * Gets all the options contained in the configuration.
- *
- * Returns: (transfer none) (element-type utf8 GObject.Value): the #GHashTable containing strings for keys and values.
- * This is the internal copy used by the configuration, and must not be modified.
- **/
-GHashTable *
-nm_dhcp4_config_get_options (NMDhcp4Config *config)
-{
- g_return_val_if_fail (NM_IS_DHCP4_CONFIG (config), NULL);
-
- return NM_DHCP4_CONFIG_GET_PRIVATE (config)->options;
-}
-
-/**
- * nm_dhcp4_config_get_one_option:
- * @config: a #NMDhcp4Config
- * @option: the option to retrieve
- *
- * Gets one option by option name.
- *
- * Returns: the configuration option's value. This is the internal string used by the
- * configuration, and must not be modified.
- **/
-const char *
-nm_dhcp4_config_get_one_option (NMDhcp4Config *config, const char *option)
-{
- g_return_val_if_fail (NM_IS_DHCP4_CONFIG (config), NULL);
-
- return g_hash_table_lookup (nm_dhcp4_config_get_options (config), option);
}
diff --git a/libnm/nm-dhcp4-config.h b/libnm/nm-dhcp4-config.h
index 90152c8f63..3423740db8 100644
--- a/libnm/nm-dhcp4-config.h
+++ b/libnm/nm-dhcp4-config.h
@@ -15,18 +15,13 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
- * Copyright 2008 Red Hat, Inc.
- * Copyright 2008 Novell, Inc.
+ * Copyright 2014 Red Hat, Inc.
*/
#ifndef __NM_DHCP4_CONFIG_H__
#define __NM_DHCP4_CONFIG_H__
-#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION)
-#error "Only <NetworkManager.h> can be included directly."
-#endif
-
-#include <nm-object.h>
+#include <nm-dhcp-config.h>
G_BEGIN_DECLS
@@ -36,25 +31,19 @@ G_BEGIN_DECLS
#define NM_IS_DHCP4_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DHCP4_CONFIG))
#define NM_IS_DHCP4_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DHCP4_CONFIG))
-struct _NMDhcp4Config {
- NMObject parent;
-};
+typedef struct {
+ NMDhcpConfig parent;
+} NMDhcp4Config;
typedef struct {
- NMObjectClass parent;
+ NMDhcpConfigClass parent;
/*< private >*/
gpointer padding[4];
} NMDhcp4ConfigClass;
-#define NM_DHCP4_CONFIG_OPTIONS "options"
-
GType nm_dhcp4_config_get_type (void);
-GHashTable * nm_dhcp4_config_get_options (NMDhcp4Config *config);
-
-const char * nm_dhcp4_config_get_one_option (NMDhcp4Config *config, const char *option);
-
G_END_DECLS
#endif /* __NM_DHCP4_CONFIG_H__ */
diff --git a/libnm/nm-dhcp6-config.c b/libnm/nm-dhcp6-config.c
index 498f1d3b4c..c332dcaa8a 100644
--- a/libnm/nm-dhcp6-config.c
+++ b/libnm/nm-dhcp6-config.c
@@ -15,169 +15,23 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
- * Copyright 2008 - 2011 Red Hat, Inc.
- * Copyright 2008 Novell, Inc.
+ * Copyright 2014 Red Hat, Inc.
*/
-#include <string.h>
-
#include "nm-dhcp6-config.h"
-#include "nm-dbus-interface.h"
#include "nm-object-private.h"
-#include "nm-utils.h"
G_DEFINE_TYPE (NMDhcp6Config, nm_dhcp6_config, NM_TYPE_OBJECT)
-#define NM_DHCP6_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP6_CONFIG, NMDhcp6ConfigPrivate))
-
-typedef struct {
- GHashTable *options;
-} NMDhcp6ConfigPrivate;
-
-enum {
- PROP_0,
- PROP_OPTIONS,
-
- LAST_PROP
-};
-
static void
nm_dhcp6_config_init (NMDhcp6Config *config)
{
- NMDhcp6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (config);
-
- priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
-}
-
-static gboolean
-demarshal_dhcp6_options (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
-{
- NMDhcp6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (object);
- GVariantIter iter;
- const char *key;
- GVariant *opt;
-
- g_hash_table_remove_all (priv->options);
-
- g_variant_iter_init (&iter, value);
- while (g_variant_iter_next (&iter, "{&sv}", &key, &opt)) {
- g_hash_table_insert (priv->options, g_strdup (key), g_variant_dup_string (opt, NULL));
- g_variant_unref (opt);
- }
-
- _nm_object_queue_notify (object, NM_DHCP6_CONFIG_OPTIONS);
- return TRUE;
-}
-
-static void
-init_dbus (NMObject *object)
-{
- NMDhcp6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (object);
- const NMPropertiesInfo property_info[] = {
- { NM_DHCP6_CONFIG_OPTIONS, &priv->options, demarshal_dhcp6_options },
- { NULL },
- };
-
- NM_OBJECT_CLASS (nm_dhcp6_config_parent_class)->init_dbus (object);
-
- _nm_object_register_properties (object,
- NM_DBUS_INTERFACE_DHCP6_CONFIG,
- property_info);
-}
-
-static void
-finalize (GObject *object)
-{
- NMDhcp6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (object);
-
- if (priv->options)
- g_hash_table_destroy (priv->options);
-
- G_OBJECT_CLASS (nm_dhcp6_config_parent_class)->finalize (object);
-}
-
-static void
-get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- NMDhcp6Config *self = NM_DHCP6_CONFIG (object);
-
- switch (prop_id) {
- case PROP_OPTIONS:
- g_value_set_boxed (value, nm_dhcp6_config_get_options (self));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
}
static void
nm_dhcp6_config_class_init (NMDhcp6ConfigClass *config_class)
{
- GObjectClass *object_class = G_OBJECT_CLASS (config_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (config_class);
- g_type_class_add_private (config_class, sizeof (NMDhcp6ConfigPrivate));
-
_nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DHCP6_CONFIG);
-
- /* virtual methods */
- object_class->get_property = get_property;
- object_class->finalize = finalize;
-
- nm_object_class->init_dbus = init_dbus;
-
- /* properties */
-
- /**
- * NMDhcp6Config:options:
- *
- * The #GHashTable containing options of the configuration.
- *
- * Type: GLib.HashTable(utf8,utf8)
- **/
- g_object_class_install_property
- (object_class, PROP_OPTIONS,
- g_param_spec_boxed (NM_DHCP6_CONFIG_OPTIONS, "", "",
- G_TYPE_HASH_TABLE,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-}
-
-/**
- * nm_dhcp6_config_get_options:
- * @config: a #NMDhcp6Config
- *
- * Gets all the options contained in the configuration.
- *
- * Returns: (transfer none) (element-type utf8 GObject.Value): the #GHashTable containing strings for keys and values.
- * This is the internal copy used by the configuration, and must not be modified.
- **/
-GHashTable *
-nm_dhcp6_config_get_options (NMDhcp6Config *config)
-{
- g_return_val_if_fail (NM_IS_DHCP6_CONFIG (config), NULL);
-
- return NM_DHCP6_CONFIG_GET_PRIVATE (config)->options;
-}
-
-/**
- * nm_dhcp6_config_get_one_option:
- * @config: a #NMDhcp6Config
- * @option: the option to retrieve
- *
- * Gets one option by option name.
- *
- * Returns: the configuration option's value. This is the internal string used by the
- * configuration, and must not be modified.
- **/
-const char *
-nm_dhcp6_config_get_one_option (NMDhcp6Config *config, const char *option)
-{
- g_return_val_if_fail (NM_IS_DHCP6_CONFIG (config), NULL);
-
- return g_hash_table_lookup (nm_dhcp6_config_get_options (config), option);
}
diff --git a/libnm/nm-dhcp6-config.h b/libnm/nm-dhcp6-config.h
index 53bd45eeb7..abb24adfd6 100644
--- a/libnm/nm-dhcp6-config.h
+++ b/libnm/nm-dhcp6-config.h
@@ -15,18 +15,13 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
- * Copyright 2008 - 2010 Red Hat, Inc.
- * Copyright 2008 Novell, Inc.
+ * Copyright 2014 Red Hat, Inc.
*/
#ifndef __NM_DHCP6_CONFIG_H__
#define __NM_DHCP6_CONFIG_H__
-#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION)
-#error "Only <NetworkManager.h> can be included directly."
-#endif
-
-#include <nm-object.h>
+#include <nm-dhcp-config.h>
G_BEGIN_DECLS
@@ -36,25 +31,19 @@ G_BEGIN_DECLS
#define NM_IS_DHCP6_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DHCP6_CONFIG))
#define NM_IS_DHCP6_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DHCP6_CONFIG))
-struct _NMDhcp6Config {
- NMObject parent;
-};
+typedef struct {
+ NMDhcpConfig parent;
+} NMDhcp6Config;
typedef struct {
- NMObjectClass parent;
+ NMDhcpConfigClass parent;
/*< private >*/
gpointer padding[4];
} NMDhcp6ConfigClass;
-#define NM_DHCP6_CONFIG_OPTIONS "options"
-
GType nm_dhcp6_config_get_type (void);
-GHashTable * nm_dhcp6_config_get_options (NMDhcp6Config *config);
-
-const char * nm_dhcp6_config_get_one_option (NMDhcp6Config *config, const char *option);
-
G_END_DECLS
#endif /* __NM_DHCP6_CONFIG_H__ */
diff --git a/libnm/nm-ip-config.c b/libnm/nm-ip-config.c
new file mode 100644
index 0000000000..fb50ac0393
--- /dev/null
+++ b/libnm/nm-ip-config.c
@@ -0,0 +1,498 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2007 - 2011 Novell, Inc.
+ * Copyright 2008 - 2014 Red Hat, Inc.
+ */
+
+#include <string.h>
+
+#include "nm-ip-config.h"
+#include "nm-ip4-config.h"
+#include "nm-ip6-config.h"
+#include "nm-setting-ip-config.h"
+#include "nm-dbus-interface.h"
+#include "nm-object-private.h"
+#include "nm-utils.h"
+#include "nm-core-internal.h"
+
+G_DEFINE_ABSTRACT_TYPE (NMIPConfig, nm_ip_config, NM_TYPE_OBJECT)
+
+#define NM_IP_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IP_CONFIG, NMIPConfigPrivate))
+
+typedef struct {
+ char *gateway;
+ GPtrArray *addresses;
+ GPtrArray *routes;
+ char **nameservers;
+ char **domains;
+ char **searches;
+ char **wins;
+
+ gboolean new_style_data;
+} NMIPConfigPrivate;
+
+enum {
+ PROP_0,
+ PROP_FAMILY,
+ PROP_GATEWAY,
+ PROP_ADDRESSES,
+ PROP_ROUTES,
+ PROP_NAMESERVERS,
+ PROP_DOMAINS,
+ PROP_SEARCHES,
+ PROP_WINS_SERVERS,
+
+ LAST_PROP
+};
+
+static void
+nm_ip_config_init (NMIPConfig *config)
+{
+ NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (config);
+
+ priv->addresses = g_ptr_array_new ();
+ priv->routes = g_ptr_array_new ();
+ priv->nameservers = g_new0 (char *, 1);
+ priv->domains = g_new0 (char *, 1);
+ priv->searches = g_new0 (char *, 1);
+ priv->wins = g_new0 (char *, 1);
+}
+
+static gboolean
+demarshal_ip_addresses (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
+{
+ NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (object);
+
+ if (priv->new_style_data)
+ return TRUE;
+
+ g_ptr_array_unref (priv->addresses);
+ if (NM_IS_IP4_CONFIG (object))
+ priv->addresses = nm_utils_ip4_addresses_from_variant (value, NULL);
+ else
+ priv->addresses = nm_utils_ip6_addresses_from_variant (value, NULL);
+ _nm_object_queue_notify (object, NM_IP_CONFIG_ADDRESSES);
+
+ return TRUE;
+}
+
+static gboolean
+demarshal_ip_address_data (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
+{
+ NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (object);
+
+ priv->new_style_data = TRUE;
+
+ g_ptr_array_unref (priv->addresses);
+ if (NM_IS_IP4_CONFIG (object))
+ priv->addresses = nm_utils_ip_addresses_from_variant (value, AF_INET);
+ else
+ priv->addresses = nm_utils_ip_addresses_from_variant (value, AF_INET6);
+ _nm_object_queue_notify (object, NM_IP_CONFIG_ADDRESSES);
+
+ return TRUE;
+}
+
+static gboolean
+demarshal_ip_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
+{
+ char ***obj_field;
+
+ obj_field = field;
+ if (*obj_field)
+ g_strfreev (*obj_field);
+
+ if (NM_IS_IP4_CONFIG (object))
+ *obj_field = nm_utils_ip4_dns_from_variant (value);
+ else
+ *obj_field = nm_utils_ip6_dns_from_variant (value);
+
+ _nm_object_queue_notify (object, pspec->name);
+ return TRUE;
+}
+
+static gboolean
+demarshal_ip_routes (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
+{
+ NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (object);
+
+ if (priv->new_style_data)
+ return TRUE;
+
+ g_ptr_array_unref (priv->routes);
+ if (NM_IS_IP4_CONFIG (object))
+ priv->routes = nm_utils_ip4_routes_from_variant (value);
+ else
+ priv->routes = nm_utils_ip6_routes_from_variant (value);
+ _nm_object_queue_notify (object, NM_IP_CONFIG_ROUTES);
+
+ return TRUE;
+}
+
+static gboolean
+demarshal_ip_route_data (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
+{
+ NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (object);
+
+ priv->new_style_data = TRUE;
+
+ g_ptr_array_unref (priv->routes);
+ if (NM_IS_IP4_CONFIG (object))
+ priv->routes = nm_utils_ip_routes_from_variant (value, AF_INET);
+ else
+ priv->routes = nm_utils_ip_routes_from_variant (value, AF_INET6);
+ _nm_object_queue_notify (object, NM_IP_CONFIG_ROUTES);
+
+ return TRUE;
+}
+
+static void
+init_dbus (NMObject *object)
+{
+ NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (object);
+ const NMPropertiesInfo property_info[] = {
+ { NM_IP_CONFIG_GATEWAY, &priv->gateway, },
+ { NM_IP_CONFIG_ADDRESSES, &priv->addresses, demarshal_ip_addresses },
+ { "address-data", &priv->addresses, demarshal_ip_address_data },
+ { NM_IP_CONFIG_ROUTES, &priv->routes, demarshal_ip_routes },
+ { "route-data", &priv->routes, demarshal_ip_route_data },
+ { NM_IP_CONFIG_NAMESERVERS, &priv->nameservers, demarshal_ip_array },
+ { NM_IP_CONFIG_DOMAINS, &priv->domains, },
+ { NM_IP_CONFIG_SEARCHES, &priv->searches, },
+ { NM_IP_CONFIG_WINS_SERVERS, &priv->wins, demarshal_ip_array },
+ { NULL },
+ };
+
+ NM_OBJECT_CLASS (nm_ip_config_parent_class)->init_dbus (object);
+
+ _nm_object_register_properties (object,
+ (NM_IS_IP4_CONFIG (object) ?
+ NM_DBUS_INTERFACE_IP4_CONFIG :
+ NM_DBUS_INTERFACE_IP6_CONFIG),
+ property_info);
+}
+
+static void
+finalize (GObject *object)
+{
+ NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (object);
+
+ g_free (priv->gateway);
+
+ g_ptr_array_unref (priv->addresses);
+ g_ptr_array_unref (priv->routes);
+
+ g_strfreev (priv->nameservers);
+ g_strfreev (priv->domains);
+ g_strfreev (priv->searches);
+ g_strfreev (priv->wins);
+
+ G_OBJECT_CLASS (nm_ip_config_parent_class)->finalize (object);
+}
+
+static void
+get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ NMIPConfig *self = NM_IP_CONFIG (object);
+
+ switch (prop_id) {
+ case PROP_FAMILY:
+ g_value_set_int (value, nm_ip_config_get_family (self));
+ break;
+ case PROP_GATEWAY:
+ g_value_set_string (value, nm_ip_config_get_gateway (self));
+ break;
+ case PROP_ADDRESSES:
+ g_value_take_boxed (value, _nm_utils_copy_array (nm_ip_config_get_addresses (self),
+ (NMUtilsCopyFunc) nm_ip_address_dup,
+ (GDestroyNotify) nm_ip_address_unref));
+ break;
+ case PROP_ROUTES:
+ g_value_take_boxed (value, _nm_utils_copy_array (nm_ip_config_get_routes (self),
+ (NMUtilsCopyFunc) nm_ip_route_dup,
+ (GDestroyNotify) nm_ip_route_unref));
+ break;
+ case PROP_NAMESERVERS:
+ g_value_set_boxed (value, (char **) nm_ip_config_get_nameservers (self));
+ break;
+ case PROP_DOMAINS:
+ g_value_set_boxed (value, (char **) nm_ip_config_get_domains (self));
+ break;
+ case PROP_SEARCHES:
+ g_value_set_boxed (value, (char **) nm_ip_config_get_searches (self));
+ break;
+ case PROP_WINS_SERVERS:
+ g_value_set_boxed (value, (char **) nm_ip_config_get_wins_servers (self));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+nm_ip_config_class_init (NMIPConfigClass *config_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (config_class);
+ NMObjectClass *nm_object_class = NM_OBJECT_CLASS (config_class);
+
+ g_type_class_add_private (config_class, sizeof (NMIPConfigPrivate));
+
+ /* virtual methods */
+ object_class->get_property = get_property;
+ object_class->finalize = finalize;
+
+ nm_object_class->init_dbus = init_dbus;
+
+ /* properties */
+
+ /**
+ * NMIPConfig:family:
+ *
+ * The IP address family of the configuration; either %AF_INET or %AF_INET6.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_FAMILY,
+ g_param_spec_int (NM_IP_CONFIG_FAMILY, "", "",
+ 0, 255, AF_UNSPEC,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * NMIPConfig:gateway:
+ *
+ * The IP gateway address of the configuration as string.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_GATEWAY,
+ g_param_spec_string (NM_IP_CONFIG_GATEWAY, "", "",
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * NMIPConfig:addresses:
+ *
+ * A #GPtrArray containing the addresses (#NMIPAddress) of the configuration.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_ADDRESSES,
+ g_param_spec_boxed (NM_IP_CONFIG_ADDRESSES, "", "",
+ G_TYPE_PTR_ARRAY,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * NMIPConfig:routes:
+ *
+ * A #GPtrArray containing the routes (#NMIPRoute) of the configuration.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_ROUTES,
+ g_param_spec_boxed (NM_IP_CONFIG_ROUTES, "", "",
+ G_TYPE_PTR_ARRAY,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * NMIPConfig:nameservers:
+ *
+ * The array containing name server IP addresses of the configuration.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_NAMESERVERS,
+ g_param_spec_boxed (NM_IP_CONFIG_NAMESERVERS, "", "",
+ G_TYPE_STRV,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * NMIPConfig:domains:
+ *
+ * The array containing domain strings of the configuration.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_DOMAINS,
+ g_param_spec_boxed (NM_IP_CONFIG_DOMAINS, "", "",
+ G_TYPE_STRV,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * NMIPConfig:searches:
+ *
+ * The array containing DNS search strings of the configuration.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_SEARCHES,
+ g_param_spec_boxed (NM_IP_CONFIG_SEARCHES, "", "",
+ G_TYPE_STRV,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * NMIPConfig:wins-servers:
+ *
+ * The array containing WINS server IP addresses of the configuration.
+ * (This will always be empty for IPv6 configurations.)
+ **/
+ g_object_class_install_property
+ (object_class, PROP_WINS_SERVERS,
+ g_param_spec_boxed (NM_IP_CONFIG_WINS_SERVERS, "", "",
+ G_TYPE_STRV,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+}
+
+/**
+ * nm_ip_config_get_family:
+ * @config: a #NMIPConfig
+ *
+ * Gets the IP address family
+ *
+ * Returns: the IP address family; either %AF_INET or %AF_INET6
+ **/
+int
+nm_ip_config_get_family (NMIPConfig *config)
+{
+ g_return_val_if_fail (NM_IS_IP_CONFIG (config), AF_UNSPEC);
+
+ return NM_IS_IP4_CONFIG (config) ? AF_INET : AF_INET6;
+}
+
+/**
+ * nm_ip_config_get_gateway:
+ * @config: a #NMIPConfig
+ *
+ * Gets the IP gateway address.
+ *
+ * Returns: (transfer none): the IP address of the gateway.
+ **/
+const char *
+nm_ip_config_get_gateway (NMIPConfig *config)
+{
+ g_return_val_if_fail (NM_IS_IP_CONFIG (config), NULL);
+
+ return NM_IP_CONFIG_GET_PRIVATE (config)->gateway;
+}
+
+/**
+ * nm_ip_config_get_addresses:
+ * @config: a #NMIPConfig
+ *
+ * Gets the IP addresses (containing the address, prefix, and gateway).
+ *
+ * Returns: (element-type NMIPAddress) (transfer none): the #GPtrArray
+ * containing #NMIPAddress<!-- -->es. This is the internal copy used by the
+ * configuration and must not be modified.
+ **/
+GPtrArray *
+nm_ip_config_get_addresses (NMIPConfig *config)
+{
+ g_return_val_if_fail (NM_IS_IP_CONFIG (config), NULL);
+
+ return NM_IP_CONFIG_GET_PRIVATE (config)->addresses;
+}
+
+/**
+ * nm_ip_config_get_nameservers:
+ * @config: a #NMIPConfig
+ *
+ * Gets the domain name servers (DNS).
+ *
+ * Returns: (transfer none): the array of nameserver IP addresses
+ **/
+const char * const *
+nm_ip_config_get_nameservers (NMIPConfig *config)
+{
+ g_return_val_if_fail (NM_IS_IP_CONFIG (config), NULL);
+
+ return (const char * const *) NM_IP_CONFIG_GET_PRIVATE (config)->nameservers;
+}
+
+/**
+ * nm_ip_config_get_domains:
+ * @config: a #NMIPConfig
+ *
+ * Gets the domain names.
+ *
+ * Returns: (transfer none): the array of domains.
+ * (This is never %NULL, though it may be 0-length).
+ **/
+const char * const *
+nm_ip_config_get_domains (NMIPConfig *config)
+{
+ g_return_val_if_fail (NM_IS_IP_CONFIG (config), NULL);
+
+ return (const char * const *) NM_IP_CONFIG_GET_PRIVATE (config)->domains;
+}
+
+/**
+ * nm_ip_config_get_searches:
+ * @config: a #NMIPConfig
+ *
+ * Gets the DNS searches.
+ *
+ * Returns: (transfer none): the array of DNS search strings.
+ * (This is never %NULL, though it may be 0-length).
+ **/
+const char * const *
+nm_ip_config_get_searches (NMIPConfig *config)
+{
+ g_return_val_if_fail (NM_IS_IP_CONFIG (config), NULL);
+
+ return (const char * const *) NM_IP_CONFIG_GET_PRIVATE (config)->searches;
+}
+
+/**
+ * nm_ip_config_get_wins_servers:
+ * @config: a #NMIPConfig
+ *
+ * Gets the Windows Internet Name Service servers (WINS).
+ *
+ * Returns: (transfer none): the arry of WINS server IP address strings.
+ * (This is never %NULL, though it may be 0-length.)
+ **/
+const char * const *
+nm_ip_config_get_wins_servers (NMIPConfig *config)
+{
+ g_return_val_if_fail (NM_IS_IP_CONFIG (config), NULL);
+
+ return (const char * const *) NM_IP_CONFIG_GET_PRIVATE (config)->wins;
+}
+
+/**
+ * nm_ip_config_get_routes:
+ * @config: a #NMIPConfig
+ *
+ * Gets the routes.
+ *
+ * Returns: (element-type NMIPRoute) (transfer none): the #GPtrArray containing
+ * #NMIPRoutes. This is the internal copy used by the configuration, and must
+ * not be modified.
+ **/
+GPtrArray *
+nm_ip_config_get_routes (NMIPConfig *config)
+{
+ g_return_val_if_fail (NM_IS_IP_CONFIG (config), NULL);
+
+ return NM_IP_CONFIG_GET_PRIVATE (config)->routes;
+}
diff --git a/libnm/nm-ip-config.h b/libnm/nm-ip-config.h
new file mode 100644
index 0000000000..815135a055
--- /dev/null
+++ b/libnm/nm-ip-config.h
@@ -0,0 +1,73 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2007 - 2008 Novell, Inc.
+ * Copyright 2008 - 2014 Red Hat, Inc.
+ */
+
+#ifndef __NM_IP_CONFIG_H__
+#define __NM_IP_CONFIG_H__
+
+#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION)
+#error "Only <NetworkManager.h> can be included directly."
+#endif
+
+#include <nm-object.h>
+
+G_BEGIN_DECLS
+
+#define NM_TYPE_IP_CONFIG (nm_ip_config_get_type ())
+#define NM_IP_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_IP_CONFIG, NMIPConfig))
+#define NM_IP_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_IP_CONFIG, NMIPConfigClass))
+#define NM_IS_IP_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_IP_CONFIG))
+#define NM_IS_IP_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_IP_CONFIG))
+#define NM_IP_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_IP_CONFIG, NMIPConfigClass))
+
+struct _NMIPConfig {
+ NMObject parent;
+};
+
+typedef struct {
+ NMObjectClass parent;
+
+ /*< private >*/
+ gpointer padding[8];
+} NMIPConfigClass;
+
+#define NM_IP_CONFIG_FAMILY "family"
+#define NM_IP_CONFIG_GATEWAY "gateway"
+#define NM_IP_CONFIG_ADDRESSES "addresses"
+#define NM_IP_CONFIG_ROUTES "routes"
+#define NM_IP_CONFIG_NAMESERVERS "nameservers"
+#define NM_IP_CONFIG_DOMAINS "domains"
+#define NM_IP_CONFIG_SEARCHES "searches"
+#define NM_IP_CONFIG_WINS_SERVERS "wins-servers"
+
+GType nm_ip_config_get_type (void);
+
+int nm_ip_config_get_family (NMIPConfig *config);
+const char * nm_ip_config_get_gateway (NMIPConfig *config);
+GPtrArray * nm_ip_config_get_addresses (NMIPConfig *config);
+GPtrArray * nm_ip_config_get_routes (NMIPConfig *config);
+const char * const *nm_ip_config_get_nameservers (NMIPConfig *config);
+const char * const *nm_ip_config_get_domains (NMIPConfig *config);
+const char * const *nm_ip_config_get_searches (NMIPConfig *config);
+const char * const *nm_ip_config_get_wins_servers (NMIPConfig *config);
+
+G_END_DECLS
+
+#endif /* __NM_IP_CONFIG_H__ */
diff --git a/libnm/nm-ip4-config.c b/libnm/nm-ip4-config.c
index ac3e5b36e9..8a7e007bfe 100644
--- a/libnm/nm-ip4-config.c
+++ b/libnm/nm-ip4-config.c
@@ -15,397 +15,23 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
- * Copyright 2007 - 2011 Novell, Inc.
- * Copyright 2008 Red Hat, Inc.
+ * Copyright 2014 Red Hat, Inc.
*/
-#include <string.h>
-
-#include <nm-setting-ip4-config.h>
#include "nm-ip4-config.h"
-#include "nm-dbus-interface.h"
#include "nm-object-private.h"
-#include "nm-utils.h"
-#include "nm-core-internal.h"
-
-G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, NM_TYPE_OBJECT)
-
-#define NM_IP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IP4_CONFIG, NMIP4ConfigPrivate))
-typedef struct {
- char *gateway;
- GPtrArray *addresses;
- GPtrArray *routes;
- char **nameservers;
- char **domains;
- char **searches;
- char **wins;
-} NMIP4ConfigPrivate;
-
-enum {
- PROP_0,
- PROP_GATEWAY,
- PROP_ADDRESSES,
- PROP_ROUTES,
- PROP_NAMESERVERS,
- PROP_DOMAINS,
- PROP_SEARCHES,
- PROP_WINS_SERVERS,
-
- LAST_PROP
-};
+G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, NM_TYPE_IP_CONFIG)
static void
nm_ip4_config_init (NMIP4Config *config)
{
- NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
-
- priv->addresses = g_ptr_array_new ();
- priv->routes = g_ptr_array_new ();
- priv->nameservers = g_new0 (char *, 1);
- priv->domains = g_new0 (char *, 1);
- priv->searches = g_new0 (char *, 1);
- priv->wins = g_new0 (char *, 1);
-}
-
-static gboolean
-demarshal_ip4_address_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
-{
- NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object);
-
- g_ptr_array_unref (priv->addresses);
- priv->addresses = nm_utils_ip4_addresses_from_variant (value);
- _nm_object_queue_notify (object, NM_IP4_CONFIG_ADDRESSES);
-
- return TRUE;
-}
-
-static gboolean
-demarshal_ip4_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
-{
- char ***obj_field;
-
- obj_field = field;
- if (*obj_field)
- g_strfreev (*obj_field);
-
- *obj_field = nm_utils_ip4_dns_from_variant (value);
-
- _nm_object_queue_notify (object, pspec->name);
- return TRUE;
-}
-
-static gboolean
-demarshal_ip4_routes_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
-{
- NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object);
-
- g_ptr_array_unref (priv->routes);
- priv->routes = nm_utils_ip4_routes_from_variant (value);
- _nm_object_queue_notify (object, NM_IP4_CONFIG_ROUTES);
-
- return TRUE;
-}
-
-static void
-init_dbus (NMObject *object)
-{
- NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object);
- const NMPropertiesInfo property_info[] = {
- { NM_IP4_CONFIG_GATEWAY, &priv->gateway, },
- { NM_IP4_CONFIG_ADDRESSES, &priv->addresses, demarshal_ip4_address_array },
- { NM_IP4_CONFIG_ROUTES, &priv->routes, demarshal_ip4_routes_array },
- { NM_IP4_CONFIG_NAMESERVERS, &priv->nameservers, demarshal_ip4_array },
- { NM_IP4_CONFIG_DOMAINS, &priv->domains, },
- { NM_IP4_CONFIG_SEARCHES, &priv->searches, },
- { NM_IP4_CONFIG_WINS_SERVERS, &priv->wins, demarshal_ip4_array },
- { NULL },
- };
-
- NM_OBJECT_CLASS (nm_ip4_config_parent_class)->init_dbus (object);
-
- _nm_object_register_properties (object,
- NM_DBUS_INTERFACE_IP4_CONFIG,
- property_info);
-}
-
-static void
-finalize (GObject *object)
-{
- NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object);
-
- g_free (priv->gateway);
-
- g_ptr_array_unref (priv->addresses);
- g_ptr_array_unref (priv->routes);
-
- g_strfreev (priv->nameservers);
- g_strfreev (priv->domains);
- g_strfreev (priv->searches);
- g_strfreev (priv->wins);
-
- G_OBJECT_CLASS (nm_ip4_config_parent_class)->finalize (object);
-}
-
-static void
-get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- NMIP4Config *self = NM_IP4_CONFIG (object);
-
- switch (prop_id) {
- case PROP_GATEWAY:
- g_value_set_string (value, nm_ip4_config_get_gateway (self));
- break;
- case PROP_ADDRESSES:
- g_value_take_boxed (value, _nm_utils_copy_array (nm_ip4_config_get_addresses (self),
- (NMUtilsCopyFunc) nm_ip4_address_dup,
- (GDestroyNotify) nm_ip4_address_unref));
- break;
- case PROP_ROUTES:
- g_value_take_boxed (value, _nm_utils_copy_array (nm_ip4_config_get_routes (self),
- (NMUtilsCopyFunc) nm_ip4_route_dup,
- (GDestroyNotify) nm_ip4_route_unref));
- break;
- case PROP_NAMESERVERS:
- g_value_set_boxed (value, (char **) nm_ip4_config_get_nameservers (self));
- break;
- case PROP_DOMAINS:
- g_value_set_boxed (value, (char **) nm_ip4_config_get_domains (self));
- break;
- case PROP_SEARCHES:
- g_value_set_boxed (value, (char **) nm_ip4_config_get_searches (self));
- break;
- case PROP_WINS_SERVERS:
- g_value_set_boxed (value, (char **) nm_ip4_config_get_wins_servers (self));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
}
static void
nm_ip4_config_class_init (NMIP4ConfigClass *config_class)
{
- GObjectClass *object_class = G_OBJECT_CLASS (config_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (config_class);
- g_type_class_add_private (config_class, sizeof (NMIP4ConfigPrivate));
-
_nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_IP4_CONFIG);
-
- /* virtual methods */
- object_class->get_property = get_property;
- object_class->finalize = finalize;
-
- nm_object_class->init_dbus = init_dbus;
-
- /* properties */
-
- /**
- * NMIP4Config:gateway:
- *
- * The IP4 gateway address of the configuration as string.
- **/
- g_object_class_install_property
- (object_class, PROP_GATEWAY,
- g_param_spec_string (NM_IP4_CONFIG_GATEWAY, "", "",
- NULL,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMIP4Config:addresses:
- *
- * A #GPtrArray containing the addresses (#NMIP4Address) of the configuration.
- **/
- g_object_class_install_property
- (object_class, PROP_ADDRESSES,
- g_param_spec_boxed (NM_IP4_CONFIG_ADDRESSES, "", "",
- G_TYPE_PTR_ARRAY,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMIP4Config:routes:
- *
- * A #GPtrArray containing the routes (#NMIP4Route) of the configuration.
- **/
- g_object_class_install_property
- (object_class, PROP_ROUTES,
- g_param_spec_boxed (NM_IP4_CONFIG_ROUTES, "", "",
- G_TYPE_PTR_ARRAY,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMIP4Config:nameservers:
- *
- * The array containing name server IP addresses of the configuration.
- **/
- g_object_class_install_property
- (object_class, PROP_NAMESERVERS,
- g_param_spec_boxed (NM_IP4_CONFIG_NAMESERVERS, "", "",
- G_TYPE_STRV,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMIP4Config:domains:
- *
- * The array containing domain strings of the configuration.
- **/
- g_object_class_install_property
- (object_class, PROP_DOMAINS,
- g_param_spec_boxed (NM_IP4_CONFIG_DOMAINS, "", "",
- G_TYPE_STRV,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMIP4Config:searches:
- *
- * The array containing DNS search strings of the configuration.
- **/
- g_object_class_install_property
- (object_class, PROP_SEARCHES,
- g_param_spec_boxed (NM_IP4_CONFIG_SEARCHES, "", "",
- G_TYPE_STRV,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMIP4Config:wins-servers:
- *
- * The array containing WINS server IP addresses of the configuration.
- **/
- g_object_class_install_property
- (object_class, PROP_WINS_SERVERS,
- g_param_spec_boxed (NM_IP4_CONFIG_WINS_SERVERS, "", "",
- G_TYPE_STRV,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-}
-
-/**
- * nm_ip4_config_get_gateway:
- * @config: a #NMIP4Config
- *
- * Gets the IP4 gateway address.
- *
- * Returns: (transfer none): the IP4 address of the gateway.
- **/
-const char *
-nm_ip4_config_get_gateway (NMIP4Config *config)
-{
- g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
-
- return NM_IP4_CONFIG_GET_PRIVATE (config)->gateway;
-}
-
-/**
- * nm_ip4_config_get_addresses:
- * @config: a #NMIP4Config
- *
- * Gets the IP4 addresses (containing the address, prefix, and gateway).
- *
- * Returns: (element-type NMIP4Address) (transfer none): the #GPtrArray
- * containing #NMIP4Address<!-- -->es. This is the internal copy used by the
- * configuration and must not be modified.
- **/
-GPtrArray *
-nm_ip4_config_get_addresses (NMIP4Config *config)
-{
- g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
-
- return NM_IP4_CONFIG_GET_PRIVATE (config)->addresses;
-}
-
-/**
- * nm_ip4_config_get_nameservers:
- * @config: a #NMIP4Config
- *
- * Gets the domain name servers (DNS).
- *
- * Returns: (transfer none): the array of nameserver IP addresses
- **/
-const char * const *
-nm_ip4_config_get_nameservers (NMIP4Config *config)
-{
- g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
-
- return (const char * const *) NM_IP4_CONFIG_GET_PRIVATE (config)->nameservers;
-}
-
-/**
- * nm_ip4_config_get_domains:
- * @config: a #NMIP4Config
- *
- * Gets the domain names.
- *
- * Returns: (transfer none): the array of domains.
- * (This is never %NULL, though it may be 0-length).
- **/
-const char * const *
-nm_ip4_config_get_domains (NMIP4Config *config)
-{
- g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
-
- return (const char * const *) NM_IP4_CONFIG_GET_PRIVATE (config)->domains;
-}
-
-/**
- * nm_ip4_config_get_searches:
- * @config: a #NMIP4Config
- *
- * Gets the DNS searches.
- *
- * Returns: (transfer none): the array of DNS search strings.
- * (This is never %NULL, though it may be 0-length).
- **/
-const char * const *
-nm_ip4_config_get_searches (NMIP4Config *config)
-{
- g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
-
- return (const char * const *) NM_IP4_CONFIG_GET_PRIVATE (config)->searches;
-}
-
-/**
- * nm_ip4_config_get_wins_servers:
- * @config: a #NMIP4Config
- *
- * Gets the Windows Internet Name Service servers (WINS).
- *
- * Returns: (element-type guint32) (transfer none): the #GArray containing #guint32s.
- * This is the internal copy used by the configuration and must not be
- * modified.
- **/
-const char * const *
-nm_ip4_config_get_wins_servers (NMIP4Config *config)
-{
- g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
-
- return (const char * const *) NM_IP4_CONFIG_GET_PRIVATE (config)->wins;
-}
-
-/**
- * nm_ip4_config_get_routes:
- * @config: a #NMIP4Config
- *
- * Gets the routes.
- *
- * Returns: (element-type NMIP4Route) (transfer none): the #GPtrArray containing
- * #NMIP4Routes. This is the internal copy used by the configuration, and must
- * not be modified.
- **/
-GPtrArray *
-nm_ip4_config_get_routes (NMIP4Config *config)
-{
- g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
-
- return NM_IP4_CONFIG_GET_PRIVATE (config)->routes;
}
diff --git a/libnm/nm-ip4-config.h b/libnm/nm-ip4-config.h
index a933a5e277..e2a18e0f31 100644
--- a/libnm/nm-ip4-config.h
+++ b/libnm/nm-ip4-config.h
@@ -22,11 +22,7 @@
#ifndef __NM_IP4_CONFIG_H__
#define __NM_IP4_CONFIG_H__
-#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION)
-#error "Only <NetworkManager.h> can be included directly."
-#endif
-
-#include <nm-object.h>
+#include <nm-ip-config.h>
G_BEGIN_DECLS
@@ -37,35 +33,19 @@ G_BEGIN_DECLS
#define NM_IS_IP4_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_IP4_CONFIG))
#define NM_IP4_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_IP4_CONFIG, NMIP4ConfigClass))
-struct _NMIP4Config {
- NMObject parent;
-};
+typedef struct {
+ NMIPConfig parent;
+} NMIP4Config;
typedef struct {
- NMObjectClass parent;
+ NMIPConfigClass parent;
/*< private >*/
gpointer padding[4];
} NMIP4ConfigClass;
-#define NM_IP4_CONFIG_GATEWAY "gateway"
-#define NM_IP4_CONFIG_ADDRESSES "addresses"
-#define NM_IP4_CONFIG_ROUTES "routes"
-#define NM_IP4_CONFIG_NAMESERVERS "nameservers"
-#define NM_IP4_CONFIG_DOMAINS "domains"
-#define NM_IP4_CONFIG_SEARCHES "searches"
-#define NM_IP4_CONFIG_WINS_SERVERS "wins-servers"
-
GType nm_ip4_config_get_type (void);
-const char * nm_ip4_config_get_gateway (NMIP4Config *config);
-GPtrArray * nm_ip4_config_get_addresses (NMIP4Config *config);
-GPtrArray * nm_ip4_config_get_routes (NMIP4Config *config);
-const char * const *nm_ip4_config_get_nameservers (NMIP4Config *config);
-const char * const *nm_ip4_config_get_domains (NMIP4Config *config);
-const char * const *nm_ip4_config_get_searches (NMIP4Config *config);
-const char * const *nm_ip4_config_get_wins_servers (NMIP4Config *config);
-
G_END_DECLS
#endif /* __NM_IP4_CONFIG_H__ */
diff --git a/libnm/nm-ip6-config.c b/libnm/nm-ip6-config.c
index 8b48c15992..cd64e7594f 100644
--- a/libnm/nm-ip6-config.c
+++ b/libnm/nm-ip6-config.c
@@ -15,361 +15,23 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
- * Copyright 2007 - 2008 Novell, Inc.
- * Copyright 2008 - 2014 Red Hat, Inc.
+ * Copyright 2014 Red Hat, Inc.
*/
-#include <string.h>
-
-#include <nm-setting-ip6-config.h>
#include "nm-ip6-config.h"
-#include "nm-dbus-interface.h"
#include "nm-object-private.h"
-#include "nm-utils.h"
-#include "nm-core-internal.h"
-
-G_DEFINE_TYPE (NMIP6Config, nm_ip6_config, NM_TYPE_OBJECT)
-
-#define NM_IP6_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IP6_CONFIG, NMIP6ConfigPrivate))
-
-typedef struct {
- char *gateway;
- GPtrArray *addresses;
- GPtrArray *routes;
- char **nameservers;
- char **domains;
- char **searches;
-} NMIP6ConfigPrivate;
-
-enum {
- PROP_0,
- PROP_GATEWAY,
- PROP_ADDRESSES,
- PROP_ROUTES,
- PROP_NAMESERVERS,
- PROP_DOMAINS,
- PROP_SEARCHES,
-
- LAST_PROP
-};
-
-static gboolean
-demarshal_ip6_address_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
-{
- NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object);
-
- g_ptr_array_unref (priv->addresses);
- priv->addresses = nm_utils_ip6_addresses_from_variant (value);
- _nm_object_queue_notify (object, NM_IP6_CONFIG_ADDRESSES);
-
- return TRUE;
-}
-
-static gboolean
-demarshal_ip6_nameserver_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
-{
- char ***obj_field;
-
- obj_field = field;
- if (*obj_field)
- g_strfreev (*obj_field);
-
- *obj_field = nm_utils_ip6_dns_from_variant (value);
-
- _nm_object_queue_notify (object, pspec->name);
- return TRUE;
-}
-
-static gboolean
-demarshal_ip6_routes_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
-{
- NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object);
-
- g_ptr_array_unref (priv->routes);
- priv->routes = nm_utils_ip6_routes_from_variant (value);
- _nm_object_queue_notify (object, NM_IP6_CONFIG_ROUTES);
-
- return TRUE;
-}
-
-static void
-init_dbus (NMObject *object)
-{
- NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object);
- const NMPropertiesInfo property_info[] = {
- { NM_IP6_CONFIG_GATEWAY, &priv->gateway, },
- { NM_IP6_CONFIG_ADDRESSES, &priv->addresses, demarshal_ip6_address_array },
- { NM_IP6_CONFIG_ROUTES, &priv->routes, demarshal_ip6_routes_array },
- { NM_IP6_CONFIG_NAMESERVERS, &priv->nameservers, demarshal_ip6_nameserver_array },
- { NM_IP6_CONFIG_DOMAINS, &priv->domains, },
- { NM_IP6_CONFIG_SEARCHES, &priv->searches, },
- { NULL },
- };
-
- NM_OBJECT_CLASS (nm_ip6_config_parent_class)->init_dbus (object);
-
- _nm_object_register_properties (object,
- NM_DBUS_INTERFACE_IP6_CONFIG,
- property_info);
-}
-
-/**
- * nm_ip6_config_get_gateway:
- * @config: a #NMIP6Config
- *
- * Gets the IP6 gateway.
- *
- * Returns: (transfer none): the IPv6 gateway of the configuration.
- **/
-const char *
-nm_ip6_config_get_gateway (NMIP6Config *config)
-{
- g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL);
-
- return NM_IP6_CONFIG_GET_PRIVATE (config)->gateway;
-}
-
-/**
- * nm_ip6_config_get_addresses:
- * @config: a #NMIP6Config
- *
- * Gets the IP6 addresses (containing the address, prefix, and gateway).
- *
- * Returns: (element-type NMIP6Address) (transfer none): the #GPtrArray
- * containing #NMIP6Address<!-- -->es. This is the internal copy used by the
- * configuration and must not be modified.
- **/
-GPtrArray *
-nm_ip6_config_get_addresses (NMIP6Config *config)
-{
- g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL);
-
- return NM_IP6_CONFIG_GET_PRIVATE (config)->addresses;
-}
-
-/**
- * nm_ip6_config_get_nameservers:
- * @config: a #NMIP6Config
- *
- * Gets the domain name servers (DNS).
- *
- * Returns: (transfer none): the array of nameserver IP addresses
- **/
-const char * const *
-nm_ip6_config_get_nameservers (NMIP6Config *config)
-{
- g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL);
- return (const char * const *) NM_IP6_CONFIG_GET_PRIVATE (config)->nameservers;
-}
-
-/**
- * nm_ip6_config_get_domains:
- * @config: a #NMIP6Config
- *
- * Gets the domain names.
- *
- * Returns: (transfer none): the array of domains.
- * (This is never %NULL, though it may be 0-length).
- **/
-const char * const *
-nm_ip6_config_get_domains (NMIP6Config *config)
-{
- g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL);
-
- return (const char * const *) NM_IP6_CONFIG_GET_PRIVATE (config)->domains;
-}
-
-/**
- * nm_ip6_config_get_searches:
- * @config: a #NMIP6Config
- *
- * Gets the DNS search strings.
- *
- * Returns: (transfer none): the array of DNS search strings.
- * (This is never %NULL, though it may be 0-length).
- **/
-const char * const *
-nm_ip6_config_get_searches (NMIP6Config *config)
-{
- g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL);
-
- return (const char * const *) NM_IP6_CONFIG_GET_PRIVATE (config)->searches;
-}
-
-/**
- * nm_ip6_config_get_routes:
- * @config: a #NMIP6Config
- *
- * Gets the routes.
- *
- * Returns: (element-type NMIP6Route) (transfer none): the #GPtrArray containing
- * #NMIP6Routes. This is the internal copy used by the configuration, and must
- * not be modified.
- **/
-GPtrArray *
-nm_ip6_config_get_routes (NMIP6Config *config)
-{
- g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL);
-
- return NM_IP6_CONFIG_GET_PRIVATE (config)->routes;
-}
-
-static void
-finalize (GObject *object)
-{
- NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object);
-
- g_free (priv->gateway);
-
- g_ptr_array_unref (priv->addresses);
- g_ptr_array_unref (priv->routes);
-
- g_strfreev (priv->nameservers);
- g_strfreev (priv->domains);
- g_strfreev (priv->searches);
-
- G_OBJECT_CLASS (nm_ip6_config_parent_class)->finalize (object);
-}
-
-static void
-get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- NMIP6Config *self = NM_IP6_CONFIG (object);
-
- switch (prop_id) {
- case PROP_GATEWAY:
- g_value_set_string (value, nm_ip6_config_get_gateway (self));
- break;
- case PROP_ADDRESSES:
- g_value_take_boxed (value, _nm_utils_copy_array (nm_ip6_config_get_addresses (self),
- (NMUtilsCopyFunc) nm_ip6_address_dup,
- (GDestroyNotify) nm_ip6_address_unref));
- break;
- case PROP_ROUTES:
- g_value_take_boxed (value, _nm_utils_copy_array (nm_ip6_config_get_routes (self),
- (NMUtilsCopyFunc) nm_ip6_route_dup,
- (GDestroyNotify) nm_ip6_route_unref));
- break;
- case PROP_NAMESERVERS:
- g_value_set_boxed (value, (char **) nm_ip6_config_get_nameservers (self));
- break;
- case PROP_DOMAINS:
- g_value_set_boxed (value, (char **) nm_ip6_config_get_domains (self));
- break;
- case PROP_SEARCHES:
- g_value_set_boxed (value, (char **) nm_ip6_config_get_searches (self));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
+G_DEFINE_TYPE (NMIP6Config, nm_ip6_config, NM_TYPE_IP_CONFIG)
static void
nm_ip6_config_init (NMIP6Config *config)
{
- NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config);
-
- priv->addresses = g_ptr_array_new ();
- priv->routes = g_ptr_array_new ();
- priv->nameservers = g_new0 (char *, 1);
- priv->domains = g_new0 (char *, 1);
- priv->searches = g_new0 (char *, 1);
}
static void
nm_ip6_config_class_init (NMIP6ConfigClass *config_class)
{
- GObjectClass *object_class = G_OBJECT_CLASS (config_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (config_class);
- g_type_class_add_private (config_class, sizeof (NMIP6ConfigPrivate));
-
_nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_IP6_CONFIG);
-
- /* virtual methods */
- object_class->get_property = get_property;
- object_class->finalize = finalize;
-
- nm_object_class->init_dbus = init_dbus;
-
- /* properties */
-
- /**
- * NMIP6Config:gateway:
- *
- * The IPv6 gateway as string
- **/
- g_object_class_install_property
- (object_class, PROP_GATEWAY,
- g_param_spec_string (NM_IP6_CONFIG_GATEWAY, "", "",
- NULL,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMIP6Config:addresses:
- *
- * The #GPtrArray containing the IPv6 addresses (#NMIP6Address).
- **/
- g_object_class_install_property
- (object_class, PROP_ADDRESSES,
- g_param_spec_boxed (NM_IP6_CONFIG_ADDRESSES, "", "",
- G_TYPE_PTR_ARRAY,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMIP6Config:routes:
- *
- * The #GPtrArray containing the IPv6 routes (#NMIP6Route).
- **/
- g_object_class_install_property
- (object_class, PROP_ROUTES,
- g_param_spec_boxed (NM_IP6_CONFIG_ROUTES, "", "",
- G_TYPE_PTR_ARRAY,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMIP6Config:nameservers:
- *
- * The #GPtrArray containing elements of type 'struct ip6_addr' which
- * contain the addresses of nameservers of the configuration.
- **/
- g_object_class_install_property
- (object_class, PROP_NAMESERVERS,
- g_param_spec_boxed (NM_IP6_CONFIG_NAMESERVERS, "", "",
- G_TYPE_STRV,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMIP6Config:domains:
- *
- * The #GPtrArray containing domain strings of the configuration.
- **/
- g_object_class_install_property
- (object_class, PROP_DOMAINS,
- g_param_spec_boxed (NM_IP6_CONFIG_DOMAINS, "", "",
- G_TYPE_STRV,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMIP6Config:searches:
- *
- * The #GPtrArray containing dns search strings of the configuration.
- **/
- g_object_class_install_property
- (object_class, PROP_SEARCHES,
- g_param_spec_boxed (NM_IP6_CONFIG_SEARCHES, "", "",
- G_TYPE_STRV,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-
}
diff --git a/libnm/nm-ip6-config.h b/libnm/nm-ip6-config.h
index 2c98633411..1953476d00 100644
--- a/libnm/nm-ip6-config.h
+++ b/libnm/nm-ip6-config.h
@@ -22,11 +22,7 @@
#ifndef __NM_IP6_CONFIG_H__
#define __NM_IP6_CONFIG_H__
-#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION)
-#error "Only <NetworkManager.h> can be included directly."
-#endif
-
-#include <nm-object.h>
+#include <nm-ip-config.h>
G_BEGIN_DECLS
@@ -37,33 +33,19 @@ G_BEGIN_DECLS
#define NM_IS_IP6_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_IP6_CONFIG))
#define NM_IP6_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_IP6_CONFIG, NMIP6ConfigClass))
-struct _NMIP6Config {
- NMObject parent;
-};
+typedef struct {
+ NMIPConfig parent;
+} NMIP6Config;
typedef struct {
- NMObjectClass parent;
+ NMIPConfigClass parent;
/*< private >*/
gpointer padding[4];
} NMIP6ConfigClass;
-#define NM_IP6_CONFIG_GATEWAY "gateway"
-#define NM_IP6_CONFIG_ADDRESSES "addresses"
-#define NM_IP6_CONFIG_ROUTES "routes"
-#define NM_IP6_CONFIG_NAMESERVERS "nameservers"
-#define NM_IP6_CONFIG_DOMAINS "domains"
-#define NM_IP6_CONFIG_SEARCHES "searches"
-
GType nm_ip6_config_get_type (void);
-const char * nm_ip6_config_get_gateway (NMIP6Config *config);
-GPtrArray * nm_ip6_config_get_addresses (NMIP6Config *config);
-GPtrArray * nm_ip6_config_get_routes (NMIP6Config *config);
-const char * const * nm_ip6_config_get_nameservers (NMIP6Config *config);
-const char * const * nm_ip6_config_get_domains (NMIP6Config *config);
-const char * const * nm_ip6_config_get_searches (NMIP6Config *config);
-
G_END_DECLS
#endif /* __NM_IP6_CONFIG_H__ */
diff --git a/libnm/nm-manager.c b/libnm/nm-manager.c
index d60845edc9..fc558620c7 100644
--- a/libnm/nm-manager.c
+++ b/libnm/nm-manager.c
@@ -743,6 +743,8 @@ typedef struct {
char *new_connection_path;
} ActivateInfo;
+static void active_removed (NMObject *object, NMActiveConnection *active, gpointer user_data);
+
static void
activate_info_complete (ActivateInfo *info,
NMActiveConnection *active,
@@ -750,6 +752,7 @@ activate_info_complete (ActivateInfo *info,
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (info->manager);
+ g_signal_handlers_disconnect_by_func (info->manager, G_CALLBACK (active_removed), info);
if (active)
g_simple_async_result_set_op_res_gpointer (info->simple, g_object_ref (active), g_object_unref);
else
@@ -837,6 +840,22 @@ activation_cancelled (GCancellable *cancellable,
}
static void
+active_removed (NMObject *object, NMActiveConnection *active, gpointer user_data)
+{
+ ActivateInfo *info = user_data;
+ GError *error = NULL;
+
+ if (strcmp (info->active_path, nm_object_get_path (NM_OBJECT (active))))
+ return;
+
+ error = g_error_new_literal (NM_CLIENT_ERROR,
+ NM_CLIENT_ERROR_FAILED,
+ _("Active connection could not be attached to the device"));
+ activate_info_complete (info, NULL, error);
+ g_clear_error (&error);
+}
+
+static void
activate_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
@@ -852,6 +871,9 @@ activate_cb (GObject *object,
G_CALLBACK (activation_cancelled), info);
}
+ g_signal_connect (info->manager, "active-connection-removed",
+ G_CALLBACK (active_removed), info);
+
recheck_pending_activations (info->manager);
} else {
g_dbus_error_strip_remote_error (error);
@@ -1043,8 +1065,6 @@ object_creation_failed (NMObject *object, const char *failed_path)
GError *error;
GSList *iter;
- g_return_if_fail (find_active_connection_by_path (self, failed_path) == NULL);
-
/* A newly activated connection failed due to some immediate error
* and disappeared from active connection list. Make sure the
* callback gets called.
diff --git a/libnm/nm-object.c b/libnm/nm-object.c
index 2023a74fa0..4bc82b8b1e 100644
--- a/libnm/nm-object.c
+++ b/libnm/nm-object.c
@@ -209,15 +209,9 @@ deferred_notify_cb (gpointer data)
g_object_ref (object);
- /* Emit property change notifications first */
- for (iter = props; iter; iter = g_slist_next (iter)) {
- NotifyItem *item = iter->data;
-
- if (item->property)
- g_object_notify (G_OBJECT (object), item->property);
- }
-
- /* And added/removed signals second */
+ /* Emit added/removed signals first since some of our internal objects
+ * use the added/removed signals for new object processing.
+ */
for (iter = props; iter; iter = g_slist_next (iter)) {
NotifyItem *item = iter->data;
char buf[50];
@@ -243,6 +237,15 @@ deferred_notify_cb (gpointer data)
g_signal_emit_by_name (object, buf, item->changed);
}
}
+
+ /* Emit property change notifications second */
+ for (iter = props; iter; iter = g_slist_next (iter)) {
+ NotifyItem *item = iter->data;
+
+ if (item->property)
+ g_object_notify (G_OBJECT (object), item->property);
+ }
+
g_object_unref (object);
g_slist_free_full (props, (GDestroyNotify) notify_item_free);
diff --git a/libnm/nm-types.h b/libnm/nm-types.h
index 940a329454..3602878a6a 100644
--- a/libnm/nm-types.h
+++ b/libnm/nm-types.h
@@ -43,10 +43,8 @@ typedef struct _NMDeviceTeam NMDeviceTeam;
typedef struct _NMDeviceVlan NMDeviceVlan;
typedef struct _NMDeviceWifi NMDeviceWifi;
typedef struct _NMDeviceWimax NMDeviceWimax;
-typedef struct _NMDhcp4Config NMDhcp4Config;
-typedef struct _NMDhcp6Config NMDhcp6Config;
-typedef struct _NMIP4Config NMIP4Config;
-typedef struct _NMIP6Config NMIP6Config;
+typedef struct _NMDhcpConfig NMDhcpConfig;
+typedef struct _NMIPConfig NMIPConfig;
typedef struct _NMObject NMObject;
typedef struct _NMRemoteConnection NMRemoteConnection;
typedef struct _NMSecretAgent NMSecretAgent;
diff --git a/libnm/nm-vpn-editor-plugin.c b/libnm/nm-vpn-editor-plugin.c
new file mode 100644
index 0000000000..02393fa8e8
--- /dev/null
+++ b/libnm/nm-vpn-editor-plugin.c
@@ -0,0 +1,179 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2008 - 2010 Red Hat, Inc.
+ * Copyright 2008 Novell, Inc.
+ */
+
+#include "nm-vpn-editor-plugin.h"
+
+static void nm_vpn_editor_plugin_default_init (NMVpnEditorPluginInterface *iface);
+
+G_DEFINE_INTERFACE (NMVpnEditorPlugin, nm_vpn_editor_plugin, G_TYPE_OBJECT)
+
+static void
+nm_vpn_editor_plugin_default_init (NMVpnEditorPluginInterface *iface)
+{
+ /* Properties */
+
+ /**
+ * NMVpnEditorPlugin:name:
+ *
+ * Short display name of the VPN plugin.
+ */
+ g_object_interface_install_property (iface,
+ g_param_spec_string (NM_VPN_EDITOR_PLUGIN_NAME, "", "",
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * NMVpnEditorPlugin:description:
+ *
+ * Longer description of the VPN plugin.
+ */
+ g_object_interface_install_property (iface,
+ g_param_spec_string (NM_VPN_EDITOR_PLUGIN_DESCRIPTION, "", "",
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * NMVpnEditorPlugin:service:
+ *
+ * D-Bus service name of the plugin's VPN service.
+ */
+ g_object_interface_install_property (iface,
+ g_param_spec_string (NM_VPN_EDITOR_PLUGIN_SERVICE, "", "",
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+}
+
+/**
+ * nm_vpn_editor_plugin_get_editor:
+ *
+ * Returns: (transfer full):
+ */
+NMVpnEditor *
+nm_vpn_editor_plugin_get_editor (NMVpnEditorPlugin *plugin,
+ NMConnection *connection,
+ GError **error)
+{
+ g_return_val_if_fail (NM_IS_VPN_EDITOR_PLUGIN (plugin), NULL);
+
+ return NM_VPN_EDITOR_PLUGIN_GET_INTERFACE (plugin)->get_editor (plugin, connection, error);
+}
+
+NMVpnEditorPluginCapability
+nm_vpn_editor_plugin_get_capabilities (NMVpnEditorPlugin *plugin)
+{
+ g_return_val_if_fail (NM_IS_VPN_EDITOR_PLUGIN (plugin), 0);
+
+ return NM_VPN_EDITOR_PLUGIN_GET_INTERFACE (plugin)->get_capabilities (plugin);
+}
+
+/**
+ * nm_vpn_editor_plugin_import:
+ *
+ * Returns: (transfer full):
+ */
+NMConnection *
+nm_vpn_editor_plugin_import (NMVpnEditorPlugin *plugin,
+ const char *path,
+ GError **error)
+{
+ g_return_val_if_fail (NM_IS_VPN_EDITOR_PLUGIN (plugin), NULL);
+
+ if (nm_vpn_editor_plugin_get_capabilities (plugin) & NM_VPN_EDITOR_PLUGIN_CAPABILITY_IMPORT) {
+ g_return_val_if_fail (NM_VPN_EDITOR_PLUGIN_GET_INTERFACE (plugin)->import_from_file != NULL, NULL);
+ return NM_VPN_EDITOR_PLUGIN_GET_INTERFACE (plugin)->import_from_file (plugin, path, error);
+ }
+ return NULL;
+}
+
+gboolean
+nm_vpn_editor_plugin_export (NMVpnEditorPlugin *plugin,
+ const char *path,
+ NMConnection *connection,
+ GError **error)
+{
+ g_return_val_if_fail (NM_IS_VPN_EDITOR_PLUGIN (plugin), FALSE);
+
+ if (nm_vpn_editor_plugin_get_capabilities (plugin) & NM_VPN_EDITOR_PLUGIN_CAPABILITY_EXPORT) {
+ g_return_val_if_fail (NM_VPN_EDITOR_PLUGIN_GET_INTERFACE (plugin)->export_to_file != NULL, FALSE);
+ return NM_VPN_EDITOR_PLUGIN_GET_INTERFACE (plugin)->export_to_file (plugin, path, connection, error);
+ }
+ return FALSE;
+}
+
+char *
+nm_vpn_editor_plugin_get_suggested_filename (NMVpnEditorPlugin *plugin,
+ NMConnection *connection)
+{
+ g_return_val_if_fail (NM_IS_VPN_EDITOR_PLUGIN (plugin), NULL);
+
+ if (NM_VPN_EDITOR_PLUGIN_GET_INTERFACE (plugin)->get_suggested_filename)
+ return NM_VPN_EDITOR_PLUGIN_GET_INTERFACE (plugin)->get_suggested_filename (plugin, connection);
+ return NULL;
+}
+
+
+static void nm_vpn_editor_default_init (NMVpnEditorInterface *iface);
+
+G_DEFINE_INTERFACE (NMVpnEditor, nm_vpn_editor, G_TYPE_OBJECT)
+
+static void
+nm_vpn_editor_default_init (NMVpnEditorInterface *iface)
+{
+ GType iface_type = G_TYPE_FROM_INTERFACE (iface);
+
+ /* Signals */
+ g_signal_new ("changed",
+ iface_type,
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (NMVpnEditorInterface, changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+}
+
+/**
+ * nm_vpn_editor_get_widget:
+ *
+ * Returns: (transfer none):
+ */
+GObject *
+nm_vpn_editor_get_widget (NMVpnEditor *editor)
+{
+ g_return_val_if_fail (NM_IS_VPN_EDITOR (editor), NULL);
+
+ return NM_VPN_EDITOR_GET_INTERFACE (editor)->get_widget (editor);
+}
+
+gboolean
+nm_vpn_editor_update_connection (NMVpnEditor *editor,
+ NMConnection *connection,
+ GError **error)
+{
+ g_return_val_if_fail (NM_IS_VPN_EDITOR (editor), FALSE);
+
+ if (error)
+ g_return_val_if_fail (*error == NULL, FALSE);
+
+ return NM_VPN_EDITOR_GET_INTERFACE (editor)->update_connection (editor, connection, error);
+}
diff --git a/libnm/nm-vpn-editor-plugin.h b/libnm/nm-vpn-editor-plugin.h
new file mode 100644
index 0000000000..5910aa3653
--- /dev/null
+++ b/libnm/nm-vpn-editor-plugin.h
@@ -0,0 +1,189 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2008 - 2014 Red Hat, Inc.
+ * Copyright 2008 Novell, Inc.
+ */
+
+#ifndef __NM_VPN_EDITOR_PLUGIN_H__
+#define __NM_VPN_EDITOR_PLUGIN_H__
+
+#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION)
+#error "Only <NetworkManager.h> can be included directly."
+#endif
+
+#include <glib.h>
+#include <glib-object.h>
+#include <nm-types.h>
+
+G_BEGIN_DECLS
+
+typedef struct _NMVpnEditorPlugin NMVpnEditorPlugin;
+typedef struct _NMVpnEditor NMVpnEditor;
+
+/* Plugin's factory function that returns a GObject that implements
+ * NMVpnEditorPlugin.
+ */
+#ifndef __GI_SCANNER__
+typedef NMVpnEditorPlugin * (*NMVpnEditorPluginFactory) (GError **error);
+NMVpnEditorPlugin *nm_vpn_editor_plugin_factory (GError **error);
+#endif
+
+
+/**************************************************/
+/* Editor plugin interface */
+/**************************************************/
+
+#define NM_TYPE_VPN_EDITOR_PLUGIN (nm_vpn_editor_plugin_get_type ())
+#define NM_VPN_EDITOR_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VPN_EDITOR_PLUGIN, NMVpnEditorPlugin))
+#define NM_IS_VPN_EDITOR_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_VPN_EDITOR_PLUGIN))
+#define NM_VPN_EDITOR_PLUGIN_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), NM_TYPE_VPN_EDITOR_PLUGIN, NMVpnEditorPluginInterface))
+
+/**
+ * NMVpnEditorPluginCapability:
+ * @NM_VPN_EDITOR_PLUGIN_CAPABILITY_NONE: unknown or no capability
+ * @NM_VPN_EDITOR_PLUGIN_CAPABILITY_IMPORT: the plugin can import new connections
+ * @NM_VPN_EDITOR_PLUGIN_CAPABILITY_EXPORT: the plugin can export connections
+ * @NM_VPN_EDITOR_PLUGIN_CAPABILITY_IPV6: the plugin supports IPv6 addressing
+ *
+ * Flags that indicate certain capabilities of the plugin to editor programs.
+ **/
+typedef enum /*< flags >*/ {
+ NM_VPN_EDITOR_PLUGIN_CAPABILITY_NONE = 0x00,
+ NM_VPN_EDITOR_PLUGIN_CAPABILITY_IMPORT = 0x01,
+ NM_VPN_EDITOR_PLUGIN_CAPABILITY_EXPORT = 0x02,
+ NM_VPN_EDITOR_PLUGIN_CAPABILITY_IPV6 = 0x04
+} NMVpnEditorPluginCapability;
+
+/* Short display name of the VPN plugin */
+#define NM_VPN_EDITOR_PLUGIN_NAME "name"
+
+/* Longer description of the VPN plugin */
+#define NM_VPN_EDITOR_PLUGIN_DESCRIPTION "description"
+
+/* D-Bus service name of the plugin's VPN service */
+#define NM_VPN_EDITOR_PLUGIN_SERVICE "service"
+
+/**
+ * NMVpnEditorPluginInterface:
+ * @g_iface: the parent interface
+ * @get_editor: returns an #NMVpnEditor, pre-filled with values from @connection
+ * if non-%NULL.
+ * @get_capabilities: returns a bitmask of capabilities.
+ * @import_from_file: Try to import a connection from the specified path. On
+ * success, return a partial #NMConnection object. On error, return %NULL and
+ * set @error with additional information. Note that @error can be %NULL, in
+ * which case no additional error information should be provided.
+ * @export_to_file: Export the given connection to the specified path. Return
+ * %TRUE on success. On error, return %FALSE and set @error with additional
+ * error information. Note that @error can be %NULL, in which case no
+ * additional error information should be provided.
+ * @get_suggested_filename: For a given connection, return a suggested file
+ * name. Returned value will be %NULL or a suggested file name to be freed by
+ * the caller.
+ *
+ * Interface for VPN editor plugins.
+ */
+typedef struct {
+ GTypeInterface g_iface;
+
+ NMVpnEditor * (*get_editor) (NMVpnEditorPlugin *plugin,
+ NMConnection *connection,
+ GError **error);
+
+ NMVpnEditorPluginCapability (*get_capabilities) (NMVpnEditorPlugin *plugin);
+
+ NMConnection * (*import_from_file) (NMVpnEditorPlugin *plugin,
+ const char *path,
+ GError **error);
+
+ gboolean (*export_to_file) (NMVpnEditorPlugin *plugin,
+ const char *path,
+ NMConnection *connection,
+ GError **error);
+
+ char * (*get_suggested_filename) (NMVpnEditorPlugin *plugin, NMConnection *connection);
+} NMVpnEditorPluginInterface;
+
+GType nm_vpn_editor_plugin_get_type (void);
+
+NMVpnEditor *nm_vpn_editor_plugin_get_editor (NMVpnEditorPlugin *plugin,
+ NMConnection *connection,
+ GError **error);
+
+NMVpnEditorPluginCapability nm_vpn_editor_plugin_get_capabilities (NMVpnEditorPlugin *plugin);
+
+NMConnection *nm_vpn_editor_plugin_import (NMVpnEditorPlugin *plugin,
+ const char *path,
+ GError **error);
+gboolean nm_vpn_editor_plugin_export (NMVpnEditorPlugin *plugin,
+ const char *path,
+ NMConnection *connection,
+ GError **error);
+char *nm_vpn_editor_plugin_get_suggested_filename (NMVpnEditorPlugin *plugin,
+ NMConnection *connection);
+
+/**************************************************/
+/* Editor interface */
+/**************************************************/
+
+#define NM_TYPE_VPN_EDITOR (nm_vpn_editor_get_type ())
+#define NM_VPN_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VPN_EDITOR, NMVpnEditor))
+#define NM_IS_VPN_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_VPN_EDITOR))
+#define NM_VPN_EDITOR_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), NM_TYPE_VPN_EDITOR, NMVpnEditorInterface))
+
+/**
+ * NMVpnEditorInterface:
+ * @g_iface: the parent interface
+ * @get_widget: return the #GtkWidget for the VPN editor's UI
+ * @placeholder: not currently used
+ * @update_connection: called to save the user-entered options to the connection
+ * object. Should return %FALSE and set @error if the current options are
+ * invalid. @error should contain enough information for the plugin to
+ * determine which UI widget is invalid at a later point in time. For
+ * example, creating unique error codes for what error occurred and populating
+ * the message field of @error with the name of the invalid property.
+ * @changed: emitted when the value of a UI widget changes. May trigger a
+ * validity check via @update_connection to write values to the connection.
+ *
+ * Interface for editing a specific #NMConnection
+ */
+typedef struct {
+ GTypeInterface g_iface;
+
+ GObject * (*get_widget) (NMVpnEditor *editor);
+
+ void (*placeholder) (void);
+
+ gboolean (*update_connection) (NMVpnEditor *editor,
+ NMConnection *connection,
+ GError **error);
+
+ void (*changed) (NMVpnEditor *editor);
+} NMVpnEditorInterface;
+
+GType nm_vpn_editor_get_type (void);
+
+GObject * nm_vpn_editor_get_widget (NMVpnEditor *editor);
+
+gboolean nm_vpn_editor_update_connection (NMVpnEditor *editor,
+ NMConnection *connection,
+ GError **error);
+
+G_END_DECLS
+
+#endif /* NM_VPN_EDITOR_PLUGIN_H */
diff --git a/libnm/nm-vpn-plugin-ui-interface.c b/libnm/nm-vpn-plugin-ui-interface.c
deleted file mode 100644
index af00cfd1da..0000000000
--- a/libnm/nm-vpn-plugin-ui-interface.c
+++ /dev/null
@@ -1,244 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
-/*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA.
- *
- * Copyright 2008 - 2010 Red Hat, Inc.
- * Copyright 2008 Novell, Inc.
- */
-
-#include "nm-vpn-plugin-ui-interface.h"
-
-static void
-interface_init (gpointer g_iface)
-{
- static gboolean initialized = FALSE;
-
- if (initialized)
- return;
-
- /* Properties */
-
- /**
- * NMVpnPluginUiInterface:name:
- *
- * Short display name of the VPN plugin.
- */
- g_object_interface_install_property (g_iface,
- g_param_spec_string (NM_VPN_PLUGIN_UI_INTERFACE_NAME, "", "",
- NULL,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMVpnPluginUiInterface:desc:
- *
- * Longer description of the VPN plugin.
- */
- g_object_interface_install_property (g_iface,
- g_param_spec_string (NM_VPN_PLUGIN_UI_INTERFACE_DESC, "", "",
- NULL,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-
- /**
- * NMVpnPluginUiInterface:service:
- *
- * D-Bus service name of the plugin's VPN service.
- */
- g_object_interface_install_property (g_iface,
- g_param_spec_string (NM_VPN_PLUGIN_UI_INTERFACE_SERVICE, "", "",
- NULL,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-
- initialized = TRUE;
-}
-
-
-GType
-nm_vpn_plugin_ui_interface_get_type (void)
-{
- static GType vpn_plugin_ui_interface_type = 0;
-
- if (!vpn_plugin_ui_interface_type) {
- const GTypeInfo vpn_plugin_ui_interface_info = {
- sizeof (NMVpnPluginUiInterface), /* class_size */
- interface_init, /* base_init */
- NULL, /* base_finalize */
- NULL,
- NULL, /* class_finalize */
- NULL, /* class_data */
- 0,
- 0, /* n_preallocs */
- NULL
- };
-
- vpn_plugin_ui_interface_type = g_type_register_static (G_TYPE_INTERFACE,
- "NMVpnPluginUiInterface",
- &vpn_plugin_ui_interface_info,
- 0);
-
- g_type_interface_add_prerequisite (vpn_plugin_ui_interface_type, G_TYPE_OBJECT);
- }
-
- return vpn_plugin_ui_interface_type;
-}
-
-
-/**
- * nm_vpn_plugin_ui_interface_ui_factory:
- *
- * Returns: (transfer full):
- */
-NMVpnPluginUiWidgetInterface *
-nm_vpn_plugin_ui_interface_ui_factory (NMVpnPluginUiInterface *iface,
- NMConnection *connection,
- GError **error)
-{
- g_return_val_if_fail (NM_IS_VPN_PLUGIN_UI_INTERFACE (iface), NULL);
-
- return NM_VPN_PLUGIN_UI_INTERFACE_GET_INTERFACE (iface)->ui_factory (iface, connection, error);
-}
-
-guint32
-nm_vpn_plugin_ui_interface_get_capabilities (NMVpnPluginUiInterface *iface)
-{
- g_return_val_if_fail (NM_IS_VPN_PLUGIN_UI_INTERFACE (iface), 0);
-
- return NM_VPN_PLUGIN_UI_INTERFACE_GET_INTERFACE (iface)->get_capabilities (iface);
-}
-
-/**
- * nm_vpn_plugin_ui_interface_import:
- *
- * Returns: (transfer full):
- */
-NMConnection *
-nm_vpn_plugin_ui_interface_import (NMVpnPluginUiInterface *iface,
- const char *path,
- GError **error)
-{
- g_return_val_if_fail (NM_IS_VPN_PLUGIN_UI_INTERFACE (iface), NULL);
-
- if (nm_vpn_plugin_ui_interface_get_capabilities (iface) & NM_VPN_PLUGIN_UI_CAPABILITY_IMPORT) {
- g_return_val_if_fail (NM_VPN_PLUGIN_UI_INTERFACE_GET_INTERFACE (iface)->import_from_file != NULL, NULL);
- return NM_VPN_PLUGIN_UI_INTERFACE_GET_INTERFACE (iface)->import_from_file (iface, path, error);
- }
- return NULL;
-}
-
-gboolean
-nm_vpn_plugin_ui_interface_export (NMVpnPluginUiInterface *iface,
- const char *path,
- NMConnection *connection,
- GError **error)
-{
- g_return_val_if_fail (NM_IS_VPN_PLUGIN_UI_INTERFACE (iface), FALSE);
-
- if (nm_vpn_plugin_ui_interface_get_capabilities (iface) & NM_VPN_PLUGIN_UI_CAPABILITY_EXPORT) {
- g_return_val_if_fail (NM_VPN_PLUGIN_UI_INTERFACE_GET_INTERFACE (iface)->export_to_file != NULL, FALSE);
- return NM_VPN_PLUGIN_UI_INTERFACE_GET_INTERFACE (iface)->export_to_file (iface, path, connection, error);
- }
- return FALSE;
-}
-
-char *
-nm_vpn_plugin_ui_interface_get_suggested_name (NMVpnPluginUiInterface *iface,
- NMConnection *connection)
-{
- g_return_val_if_fail (NM_IS_VPN_PLUGIN_UI_INTERFACE (iface), NULL);
-
- if (NM_VPN_PLUGIN_UI_INTERFACE_GET_INTERFACE (iface)->get_suggested_name)
- return NM_VPN_PLUGIN_UI_INTERFACE_GET_INTERFACE (iface)->get_suggested_name (iface, connection);
- return NULL;
-}
-
-
-static void
-widget_interface_init (gpointer g_iface)
-{
- GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
- static gboolean initialized = FALSE;
-
- if (initialized)
- return;
-
- /* Signals */
- g_signal_new ("changed",
- iface_type,
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (NMVpnPluginUiWidgetInterface, changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- initialized = TRUE;
-}
-
-GType
-nm_vpn_plugin_ui_widget_interface_get_type (void)
-{
- static GType vpn_plugin_ui_widget_interface_type = 0;
-
- if (!vpn_plugin_ui_widget_interface_type) {
- const GTypeInfo vpn_plugin_ui_widget_interface_info = {
- sizeof (NMVpnPluginUiWidgetInterface), /* class_size */
- widget_interface_init, /* base_init */
- NULL, /* base_finalize */
- NULL,
- NULL, /* class_finalize */
- NULL, /* class_data */
- 0,
- 0, /* n_preallocs */
- NULL
- };
-
- vpn_plugin_ui_widget_interface_type = g_type_register_static (G_TYPE_INTERFACE,
- "NMVpnPluginUiWidgetInterface",
- &vpn_plugin_ui_widget_interface_info,
- 0);
-
- g_type_interface_add_prerequisite (vpn_plugin_ui_widget_interface_type, G_TYPE_OBJECT);
- }
-
- return vpn_plugin_ui_widget_interface_type;
-}
-
-/**
- * nm_vpn_plugin_ui_widget_interface_get_widget:
- *
- * Returns: (transfer none):
- */
-GObject *
-nm_vpn_plugin_ui_widget_interface_get_widget (NMVpnPluginUiWidgetInterface *iface)
-{
- g_return_val_if_fail (NM_IS_VPN_PLUGIN_UI_WIDGET_INTERFACE (iface), NULL);
-
- return NM_VPN_PLUGIN_UI_WIDGET_INTERFACE_GET_INTERFACE (iface)->get_widget (iface);
-}
-
-gboolean
-nm_vpn_plugin_ui_widget_interface_update_connection (NMVpnPluginUiWidgetInterface *iface,
- NMConnection *connection,
- GError **error)
-{
- g_return_val_if_fail (NM_IS_VPN_PLUGIN_UI_WIDGET_INTERFACE (iface), FALSE);
-
- if (error)
- g_return_val_if_fail (*error == NULL, FALSE);
-
- return NM_VPN_PLUGIN_UI_WIDGET_INTERFACE_GET_INTERFACE (iface)->update_connection (iface, connection, error);
-}
diff --git a/libnm/nm-vpn-plugin-ui-interface.h b/libnm/nm-vpn-plugin-ui-interface.h
deleted file mode 100644
index 4aab74482e..0000000000
--- a/libnm/nm-vpn-plugin-ui-interface.h
+++ /dev/null
@@ -1,206 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
-/*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA.
- *
- * Copyright 2008 - 2010 Red Hat, Inc.
- * Copyright 2008 Novell, Inc.
- */
-
-#ifndef __NM_VPN_PLUGIN_UI_INTERFACE_H__
-#define __NM_VPN_PLUGIN_UI_INTERFACE_H__
-
-#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION)
-#error "Only <NetworkManager.h> can be included directly."
-#endif
-
-#include <glib.h>
-#include <glib-object.h>
-#include <nm-connection.h>
-
-G_BEGIN_DECLS
-
-typedef struct _NMVpnPluginUiInterface NMVpnPluginUiInterface;
-typedef struct _NMVpnPluginUiWidgetInterface NMVpnPluginUiWidgetInterface;
-
-/* Plugin's factory function that returns a GObject that implements
- * NMVpnPluginUiInterface.
- */
-#ifndef __GI_SCANNER__
-typedef NMVpnPluginUiInterface * (*NMVpnPluginUiFactory) (GError **error);
-NMVpnPluginUiInterface *nm_vpn_plugin_ui_factory (GError **error);
-#endif
-
-
-/**************************************************/
-/* Plugin interface */
-/**************************************************/
-
-#define NM_TYPE_VPN_PLUGIN_UI_INTERFACE (nm_vpn_plugin_ui_interface_get_type ())
-#define NM_VPN_PLUGIN_UI_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VPN_PLUGIN_UI_INTERFACE, NMVpnPluginUiInterface))
-#define NM_IS_VPN_PLUGIN_UI_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_VPN_PLUGIN_UI_INTERFACE))
-#define NM_VPN_PLUGIN_UI_INTERFACE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), NM_TYPE_VPN_PLUGIN_UI_INTERFACE, NMVpnPluginUiInterface))
-
-/**
- * NMVpnPluginUiCapability:
- * @NM_VPN_PLUGIN_UI_CAPABILITY_NONE: unknown or no capability
- * @NM_VPN_PLUGIN_UI_CAPABILITY_IMPORT: the plugin can import new connections
- * @NM_VPN_PLUGIN_UI_CAPABILITY_EXPORT: the plugin can export connections
- * @NM_VPN_PLUGIN_UI_CAPABILITY_IPV6: the plugin supports IPv6 addressing
- *
- * Flags that indicate to UI programs certain capabilities of the plugin.
- **/
-typedef enum /*< flags >*/ {
- NM_VPN_PLUGIN_UI_CAPABILITY_NONE = 0x00,
- NM_VPN_PLUGIN_UI_CAPABILITY_IMPORT = 0x01,
- NM_VPN_PLUGIN_UI_CAPABILITY_EXPORT = 0x02,
- NM_VPN_PLUGIN_UI_CAPABILITY_IPV6 = 0x04
-} NMVpnPluginUiCapability;
-
-/* Short display name of the VPN plugin */
-#define NM_VPN_PLUGIN_UI_INTERFACE_NAME "name"
-
-/* Longer description of the VPN plugin */
-#define NM_VPN_PLUGIN_UI_INTERFACE_DESC "desc"
-
-/* D-Bus service name of the plugin's VPN service */
-#define NM_VPN_PLUGIN_UI_INTERFACE_SERVICE "service"
-
-/**
- * NMVpnPluginUiInterfaceProp:
- * @NM_VPN_PLUGIN_UI_INTERFACE_PROP_NAME: the VPN plugin's name
- * @NM_VPN_PLUGIN_UI_INTERFACE_PROP_DESC: description of the VPN plugin and what
- * VPN services it supports
- * @NM_VPN_PLUGIN_UI_INTERFACE_PROP_SERVICE: the D-Bus service name used by the
- * plugin's VPN service daemon
- *
- * #GObject property numbers that plugins should override to provide certain
- * information to UI programs.
- **/
-typedef enum {
- /* private */
- NM_VPN_PLUGIN_UI_INTERFACE_PROP_FIRST = 0x1000,
-
- /* public */
- NM_VPN_PLUGIN_UI_INTERFACE_PROP_NAME = NM_VPN_PLUGIN_UI_INTERFACE_PROP_FIRST,
- NM_VPN_PLUGIN_UI_INTERFACE_PROP_DESC,
- NM_VPN_PLUGIN_UI_INTERFACE_PROP_SERVICE
-} NMVpnPluginUiInterfaceProp;
-
-
-struct _NMVpnPluginUiInterface {
- GTypeInterface g_iface;
-
- /* Plugin's factory function that returns a GObject that implements
- * NMVpnPluginUiWidgetInterface, pre-filled with values from 'connection'
- * if non-NULL.
- */
- NMVpnPluginUiWidgetInterface * (*ui_factory) (NMVpnPluginUiInterface *iface,
- NMConnection *connection,
- GError **error);
-
- /* Plugin's capabiltity function that returns a bitmask of capabilities
- * described by NM_VPN_PLUGIN_UI_CAPABILITY_* defines.
- */
- guint32 (*get_capabilities) (NMVpnPluginUiInterface *iface);
-
- /* Try to import a connection from the specified path. On success, return a
- * partial NMConnection object. On error, return NULL and set 'error' with
- * additional information. Note that 'error' can be NULL, in which case no
- * additional error information should be provided.
- */
- NMConnection * (*import_from_file) (NMVpnPluginUiInterface *iface,
- const char *path,
- GError **error);
-
- /* Export the given connection to the specified path. Return TRUE on success.
- * On error, return FALSE and set 'error' with additional error information.
- * Note that 'error' can be NULL, in which case no additional error information
- * should be provided.
- */
- gboolean (*export_to_file) (NMVpnPluginUiInterface *iface,
- const char *path,
- NMConnection *connection,
- GError **error);
-
- /* For a given connection, return a suggested file name. Returned value should
- * be NULL or a suggested file name allocated via g_malloc/g_new/etc to be freed
- * by the caller.
- */
- char * (*get_suggested_name) (NMVpnPluginUiInterface *iface, NMConnection *connection);
-};
-
-GType nm_vpn_plugin_ui_interface_get_type (void);
-
-NMVpnPluginUiWidgetInterface *nm_vpn_plugin_ui_interface_ui_factory (NMVpnPluginUiInterface *iface,
- NMConnection *connection,
- GError **error);
-
-guint32 nm_vpn_plugin_ui_interface_get_capabilities (NMVpnPluginUiInterface *iface);
-
-NMConnection *nm_vpn_plugin_ui_interface_import (NMVpnPluginUiInterface *iface,
- const char *path,
- GError **error);
-
-gboolean nm_vpn_plugin_ui_interface_export (NMVpnPluginUiInterface *iface,
- const char *path,
- NMConnection *connection,
- GError **error);
-
-char *nm_vpn_plugin_ui_interface_get_suggested_name (NMVpnPluginUiInterface *iface,
- NMConnection *connection);
-
-/**************************************************/
-/* UI widget interface */
-/**************************************************/
-
-#define NM_TYPE_VPN_PLUGIN_UI_WIDGET_INTERFACE (nm_vpn_plugin_ui_widget_interface_get_type ())
-#define NM_VPN_PLUGIN_UI_WIDGET_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VPN_PLUGIN_UI_WIDGET_INTERFACE, NMVpnPluginUiWidgetInterface))
-#define NM_IS_VPN_PLUGIN_UI_WIDGET_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_VPN_PLUGIN_UI_WIDGET_INTERFACE))
-#define NM_VPN_PLUGIN_UI_WIDGET_INTERFACE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), NM_TYPE_VPN_PLUGIN_UI_WIDGET_INTERFACE, NMVpnPluginUiWidgetInterface))
-
-struct _NMVpnPluginUiWidgetInterface {
- GTypeInterface g_iface;
-
- /* Return the GtkWidget for the VPN's UI */
- GObject * (*get_widget) (NMVpnPluginUiWidgetInterface *iface);
-
- /* Called to save the user-entered options to the connection object. Should
- * return FALSE and set 'error' if the current options are invalid. 'error'
- * should contain enough information for the plugin to determine which UI
- * widget is invalid at a later point in time. For example, creating unique
- * error codes for what error occurred and populating the message field
- * of 'error' with the name of the invalid property.
- */
- gboolean (*update_connection) (NMVpnPluginUiWidgetInterface *iface,
- NMConnection *connection,
- GError **error);
-
- /* Emitted when the value of a UI widget changes. May trigger a validity
- * check via update_connection() to write values to the connection */
- void (*changed) (NMVpnPluginUiWidgetInterface *iface);
-};
-
-GType nm_vpn_plugin_ui_widget_interface_get_type (void);
-
-GObject * nm_vpn_plugin_ui_widget_interface_get_widget (NMVpnPluginUiWidgetInterface *iface);
-
-gboolean nm_vpn_plugin_ui_widget_interface_update_connection (NMVpnPluginUiWidgetInterface *iface,
- NMConnection *connection,
- GError **error);
-
-G_END_DECLS
-
-#endif /* NM_VPN_PLUGIN_UI_INTERFACE_H */
diff --git a/libnm/nm-wimax-nsp.h b/libnm/nm-wimax-nsp.h
index a8f9105268..cdc7b23665 100644
--- a/libnm/nm-wimax-nsp.h
+++ b/libnm/nm-wimax-nsp.h
@@ -41,6 +41,15 @@ G_BEGIN_DECLS
#define NM_WIMAX_NSP_SIGNAL_QUALITY "signal-quality"
#define NM_WIMAX_NSP_NETWORK_TYPE "network-type"
+/**
+ * NMWimaxNspNetworkType:
+ * @NM_WIMAX_NSP_NETWORK_TYPE_UNKNOWN: unknown network type
+ * @NM_WIMAX_NSP_NETWORK_TYPE_HOME: home network
+ * @NM_WIMAX_NSP_NETWORK_TYPE_PARTNER: partner network
+ * @NM_WIMAX_NSP_NETWORK_TYPE_ROAMING_PARTNER: roaming partner network
+ *
+ * WiMAX network type.
+ */
typedef enum {
NM_WIMAX_NSP_NETWORK_TYPE_UNKNOWN = 0,
NM_WIMAX_NSP_NETWORK_TYPE_HOME = 1,
diff --git a/libnm/tests/test-nm-client.c b/libnm/tests/test-nm-client.c
index 867a27933b..35836e6bd3 100644
--- a/libnm/tests/test-nm-client.c
+++ b/libnm/tests/test-nm-client.c
@@ -192,8 +192,8 @@ test_device_added_signal_after_init (void)
g_signal_handlers_disconnect_by_func (client, device_sai_added_cb, &result);
g_signal_handlers_disconnect_by_func (client, devices_sai_notify_cb, &result);
- g_assert ((result & NOTIFY_MASK) == NOTIFY_FIRST);
- g_assert ((result & SIGNAL_MASK) == SIGNAL_SECOND);
+ g_assert ((result & SIGNAL_MASK) == SIGNAL_FIRST);
+ g_assert ((result & NOTIFY_MASK) == NOTIFY_SECOND);
devices = nm_client_get_devices (client);
g_assert (devices);
@@ -1007,7 +1007,7 @@ client_devices_changed_cb (GObject *client,
info->remaining--;
else {
g_signal_connect (device, "notify::" NM_DEVICE_ACTIVE_CONNECTION,
- G_CALLBACK (device_ac_changed_cb), &info);
+ G_CALLBACK (device_ac_changed_cb), info);
}
info->remaining--;
diff --git a/m4/compiler_warnings.m4 b/m4/compiler_warnings.m4
index 3fde795504..c05a26d098 100644
--- a/m4/compiler_warnings.m4
+++ b/m4/compiler_warnings.m4
@@ -29,7 +29,7 @@ if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then
-fno-strict-aliasing -Wno-unused-but-set-variable \
-Wundef -Wimplicit-function-declaration \
-Wpointer-arith -Winit-self \
- -Wmissing-include-dirs -Waggregate-return; do
+ -Wmissing-include-dirs; do
CFLAGS="$CFLAGS_MORE_WARNINGS $CFLAGS_EXTRA $option $CFLAGS_SAVED"
AC_MSG_CHECKING([whether gcc understands $option])
AC_TRY_COMPILE([], [],
diff --git a/man/Makefile.am b/man/Makefile.am
index 376a8b42ac..5d0386ff38 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -52,6 +52,7 @@ endif
configure_generated_man_pages = \
nmcli.1 \
+ nmtui.1 \
nm-online.1 \
nm-system-settings.conf.5
@@ -82,6 +83,18 @@ DISTCLEANFILES = \
man_MANS += $(configure_generated_man_pages)
+links = nmtui-edit nmtui-connect nmtui-hostname
+
+install-data-hook:
+ for link in $(links); do \
+ ln -f $(DESTDIR)$(mandir)/man1/nmtui.1 $(DESTDIR)$(mandir)/man1/$$link.1; \
+ done
+
+uninstall-hook:
+ for link in $(links); do \
+ rm -f $(DESTDIR)$(mandir)/man1/$$link.1; \
+ done
+
if ENABLE_GTK_DOC
man_MANS += $(docbook_generated_man_pages)
CLEANFILES += $(docbook_generated_man_pages)
diff --git a/man/NetworkManager.conf.xml.in b/man/NetworkManager.conf.xml.in
index 67919cfb4f..4fb8f502c0 100644
--- a/man/NetworkManager.conf.xml.in
+++ b/man/NetworkManager.conf.xml.in
@@ -3,7 +3,7 @@
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
<!--
-Copyright (C) 2010 - 2013 Red Hat, Inc.
+Copyright 2010 - 2014 Red Hat, Inc.
-->
<refentry id="NetworkManager.conf">
@@ -200,6 +200,28 @@ Copyright (C) 2010 - 2013 Red Hat, Inc.
</varlistentry>
<varlistentry>
+ <term><varname>configure-and-quit</varname></term>
+ <listitem>
+ <para>
+ When set to <literal>true</literal>, NetworkManager quits after
+ performing initial network configuration but spawns small helpers
+ to preserve DHCP leases and IPv6 addresses. This is useful in
+ environments where network setup is more or less static or it is
+ desirable to save process time but still handle some dynamic
+ configurations. When this option is <literal>true</literal>,
+ network configuration for WiFi, WWAN, Bluetooth, ADSL, and PPPoE
+ interfaces cannot be preserved due to their use of external
+ services, and these devices will be deconfigured when NetworkManager
+ quits even though other interface's configuration may be preserved.
+ The default value is <literal>false</literal>, meaning that
+ NetworkManager will continue running after initial network
+ configuration and continue responding to system and hardware events,
+ D-Bus requests, and user commands.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><varname>dns</varname></term>
<listitem><para>Set the DNS (<filename>resolv.conf</filename>) processing mode.</para>
<para><literal>default</literal>: The default if the key is
diff --git a/man/nmcli.1.in b/man/nmcli.1.in
index 109317f768..66e1567d45 100644
--- a/man/nmcli.1.in
+++ b/man/nmcli.1.in
@@ -21,7 +21,7 @@
.\"
.\" Copyright 2010 - 2014 Red Hat, Inc.
.\"
-.TH NMCLI "1" "11 September 2014"
+.TH NMCLI "1" "4 November 2014"
.SH NAME
nmcli \- command\(hyline tool for controlling NetworkManager
@@ -33,7 +33,7 @@ nmcli \- command\(hyline tool for controlling NetworkManager
.sp
.IR OBJECT " := { "
-.BR general " | " networking " | " radio " | " connection " | " device
+.BR general " | " networking " | " radio " | " connection " | " device " | " agent
.RI " }"
.sp
@@ -131,6 +131,8 @@ incompatible versions may produce incorrect results.
.B \-a, \-\-ask
When using this option \fInmcli\fP will stop and ask for any missing required
arguments, so do not use this option for non-interactive purposes like scripts.
+This option controls, for example, whether you will be prompted for a password
+if it is required for connecting to a network.
.TP
.B \-w, \-\-wait <seconds>
This option sets a timeout period for which \fInmcli\fP will wait for \fINetworkManager\fP
@@ -327,10 +329,10 @@ When no command is given to the \fIconnection\fP object, the default action
is 'nmcli connection show'.
.RE
.TP
-.B up [ id | uuid | path ] <ID> [ifname <ifname>] [ap <BSSID>] [nsp <name>]
+.B up [ id | uuid | path ] <ID> [ifname <ifname>] [ap <BSSID>] [nsp <name>] [passwd <file with passwords>]
.RE
.RS
-.B up ifname <ifname> [ap <BSSID>] [nsp <name>]
+.B up ifname <ifname> [ap <BSSID>] [nsp <name>] [passwd <file with passwords>]
.RS
.br
Activate a connection. The connection is identified by its name, UUID or D-Bus
@@ -355,6 +357,26 @@ Available options are:
\(en BSSID of the AP which the command should connect to (for Wi\(hyFi connections)
.IP \fInsp\fP 13
\(en NSP (Network Service Provider) which the command should connect to (for WiMAX connections)
+.IP \fIpasswd-file\fP 13
+\(en some networks may require credentials during activation. You can give these
+credentials using this option.
+Each line of the file should contain one password in the form of
+.br
+\fBsetting_name.property_name:the password\fP
+.br
+For example, for WPA Wi-Fi with PSK, the line would be
+.br
+\fI802-11-wireless-security.psk:secret12345\fP
+.br
+For 802.1X password, the line would be
+.br
+\fI802-1x.password:my 1X password\fP
+.br
+nmcli also accepts "wifi-sec" and "wifi" strings instead of "802-11-wireless-security".
+When NetworkManager requires a password and it is not given, nmcli will ask for it
+when run with --ask. If --ask was not passed, NetworkManager can ask another secret
+agent that may be running (typically a GUI secret agent, such as nm-applet or
+gnome-shell).
.RE
.RE
.TP
@@ -771,6 +793,39 @@ This command does not show the APs, use 'nmcli device wifi list' for that.
List available WiMAX NSP. The \fIifname\fP and \fInsp\fP options
can be used to list networks for a particular interface or with a specific
NSP, respectively.
+.RE
+
+.TP
+.B agent \- run nmcli as a NetworkManager secret agent, or polkit agent
+.br
+.TP
+.SS \fICOMMAND\fP := { secret | polkit | all }
+.sp
+.RS
+.TP
+.B secret
+.br
+Register nmcli as a NetworkManager secret agent and listen for secret requests.
+You do usually not need this command, because nmcli can handle secrets when
+connecting to networks. However, you may find the command useful when you use
+another tool for activating connections and you do not have a secret agent
+available (like nm-applet).
+.TP
+.B polkit
+.br
+Register nmcli as a polkit agent for the user session and listen for
+authorization requests. You do not usually need this command, because nmcli can
+handle polkit actions related to NetworkManager operations (when run with
+--ask). However, you may find the command useful when you want to run a simple
+text based polkit agent and you do not have an agent of a desktop environment.
+Note that running this command makes nmcli handle all polkit requests, not only
+NetworkManager related ones, because only one polkit agent can run for the
+session.
+.TP
+.B all
+.br
+Runs nmcli as both NetworkManager secret and a polkit agent.
+.RE
.SH ENVIRONMENT VARIABLES
\fInmcli\fP's behavior is affected by the following environment variables.
diff --git a/man/nmtui.1.in b/man/nmtui.1.in
new file mode 100644
index 0000000000..2aa99eb96a
--- /dev/null
+++ b/man/nmtui.1.in
@@ -0,0 +1,66 @@
+.\" nmtui (1) manual page
+.\"
+.\" This is free documentation; you can redistribute it and/or
+.\" modify it under the terms of the GNU General Public License as
+.\" published by the Free Software Foundation; either version 2 of
+.\" the License, or (at your option) any later version.
+.\"
+.\" The GNU General Public License's references to "object code"
+.\" and "executables" are to be interpreted as the output of any
+.\" document formatting or typesetting system, including
+.\" intermediate and printed output.
+.\"
+.\" This manual is distributed in the hope that it will be useful,
+.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
+.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+.\" GNU General Public License for more details.
+.\"
+.\" You should have received a copy of the GNU General Public Licence along
+.\" with this manual; if not, write to the Free Software Foundation, Inc.,
+.\" 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+.\"
+.\" Copyright (C) 2014 Red Hat, Inc.
+.\"
+.TH NMTUI "1" "6 November 2014"
+
+.SH NAME
+nmtui \- Text User Interface for controlling NetworkManager
+.SH SYNOPSIS
+.B nmtui
+.RI " [ " edit " | " connect " | " hostname " ] [ ... ] "
+.P
+.B nmtui\-edit
+.RI " [ " connection-id " | " connection-name " ] "
+.P
+.B nmtui\-connect
+.RI " [ " connection-name " | " connection-uuid " | " device-name " | " Wi-Fi-SSID " ] "
+.P
+.B nmtui\-hostname
+
+.SH DESCRIPTION
+.B nmtui
+is a curses\(hybased TUI application for interacting with \fINetworkManager\fP.
+.P
+When starting \fInmtui\fP, the user is prompted to choose the activity to perform
+unless it was specified as first argument.
+.P
+The supported activities are:
+.IP \(em 4
+\fIedit\fP: show a connection editor that supports adding, modifying, viewing and deleting.
+It provides similar functionality as \fInm\-connection\-editor\fP.
+.IP \(em 4
+\fIconnect\fP: show a list of available connections, with the option to activate or deactivate
+them. It provides similar functionality as \fInm\-applet\fP.
+.IP \(em 4
+\fIhostname\fP: set the system hostname.
+
+.P
+Corresponding to above activities, \fInmtui\fP also comes with binaries named
+\fInmtui\-edit\fP, \fInmtui\-connect\fP, and \fInmtui-hostname\fP to skip the selection
+of the actvities.
+
+.SH SEE ALSO
+.BR NetworkManager(8),
+.BR nmcli(1).
+.BR nm\-applet(1).
+.BR nm\-connection\-editor(1).
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 0acabd9173..0571f0e238 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,13 +1,17 @@
[encoding: UTF-8]
# List of source files containing translatable strings.
# Please keep this file sorted alphabetically.
+clients/cli/agent.c
clients/cli/common.c
clients/cli/connections.c
clients/cli/devices.c
clients/cli/general.c
clients/cli/nmcli.c
+clients/cli/polkit-agent.c
clients/cli/settings.c
clients/cli/utils.c
+clients/common/nm-polkit-listener.c
+clients/common/nm-secret-agent-simple.c
clients/nm-online.c
clients/tui/newt/nmt-newt-utils.c
clients/tui/nm-editor-utils.c
@@ -34,7 +38,6 @@ clients/tui/nmt-password-dialog.c
clients/tui/nmt-password-fields.c
clients/tui/nmt-route-editor.c
clients/tui/nmt-route-table.c
-clients/tui/nmt-secret-agent.c
clients/tui/nmt-slave-list.c
clients/tui/nmt-widget-list.c
clients/tui/nmtui-connect.c
@@ -56,6 +59,7 @@ libnm-core/nm-setting-connection.c
libnm-core/nm-setting-dcb.c
libnm-core/nm-setting-gsm.c
libnm-core/nm-setting-infiniband.c
+libnm-core/nm-setting-ip-config.c
libnm-core/nm-setting-ip4-config.c
libnm-core/nm-setting-ip6-config.c
libnm-core/nm-setting-olpc-mesh.c
@@ -122,6 +126,7 @@ libnm/nm-vpn-plugin-old.c
policy/org.freedesktop.NetworkManager.policy.in.in
src/NetworkManagerUtils.c
src/main.c
+src/main-utils.c
src/dhcp-manager/nm-dhcp-dhclient.c
src/dhcp-manager/nm-dhcp-dhclient-utils.c
src/dhcp-manager/nm-dhcp-manager.c
@@ -142,6 +147,7 @@ src/devices/wifi/nm-wifi-ap-utils.c
src/devices/wimax/nm-device-wimax.c
src/devices/wwan/nm-modem-broadband.c
src/nm-config.c
+src/nm-iface-helper.c
src/nm-logging.c
src/nm-manager.c
src/nm-sleep-monitor-systemd.c
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 2a7f3518a1..f611e4ce29 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -5,3 +5,4 @@ policy/org.freedesktop.NetworkManager.policy.in
vpn-daemons/openvpn
vpn-daemons/pptp
vpn-daemons/vpnc
+contrib/fedora/rpm/
diff --git a/src/Makefile.am b/src/Makefile.am
index d568c00a46..eb5c64c089 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -48,6 +48,77 @@ AM_CPPFLAGS = \
# primarily for its side effect of removing duplicates.
AM_CPPFLAGS += $(foreach d,$(sort $(dir $(libNetworkManager_la_SOURCES))),-I$(top_srcdir)/src/$d)
+noinst_LTLIBRARIES = \
+ libNetworkManager.la \
+ libnm-iface-helper.la \
+ libsystemd-dhcp.la
+
+######################
+# libsystemd-dhcp
+######################
+
+SYSTEMD_DHCP_CFLAGS = \
+ -I$(top_srcdir)/src/dhcp-manager/systemd-dhcp/src/systemd \
+ -I$(top_srcdir)/src/dhcp-manager/systemd-dhcp/src/libsystemd-network \
+ -I$(top_srcdir)/src/dhcp-manager/systemd-dhcp/src/shared \
+ -I$(top_srcdir)/src/dhcp-manager/systemd-dhcp
+
+libsystemd_dhcp_la_SOURCES = \
+ dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-network.c \
+ dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-packet.c \
+ dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-internal.h \
+ dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-network.c \
+ dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-lease-internal.h \
+ dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-option.c \
+ dhcp-manager/systemd-dhcp/src/libsystemd-network/network-internal.c \
+ dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-lease.c \
+ dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-client.c \
+ dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-option.c \
+ dhcp-manager/systemd-dhcp/src/libsystemd-network/network-internal.h \
+ dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp6-lease.c \
+ dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-protocol.h \
+ dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-internal.h \
+ dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-protocol.h \
+ dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-lease-internal.h \
+ dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp6-client.c \
+ dhcp-manager/systemd-dhcp/src/shared/async.h \
+ dhcp-manager/systemd-dhcp/src/shared/time-util.h \
+ dhcp-manager/systemd-dhcp/src/shared/siphash24.h \
+ dhcp-manager/systemd-dhcp/src/shared/time-util.c \
+ dhcp-manager/systemd-dhcp/src/shared/socket-util.h \
+ dhcp-manager/systemd-dhcp/src/shared/sparse-endian.h \
+ dhcp-manager/systemd-dhcp/src/shared/macro.h \
+ dhcp-manager/systemd-dhcp/src/shared/refcnt.h \
+ dhcp-manager/systemd-dhcp/src/shared/util.c \
+ dhcp-manager/systemd-dhcp/src/shared/in-addr-util.c \
+ dhcp-manager/systemd-dhcp/src/shared/siphash24.c \
+ dhcp-manager/systemd-dhcp/src/shared/util.h \
+ dhcp-manager/systemd-dhcp/src/shared/in-addr-util.h \
+ dhcp-manager/systemd-dhcp/src/shared/list.h \
+ dhcp-manager/systemd-dhcp/src/shared/fileio.h \
+ dhcp-manager/systemd-dhcp/src/shared/fileio.c \
+ dhcp-manager/systemd-dhcp/src/shared/strv.h \
+ dhcp-manager/systemd-dhcp/src/shared/strv.c \
+ dhcp-manager/systemd-dhcp/src/shared/utf8.h \
+ dhcp-manager/systemd-dhcp/src/shared/utf8.c \
+ dhcp-manager/systemd-dhcp/src/systemd/sd-dhcp-lease.h \
+ dhcp-manager/systemd-dhcp/src/systemd/sd-dhcp-client.h \
+ dhcp-manager/systemd-dhcp/src/systemd/sd-id128.h \
+ dhcp-manager/systemd-dhcp/src/systemd/sd-dhcp6-lease.h \
+ dhcp-manager/systemd-dhcp/src/systemd/sd-dhcp6-client.h \
+ dhcp-manager/systemd-dhcp/src/systemd/sd-event.h \
+ dhcp-manager/systemd-dhcp/src/systemd/_sd-common.h \
+ dhcp-manager/systemd-dhcp/nm-sd-adapt.h \
+ dhcp-manager/systemd-dhcp/nm-sd-adapt.c
+
+libsystemd_dhcp_la_CPPFLAGS = \
+ -I$(top_srcdir)/include \
+ $(SYSTEMD_DHCP_CFLAGS) \
+ $(GLIB_CFLAGS)
+
+libsystemd_dhcp_la_LIBADD = \
+ $(GLIB_LIBS)
+
###########################################
# NetworkManager
###########################################
@@ -56,12 +127,13 @@ sbin_PROGRAMS = NetworkManager
NetworkManager_SOURCES = \
$(nm_device_sources) $(nm_device_headers) \
+ $(nm_dhcp_client_sources) $(nm_dhcp_client_headers) \
+ main-utils.c \
+ main-utils.h \
main.c
NetworkManager_LDADD = libNetworkManager.la
-noinst_LTLIBRARIES = libNetworkManager.la
-
nm_device_sources = \
devices/nm-device-bond.c \
devices/nm-device-bridge.c \
@@ -87,8 +159,21 @@ nm_device_headers = \
devices/nm-device-vlan.h \
devices/nm-device-vxlan.h
+nm_dhcp_client_sources = \
+ dhcp-manager/nm-dhcp-dhclient.c \
+ dhcp-manager/nm-dhcp-dhclient-utils.c \
+ dhcp-manager/nm-dhcp-dhcpcd.c \
+ dhcp-manager/nm-dhcp-systemd.c
+
+nm_dhcp_client_headers = \
+ dhcp-manager/nm-dhcp-dhclient.h \
+ dhcp-manager/nm-dhcp-dhclient-utils.h \
+ dhcp-manager/nm-dhcp-dhcpcd.h \
+ dhcp-manager/nm-dhcp-systemd.h
+
nm_sources = \
$(nm_device_headers) \
+ $(nm_dhcp_client_headers) \
devices/nm-device.c \
devices/nm-device.h \
devices/nm-device-ethernet-utils.c \
@@ -104,12 +189,8 @@ nm_sources = \
dhcp-manager/nm-dhcp-client.h \
dhcp-manager/nm-dhcp-utils.c \
dhcp-manager/nm-dhcp-utils.h \
- dhcp-manager/nm-dhcp-dhclient.c \
- dhcp-manager/nm-dhcp-dhclient.h \
- dhcp-manager/nm-dhcp-dhclient-utils.c \
- dhcp-manager/nm-dhcp-dhclient-utils.h \
- dhcp-manager/nm-dhcp-dhcpcd.c \
- dhcp-manager/nm-dhcp-dhcpcd.h \
+ dhcp-manager/nm-dhcp-listener.c \
+ dhcp-manager/nm-dhcp-listener.h \
dhcp-manager/nm-dhcp-manager.c \
dhcp-manager/nm-dhcp-manager.h \
\
@@ -213,6 +294,8 @@ nm_sources = \
nm-dbus-manager.h \
nm-dcb.c \
nm-dcb.h \
+ nm-default-route-manager.c \
+ nm-default-route-manager.h \
nm-dhcp4-config.c \
nm-dhcp4-config.h \
nm-dhcp6-config.c \
@@ -328,6 +411,7 @@ AM_CPPFLAGS += \
$(LIBNDP_CFLAGS) \
$(LIBSOUP_CFLAGS) \
$(SYSTEMD_LOGIN_CFLAGS) \
+ $(SYSTEMD_DHCP_CFLAGS) \
\
-DBINDIR=\"$(bindir)\" \
-DDATADIR=\"$(datadir)\" \
@@ -359,6 +443,7 @@ libNetworkManager_la_SOURCES = \
libNetworkManager_la_LIBADD = \
$(top_builddir)/libnm-core/libnm-core.la \
+ libsystemd-dhcp.la \
$(DBUS_LIBS) \
$(GLIB_LIBS) \
$(GUDEV_LIBS) \
@@ -374,6 +459,88 @@ endif
NetworkManager_LDFLAGS = -rdynamic
+######################
+
+libnm_iface_helper_la_SOURCES = \
+ dhcp-manager/nm-dhcp-client.c \
+ dhcp-manager/nm-dhcp-client.h \
+ dhcp-manager/nm-dhcp-utils.c \
+ dhcp-manager/nm-dhcp-utils.h \
+ dhcp-manager/nm-dhcp-manager.c \
+ dhcp-manager/nm-dhcp-manager.h \
+ \
+ platform/nm-linux-platform.c \
+ platform/nm-linux-platform.h \
+ platform/nm-platform.c \
+ platform/nm-platform.h \
+ platform/wifi/wifi-utils-nl80211.c \
+ platform/wifi/wifi-utils-nl80211.h \
+ platform/wifi/wifi-utils-private.h \
+ platform/wifi/wifi-utils.c \
+ platform/wifi/wifi-utils.h \
+ \
+ rdisc/nm-fake-rdisc.c \
+ rdisc/nm-fake-rdisc.h \
+ rdisc/nm-lndp-rdisc.c \
+ rdisc/nm-lndp-rdisc.h \
+ rdisc/nm-rdisc.c \
+ rdisc/nm-rdisc.h \
+ \
+ nm-ip4-config.c \
+ nm-ip4-config.h \
+ nm-ip6-config.c \
+ nm-ip6-config.h \
+ \
+ nm-enum-types.c \
+ nm-enum-types.h \
+ nm-logging.c \
+ nm-logging.h \
+ nm-posix-signals.c \
+ nm-posix-signals.h \
+ NetworkManagerUtils.c \
+ NetworkManagerUtils.h
+
+if WITH_WEXT
+libnm_iface_helper_la_SOURCES += \
+ platform/wifi/wifi-utils-wext.c \
+ platform/wifi/wifi-utils-wext.h
+endif
+
+libnm_iface_helper_la_LIBADD = \
+ $(top_builddir)/libnm-core/libnm-core.la \
+ libsystemd-dhcp.la \
+ $(DBUS_LIBS) \
+ $(GLIB_LIBS) \
+ $(GUDEV_LIBS) \
+ $(LIBNL_LIBS) \
+ $(LIBNDP_LIBS) \
+ $(LIBDL) \
+ $(LIBM)
+
+libexec_PROGRAMS = nm-iface-helper
+
+nm_iface_helper_SOURCES = \
+ dhcp-manager/nm-dhcp-systemd.h \
+ dhcp-manager/nm-dhcp-systemd.c \
+ nm-iface-helper.c \
+ main-utils.c \
+ main-utils.h
+
+nm_iface_helper_LDADD = \
+ $(top_builddir)/libnm-core/libnm-core.la \
+ libsystemd-dhcp.la \
+ libnm-iface-helper.la \
+ $(DBUS_LIBS) \
+ $(GLIB_LIBS) \
+ $(GUDEV_LIBS) \
+ $(LIBNL_LIBS) \
+ $(LIBNDP_LIBS) \
+ $(LIBM)
+
+nm_iface_helper_LDFLAGS = -rdynamic
+
+######################
+
dbusservicedir = $(DBUS_SYS_DIR)
dbusservice_DATA = org.freedesktop.NetworkManager.conf
diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c
index 526aba570c..0dcd643bf3 100644
--- a/src/NetworkManagerUtils.c
+++ b/src/NetworkManagerUtils.c
@@ -22,6 +22,7 @@
#include "config.h"
#include <glib.h>
+#include <gio/gio.h>
#include <glib/gi18n.h>
#include <errno.h>
#include <fcntl.h>
@@ -35,6 +36,7 @@
#include <linux/if_infiniband.h>
#include "NetworkManagerUtils.h"
+#include "nm-platform.h"
#include "nm-utils.h"
#include "nm-core-internal.h"
#include "nm-logging.h"
@@ -1212,8 +1214,7 @@ nm_utils_get_ip_config_method (NMConnection *connection,
GType ip_setting_type)
{
NMSettingConnection *s_con;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4, *s_ip6;
const char *method;
s_con = nm_connection_get_setting_connection (connection);
@@ -1226,7 +1227,7 @@ nm_utils_get_ip_config_method (NMConnection *connection,
else {
s_ip4 = nm_connection_get_setting_ip4_config (connection);
g_return_val_if_fail (s_ip4 != NULL, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
- method = nm_setting_ip4_config_get_method (s_ip4);
+ method = nm_setting_ip_config_get_method (s_ip4);
g_return_val_if_fail (method != NULL, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
return method;
@@ -1240,7 +1241,7 @@ nm_utils_get_ip_config_method (NMConnection *connection,
else {
s_ip6 = nm_connection_get_setting_ip6_config (connection);
g_return_val_if_fail (s_ip6 != NULL, NM_SETTING_IP6_CONFIG_METHOD_AUTO);
- method = nm_setting_ip6_config_get_method (s_ip6);
+ method = nm_setting_ip_config_get_method (s_ip6);
g_return_val_if_fail (method != NULL, NM_SETTING_IP6_CONFIG_METHOD_AUTO);
return method;
@@ -1387,12 +1388,12 @@ check_ip6_method (NMConnection *orig,
{
GHashTable *props;
const char *orig_ip6_method, *candidate_ip6_method;
- NMSettingIP6Config *candidate_ip6;
+ NMSettingIPConfig *candidate_ip6;
gboolean allow = FALSE;
props = check_property_in_hash (settings,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
if (!props)
return TRUE;
@@ -1408,7 +1409,7 @@ check_ip6_method (NMConnection *orig,
if ( strcmp (orig_ip6_method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL) == 0
&& strcmp (candidate_ip6_method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0
- && (!candidate_ip6 || nm_setting_ip6_config_get_may_fail (candidate_ip6))) {
+ && (!candidate_ip6 || nm_setting_ip_config_get_may_fail (candidate_ip6))) {
allow = TRUE;
}
@@ -1425,7 +1426,7 @@ check_ip6_method (NMConnection *orig,
if (allow) {
remove_from_hash (settings, props,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
}
return allow;
}
@@ -1438,11 +1439,11 @@ check_ip4_method (NMConnection *orig,
{
GHashTable *props;
const char *orig_ip4_method, *candidate_ip4_method;
- NMSettingIP4Config *candidate_ip4;
+ NMSettingIPConfig *candidate_ip4;
props = check_property_in_hash (settings,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
if (!props)
return TRUE;
@@ -1457,11 +1458,11 @@ check_ip4_method (NMConnection *orig,
if ( strcmp (orig_ip4_method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0
&& strcmp (candidate_ip4_method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0
- && (!candidate_ip4 || nm_setting_ip4_config_get_may_fail (candidate_ip4))
+ && (!candidate_ip4 || nm_setting_ip_config_get_may_fail (candidate_ip4))
&& (device_has_carrier == FALSE)) {
remove_from_hash (settings, props,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
return TRUE;
}
return FALSE;
@@ -2155,6 +2156,32 @@ out:
}
+#define IPV6_PROPERTY_DIR "/proc/sys/net/ipv6/conf/"
+#define IPV4_PROPERTY_DIR "/proc/sys/net/ipv4/conf/"
+G_STATIC_ASSERT (sizeof (IPV4_PROPERTY_DIR) == sizeof (IPV6_PROPERTY_DIR));
+
+static const char *
+_get_property_path (const char *ifname,
+ const char *property,
+ gboolean ipv6)
+{
+ static char path[sizeof (IPV6_PROPERTY_DIR) + IFNAMSIZ + 32];
+ int len;
+
+ ifname = ASSERT_VALID_PATH_COMPONENT (ifname);
+ property = ASSERT_VALID_PATH_COMPONENT (property);
+
+ len = g_snprintf (path,
+ sizeof (path),
+ "%s%s/%s",
+ ipv6 ? IPV6_PROPERTY_DIR : IPV4_PROPERTY_DIR,
+ ifname,
+ property);
+ g_assert (len < sizeof (path) - 1);
+
+ return path;
+}
+
/**
* nm_utils_ip6_property_path:
* @ifname: an interface name
@@ -2166,18 +2193,21 @@ out:
const char *
nm_utils_ip6_property_path (const char *ifname, const char *property)
{
-#define IPV6_PROPERTY_DIR "/proc/sys/net/ipv6/conf/"
- static char path[sizeof (IPV6_PROPERTY_DIR) + IFNAMSIZ + 32];
- int len;
-
- ifname = ASSERT_VALID_PATH_COMPONENT (ifname);
- property = ASSERT_VALID_PATH_COMPONENT (property);
-
- len = g_snprintf (path, sizeof (path), IPV6_PROPERTY_DIR "%s/%s",
- ifname, property);
- g_assert (len < sizeof (path) - 1);
+ return _get_property_path (ifname, property, TRUE);
+}
- return path;
+/**
+ * nm_utils_ip4_property_path:
+ * @ifname: an interface name
+ * @property: a property name
+ *
+ * Returns the path to IPv4 property @property on @ifname. Note that
+ * this uses a static buffer.
+ */
+const char *
+nm_utils_ip4_property_path (const char *ifname, const char *property)
+{
+ return _get_property_path (ifname, property, FALSE);
}
const char *
@@ -2391,19 +2421,25 @@ nm_utils_ip4_routes_from_gvalue (const GValue *value)
routes = (GPtrArray *) g_value_get_boxed (value);
for (i = 0; routes && (i < routes->len); i++) {
GArray *array = (GArray *) g_ptr_array_index (routes, i);
- NMIP4Route *route;
+ guint32 *array_val = (guint32 *) array->data;
+ NMIPRoute *route;
+ GError *error = NULL;
if (array->len < 4) {
g_warning ("Ignoring invalid IP4 route");
continue;
}
- route = nm_ip4_route_new ();
- nm_ip4_route_set_dest (route, g_array_index (array, guint32, 0));
- nm_ip4_route_set_prefix (route, g_array_index (array, guint32, 1));
- nm_ip4_route_set_next_hop (route, g_array_index (array, guint32, 2));
- nm_ip4_route_set_metric (route, g_array_index (array, guint32, 3));
- list = g_slist_prepend (list, route);
+ route = nm_ip_route_new_binary (AF_INET,
+ &array_val[0], array_val[1],
+ &array_val[2], array_val[3],
+ &error);
+ if (route)
+ list = g_slist_prepend (list, route);
+ else {
+ g_warning ("Ignoring invalid IP4 route: %s", error->message);
+ g_clear_error (&error);
+ }
}
return g_slist_reverse (list);
@@ -2445,7 +2481,8 @@ nm_utils_ip6_routes_from_gvalue (const GValue *value)
GValueArray *route_values = (GValueArray *) g_ptr_array_index (routes, i);
GByteArray *dest, *next_hop;
guint prefix, metric;
- NMIP6Route *route;
+ NMIPRoute *route;
+ GError *error = NULL;
if (!_nm_utils_gvalue_array_validate (route_values, 4,
DBUS_TYPE_G_UCHAR_ARRAY,
@@ -2474,12 +2511,16 @@ nm_utils_ip6_routes_from_gvalue (const GValue *value)
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);
+ route = nm_ip_route_new_binary (AF_INET6,
+ dest->data, prefix,
+ next_hop->data, metric,
+ &error);
+ if (route)
+ list = g_slist_prepend (list, route);
+ else {
+ g_warning ("Ignoring invalid IP6 route: %s", error->message);
+ g_clear_error (&error);
+ }
}
return g_slist_reverse (list);
diff --git a/src/NetworkManagerUtils.h b/src/NetworkManagerUtils.h
index 90182b1921..0ed7587a63 100644
--- a/src/NetworkManagerUtils.h
+++ b/src/NetworkManagerUtils.h
@@ -24,9 +24,10 @@
#include <glib.h>
#include <stdio.h>
+#include <arpa/inet.h>
#include "nm-connection.h"
-#include "nm-platform.h"
+#include "nm-types.h"
gboolean nm_ethernet_address_is_valid (gconstpointer addr, gssize len);
@@ -167,6 +168,7 @@ gint32 nm_utils_get_monotonic_timestamp_s (void);
const char *ASSERT_VALID_PATH_COMPONENT (const char *name) G_GNUC_WARN_UNUSED_RESULT;
const char *nm_utils_ip6_property_path (const char *ifname, const char *property);
+const char *nm_utils_ip4_property_path (const char *ifname, const char *property);
gboolean nm_utils_is_specific_hostname (const char *name);
@@ -188,7 +190,7 @@ typedef struct {
};
} NMUtilsIPv6IfaceId;
-#define NM_UTILS_IPV6_IFACE_ID_INIT { .id = 0 };
+#define NM_UTILS_IPV6_IFACE_ID_INIT { .id = 0 }
gboolean nm_utils_get_ipv6_interface_identifier (NMLinkType link_type,
const guint8 *hwaddr,
diff --git a/src/devices/adsl/nm-atm-manager.c b/src/devices/adsl/nm-atm-manager.c
index 37be69c6e4..1c8ea6b6b6 100644
--- a/src/devices/adsl/nm-atm-manager.c
+++ b/src/devices/adsl/nm-atm-manager.c
@@ -28,6 +28,7 @@
#include "nm-device-adsl.h"
#include "nm-device-factory.h"
#include "nm-logging.h"
+#include "nm-glib-compat.h"
typedef struct {
GUdevClient *client;
diff --git a/src/devices/bluetooth/nm-bluez-device.c b/src/devices/bluetooth/nm-bluez-device.c
index 74a89a5f64..6e80708d87 100644
--- a/src/devices/bluetooth/nm-bluez-device.c
+++ b/src/devices/bluetooth/nm-bluez-device.c
@@ -30,9 +30,12 @@
#include "nm-bluez-device.h"
#include "nm-logging.h"
#include "nm-settings-connection.h"
-#include "nm-bluez5-dun.h"
#include "NetworkManagerUtils.h"
+#if WITH_BLUEZ5_DUN
+#include "nm-bluez5-dun.h"
+#endif
+
G_DEFINE_TYPE (NMBluezDevice, nm_bluez_device, G_TYPE_OBJECT)
#define NM_BLUEZ_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_BLUEZ_DEVICE, NMBluezDevicePrivate))
@@ -59,7 +62,9 @@ typedef struct {
gboolean connected;
char *b4_iface;
+#if WITH_BLUEZ5_DUN
NMBluez5DunContext *b5_dun_context;
+#endif
NMConnectionProvider *provider;
GSList *connections;
@@ -211,16 +216,16 @@ pan_connection_check_create (NMBluezDevice *self)
/* Setting: IPv4 */
setting = nm_setting_ip4_config_new ();
g_object_set (G_OBJECT (setting),
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
- NM_SETTING_IP4_CONFIG_MAY_FAIL, FALSE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, FALSE,
NULL);
nm_connection_add_setting (connection, setting);
/* Setting: IPv6 */
setting = nm_setting_ip6_config_new ();
g_object_set (G_OBJECT (setting),
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
nm_connection_add_setting (connection, setting);
@@ -427,7 +432,11 @@ nm_bluez_device_disconnect (NMBluezDevice *self)
args = g_variant_new ("(s)", priv->b4_iface),
dbus_iface = BLUEZ4_SERIAL_INTERFACE;
} else if (priv->bluez_version == 5) {
+#if WITH_BLUEZ5_DUN
nm_bluez5_dun_cleanup (priv->b5_dun_context);
+#else
+ g_assert_not_reached ();
+#endif
priv->connected = FALSE;
goto out;
}
@@ -491,6 +500,7 @@ bluez_connect_cb (GDBusConnection *dbus_connection,
g_object_unref (result_object);
}
+#if WITH_BLUEZ5_DUN
static void
bluez5_dun_connect_cb (NMBluez5DunContext *context,
const char *device,
@@ -510,6 +520,7 @@ bluez5_dun_connect_cb (NMBluez5DunContext *context,
g_simple_async_result_complete (result);
g_object_unref (result);
}
+#endif
void
nm_bluez_device_connect_async (NMBluezDevice *self,
@@ -541,9 +552,13 @@ nm_bluez_device_connect_async (NMBluezDevice *self,
if (priv->bluez_version == 4)
dbus_iface = BLUEZ4_SERIAL_INTERFACE;
else if (priv->bluez_version == 5) {
+#if WITH_BLUEZ5_DUN
if (priv->b5_dun_context == NULL)
priv->b5_dun_context = nm_bluez5_dun_new (priv->adapter_address, priv->address);
nm_bluez5_dun_connect (priv->b5_dun_context, bluez5_dun_connect_cb, simple);
+#else
+ g_assert_not_reached ();
+#endif
return;
}
} else
@@ -1089,10 +1104,12 @@ dispose (GObject *object)
priv->pan_connection = NULL;
}
+#if WITH_BLUEZ5_DUN
if (priv->b5_dun_context) {
nm_bluez5_dun_free (priv->b5_dun_context);
priv->b5_dun_context = NULL;
}
+#endif
g_signal_handlers_disconnect_by_func (priv->provider, cp_connection_added, self);
g_signal_handlers_disconnect_by_func (priv->provider, cp_connection_removed, self);
diff --git a/src/devices/nm-device-gre.c b/src/devices/nm-device-gre.c
index e7df12e3f8..9c25b398ce 100644
--- a/src/devices/nm-device-gre.c
+++ b/src/devices/nm-device-gre.c
@@ -21,6 +21,7 @@
#include "config.h"
#include <string.h>
+#include <arpa/inet.h>
#include "nm-device-gre.h"
#include "nm-device-private.h"
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index af5e52750c..263e1f64d3 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -68,6 +68,7 @@
#include "nm-config.h"
#include "nm-dns-manager.h"
#include "nm-core-internal.h"
+#include "nm-default-route-manager.h"
#include "nm-device-logging.h"
_LOG_DECLARE_SELF (NMDevice);
@@ -237,6 +238,12 @@ typedef struct {
NMIP4Config * dev_ip4_config; /* Config from DHCP, PPP, LLv4, etc */
NMIP4Config * ext_ip4_config; /* Stuff added outside NM */
NMIP4Config * wwan_ip4_config; /* WWAN configuration */
+ struct {
+ gboolean v4_has;
+ NMPlatformIP4Route v4;
+ gboolean v6_has;
+ NMPlatformIP6Route v6;
+ } default_route;
/* DHCPv4 tracking */
NMDhcpClient * dhcp4_client;
@@ -640,7 +647,7 @@ nm_device_get_device_type (NMDevice *self)
int
nm_device_get_priority (NMDevice *self)
{
- g_return_val_if_fail (NM_IS_DEVICE (self), 100);
+ g_return_val_if_fail (NM_IS_DEVICE (self), 1000);
/* Device 'priority' is used for two things:
*
@@ -653,33 +660,90 @@ nm_device_get_priority (NMDevice *self)
*/
switch (nm_device_get_device_type (self)) {
+ /* 10 is reserved for VPN (NM_VPN_ROUTE_METRIC_DEFAULT) */
case NM_DEVICE_TYPE_ETHERNET:
- return 1;
+ return 20;
case NM_DEVICE_TYPE_INFINIBAND:
- return 2;
+ return 30;
case NM_DEVICE_TYPE_ADSL:
- return 3;
+ return 40;
case NM_DEVICE_TYPE_WIMAX:
- return 4;
+ return 50;
case NM_DEVICE_TYPE_BOND:
- return 5;
+ return 60;
case NM_DEVICE_TYPE_TEAM:
- return 6;
+ return 70;
case NM_DEVICE_TYPE_VLAN:
- return 7;
+ return 80;
case NM_DEVICE_TYPE_MODEM:
- return 8;
+ return 90;
case NM_DEVICE_TYPE_BT:
- return 9;
+ return 100;
case NM_DEVICE_TYPE_WIFI:
- return 10;
+ return 110;
case NM_DEVICE_TYPE_OLPC_MESH:
- return 11;
+ return 120;
default:
- return 20;
+ return 200;
}
}
+guint32
+nm_device_get_ip4_route_metric (NMDevice *self)
+{
+ NMConnection *connection;
+ gint64 route_metric = -1;
+
+ g_return_val_if_fail (NM_IS_DEVICE (self), G_MAXUINT32);
+
+ connection = nm_device_get_connection (self);
+
+ if (connection)
+ route_metric = nm_setting_ip_config_get_route_metric (nm_connection_get_setting_ip4_config (connection));
+
+ return route_metric >= 0 ? route_metric : nm_device_get_priority (self);
+}
+
+guint32
+nm_device_get_ip6_route_metric (NMDevice *self)
+{
+ NMConnection *connection;
+ gint64 route_metric = -1;
+
+ g_return_val_if_fail (NM_IS_DEVICE (self), G_MAXUINT32);
+
+ connection = nm_device_get_connection (self);
+
+ if (connection)
+ route_metric = nm_setting_ip_config_get_route_metric (nm_connection_get_setting_ip6_config (connection));
+
+ return route_metric >= 0 ? route_metric : nm_device_get_priority (self);
+}
+
+const NMPlatformIP4Route *
+nm_device_get_ip4_default_route (NMDevice *self)
+{
+ NMDevicePrivate *priv;
+
+ g_return_val_if_fail (NM_IS_DEVICE (self), NULL);
+
+ priv = NM_DEVICE_GET_PRIVATE (self);
+
+ return priv->default_route.v4_has ? &priv->default_route.v4 : NULL;
+}
+
+const NMPlatformIP6Route *
+nm_device_get_ip6_default_route (NMDevice *self)
+{
+ NMDevicePrivate *priv;
+
+ g_return_val_if_fail (NM_IS_DEVICE (self), NULL);
+
+ priv = NM_DEVICE_GET_PRIVATE (self);
+
+ return priv->default_route.v6_has ? &priv->default_route.v6 : NULL;
+}
+
const char *
nm_device_get_type_desc (NMDevice *self)
{
@@ -742,6 +806,17 @@ nm_device_uses_generated_assumed_connection (NMDevice *self)
return FALSE;
}
+gboolean
+nm_device_uses_assumed_connection (NMDevice *self)
+{
+ NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
+
+ if ( priv->act_request
+ && nm_active_connection_get_assumed (NM_ACTIVE_CONNECTION (priv->act_request)))
+ return TRUE;
+ return FALSE;
+}
+
static SlaveInfo *
find_slave_info (NMDevice *self, NMDevice *slave)
{
@@ -2106,8 +2181,7 @@ gboolean
nm_device_ip_config_should_fail (NMDevice *self, gboolean ip6)
{
NMConnection *connection;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4, *s_ip6;
g_return_val_if_fail (self != NULL, TRUE);
@@ -2117,11 +2191,11 @@ nm_device_ip_config_should_fail (NMDevice *self, gboolean ip6)
/* Fail the connection if the failed IP method is required to complete */
if (ip6) {
s_ip6 = nm_connection_get_setting_ip6_config (connection);
- if (!nm_setting_ip6_config_get_may_fail (s_ip6))
+ if (!nm_setting_ip_config_get_may_fail (s_ip6))
return TRUE;
} else {
s_ip4 = nm_connection_get_setting_ip4_config (connection);
- if (!nm_setting_ip4_config_get_may_fail (s_ip4))
+ if (!nm_setting_ip_config_get_may_fail (s_ip4))
return TRUE;
}
@@ -2394,7 +2468,7 @@ aipd_get_ip4_config (NMDevice *self, guint32 lla)
route.network = htonl (0xE0000000L);
route.plen = 4;
route.source = NM_IP_CONFIG_SOURCE_IP4LL;
- route.metric = nm_device_get_priority (self);
+ route.metric = nm_device_get_ip4_route_metric (self);
nm_ip4_config_add_route (config, &route);
return config;
@@ -2594,6 +2668,52 @@ aipd_start (NMDevice *self, NMDeviceStateReason *reason)
}
/*********************************************/
+
+static gboolean
+_device_get_default_route_from_platform (NMDevice *self, int addr_family, NMPlatformIPRoute *out_route)
+{
+ gboolean success = FALSE;
+ int ifindex = nm_device_get_ip_ifindex (self);
+ GArray *routes;
+
+ if (addr_family == AF_INET)
+ routes = nm_platform_ip4_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT);
+ else
+ routes = nm_platform_ip6_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT);
+
+ if (routes) {
+ guint route_metric = G_MAXUINT32, m;
+ const NMPlatformIPRoute *route = NULL, *r;
+ guint i;
+
+ /* if there are several default routes, find the one with the best metric */
+ for (i = 0; i < routes->len; i++) {
+ if (addr_family == AF_INET) {
+ r = (const NMPlatformIPRoute *) &g_array_index (routes, NMPlatformIP4Route, i);
+ m = r->metric;
+ } else {
+ r = (const NMPlatformIPRoute *) &g_array_index (routes, NMPlatformIP6Route, i);
+ m = nm_utils_ip6_route_metric_normalize (r->metric);
+ }
+ if (!route || m < route_metric) {
+ route = r;
+ route_metric = m;
+ }
+ }
+
+ if (route) {
+ if (addr_family == AF_INET)
+ *((NMPlatformIP4Route *) out_route) = *((NMPlatformIP4Route *) route);
+ else
+ *((NMPlatformIP6Route *) out_route) = *((NMPlatformIP6Route *) route);
+ success = TRUE;
+ }
+ g_array_free (routes, TRUE);
+ }
+ return success;
+}
+
+/*********************************************/
/* DHCPv4 stuff */
static void
@@ -2658,11 +2778,58 @@ ip4_config_merge_and_apply (NMDevice *self,
* be redundant, so don't bother.
*/
connection = nm_device_get_connection (self);
- if ( connection
- && !nm_settings_connection_get_nm_generated_assumed (NM_SETTINGS_CONNECTION (connection))) {
- nm_ip4_config_merge_setting (composite,
- nm_connection_get_setting_ip4_config (connection),
- nm_device_get_priority (self));
+ priv->default_route.v4_has = FALSE;
+ if (connection) {
+ gboolean assumed = nm_device_uses_assumed_connection (self);
+
+ if (!nm_settings_connection_get_nm_generated_assumed (NM_SETTINGS_CONNECTION (connection))) {
+ nm_ip4_config_merge_setting (composite,
+ nm_connection_get_setting_ip4_config (connection),
+ nm_device_get_ip4_route_metric (self));
+ }
+
+ /* Add the default route.
+ *
+ * We keep track of the default route of a device in a private field.
+ * NMDevice needs to know the default route at this point, because the gateway
+ * might require a direct route (see below).
+ *
+ * But also, we don't want to add the default route to priv->ip4_config,
+ * because the default route from the setting might not be the same that
+ * NMDefaultRouteManager eventually configures (because the it might
+ * tweak the effective metric).
+ */
+ if (nm_default_route_manager_ip4_connection_has_default_route (nm_default_route_manager_get (), connection)) {
+ guint32 gateway = 0;
+ NMPlatformIP4Route *route = &priv->default_route.v4;
+
+ if (assumed)
+ priv->default_route.v4_has = _device_get_default_route_from_platform (self, AF_INET, (NMPlatformIPRoute *) route);
+ else {
+ gateway = nm_ip4_config_get_gateway (composite);
+ if ( gateway
+ || nm_device_get_device_type (self) == NM_DEVICE_TYPE_MODEM) {
+ memset (route, 0, sizeof (*route));
+ route->source = NM_IP_CONFIG_SOURCE_USER;
+ route->gateway = gateway;
+ route->metric = nm_device_get_ip4_route_metric (self);
+ route->mss = nm_ip4_config_get_mss (composite);
+ priv->default_route.v4_has = TRUE;
+
+ if ( gateway
+ && !nm_ip4_config_get_subnet_for_host (composite, gateway)
+ && !nm_ip4_config_get_direct_route_for_host (composite, gateway)) {
+ /* add a direct route to the gateway */
+ NMPlatformIP4Route r = *route;
+
+ r.network = gateway;
+ r.plen = 32;
+ r.gateway = 0;
+ nm_ip4_config_add_route (composite, &r);
+ }
+ }
+ }
+ }
}
/* Allow setting MTU etc */
@@ -2778,7 +2945,7 @@ dhcp4_start (NMDevice *self,
NMDeviceStateReason *reason)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
const guint8 *hw_addr;
size_t hw_addr_len = 0;
GByteArray *tmp = NULL;
@@ -2803,12 +2970,13 @@ dhcp4_start (NMDevice *self,
nm_device_get_ip_ifindex (self),
tmp,
nm_connection_get_uuid (connection),
- nm_device_get_priority (self),
- nm_setting_ip4_config_get_dhcp_send_hostname (s_ip4),
- nm_setting_ip4_config_get_dhcp_hostname (s_ip4),
- nm_setting_ip4_config_get_dhcp_client_id (s_ip4),
+ nm_device_get_ip4_route_metric (self),
+ nm_setting_ip_config_get_dhcp_send_hostname (s_ip4),
+ nm_setting_ip_config_get_dhcp_hostname (s_ip4),
+ nm_setting_ip4_config_get_dhcp_client_id (NM_SETTING_IP4_CONFIG (s_ip4)),
priv->dhcp_timeout,
- priv->dhcp_anycast_address);
+ priv->dhcp_anycast_address,
+ NULL);
if (tmp)
g_byte_array_free (tmp, TRUE);
@@ -2864,20 +3032,20 @@ release_shared_ip (gpointer data)
}
static gboolean
-reserve_shared_ip (NMDevice *self, NMSettingIP4Config *s_ip4, NMPlatformIP4Address *address)
+reserve_shared_ip (NMDevice *self, NMSettingIPConfig *s_ip4, NMPlatformIP4Address *address)
{
if (G_UNLIKELY (shared_ips == NULL))
shared_ips = g_hash_table_new (g_direct_hash, g_direct_equal);
memset (address, 0, sizeof (*address));
- if (s_ip4 && nm_setting_ip4_config_get_num_addresses (s_ip4)) {
+ if (s_ip4 && nm_setting_ip_config_get_num_addresses (s_ip4)) {
/* Use the first user-supplied address */
- NMIP4Address *user = nm_setting_ip4_config_get_address (s_ip4, 0);
+ NMIPAddress *user = nm_setting_ip_config_get_address (s_ip4, 0);
g_assert (user);
- address->address = nm_ip4_address_get_address (user);
- address->plen = nm_ip4_address_get_prefix (user);
+ nm_ip_address_get_address_binary (user, &address->address);
+ address->plen = nm_ip_address_get_prefix (user);
} else {
/* Find an unused address in the 10.42.x.x range */
guint32 start = (guint32) ntohl (0x0a2a0001); /* 10.42.0.1 */
@@ -2964,8 +3132,7 @@ connection_ip6_method_requires_carrier (NMConnection *connection,
static gboolean
connection_requires_carrier (NMConnection *connection)
{
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4, *s_ip6;
gboolean ip4_carrier_wanted, ip6_carrier_wanted;
gboolean ip4_used = FALSE, ip6_used = FALSE;
@@ -2975,7 +3142,7 @@ connection_requires_carrier (NMConnection *connection)
* requires a carrier regardless of the IPv6 method.
*/
s_ip4 = nm_connection_get_setting_ip4_config (connection);
- if (s_ip4 && !nm_setting_ip4_config_get_may_fail (s_ip4))
+ if (s_ip4 && !nm_setting_ip_config_get_may_fail (s_ip4))
return TRUE;
}
@@ -2985,7 +3152,7 @@ connection_requires_carrier (NMConnection *connection)
* requires a carrier regardless of the IPv4 method.
*/
s_ip6 = nm_connection_get_setting_ip6_config (connection);
- if (s_ip6 && !nm_setting_ip6_config_get_may_fail (s_ip6))
+ if (s_ip6 && !nm_setting_ip_config_get_may_fail (s_ip6))
return TRUE;
}
@@ -3160,11 +3327,57 @@ ip6_config_merge_and_apply (NMDevice *self,
* be redundant, so don't bother.
*/
connection = nm_device_get_connection (self);
- if ( connection
- && !nm_settings_connection_get_nm_generated_assumed (NM_SETTINGS_CONNECTION (connection))) {
- nm_ip6_config_merge_setting (composite,
- nm_connection_get_setting_ip6_config (connection),
- nm_device_get_priority (self));
+ priv->default_route.v6_has = FALSE;
+ if (connection) {
+ gboolean assumed = nm_device_uses_assumed_connection (self);
+
+ if (!nm_settings_connection_get_nm_generated_assumed (NM_SETTINGS_CONNECTION (connection))) {
+ nm_ip6_config_merge_setting (composite,
+ nm_connection_get_setting_ip6_config (connection),
+ nm_device_get_ip6_route_metric (self));
+ }
+
+ /* Add the default route.
+ *
+ * We keep track of the default route of a device in a private field.
+ * NMDevice needs to know the default route at this point, because the gateway
+ * might require a direct route (see below).
+ *
+ * But also, we don't want to add the default route to priv->ip4_config,
+ * because the default route from the setting might not be the same that
+ * NMDefaultRouteManager eventually configures (because the it might
+ * tweak the effective metric).
+ */
+ if (nm_default_route_manager_ip6_connection_has_default_route (nm_default_route_manager_get (), connection)) {
+ const struct in6_addr *gateway = NULL;
+ NMPlatformIP6Route *route = &priv->default_route.v6;
+
+ if (assumed)
+ priv->default_route.v6_has = _device_get_default_route_from_platform (self, AF_INET6, (NMPlatformIPRoute *) route);
+ else {
+ gateway = nm_ip6_config_get_gateway (composite);
+ if (gateway) {
+ memset (route, 0, sizeof (*route));
+ route->source = NM_IP_CONFIG_SOURCE_USER;
+ route->gateway = *gateway;
+ route->metric = nm_device_get_ip6_route_metric (self);
+ route->mss = nm_ip6_config_get_mss (composite);
+ priv->default_route.v6_has = TRUE;
+
+ if ( gateway
+ && !nm_ip6_config_get_subnet_for_host (composite, gateway)
+ && !nm_ip6_config_get_direct_route_for_host (composite, gateway)) {
+ /* add a direct route to the gateway */
+ NMPlatformIP6Route r = *route;
+
+ r.network = *gateway;
+ r.plen = 128;
+ r.gateway = in6addr_any;
+ nm_ip6_config_add_route (composite, &r);
+ }
+ }
+ }
+ }
}
nm_ip6_config_addresses_sort (composite,
@@ -3320,7 +3533,7 @@ dhcp6_start (NMDevice *self,
guint32 dhcp_opt,
NMDeviceStateReason *reason)
{
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip6;
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE;
GByteArray *tmp = NULL;
@@ -3357,12 +3570,13 @@ dhcp6_start (NMDevice *self,
nm_device_get_ip_ifindex (self),
tmp,
nm_connection_get_uuid (connection),
- nm_device_get_priority (self),
- nm_setting_ip6_config_get_dhcp_hostname (s_ip6),
+ nm_device_get_ip6_route_metric (self),
+ nm_setting_ip_config_get_dhcp_send_hostname (s_ip6),
+ nm_setting_ip_config_get_dhcp_hostname (s_ip6),
priv->dhcp_timeout,
priv->dhcp_anycast_address,
(dhcp_opt == NM_RDISC_DHCP_LEVEL_OTHERCONF) ? TRUE : FALSE,
- nm_setting_ip6_config_get_ip6_privacy (s_ip6));
+ nm_setting_ip6_config_get_ip6_privacy (NM_SETTING_IP6_CONFIG (s_ip6)));
if (tmp)
g_byte_array_free (tmp, TRUE);
@@ -3373,8 +3587,8 @@ dhcp6_start (NMDevice *self,
self);
s_ip6 = nm_connection_get_setting_ip6_config (connection);
- if (!nm_setting_ip6_config_get_may_fail (s_ip6) ||
- !strcmp (nm_setting_ip6_config_get_method (s_ip6), NM_SETTING_IP6_CONFIG_METHOD_DHCP))
+ if (!nm_setting_ip_config_get_may_fail (s_ip6) ||
+ !strcmp (nm_setting_ip_config_get_method (s_ip6), NM_SETTING_IP6_CONFIG_METHOD_DHCP))
nm_device_add_pending_action (self, PENDING_ACTION_DHCP6, TRUE);
/* DHCP devices will be notified by the DHCP manager when stuff happens */
@@ -3700,7 +3914,7 @@ rdisc_config_changed (NMRDisc *rdisc, NMRDiscConfigMap changed, NMDevice *self)
route.plen = discovered_route->plen;
route.gateway = discovered_route->gateway;
route.source = NM_IP_CONFIG_SOURCE_RDISC;
- route.metric = nm_device_get_priority (self);
+ route.metric = nm_device_get_ip6_route_metric (self);
nm_ip6_config_add_route (priv->ac_ip6_config, &route);
}
@@ -3858,7 +4072,7 @@ addrconf6_start (NMDevice *self, NMSettingIP6ConfigPrivacy use_tempaddr)
priv->rdisc_use_tempaddr = use_tempaddr;
print_support_extended_ifa_flags (use_tempaddr);
- if (!nm_setting_ip6_config_get_may_fail (nm_connection_get_setting_ip6_config (connection)))
+ if (!nm_setting_ip_config_get_may_fail (nm_connection_get_setting_ip6_config (connection)))
nm_device_add_pending_action (self, PENDING_ACTION_AUTOCONF6, TRUE);
/* ensure link local is ready... */
@@ -4116,10 +4330,10 @@ act_stage3_ip6_config_start (NMDevice *self,
*/
ip6_privacy = ip6_use_tempaddr ();
if (ip6_privacy == NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN) {
- NMSettingIP6Config *s_ip6 = nm_connection_get_setting_ip6_config (connection);
+ NMSettingIPConfig *s_ip6 = nm_connection_get_setting_ip6_config (connection);
if (s_ip6)
- ip6_privacy = nm_setting_ip6_config_get_ip6_privacy (s_ip6);
+ ip6_privacy = nm_setting_ip6_config_get_ip6_privacy (NM_SETTING_IP6_CONFIG (s_ip6));
}
ip6_privacy = use_tempaddr_clamp (ip6_privacy);
@@ -4648,10 +4862,9 @@ send_arps (NMDevice *self, const char *mode_arg)
const char *argv[] = { NULL, mode_arg, "-q", "-I", nm_device_get_ip_iface (self), "-c", "1", NULL, NULL };
int ip_arg = G_N_ELEMENTS (argv) - 2;
NMConnection *connection;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
int i, num;
- NMIP4Address *addr;
- guint32 ipaddr;
+ NMIPAddress *addr;
GError *error = NULL;
connection = nm_device_get_connection (self);
@@ -4660,7 +4873,7 @@ send_arps (NMDevice *self, const char *mode_arg)
s_ip4 = nm_connection_get_setting_ip4_config (connection);
if (!s_ip4)
return;
- num = nm_setting_ip4_config_get_num_addresses (s_ip4);
+ num = nm_setting_ip_config_get_num_addresses (s_ip4);
if (num == 0)
return;
@@ -4672,9 +4885,8 @@ send_arps (NMDevice *self, const char *mode_arg)
for (i = 0; i < num; i++) {
gs_free char *tmp_str = NULL;
- addr = nm_setting_ip4_config_get_address (s_ip4, i);
- ipaddr = nm_ip4_address_get_address (addr);
- argv[ip_arg] = (char *) nm_utils_inet4_ntop (ipaddr, NULL);
+ addr = nm_setting_ip_config_get_address (s_ip4, i);
+ argv[ip_arg] = nm_ip_address_get_address (addr);
_LOGD (LOGD_DEVICE | LOGD_IP4,
"arping: run %s", (tmp_str = g_strjoinv (" ", (char **) argv)));
@@ -4721,7 +4933,7 @@ arp_announce (NMDevice *self)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
NMConnection *connection;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
int num;
arp_cleanup (self);
@@ -4735,7 +4947,7 @@ arp_announce (NMDevice *self)
s_ip4 = nm_connection_get_setting_ip4_config (connection);
if (!s_ip4)
return;
- num = nm_setting_ip4_config_get_num_addresses (s_ip4);
+ num = nm_setting_ip_config_get_num_addresses (s_ip4);
if (num == 0)
return;
@@ -5084,6 +5296,8 @@ delete_on_deactivate_check_and_schedule (NMDevice *self, int ifindex)
return;
if (!priv->is_nm_owned)
return;
+ if (priv->queued_act_request)
+ return;
if (!nm_device_is_software (self))
return;
if (nm_device_get_state (self) == NM_DEVICE_STATE_UNMANAGED)
@@ -5362,6 +5576,8 @@ nm_device_set_ip4_config (NMDevice *self,
g_clear_object (&priv->dev_ip4_config);
}
+ nm_default_route_manager_ip4_update_default_route (nm_default_route_manager_get (), self);
+
if (has_changes) {
_update_ip4_address (self);
@@ -5483,6 +5699,8 @@ nm_device_set_ip6_config (NMDevice *self,
nm_ip6_config_get_dbus_path (old_config));
}
+ nm_default_route_manager_ip6_update_default_route (nm_default_route_manager_get (), self);
+
if (has_changes) {
if (old_config != priv->ip6_config)
g_object_notify (G_OBJECT (self), NM_DEVICE_IP6_CONFIG);
@@ -6677,6 +6895,12 @@ _cleanup_generic_post (NMDevice *self, gboolean deconfigure)
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
NMDeviceStateReason ignored = NM_DEVICE_STATE_REASON_NONE;
+ priv->default_route.v4_has = FALSE;
+ priv->default_route.v6_has = FALSE;
+
+ nm_default_route_manager_ip4_remove_default_route (nm_default_route_manager_get (), self);
+ nm_default_route_manager_ip6_remove_default_route (nm_default_route_manager_get (), self);
+
/* Clean up IP configs; this does not actually deconfigure the
* interface; the caller must flush routes and addresses explicitly.
*/
@@ -6766,6 +6990,173 @@ nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason)
_cleanup_generic_post (self, TRUE);
}
+static char *
+bin2hexstr (const char *bytes, gsize len)
+{
+ GString *str;
+ int i;
+
+ g_return_val_if_fail (bytes != NULL, NULL);
+ g_return_val_if_fail (len > 0, NULL);
+
+ str = g_string_sized_new (len * 2 + 1);
+ for (i = 0; i < len; i++) {
+ if (str->len)
+ g_string_append_c (str, ':');
+ g_string_append_printf (str, "%02x", (guint8) bytes[i]);
+ }
+ return g_string_free (str, FALSE);
+}
+
+static char *
+find_dhcp4_address (NMDevice *self)
+{
+ NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
+ guint i, n;
+
+ if (!priv->ip4_config)
+ return NULL;
+
+ n = nm_ip4_config_get_num_addresses (priv->ip4_config);
+ for (i = 0; i < n; i++) {
+ const NMPlatformIP4Address *a = nm_ip4_config_get_address (priv->ip4_config, i);
+
+ if (a->source == NM_IP_CONFIG_SOURCE_DHCP)
+ return g_strdup (nm_utils_inet4_ntop (a->address, NULL));
+ }
+ return NULL;
+}
+
+void
+nm_device_spawn_iface_helper (NMDevice *self)
+{
+ NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
+ gboolean priority_set = FALSE, configured = FALSE;
+ NMConnection *connection;
+ GError *error = NULL;
+ const char *method;
+ GPtrArray *argv;
+ gs_free char *dhcp4_address = NULL;
+
+ if (priv->state != NM_DEVICE_STATE_ACTIVATED)
+ return;
+ if (!nm_device_can_assume_connections (self))
+ return;
+
+ connection = nm_device_get_connection (self);
+ g_assert (connection);
+
+ argv = g_ptr_array_sized_new (10);
+ g_ptr_array_set_free_func (argv, g_free);
+
+ g_ptr_array_add (argv, g_strdup (LIBEXECDIR "/nm-iface-helper"));
+ g_ptr_array_add (argv, g_strdup ("--ifname"));
+ g_ptr_array_add (argv, g_strdup (nm_device_get_ip_iface (self)));
+ g_ptr_array_add (argv, g_strdup ("--uuid"));
+ g_ptr_array_add (argv, g_strdup (nm_connection_get_uuid (connection)));
+
+ dhcp4_address = find_dhcp4_address (self);
+
+ method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG);
+ if ( priv->ip4_config
+ && priv->ip4_state == IP_DONE
+ && g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0
+ && priv->dhcp4_client
+ && dhcp4_address) {
+ NMSettingIPConfig *s_ip4;
+ GBytes *client_id;
+ char *hex_client_id;
+ const char *hostname;
+
+ s_ip4 = nm_connection_get_setting_ip4_config (connection);
+ g_assert (s_ip4);
+
+ g_ptr_array_add (argv, g_strdup ("--priority"));
+ g_ptr_array_add (argv, g_strdup_printf ("%u", nm_dhcp_client_get_priority (priv->dhcp4_client)));
+ priority_set = TRUE;
+
+ g_ptr_array_add (argv, g_strdup ("--dhcp4"));
+ g_ptr_array_add (argv, g_strdup (dhcp4_address));
+ if (nm_setting_ip_config_get_may_fail (s_ip4) == FALSE)
+ g_ptr_array_add (argv, g_strdup ("--dhcp4-required"));
+
+ client_id = nm_dhcp_client_get_client_id (priv->dhcp4_client);
+ if (client_id) {
+ g_ptr_array_add (argv, g_strdup ("--dhcp4-clientid"));
+ hex_client_id = bin2hexstr (g_bytes_get_data (client_id, NULL),
+ g_bytes_get_size (client_id));
+ g_ptr_array_add (argv, hex_client_id);
+ }
+
+ hostname = nm_dhcp_client_get_hostname (priv->dhcp4_client);
+ if (client_id) {
+ g_ptr_array_add (argv, g_strdup ("--dhcp4-hostname"));
+ g_ptr_array_add (argv, g_strdup (hostname));
+ }
+
+ configured = TRUE;
+ }
+
+ method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP6_CONFIG);
+ if ( priv->ip6_config
+ && priv->ip6_state == IP_DONE
+ && g_strcmp0 (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0
+ && priv->rdisc
+ && priv->ac_ip6_config) {
+ NMSettingIPConfig *s_ip6;
+ char *hex_iid;
+ NMUtilsIPv6IfaceId iid = NM_UTILS_IPV6_IFACE_ID_INIT;
+
+ s_ip6 = nm_connection_get_setting_ip6_config (connection);
+ g_assert (s_ip6);
+
+ g_ptr_array_add (argv, g_strdup ("--slaac"));
+
+ if (nm_setting_ip_config_get_may_fail (s_ip6) == FALSE)
+ g_ptr_array_add (argv, g_strdup ("--slaac-required"));
+
+ g_ptr_array_add (argv, g_strdup ("--slaac-tempaddr"));
+ g_ptr_array_add (argv, g_strdup_printf ("%d", priv->rdisc_use_tempaddr));
+
+ if (nm_device_get_ip_iface_identifier (self, &iid)) {
+ g_ptr_array_add (argv, g_strdup ("--iid"));
+ hex_iid = bin2hexstr ((const char *) iid.id_u8, sizeof (NMUtilsIPv6IfaceId));
+ g_ptr_array_add (argv, hex_iid);
+ }
+
+ configured = TRUE;
+ }
+
+ if (configured) {
+ GPid pid;
+
+ if (!priority_set) {
+ g_ptr_array_add (argv, g_strdup ("--priority"));
+ g_ptr_array_add (argv, g_strdup_printf ("%u", nm_device_get_priority (self)));
+ }
+
+ g_ptr_array_add (argv, NULL);
+
+ if (nm_logging_enabled (LOGL_DEBUG, LOGD_DEVICE)) {
+ char *tmp;
+
+ tmp = g_strjoinv (" ", (char **) argv->pdata);
+ _LOGD (LOGD_DEVICE, "running '%s'", tmp);
+ g_free (tmp);
+ }
+
+ if (g_spawn_async (NULL, (char **) argv->pdata, NULL,
+ G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, &error)) {
+ _LOGI (LOGD_DEVICE, "spawned helper PID %u", (guint) pid);
+ } else {
+ _LOGW (LOGD_DEVICE, "failed to spawn helper: %s", error->message);
+ g_error_free (error);
+ }
+ }
+
+ g_ptr_array_unref (argv);
+}
+
/***********************************************************/
static gboolean
diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h
index b053070388..840a19c08b 100644
--- a/src/devices/nm-device.h
+++ b/src/devices/nm-device.h
@@ -228,6 +228,8 @@ const char * nm_device_get_type_desc (NMDevice *dev);
NMDeviceType nm_device_get_device_type (NMDevice *dev);
int nm_device_get_priority (NMDevice *dev);
+guint32 nm_device_get_ip4_route_metric (NMDevice *dev);
+guint32 nm_device_get_ip6_route_metric (NMDevice *dev);
const char * nm_device_get_hw_address (NMDevice *dev);
@@ -273,6 +275,8 @@ gboolean nm_device_complete_connection (NMDevice *device,
gboolean nm_device_check_connection_compatible (NMDevice *device, NMConnection *connection);
+gboolean nm_device_uses_assumed_connection (NMDevice *device);
+
gboolean nm_device_can_assume_active_connection (NMDevice *device);
gboolean nm_device_spec_match_list (NMDevice *device, const GSList *specs);
@@ -358,6 +362,11 @@ gboolean nm_device_owns_iface (NMDevice *device, const char *iface);
NMConnection *nm_device_new_default_connection (NMDevice *self);
+const NMPlatformIP4Route *nm_device_get_ip4_default_route (NMDevice *self);
+const NMPlatformIP6Route *nm_device_get_ip6_default_route (NMDevice *self);
+
+void nm_device_spawn_iface_helper (NMDevice *self);
+
G_END_DECLS
/* For testing only */
diff --git a/src/devices/team/nm-device-team.c b/src/devices/team/nm-device-team.c
index df27562019..3c949258c0 100644
--- a/src/devices/team/nm-device-team.c
+++ b/src/devices/team/nm-device-team.c
@@ -453,6 +453,7 @@ teamd_start (NMDevice *device, NMSettingTeam *s_team)
g_ptr_array_add (argv, (gpointer) "-n");
g_ptr_array_add (argv, (gpointer) "-U");
g_ptr_array_add (argv, (gpointer) "-D");
+ g_ptr_array_add (argv, (gpointer) "-N");
g_ptr_array_add (argv, (gpointer) "-t");
g_ptr_array_add (argv, (gpointer) iface);
diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c
index 1210106a0e..f8b4c2a3d6 100644
--- a/src/devices/wifi/nm-device-wifi.c
+++ b/src/devices/wifi/nm-device-wifi.c
@@ -2809,14 +2809,14 @@ act_stage3_ip4_config_start (NMDevice *device,
NMDeviceStateReason *reason)
{
NMConnection *connection;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
const char *method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
connection = nm_device_get_connection (device);
g_assert (connection);
s_ip4 = nm_connection_get_setting_ip4_config (connection);
if (s_ip4)
- method = nm_setting_ip4_config_get_method (s_ip4);
+ method = nm_setting_ip_config_get_method (s_ip4);
/* Indicate that a critical protocol is about to start */
if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0)
@@ -2831,14 +2831,14 @@ act_stage3_ip6_config_start (NMDevice *device,
NMDeviceStateReason *reason)
{
NMConnection *connection;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip6;
const char *method = NM_SETTING_IP6_CONFIG_METHOD_AUTO;
connection = nm_device_get_connection (device);
g_assert (connection);
s_ip6 = nm_connection_get_setting_ip6_config (connection);
if (s_ip6)
- method = nm_setting_ip6_config_get_method (s_ip6);
+ method = nm_setting_ip_config_get_method (s_ip6);
/* Indicate that a critical protocol is about to start */
if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0 ||
@@ -2938,7 +2938,7 @@ static NMActStageReturn
act_stage4_ip4_config_timeout (NMDevice *device, NMDeviceStateReason *reason)
{
NMConnection *connection;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
gboolean may_fail = FALSE, chain_up = FALSE;
NMActStageReturn ret;
@@ -2946,7 +2946,7 @@ act_stage4_ip4_config_timeout (NMDevice *device, NMDeviceStateReason *reason)
g_assert (connection);
s_ip4 = nm_connection_get_setting_ip4_config (connection);
- may_fail = nm_setting_ip4_config_get_may_fail (s_ip4);
+ may_fail = nm_setting_ip_config_get_may_fail (s_ip4);
ret = handle_ip_config_timeout (NM_DEVICE_WIFI (device), connection, may_fail, &chain_up, reason);
if (chain_up)
@@ -2959,7 +2959,7 @@ static NMActStageReturn
act_stage4_ip6_config_timeout (NMDevice *device, NMDeviceStateReason *reason)
{
NMConnection *connection;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip6;
gboolean may_fail = FALSE, chain_up = FALSE;
NMActStageReturn ret;
@@ -2967,7 +2967,7 @@ act_stage4_ip6_config_timeout (NMDevice *device, NMDeviceStateReason *reason)
g_assert (connection);
s_ip6 = nm_connection_get_setting_ip6_config (connection);
- may_fail = nm_setting_ip6_config_get_may_fail (s_ip6);
+ may_fail = nm_setting_ip_config_get_may_fail (s_ip6);
ret = handle_ip_config_timeout (NM_DEVICE_WIFI (device), connection, may_fail, &chain_up, reason);
if (chain_up)
diff --git a/src/devices/wwan/nm-modem-broadband.c b/src/devices/wwan/nm-modem-broadband.c
index e896cbc10a..cf61a077f4 100644
--- a/src/devices/wwan/nm-modem-broadband.c
+++ b/src/devices/wwan/nm-modem-broadband.c
@@ -20,6 +20,7 @@
#include <glib/gi18n.h>
#include <string.h>
+#include <arpa/inet.h>
#include <libmm-glib.h>
#include "nm-modem-broadband.h"
diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c
index 431dc05c0b..ba01d5ca46 100644
--- a/src/devices/wwan/nm-modem.c
+++ b/src/devices/wwan/nm-modem.c
@@ -235,26 +235,25 @@ nm_modem_get_connection_ip_type (NMModem *self,
GError **error)
{
NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self);
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4, *s_ip6;
const char *method;
gboolean ip4 = TRUE, ip6 = TRUE;
gboolean ip4_may_fail = TRUE, ip6_may_fail = TRUE;
s_ip4 = nm_connection_get_setting_ip4_config (connection);
if (s_ip4) {
- method = nm_setting_ip4_config_get_method (s_ip4);
+ method = nm_setting_ip_config_get_method (s_ip4);
if (g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0)
ip4 = FALSE;
- ip4_may_fail = nm_setting_ip4_config_get_may_fail (s_ip4);
+ ip4_may_fail = nm_setting_ip_config_get_may_fail (s_ip4);
}
s_ip6 = nm_connection_get_setting_ip6_config (connection);
if (s_ip6) {
- method = nm_setting_ip6_config_get_method (s_ip6);
+ method = nm_setting_ip_config_get_method (s_ip6);
if (g_strcmp0 (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE) == 0)
ip6 = FALSE;
- ip6_may_fail = nm_setting_ip6_config_get_may_fail (s_ip6);
+ ip6_may_fail = nm_setting_ip_config_get_may_fail (s_ip6);
}
if (ip4 && !ip6) {
diff --git a/src/dhcp-manager/nm-dhcp-client.c b/src/dhcp-manager/nm-dhcp-client.c
index 085f7f3655..28959da3df 100644
--- a/src/dhcp-manager/nm-dhcp-client.c
+++ b/src/dhcp-manager/nm-dhcp-client.c
@@ -42,9 +42,11 @@ typedef struct {
GByteArray * hwaddr;
gboolean ipv6;
char * uuid;
- guint priority;
+ guint32 priority;
guint32 timeout;
GByteArray * duid;
+ GBytes * client_id;
+ char * hostname;
NMDhcpState state;
pid_t pid;
@@ -143,6 +145,37 @@ nm_dhcp_client_get_priority (NMDhcpClient *self)
return NM_DHCP_CLIENT_GET_PRIVATE (self)->priority;
}
+GBytes *
+nm_dhcp_client_get_client_id (NMDhcpClient *self)
+{
+ g_return_val_if_fail (NM_IS_DHCP_CLIENT (self), NULL);
+
+ return NM_DHCP_CLIENT_GET_PRIVATE (self)->client_id;
+}
+
+void
+nm_dhcp_client_set_client_id (NMDhcpClient *self, GBytes *client_id)
+{
+ NMDhcpClientPrivate *priv;
+
+ g_return_if_fail (NM_IS_DHCP_CLIENT (self));
+
+ priv = NM_DHCP_CLIENT_GET_PRIVATE (self);
+
+ if (priv->client_id && client_id && g_bytes_equal (priv->client_id, client_id))
+ return;
+ g_clear_pointer (&priv->client_id, g_bytes_unref);
+ priv->client_id = client_id ? g_bytes_ref (client_id) : NULL;
+}
+
+const char *
+nm_dhcp_client_get_hostname (NMDhcpClient *self)
+{
+ g_return_val_if_fail (NM_IS_DHCP_CLIENT (self), NULL);
+
+ return NM_DHCP_CLIENT_GET_PRIVATE (self)->hostname;
+}
+
/********************************************/
static const char *state_table[NM_DHCP_STATE_MAX + 1] = {
@@ -360,7 +393,8 @@ gboolean
nm_dhcp_client_start_ip4 (NMDhcpClient *self,
const char *dhcp_client_id,
const char *dhcp_anycast_addr,
- const char *hostname)
+ const char *hostname,
+ const char *last_ip4_address)
{
NMDhcpClientPrivate *priv;
@@ -374,7 +408,12 @@ nm_dhcp_client_start_ip4 (NMDhcpClient *self,
nm_log_info (LOGD_DHCP, "Activation (%s) Beginning DHCPv4 transaction (timeout in %d seconds)",
priv->iface, priv->timeout);
- return NM_DHCP_CLIENT_GET_CLASS (self)->ip4_start (self, dhcp_client_id, dhcp_anycast_addr, hostname);
+ nm_dhcp_client_set_client_id (self, dhcp_client_id ? nm_dhcp_utils_client_id_string_to_bytes (dhcp_client_id) : NULL);
+
+ g_clear_pointer (&priv->hostname, g_free);
+ priv->hostname = g_strdup (hostname);
+
+ return NM_DHCP_CLIENT_GET_CLASS (self)->ip4_start (self, dhcp_anycast_addr, last_ip4_address);
}
/* uuid_parse does not work for machine-id, so we use our own converter */
@@ -518,6 +557,9 @@ nm_dhcp_client_start_ip6 (NMDhcpClient *self,
g_free (str);
}
+ g_clear_pointer (&priv->hostname, g_free);
+ priv->hostname = g_strdup (hostname);
+
priv->info_only = info_only;
nm_log_info (LOGD_DHCP, "Activation (%s) Beginning DHCPv6 transaction (timeout in %d seconds)",
@@ -525,7 +567,6 @@ nm_dhcp_client_start_ip6 (NMDhcpClient *self,
return NM_DHCP_CLIENT_GET_CLASS (self)->ip6_start (self,
dhcp_anycast_addr,
- hostname,
info_only,
privacy,
priv->duid);
@@ -673,10 +714,13 @@ copy_option (const char * key,
g_hash_table_insert (hash, g_strdup (key), str_value);
}
-void
-nm_dhcp_client_new_options (NMDhcpClient *self,
- GHashTable *options,
- const char *reason)
+gboolean
+nm_dhcp_client_handle_event (gpointer unused,
+ const char *iface,
+ gint pid,
+ GHashTable *options,
+ const char *reason,
+ NMDhcpClient *self)
{
NMDhcpClientPrivate *priv;
guint32 old_state;
@@ -684,11 +728,19 @@ nm_dhcp_client_new_options (NMDhcpClient *self,
GHashTable *str_options = NULL;
GObject *ip_config = NULL;
- g_return_if_fail (NM_IS_DHCP_CLIENT (self));
- g_return_if_fail (options != NULL);
- g_return_if_fail (reason != NULL);
+ g_return_val_if_fail (NM_IS_DHCP_CLIENT (self), FALSE);
+ g_return_val_if_fail (iface != NULL, FALSE);
+ g_return_val_if_fail (pid > 0, FALSE);
+ g_return_val_if_fail (options != NULL, FALSE);
+ g_return_val_if_fail (reason != NULL, FALSE);
priv = NM_DHCP_CLIENT_GET_PRIVATE (self);
+
+ if (g_strcmp0 (priv->iface, iface) != 0)
+ return FALSE;
+ if (priv->pid != pid)
+ return FALSE;
+
old_state = priv->state;
new_state = reason_to_state (priv->iface, reason);
@@ -719,6 +771,8 @@ nm_dhcp_client_new_options (NMDhcpClient *self,
if (str_options)
g_hash_table_destroy (str_options);
g_clear_object (&ip_config);
+
+ return TRUE;
}
/********************************************/
@@ -885,7 +939,7 @@ nm_dhcp_client_class_init (NMDhcpClientClass *client_class)
g_object_class_install_property
(object_class, PROP_PRIORITY,
g_param_spec_uint (NM_DHCP_CLIENT_PRIORITY, "", "",
- 0, G_MAXUINT, 0,
+ 0, G_MAXUINT32, 0,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
diff --git a/src/dhcp-manager/nm-dhcp-client.h b/src/dhcp-manager/nm-dhcp-client.h
index 89fe821db5..3329fe38f3 100644
--- a/src/dhcp-manager/nm-dhcp-client.h
+++ b/src/dhcp-manager/nm-dhcp-client.h
@@ -64,13 +64,11 @@ typedef struct {
/* Methods */
gboolean (*ip4_start) (NMDhcpClient *self,
- const char *dhcp_client_id,
const char *anycast_addr,
- const char *hostname);
+ const char *last_ip4_address);
gboolean (*ip6_start) (NMDhcpClient *self,
const char *anycast_addr,
- const char *hostname,
gboolean info_only,
NMSettingIP6ConfigPrivacy privacy,
const GByteArray *duid);
@@ -99,6 +97,17 @@ typedef struct {
GType nm_dhcp_client_get_type (void);
+typedef const char *(*NMDhcpClientGetPathFunc) (void);
+
+typedef GSList * (*NMDhcpClientGetLeaseConfigsFunc) (const char *iface,
+ const char *uuid,
+ gboolean ipv6);
+
+void _nm_dhcp_client_register (GType gtype,
+ const char *name,
+ NMDhcpClientGetPathFunc get_path_func,
+ NMDhcpClientGetLeaseConfigsFunc get_lease_configs_func);
+
pid_t nm_dhcp_client_get_pid (NMDhcpClient *self);
const char *nm_dhcp_client_get_iface (NMDhcpClient *self);
@@ -115,10 +124,15 @@ const GByteArray *nm_dhcp_client_get_hw_addr (NMDhcpClient *self);
guint32 nm_dhcp_client_get_priority (NMDhcpClient *self);
+GBytes *nm_dhcp_client_get_client_id (NMDhcpClient *self);
+
+const char *nm_dhcp_client_get_hostname (NMDhcpClient *self);
+
gboolean nm_dhcp_client_start_ip4 (NMDhcpClient *self,
const char *dhcp_client_id,
const char *dhcp_anycast_addr,
- const char *hostname);
+ const char *hostname,
+ const char *last_ip4_address);
gboolean nm_dhcp_client_start_ip6 (NMDhcpClient *self,
const char *dhcp_anycast_addr,
@@ -128,10 +142,6 @@ gboolean nm_dhcp_client_start_ip6 (NMDhcpClient *self,
void nm_dhcp_client_stop (NMDhcpClient *self, gboolean release);
-void nm_dhcp_client_new_options (NMDhcpClient *self,
- GHashTable *options,
- const char *reason);
-
/* Backend helpers for subclasses */
void nm_dhcp_client_stop_existing (const char *pid_file, const char *binary_name);
@@ -144,5 +154,14 @@ void nm_dhcp_client_set_state (NMDhcpClient *self,
GObject *ip_config, /* NMIP4Config or NMIP6Config */
GHashTable *options); /* str:str hash */
+gboolean nm_dhcp_client_handle_event (gpointer unused,
+ const char *iface,
+ gint pid,
+ GHashTable *options,
+ const char *reason,
+ NMDhcpClient *self);
+
+void nm_dhcp_client_set_client_id (NMDhcpClient *self, GBytes *client_id);
+
#endif /* __NETWORKMANAGER_DHCP_CLIENT_H__ */
diff --git a/src/dhcp-manager/nm-dhcp-dhclient-utils.c b/src/dhcp-manager/nm-dhcp-dhclient-utils.c
index 2469076719..3c3c42c84a 100644
--- a/src/dhcp-manager/nm-dhcp-dhclient-utils.c
+++ b/src/dhcp-manager/nm-dhcp-dhclient-utils.c
@@ -23,16 +23,17 @@
#include <glib/gi18n.h>
#include <string.h>
#include <ctype.h>
+#include <arpa/inet.h>
#include "nm-dhcp-dhclient-utils.h"
+#include "nm-dhcp-utils.h"
#include "nm-ip4-config.h"
#include "nm-utils.h"
#include "nm-platform.h"
#include "NetworkManagerUtils.h"
+#include "gsystem-local-alloc.h"
#define CLIENTID_TAG "send dhcp-client-identifier"
-#define CLIENTID_FORMAT CLIENTID_TAG " \"%s\"; # added by NetworkManager"
-#define CLIENTID_FORMAT_OCTETS CLIENTID_TAG " %s; # added by NetworkManager"
#define HOSTNAME4_TAG "send host-name"
#define HOSTNAME4_FORMAT HOSTNAME4_TAG " \"%s\"; # added by NetworkManager"
@@ -72,40 +73,39 @@ add_hostname (GString *str, const char *format, const char *hostname)
}
static void
-add_ip4_config (GString *str, const char *dhcp_client_id, const char *hostname)
+add_ip4_config (GString *str, GBytes *client_id, const char *hostname)
{
- if (dhcp_client_id && *dhcp_client_id) {
- gboolean is_octets = TRUE;
- int i = 0;
+ if (client_id) {
+ const char *p;
+ gsize l;
+ guint i;
- while (dhcp_client_id[i]) {
- if (!g_ascii_isxdigit (dhcp_client_id[i])) {
- is_octets = FALSE;
- break;
- }
- i++;
- if (!dhcp_client_id[i])
- break;
- if (g_ascii_isxdigit (dhcp_client_id[i])) {
- i++;
- if (!dhcp_client_id[i])
- break;
- }
- if (dhcp_client_id[i] != ':') {
- is_octets = FALSE;
+ p = g_bytes_get_data (client_id, &l);
+ g_assert (p);
+
+ /* Allow type 0 (non-hardware address) to be represented as a string
+ * as long as all the characters are printable.
+ */
+ for (i = 1; (p[0] == 0) && i < l; i++) {
+ if (!g_ascii_isprint (p[i]))
break;
- }
- i++;
}
- /* If the client ID is just hex digits and : then don't use quotes,
- * because dhclient expects either a quoted ASCII string, or a byte
- * array formated as hex octets separated by :
- */
- if (is_octets)
- g_string_append_printf (str, CLIENTID_FORMAT_OCTETS "\n", dhcp_client_id);
- else
- g_string_append_printf (str, CLIENTID_FORMAT "\n", dhcp_client_id);
+ g_string_append (str, CLIENTID_TAG " ");
+ if (i < l) {
+ /* Unprintable; convert to a hex string */
+ for (i = 0; i < l; i++) {
+ if (i > 0)
+ g_string_append_c (str, ':');
+ g_string_append_printf (str, "%02x", (guint8) p[i]);
+ }
+ } else {
+ /* Printable; just add to the line minus the 'type' */
+ g_string_append_c (str, '"');
+ g_string_append_len (str, p + 1, l - 1);
+ g_string_append_c (str, '"');
+ }
+ g_string_append (str, "; # added by NetworkManager\n");
}
add_hostname (str, HOSTNAME4_FORMAT "\n", hostname);
@@ -133,14 +133,67 @@ add_ip6_config (GString *str, const char *hostname)
"send fqdn.server-update on;\n");
}
+static GBytes *
+read_client_id (const char *str)
+{
+ gs_free char *s = NULL;
+ char *p;
+
+ g_assert (!strncmp (str, CLIENTID_TAG, STRLEN (CLIENTID_TAG)));
+
+ str += STRLEN (CLIENTID_TAG);
+ while (g_ascii_isspace (*str))
+ str++;
+
+ if (*str == '"') {
+ s = g_strdup (str + 1);
+ p = strrchr (s, '"');
+ if (p)
+ *p = '\0';
+ else
+ return NULL;
+ } else
+ s = g_strdup (str);
+
+ g_strchomp (s);
+ if (s[strlen (s) - 1] == ';')
+ s[strlen (s) - 1] = '\0';
+
+ return nm_dhcp_utils_client_id_string_to_bytes (s);
+}
+
+GBytes *
+nm_dhcp_dhclient_get_client_id_from_config_file (const char *path)
+{
+ gs_free char *contents = NULL;
+ gs_strfreev char **lines = NULL;
+ char **line;
+
+ g_return_val_if_fail (path != NULL, NULL);
+
+ if (!g_file_test (path, G_FILE_TEST_EXISTS))
+ return NULL;
+
+ if (!g_file_get_contents (path, &contents, NULL, NULL))
+ return NULL;
+
+ lines = g_strsplit_set (contents, "\n\r", 0);
+ for (line = lines; lines && *line; line++) {
+ if (!strncmp (*line, CLIENTID_TAG, STRLEN (CLIENTID_TAG)))
+ return read_client_id (*line);
+ }
+ return NULL;
+}
+
char *
nm_dhcp_dhclient_create_config (const char *interface,
gboolean is_ip6,
- const char *dhcp_client_id,
+ GBytes *client_id,
const char *anycast_addr,
const char *hostname,
const char *orig_path,
- const char *orig_contents)
+ const char *orig_contents,
+ GBytes **out_new_client_id)
{
GString *new_contents;
GPtrArray *alsoreq;
@@ -164,11 +217,15 @@ nm_dhcp_dhclient_create_config (const char *interface,
if (!strlen (g_strstrip (p)))
continue;
- /* Override config file "dhcp-client-id" and use one from the
- * connection.
- */
- if (dhcp_client_id && !strncmp (p, CLIENTID_TAG, strlen (CLIENTID_TAG)))
- continue;
+ if (!strncmp (p, CLIENTID_TAG, strlen (CLIENTID_TAG))) {
+ /* Override config file "dhcp-client-id" and use one from the connection */
+ if (client_id)
+ continue;
+
+ /* Otherwise capture and return the existing client id */
+ if (out_new_client_id)
+ *out_new_client_id = read_client_id (p);
+ }
/* Override config file hostname and use one from the connection */
if (hostname) {
@@ -237,7 +294,7 @@ nm_dhcp_dhclient_create_config (const char *interface,
add_also_request (alsoreq, "dhcp6.domain-search");
add_also_request (alsoreq, "dhcp6.client-id");
} else {
- add_ip4_config (new_contents, dhcp_client_id, hostname);
+ add_ip4_config (new_contents, client_id, hostname);
add_also_request (alsoreq, "rfc3442-classless-static-routes");
add_also_request (alsoreq, "ms-classless-static-routes");
add_also_request (alsoreq, "static-routes");
diff --git a/src/dhcp-manager/nm-dhcp-dhclient-utils.h b/src/dhcp-manager/nm-dhcp-dhclient-utils.h
index 3b786a65a6..a1828add4a 100644
--- a/src/dhcp-manager/nm-dhcp-dhclient-utils.h
+++ b/src/dhcp-manager/nm-dhcp-dhclient-utils.h
@@ -27,11 +27,12 @@
char *nm_dhcp_dhclient_create_config (const char *interface,
gboolean is_ip6,
- const char *dhcp_client_id,
+ GBytes *client_id,
const char *anycast_addr,
const char *hostname,
const char *orig_path,
- const char *orig_contents);
+ const char *orig_contents,
+ GBytes **out_new_client_id);
char *nm_dhcp_dhclient_escape_duid (const GByteArray *duid);
@@ -48,5 +49,7 @@ GSList *nm_dhcp_dhclient_read_lease_ip_configs (const char *iface,
gboolean ipv6,
GDateTime *now);
+GBytes *nm_dhcp_dhclient_get_client_id_from_config_file (const char *path);
+
#endif /* __NETWORKMANAGER_DHCP_DHCLIENT_UTILS_H__ */
diff --git a/src/dhcp-manager/nm-dhcp-dhclient.c b/src/dhcp-manager/nm-dhcp-dhclient.c
index e4b37377bc..4cabb2257b 100644
--- a/src/dhcp-manager/nm-dhcp-dhclient.c
+++ b/src/dhcp-manager/nm-dhcp-dhclient.c
@@ -43,6 +43,8 @@
#include "nm-dhcp-manager.h"
#include "nm-posix-signals.h"
#include "NetworkManagerUtils.h"
+#include "nm-dhcp-listener.h"
+#include "gsystem-local-alloc.h"
G_DEFINE_TYPE (NMDhcpDhclient, nm_dhcp_dhclient, NM_TYPE_DHCP_CLIENT)
@@ -55,7 +57,7 @@ typedef struct {
char *pid_file;
} NMDhcpDhclientPrivate;
-const char *
+static const char *
nm_dhcp_dhclient_get_path (void)
{
const char *path = NULL;
@@ -122,7 +124,7 @@ get_dhclient_leasefile (const char *iface,
return NULL;
}
-GSList *
+static GSList *
nm_dhcp_dhclient_get_lease_ip_configs (const char *iface,
const char *uuid,
gboolean ipv6)
@@ -151,10 +153,11 @@ static gboolean
merge_dhclient_config (const char *iface,
const char *conf_file,
gboolean is_ip6,
- const char *dhcp_client_id,
+ GBytes *client_id,
const char *anycast_addr,
const char *hostname,
const char *orig_path,
+ GBytes **out_new_client_id,
GError **error)
{
char *orig = NULL, *new;
@@ -173,7 +176,7 @@ merge_dhclient_config (const char *iface,
}
}
- new = nm_dhcp_dhclient_create_config (iface, is_ip6, dhcp_client_id, anycast_addr, hostname, orig_path, orig);
+ new = nm_dhcp_dhclient_create_config (iface, is_ip6, client_id, anycast_addr, hostname, orig_path, orig, out_new_client_id);
g_assert (new);
success = g_file_set_contents (conf_file, new, -1, error);
g_free (new);
@@ -257,9 +260,10 @@ static char *
create_dhclient_config (const char *iface,
gboolean is_ip6,
const char *uuid,
- const char *dhcp_client_id,
+ GBytes *client_id,
const char *dhcp_anycast_addr,
- const char *hostname)
+ const char *hostname,
+ GBytes **out_new_client_id)
{
char *orig = NULL, *new = NULL;
GError *error = NULL;
@@ -284,7 +288,7 @@ create_dhclient_config (const char *iface,
}
error = NULL;
- success = merge_dhclient_config (iface, new, is_ip6, dhcp_client_id, dhcp_anycast_addr, hostname, orig, &error);
+ success = merge_dhclient_config (iface, new, is_ip6, client_id, dhcp_anycast_addr, hostname, orig, out_new_client_id, &error);
if (!success) {
nm_log_warn (LOGD_DHCP, "(%s): error creating dhclient%s configuration: %s",
iface, is_ip6 ? "6" : "", error->message);
@@ -473,41 +477,45 @@ dhclient_start (NMDhcpClient *client,
}
static gboolean
-ip4_start (NMDhcpClient *client,
- const char *dhcp_client_id,
- const char *dhcp_anycast_addr,
- const char *hostname)
+ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last_ip4_address)
{
NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE (client);
- const char *iface, *uuid;
+ GBytes *client_id;
+ gs_unref_bytes GBytes *new_client_id = NULL;
+ const char *iface, *uuid, *hostname;
+ gboolean success = FALSE;
iface = nm_dhcp_client_get_iface (client);
uuid = nm_dhcp_client_get_uuid (client);
+ client_id = nm_dhcp_client_get_client_id (client);
+ hostname = nm_dhcp_client_get_hostname (client);
- priv->conf_file = create_dhclient_config (iface, FALSE, uuid, dhcp_client_id, dhcp_anycast_addr, hostname);
- if (!priv->conf_file) {
+ priv->conf_file = create_dhclient_config (iface, FALSE, uuid, client_id, dhcp_anycast_addr, hostname, &new_client_id);
+ if (priv->conf_file) {
+ if (new_client_id)
+ nm_dhcp_client_set_client_id (client, new_client_id);
+ success = dhclient_start (client, NULL, NULL, FALSE, NULL);
+ } else
nm_log_warn (LOGD_DHCP4, "(%s): error creating dhclient configuration file.", iface);
- return FALSE;
- }
- return dhclient_start (client, NULL, NULL, FALSE, NULL);
+ return success;
}
static gboolean
ip6_start (NMDhcpClient *client,
const char *dhcp_anycast_addr,
- const char *hostname,
gboolean info_only,
NMSettingIP6ConfigPrivacy privacy,
const GByteArray *duid)
{
NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE (client);
- const char *iface, *uuid;
+ const char *iface, *uuid, *hostname;
iface = nm_dhcp_client_get_iface (client);
uuid = nm_dhcp_client_get_uuid (client);
+ hostname = nm_dhcp_client_get_hostname (client);
- priv->conf_file = create_dhclient_config (iface, TRUE, uuid, NULL, dhcp_anycast_addr, hostname);
+ priv->conf_file = create_dhclient_config (iface, TRUE, uuid, NULL, dhcp_anycast_addr, hostname, NULL);
if (!priv->conf_file) {
nm_log_warn (LOGD_DHCP6, "(%s): error creating dhclient6 configuration file.", iface);
return FALSE;
@@ -544,6 +552,24 @@ stop (NMDhcpClient *client, gboolean release, const GByteArray *duid)
}
}
+static void
+state_changed (NMDhcpClient *client,
+ NMDhcpState state,
+ GObject *ip_config,
+ GHashTable *options)
+{
+ NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE (client);
+ gs_unref_bytes GBytes *client_id = NULL;
+
+ if (nm_dhcp_client_get_client_id (client))
+ return;
+ if (state != NM_DHCP_STATE_BOUND)
+ return;
+
+ client_id = nm_dhcp_dhclient_get_client_id_from_config_file (priv->conf_file);
+ nm_dhcp_client_set_client_id (client, client_id);
+}
+
static GByteArray *
get_duid (NMDhcpClient *client)
{
@@ -612,6 +638,11 @@ nm_dhcp_dhclient_init (NMDhcpDhclient *self)
/* Fallback option */
if (!priv->def_leasefile)
priv->def_leasefile = SYSCONFDIR "/dhclient6.leases";
+
+ g_signal_connect (nm_dhcp_listener_get (),
+ NM_DHCP_LISTENER_EVENT,
+ G_CALLBACK (nm_dhcp_client_handle_event),
+ self);
}
static void
@@ -619,6 +650,10 @@ dispose (GObject *object)
{
NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE (object);
+ g_signal_handlers_disconnect_by_func (nm_dhcp_listener_get (),
+ G_CALLBACK (nm_dhcp_client_handle_event),
+ NM_DHCP_DHCLIENT (object));
+
g_free (priv->pid_file);
g_free (priv->conf_file);
g_free (priv->lease_file);
@@ -641,5 +676,16 @@ nm_dhcp_dhclient_class_init (NMDhcpDhclientClass *dhclient_class)
client_class->ip6_start = ip6_start;
client_class->stop = stop;
client_class->get_duid = get_duid;
+ client_class->state_changed = state_changed;
+}
+
+static void __attribute__((constructor))
+register_dhcp_dhclient (void)
+{
+ g_type_init ();
+ _nm_dhcp_client_register (NM_TYPE_DHCP_DHCLIENT,
+ "dhclient",
+ nm_dhcp_dhclient_get_path,
+ nm_dhcp_dhclient_get_lease_ip_configs);
}
diff --git a/src/dhcp-manager/nm-dhcp-dhclient.h b/src/dhcp-manager/nm-dhcp-dhclient.h
index 6c58826241..5abcc08ee3 100644
--- a/src/dhcp-manager/nm-dhcp-dhclient.h
+++ b/src/dhcp-manager/nm-dhcp-dhclient.h
@@ -41,11 +41,5 @@ typedef struct {
GType nm_dhcp_dhclient_get_type (void);
-GSList *nm_dhcp_dhclient_get_lease_ip_configs (const char *iface,
- const char *uuid,
- gboolean ipv6);
-
-const char *nm_dhcp_dhclient_get_path (void);
-
#endif /* __NETWORKMANAGER_DHCP_DHCLIENT_H__ */
diff --git a/src/dhcp-manager/nm-dhcp-dhcpcd.c b/src/dhcp-manager/nm-dhcp-dhcpcd.c
index a018c4cd42..9aacba7667 100644
--- a/src/dhcp-manager/nm-dhcp-dhcpcd.c
+++ b/src/dhcp-manager/nm-dhcp-dhcpcd.c
@@ -38,6 +38,7 @@
#include "nm-logging.h"
#include "nm-posix-signals.h"
#include "NetworkManagerUtils.h"
+#include "nm-dhcp-listener.h"
G_DEFINE_TYPE (NMDhcpDhcpcd, nm_dhcp_dhcpcd, NM_TYPE_DHCP_CLIENT)
@@ -47,7 +48,7 @@ typedef struct {
char *pid_file;
} NMDhcpDhcpcdPrivate;
-const char *
+static const char *
nm_dhcp_dhcpcd_get_path (void)
{
const char *path = NULL;
@@ -72,17 +73,14 @@ dhcpcd_child_setup (gpointer user_data G_GNUC_UNUSED)
}
static gboolean
-ip4_start (NMDhcpClient *client,
- const char *dhcp_client_id,
- const char *dhcp_anycast_addr,
- const char *hostname)
+ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last_ip4_address)
{
NMDhcpDhcpcdPrivate *priv = NM_DHCP_DHCPCD_GET_PRIVATE (client);
GPtrArray *argv = NULL;
pid_t pid = -1;
GError *error = NULL;
char *pid_contents = NULL, *binary_name, *cmd_str;
- const char *iface, *dhcpcd_path = NULL;
+ const char *iface, *dhcpcd_path, *hostname;
g_return_val_if_fail (priv->pid_file == NULL, FALSE);
@@ -129,7 +127,8 @@ ip4_start (NMDhcpClient *client,
g_ptr_array_add (argv, (gpointer) "-4");
#endif
- if (hostname && strlen (hostname)) {
+ hostname = nm_dhcp_client_get_hostname (client);
+ if (hostname) {
g_ptr_array_add (argv, (gpointer) "-h"); /* Send hostname to DHCP server */
g_ptr_array_add (argv, (gpointer) hostname );
}
@@ -160,7 +159,6 @@ ip4_start (NMDhcpClient *client,
static gboolean
ip6_start (NMDhcpClient *client,
const char *dhcp_anycast_addr,
- const char *hostname,
gboolean info_only,
NMSettingIP6ConfigPrivacy privacy,
const GByteArray *duid)
@@ -190,6 +188,10 @@ stop (NMDhcpClient *client, gboolean release, const GByteArray *duid)
static void
nm_dhcp_dhcpcd_init (NMDhcpDhcpcd *self)
{
+ g_signal_connect (nm_dhcp_listener_get (),
+ NM_DHCP_LISTENER_EVENT,
+ G_CALLBACK (nm_dhcp_client_handle_event),
+ self);
}
static void
@@ -197,6 +199,10 @@ dispose (GObject *object)
{
NMDhcpDhcpcdPrivate *priv = NM_DHCP_DHCPCD_GET_PRIVATE (object);
+ g_signal_handlers_disconnect_by_func (nm_dhcp_listener_get (),
+ G_CALLBACK (nm_dhcp_client_handle_event),
+ NM_DHCP_DHCPCD (object));
+
g_free (priv->pid_file);
G_OBJECT_CLASS (nm_dhcp_dhcpcd_parent_class)->dispose (object);
@@ -218,3 +224,13 @@ nm_dhcp_dhcpcd_class_init (NMDhcpDhcpcdClass *dhcpcd_class)
client_class->stop = stop;
}
+static void __attribute__((constructor))
+register_dhcp_dhclient (void)
+{
+ g_type_init ();
+ _nm_dhcp_client_register (NM_TYPE_DHCP_DHCPCD,
+ "dhcpcd",
+ nm_dhcp_dhcpcd_get_path,
+ NULL);
+}
+
diff --git a/src/dhcp-manager/nm-dhcp-dhcpcd.h b/src/dhcp-manager/nm-dhcp-dhcpcd.h
index 4e3502ab5a..deed70e0f9 100644
--- a/src/dhcp-manager/nm-dhcp-dhcpcd.h
+++ b/src/dhcp-manager/nm-dhcp-dhcpcd.h
@@ -41,7 +41,5 @@ typedef struct {
GType nm_dhcp_dhcpcd_get_type (void);
-const char *nm_dhcp_dhcpcd_get_path (void);
-
#endif /* __NETWORKMANAGER_DHCP_DHCPCD_H__ */
diff --git a/src/dhcp-manager/nm-dhcp-listener.c b/src/dhcp-manager/nm-dhcp-listener.c
new file mode 100644
index 0000000000..07c153e72a
--- /dev/null
+++ b/src/dhcp-manager/nm-dhcp-listener.c
@@ -0,0 +1,289 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2014 Red Hat, Inc.
+ *
+ */
+
+#include <config.h>
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <dbus/dbus.h>
+#include <sys/socket.h>
+#include <sys/wait.h>
+#include <signal.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include "nm-dhcp-listener.h"
+#include "nm-logging.h"
+#include "nm-dbus-manager.h"
+#include "nm-dbus-glib-types.h"
+#include "nm-glib-compat.h"
+#include "NetworkManagerUtils.h"
+
+#define NM_DHCP_CLIENT_DBUS_IFACE "org.freedesktop.nm_dhcp_client"
+#define PRIV_SOCK_PATH NMRUNDIR "/private-dhcp"
+#define PRIV_SOCK_TAG "dhcp"
+
+typedef struct {
+ NMDBusManager * dbus_mgr;
+ guint new_conn_id;
+ guint dis_conn_id;
+ GHashTable * proxies;
+ DBusGProxy * proxy;
+} NMDhcpListenerPrivate;
+
+#define NM_DHCP_LISTENER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP_LISTENER, NMDhcpListenerPrivate))
+
+G_DEFINE_TYPE (NMDhcpListener, nm_dhcp_listener, G_TYPE_OBJECT)
+
+enum {
+ EVENT,
+ LAST_SIGNAL
+};
+static guint signals[LAST_SIGNAL] = { 0 };
+
+/***************************************************/
+
+static char *
+garray_to_string (GArray *array, const char *key)
+{
+ GString *str;
+ int i;
+ unsigned char c;
+ char *converted = NULL;
+
+ g_return_val_if_fail (array != NULL, NULL);
+
+ /* Since the DHCP options come through environment variables, they should
+ * already be UTF-8 safe, but just make sure.
+ */
+ str = g_string_sized_new (array->len);
+ for (i = 0; i < array->len; i++) {
+ c = array->data[i];
+
+ /* Convert NULLs to spaces and non-ASCII characters to ? */
+ if (c == '\0')
+ c = ' ';
+ else if (c > 127)
+ c = '?';
+ str = g_string_append_c (str, c);
+ }
+ str = g_string_append_c (str, '\0');
+
+ converted = str->str;
+ if (!g_utf8_validate (converted, -1, NULL))
+ nm_log_warn (LOGD_DHCP, "DHCP option '%s' couldn't be converted to UTF-8", key);
+ g_string_free (str, FALSE);
+ return converted;
+}
+
+static char *
+get_option (GHashTable *hash, const char *key)
+{
+ GValue *value;
+
+ value = g_hash_table_lookup (hash, key);
+ if (value == NULL)
+ return NULL;
+
+ if (G_VALUE_TYPE (value) != DBUS_TYPE_G_UCHAR_ARRAY) {
+ nm_log_warn (LOGD_DHCP, "unexpected key %s value type was not "
+ "DBUS_TYPE_G_UCHAR_ARRAY",
+ (char *) key);
+ return NULL;
+ }
+
+ return garray_to_string ((GArray *) g_value_get_boxed (value), key);
+}
+
+static void
+handle_event (DBusGProxy *proxy,
+ GHashTable *options,
+ gpointer user_data)
+{
+ NMDhcpListener *self = NM_DHCP_LISTENER (user_data);
+ char *iface = NULL;
+ char *pid_str = NULL;
+ char *reason = NULL;
+ gint pid;
+ gboolean handled = FALSE;
+
+ iface = get_option (options, "interface");
+ if (iface == NULL) {
+ nm_log_warn (LOGD_DHCP, "DHCP event: didn't have associated interface.");
+ goto out;
+ }
+
+ pid_str = get_option (options, "pid");
+ pid = nm_utils_ascii_str_to_int64 (pid_str, 10, 0, G_MAXINT32, -1);
+ if (pid == -1) {
+ nm_log_warn (LOGD_DHCP, "DHCP event: couldn't convert PID '%s' to an integer", pid_str ? pid_str : "(null)");
+ goto out;
+ }
+
+ reason = get_option (options, "reason");
+ if (reason == NULL) {
+ nm_log_warn (LOGD_DHCP, "(pid %d) DHCP event didn't have a reason", pid);
+ goto out;
+ }
+
+ g_signal_emit (self, signals[EVENT], 0, iface, pid, options, reason, &handled);
+ if (!handled) {
+ if (g_ascii_strcasecmp (reason, "RELEASE") == 0) {
+ /* Ignore event when the dhcp client gets killed and we receive its last message */
+ nm_log_dbg (LOGD_DHCP, "(pid %d) unhandled RELEASE DHCP event for interface %s", pid, iface);
+ } else
+ nm_log_warn (LOGD_DHCP, "(pid %d) unhandled DHCP event for interface %s", pid, iface);
+ }
+
+out:
+ g_free (iface);
+ g_free (pid_str);
+ g_free (reason);
+}
+
+#if HAVE_DBUS_GLIB_100
+static void
+new_connection_cb (NMDBusManager *mgr,
+ DBusGConnection *connection,
+ NMDhcpListener *self)
+{
+ DBusGProxy *proxy;
+
+ /* Create a new proxy for the client */
+ proxy = dbus_g_proxy_new_for_peer (connection, "/", NM_DHCP_CLIENT_DBUS_IFACE);
+ dbus_g_proxy_add_signal (proxy, "Event", DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_INVALID);
+ dbus_g_proxy_connect_signal (proxy, "Event", G_CALLBACK (handle_event), self, NULL);
+
+ g_hash_table_insert (NM_DHCP_LISTENER_GET_PRIVATE (self)->proxies, connection, proxy);
+}
+
+static void
+dis_connection_cb (NMDBusManager *mgr,
+ DBusGConnection *connection,
+ NMDhcpListener *self)
+{
+ NMDhcpListenerPrivate *priv = NM_DHCP_LISTENER_GET_PRIVATE (self);
+ DBusGProxy *proxy;
+
+ proxy = g_hash_table_lookup (priv->proxies, connection);
+ if (proxy) {
+ dbus_g_proxy_disconnect_signal (proxy, "Event", G_CALLBACK (handle_event), self);
+ g_hash_table_remove (priv->proxies, connection);
+ }
+}
+#endif
+
+/***************************************************/
+
+NMDhcpListener *
+nm_dhcp_listener_get (void)
+{
+ static NMDhcpListener *singleton = NULL;
+
+ if (G_UNLIKELY (singleton == NULL))
+ singleton = g_object_new (NM_TYPE_DHCP_LISTENER, NULL);
+ g_assert (singleton);
+ return singleton;
+}
+
+static void
+nm_dhcp_listener_init (NMDhcpListener *self)
+{
+ NMDhcpListenerPrivate *priv = NM_DHCP_LISTENER_GET_PRIVATE (self);
+#if !HAVE_DBUS_GLIB_100
+ DBusGConnection *g_connection;
+#endif
+
+ /* Maps DBusGConnection :: DBusGProxy */
+ priv->proxies = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref);
+
+ priv->dbus_mgr = nm_dbus_manager_get ();
+
+#if HAVE_DBUS_GLIB_100
+ /* Register the socket our DHCP clients will return lease info on */
+ nm_dbus_manager_private_server_register (priv->dbus_mgr, PRIV_SOCK_PATH, PRIV_SOCK_TAG);
+ priv->new_conn_id = g_signal_connect (priv->dbus_mgr,
+ NM_DBUS_MANAGER_PRIVATE_CONNECTION_NEW "::" PRIV_SOCK_TAG,
+ G_CALLBACK (new_connection_cb),
+ self);
+ priv->dis_conn_id = g_signal_connect (priv->dbus_mgr,
+ NM_DBUS_MANAGER_PRIVATE_CONNECTION_DISCONNECTED "::" PRIV_SOCK_TAG,
+ G_CALLBACK (dis_connection_cb),
+ self);
+#else
+ g_connection = nm_dbus_manager_get_connection (priv->dbus_mgr);
+ priv->proxy = dbus_g_proxy_new_for_name (g_connection,
+ "org.freedesktop.nm_dhcp_client",
+ "/",
+ NM_DHCP_CLIENT_DBUS_IFACE);
+ g_assert (priv->proxy);
+ dbus_g_proxy_add_signal (priv->proxy, "Event", DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_INVALID);
+ dbus_g_proxy_connect_signal (priv->proxy, "Event", G_CALLBACK (handle_event), self, NULL);
+#endif
+}
+
+static void
+dispose (GObject *object)
+{
+ NMDhcpListenerPrivate *priv = NM_DHCP_LISTENER_GET_PRIVATE (object);
+
+ if (priv->new_conn_id) {
+ g_signal_handler_disconnect (priv->dbus_mgr, priv->new_conn_id);
+ priv->new_conn_id = 0;
+ }
+ if (priv->dis_conn_id) {
+ g_signal_handler_disconnect (priv->dbus_mgr, priv->dis_conn_id);
+ priv->dis_conn_id = 0;
+ }
+ priv->dbus_mgr = NULL;
+
+ if (priv->proxies) {
+ g_hash_table_destroy (priv->proxies);
+ priv->proxies = NULL;
+ }
+ g_clear_object (&priv->proxy);
+
+ G_OBJECT_CLASS (nm_dhcp_listener_parent_class)->dispose (object);
+}
+
+static void
+nm_dhcp_listener_class_init (NMDhcpListenerClass *listener_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (listener_class);
+
+ g_type_class_add_private (listener_class, sizeof (NMDhcpListenerPrivate));
+
+ /* virtual methods */
+ object_class->dispose = dispose;
+
+ /* signals */
+ signals[EVENT] =
+ g_signal_new (NM_DHCP_LISTENER_EVENT,
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST, 0,
+ g_signal_accumulator_true_handled,
+ NULL, NULL,
+ G_TYPE_BOOLEAN, /* listeners return TRUE if handled */
+ 4,
+ G_TYPE_STRING, /* iface */
+ G_TYPE_INT, /* pid */
+ G_TYPE_HASH_TABLE, /* options */
+ G_TYPE_STRING); /* reason */
+}
diff --git a/src/dhcp-manager/nm-dhcp-listener.h b/src/dhcp-manager/nm-dhcp-listener.h
new file mode 100644
index 0000000000..15ec053109
--- /dev/null
+++ b/src/dhcp-manager/nm-dhcp-listener.h
@@ -0,0 +1,39 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2014 Red Hat, Inc.
+ */
+
+#ifndef __NETWORKMANAGER_DHCP_LISTENER_H__
+#define __NETWORKMANAGER_DHCP_LISTENER_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+#define NM_TYPE_DHCP_LISTENER (nm_dhcp_listener_get_type ())
+#define NM_DHCP_LISTENER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DHCP_LISTENER, NMDhcpListener))
+#define NM_IS_DHCP_LISTENER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DHCP_LISTENER))
+#define NM_DHCP_LISTENER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DHCP_LISTENER, NMDhcpListenerClass))
+
+#define NM_DHCP_LISTENER_EVENT "event"
+
+typedef GObject NMDhcpListener;
+typedef GObjectClass NMDhcpListenerClass;
+
+GType nm_dhcp_listener_get_type (void);
+
+NMDhcpListener *nm_dhcp_listener_get (void);
+
+#endif /* __NETWORKMANAGER_DHCP_LISTENER_H__ */
diff --git a/src/dhcp-manager/nm-dhcp-manager.c b/src/dhcp-manager/nm-dhcp-manager.c
index b19590a69b..419bdafbcb 100644
--- a/src/dhcp-manager/nm-dhcp-manager.c
+++ b/src/dhcp-manager/nm-dhcp-manager.c
@@ -23,7 +23,6 @@
#include "config.h"
#include <glib.h>
#include <glib/gi18n.h>
-#include <dbus/dbus.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <signal.h>
@@ -37,20 +36,15 @@
#include "nm-dhcp-manager.h"
#include "nm-dhcp-dhclient.h"
#include "nm-dhcp-dhcpcd.h"
+#include "nm-dhcp-systemd.h"
#include "nm-logging.h"
-#include "nm-dbus-manager.h"
#include "nm-config.h"
#include "nm-dbus-glib-types.h"
#include "nm-glib-compat.h"
#include "NetworkManagerUtils.h"
-#define NM_DHCP_CLIENT_DBUS_IFACE "org.freedesktop.nm_dhcp_client"
-
#define DHCP_TIMEOUT 45 /* default DHCP timeout, in seconds */
-#define PRIV_SOCK_PATH NMRUNDIR "/private-dhcp"
-#define PRIV_SOCK_TAG "dhcp"
-
/* default to installed helper, but can be modified for testing */
const char *nm_dhcp_helper_path = LIBEXECDIR "/nm-dhcp-helper";
@@ -58,78 +52,87 @@ typedef GSList * (*GetLeaseConfigFunc) (const char *iface, const char *uuid, gbo
typedef struct {
GType client_type;
- GetLeaseConfigFunc get_lease_ip_configs_func;
-
- NMDBusManager * dbus_mgr;
- guint new_conn_id;
- guint dis_conn_id;
- GHashTable * proxies;
-
GHashTable * clients;
- DBusGProxy * proxy;
char * default_hostname;
} NMDhcpManagerPrivate;
-
#define NM_DHCP_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP_MANAGER, NMDhcpManagerPrivate))
G_DEFINE_TYPE (NMDhcpManager, nm_dhcp_manager, G_TYPE_OBJECT)
-static char *
-garray_to_string (GArray *array, const char *key)
+/***************************************************/
+
+typedef struct {
+ GType gtype;
+ const char *name;
+ NMDhcpClientGetPathFunc get_path_func;
+ NMDhcpClientGetLeaseConfigsFunc get_lease_configs_func;
+} ClientDesc;
+
+static GSList *client_descs = NULL;
+
+void
+_nm_dhcp_client_register (GType gtype,
+ const char *name,
+ NMDhcpClientGetPathFunc get_path_func,
+ NMDhcpClientGetLeaseConfigsFunc get_lease_configs_func)
{
- GString *str;
- int i;
- unsigned char c;
- char *converted = NULL;
+ ClientDesc *desc;
+ GSList *iter;
- g_return_val_if_fail (array != NULL, NULL);
+ g_return_if_fail (gtype != G_TYPE_INVALID);
+ g_return_if_fail (name != NULL);
- /* Since the DHCP options come through environment variables, they should
- * already be UTF-8 safe, but just make sure.
- */
- str = g_string_sized_new (array->len);
- for (i = 0; i < array->len; i++) {
- c = array->data[i];
-
- /* Convert NULLs to spaces and non-ASCII characters to ? */
- if (c == '\0')
- c = ' ';
- else if (c > 127)
- c = '?';
- str = g_string_append_c (str, c);
+ for (iter = client_descs; iter; iter = iter->next) {
+ desc = iter->data;
+ g_return_if_fail (desc->gtype != gtype);
+ g_return_if_fail (strcmp (desc->name, name) != 0);
}
- str = g_string_append_c (str, '\0');
- converted = str->str;
- if (!g_utf8_validate (converted, -1, NULL))
- nm_log_warn (LOGD_DHCP, "DHCP option '%s' couldn't be converted to UTF-8", key);
- g_string_free (str, FALSE);
- return converted;
+ desc = g_slice_new0 (ClientDesc);
+ desc->gtype = gtype;
+ desc->name = name;
+ desc->get_path_func = get_path_func;
+ desc->get_lease_configs_func = get_lease_configs_func;
+ client_descs = g_slist_prepend (client_descs, desc);
}
-static NMDhcpClient *
-get_client_for_pid (NMDhcpManager *manager, GPid pid)
+static ClientDesc *
+find_client_desc (const char *name, GType gtype)
{
- NMDhcpManagerPrivate *priv;
- GHashTableIter iter;
- gpointer value;
-
- g_return_val_if_fail (NM_IS_DHCP_MANAGER (manager), NULL);
+ GSList *iter;
- priv = NM_DHCP_MANAGER_GET_PRIVATE (manager);
+ g_return_val_if_fail (name || gtype, NULL);
- g_hash_table_iter_init (&iter, priv->clients);
- while (g_hash_table_iter_next (&iter, NULL, &value)) {
- NMDhcpClient *candidate = NM_DHCP_CLIENT (value);
+ for (iter = client_descs; iter; iter = iter->next) {
+ ClientDesc *desc = iter->data;
- if (nm_dhcp_client_get_pid (candidate) == pid)
- return candidate;
+ if (name && strcmp (desc->name, name) != 0)
+ continue;
+ if (gtype && desc->name != 0)
+ continue;
+ return desc;
}
-
return NULL;
}
+static GType
+is_client_enabled (const char *name, GError **error)
+{
+ ClientDesc *desc;
+
+ desc = find_client_desc (name, G_TYPE_INVALID);
+ if (desc && (!desc->get_path_func || desc->get_path_func()))
+ return desc->gtype;
+
+ g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED,
+ _("'%s' support not found or not enabled."),
+ name);
+ return G_TYPE_INVALID;
+}
+
+/***************************************************/
+
static NMDhcpClient *
get_client_for_ifindex (NMDhcpManager *manager, int ifindex, gboolean ip6)
{
@@ -154,169 +157,26 @@ get_client_for_ifindex (NMDhcpManager *manager, int ifindex, gboolean ip6)
return NULL;
}
-static char *
-get_option (GHashTable *hash, const char *key)
-{
- GValue *value;
-
- value = g_hash_table_lookup (hash, key);
- if (value == NULL)
- return NULL;
-
- if (G_VALUE_TYPE (value) != DBUS_TYPE_G_UCHAR_ARRAY) {
- nm_log_warn (LOGD_DHCP, "unexpected key %s value type was not "
- "DBUS_TYPE_G_UCHAR_ARRAY",
- (char *) key);
- return NULL;
- }
-
- return garray_to_string ((GArray *) g_value_get_boxed (value), key);
-}
-
-static void
-nm_dhcp_manager_handle_event (DBusGProxy *proxy,
- GHashTable *options,
- gpointer user_data)
-{
- NMDhcpManager *manager = NM_DHCP_MANAGER (user_data);
- NMDhcpClient *client;
- char *iface = NULL;
- char *pid_str = NULL;
- char *reason = NULL;
- long pid;
-
- iface = get_option (options, "interface");
- if (iface == NULL) {
- nm_log_warn (LOGD_DHCP, "DHCP event: didn't have associated interface.");
- goto out;
- }
-
- pid_str = get_option (options, "pid");
- pid = nm_utils_ascii_str_to_int64 (pid_str, 10, 0, LONG_MAX, -1);
- if (pid == -1 || pid != (GPid)pid) {
- nm_log_warn (LOGD_DHCP, "DHCP event: couldn't convert PID '%s' to an integer", pid_str ? pid_str : "(null)");
- goto out;
- }
-
- reason = get_option (options, "reason");
- client = get_client_for_pid (manager, (GPid) pid);
- if (client == NULL) {
- if (reason && g_ascii_strcasecmp (reason, "RELEASE") == 0) {
- /* This happens regularly, when the dhcp client gets killed and we receive its last message.
- * Don't log a warning in this case. */
- nm_log_dbg (LOGD_DHCP, "(pid %ld) unhandled RELEASE DHCP event for interface %s", pid, iface);
- } else
- nm_log_warn (LOGD_DHCP, "(pid %ld) unhandled DHCP event for interface %s", pid, iface);
- goto out;
- }
-
- if (strcmp (iface, nm_dhcp_client_get_iface (client))) {
- nm_log_warn (LOGD_DHCP, "(pid %ld) received DHCP event from unexpected interface '%s' (expected '%s')",
- pid, iface, nm_dhcp_client_get_iface (client));
- goto out;
- }
-
- if (reason == NULL) {
- nm_log_warn (LOGD_DHCP, "(pid %ld) DHCP event didn't have a reason", pid);
- goto out;
- }
-
- nm_dhcp_client_new_options (client, options, reason);
-
-out:
- g_free (iface);
- g_free (pid_str);
- g_free (reason);
-}
-
-#if HAVE_DBUS_GLIB_100
-static void
-new_connection_cb (NMDBusManager *mgr,
- DBusGConnection *connection,
- NMDhcpManager *self)
-{
- NMDhcpManagerPrivate *priv = NM_DHCP_MANAGER_GET_PRIVATE (self);
- DBusGProxy *proxy;
-
- /* Create a new proxy for the client */
- proxy = dbus_g_proxy_new_for_peer (connection, "/", NM_DHCP_CLIENT_DBUS_IFACE);
- dbus_g_proxy_add_signal (proxy,
- "Event",
- DBUS_TYPE_G_MAP_OF_VARIANT,
- G_TYPE_INVALID);
- dbus_g_proxy_connect_signal (proxy,
- "Event",
- G_CALLBACK (nm_dhcp_manager_handle_event),
- self,
- NULL);
- g_hash_table_insert (priv->proxies, connection, proxy);
-}
-
-static void
-dis_connection_cb (NMDBusManager *mgr,
- DBusGConnection *connection,
- NMDhcpManager *self)
-{
- NMDhcpManagerPrivate *priv = NM_DHCP_MANAGER_GET_PRIVATE (self);
- DBusGProxy *proxy;
-
- proxy = g_hash_table_lookup (priv->proxies, connection);
- if (proxy) {
- dbus_g_proxy_disconnect_signal (proxy,
- "Event",
- G_CALLBACK (nm_dhcp_manager_handle_event),
- self);
- g_hash_table_remove (priv->proxies, connection);
- }
-}
-#endif
-
static GType
get_client_type (const char *client, GError **error)
{
- gboolean use_dhclient, use_dhcpcd;
-
- /* If a client was disabled at build-time, these will return FALSE */
- use_dhclient = !!nm_dhcp_dhclient_get_path ();
- use_dhcpcd = !!nm_dhcp_dhcpcd_get_path ();
-
- if (!client) {
- if (use_dhclient)
- return NM_TYPE_DHCP_DHCLIENT;
- else if (use_dhcpcd)
- return NM_TYPE_DHCP_DHCPCD;
- else {
- g_set_error_literal (error,
- NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED,
- _("no usable DHCP client could be found."));
- return G_TYPE_INVALID;
- }
- }
-
- if (!strcmp (client, "dhclient")) {
- if (!use_dhclient) {
- g_set_error_literal (error,
- NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED,
- _("'dhclient' could not be found or was disabled."));
- return G_TYPE_INVALID;
+ GType client_gtype;
+
+ if (client)
+ client_gtype = is_client_enabled (client, error);
+ else {
+ /* Fallbacks */
+ client_gtype = is_client_enabled ("dhclient", NULL);
+ if (client_gtype == G_TYPE_INVALID)
+ client_gtype = is_client_enabled ("dhcpcd", NULL);
+ if (client_gtype == G_TYPE_INVALID)
+ client_gtype = is_client_enabled ("internal", NULL);
+ if (client_gtype == G_TYPE_INVALID) {
+ g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED,
+ _("no usable DHCP client could be found."));
}
- return NM_TYPE_DHCP_DHCLIENT;
}
-
- if (!strcmp (client, "dhcpcd")) {
- if (!use_dhcpcd) {
- g_set_error_literal (error,
- NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED,
- _("'dhcpcd' could not be found or was disabled."));
- return G_TYPE_INVALID;
- }
- return NM_TYPE_DHCP_DHCPCD;
- }
-
- g_set_error (error,
- NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED,
- _("unsupported DHCP client '%s'"), client);
- return G_TYPE_INVALID;
+ return client_gtype;
}
static void client_state_changed (NMDhcpClient *client,
@@ -355,14 +215,15 @@ client_start (NMDhcpManager *self,
int ifindex,
const GByteArray *hwaddr,
const char *uuid,
- guint priority,
+ guint32 priority,
gboolean ipv6,
const char *dhcp_client_id,
guint32 timeout,
const char *dhcp_anycast_addr,
const char *hostname,
gboolean info_only,
- NMSettingIP6ConfigPrivacy privacy)
+ NMSettingIP6ConfigPrivacy privacy,
+ const char *last_ip4_address)
{
NMDhcpManagerPrivate *priv;
NMDhcpClient *client;
@@ -403,7 +264,7 @@ client_start (NMDhcpManager *self,
if (ipv6)
success = nm_dhcp_client_start_ip6 (client, dhcp_anycast_addr, hostname, info_only, privacy);
else
- success = nm_dhcp_client_start_ip4 (client, dhcp_client_id, dhcp_anycast_addr, hostname);
+ success = nm_dhcp_client_start_ip4 (client, dhcp_client_id, dhcp_anycast_addr, hostname, last_ip4_address);
if (!success) {
remove_client (self, client);
@@ -429,12 +290,13 @@ nm_dhcp_manager_start_ip4 (NMDhcpManager *self,
int ifindex,
const GByteArray *hwaddr,
const char *uuid,
- guint priority,
+ guint32 priority,
gboolean send_hostname,
const char *dhcp_hostname,
const char *dhcp_client_id,
guint32 timeout,
- const char *dhcp_anycast_addr)
+ const char *dhcp_anycast_addr,
+ const char *last_ip_address)
{
const char *hostname = NULL;
@@ -444,7 +306,7 @@ nm_dhcp_manager_start_ip4 (NMDhcpManager *self,
hostname = get_send_hostname (self, dhcp_hostname);
return client_start (self, iface, ifindex, hwaddr, uuid, priority, FALSE,
dhcp_client_id, timeout, dhcp_anycast_addr, hostname,
- FALSE, 0);
+ FALSE, 0, last_ip_address);
}
/* Caller owns a reference to the NMDhcpClient on return */
@@ -454,22 +316,23 @@ nm_dhcp_manager_start_ip6 (NMDhcpManager *self,
int ifindex,
const GByteArray *hwaddr,
const char *uuid,
- guint priority,
+ guint32 priority,
+ gboolean send_hostname,
const char *dhcp_hostname,
guint32 timeout,
const char *dhcp_anycast_addr,
gboolean info_only,
NMSettingIP6ConfigPrivacy privacy)
{
- const char *hostname;
+ const char *hostname = NULL;
g_return_val_if_fail (NM_IS_DHCP_MANAGER (self), NULL);
- hostname = dhcp_hostname ? get_send_hostname (self, dhcp_hostname) : NULL;
-
+ if (send_hostname)
+ hostname = get_send_hostname (self, dhcp_hostname);
return client_start (self, iface, ifindex, hwaddr, uuid, priority, TRUE,
NULL, timeout, dhcp_anycast_addr, hostname, info_only,
- privacy);
+ privacy, NULL);
}
void
@@ -492,16 +355,15 @@ nm_dhcp_manager_get_lease_ip_configs (NMDhcpManager *self,
const char *uuid,
gboolean ipv6)
{
- NMDhcpManagerPrivate *priv;
+ ClientDesc *desc;
g_return_val_if_fail (NM_IS_DHCP_MANAGER (self), NULL);
g_return_val_if_fail (iface != NULL, NULL);
g_return_val_if_fail (uuid != NULL, NULL);
- priv = NM_DHCP_MANAGER_GET_PRIVATE (self);
-
- if (priv->get_lease_ip_configs_func)
- return priv->get_lease_ip_configs_func (iface, uuid, ipv6);
+ desc = find_client_desc (NULL, NM_DHCP_MANAGER_GET_PRIVATE (self)->client_type);
+ if (desc && desc->get_lease_configs_func)
+ return desc->get_lease_configs_func (iface, uuid, ipv6);
return NULL;
}
@@ -522,22 +384,21 @@ static void
nm_dhcp_manager_init (NMDhcpManager *self)
{
NMDhcpManagerPrivate *priv = NM_DHCP_MANAGER_GET_PRIVATE (self);
+ NMConfig *config = nm_config_get ();
const char *client;
GError *error = NULL;
-#if !HAVE_DBUS_GLIB_100
- DBusGConnection *g_connection;
-#endif
-
- /* Maps DBusGConnection :: DBusGProxy */
- priv->proxies = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref);
+ GSList *iter;
/* Client-specific setup */
- client = nm_config_get_dhcp_client (nm_config_get ());
- priv->client_type = get_client_type (client, &error);
+ client = nm_config_get_dhcp_client (config);
+ if (nm_config_get_configure_and_quit (config)) {
+ if (g_strcmp0 (client, "internal") != 0)
+ nm_log_warn (LOGD_DHCP, "Using internal DHCP client since configure-and-quit is set.");
+ client = "internal";
+ }
- if (priv->client_type == NM_TYPE_DHCP_DHCLIENT)
- priv->get_lease_ip_configs_func = nm_dhcp_dhclient_get_lease_ip_configs;
- else if (priv->client_type == G_TYPE_INVALID) {
+ priv->client_type = get_client_type (client, &error);
+ if (priv->client_type == G_TYPE_INVALID) {
nm_log_warn (LOGD_DHCP, "No usable DHCP client found (%s)! DHCP configurations will fail.",
error->message);
}
@@ -548,32 +409,12 @@ nm_dhcp_manager_init (NMDhcpManager *self)
(GDestroyNotify) g_object_unref);
g_assert (priv->clients);
- priv->dbus_mgr = nm_dbus_manager_get ();
-
-#if HAVE_DBUS_GLIB_100
- /* Register the socket our DHCP clients will return lease info on */
- nm_dbus_manager_private_server_register (priv->dbus_mgr, PRIV_SOCK_PATH, PRIV_SOCK_TAG);
- priv->new_conn_id = g_signal_connect (priv->dbus_mgr,
- NM_DBUS_MANAGER_PRIVATE_CONNECTION_NEW "::" PRIV_SOCK_TAG,
- (GCallback) new_connection_cb,
- self);
- priv->dis_conn_id = g_signal_connect (priv->dbus_mgr,
- NM_DBUS_MANAGER_PRIVATE_CONNECTION_DISCONNECTED "::" PRIV_SOCK_TAG,
- (GCallback) dis_connection_cb,
- self);
-#else
- g_connection = nm_dbus_manager_get_connection (priv->dbus_mgr);
- priv->proxy = dbus_g_proxy_new_for_name (g_connection,
- "org.freedesktop.nm_dhcp_client",
- "/",
- NM_DHCP_CLIENT_DBUS_IFACE);
- g_assert (priv->proxy);
- dbus_g_proxy_add_signal (priv->proxy, "Event", DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal (priv->proxy, "Event",
- G_CALLBACK (nm_dhcp_manager_handle_event),
- self,
- NULL);
-#endif
+ for (iter = client_descs; iter; iter = iter->next) {
+ ClientDesc *desc = iter->data;
+
+ nm_log_dbg (LOGD_DHCP, "Registered DHCP client '%s' (%s)",
+ desc->name, g_type_name (desc->gtype));
+ }
}
static void
@@ -589,23 +430,6 @@ dispose (GObject *object)
g_list_free (values);
}
- if (priv->new_conn_id) {
- g_signal_handler_disconnect (priv->dbus_mgr, priv->new_conn_id);
- priv->new_conn_id = 0;
- }
- if (priv->dis_conn_id) {
- g_signal_handler_disconnect (priv->dbus_mgr, priv->dis_conn_id);
- priv->dis_conn_id = 0;
- }
- priv->dbus_mgr = NULL;
-
- if (priv->proxies) {
- g_hash_table_destroy (priv->proxies);
- priv->proxies = NULL;
- }
- if (priv->proxy)
- g_object_unref (priv->proxy);
-
G_OBJECT_CLASS (nm_dhcp_manager_parent_class)->dispose (object);
}
diff --git a/src/dhcp-manager/nm-dhcp-manager.h b/src/dhcp-manager/nm-dhcp-manager.h
index 58fc23d28e..cf5519fbf8 100644
--- a/src/dhcp-manager/nm-dhcp-manager.h
+++ b/src/dhcp-manager/nm-dhcp-manager.h
@@ -56,19 +56,21 @@ NMDhcpClient * nm_dhcp_manager_start_ip4 (NMDhcpManager *manager,
int ifindex,
const GByteArray *hwaddr,
const char *uuid,
- guint priority,
+ guint32 priority,
gboolean send_hostname,
const char *dhcp_hostname,
const char *dhcp_client_id,
guint32 timeout,
- const char *dhcp_anycast_addr);
+ const char *dhcp_anycast_addr,
+ const char *last_ip_address);
NMDhcpClient * nm_dhcp_manager_start_ip6 (NMDhcpManager *manager,
const char *iface,
int ifindex,
const GByteArray *hwaddr,
const char *uuid,
- guint priority,
+ guint32 priority,
+ gboolean send_hostname,
const char *dhcp_hostname,
guint32 timeout,
const char *dhcp_anycast_addr,
diff --git a/src/dhcp-manager/nm-dhcp-systemd.c b/src/dhcp-manager/nm-dhcp-systemd.c
new file mode 100644
index 0000000000..3910339e5d
--- /dev/null
+++ b/src/dhcp-manager/nm-dhcp-systemd.c
@@ -0,0 +1,851 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ */
+
+#include <config.h>
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <ctype.h>
+#include <net/if_arp.h>
+
+#include "nm-dhcp-systemd.h"
+#include "nm-utils.h"
+#include "nm-logging.h"
+#include "nm-dhcp-utils.h"
+#include "NetworkManagerUtils.h"
+#include "gsystem-local-alloc.h"
+#include "nm-platform.h"
+
+#include "nm-sd-adapt.h"
+
+#include "sd-dhcp-client.h"
+#include "sd-dhcp6-client.h"
+#include "dhcp-protocol.h"
+#include "dhcp-lease-internal.h"
+#include "dhcp6-protocol.h"
+#include "dhcp6-lease-internal.h"
+
+G_DEFINE_TYPE (NMDhcpSystemd, nm_dhcp_systemd, NM_TYPE_DHCP_CLIENT)
+
+#define NM_DHCP_SYSTEMD_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP_SYSTEMD, NMDhcpSystemdPrivate))
+
+typedef struct {
+ struct sd_dhcp_client *client4;
+ struct sd_dhcp6_client *client6;
+ char *lease_file;
+
+ guint timeout_id;
+ guint request_count;
+
+ gboolean privacy;
+} NMDhcpSystemdPrivate;
+
+/************************************************************/
+
+#define DHCP_OPTION_NIS_DOMAIN 40
+#define DHCP_OPTION_NIS_SERVERS 41
+#define DHCP_OPTION_DOMAIN_SEARCH 119
+#define DHCP_OPTION_RFC3442_ROUTES 121
+#define DHCP_OPTION_MS_ROUTES 249
+#define DHCP_OPTION_WPAD 252
+
+/* Internal values */
+#define DHCP_OPTION_IP_ADDRESS 1024
+#define DHCP_OPTION_EXPIRY 1025
+#define DHCP6_OPTION_IP_ADDRESS 1026
+#define DHCP6_OPTION_PREFIXLEN 1027
+#define DHCP6_OPTION_PREFERRED_LIFE 1028
+#define DHCP6_OPTION_MAX_LIFE 1029
+#define DHCP6_OPTION_STARTS 1030
+#define DHCP6_OPTION_LIFE_STARTS 1031
+#define DHCP6_OPTION_RENEW 1032
+#define DHCP6_OPTION_REBIND 1033
+#define DHCP6_OPTION_IAID 1034
+
+typedef struct {
+ guint num;
+ const char *name;
+ gboolean include;
+} ReqOption;
+
+#define REQPREFIX "requested_"
+
+static const ReqOption dhcp4_requests[] = {
+ { DHCP_OPTION_SUBNET_MASK, REQPREFIX "subnet_mask", TRUE },
+ { DHCP_OPTION_TIME_OFFSET, REQPREFIX "time_offset", TRUE },
+ { DHCP_OPTION_ROUTER, REQPREFIX "routers", TRUE },
+ { DHCP_OPTION_DOMAIN_NAME_SERVER, REQPREFIX "domain_name_servers", TRUE },
+ { DHCP_OPTION_HOST_NAME, REQPREFIX "host_name", TRUE },
+ { DHCP_OPTION_DOMAIN_NAME, REQPREFIX "domain_name", TRUE },
+ { DHCP_OPTION_INTERFACE_MTU, REQPREFIX "interface_mtu", TRUE },
+ { DHCP_OPTION_BROADCAST, REQPREFIX "broadcast_address", TRUE },
+ { DHCP_OPTION_STATIC_ROUTE, REQPREFIX "static_routes", TRUE },
+ { DHCP_OPTION_NIS_DOMAIN, REQPREFIX "nis_domain", TRUE },
+ { DHCP_OPTION_NIS_SERVERS, REQPREFIX "nis_servers", TRUE },
+ { DHCP_OPTION_NTP_SERVER, REQPREFIX "ntp_servers", TRUE },
+ { DHCP_OPTION_SERVER_IDENTIFIER, REQPREFIX "dhcp_server_identifier", TRUE },
+ { DHCP_OPTION_DOMAIN_SEARCH, REQPREFIX "domain_search", TRUE },
+ { DHCP_OPTION_CLASSLESS_STATIC_ROUTE, REQPREFIX "rfc3442_classless_static_routes", TRUE },
+ { DHCP_OPTION_MS_ROUTES, REQPREFIX "ms_classless_static_routes", TRUE },
+ { DHCP_OPTION_WPAD, REQPREFIX "wpad", TRUE },
+
+ /* Internal values */
+ { DHCP_OPTION_IP_ADDRESS_LEASE_TIME, REQPREFIX "expiry", FALSE },
+ { DHCP_OPTION_CLIENT_IDENTIFIER, REQPREFIX "dhcp_client_identifier", FALSE },
+ { DHCP_OPTION_IP_ADDRESS, REQPREFIX "ip_address", FALSE },
+ { 0, NULL, FALSE }
+};
+
+static const ReqOption dhcp6_requests[] = {
+ { DHCP6_OPTION_CLIENTID, REQPREFIX "dhcp6_client_id", TRUE },
+
+ /* Don't request server ID by default; some servers don't reply to
+ * Information Requests that request the Server ID.
+ */
+ { DHCP6_OPTION_SERVERID, REQPREFIX "dhcp6_server_id", FALSE },
+
+ { DHCP6_OPTION_DNS_SERVERS, REQPREFIX "dhcp6_name_servers", TRUE },
+ { DHCP6_OPTION_DOMAIN_LIST, REQPREFIX "dhcp6_domain_search", TRUE },
+ { DHCP6_OPTION_SNTP_SERVERS, REQPREFIX "dhcp6_sntp_servers", TRUE },
+
+ /* Internal values */
+ { DHCP6_OPTION_IP_ADDRESS, REQPREFIX "ip6_address", FALSE },
+ { DHCP6_OPTION_PREFIXLEN, REQPREFIX "ip6_prefixlen", FALSE },
+ { DHCP6_OPTION_PREFERRED_LIFE, REQPREFIX "preferred_life", FALSE },
+ { DHCP6_OPTION_MAX_LIFE, REQPREFIX "max_life", FALSE },
+ { DHCP6_OPTION_STARTS, REQPREFIX "starts", FALSE },
+ { DHCP6_OPTION_LIFE_STARTS, REQPREFIX "life_starts", FALSE },
+ { DHCP6_OPTION_RENEW, REQPREFIX "renew", FALSE },
+ { DHCP6_OPTION_REBIND, REQPREFIX "rebind", FALSE },
+ { DHCP6_OPTION_IAID, REQPREFIX "iaid", FALSE },
+ { 0, NULL, FALSE }
+};
+
+static void
+take_option (GHashTable *options,
+ const ReqOption *requests,
+ guint option,
+ char *value)
+{
+ guint i;
+
+ g_return_if_fail (value != NULL);
+
+ for (i = 0; requests[i].name; i++) {
+ if (requests[i].num == option) {
+ g_hash_table_insert (options,
+ (gpointer) (requests[i].name + STRLEN (REQPREFIX)),
+ value);
+ break;
+ }
+ }
+ /* Option should always be found */
+ g_assert (requests[i].name);
+}
+
+static void
+add_option (GHashTable *options, const ReqOption *requests, guint option, const char *value)
+{
+ if (options)
+ take_option (options, requests, option, g_strdup (value));
+}
+
+static void
+add_option_u32 (GHashTable *options, const ReqOption *requests, guint option, guint32 value)
+{
+ if (options)
+ take_option (options, requests, option, g_strdup_printf ("%u", value));
+}
+
+static void
+add_requests_to_options (GHashTable *options, const ReqOption *requests)
+{
+ guint i;
+
+ for (i = 0; options && requests[i].name; i++) {
+ if (requests[i].include)
+ g_hash_table_insert (options, (gpointer) requests[i].name, g_strdup ("1"));
+ }
+}
+
+#define LOG_LEASE(domain, ...) \
+G_STMT_START { \
+ if (log_lease) { \
+ nm_log (LOGL_INFO, (domain), __VA_ARGS__); \
+ } \
+} G_STMT_END
+
+static NMIP4Config *
+lease_to_ip4_config (sd_dhcp_lease *lease,
+ GHashTable *options,
+ guint32 default_priority,
+ gboolean log_lease,
+ GError **error)
+{
+ NMIP4Config *ip4_config = NULL;
+ struct in_addr tmp_addr;
+ const struct in_addr *addr_list;
+ char buf[INET_ADDRSTRLEN];
+ const char *str;
+ guint32 lifetime = 0, plen = 0, i;
+ NMPlatformIP4Address address;
+ GString *l;
+ struct sd_dhcp_route *routes;
+ guint16 mtu;
+ int r, num;
+ gint64 end_time;
+
+ r = sd_dhcp_lease_get_address (lease, &tmp_addr);
+ if (r < 0) {
+ g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED,
+ "failed to read address from lease");
+ return NULL;
+ }
+
+ ip4_config = nm_ip4_config_new ();
+
+ /* Address */
+ memset (&address, 0, sizeof (address));
+ address.address = tmp_addr.s_addr;
+ str = nm_utils_inet4_ntop (tmp_addr.s_addr, NULL);
+ LOG_LEASE (LOGD_DHCP4, " address %s", str);
+ add_option (options, dhcp4_requests, DHCP_OPTION_IP_ADDRESS, str);
+
+ /* Prefix/netmask */
+ r = sd_dhcp_lease_get_netmask (lease, &tmp_addr);
+ if (r < 0) {
+ /* Get default netmask for the IP according to appropriate class. */
+ plen = nm_utils_ip4_get_default_prefix (address.address);
+ LOG_LEASE (LOGD_DHCP4, " plen %d (default)", plen);
+ } else {
+ plen = nm_utils_ip4_netmask_to_prefix (tmp_addr.s_addr);
+ LOG_LEASE (LOGD_DHCP4, " plen %d", plen);
+ }
+ address.plen = plen;
+ tmp_addr.s_addr = nm_utils_ip4_prefix_to_netmask (plen);
+ add_option (options,
+ dhcp4_requests,
+ DHCP_OPTION_SUBNET_MASK,
+ nm_utils_inet4_ntop (tmp_addr.s_addr, NULL));
+
+ /* Lease time */
+ r = sd_dhcp_lease_get_lifetime (lease, &lifetime);
+ if (r < 0)
+ lifetime = 3600; /* one hour */
+ address.timestamp = nm_utils_get_monotonic_timestamp_s ();
+ address.lifetime = address.preferred = lifetime;
+ end_time = (gint64) time (NULL) + lifetime;
+ add_option_u32 (options,
+ dhcp4_requests,
+ DHCP_OPTION_IP_ADDRESS_LEASE_TIME,
+ (guint) CLAMP (end_time, 0, G_MAXUINT32 - 1));
+
+ address.source = NM_IP_CONFIG_SOURCE_DHCP;
+ nm_ip4_config_add_address (ip4_config, &address);
+
+ /* Gateway */
+ r = sd_dhcp_lease_get_router (lease, &tmp_addr);
+ if (r == 0) {
+ nm_ip4_config_set_gateway (ip4_config, tmp_addr.s_addr);
+ str = nm_utils_inet4_ntop (tmp_addr.s_addr, NULL);
+ LOG_LEASE (LOGD_DHCP4, " gateway %s", str);
+ add_option (options, dhcp4_requests, DHCP_OPTION_ROUTER, str);
+ }
+
+ /* DNS Servers */
+ num = sd_dhcp_lease_get_dns (lease, &addr_list);
+ if (num > 0) {
+ l = g_string_sized_new (30);
+ for (i = 0; i < num; i++) {
+ if (addr_list[i].s_addr) {
+ nm_ip4_config_add_nameserver (ip4_config, addr_list[i].s_addr);
+ str = nm_utils_inet4_ntop (addr_list[i].s_addr, NULL);
+ LOG_LEASE (LOGD_DHCP4, " nameserver '%s'", str);
+ g_string_append_printf (l, "%s%s", l->len ? " " : "", str);
+ }
+ }
+ if (l->len)
+ add_option (options, dhcp4_requests, DHCP_OPTION_DOMAIN_NAME_SERVER, l->str);
+ g_string_free (l, TRUE);
+ }
+
+ /* Domain Name */
+ r = sd_dhcp_lease_get_domainname (lease, &str);
+ if (r == 0) {
+ /* Multiple domains sometimes stuffed into the option */
+ char **domains = g_strsplit (str, " ", 0);
+ char **s;
+
+ for (s = domains; *s; s++) {
+ LOG_LEASE (LOGD_DHCP4, " domain name '%s'", *s);
+ nm_ip4_config_add_domain (ip4_config, *s);
+ }
+ g_strfreev (domains);
+ add_option (options, dhcp4_requests, DHCP_OPTION_DOMAIN_NAME, str);
+ }
+
+ /* Hostname */
+ r = sd_dhcp_lease_get_hostname (lease, &str);
+ if (r == 0) {
+ LOG_LEASE (LOGD_DHCP4, " hostname '%s'", str);
+ add_option (options, dhcp4_requests, DHCP_OPTION_HOST_NAME, str);
+ }
+
+ /* Routes */
+ num = sd_dhcp_lease_get_routes (lease, &routes);
+ if (num > 0) {
+ l = g_string_sized_new (30);
+ for (i = 0; i < num; i++) {
+ NMPlatformIP4Route route;
+ const char *gw_str;
+
+ memset (&route, 0, sizeof (route));
+ route.network = routes[i].dst_addr.s_addr;
+ route.plen = routes[i].dst_prefixlen;
+ route.gateway = routes[i].gw_addr.s_addr;
+ route.source = NM_IP_CONFIG_SOURCE_DHCP;
+ route.metric = default_priority;
+ nm_ip4_config_add_route (ip4_config, &route);
+
+ str = nm_utils_inet4_ntop (route.network, buf);
+ gw_str = nm_utils_inet4_ntop (route.gateway, NULL);
+ LOG_LEASE (LOGD_DHCP4, " static route %s/%d gw %s", str, route.plen, gw_str);
+
+ g_string_append_printf (l, "%s%s/%d %s", l->len ? " " : "", str, route.plen, gw_str);
+ }
+ add_option (options, dhcp4_requests, DHCP_OPTION_RFC3442_ROUTES, l->str);
+ g_string_free (l, TRUE);
+ }
+
+ /* MTU */
+ r = sd_dhcp_lease_get_mtu (lease, &mtu);
+ if (r == 0 && mtu) {
+ nm_ip4_config_set_mtu (ip4_config, mtu, NM_IP_CONFIG_SOURCE_DHCP);
+ add_option_u32 (options, dhcp4_requests, DHCP_OPTION_INTERFACE_MTU, mtu);
+ LOG_LEASE (LOGD_DHCP4, " mtu %u", mtu);
+ }
+
+ /* NTP servers */
+ num = sd_dhcp_lease_get_ntp(lease, &addr_list);
+ if (num > 0) {
+ l = g_string_sized_new (30);
+ for (i = 0; i < num; i++) {
+ str = nm_utils_inet4_ntop (addr_list[i].s_addr, buf);
+ g_string_append_printf (l, "%s%s", l->len ? " " : "", str);
+ }
+ add_option (options, dhcp4_requests, DHCP_OPTION_NTP_SERVER, l->str);
+ g_string_free (l, TRUE);
+ }
+
+ return ip4_config;
+}
+
+/************************************************************/
+
+static char *
+get_leasefile_path (const char *iface, const char *uuid, gboolean ipv6)
+{
+ return g_strdup_printf (NMSTATEDIR "/internal%s-%s-%s.lease",
+ ipv6 ? "6" : "",
+ uuid,
+ iface);
+}
+
+static GSList *
+nm_dhcp_systemd_get_lease_ip_configs (const char *iface,
+ const char *uuid,
+ gboolean ipv6)
+{
+ GSList *leases = NULL;
+ gs_free char *path = NULL;
+ sd_dhcp_lease *lease = NULL;
+ NMIP4Config *ip4_config;
+ int r;
+
+ if (ipv6)
+ return NULL;
+
+ path = get_leasefile_path (iface, uuid, FALSE);
+ r = sd_dhcp_lease_load (path, &lease);
+ if (r == 0) {
+ ip4_config = lease_to_ip4_config (lease, NULL, 0, FALSE, NULL);
+ if (ip4_config)
+ leases = g_slist_append (leases, ip4_config);
+ }
+
+ return leases;
+}
+
+/************************************************************/
+
+static void
+_save_client_id (NMDhcpSystemd *self,
+ uint8_t type,
+ const uint8_t *client_id,
+ size_t len)
+{
+ gs_unref_bytes GBytes *b = NULL;
+ gs_free char *buf = NULL;
+
+ g_return_if_fail (self != NULL);
+ g_return_if_fail (client_id != NULL);
+ g_return_if_fail (len > 0);
+
+ if (!nm_dhcp_client_get_client_id (NM_DHCP_CLIENT (self))) {
+ buf = g_malloc (len + 1);
+ buf[0] = type;
+ memcpy (buf + 1, client_id, len);
+ b = g_bytes_new (buf, len + 1);
+ nm_dhcp_client_set_client_id (NM_DHCP_CLIENT (self), b);
+ }
+}
+
+static void
+bound4_handle (NMDhcpSystemd *self)
+{
+ NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (self);
+ const char *iface = nm_dhcp_client_get_iface (NM_DHCP_CLIENT (self));
+ sd_dhcp_lease *lease;
+ NMIP4Config *ip4_config;
+ GHashTable *options;
+ GError *error = NULL;
+ int r;
+
+ nm_log_dbg (LOGD_DHCP4, "(%s): lease available", iface);
+
+ r = sd_dhcp_client_get_lease (priv->client4, &lease);
+ if (r < 0 || !lease) {
+ nm_log_warn (LOGD_DHCP4, "(%s): no lease!", iface);
+ nm_dhcp_client_set_state (NM_DHCP_CLIENT (self), NM_DHCP_STATE_FAIL, NULL, NULL);
+ return;
+ }
+
+ options = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
+ ip4_config = lease_to_ip4_config (lease,
+ options,
+ nm_dhcp_client_get_priority (NM_DHCP_CLIENT (self)),
+ TRUE,
+ &error);
+ if (ip4_config) {
+ const uint8_t *client_id = NULL;
+ size_t client_id_len = 0;
+ uint8_t type = 0;
+
+ add_requests_to_options (options, dhcp4_requests);
+ sd_dhcp_lease_save (lease, priv->lease_file);
+
+ client_id = sd_dhcp_client_get_client_id(priv->client4, &type, &client_id_len);
+ if (client_id)
+ _save_client_id (self, type, client_id, client_id_len);
+
+ nm_dhcp_client_set_state (NM_DHCP_CLIENT (self),
+ NM_DHCP_STATE_BOUND,
+ G_OBJECT (ip4_config),
+ options);
+ } else {
+ nm_log_warn (LOGD_DHCP4, "(%s): %s", iface, error->message);
+ nm_dhcp_client_set_state (NM_DHCP_CLIENT (self), NM_DHCP_STATE_FAIL, NULL, NULL);
+ g_clear_error (&error);
+ }
+
+ sd_dhcp_lease_unref (lease);
+ g_hash_table_destroy (options);
+ g_clear_object (&ip4_config);
+}
+
+static void
+dhcp_event_cb (sd_dhcp_client *client, int event, gpointer user_data)
+{
+ NMDhcpSystemd *self = NM_DHCP_SYSTEMD (user_data);
+ NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (self);
+ const char *iface = nm_dhcp_client_get_iface (NM_DHCP_CLIENT (self));
+
+ g_assert (priv->client4 == client);
+
+ nm_log_dbg (LOGD_DHCP4, "(%s): DHCPv4 client event %d", iface, event);
+
+ switch (event) {
+ case DHCP_EVENT_EXPIRED:
+ case DHCP_EVENT_STOP:
+ nm_dhcp_client_set_state (NM_DHCP_CLIENT (user_data), NM_DHCP_STATE_FAIL, NULL, NULL);
+ break;
+ case DHCP_EVENT_RENEW:
+ case DHCP_EVENT_IP_CHANGE:
+ case DHCP_EVENT_IP_ACQUIRE:
+ bound4_handle (self);
+ break;
+ default:
+ nm_log_warn (LOGD_DHCP4, "(%s): unhandled DHCP event %d", iface, event);
+ break;
+ }
+}
+
+static guint16
+get_arp_type (const GByteArray *hwaddr)
+{
+ if (hwaddr->len == ETH_ALEN)
+ return ARPHRD_ETHER;
+ else if (hwaddr->len == INFINIBAND_ALEN)
+ return ARPHRD_INFINIBAND;
+ else
+ g_assert_not_reached ();
+}
+
+static gboolean
+ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last_ip4_address)
+{
+ NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (client);
+ const char *iface = nm_dhcp_client_get_iface (client);
+ const GByteArray *hwaddr;
+ sd_dhcp_lease *lease = NULL;
+ GBytes *override_client_id;
+ const uint8_t *client_id = NULL;
+ size_t client_id_len = 0;
+ struct in_addr last_addr = { 0 };
+ const char *hostname;
+ int r, i;
+
+ g_assert (priv->client4 == NULL);
+ g_assert (priv->client6 == NULL);
+
+ g_free (priv->lease_file);
+ priv->lease_file = get_leasefile_path (iface, nm_dhcp_client_get_uuid (client), FALSE);
+
+ r = sd_dhcp_client_new (&priv->client4);
+ if (r < 0) {
+ nm_log_warn (LOGD_DHCP4, "(%s): failed to create DHCPv4 client (%d)", iface, r);
+ return FALSE;
+ }
+
+ r = sd_dhcp_client_attach_event (priv->client4, NULL, 0);
+ if (r < 0) {
+ nm_log_warn (LOGD_DHCP4, "(%s): failed to attach DHCP event (%d)", iface, r);
+ goto error;
+ }
+
+ hwaddr = nm_dhcp_client_get_hw_addr (client);
+ if (hwaddr) {
+ r = sd_dhcp_client_set_mac (priv->client4,
+ hwaddr->data,
+ hwaddr->len,
+ get_arp_type (hwaddr));
+ if (r < 0) {
+ nm_log_warn (LOGD_DHCP4, "(%s): failed to set DHCP MAC address (%d)", iface, r);
+ goto error;
+ }
+ }
+
+ r = sd_dhcp_client_set_index (priv->client4, nm_dhcp_client_get_ifindex (client));
+ if (r < 0) {
+ nm_log_warn (LOGD_DHCP4, "(%s): failed to set DHCP ifindex (%d)", iface, r);
+ goto error;
+ }
+
+ r = sd_dhcp_client_set_callback (priv->client4, dhcp_event_cb, client);
+ if (r < 0) {
+ nm_log_warn (LOGD_DHCP4, "(%s): failed to set DHCP callback (%d)", iface, r);
+ goto error;
+ }
+
+ r = sd_dhcp_client_set_request_broadcast (priv->client4, true);
+ if (r < 0) {
+ nm_log_warn (LOGD_DHCP4, "(%s): failed to set DHCP broadcast (%d)", iface, r);
+ goto error;
+ }
+
+ sd_dhcp_lease_load (priv->lease_file, &lease);
+
+ if (last_ip4_address)
+ inet_pton (AF_INET, last_ip4_address, &last_addr);
+ else if (lease)
+ sd_dhcp_lease_get_address (lease, &last_addr);
+
+ if (last_addr.s_addr) {
+ r = sd_dhcp_client_set_request_address (priv->client4, &last_addr);
+ if (r < 0) {
+ nm_log_warn (LOGD_DHCP4, "(%s): failed to set last IPv4 address (%d)", iface, r);
+ goto error;
+ }
+ }
+
+ override_client_id = nm_dhcp_client_get_client_id (client);
+ if (override_client_id) {
+ client_id = g_bytes_get_data (override_client_id, &client_id_len);
+ g_assert (client_id && client_id_len);
+ sd_dhcp_client_set_client_id (priv->client4,
+ client_id[0],
+ client_id + 1,
+ client_id_len - 1);
+ } else if (lease) {
+ r = sd_dhcp_lease_get_client_id (lease, &client_id, &client_id_len);
+ if (r == 0 && client_id_len) {
+ sd_dhcp_client_set_client_id (priv->client4,
+ client_id[0],
+ client_id + 1,
+ client_id_len - 1);
+ _save_client_id (NM_DHCP_SYSTEMD (client),
+ client_id[0],
+ client_id + 1,
+ client_id_len - 1);
+ }
+ }
+
+ if (lease)
+ sd_dhcp_lease_unref (lease);
+
+ /* Add requested options */
+ for (i = 0; dhcp4_requests[i].name; i++) {
+ if (dhcp4_requests[i].include)
+ sd_dhcp_client_set_request_option (priv->client4, dhcp4_requests[i].num);
+ }
+
+ hostname = nm_dhcp_client_get_hostname (client);
+ if (hostname) {
+ r = sd_dhcp_client_set_hostname (priv->client4, hostname);
+ if (r < 0) {
+ nm_log_warn (LOGD_DHCP4, "(%s): failed to set DHCP hostname (%d)", iface, r);
+ goto error;
+ }
+ }
+
+ r = sd_dhcp_client_start (priv->client4);
+ if (r < 0) {
+ nm_log_warn (LOGD_DHCP4, "(%s): failed to start DHCP (%d)", iface, r);
+ goto error;
+ }
+
+ return TRUE;
+
+error:
+ sd_dhcp_client_unref (priv->client4);
+ priv->client4 = NULL;
+ return FALSE;
+}
+
+static void
+bound6_handle (NMDhcpSystemd *self)
+{
+ /* not yet supported... */
+ nm_log_warn (LOGD_DHCP6, "(%s): internal DHCP does not yet support DHCPv6",
+ nm_dhcp_client_get_iface (NM_DHCP_CLIENT (self)));
+ nm_dhcp_client_set_state (NM_DHCP_CLIENT (self), NM_DHCP_STATE_FAIL, NULL, NULL);
+}
+
+static void
+dhcp6_event_cb (sd_dhcp6_client *client, int event, gpointer user_data)
+{
+ NMDhcpSystemd *self = NM_DHCP_SYSTEMD (user_data);
+ NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (self);
+ const char *iface = nm_dhcp_client_get_iface (NM_DHCP_CLIENT (self));
+
+ g_assert (priv->client6 == client);
+
+ nm_log_dbg (LOGD_DHCP6, "(%s): DHCPv6 client event %d", iface, event);
+
+ switch (event) {
+ case DHCP6_EVENT_RETRANS_MAX:
+ nm_dhcp_client_set_state (NM_DHCP_CLIENT (user_data), NM_DHCP_STATE_TIMEOUT, NULL, NULL);
+ break;
+ case DHCP6_EVENT_RESEND_EXPIRE:
+ case DHCP6_EVENT_STOP:
+ nm_dhcp_client_set_state (NM_DHCP_CLIENT (user_data), NM_DHCP_STATE_FAIL, NULL, NULL);
+ break;
+ case DHCP6_EVENT_IP_ACQUIRE:
+ bound6_handle (self);
+ break;
+ default:
+ nm_log_warn (LOGD_DHCP6, "(%s): unhandled DHCPv6 event %d", iface, event);
+ break;
+ }
+}
+
+static gboolean
+ip6_start (NMDhcpClient *client,
+ const char *dhcp_anycast_addr,
+ gboolean info_only,
+ NMSettingIP6ConfigPrivacy privacy,
+ const GByteArray *duid)
+{
+ NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (client);
+ const char *iface = nm_dhcp_client_get_iface (client);
+ const GByteArray *hwaddr;
+ int r, i;
+
+ g_assert (priv->client4 == NULL);
+ g_assert (priv->client6 == NULL);
+ g_return_val_if_fail (duid != NULL, FALSE);
+
+ g_free (priv->lease_file);
+ priv->lease_file = get_leasefile_path (iface, nm_dhcp_client_get_uuid (client), TRUE);
+
+ r = sd_dhcp6_client_new (&priv->client6);
+ if (r < 0) {
+ nm_log_warn (LOGD_DHCP6, "(%s): failed to create DHCPv6 client (%d)", iface, r);
+ return FALSE;
+ }
+
+ /* NM stores the entire DUID which includes the uint16 "type", while systemd
+ * wants the type passed separately from the following data.
+ */
+ r = sd_dhcp6_client_set_duid (priv->client6,
+ ntohs (((const guint16 *) duid->data)[0]),
+ duid->data + 2,
+ duid->len - 2);
+ if (r < 0) {
+ nm_log_warn (LOGD_DHCP6, "(%s): failed to create DHCPv6 client (%d)", iface, r);
+ return FALSE;
+ }
+
+ r = sd_dhcp6_client_attach_event (priv->client6, NULL, 0);
+ if (r < 0) {
+ nm_log_warn (LOGD_DHCP6, "(%s): failed to attach DHCP event (%d)", iface, r);
+ goto error;
+ }
+
+ hwaddr = nm_dhcp_client_get_hw_addr (client);
+ if (hwaddr) {
+ r = sd_dhcp6_client_set_mac (priv->client6,
+ hwaddr->data,
+ hwaddr->len,
+ get_arp_type (hwaddr));
+ if (r < 0) {
+ nm_log_warn (LOGD_DHCP6, "(%s): failed to set DHCP MAC address (%d)", iface, r);
+ goto error;
+ }
+ }
+
+ r = sd_dhcp6_client_set_index (priv->client6, nm_dhcp_client_get_ifindex (client));
+ if (r < 0) {
+ nm_log_warn (LOGD_DHCP6, "(%s): failed to set DHCP ifindex (%d)", iface, r);
+ goto error;
+ }
+
+ r = sd_dhcp6_client_set_ifname (priv->client6, iface);
+ if (r < 0) {
+ nm_log_warn (LOGD_DHCP6, "(%s): failed to set DHCP ifname (%d)", iface, r);
+ goto error;
+ }
+
+ r = sd_dhcp6_client_set_callback (priv->client6, dhcp6_event_cb, client);
+ if (r < 0) {
+ nm_log_warn (LOGD_DHCP6, "(%s): failed to set DHCP callback (%d)", iface, r);
+ goto error;
+ }
+
+ /* Add requested options */
+ for (i = 0; dhcp6_requests[i].name; i++) {
+ if (dhcp6_requests[i].include)
+ sd_dhcp6_client_set_request_option (priv->client6, dhcp6_requests[i].num);
+ }
+
+ r = sd_dhcp6_client_start (priv->client6);
+ if (r < 0) {
+ nm_log_warn (LOGD_DHCP6, "(%s): failed to start DHCP (%d)", iface, r);
+ goto error;
+ }
+
+ return TRUE;
+
+error:
+ sd_dhcp6_client_unref (priv->client6);
+ priv->client6 = NULL;
+ return FALSE;
+}
+
+static void
+stop (NMDhcpClient *client, gboolean release, const GByteArray *duid)
+{
+ NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (client);
+ int r = 0;
+
+ if (priv->client4)
+ r = sd_dhcp_client_stop (priv->client4);
+ else if (priv->client6)
+ r = sd_dhcp6_client_stop (priv->client6);
+
+ if (r) {
+ nm_log_warn (priv->client6 ? LOGD_DHCP6 : LOGD_DHCP4,
+ "(%s): failed to stop DHCP client (%d)",
+ nm_dhcp_client_get_iface (client),
+ r);
+ }
+}
+
+/***************************************************/
+
+static void
+nm_dhcp_systemd_init (NMDhcpSystemd *self)
+{
+}
+
+static void
+dispose (GObject *object)
+{
+ NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (object);
+
+ g_clear_pointer (&priv->lease_file, g_free);
+
+ if (priv->client4) {
+ sd_dhcp_client_stop (priv->client4);
+ sd_dhcp_client_unref (priv->client4);
+ priv->client4 = NULL;
+ }
+
+ if (priv->client6) {
+ sd_dhcp6_client_stop (priv->client6);
+ sd_dhcp6_client_unref (priv->client6);
+ priv->client6 = NULL;
+ }
+
+ G_OBJECT_CLASS (nm_dhcp_systemd_parent_class)->dispose (object);
+}
+
+static void
+nm_dhcp_systemd_class_init (NMDhcpSystemdClass *sdhcp_class)
+{
+ NMDhcpClientClass *client_class = NM_DHCP_CLIENT_CLASS (sdhcp_class);
+ GObjectClass *object_class = G_OBJECT_CLASS (sdhcp_class);
+
+ g_type_class_add_private (sdhcp_class, sizeof (NMDhcpSystemdPrivate));
+
+ /* virtual methods */
+ object_class->dispose = dispose;
+
+ client_class->ip4_start = ip4_start;
+ client_class->ip6_start = ip6_start;
+ client_class->stop = stop;
+}
+
+static void __attribute__((constructor))
+register_dhcp_dhclient (void)
+{
+ g_type_init ();
+ _nm_dhcp_client_register (NM_TYPE_DHCP_SYSTEMD,
+ "internal",
+ NULL,
+ nm_dhcp_systemd_get_lease_ip_configs);
+}
+
diff --git a/src/dhcp-manager/nm-dhcp-systemd.h b/src/dhcp-manager/nm-dhcp-systemd.h
new file mode 100644
index 0000000000..2a7a463eb5
--- /dev/null
+++ b/src/dhcp-manager/nm-dhcp-systemd.h
@@ -0,0 +1,45 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ */
+
+#ifndef NM_DHCP_SYSTEMD_H
+#define NM_DHCP_SYSTEMD_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include "nm-dhcp-client.h"
+
+#define NM_TYPE_DHCP_SYSTEMD (nm_dhcp_systemd_get_type ())
+#define NM_DHCP_SYSTEMD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DHCP_SYSTEMD, NMDhcpSystemd))
+#define NM_DHCP_SYSTEMD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DHCP_SYSTEMD, NMDhcpSystemdClass))
+#define NM_IS_DHCP_SYSTEMD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DHCP_SYSTEMD))
+#define NM_IS_DHCP_SYSTEMD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DHCP_SYSTEMD))
+#define NM_DHCP_SYSTEMD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DHCP_SYSTEMD, NMDhcpSystemdClass))
+
+typedef struct {
+ NMDhcpClient parent;
+} NMDhcpSystemd;
+
+typedef struct {
+ NMDhcpClientClass parent;
+} NMDhcpSystemdClass;
+
+GType nm_dhcp_systemd_get_type (void);
+
+#endif /* NM_DHCP_SYSTEMD_H */
+
diff --git a/src/dhcp-manager/nm-dhcp-utils.c b/src/dhcp-manager/nm-dhcp-utils.c
index 014937f6ea..4b8c44a452 100644
--- a/src/dhcp-manager/nm-dhcp-utils.c
+++ b/src/dhcp-manager/nm-dhcp-utils.c
@@ -22,6 +22,7 @@
#include <string.h>
#include <errno.h>
#include <unistd.h>
+#include <arpa/inet.h>
#include "nm-logging.h"
#include "nm-dhcp-utils.h"
@@ -33,7 +34,7 @@
static gboolean
ip4_process_dhcpcd_rfc3442_routes (const char *str,
- guint priority,
+ guint32 priority,
NMIP4Config *ip4_config,
guint32 *gwaddr)
{
@@ -160,7 +161,7 @@ error:
static gboolean
ip4_process_dhclient_rfc3442_routes (const char *str,
- guint priority,
+ guint32 priority,
NMIP4Config *ip4_config,
guint32 *gwaddr)
{
@@ -208,7 +209,7 @@ out:
static gboolean
ip4_process_classless_routes (GHashTable *options,
- guint priority,
+ guint32 priority,
NMIP4Config *ip4_config,
guint32 *gwaddr)
{
@@ -271,7 +272,7 @@ ip4_process_classless_routes (GHashTable *options,
}
static void
-process_classful_routes (GHashTable *options, guint priority, NMIP4Config *ip4_config)
+process_classful_routes (GHashTable *options, guint32 priority, NMIP4Config *ip4_config)
{
const char *str;
char **searches, **s;
@@ -373,7 +374,7 @@ ip4_add_domain_search (gpointer data, gpointer user_data)
NMIP4Config *
nm_dhcp_utils_ip4_config_from_options (const char *iface,
GHashTable *options,
- guint priority)
+ guint32 priority)
{
NMIP4Config *ip4_config = NULL;
guint32 tmp_addr;
@@ -590,7 +591,7 @@ ip6_add_domain_search (gpointer data, gpointer user_data)
NMIP6Config *
nm_dhcp_utils_ip6_config_from_options (const char *iface,
GHashTable *options,
- guint priority,
+ guint32 priority,
gboolean info_only)
{
NMIP6Config *ip6_config = NULL;
@@ -692,3 +693,39 @@ nm_dhcp_utils_duid_to_string (const GByteArray *duid)
return g_string_free (s, FALSE);
}
+/**
+ * nm_dhcp_utils_client_id_string_to_bytes:
+ * @client_id: the client ID string
+ *
+ * Accepts either a hex string ("aa:bb:cc") representing a binary client ID
+ * (the first byte is assumed to be the 'type' field per RFC 2132 section 9.14),
+ * or a string representing a non-hardware-address client ID, in which case
+ * the 'type' field is set to 0.
+ *
+ * Returns: the binary client ID suitable for sending over the wire
+ * to the DHCP server.
+ */
+GBytes *
+nm_dhcp_utils_client_id_string_to_bytes (const char *client_id)
+{
+ GBytes *bytes = NULL;
+ guint len;
+ char *c;
+
+ g_return_val_if_fail (client_id && client_id[0], NULL);
+
+ /* Try as hex encoded */
+ if (strchr (client_id, ':'))
+ bytes = nm_utils_hexstr2bin (client_id);
+ if (!bytes) {
+ /* Fall back to string */
+ len = strlen (client_id);
+ c = g_malloc (len + 1);
+ c[0] = 0; /* type: non-hardware address per RFC 2132 section 9.14 */
+ memcpy (c + 1, client_id, len);
+ bytes = g_bytes_new_take (c, len + 1);
+ }
+
+ return bytes;
+}
+
diff --git a/src/dhcp-manager/nm-dhcp-utils.h b/src/dhcp-manager/nm-dhcp-utils.h
index ab9d45fe4b..a01cf4c267 100644
--- a/src/dhcp-manager/nm-dhcp-utils.h
+++ b/src/dhcp-manager/nm-dhcp-utils.h
@@ -35,5 +35,7 @@ NMIP6Config *nm_dhcp_utils_ip6_config_from_options (const char *iface,
char * nm_dhcp_utils_duid_to_string (const GByteArray *duid);
+GBytes * nm_dhcp_utils_client_id_string_to_bytes (const char *client_id);
+
#endif /* __NETWORKMANAGER_DHCP_UTILS_H__ */
diff --git a/src/dhcp-manager/systemd-dhcp/nm-sd-adapt.c b/src/dhcp-manager/systemd-dhcp/nm-sd-adapt.c
new file mode 100644
index 0000000000..dbc922e9eb
--- /dev/null
+++ b/src/dhcp-manager/systemd-dhcp/nm-sd-adapt.c
@@ -0,0 +1,208 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ */
+
+#include <config.h>
+#include <glib.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include "sd-event.h"
+#include "time-util.h"
+
+struct sd_event_source {
+ guint refcount;
+ guint id;
+ gpointer user_data;
+
+ GIOChannel *channel;
+ sd_event_io_handler_t io_cb;
+
+ uint64_t usec;
+ sd_event_time_handler_t time_cb;
+};
+
+int
+sd_event_source_set_priority (sd_event_source *s, int64_t priority)
+{
+ return 0;
+}
+
+sd_event_source*
+sd_event_source_unref (sd_event_source *s)
+{
+
+ if (!s)
+ return NULL;
+
+ g_return_val_if_fail (s->refcount, NULL);
+
+ s->refcount--;
+ if (s->refcount == 0) {
+ if (s->id)
+ g_source_remove (s->id);
+ if (s->channel) {
+ /* Don't shut down the channel since systemd will soon close
+ * the file descriptor itself, which would cause -EBADF.
+ */
+ g_io_channel_unref (s->channel);
+ }
+ g_free (s);
+ }
+ return NULL;
+}
+
+int
+sd_event_source_set_name(sd_event_source *s, const char *name)
+{
+ if (!s)
+ return -EINVAL;
+
+ g_source_set_name_by_id (s->id, name);
+ return 0;
+}
+
+static gboolean
+io_ready (GIOChannel *channel, GIOCondition condition, struct sd_event_source *source)
+{
+ int r, revents = 0;
+
+ if (condition & G_IO_IN)
+ revents |= EPOLLIN;
+ if (condition & G_IO_OUT)
+ revents |= EPOLLOUT;
+ if (condition & G_IO_PRI)
+ revents |= EPOLLPRI;
+ if (condition & G_IO_ERR)
+ revents |= EPOLLERR;
+ if (condition & G_IO_HUP)
+ revents |= EPOLLHUP;
+
+ r = source->io_cb (source, g_io_channel_unix_get_fd (channel), revents, source->user_data);
+ if (r < 0) {
+ source->id = 0;
+ return G_SOURCE_REMOVE;
+ }
+
+ return G_SOURCE_CONTINUE;
+}
+
+int
+sd_event_add_io (sd_event *e, sd_event_source **s, int fd, uint32_t events, sd_event_io_handler_t callback, void *userdata)
+{
+ struct sd_event_source *source;
+ GIOChannel *channel;
+ GIOCondition condition = 0;
+
+ channel = g_io_channel_unix_new (fd);
+ if (!channel)
+ return -EINVAL;
+
+ source = g_new0 (struct sd_event_source, 1);
+ source->refcount = 1;
+ source->io_cb = callback;
+ source->user_data = userdata;
+ source->channel = channel;
+
+ if (events & EPOLLIN)
+ condition |= G_IO_IN;
+ if (events & EPOLLOUT)
+ condition |= G_IO_OUT;
+ if (events & EPOLLPRI)
+ condition |= G_IO_PRI;
+ if (events & EPOLLERR)
+ condition |= G_IO_ERR;
+ if (events & EPOLLHUP)
+ condition |= G_IO_HUP;
+
+ g_io_channel_set_encoding (source->channel, NULL, NULL);
+ g_io_channel_set_buffered (source->channel, FALSE);
+ source->id = g_io_add_watch (source->channel, condition, (GIOFunc) io_ready, source);
+
+ *s = source;
+ return 0;
+}
+
+static gboolean
+time_ready (struct sd_event_source *source)
+{
+ int r;
+
+ r = source->time_cb (source, source->usec, source->user_data);
+ if (r < 0) {
+ source->id = 0;
+ return G_SOURCE_REMOVE;
+ }
+
+ return G_SOURCE_CONTINUE;
+}
+
+int
+sd_event_add_time(sd_event *e, sd_event_source **s, clockid_t clock, uint64_t usec, uint64_t accuracy, sd_event_time_handler_t callback, void *userdata)
+{
+ struct sd_event_source *source;
+ uint64_t n = now (clock);
+
+ source = g_new0 (struct sd_event_source, 1);
+ source->refcount = 1;
+ source->time_cb = callback;
+ source->user_data = userdata;
+ source->usec = usec;
+
+ if (usec > 1000)
+ usec = n < usec - 1000 ? usec - n : 1000;
+ source->id = g_timeout_add (usec / 1000, (GSourceFunc) time_ready, source);
+
+ *s = source;
+ return 0;
+}
+
+/* sd_event is basically a GMainContext; but since we only
+ * ever use the default context, nothing to do here.
+ */
+
+int
+sd_event_default (sd_event **e)
+{
+ *e = GUINT_TO_POINTER (1);
+ return 0;
+}
+
+sd_event*
+sd_event_ref (sd_event *e)
+{
+ return e;
+}
+
+sd_event*
+sd_event_unref (sd_event *e)
+{
+ return NULL;
+}
+
+int
+sd_event_now (sd_event *e, clockid_t clock, uint64_t *usec)
+{
+ *usec = now (clock);
+ return 0;
+}
+
+int asynchronous_close(int fd) {
+ safe_close(fd);
+ return -1;
+}
+
diff --git a/src/dhcp-manager/systemd-dhcp/nm-sd-adapt.h b/src/dhcp-manager/systemd-dhcp/nm-sd-adapt.h
new file mode 100644
index 0000000000..5bd1f81f8b
--- /dev/null
+++ b/src/dhcp-manager/systemd-dhcp/nm-sd-adapt.h
@@ -0,0 +1,109 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ */
+
+#ifndef NM_SD_ADAPT_H
+#define NM_SD_ADAPT_H
+
+#include <config.h>
+
+#include <glib.h>
+
+#include <netinet/in.h>
+#include <stdbool.h>
+#include <syslog.h>
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <elf.h>
+#ifdef HAVE_SYS_AUXV_H
+#include <sys/auxv.h>
+#endif
+#include <unistd.h>
+#include <sys/syscall.h>
+
+#include "nm-logging.h"
+
+static inline guint32
+_slog_level_to_nm (int slevel)
+{
+ switch (slevel) {
+ case LOG_DEBUG: return LOGL_DEBUG;
+ case LOG_WARNING: return LOGL_WARN;
+ case LOG_ERR: return LOGL_ERR;
+ case LOG_INFO:
+ case LOG_NOTICE:
+ default: return LOGL_INFO;
+ }
+}
+
+#define log_meta(level, file, line, func, format, ...) \
+G_STMT_START { \
+ guint32 _l = _slog_level_to_nm ((level)); \
+ if (nm_logging_enabled (_l, LOGD_DHCP)) { \
+ const char *_location = strrchr ((file ":" G_STRINGIFY(line)), '/'); \
+ \
+ _nm_log (_location ? _location + 1 : (file ":" G_STRINGIFY(line)), func, _l, LOGD_DHCP, format, ## __VA_ARGS__); \
+ } \
+} G_STMT_END
+
+#define log_debug(...) log_full(LOG_DEBUG, __VA_ARGS__)
+#define log_error(...) log_full(LOG_ERR, __VA_ARGS__)
+#define log_full(level, ...) log_meta((level), __FILE__, __LINE__, __func__, __VA_ARGS__);
+
+#define log_dhcp_client(client, fmt, ...) \
+ log_meta(LOG_DEBUG, __FILE__, __LINE__, __func__, "DHCP CLIENT (0x%x): " fmt, client->xid, ##__VA_ARGS__)
+
+#define log_assert_failed(e, file, line, func) \
+G_STMT_START { \
+ nm_log_err (LOGD_DHCP, #file ":" #line "(" #func "): assertion failed: " # e); \
+ g_assert (FALSE); \
+} G_STMT_END
+
+#define log_assert_failed_unreachable(t, file, line, func) \
+G_STMT_START { \
+ nm_log_err (LOGD_DHCP, #file ":" #line "(" #func "): assert unreachable: " # t); \
+ g_assert_not_reached (); \
+} G_STMT_END
+
+#define log_assert_failed_return(e, file, line, func) \
+ nm_log_err (LOGD_DHCP, #file ":" #line "(" #func "): assert return: " # e); \
+
+#define log_oom nm_log_err(LOGD_CORE, "%s:%s/%s: OOM", __FILE__, __LINE__, __func__)
+
+/* Can't include both net/if.h and linux/if.h; so have to define this here */
+#ifndef IFNAMSIZ
+#define IFNAMSIZ 16
+#endif
+
+#ifndef MAX_HANDLE_SZ
+#define MAX_HANDLE_SZ 128
+#endif
+
+#define noreturn G_GNUC_NORETURN
+
+#include "sd-id128.h"
+#include "sparse-endian.h"
+#include "async.h"
+#include "util.h"
+
+static inline pid_t gettid(void) {
+ return (pid_t) syscall(SYS_gettid);
+}
+
+#endif /* NM_SD_ADAPT_H */
+
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-internal.h b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-internal.h
index d358a49307..28c0e63454 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-internal.h
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-internal.h
@@ -22,6 +22,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <stdint.h>
#include <linux/if_packet.h>
#include <net/if_arp.h>
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-lease-internal.h b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-lease-internal.h
index 9fb4f4b4e4..9e184ac4b5 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-lease-internal.h
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-lease-internal.h
@@ -70,16 +70,18 @@ struct sd_dhcp_lease {
char *domainname;
char *hostname;
char *root_path;
+ uint8_t *client_id;
+ size_t client_id_len;
};
int dhcp_lease_new(sd_dhcp_lease **ret);
int dhcp_lease_parse_options(uint8_t code, uint8_t len, const uint8_t *option,
void *user_data);
-int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file);
-int dhcp_lease_load(const char *lease_file, sd_dhcp_lease **ret);
-
int dhcp_lease_set_default_subnet_mask(sd_dhcp_lease *lease);
+int dhcp_lease_set_client_id(sd_dhcp_lease *lease, const uint8_t *client_id,
+ size_t client_id_len);
+
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_dhcp_lease*, sd_dhcp_lease_unref);
#define _cleanup_dhcp_lease_unref_ _cleanup_(sd_dhcp_lease_unrefp)
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-network.c b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-network.c
index 29e9993f66..26e6e9f3df 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-network.c
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-network.c
@@ -17,6 +17,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-option.c b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-option.c
index b6110c5f16..50ecf87383 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-option.c
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-option.c
@@ -19,6 +19,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <stdint.h>
#include <string.h>
#include <errno.h>
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-packet.c b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-packet.c
index 7581daeeeb..e6ebf86ae1 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-packet.c
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-packet.c
@@ -18,6 +18,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <stdlib.h>
#include <errno.h>
#include <string.h>
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-internal.h b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-internal.h
index 6cc0aa8a8d..e29e2f0ee0 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-internal.h
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-internal.h
@@ -21,6 +21,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <net/ethernet.h>
#include <netinet/in.h>
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-lease-internal.h b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-lease-internal.h
index 109e0f4f21..9f7826c466 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-lease-internal.h
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-lease-internal.h
@@ -22,6 +22,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <stdint.h>
#include "refcnt.h"
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-network.c b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-network.c
index fe56c10273..626a4d6a7f 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-network.c
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-network.c
@@ -17,6 +17,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-option.c b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-option.c
index ea863f45e4..10872a3159 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-option.c
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp6-option.c
@@ -19,6 +19,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <netinet/in.h>
#include <errno.h>
#include <string.h>
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/network-internal.c b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/network-internal.c
index 6f16050cdc..8418f5e429 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/network-internal.c
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/network-internal.c
@@ -19,22 +19,31 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <netinet/ether.h>
#include <linux/if.h>
#include <arpa/inet.h>
#include <fnmatch.h>
+#if 0 /* NM_IGNORED */
#include "strv.h"
#include "siphash24.h"
#include "libudev-private.h"
+#endif
#include "dhcp-lease-internal.h"
+#if 0 /* NM_IGNORED */
#include "log.h"
#include "utf8.h"
+#endif
#include "util.h"
+#if 0 /* NM_IGNORED */
#include "conf-parser.h"
#include "condition.h"
+#endif
#include "network-internal.h"
+#if 0 /* NM_IGNORED */
const char *net_get_name(struct udev_device *device) {
const char *name, *field;
@@ -295,6 +304,7 @@ int config_parse_hwaddr(const char *unit,
return 0;
}
+#endif
void serialize_in_addrs(FILE *f, const struct in_addr *addresses, size_t size) {
unsigned i;
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/network-internal.h b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/network-internal.h
index c64db2e79d..f87c863d91 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/network-internal.h
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/network-internal.h
@@ -21,10 +21,13 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <netinet/ether.h>
#include <netinet/in.h>
#include <stdbool.h>
+#if 0 /* NM_IGNORED */
#include "udev.h"
#include "condition.h"
@@ -62,6 +65,7 @@ int config_parse_ifalias(const char *unit, const char *filename, unsigned line,
int net_get_unique_predictable_data(struct udev_device *device, uint8_t result[8]);
const char *net_get_name(struct udev_device *device);
+#endif
void serialize_in_addrs(FILE *f, const struct in_addr *addresses, size_t size);
int deserialize_in_addrs(struct in_addr **addresses, const char *string);
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-client.c b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-client.c
index 689163cffe..1cb698dc4d 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-client.c
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-client.c
@@ -17,6 +17,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <stdlib.h>
#include <errno.h>
#include <string.h>
@@ -38,6 +40,7 @@
#include "dhcp-lease-internal.h"
#include "sd-dhcp-client.h"
+#define MAX_CLIENT_ID_LEN 32
#define MAX_MAC_ADDR_LEN INFINIBAND_ALEN
struct sd_dhcp_client {
@@ -56,19 +59,38 @@ struct sd_dhcp_client {
size_t req_opts_allocated;
size_t req_opts_size;
be32_t last_addr;
- struct {
- uint8_t type;
- struct ether_addr mac_addr;
- } _packed_ client_id;
uint8_t mac_addr[MAX_MAC_ADDR_LEN];
size_t mac_addr_len;
uint16_t arp_type;
+ union {
+ struct {
+ uint8_t type; /* 0: Generic (non-LL) (RFC 2132) */
+ uint8_t data[MAX_CLIENT_ID_LEN];
+ } _packed_ gen;
+ struct {
+ uint8_t type; /* 1: Ethernet Link-Layer (RFC 2132) */
+ uint8_t haddr[ETH_ALEN];
+ } _packed_ eth;
+ struct {
+ uint8_t type; /* 2 - 254: ARP/Link-Layer (RFC 2132) */
+ uint8_t haddr[0];
+ } _packed_ ll;
+ struct {
+ uint8_t type; /* 255: Node-specific (RFC 4361) */
+ uint8_t iaid[4];
+ uint8_t duid[MAX_CLIENT_ID_LEN - 4];
+ } _packed_ ns;
+ struct {
+ uint8_t type;
+ uint8_t data[MAX_CLIENT_ID_LEN];
+ } _packed_ raw;
+ } client_id;
+ size_t client_id_len;
char *hostname;
char *vendor_class_identifier;
uint32_t mtu;
uint32_t xid;
usec_t start_time;
- uint16_t secs;
unsigned int attempt;
usec_t request_sent;
sd_event_source *timeout_t1;
@@ -201,8 +223,65 @@ int sd_dhcp_client_set_mac(sd_dhcp_client *client, const uint8_t *addr,
client->mac_addr_len = addr_len;
client->arp_type = arp_type;
- memcpy(&client->client_id.mac_addr, addr, ETH_ALEN);
- client->client_id.type = 0x01;
+ if (need_restart && client->state != DHCP_STATE_STOPPED)
+ sd_dhcp_client_start(client);
+
+ return 0;
+}
+
+const uint8_t *sd_dhcp_client_get_client_id(sd_dhcp_client *client,
+ uint8_t *type,
+ size_t *len) {
+
+ assert_return(client, NULL);
+ assert_return(type, NULL);
+ assert_return(len, NULL);
+
+ if (!client->client_id_len)
+ return NULL;
+
+ *type = client->client_id.raw.type;
+ *len = client->client_id_len - 1; /* -1 for sizeof(type) */
+ return (const uint8_t *) &client->client_id.raw.data;
+}
+
+int sd_dhcp_client_set_client_id(sd_dhcp_client *client, uint8_t type,
+ const uint8_t *data, size_t data_len) {
+ DHCP_CLIENT_DONT_DESTROY(client);
+ bool need_restart = false;
+
+ assert_return(client, -EINVAL);
+ assert_return(data, -EINVAL);
+ assert_return(data_len > 0 && data_len <= MAX_CLIENT_ID_LEN, -EINVAL);
+
+ switch (type) {
+ case ARPHRD_ETHER:
+ if (data_len != ETH_ALEN)
+ return -EINVAL;
+ break;
+ case ARPHRD_INFINIBAND:
+ if (data_len != INFINIBAND_ALEN)
+ return -EINVAL;
+ break;
+ default:
+ break;
+ }
+
+ if (client->client_id_len == data_len + 1 &&
+ client->client_id.raw.type == type &&
+ memcmp(&client->client_id.raw.data, data, data_len) == 0)
+ return 0;
+
+ if (!IN_SET(client->state, DHCP_STATE_INIT, DHCP_STATE_STOPPED)) {
+ log_dhcp_client(client, "Changing client ID on running DHCP "
+ "client, restarting");
+ need_restart = true;
+ client_stop(client, DHCP_EVENT_STOP);
+ }
+
+ client->client_id.raw.type = type;
+ memcpy(&client->client_id.raw.data, data, data_len);
+ client->client_id_len = data_len + 1; /* +1 for sizeof(type) */
if (need_restart && client->state != DHCP_STATE_STOPPED)
sd_dhcp_client_start(client);
@@ -318,18 +397,22 @@ static void client_stop(sd_dhcp_client *client, int error) {
static int client_message_init(sd_dhcp_client *client, DHCPPacket **ret,
uint8_t type, size_t *_optlen, size_t *_optoffset) {
- _cleanup_free_ DHCPPacket *packet;
+ _cleanup_free_ DHCPPacket *packet = NULL;
size_t optlen, optoffset, size;
be16_t max_size;
+ usec_t time_now;
+ uint16_t secs;
int r;
assert(client);
- assert(client->secs);
+ assert(client->start_time);
assert(ret);
assert(_optlen);
assert(_optoffset);
assert(type == DHCP_DISCOVER || type == DHCP_REQUEST);
+ /* See RFC2131 section 4.4.1 */
+
optlen = DHCP_MIN_OPTIONS_SIZE;
size = sizeof(DHCPPacket) + optlen;
@@ -344,7 +427,15 @@ static int client_message_init(sd_dhcp_client *client, DHCPPacket **ret,
/* Although 'secs' field is a SHOULD in RFC 2131, certain DHCP servers
refuse to issue an DHCP lease if 'secs' is set to zero */
- packet->dhcp.secs = htobe16(client->secs);
+ r = sd_event_now(client->event, clock_boottime_or_monotonic(), &time_now);
+ if (r < 0)
+ return r;
+ assert(time_now >= client->start_time);
+
+ /* seconds between sending first and last DISCOVER
+ * must always be strictly positive to deal with broken servers */
+ secs = ((time_now - client->start_time) / USEC_PER_SEC) ? : 1;
+ packet->dhcp.secs = htobe16(secs);
/* RFC2132 section 4.1
A client that cannot receive unicast IP datagrams until its protocol
@@ -369,14 +460,24 @@ static int client_message_init(sd_dhcp_client *client, DHCPPacket **ret,
if (client->arp_type == ARPHRD_ETHER)
memcpy(&packet->dhcp.chaddr, &client->mac_addr, ETH_ALEN);
+ /* If no client identifier exists, construct one from an ethernet
+ address if present */
+ if (client->client_id_len == 0 && client->arp_type == ARPHRD_ETHER) {
+ client->client_id.eth.type = ARPHRD_ETHER;
+ memcpy(&client->client_id.eth.haddr, &client->mac_addr, ETH_ALEN);
+ client->client_id_len = sizeof (client->client_id.eth);
+ }
+
/* Some DHCP servers will refuse to issue an DHCP lease if the Client
Identifier option is not set */
- r = dhcp_option_append(&packet->dhcp, optlen, &optoffset, 0,
- DHCP_OPTION_CLIENT_IDENTIFIER,
- sizeof(client->client_id), &client->client_id);
- if (r < 0)
- return r;
-
+ if (client->client_id_len) {
+ r = dhcp_option_append(&packet->dhcp, optlen, &optoffset, 0,
+ DHCP_OPTION_CLIENT_IDENTIFIER,
+ client->client_id_len,
+ &client->client_id.raw);
+ if (r < 0)
+ return r;
+ }
/* RFC2131 section 3.5:
in its initial DHCPDISCOVER or DHCPREQUEST message, a
@@ -441,24 +542,12 @@ static int dhcp_client_send_raw(sd_dhcp_client *client, DHCPPacket *packet,
static int client_send_discover(sd_dhcp_client *client) {
_cleanup_free_ DHCPPacket *discover = NULL;
size_t optoffset, optlen;
- usec_t time_now;
int r;
assert(client);
assert(client->state == DHCP_STATE_INIT ||
client->state == DHCP_STATE_SELECTING);
- /* See RFC2131 section 4.4.1 */
-
- r = sd_event_now(client->event, clock_boottime_or_monotonic(), &time_now);
- if (r < 0)
- return r;
- assert(time_now >= client->start_time);
-
- /* seconds between sending first and last DISCOVER
- * must always be strictly positive to deal with broken servers */
- client->secs = ((time_now - client->start_time) / USEC_PER_SEC) ? : 1;
-
r = client_message_init(client, &discover, DHCP_DISCOVER,
&optlen, &optoffset);
if (r < 0)
@@ -872,10 +961,8 @@ static int client_start(sd_dhcp_client *client) {
}
client->fd = r;
- if (client->state == DHCP_STATE_INIT) {
+ if (client->state == DHCP_STATE_INIT || client->state == DHCP_STATE_INIT_REBOOT)
client->start_time = now(clock_boottime_or_monotonic());
- client->secs = 0;
- }
return client_initialize_events(client, client_receive_message_raw);
}
@@ -941,6 +1028,14 @@ static int client_handle_offer(sd_dhcp_client *client, DHCPMessage *offer,
if (r < 0)
return r;
+ if (client->client_id_len) {
+ r = dhcp_lease_set_client_id(lease,
+ (uint8_t *) &client->client_id,
+ client->client_id_len);
+ if (r < 0)
+ return r;
+ }
+
r = dhcp_option_parse(offer, len, dhcp_lease_parse_options, lease);
if (r != DHCP_OFFER) {
log_dhcp_client(client, "received message was not an OFFER, ignoring");
@@ -1000,6 +1095,14 @@ static int client_handle_ack(sd_dhcp_client *client, DHCPMessage *ack,
if (r < 0)
return r;
+ if (client->client_id_len) {
+ r = dhcp_lease_set_client_id(lease,
+ (uint8_t *) &client->client_id,
+ client->client_id_len);
+ if (r < 0)
+ return r;
+ }
+
r = dhcp_option_parse(ack, len, dhcp_lease_parse_options, lease);
if (r == DHCP_NAK) {
log_dhcp_client(client, "NAK");
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-lease.c b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-lease.c
index f6b572a996..e6c26cc0a8 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-lease.c
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-lease.c
@@ -18,6 +18,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <stdlib.h>
#include <errno.h>
#include <string.h>
@@ -28,7 +30,9 @@
#include "util.h"
#include "list.h"
+#if 0 /* NM_IGNORED */
#include "mkdir.h"
+#endif
#include "fileio.h"
#include "unaligned.h"
#include "in-addr-util.h"
@@ -199,6 +203,7 @@ sd_dhcp_lease *sd_dhcp_lease_unref(sd_dhcp_lease *lease) {
free(lease->dns);
free(lease->ntp);
free(lease->static_route);
+ free(lease->client_id);
free(lease);
}
@@ -580,11 +585,13 @@ int dhcp_lease_new(sd_dhcp_lease **ret) {
return 0;
}
-int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
+int sd_dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
_cleanup_free_ char *temp_path = NULL;
_cleanup_fclose_ FILE *f = NULL;
struct in_addr address;
const struct in_addr *addresses;
+ const uint8_t *client_id;
+ size_t client_id_len;
const char *string;
uint16_t mtu;
struct sd_dhcp_route *routes;
@@ -658,6 +665,18 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
if (r >= 0)
serialize_dhcp_routes(f, "ROUTES", routes, r);
+ r = sd_dhcp_lease_get_client_id(lease, &client_id, &client_id_len);
+ if (r >= 0) {
+ _cleanup_free_ char *client_id_hex = NULL;
+
+ client_id_hex = hexmem (client_id, client_id_len);
+ if (!client_id_hex) {
+ r = -ENOMEM;
+ goto finish;
+ }
+ fprintf(f, "CLIENTID=%s\n", client_id_hex);
+ }
+
r = 0;
fflush(f);
@@ -675,11 +694,12 @@ finish:
return r;
}
-int dhcp_lease_load(const char *lease_file, sd_dhcp_lease **ret) {
+int sd_dhcp_lease_load(const char *lease_file, sd_dhcp_lease **ret) {
_cleanup_dhcp_lease_unref_ sd_dhcp_lease *lease = NULL;
_cleanup_free_ char *address = NULL, *router = NULL, *netmask = NULL,
*server_address = NULL, *next_server = NULL,
- *dns = NULL, *ntp = NULL, *mtu = NULL, *routes = NULL;
+ *dns = NULL, *ntp = NULL, *mtu = NULL,
+ *routes = NULL, *client_id_hex = NULL;
struct in_addr addr;
int r;
@@ -703,6 +723,7 @@ int dhcp_lease_load(const char *lease_file, sd_dhcp_lease **ret) {
"HOSTNAME", &lease->hostname,
"ROOT_PATH", &lease->root_path,
"ROUTES", &routes,
+ "CLIENTID", &client_id_hex,
NULL);
if (r < 0) {
if (r == -ENOENT)
@@ -777,6 +798,16 @@ int dhcp_lease_load(const char *lease_file, sd_dhcp_lease **ret) {
return r;
}
+ if (client_id_hex) {
+ if (strlen (client_id_hex) % 2)
+ return -EINVAL;
+
+ lease->client_id = unhexmem (client_id_hex, strlen (client_id_hex));
+ if (!lease->client_id)
+ return -ENOMEM;
+ lease->client_id_len = strlen (client_id_hex) / 2;
+ }
+
*ret = lease;
lease = NULL;
@@ -801,3 +832,32 @@ int dhcp_lease_set_default_subnet_mask(sd_dhcp_lease *lease) {
return 0;
}
+
+int sd_dhcp_lease_get_client_id(sd_dhcp_lease *lease, const uint8_t **client_id,
+ size_t *client_id_len) {
+ assert_return(lease, -EINVAL);
+ assert_return(client_id, -EINVAL);
+ assert_return(client_id_len, -EINVAL);
+
+ *client_id = lease->client_id;
+ *client_id_len = lease->client_id_len;
+ return 0;
+}
+
+int dhcp_lease_set_client_id(sd_dhcp_lease *lease, const uint8_t *client_id,
+ size_t client_id_len) {
+ assert_return(lease, -EINVAL);
+ assert_return((!client_id && !client_id_len) ||
+ (client_id && client_id_len), -EINVAL);
+
+ free (lease->client_id);
+ lease->client_id = NULL;
+ lease->client_id_len = 0;
+
+ if (client_id) {
+ lease->client_id = memdup (client_id, client_id_len);
+ lease->client_id_len = client_id_len;
+ }
+
+ return 0;
+}
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp6-client.c b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp6-client.c
index 8537d7cc86..20ba0db2cc 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp6-client.c
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp6-client.c
@@ -19,14 +19,18 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <errno.h>
#include <string.h>
#include <sys/ioctl.h>
#include <linux/if_infiniband.h>
+#if 0 /* NM_IGNORED */
#include "udev.h"
#include "udev-util.h"
#include "virt.h"
+#endif
#include "siphash24.h"
#include "util.h"
#include "refcnt.h"
@@ -57,6 +61,7 @@ struct sd_dhcp6_client {
uint8_t mac_addr[MAX_MAC_ADDR_LEN];
size_t mac_addr_len;
uint16_t arp_type;
+ char ifname[IFNAMSIZ];
DHCP6IA ia_na;
be32_t transaction_id;
usec_t transaction_start;
@@ -626,10 +631,7 @@ error:
}
static int client_ensure_iaid(sd_dhcp6_client *client) {
- /* name is a pointer to memory in the udev_device struct, so must
- have the same scope */
- _cleanup_udev_device_unref_ struct udev_device *device = NULL;
- const char *name = NULL;
+ const char *name;
uint64_t id;
assert(client);
@@ -637,27 +639,7 @@ static int client_ensure_iaid(sd_dhcp6_client *client) {
if (client->ia_na.id)
return 0;
- if (detect_container(NULL) <= 0) {
- /* not in a container, udev will be around */
- _cleanup_udev_unref_ struct udev *udev;
- char ifindex_str[2 + DECIMAL_STR_MAX(int)];
-
- udev = udev_new();
- if (!udev)
- return -ENOMEM;
-
- sprintf(ifindex_str, "n%d", client->index);
- device = udev_device_new_from_device_id(udev, ifindex_str);
- if (!device)
- return -errno;
-
- if (udev_device_get_is_initialized(device) <= 0)
- /* not yet ready */
- return -EBUSY;
-
- name = net_get_name(device);
- }
-
+ name = client->ifname;
if (name)
siphash24((uint8_t*)&id, name, strlen(name), HASH_KEY.bytes);
else
@@ -860,7 +842,7 @@ static int client_receive_message(sd_event_source *s, int fd, uint32_t revents,
void *userdata) {
sd_dhcp6_client *client = userdata;
DHCP6_CLIENT_DONT_DESTROY(client);
- _cleanup_free_ DHCP6Message *message;
+ _cleanup_free_ DHCP6Message *message = NULL;
int r, buflen, len;
assert(s);
@@ -1193,8 +1175,10 @@ sd_dhcp6_client *sd_dhcp6_client_unref(sd_dhcp6_client *client) {
int sd_dhcp6_client_new(sd_dhcp6_client **ret)
{
_cleanup_dhcp6_client_unref_ sd_dhcp6_client *client = NULL;
+#if 0 /* NM_IGNORED */
sd_id128_t machine_id;
int r;
+#endif
size_t t;
assert_return(ret, -EINVAL);
@@ -1211,6 +1195,7 @@ int sd_dhcp6_client_new(sd_dhcp6_client **ret)
client->fd = -1;
+#if 0 /* NM_IGNORED */
/* initialize DUID */
client->duid.en.type = htobe16(DHCP6_DUID_EN);
client->duid.en.pen = htobe32(SYSTEMD_PEN);
@@ -1223,6 +1208,7 @@ int sd_dhcp6_client_new(sd_dhcp6_client **ret)
/* a bit of snake-oil perhaps, but no need to expose the machine-id
directly */
siphash24(client->duid.en.id, &machine_id, sizeof(machine_id), HASH_KEY.bytes);
+#endif
client->req_opts_len = ELEMENTSOF(default_req_opts);
@@ -1238,3 +1224,17 @@ int sd_dhcp6_client_new(sd_dhcp6_client **ret)
return 0;
}
+
+/*******************************************/
+/* NetworkManager additions */
+
+int sd_dhcp6_client_set_ifname(sd_dhcp6_client *client, const char *ifname)
+{
+ assert_return(client, -EINVAL);
+ assert_return(ifname, -EINVAL);
+ assert_return(strlen (ifname) < sizeof (client->ifname), -EINVAL);
+
+ strcpy(client->ifname, ifname);
+ return 0;
+}
+
diff --git a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp6-lease.c b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp6-lease.c
index e2715ea659..6a1cb22daa 100644
--- a/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp6-lease.c
+++ b/src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp6-lease.c
@@ -18,6 +18,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <errno.h>
#include "util.h"
diff --git a/src/dhcp-manager/systemd-dhcp/src/shared/fileio.c b/src/dhcp-manager/systemd-dhcp/src/shared/fileio.c
index ff6b1a7ed7..39a3bc1732 100644
--- a/src/dhcp-manager/systemd-dhcp/src/shared/fileio.c
+++ b/src/dhcp-manager/systemd-dhcp/src/shared/fileio.c
@@ -508,17 +508,15 @@ static int parse_env_file_push(
va_list aq, *ap = userdata;
if (!utf8_is_valid(key)) {
- _cleanup_free_ char *p;
+ _cleanup_free_ char *p = utf8_escape_invalid(key);
- p = utf8_escape_invalid(key);
log_error("%s:%u: invalid UTF-8 in key '%s', ignoring.", strna(filename), line, p);
return -EINVAL;
}
if (value && !utf8_is_valid(value)) {
- _cleanup_free_ char *p;
+ _cleanup_free_ char *p = utf8_escape_invalid(value);
- p = utf8_escape_invalid(value);
log_error("%s:%u: invalid UTF-8 value for key %s: '%s', ignoring.", strna(filename), line, key, p);
return -EINVAL;
}
diff --git a/src/dhcp-manager/systemd-dhcp/src/shared/macro.h b/src/dhcp-manager/systemd-dhcp/src/shared/macro.h
index 9ee332c8df..e6cf6eecd7 100644
--- a/src/dhcp-manager/systemd-dhcp/src/shared/macro.h
+++ b/src/dhcp-manager/systemd-dhcp/src/shared/macro.h
@@ -373,17 +373,18 @@ do { \
#define IN_SET(x, y, ...) \
({ \
const typeof(y) _y = (y); \
- const typeof(_y) _x = (x); \
+ typeof(_y) _x = (x); \
unsigned _i; \
bool _found = false; \
- for (_i = 0; _i < 1 + sizeof((const typeof(_x)[]) { __VA_ARGS__ })/sizeof(const typeof(_x)); _i++) \
- if (((const typeof(_x)[]) { _y, __VA_ARGS__ })[_i] == _x) { \
+ for (_i = 0; _i < 1 + sizeof((typeof(_x)[]) { __VA_ARGS__ })/sizeof(typeof(_x)); _i++) \
+ if (((typeof(_x)[]) { _y, __VA_ARGS__ })[_i] == _x) { \
_found = true; \
break; \
} \
_found; \
})
+#if 0 /* NM_IGNORED */
/* Define C11 thread_local attribute even on older gcc compiler
* version */
#ifndef thread_local
@@ -409,3 +410,4 @@ do { \
#endif
#include "log.h"
+#endif
diff --git a/src/dhcp-manager/systemd-dhcp/src/shared/strv.c b/src/dhcp-manager/systemd-dhcp/src/shared/strv.c
index aeb93eac6b..a22f83c2fd 100644
--- a/src/dhcp-manager/systemd-dhcp/src/shared/strv.c
+++ b/src/dhcp-manager/systemd-dhcp/src/shared/strv.c
@@ -19,6 +19,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <assert.h>
#include <stdlib.h>
#include <stdarg.h>
diff --git a/src/dhcp-manager/systemd-dhcp/src/shared/time-util.c b/src/dhcp-manager/systemd-dhcp/src/shared/time-util.c
index d3404afd55..184f57bdc6 100644
--- a/src/dhcp-manager/systemd-dhcp/src/shared/time-util.c
+++ b/src/dhcp-manager/systemd-dhcp/src/shared/time-util.c
@@ -19,6 +19,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <time.h>
#include <string.h>
#include <sys/timex.h>
@@ -26,7 +28,9 @@
#include "util.h"
#include "time-util.h"
+#if 0 /* NM_IGNORED */
#include "strv.h"
+#endif
usec_t now(clockid_t clock_id) {
struct timespec ts;
@@ -118,6 +122,7 @@ struct timespec *timespec_store(struct timespec *ts, usec_t u) {
return ts;
}
+#if 0 /* NM_IGNORED */
usec_t timeval_load(const struct timeval *tv) {
assert(tv);
@@ -272,6 +277,7 @@ char *format_timestamp_relative(char *buf, size_t l, usec_t t) {
buf[l-1] = 0;
return buf;
}
+#endif
char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
static const struct {
@@ -383,6 +389,7 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
return buf;
}
+#if 0 /* NM_IGNORED */
void dual_timestamp_serialize(FILE *f, const char *name, dual_timestamp *t) {
assert(f);
@@ -500,9 +507,8 @@ int parse_timestamp(const char *t, usec_t *usec) {
return parse_sec(t + 1, usec);
else if (endswith(t, " ago")) {
- _cleanup_free_ char *z;
+ _cleanup_free_ char *z = strndup(t, strlen(t) - 4);
- z = strndup(t, strlen(t) - 4);
if (!z)
return -ENOMEM;
@@ -512,9 +518,8 @@ int parse_timestamp(const char *t, usec_t *usec) {
goto finish;
} else if (endswith(t, " left")) {
- _cleanup_free_ char *z;
+ _cleanup_free_ char *z = strndup(t, strlen(t) - 4);
- z = strndup(t, strlen(t) - 4);
if (!z)
return -ENOMEM;
@@ -974,6 +979,7 @@ bool timezone_is_valid(const char *name) {
return true;
}
+#endif
clockid_t clock_boottime_or_monotonic(void) {
static clockid_t clock = -1;
@@ -992,3 +998,4 @@ clockid_t clock_boottime_or_monotonic(void) {
return clock;
}
+
diff --git a/src/dhcp-manager/systemd-dhcp/src/shared/time-util.h b/src/dhcp-manager/systemd-dhcp/src/shared/time-util.h
index b55a660bb0..578a0c1ca4 100644
--- a/src/dhcp-manager/systemd-dhcp/src/shared/time-util.h
+++ b/src/dhcp-manager/systemd-dhcp/src/shared/time-util.h
@@ -27,6 +27,8 @@
typedef uint64_t usec_t;
typedef uint64_t nsec_t;
+#include "nm-sd-adapt.h"
+
#define NSEC_FMT "%" PRIu64
#define USEC_FMT "%" PRIu64
diff --git a/src/dhcp-manager/systemd-dhcp/src/shared/utf8.c b/src/dhcp-manager/systemd-dhcp/src/shared/utf8.c
index 8702ceb1b2..261f39db84 100644
--- a/src/dhcp-manager/systemd-dhcp/src/shared/utf8.c
+++ b/src/dhcp-manager/systemd-dhcp/src/shared/utf8.c
@@ -43,6 +43,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "nm-sd-adapt.h"
+
#include <errno.h>
#include <stdlib.h>
#include <inttypes.h>
diff --git a/src/dhcp-manager/systemd-dhcp/src/shared/util.c b/src/dhcp-manager/systemd-dhcp/src/shared/util.c
index 2f4fa237dd..8e55d40f04 100644
--- a/src/dhcp-manager/systemd-dhcp/src/shared/util.c
+++ b/src/dhcp-manager/systemd-dhcp/src/shared/util.c
@@ -19,6 +19,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <assert.h>
#include <string.h>
#include <unistd.h>
@@ -69,6 +71,7 @@
#include "macro.h"
#include "util.h"
+#if 0 /* NM_IGNORED */
#include "ioprio.h"
#include "missing.h"
#include "log.h"
@@ -85,7 +88,9 @@
#include "gunicode.h"
#include "virt.h"
#include "def.h"
+#endif
+#if 0 /* NM_IGNORED */
int saved_argc = 0;
char **saved_argv = NULL;
@@ -105,6 +110,7 @@ size_t page_size(void) {
pgsz = (size_t) r;
return pgsz;
}
+#endif
bool streq_ptr(const char *a, const char *b) {
@@ -219,6 +225,7 @@ int safe_close(int fd) {
return -1;
}
+#if 0 /* NM_IGNORED */
void close_many(const int fds[], unsigned n_fd) {
unsigned i;
@@ -302,6 +309,7 @@ int parse_uid(const char *s, uid_t* ret_uid) {
*ret_uid = uid;
return 0;
}
+#endif
int safe_atou(const char *s, unsigned *ret_u) {
char *x = NULL;
@@ -323,6 +331,7 @@ int safe_atou(const char *s, unsigned *ret_u) {
return 0;
}
+#if 0 /* NM_IGNORED */
int safe_atoi(const char *s, int *ret_i) {
char *x = NULL;
long l;
@@ -415,6 +424,7 @@ int safe_atod(const char *s, double *ret_d) {
*ret_d = (double) d;
return 0;
}
+#endif
static size_t strcspn_escaped(const char *s, const char *reject) {
bool escaped = false;
@@ -472,6 +482,7 @@ const char* split(const char **state, size_t *l, const char *separator, bool quo
return current;
}
+#if 0 /* NM_IGNORED */
int get_parent_of_pid(pid_t pid, pid_t *_ppid) {
int r;
_cleanup_free_ char *line = NULL;
@@ -564,6 +575,7 @@ int get_starttime_of_pid(pid_t pid, unsigned long long *st) {
return 0;
}
+#endif
int fchmod_umask(int fd, mode_t m) {
mode_t u;
@@ -583,6 +595,7 @@ char *truncate_nl(char *s) {
return s;
}
+#if 0 /* NM_IGNORED */
int get_process_state(pid_t pid) {
const char *p;
char state;
@@ -820,6 +833,7 @@ int get_process_gid(pid_t pid, gid_t *gid) {
assert_cc(sizeof(uid_t) == sizeof(gid_t));
return get_process_id(pid, "Gid:", gid);
}
+#endif
char *strnappend(const char *s, const char *suffix, size_t b) {
size_t a;
@@ -856,6 +870,7 @@ char *strappend(const char *s, const char *suffix) {
return strnappend(s, suffix, suffix ? strlen(suffix) : 0);
}
+#if 0 /* NM_IGNORED */
int readlinkat_malloc(int fd, const char *p, char **ret) {
size_t l = 100;
int r;
@@ -992,6 +1007,7 @@ int reset_signal_mask(void) {
return 0;
}
+#endif
char *strstrip(char *s) {
char *e;
@@ -1010,6 +1026,7 @@ char *strstrip(char *s) {
return s;
}
+#if 0 /* NM_IGNORED */
char *delete_chars(char *s, const char *bad) {
char *f, *t;
@@ -1099,6 +1116,7 @@ int rmdir_parents(const char *path, const char *stop) {
return 0;
}
+#endif
char hexchar(int x) {
static const char table[16] = "0123456789abcdef";
@@ -1396,6 +1414,7 @@ char *cunescape_length(const char *s, size_t length) {
return cunescape_length_with_prefix(s, length, NULL);
}
+#if 0 /* NM_IGNORED */
char *cunescape(const char *s) {
assert(s);
@@ -1585,6 +1604,7 @@ int close_all_fds(const int except[], unsigned n_except) {
return r;
}
+#endif
bool chars_intersect(const char *a, const char *b) {
const char *p;
@@ -1597,6 +1617,7 @@ bool chars_intersect(const char *a, const char *b) {
return false;
}
+#if 0 /* NM_IGNORED */
bool fstype_is_network(const char *fstype) {
static const char table[] =
"cifs\0"
@@ -1620,7 +1641,7 @@ bool fstype_is_network(const char *fstype) {
}
int chvt(int vt) {
- _cleanup_close_ int fd;
+ _cleanup_close_ int fd = -1;
fd = open_terminal("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC);
if (fd < 0)
@@ -2206,6 +2227,7 @@ void safe_close_pair(int p[]) {
p[0] = safe_close(p[0]);
p[1] = safe_close(p[1]);
}
+#endif
ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll) {
uint8_t *p = buf;
@@ -2242,6 +2264,7 @@ ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll) {
return n;
}
+#if 0 /* NM_IGNORED */
ssize_t loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) {
const uint8_t *p = buf;
ssize_t n = 0;
@@ -2486,6 +2509,7 @@ char* dirname_malloc(const char *path) {
return dir;
}
+#endif
int dev_urandom(void *p, size_t n) {
static int have_syscall = -1;
@@ -2589,6 +2613,7 @@ void random_bytes(void *p, size_t n) {
*q = rand();
}
+#if 0 /* NM_IGNORED */
void rename_process(const char name[8]) {
assert(name);
@@ -3551,7 +3576,7 @@ char *ellipsize(const char *s, size_t length, unsigned percent) {
}
int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gid, mode_t mode) {
- _cleanup_close_ int fd;
+ _cleanup_close_ int fd = -1;
int r;
assert(path);
@@ -4097,6 +4122,7 @@ char* strshorten(char *s, size_t l) {
return s;
}
+#endif
static bool hostname_valid_char(char c) {
return
@@ -4138,6 +4164,7 @@ bool hostname_is_valid(const char *s) {
return true;
}
+#if 0 /* NM_IGNORED */
char* hostname_cleanup(char *s, bool lowercase) {
char *p, *d;
bool dot;
@@ -4198,6 +4225,7 @@ int pipe_eof(int fd) {
return pollfd.revents & POLLHUP;
}
+#endif
int fd_wait_for_event(int fd, int event, usec_t t) {
@@ -4251,6 +4279,7 @@ int fopen_temporary(const char *path, FILE **_f, char **_temp_path) {
return 0;
}
+#if 0 /* NM_IGNORED */
int terminal_vhangup_fd(int fd) {
assert(fd >= 0);
@@ -4261,7 +4290,7 @@ int terminal_vhangup_fd(int fd) {
}
int terminal_vhangup(const char *name) {
- _cleanup_close_ int fd;
+ _cleanup_close_ int fd = -1;
fd = open_terminal(name, O_RDWR|O_NOCTTY|O_CLOEXEC);
if (fd < 0)
@@ -4729,6 +4758,7 @@ int get_files_in_directory(const char *path, char ***list) {
return n;
}
+#endif
char *strjoin(const char *x, ...) {
va_list ap;
@@ -4787,6 +4817,7 @@ char *strjoin(const char *x, ...) {
return r;
}
+#if 0 /* NM_IGNORED */
bool is_main_thread(void) {
static thread_local int cached = 0;
@@ -5094,6 +5125,7 @@ finish:
return buf;
}
+#endif
void* memdup(const void *p, size_t l) {
void *r;
@@ -5108,6 +5140,7 @@ void* memdup(const void *p, size_t l) {
return r;
}
+#if 0 /* NM_IGNORED */
int fd_inc_sndbuf(int fd, size_t n) {
int r, value;
socklen_t l = sizeof(value);
@@ -5539,6 +5572,7 @@ bool string_is_safe(const char *p) {
return true;
}
+#endif
/**
* Check if a string contains control characters. If 'ok' is non-NULL
@@ -5563,6 +5597,7 @@ bool string_has_cc(const char *p, const char *ok) {
return false;
}
+#if 0 /* NM_IGNORED */
bool path_is_safe(const char *p) {
if (isempty(p))
@@ -6040,6 +6075,7 @@ char *strrep(const char *s, unsigned n) {
*p = 0;
return r;
}
+#endif
void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size) {
size_t a, newalloc;
@@ -6067,6 +6103,7 @@ void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size) {
return q;
}
+#if 0 /* NM_IGNORED */
void* greedy_realloc0(void **p, size_t *allocated, size_t need, size_t size) {
size_t prev;
uint8_t *q;
@@ -6454,6 +6491,7 @@ int getpeersec(int fd, char **ret) {
*ret = s;
return 0;
}
+#endif
/* This is much like like mkostemp() but is subject to umask(). */
int mkostemp_safe(char *pattern, int flags) {
@@ -6471,6 +6509,7 @@ int mkostemp_safe(char *pattern, int flags) {
return fd;
}
+#if 0 /* NM_IGNORED */
int open_tmpfile(const char *path, int flags) {
char *p;
int fd;
@@ -6857,6 +6896,7 @@ int bind_remount_recursive(const char *prefix, bool ro) {
}
}
}
+#endif
int fflush_and_check(FILE *f) {
assert(f);
@@ -6889,6 +6929,7 @@ char *tempfn_xxxxxx(const char *p) {
return t;
}
+#if 0 /* NM_IGNORED */
char *tempfn_random(const char *p) {
const char *fn;
char *t, *x;
@@ -6917,6 +6958,7 @@ char *tempfn_random(const char *p) {
return t;
}
+#endif
/* make sure the hostname is not "localhost" */
bool is_localhost(const char *hostname) {
@@ -6935,6 +6977,7 @@ bool is_localhost(const char *hostname) {
endswith(hostname, ".localdomain.");
}
+#if 0 /* NM_IGNORED */
int take_password_lock(const char *root) {
struct flock flock = {
@@ -7254,3 +7297,5 @@ int sethostname_idempotent(const char *s) {
return 1;
}
+#endif
+
diff --git a/src/dhcp-manager/systemd-dhcp/src/shared/util.h b/src/dhcp-manager/systemd-dhcp/src/shared/util.h
index 04f2d8a564..e8913277fe 100644
--- a/src/dhcp-manager/systemd-dhcp/src/shared/util.h
+++ b/src/dhcp-manager/systemd-dhcp/src/shared/util.h
@@ -21,6 +21,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "nm-sd-adapt.h"
+
#include <alloca.h>
#include <fcntl.h>
#include <inttypes.h>
@@ -43,6 +45,7 @@
#include <mntent.h>
#include <sys/socket.h>
+#if 0 /* NM_IGNORED */
#if SIZEOF_PID_T == 4
# define PID_FMT "%" PRIu32
#elif SIZEOF_PID_T == 2
@@ -82,9 +85,12 @@
#else
# error Unknown rlim_t size
#endif
+#endif
#include "macro.h"
+#if 0 /* NM_IGNORED */
#include "missing.h"
+#endif
#include "time-util.h"
/* What is interpreted as whitespace? */
@@ -975,8 +981,10 @@ int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int root_fd);
bool pid_is_alive(pid_t pid);
bool pid_is_unwaited(pid_t pid);
+#if 0 /* NM_IGNORED */
int getpeercred(int fd, struct ucred *ucred);
int getpeersec(int fd, char **ret);
+#endif
int writev_safe(int fd, const struct iovec *w, int j);
@@ -994,10 +1002,12 @@ char* mount_test_option(const char *haystack, const char *needle);
void hexdump(FILE *f, const void *p, size_t s);
+#if 0 /* NM_IGNORED */
union file_handle_union {
struct file_handle handle;
char padding[sizeof(struct file_handle) + MAX_HANDLE_SZ];
};
+#endif
int update_reboot_param_file(const char *param);
diff --git a/src/dhcp-manager/systemd-dhcp/src/systemd/sd-dhcp-client.h b/src/dhcp-manager/systemd-dhcp/src/systemd/sd-dhcp-client.h
index 7416f82193..953f6cddef 100644
--- a/src/dhcp-manager/systemd-dhcp/src/systemd/sd-dhcp-client.h
+++ b/src/dhcp-manager/systemd-dhcp/src/systemd/sd-dhcp-client.h
@@ -51,6 +51,11 @@ int sd_dhcp_client_set_request_broadcast(sd_dhcp_client *client, int broadcast);
int sd_dhcp_client_set_index(sd_dhcp_client *client, int interface_index);
int sd_dhcp_client_set_mac(sd_dhcp_client *client, const uint8_t *addr,
size_t addr_len, uint16_t arp_type);
+int sd_dhcp_client_set_client_id(sd_dhcp_client *client, uint8_t type,
+ const uint8_t *data, size_t data_len);
+const uint8_t *sd_dhcp_client_get_client_id(sd_dhcp_client *client,
+ uint8_t *type,
+ size_t *len);
int sd_dhcp_client_set_mtu(sd_dhcp_client *client, uint32_t mtu);
int sd_dhcp_client_set_hostname(sd_dhcp_client *client, const char *hostname);
int sd_dhcp_client_set_vendor_class_identifier(sd_dhcp_client *client, const char *vci);
diff --git a/src/dhcp-manager/systemd-dhcp/src/systemd/sd-dhcp-lease.h b/src/dhcp-manager/systemd-dhcp/src/systemd/sd-dhcp-lease.h
index a3728a702f..1b0207b1c4 100644
--- a/src/dhcp-manager/systemd-dhcp/src/systemd/sd-dhcp-lease.h
+++ b/src/dhcp-manager/systemd-dhcp/src/systemd/sd-dhcp-lease.h
@@ -45,5 +45,10 @@ int sd_dhcp_lease_get_domainname(sd_dhcp_lease *lease, const char **domainname);
int sd_dhcp_lease_get_hostname(sd_dhcp_lease *lease, const char **hostname);
int sd_dhcp_lease_get_root_path(sd_dhcp_lease *lease, const char **root_path);
int sd_dhcp_lease_get_routes(sd_dhcp_lease *lease, struct sd_dhcp_route **routesgn);
+int sd_dhcp_lease_get_client_id(sd_dhcp_lease *lease, const uint8_t **client_id,
+ size_t *client_id_len);
+
+int sd_dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file);
+int sd_dhcp_lease_load(const char *lease_file, sd_dhcp_lease **ret);
#endif
diff --git a/src/dhcp-manager/systemd-dhcp/src/systemd/sd-dhcp6-client.h b/src/dhcp-manager/systemd-dhcp/src/systemd/sd-dhcp6-client.h
index c7f168fe21..38c1c3fb12 100644
--- a/src/dhcp-manager/systemd-dhcp/src/systemd/sd-dhcp6-client.h
+++ b/src/dhcp-manager/systemd-dhcp/src/systemd/sd-dhcp6-client.h
@@ -47,6 +47,7 @@ int sd_dhcp6_client_set_mac(sd_dhcp6_client *client, const uint8_t *addr,
size_t addr_len, uint16_t arp_type);
int sd_dhcp6_client_set_duid(sd_dhcp6_client *client, uint16_t type, uint8_t *duid,
size_t duid_len);
+int sd_dhcp6_client_set_ifname(sd_dhcp6_client *client, const char *ifname);
int sd_dhcp6_client_set_request_option(sd_dhcp6_client *client,
uint16_t option);
diff --git a/src/dhcp-manager/tests/Makefile.am b/src/dhcp-manager/tests/Makefile.am
index 9d6e7b97b4..9dc5dcb13d 100644
--- a/src/dhcp-manager/tests/Makefile.am
+++ b/src/dhcp-manager/tests/Makefile.am
@@ -13,27 +13,31 @@ AM_CPPFLAGS = \
noinst_PROGRAMS = \
test-dhcp-dhclient \
- test-dhcp-options
+ test-dhcp-utils
####### dhclient leases test #######
test_dhcp_dhclient_SOURCES = \
+ $(top_srcdir)/src/dhcp-manager/nm-dhcp-dhclient-utils.h \
+ $(top_srcdir)/src/dhcp-manager/nm-dhcp-dhclient-utils.c \
+ $(top_srcdir)/src/dhcp-manager/nm-dhcp-utils.h \
+ $(top_srcdir)/src/dhcp-manager/nm-dhcp-utils.c \
test-dhcp-dhclient.c
test_dhcp_dhclient_LDADD = \
$(top_builddir)/src/libNetworkManager.la
-####### DHCP options test #######
+####### DHCP utils test #######
-test_dhcp_options_SOURCES = \
- test-dhcp-options.c
+test_dhcp_utils_SOURCES = \
+ test-dhcp-utils.c
-test_dhcp_options_LDADD = \
+test_dhcp_utils_LDADD = \
$(top_builddir)/src/libNetworkManager.la
#################################
-TESTS = test-dhcp-dhclient test-dhcp-options
+TESTS = test-dhcp-dhclient test-dhcp-utils
EXTRA_DIST = \
test-dhclient-duid.leases \
diff --git a/src/dhcp-manager/tests/test-dhcp-dhclient.c b/src/dhcp-manager/tests/test-dhcp-dhclient.c
index ab496b38bd..544bd89efe 100644
--- a/src/dhcp-manager/tests/test-dhcp-dhclient.c
+++ b/src/dhcp-manager/tests/test-dhcp-dhclient.c
@@ -21,31 +21,44 @@
#include <glib.h>
#include <string.h>
#include <unistd.h>
+#include <arpa/inet.h>
+#include "gsystem-local-alloc.h"
+#include "NetworkManagerUtils.h"
#include "nm-dhcp-dhclient-utils.h"
+#include "nm-dhcp-utils.h"
#include "nm-utils.h"
#include "nm-ip4-config.h"
#include "nm-platform.h"
-#define DEBUG 0
+#define DEBUG 1
static void
test_config (const char *orig,
const char *expected,
const char *hostname,
const char *dhcp_client_id,
+ GBytes *expected_new_client_id,
const char *iface,
const char *anycast_addr)
{
- char *new;
+ gs_free char *new = NULL;
+ gs_unref_bytes GBytes *client_id = NULL;
+ gs_unref_bytes GBytes *new_client_id = NULL;
+
+ if (dhcp_client_id) {
+ client_id = nm_dhcp_utils_client_id_string_to_bytes (dhcp_client_id);
+ g_assert (client_id);
+ }
new = nm_dhcp_dhclient_create_config (iface,
FALSE,
- dhcp_client_id,
+ client_id,
anycast_addr,
hostname,
"/path/to/dhclient.conf",
- orig);
+ orig,
+ &new_client_id);
g_assert (new != NULL);
#if DEBUG
@@ -59,9 +72,13 @@ test_config (const char *orig,
new, expected);
}
#endif
- g_assert (strlen (new) == strlen (expected));
- g_assert (strcmp (new, expected) == 0);
- g_free (new);
+ g_assert_cmpstr (new, ==, expected);
+
+ if (expected_new_client_id) {
+ g_assert (new_client_id);
+ g_assert (g_bytes_equal (new_client_id, expected_new_client_id));
+ } else
+ g_assert (new_client_id == NULL);
}
/*******************************************/
@@ -83,11 +100,7 @@ static const char *orig_missing_expected = \
static void
test_orig_missing (void)
{
- test_config (NULL, orig_missing_expected,
- NULL,
- NULL,
- "eth0",
- NULL);
+ test_config (NULL, orig_missing_expected, NULL, NULL, NULL, "eth0", NULL);
}
/*******************************************/
@@ -118,6 +131,7 @@ test_override_client_id (void)
test_config (override_client_id_orig, override_client_id_expected,
NULL,
"11:22:33:44:55:66",
+ NULL,
"eth0",
NULL);
}
@@ -146,6 +160,7 @@ test_quote_client_id (void)
test_config (NULL, quote_client_id_expected,
NULL,
"1234",
+ NULL,
"eth0",
NULL);
}
@@ -174,6 +189,7 @@ test_ascii_client_id (void)
test_config (NULL, ascii_client_id_expected,
NULL,
"qb:cd:ef:12:34:56",
+ NULL,
"eth0",
NULL);
}
@@ -183,7 +199,7 @@ test_ascii_client_id (void)
static const char *hex_single_client_id_expected = \
"# Created by NetworkManager\n"
"\n"
- "send dhcp-client-identifier ab:cd:e:12:34:56; # added by NetworkManager\n"
+ "send dhcp-client-identifier ab:cd:0e:12:34:56; # added by NetworkManager\n"
"\n"
"option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;\n"
"option ms-classless-static-routes code 249 = array of unsigned integer 8;\n"
@@ -202,6 +218,84 @@ test_hex_single_client_id (void)
test_config (NULL, hex_single_client_id_expected,
NULL,
"ab:cd:e:12:34:56",
+ NULL,
+ "eth0",
+ NULL);
+}
+
+/*******************************************/
+
+static const char *existing_hex_client_id_orig = \
+ "send dhcp-client-identifier 00:30:04:20:7A:08;\n";
+
+static const char *existing_hex_client_id_expected = \
+ "# Created by NetworkManager\n"
+ "# Merged from /path/to/dhclient.conf\n"
+ "\n"
+ "send dhcp-client-identifier 00:30:04:20:7A:08;\n"
+ "\n"
+ "option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;\n"
+ "option ms-classless-static-routes code 249 = array of unsigned integer 8;\n"
+ "option wpad code 252 = string;\n"
+ "\n"
+ "also request rfc3442-classless-static-routes;\n"
+ "also request ms-classless-static-routes;\n"
+ "also request static-routes;\n"
+ "also request wpad;\n"
+ "also request ntp-servers;\n"
+ "\n";
+
+static void
+test_existing_hex_client_id (void)
+{
+ gs_unref_bytes GBytes *new_client_id = NULL;
+ const guint8 bytes[] = { 0x00, 0x30, 0x04,0x20, 0x7A, 0x08 };
+
+ new_client_id = g_bytes_new (bytes, sizeof (bytes));
+ test_config (existing_hex_client_id_orig, existing_hex_client_id_expected,
+ NULL,
+ NULL,
+ new_client_id,
+ "eth0",
+ NULL);
+}
+
+/*******************************************/
+
+#define EACID "qb:cd:ef:12:34:56"
+
+static const char *existing_ascii_client_id_orig = \
+ "send dhcp-client-identifier \"" EACID "\";\n";
+
+static const char *existing_ascii_client_id_expected = \
+ "# Created by NetworkManager\n"
+ "# Merged from /path/to/dhclient.conf\n"
+ "\n"
+ "send dhcp-client-identifier \"" EACID "\";\n"
+ "\n"
+ "option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;\n"
+ "option ms-classless-static-routes code 249 = array of unsigned integer 8;\n"
+ "option wpad code 252 = string;\n"
+ "\n"
+ "also request rfc3442-classless-static-routes;\n"
+ "also request ms-classless-static-routes;\n"
+ "also request static-routes;\n"
+ "also request wpad;\n"
+ "also request ntp-servers;\n"
+ "\n";
+
+static void
+test_existing_ascii_client_id (void)
+{
+ gs_unref_bytes GBytes *new_client_id = NULL;
+ char buf[STRLEN (EACID) + 1] = { 0 };
+
+ memcpy (buf + 1, EACID, STRLEN (EACID));
+ new_client_id = g_bytes_new (buf, sizeof (buf));
+ test_config (existing_ascii_client_id_orig, existing_ascii_client_id_expected,
+ NULL,
+ NULL,
+ new_client_id,
"eth0",
NULL);
}
@@ -234,6 +328,7 @@ test_override_hostname (void)
test_config (override_hostname_orig, override_hostname_expected,
"blahblah",
NULL,
+ NULL,
"eth0",
NULL);
}
@@ -268,6 +363,7 @@ test_existing_alsoreq (void)
test_config (existing_alsoreq_orig, existing_alsoreq_expected,
NULL,
NULL,
+ NULL,
"eth0",
NULL);
}
@@ -306,6 +402,7 @@ test_existing_multiline_alsoreq (void)
test_config (existing_multiline_alsoreq_orig, existing_multiline_alsoreq_expected,
NULL,
NULL,
+ NULL,
"eth0",
NULL);
}
@@ -615,6 +712,8 @@ main (int argc, char **argv)
g_test_add_func ("/dhcp/dhclient/quote_client_id", test_quote_client_id);
g_test_add_func ("/dhcp/dhclient/ascii_client_id", test_ascii_client_id);
g_test_add_func ("/dhcp/dhclient/hex_single_client_id", test_hex_single_client_id);
+ g_test_add_func ("/dhcp/dhclient/existing-hex-client-id", test_existing_hex_client_id);
+ g_test_add_func ("/dhcp/dhclient/existing-ascii-client-id", test_existing_ascii_client_id);
g_test_add_func ("/dhcp/dhclient/override_hostname", test_override_hostname);
g_test_add_func ("/dhcp/dhclient/existing_alsoreq", test_existing_alsoreq);
g_test_add_func ("/dhcp/dhclient/existing_multiline_alsoreq", test_existing_multiline_alsoreq);
diff --git a/src/dhcp-manager/tests/test-dhcp-options.c b/src/dhcp-manager/tests/test-dhcp-utils.c
index 15f5ee60b5..2c87664fa9 100644
--- a/src/dhcp-manager/tests/test-dhcp-options.c
+++ b/src/dhcp-manager/tests/test-dhcp-utils.c
@@ -652,6 +652,42 @@ test_ip4_prefix_classless (void)
g_hash_table_destroy (options);
}
+#define COMPARE_ID(src, is_str, expected, expected_len) \
+G_STMT_START { \
+ gs_unref_bytes GBytes *b = NULL; \
+ const char *p; \
+ gsize l; \
+ \
+ b = nm_dhcp_utils_client_id_string_to_bytes (src); \
+ g_assert (b); \
+ p = g_bytes_get_data (b, &l); \
+ if (is_str) { \
+ g_assert_cmpint (l, ==, expected_len + 1); \
+ g_assert_cmpint (((const char *) p)[0], ==, 0); \
+ g_assert (memcmp (p + 1, expected, expected_len) == 0); \
+ } else { \
+ g_assert_cmpint (l, ==, expected_len); \
+ g_assert (memcmp (p, expected, expected_len) == 0); \
+ } \
+} G_STMT_END
+
+static void
+test_client_id_from_string (void)
+{
+ const char *nothex = "asdfasdfasdfasdfasdfasdfasdf";
+ const char *allhex = "00:11:22:33:4:55:66:77:88";
+ const guint8 allhex_bin[] = { 0x00, 0x11, 0x22, 0x33, 0x04, 0x55, 0x66, 0x77, 0x88 };
+ const char *somehex = "00:11:22:33:44:55:asdfasdfasdf:99:10";
+ const char *nocolons = "0011223344559910";
+ const char *endcolon = "00:11:22:33:44:55:";
+
+ COMPARE_ID (nothex, TRUE, nothex, strlen (nothex));
+ COMPARE_ID (allhex, FALSE, allhex_bin, sizeof (allhex_bin));
+ COMPARE_ID (somehex, TRUE, somehex, strlen (somehex));
+ COMPARE_ID (nocolons, TRUE, nocolons, strlen (nocolons));
+ COMPARE_ID (endcolon, TRUE, endcolon, strlen (endcolon));
+}
+
NMTST_DEFINE ();
int main (int argc, char **argv)
@@ -678,6 +714,7 @@ int main (int argc, char **argv)
g_test_add_func ("/dhcp/ip4-missing-prefix-16", test_ip4_missing_prefix_16);
g_test_add_func ("/dhcp/ip4-missing-prefix-8", test_ip4_missing_prefix_8);
g_test_add_func ("/dhcp/ip4-prefix-classless", test_ip4_prefix_classless);
+ g_test_add_func ("/dhcp/client-id-from-string", test_client_id_from_string);
return g_test_run ();
}
diff --git a/src/main-utils.c b/src/main-utils.c
new file mode 100644
index 0000000000..55da4dfe41
--- /dev/null
+++ b/src/main-utils.c
@@ -0,0 +1,281 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager -- Network link manager
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2004 - 2012 Red Hat, Inc.
+ * Copyright (C) 2005 - 2008 Novell, Inc.
+ */
+
+#include <config.h>
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <locale.h>
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gmodule.h>
+
+#include "main-utils.h"
+#include "nm-posix-signals.h"
+#include "nm-logging.h"
+
+static sigset_t signal_set;
+static gboolean *quit_early = NULL;
+
+/*
+ * Thread function waiting for signals and processing them.
+ * Wait for signals in signal set. The semantics of sigwait() require that all
+ * threads (including the thread calling sigwait()) have the signal masked, for
+ * reliable operation. Otherwise, a signal that arrives while this thread is
+ * not blocked in sigwait() might be delivered to another thread.
+ */
+static void *
+signal_handling_thread (void *arg)
+{
+ GMainLoop *main_loop = arg;
+ int signo;
+
+ while (1) {
+ sigwait (&signal_set, &signo);
+
+ switch (signo) {
+ case SIGINT:
+ case SIGTERM:
+ nm_log_info (LOGD_CORE, "caught signal %d, shutting down normally.", signo);
+ *quit_early = TRUE; /* for quitting before entering the main loop */
+ g_main_loop_quit (main_loop);
+ break;
+ case SIGHUP:
+ /* Reread config stuff like system config files, VPN service files, etc */
+ nm_log_info (LOGD_CORE, "caught signal %d, not supported yet.", signo);
+ break;
+ case SIGPIPE:
+ /* silently ignore signal */
+ break;
+ default:
+ nm_log_err (LOGD_CORE, "caught unexpected signal %d", signo);
+ break;
+ }
+ }
+ return NULL;
+}
+
+/**
+ * nm_main_utils_setup_signals:
+ * @main_loop: the #GMainLoop to quit when SIGINT or SIGTERM is received
+ * @quit_early: location of a variable that will be set to TRUE when
+ * SIGINT or SIGTERM is received
+ *
+ * Mask the signals we are interested in and create a signal handling thread.
+ * Because all threads inherit the signal mask from their creator, all threads
+ * in the process will have the signals masked. That's why setup_signals() has
+ * to be called before creating other threads.
+ *
+ * Returns: %TRUE on success
+ */
+gboolean
+nm_main_utils_setup_signals (GMainLoop *main_loop, gboolean *quit_early_ptr)
+{
+ pthread_t signal_thread_id;
+ sigset_t old_sig_mask;
+ int status;
+
+ g_return_val_if_fail (main_loop != NULL, FALSE);
+ g_return_val_if_fail (quit_early_ptr != NULL, FALSE);
+
+ quit_early = quit_early_ptr;
+
+ sigemptyset (&signal_set);
+ sigaddset (&signal_set, SIGHUP);
+ sigaddset (&signal_set, SIGINT);
+ sigaddset (&signal_set, SIGTERM);
+ sigaddset (&signal_set, SIGPIPE);
+
+ /* Block all signals of interest. */
+ status = pthread_sigmask (SIG_BLOCK, &signal_set, &old_sig_mask);
+ if (status != 0) {
+ fprintf (stderr, _("Failed to set signal mask: %d"), status);
+ return FALSE;
+ }
+ /* Save original mask so that we could use it for child processes. */
+ nm_save_original_signal_mask (old_sig_mask);
+
+ /* Create the signal handling thread. */
+ status = pthread_create (&signal_thread_id, NULL, signal_handling_thread, main_loop);
+ if (status != 0) {
+ fprintf (stderr, _("Failed to create signal handling thread: %d"), status);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+gboolean
+nm_main_utils_write_pidfile (const char *pidfile)
+{
+ char pid[16];
+ int fd;
+ gboolean success = FALSE;
+
+ if ((fd = open (pidfile, O_CREAT|O_WRONLY|O_TRUNC, 00644)) < 0) {
+ fprintf (stderr, _("Opening %s failed: %s\n"), pidfile, strerror (errno));
+ return FALSE;
+ }
+
+ g_snprintf (pid, sizeof (pid), "%d", getpid ());
+ if (write (fd, pid, strlen (pid)) < 0)
+ fprintf (stderr, _("Writing to %s failed: %s\n"), pidfile, strerror (errno));
+ else
+ success = TRUE;
+
+ if (close (fd))
+ fprintf (stderr, _("Closing %s failed: %s\n"), pidfile, strerror (errno));
+
+ return success;
+}
+
+/**
+ * nm_main_utils_check_pidfile:
+ * @pidfile: the pid file
+ * @name: the process name
+ *
+ * Checks whether the pidfile already exists and contains PID of a running
+ * process.
+ *
+ * Returns: %TRUE if the specified pidfile already exists and contains the PID
+ * of a running process named @name, or %FALSE if not
+ */
+gboolean
+nm_main_utils_check_pidfile (const char *pidfile, const char *name)
+{
+ char *contents = NULL;
+ gsize len = 0;
+ glong pid;
+ char *proc_cmdline = NULL;
+ gboolean nm_running = FALSE;
+ const char *process_name;
+
+ /* Setup runtime directory */
+ if (g_mkdir_with_parents (NMRUNDIR, 0755) != 0) {
+ nm_log_err (LOGD_CORE, "Cannot create '%s': %s", NMRUNDIR, strerror (errno));
+ exit (1);
+ }
+
+ if (!g_file_get_contents (pidfile, &contents, &len, NULL))
+ return FALSE;
+
+ if (len <= 0)
+ goto done;
+
+ errno = 0;
+ pid = strtol (contents, NULL, 10);
+ if (pid <= 0 || pid > 65536 || errno)
+ goto done;
+
+ g_free (contents);
+ proc_cmdline = g_strdup_printf ("/proc/%ld/cmdline", pid);
+ if (!g_file_get_contents (proc_cmdline, &contents, &len, NULL))
+ goto done;
+
+ process_name = strrchr (contents, '/');
+ if (process_name)
+ process_name++;
+ else
+ process_name = contents;
+ if (strcmp (process_name, name) == 0) {
+ /* Check that the process exists */
+ if (kill (pid, 0) == 0) {
+ fprintf (stderr, _("%s is already running (pid %ld)\n"), name, pid);
+ nm_running = TRUE;
+ }
+ }
+
+done:
+ g_free (proc_cmdline);
+ g_free (contents);
+ return nm_running;
+}
+
+gboolean
+nm_main_utils_early_setup (const char *progname,
+ char **argv[],
+ int *argc,
+ GOptionEntry *options,
+ GOptionEntry *more_options,
+ const char *summary)
+{
+ GOptionContext *opt_ctx = NULL;
+ GError *error = NULL;
+ gboolean success = FALSE;
+ int i;
+
+ /* Make GIO ignore the remote VFS service; otherwise it tries to use the
+ * session bus to contact the remote service, and NM shouldn't ever be
+ * talking on the session bus. See rh #588745
+ */
+ setenv ("GIO_USE_VFS", "local", 1);
+
+ /*
+ * Set the umask to 0022, which results in 0666 & ~0022 = 0644.
+ * Otherwise, if root (or an su'ing user) has a wacky umask, we could
+ * write out an unreadable resolv.conf.
+ */
+ umask (022);
+
+ /* Ensure gettext() gets the right environment (bgo #666516) */
+ setlocale (LC_ALL, "");
+
+ bindtextdomain (GETTEXT_PACKAGE, NMLOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ textdomain (GETTEXT_PACKAGE);
+
+ if (getuid () != 0) {
+ fprintf (stderr, _("You must be root to run %s!\n"), progname);
+ exit (1);
+ }
+
+ for (i = 0; options[i].long_name; i++) {
+ if (!strcmp (options[i].long_name, "log-level"))
+ options[i].description = g_strdup_printf (options[i].description, nm_logging_all_levels_to_string ());
+ else if (!strcmp (options[i].long_name, "log-domains"))
+ options[i].description = g_strdup_printf (options[i].description, nm_logging_all_domains_to_string ());
+ }
+
+ /* Parse options */
+ opt_ctx = g_option_context_new (NULL);
+ g_option_context_set_translation_domain (opt_ctx, GETTEXT_PACKAGE);
+ g_option_context_set_ignore_unknown_options (opt_ctx, FALSE);
+ g_option_context_set_help_enabled (opt_ctx, TRUE);
+ g_option_context_add_main_entries (opt_ctx, options, NULL);
+ if (more_options)
+ g_option_context_add_main_entries (opt_ctx, more_options, NULL);
+ g_option_context_set_summary (opt_ctx, summary);
+
+ success = g_option_context_parse (opt_ctx, argc, argv, &error);
+ if (!success) {
+ fprintf (stderr, _("%s. Please use --help to see a list of valid options.\n"),
+ error->message);
+ g_clear_error (&error);
+ }
+ g_option_context_free (opt_ctx);
+
+ return success;
+}
+
diff --git a/src/main-utils.h b/src/main-utils.h
new file mode 100644
index 0000000000..472fa5e70e
--- /dev/null
+++ b/src/main-utils.h
@@ -0,0 +1,39 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager -- Network link manager
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ */
+
+#ifndef __MAIN_UTILS_H__
+#define __MAIN_UTILS_H__
+
+#include <glib.h>
+
+gboolean nm_main_utils_setup_signals (GMainLoop *main_loop, gboolean *quit_early_ptr);
+
+gboolean nm_main_utils_write_pidfile (const char *pidfile);
+
+gboolean nm_main_utils_check_pidfile (const char *pidfile, const char *name);
+
+gboolean nm_main_utils_early_setup (const char *progname,
+ char **argv[],
+ int *argc,
+ GOptionEntry *options,
+ GOptionEntry *more_options,
+ const char *summary);
+
+#endif /* __MAIN_UTILS_H__ */
diff --git a/src/main.c b/src/main.c
index f4f693d1e4..476d2a7711 100644
--- a/src/main.c
+++ b/src/main.c
@@ -42,6 +42,7 @@
#include "gsystem-local-alloc.h"
#include "nm-dbus-interface.h"
#include "NetworkManagerUtils.h"
+#include "main-utils.h"
#include "nm-manager.h"
#include "nm-linux-platform.h"
#include "nm-dns-manager.h"
@@ -65,161 +66,7 @@
#define NM_DEFAULT_PID_FILE NMRUNDIR "/NetworkManager.pid"
#define NM_DEFAULT_SYSTEM_STATE_FILE NMSTATEDIR "/NetworkManager.state"
-/*
- * Globals
- */
static GMainLoop *main_loop = NULL;
-static gboolean quit_early = FALSE;
-static sigset_t signal_set;
-
-void *signal_handling_thread (void *arg);
-/*
- * Thread function waiting for signals and processing them.
- * Wait for signals in signal set. The semantics of sigwait() require that all
- * threads (including the thread calling sigwait()) have the signal masked, for
- * reliable operation. Otherwise, a signal that arrives while this thread is
- * not blocked in sigwait() might be delivered to another thread.
- */
-void *
-signal_handling_thread (void *arg)
-{
- int signo;
-
- while (1) {
- sigwait (&signal_set, &signo);
-
- switch (signo) {
- case SIGINT:
- case SIGTERM:
- nm_log_info (LOGD_CORE, "caught signal %d, shutting down normally.", signo);
- quit_early = TRUE; /* for quitting before entering the main loop */
- g_main_loop_quit (main_loop);
- break;
- case SIGHUP:
- /* Reread config stuff like system config files, VPN service files, etc */
- nm_log_info (LOGD_CORE, "caught signal %d, not supported yet.", signo);
- break;
- case SIGPIPE:
- /* silently ignore signal */
- break;
- default:
- nm_log_err (LOGD_CORE, "caught unexpected signal %d", signo);
- break;
- }
- }
- return NULL;
-}
-
-/*
- * Mask the signals we are interested in and create a signal handling thread.
- * Because all threads inherit the signal mask from their creator, all threads
- * in the process will have the signals masked. That's why setup_signals() has
- * to be called before creating other threads.
- */
-static gboolean
-setup_signals (void)
-{
- pthread_t signal_thread_id;
- sigset_t old_sig_mask;
- int status;
-
- sigemptyset (&signal_set);
- sigaddset (&signal_set, SIGHUP);
- sigaddset (&signal_set, SIGINT);
- sigaddset (&signal_set, SIGTERM);
- sigaddset (&signal_set, SIGPIPE);
-
- /* Block all signals of interest. */
- status = pthread_sigmask (SIG_BLOCK, &signal_set, &old_sig_mask);
- if (status != 0) {
- fprintf (stderr, _("Failed to set signal mask: %d"), status);
- return FALSE;
- }
- /* Save original mask so that we could use it for child processes. */
- nm_save_original_signal_mask (old_sig_mask);
-
- /* Create the signal handling thread. */
- status = pthread_create (&signal_thread_id, NULL, signal_handling_thread, NULL);
- if (status != 0) {
- fprintf (stderr, _("Failed to create signal handling thread: %d"), status);
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean
-write_pidfile (const char *pidfile)
-{
- char pid[16];
- int fd;
- gboolean success = FALSE;
-
- if ((fd = open (pidfile, O_CREAT|O_WRONLY|O_TRUNC, 00644)) < 0) {
- fprintf (stderr, _("Opening %s failed: %s\n"), pidfile, strerror (errno));
- return FALSE;
- }
-
- g_snprintf (pid, sizeof (pid), "%d", getpid ());
- if (write (fd, pid, strlen (pid)) < 0)
- fprintf (stderr, _("Writing to %s failed: %s\n"), pidfile, strerror (errno));
- else
- success = TRUE;
-
- if (close (fd))
- fprintf (stderr, _("Closing %s failed: %s\n"), pidfile, strerror (errno));
-
- return success;
-}
-
-/* Check whether the pidfile already exists and contains PID of a running NetworkManager
- * Returns: FALSE - specified pidfile doesn't exist or doesn't contain PID of a running NM process
- * TRUE - specified pidfile already exists and contains PID of a running NM process
- */
-static gboolean
-check_pidfile (const char *pidfile)
-{
- char *contents = NULL;
- gsize len = 0;
- glong pid;
- char *proc_cmdline = NULL;
- gboolean nm_running = FALSE;
- const char *process_name;
-
- if (!g_file_get_contents (pidfile, &contents, &len, NULL))
- return FALSE;
-
- if (len <= 0)
- goto done;
-
- errno = 0;
- pid = strtol (contents, NULL, 10);
- if (pid <= 0 || pid > 65536 || errno)
- goto done;
-
- g_free (contents);
- proc_cmdline = g_strdup_printf ("/proc/%ld/cmdline", pid);
- if (!g_file_get_contents (proc_cmdline, &contents, &len, NULL))
- goto done;
-
- process_name = strrchr (contents, '/');
- if (process_name)
- process_name++;
- else
- process_name = contents;
- if (strcmp (process_name, "NetworkManager") == 0) {
- /* Check that the process exists */
- if (kill (pid, 0) == 0) {
- fprintf (stderr, _("NetworkManager is already running (pid %ld)\n"), pid);
- nm_running = TRUE;
- }
- }
-
-done:
- g_free (proc_cmdline);
- g_free (contents);
- return nm_running;
-}
static gboolean
parse_state_file (const char *filename,
@@ -330,6 +177,13 @@ _init_nm_debug (const char *debug)
}
}
+static void
+manager_configure_quit (NMManager *manager, gpointer user_data)
+{
+ nm_log_info (LOGD_CORE, "quitting now that startup is complete");
+ g_main_loop_quit (main_loop);
+}
+
/*
* main
*
@@ -337,7 +191,6 @@ _init_nm_debug (const char *debug)
int
main (int argc, char *argv[])
{
- GOptionContext *opt_ctx = NULL;
char *opt_log_level = NULL;
char *opt_log_domains = NULL;
gboolean become_daemon = TRUE, run_from_build_dir = FALSE;
@@ -347,7 +200,6 @@ main (int argc, char *argv[])
gs_free char *state_file = NULL;
gboolean wifi_enabled = TRUE, net_enabled = TRUE, wwan_enabled = TRUE, wimax_enabled = TRUE;
gboolean success, show_version = FALSE;
- int i;
NMManager *manager = NULL;
gs_unref_object NMVpnManager *vpn_manager = NULL;
gs_unref_object NMDnsManager *dns_mgr = NULL;
@@ -361,6 +213,7 @@ main (int argc, char *argv[])
GError *error = NULL;
gboolean wrote_pidfile = FALSE;
char *bad_domains = NULL;
+ gboolean quit_early = FALSE;
GOptionEntry options[] = {
{ "version", 'V', 0, G_OPTION_ARG_NONE, &show_version, N_("Print NetworkManager version and exit"), NULL },
@@ -377,66 +230,15 @@ main (int argc, char *argv[])
{NULL}
};
- /* Make GIO ignore the remote VFS service; otherwise it tries to use the
- * session bus to contact the remote service, and NM shouldn't ever be
- * talking on the session bus. See rh #588745
- */
- setenv ("GIO_USE_VFS", "local", 1);
-
- /*
- * Set the umask to 0022, which results in 0666 & ~0022 = 0644.
- * Otherwise, if root (or an su'ing user) has a wacky umask, we could
- * write out an unreadable resolv.conf.
- */
- umask (022);
-
- /* Set locale to be able to use environment variables */
- setlocale (LC_ALL, "");
-
- bindtextdomain (GETTEXT_PACKAGE, NMLOCALEDIR);
- bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
- textdomain (GETTEXT_PACKAGE);
-
- if (!g_module_supported ()) {
- fprintf (stderr, _("GModules are not supported on your platform!\n"));
- exit (1);
- }
-
- if (getuid () != 0) {
- fprintf (stderr, _("You must be root to run NetworkManager!\n"));
- exit (1);
- }
-
- for (i = 0; options[i].long_name; i++) {
- if (!strcmp (options[i].long_name, "log-level")) {
- options[i].description = g_strdup_printf (options[i].description,
- nm_logging_all_levels_to_string ());
- } else if (!strcmp (options[i].long_name, "log-domains")) {
- options[i].description = g_strdup_printf (options[i].description,
- nm_logging_all_domains_to_string ());
- }
- }
-
- /* Parse options */
- opt_ctx = g_option_context_new (NULL);
- g_option_context_set_translation_domain (opt_ctx, GETTEXT_PACKAGE);
- g_option_context_set_ignore_unknown_options (opt_ctx, FALSE);
- g_option_context_set_help_enabled (opt_ctx, TRUE);
- g_option_context_add_main_entries (opt_ctx, options, NULL);
- g_option_context_add_main_entries (opt_ctx, nm_config_get_options (), NULL);
-
- g_option_context_set_summary (opt_ctx,
- _("NetworkManager monitors all network connections and automatically\nchooses the best connection to use. It also allows the user to\nspecify wireless access points which wireless cards in the computer\nshould associate with."));
-
- success = g_option_context_parse (opt_ctx, &argc, &argv, &error);
- g_option_context_free (opt_ctx);
+ main_loop = g_main_loop_new (NULL, FALSE);
- if (!success) {
- fprintf (stderr, _("%s. Please use --help to see a list of valid options.\n"),
- error->message);
- g_clear_error (&error);
+ if (!nm_main_utils_early_setup ("NetworkManager",
+ &argv,
+ &argc,
+ options,
+ nm_config_get_options (),
+ _("NetworkManager monitors all network connections and automatically\nchooses the best connection to use. It also allows the user to\nspecify wireless access points which wireless cards in the computer\nshould associate with.")))
exit (1);
- }
if (show_version) {
fprintf (stdout, NM_DIST_VERSION "\n");
@@ -482,12 +284,6 @@ main (int argc, char *argv[])
g_free (path);
}
- /* Setup runtime directory */
- if (g_mkdir_with_parents (NMRUNDIR, 0755) != 0) {
- nm_log_err (LOGD_CORE, "Cannot create '%s': %s", NMRUNDIR, strerror (errno));
- exit (1);
- }
-
/* Ensure state directory exists */
if (g_mkdir_with_parents (NMSTATEDIR, 0755) != 0) {
nm_log_err (LOGD_CORE, "Cannot create '%s': %s", NMSTATEDIR, strerror (errno));
@@ -498,7 +294,7 @@ main (int argc, char *argv[])
state_file = state_file ? state_file : g_strdup (NM_DEFAULT_SYSTEM_STATE_FILE);
/* check pid file */
- if (check_pidfile (pidfile))
+ if (nm_main_utils_check_pidfile (pidfile, "NetworkManager"))
exit (1);
/* Read the config file and CLI overrides */
@@ -549,14 +345,13 @@ main (int argc, char *argv[])
saved_errno);
exit (1);
}
- if (write_pidfile (pidfile))
- wrote_pidfile = TRUE;
+ wrote_pidfile = nm_main_utils_write_pidfile (pidfile);
}
_init_nm_debug (nm_config_get_debug (config));
/* Set up unix signal handling - before creating threads, but after daemonizing! */
- if (!setup_signals ())
+ if (!nm_main_utils_setup_signals (main_loop, &quit_early))
exit (1);
if (g_fatal_warnings) {
@@ -592,8 +387,6 @@ main (int argc, char *argv[])
#endif
);
- main_loop = g_main_loop_new (NULL, FALSE);
-
/* Set up platform interaction layer */
nm_linux_platform_setup ();
@@ -662,6 +455,8 @@ main (int argc, char *argv[])
}
}
+ g_signal_connect (manager, NM_MANAGER_CONFIGURE_QUIT, G_CALLBACK (manager_configure_quit), config);
+
nm_manager_start (manager);
/* Make sure the loopback interface is up. If interface is down, we bring
@@ -680,10 +475,10 @@ main (int argc, char *argv[])
success = TRUE;
/* Told to quit before getting to the mainloop by the signal handler */
- if (quit_early == TRUE)
- goto done;
+ if (!quit_early)
+ g_main_loop_run (main_loop);
- g_main_loop_run (main_loop);
+ nm_manager_stop (manager);
done:
g_clear_object (&manager);
diff --git a/src/nm-active-connection.c b/src/nm-active-connection.c
index 73925659df..ff70d802bf 100644
--- a/src/nm-active-connection.c
+++ b/src/nm-active-connection.c
@@ -33,6 +33,7 @@
#include "NetworkManagerUtils.h"
#include "gsystem-local-alloc.h"
#include "nm-active-connection-glue.h"
+#include "nm-glib-compat.h"
/* Base class for anything implementing the Connection.Active D-Bus interface */
G_DEFINE_ABSTRACT_TYPE (NMActiveConnection, nm_active_connection, G_TYPE_OBJECT)
diff --git a/src/nm-config.c b/src/nm-config.c
index 1f41553355..aba4fa1a1b 100644
--- a/src/nm-config.c
+++ b/src/nm-config.c
@@ -61,6 +61,8 @@ typedef struct {
char **no_auto_default;
char **ignore_carrier;
+
+ gboolean configure_and_quit;
} NMConfigPrivate;
static NMConfig *singleton = NULL;
@@ -72,41 +74,36 @@ G_DEFINE_TYPE (NMConfig, nm_config, G_TYPE_OBJECT)
/************************************************************************/
static gboolean
-_parse_bool_str (const char *str, gboolean *out_value)
+_get_bool_value (GKeyFile *keyfile,
+ const char *section,
+ const char *key,
+ gboolean default_value)
{
- gboolean value;
- gsize len;
- char *s = NULL;
-
- g_return_val_if_fail (str, FALSE);
-
- while (g_ascii_isspace (*str))
- str++;
-
- if (!*str)
- return FALSE;
-
- len = strlen (str);
-
- if (g_ascii_isspace (str[len-1])) {
- str = s = g_strdup (str);
- g_strchomp (s);
- }
-
- if (!g_ascii_strcasecmp (str, "true") || !g_ascii_strcasecmp (str, "yes") || !g_ascii_strcasecmp (str, "on") || !g_ascii_strcasecmp (str, "1"))
- value = TRUE;
- else if (!g_ascii_strcasecmp (str, "false") || !g_ascii_strcasecmp (str, "no") || !g_ascii_strcasecmp (str, "off") || !g_ascii_strcasecmp (str, "0"))
- value = FALSE;
- else {
- g_free (s);
- return FALSE;
+ gboolean value = default_value;
+ char *str;
+
+ g_return_val_if_fail (keyfile != NULL, default_value);
+ g_return_val_if_fail (section != NULL, default_value);
+ g_return_val_if_fail (key != NULL, default_value);
+
+ str = g_key_file_get_value (keyfile, section, key, NULL);
+ if (!str)
+ return default_value;
+
+ g_strstrip (str);
+ if (str[0]) {
+ if (!g_ascii_strcasecmp (str, "true") || !g_ascii_strcasecmp (str, "yes") || !g_ascii_strcasecmp (str, "on") || !g_ascii_strcasecmp (str, "1"))
+ value = TRUE;
+ else if (!g_ascii_strcasecmp (str, "false") || !g_ascii_strcasecmp (str, "no") || !g_ascii_strcasecmp (str, "off") || !g_ascii_strcasecmp (str, "0"))
+ value = FALSE;
+ else {
+ nm_log_warn (LOGD_CORE, "Unrecognized value for %s.%s: '%s'. Assuming '%s'",
+ section, key, str, default_value ? "true" : "false");
+ }
}
- if (out_value)
- *out_value = value;
-
- g_free (s);
- return TRUE;
+ g_free (str);
+ return value;
}
/************************************************************************/
@@ -218,6 +215,12 @@ nm_config_get_connectivity_response (NMConfig *config)
return NM_CONFIG_GET_PRIVATE (config)->connectivity_response;
}
+gboolean
+nm_config_get_configure_and_quit (NMConfig *config)
+{
+ return NM_CONFIG_GET_PRIVATE (config)->configure_and_quit;
+}
+
char *
nm_config_get_value (NMConfig *config, const char *group, const char *key, GError **error)
{
@@ -513,7 +516,6 @@ nm_config_new (GError **error)
GFileInfo *info;
GPtrArray *confs;
const char *name;
- char *value;
int i;
GString *config_description;
@@ -583,23 +585,9 @@ nm_config_new (GError **error)
if (!priv->plugins && STRLEN (CONFIG_PLUGINS_DEFAULT) > 0)
priv->plugins = g_strsplit (CONFIG_PLUGINS_DEFAULT, ",", -1);
- value = g_key_file_get_value (priv->keyfile, "main", "monitor-connection-files", NULL);
- priv->monitor_connection_files = FALSE;
- if (value) {
- if (!_parse_bool_str (value, &priv->monitor_connection_files))
- nm_log_warn (LOGD_CORE, "Unrecognized value for main.monitor-connection-files: %s. Assuming 'false'", value);
- g_free (value);
- }
+ priv->monitor_connection_files = _get_bool_value (priv->keyfile, "main", "monitor-connection-files", FALSE);
- value = g_key_file_get_value (priv->keyfile, "main", "auth-polkit", NULL);
- priv->auth_polkit = NM_CONFIG_DEFAULT_AUTH_POLKIT;
- if (value) {
- if (!_parse_bool_str (value, &priv->auth_polkit)) {
- nm_log_warn (LOGD_CORE, "Unrecognized value for main.auth-polkit: %s. Assuming '%s'", value,
- NM_CONFIG_DEFAULT_AUTH_POLKIT ? "true" : "false");
- }
- g_free (value);
- }
+ priv->auth_polkit = _get_bool_value (priv->keyfile, "main", "auth-polkit", NM_CONFIG_DEFAULT_AUTH_POLKIT);
priv->dhcp_client = g_key_file_get_value (priv->keyfile, "main", "dhcp", NULL);
priv->dns_mode = g_key_file_get_value (priv->keyfile, "main", "dns", NULL);
@@ -623,6 +611,8 @@ nm_config_new (GError **error)
priv->ignore_carrier = g_key_file_get_string_list (priv->keyfile, "main", "ignore-carrier", NULL, NULL);
+ priv->configure_and_quit = _get_bool_value (priv->keyfile, "main", "configure-and-quit", FALSE);
+
return singleton;
}
diff --git a/src/nm-config.h b/src/nm-config.h
index 27da4cbbc6..56f75fb5f6 100644
--- a/src/nm-config.h
+++ b/src/nm-config.h
@@ -61,6 +61,7 @@ const char *nm_config_get_debug (NMConfig *config);
const char *nm_config_get_connectivity_uri (NMConfig *config);
guint nm_config_get_connectivity_interval (NMConfig *config);
const char *nm_config_get_connectivity_response (NMConfig *config);
+gboolean nm_config_get_configure_and_quit (NMConfig *config);
gboolean nm_config_get_ethernet_can_auto_default (NMConfig *config, NMDevice *device);
void nm_config_set_ethernet_no_auto_default (NMConfig *config, NMDevice *device);
diff --git a/src/nm-default-route-manager.c b/src/nm-default-route-manager.c
new file mode 100644
index 0000000000..ebe60c4df0
--- /dev/null
+++ b/src/nm-default-route-manager.c
@@ -0,0 +1,997 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager -- Network link manager
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ */
+
+
+#include "nm-default-route-manager.h"
+
+#include "config.h"
+
+#include "string.h"
+
+#include "nm-logging.h"
+#include "nm-device.h"
+#include "nm-vpn-connection.h"
+#include "nm-platform.h"
+#include "nm-manager.h"
+#include "nm-ip4-config.h"
+#include "nm-ip6-config.h"
+#include "nm-activation-request.h"
+
+typedef struct {
+ GPtrArray *entries_ip4;
+ GPtrArray *entries_ip6;
+} NMDefaultRouteManagerPrivate;
+
+#define NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEFAULT_ROUTE_MANAGER, NMDefaultRouteManagerPrivate))
+
+G_DEFINE_TYPE (NMDefaultRouteManager, nm_default_route_manager, G_TYPE_OBJECT)
+
+static NMDefaultRouteManager *_instance;
+
+#define _LOG(level, addr_family, ...) \
+ G_STMT_START { \
+ int __addr_family = (addr_family); \
+ guint64 __domain = __addr_family == AF_INET ? LOGD_IP4 : LOGD_IP6; \
+ \
+ if (nm_logging_enabled ((level), (__domain))) { \
+ char __ch = __addr_family == AF_INET ? '4' : '6'; \
+ char __prefix[30] = "default-route"; \
+ \
+ if ((self) != _instance) \
+ g_snprintf (__prefix, sizeof (__prefix), "default-route%c[%p]", __ch, (self)); \
+ else \
+ __prefix[STRLEN ("default-route")] = __ch; \
+ nm_log ((level), (__domain), \
+ "%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
+ __prefix _NM_UTILS_MACRO_REST(__VA_ARGS__)); \
+ } \
+ } G_STMT_END
+
+#define _LOGD(addr_family, ...) _LOG (LOGL_DEBUG, addr_family, __VA_ARGS__)
+#define _LOGI(addr_family, ...) _LOG (LOGL_INFO , addr_family, __VA_ARGS__)
+#define _LOGW(addr_family, ...) _LOG (LOGL_WARN , addr_family, __VA_ARGS__)
+#define _LOGE(addr_family, ...) _LOG (LOGL_ERR , addr_family, __VA_ARGS__)
+
+#define LOG_ENTRY_FMT "entry[%u/%s:%p:%s]"
+#define LOG_ENTRY_ARGS(entry_idx, entry) \
+ entry_idx, \
+ NM_IS_DEVICE (entry->source.pointer) ? "dev" : "vpn", \
+ entry->source.pointer, \
+ NM_IS_DEVICE (entry->source.pointer) ? nm_device_get_iface (entry->source.device) : nm_vpn_connection_get_connection_id (entry->source.vpn)
+
+/***********************************************************************************/
+
+typedef struct {
+ union {
+ void *pointer;
+ GObject *object;
+ NMDevice *device;
+ NMVpnConnection *vpn;
+ } source;
+ union {
+ NMPlatformIPRoute route;
+ NMPlatformIP4Route route4;
+ NMPlatformIP6Route route6;
+ };
+ gboolean synced; /* if true, we synced the entry to platform. We don't sync assumed devices */
+
+ /* it makes sense to order sources based on their priority, without
+ * actually adding a default route. This is useful to decide which
+ * DNS server to prefer. never_default entries are not synced to platform. */
+ gboolean never_default;
+
+ guint32 effective_metric;
+} Entry;
+
+typedef struct {
+ int addr_family;
+ GPtrArray *(*get_entries) (NMDefaultRouteManagerPrivate *priv);
+ const char *(*platform_route_to_string) (const NMPlatformIPRoute *route);
+ gboolean (*platform_route_delete_default) (int ifindex, guint32 metric);
+ guint32 (*route_metric_normalize) (guint32 metric);
+} VTableIP;
+
+static const VTableIP vtable_ip4, vtable_ip6;
+
+#define VTABLE_IS_IP4 (vtable->addr_family == AF_INET)
+
+static void
+_entry_free (Entry *entry)
+{
+ if (entry) {
+ g_object_unref (entry->source.object);
+ g_slice_free (Entry, entry);
+ }
+}
+
+static Entry *
+_entry_find_by_source (GPtrArray *entries, gpointer source, guint *out_idx)
+{
+ guint i;
+
+ for (i = 0; i < entries->len; i++) {
+ Entry *e = g_ptr_array_index (entries, i);
+
+ if (e->source.pointer == source) {
+ if (out_idx)
+ *out_idx = i;
+ return e;
+ }
+ }
+
+ if (out_idx)
+ *out_idx = G_MAXUINT;
+ return NULL;
+}
+
+static void
+_platform_route_sync_add (const VTableIP *vtable, NMDefaultRouteManager *self, guint32 metric)
+{
+ NMDefaultRouteManagerPrivate *priv = NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE (self);
+ GPtrArray *entries = vtable->get_entries (priv);
+ guint i;
+ gboolean has_unsynced_entry = FALSE;
+ Entry *entry = NULL;
+ gboolean success;
+
+ /* Find the entries for the given metric.
+ * The effective metric for synced entries is choosen in a way that it
+ * is unique (except for G_MAXUINT32, where a clash is not solvable). */
+ for (i = 0; i < entries->len; i++) {
+ Entry *e = g_ptr_array_index (entries, i);
+
+ if (e->never_default)
+ continue;
+
+ if (e->effective_metric != metric)
+ continue;
+
+ if (e->synced) {
+ g_assert (!entry || metric == G_MAXUINT32);
+ entry = e;
+ } else
+ has_unsynced_entry = TRUE;
+ }
+
+ /* For synced entries, we expect that the metric is chosen uniquely. */
+ g_assert (!entry || !has_unsynced_entry || metric == G_MAXUINT32);
+
+ /* we only add the route, if we have an (to be synced) entry for it. */
+ if (!entry)
+ return;
+
+ if (VTABLE_IS_IP4) {
+ success = nm_platform_ip4_route_add (entry->route.ifindex,
+ entry->route.source,
+ 0,
+ 0,
+ entry->route4.gateway,
+ entry->effective_metric,
+ entry->route.mss);
+ } else {
+ success = nm_platform_ip6_route_add (entry->route.ifindex,
+ entry->route.source,
+ in6addr_any,
+ 0,
+ entry->route6.gateway,
+ entry->effective_metric,
+ entry->route.mss);
+ }
+ if (!success)
+ _LOGW (vtable->addr_family, "failed to add default route %s with effective metric %u", vtable->platform_route_to_string (&entry->route), (guint) entry->effective_metric);
+}
+
+static void
+_platform_route_sync_flush (const VTableIP *vtable, NMDefaultRouteManager *self)
+{
+ NMDefaultRouteManagerPrivate *priv = NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE (self);
+ GPtrArray *entries = vtable->get_entries (priv);
+ GArray *routes;
+ guint i, j;
+
+ /* prune all other default routes from this device. */
+ if (VTABLE_IS_IP4)
+ routes = nm_platform_ip4_route_get_all (0, NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT);
+ else
+ routes = nm_platform_ip6_route_get_all (0, NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT);
+
+ for (i = 0; i < routes->len; i++) {
+ const NMPlatformIPRoute *route;
+ gboolean has_ifindex_synced = FALSE;
+ Entry *entry = NULL;
+
+ if (VTABLE_IS_IP4)
+ route = (const NMPlatformIPRoute *) &g_array_index (routes, NMPlatformIP4Route, i);
+ else
+ route = (const NMPlatformIPRoute *) &g_array_index (routes, NMPlatformIP6Route, i);
+
+ /* look at all entires and see if the route for this ifindex pair is
+ * a known entry. */
+ for (j = 0; j < entries->len; j++) {
+ Entry *e = g_ptr_array_index (entries, j);
+
+ if (e->never_default)
+ continue;
+
+ if ( e->route.ifindex == route->ifindex
+ && e->synced) {
+ has_ifindex_synced = TRUE;
+ if (e->effective_metric == route->metric)
+ entry = e;
+ }
+ }
+
+ /* we only delete the route if we don't have a matching entry,
+ * and there is at least one entry that references this ifindex
+ * (indicating that the ifindex is managed by us -- not assumed).
+ *
+ * Otherwise, don't delete the route because it's configured
+ * externally (and will be assumed -- or already is assumed).
+ */
+ if (has_ifindex_synced && !entry)
+ vtable->platform_route_delete_default (route->ifindex, route->metric);
+ }
+ g_array_free (routes, TRUE);
+}
+
+static int
+_sort_entries_cmp (gconstpointer a, gconstpointer b, gpointer user_data)
+{
+ guint32 m_a, m_b;
+ const Entry *e_a = *((const Entry **) a);
+ const Entry *e_b = *((const Entry **) b);
+
+ /* when comparing routes, we consider the (original) metric. */
+ m_a = e_a->route.metric;
+ m_b = e_b->route.metric;
+
+ /* we normalize route.metric already in _ipx_update_default_route().
+ * so we can just compare the metrics numerically */
+
+ if (m_a != m_b)
+ return (m_a < m_b) ? -1 : 1;
+
+ /* If the metrics are equal, we prefer the one that is !never_default */
+ if (!!e_a->never_default != !!e_b->never_default)
+ return e_a->never_default ? 1 : -1;
+
+ /* If the metrics are equal, we prefer the one that is assumed (!synced).
+ * Entries that we sync, can be modified so that only the best
+ * entry has a (deterministically) lowest metric.
+ * With assumed devices we cannot increase/change the metric.
+ * For example: two devices, both metric 0. One is assumed the other is
+ * synced.
+ * If we would choose the synced entry as best, we cannot
+ * increase the metric of the assumed one and we would have non-determinism.
+ * If we instead prefer the assumed device, we can increase the metric
+ * of the synced device and the assumed device is (deterministically)
+ * prefered.
+ * If both devices are assumed, we also have non-determinism, but also
+ * we don't reorder either.
+ */
+ if (!!e_a->synced != !!e_b->synced)
+ return e_a->synced ? 1 : -1;
+
+ /* otherwise, do not reorder */
+ return 0;
+}
+
+static void
+_resync_all (const VTableIP *vtable, NMDefaultRouteManager *self, const Entry *changed_entry, const Entry *old_entry, gboolean do_sync)
+{
+ NMDefaultRouteManagerPrivate *priv = NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE (self);
+ Entry *entry;
+ guint i;
+ gint64 last_metric = -1;
+ guint32 expected_metric;
+ GPtrArray *entries;
+ GHashTableIter iter;
+ gpointer ptr;
+ GHashTable *changed_metrics = g_hash_table_new (NULL, NULL);
+
+ entries = vtable->get_entries (priv);
+
+ if (old_entry && old_entry->synced) {
+ /* The old version obviously changed. */
+ g_hash_table_add (changed_metrics, GUINT_TO_POINTER (old_entry->effective_metric));
+ }
+
+ /* first iterate over all entries and adjust the effective metrics. */
+ for (i = 0; i < entries->len; i++) {
+ entry = g_ptr_array_index (entries, i);
+
+ g_assert (entry != old_entry);
+
+ if (entry->never_default)
+ continue;
+
+ if (!entry->synced) {
+ last_metric = MAX (last_metric, (gint64) entry->effective_metric);
+ continue;
+ }
+
+ expected_metric = entry->route.metric;
+ if ((gint64) expected_metric <= last_metric)
+ expected_metric = last_metric == G_MAXUINT32 ? G_MAXUINT32 : last_metric + 1;
+
+ if (changed_entry == entry) {
+ /* for the changed entry, the previous metric was either old_entry->effective_metric,
+ * or none. Hence, we only have to remember what is going to change. */
+ g_hash_table_add (changed_metrics, GUINT_TO_POINTER (expected_metric));
+ if (old_entry)
+ _LOGD (vtable->addr_family, LOG_ENTRY_FMT": update %s (%u -> %u)", LOG_ENTRY_ARGS (i, entry), vtable->platform_route_to_string (&entry->route), (guint) old_entry->effective_metric, (guint) expected_metric);
+ else
+ _LOGD (vtable->addr_family, LOG_ENTRY_FMT": add %s (%u)", LOG_ENTRY_ARGS (i, entry), vtable->platform_route_to_string (&entry->route), (guint) expected_metric);
+ } else if (entry->effective_metric != expected_metric) {
+ g_hash_table_add (changed_metrics, GUINT_TO_POINTER (entry->effective_metric));
+ g_hash_table_add (changed_metrics, GUINT_TO_POINTER (expected_metric));
+ _LOGD (vtable->addr_family, LOG_ENTRY_FMT": resync metric %s (%u -> %u)", LOG_ENTRY_ARGS (i, entry), vtable->platform_route_to_string (&entry->route), (guint) entry->effective_metric, (guint) expected_metric);
+ }
+
+ entry->effective_metric = expected_metric;
+ last_metric = expected_metric;
+ }
+
+ if (do_sync) {
+ g_hash_table_iter_init (&iter, changed_metrics);
+ while (g_hash_table_iter_next (&iter, &ptr, NULL))
+ _platform_route_sync_add (vtable, self, GPOINTER_TO_UINT (ptr));
+ _platform_route_sync_flush (vtable, self);
+ }
+
+ g_hash_table_unref (changed_metrics);
+}
+
+static void
+_entry_at_idx_update (const VTableIP *vtable, NMDefaultRouteManager *self, guint entry_idx, const Entry *old_entry, gboolean do_sync)
+{
+ NMDefaultRouteManagerPrivate *priv = NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE (self);
+ Entry *entry;
+ GPtrArray *entries;
+
+ entries = vtable->get_entries (priv);
+ g_assert (entry_idx < entries->len);
+
+ entry = g_ptr_array_index (entries, entry_idx);
+
+ g_assert ( !old_entry
+ || (entry->source.pointer == old_entry->source.pointer && entry->route.ifindex == old_entry->route.ifindex));
+
+ if (!entry->synced) {
+ entry->effective_metric = entry->route.metric;
+ _LOGD (vtable->addr_family, LOG_ENTRY_FMT": %s %s%s",
+ LOG_ENTRY_ARGS (entry_idx, entry),
+ old_entry ? "update" : "add",
+ vtable->platform_route_to_string (&entry->route),
+ entry->never_default ? " (never-default)" : (entry->synced ? "" : " (not synced)"));
+ }
+
+ g_ptr_array_sort_with_data (entries, _sort_entries_cmp, NULL);
+
+ _resync_all (vtable, self, entry, old_entry, do_sync);
+}
+
+static void
+_entry_at_idx_remove (const VTableIP *vtable, NMDefaultRouteManager *self, guint entry_idx, gboolean do_sync)
+{
+ NMDefaultRouteManagerPrivate *priv = NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE (self);
+ Entry *entry;
+ GPtrArray *entries;
+
+ entries = vtable->get_entries (priv);
+
+ g_assert (entry_idx < entries->len);
+
+ entry = g_ptr_array_index (entries, entry_idx);
+
+ _LOGD (vtable->addr_family, LOG_ENTRY_FMT": remove %s (%u%s)", LOG_ENTRY_ARGS (entry_idx, entry), vtable->platform_route_to_string (&entry->route), (guint) entry->effective_metric, entry->synced ? "" : ", not synced");
+
+ /* Remove the entry from the list (but don't free it yet) */
+ g_ptr_array_index (entries, entry_idx) = NULL;
+ g_ptr_array_remove_index (entries, entry_idx);
+
+ _resync_all (vtable, self, NULL, entry, do_sync);
+
+ _entry_free (entry);
+}
+
+/***********************************************************************************/
+
+static void
+_ipx_update_default_route (const VTableIP *vtable, NMDefaultRouteManager *self, gpointer source)
+{
+ NMDefaultRouteManagerPrivate *priv;
+ Entry *entry;
+ guint entry_idx;
+ const NMPlatformIPRoute *default_route = NULL;
+ union {
+ NMPlatformIPRoute vx;
+ NMPlatformIP4Route v4;
+ NMPlatformIP6Route v6;
+ } rt;
+ int ip_ifindex;
+ GPtrArray *entries;
+ NMDevice *device = NULL;
+ NMVpnConnection *vpn = NULL;
+ gboolean never_default = FALSE;
+ gboolean synced;
+
+ g_return_if_fail (NM_IS_DEFAULT_ROUTE_MANAGER (self));
+ if (NM_IS_DEVICE (source))
+ device = source;
+ else if (NM_IS_VPN_CONNECTION (source))
+ vpn = source;
+ else
+ g_return_if_reached ();
+
+ if (device)
+ ip_ifindex = nm_device_get_ip_ifindex (device);
+ else {
+ ip_ifindex = nm_vpn_connection_get_ip_ifindex (vpn);
+
+ if (ip_ifindex <= 0) {
+ NMDevice *parent = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (vpn));
+
+ if (parent)
+ ip_ifindex = nm_device_get_ip_ifindex (parent);
+ }
+ }
+
+ priv = NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE (self);
+
+ entries = vtable->get_entries (priv);
+ entry = _entry_find_by_source (entries, source, &entry_idx);
+
+ if ( entry
+ && entry->route.ifindex != ip_ifindex) {
+ /* Strange... the ifindex changed... Remove the device and start again. */
+ _LOGD (vtable->addr_family, "ifindex of "LOG_ENTRY_FMT" changed: %d -> %d",
+ LOG_ENTRY_ARGS (entry_idx, entry),
+ entry->route.ifindex, ip_ifindex);
+
+ g_object_freeze_notify (G_OBJECT (self));
+ _entry_at_idx_remove (vtable, self, entry_idx, FALSE);
+ g_assert (!_entry_find_by_source (entries, source, NULL));
+ _ipx_update_default_route (vtable, self, source);
+ g_object_thaw_notify (G_OBJECT (self));
+ return;
+ }
+
+ /* get the @default_route from the device. */
+ if (ip_ifindex > 0) {
+ if (device) {
+ if (VTABLE_IS_IP4)
+ default_route = (const NMPlatformIPRoute *) nm_device_get_ip4_default_route (device);
+ else
+ default_route = (const NMPlatformIPRoute *) nm_device_get_ip6_default_route (device);
+ } else {
+ NMConnection *connection = nm_active_connection_get_connection ((NMActiveConnection *) vpn);
+
+ if ( connection
+ && nm_vpn_connection_get_vpn_state (vpn) == NM_VPN_CONNECTION_STATE_ACTIVATED) {
+
+ if (VTABLE_IS_IP4) {
+ NMIP4Config *vpn_config;
+
+ vpn_config = nm_vpn_connection_get_ip4_config (vpn);
+ if (vpn_config) {
+ never_default = nm_ip4_config_get_never_default (vpn_config);
+ memset (&rt.v4, 0, sizeof (rt.v4));
+ rt.v4.ifindex = ip_ifindex;
+ rt.v4.source = NM_IP_CONFIG_SOURCE_VPN;
+ rt.v4.gateway = nm_vpn_connection_get_ip4_internal_gateway (vpn);
+ rt.v4.metric = nm_vpn_connection_get_ip4_route_metric (vpn);
+ rt.v4.mss = nm_ip4_config_get_mss (vpn_config);
+ default_route = &rt.vx;
+ }
+ } else {
+ NMIP6Config *vpn_config;
+
+ vpn_config = nm_vpn_connection_get_ip6_config (vpn);
+ if (vpn_config) {
+ const struct in6_addr *int_gw = nm_vpn_connection_get_ip6_internal_gateway (vpn);
+
+ never_default = nm_ip6_config_get_never_default (vpn_config);
+ memset (&rt.v6, 0, sizeof (rt.v6));
+ rt.v6.ifindex = ip_ifindex;
+ rt.v6.source = NM_IP_CONFIG_SOURCE_VPN;
+ rt.v6.gateway = int_gw ? *int_gw : in6addr_any;
+ rt.v6.metric = nm_vpn_connection_get_ip6_route_metric (vpn);
+ rt.v6.mss = nm_ip6_config_get_mss (vpn_config);
+ default_route = &rt.vx;
+ }
+ }
+ }
+ }
+ }
+ g_assert (!default_route || default_route->plen == 0);
+
+ /* if the source is never_default or the device uses an assumed connection,
+ * we don't sync the route. */
+ synced = !never_default && (!device || !nm_device_uses_assumed_connection (device));
+
+ if (!entry && !default_route)
+ /* nothing to do */;
+ else if (!entry) {
+ /* add */
+ entry = g_slice_new0 (Entry);
+ entry->source.object = g_object_ref (source);
+
+ if (VTABLE_IS_IP4)
+ entry->route4 = *((const NMPlatformIP4Route *) default_route);
+ else
+ entry->route6 = *((const NMPlatformIP6Route *) default_route);
+
+ /* only use normalized metrics */
+ entry->route.metric = vtable->route_metric_normalize (entry->route.metric);
+ entry->route.ifindex = ip_ifindex;
+ entry->never_default = never_default;
+ entry->effective_metric = entry->route.metric;
+ entry->synced = synced;
+
+ g_ptr_array_add (entries, entry);
+ _entry_at_idx_update (vtable, self, entries->len - 1, NULL, TRUE);
+ } else if (default_route) {
+ /* update */
+ Entry old_entry, new_entry;
+
+ new_entry = *entry;
+ if (VTABLE_IS_IP4)
+ new_entry.route4 = *((const NMPlatformIP4Route *) default_route);
+ else
+ new_entry.route6 = *((const NMPlatformIP6Route *) default_route);
+ /* only use normalized metrics */
+ new_entry.route.metric = vtable->route_metric_normalize (new_entry.route.metric);
+ new_entry.route.ifindex = ip_ifindex;
+ new_entry.never_default = never_default;
+ new_entry.synced = synced;
+
+ if (memcmp (entry, &new_entry, sizeof (new_entry)) == 0)
+ return;
+
+ old_entry = *entry;
+ *entry = new_entry;
+ _entry_at_idx_update (vtable, self, entry_idx, &old_entry, TRUE);
+ } else {
+ /* delete */
+ _entry_at_idx_remove (vtable, self, entry_idx, TRUE);
+ }
+}
+
+void
+nm_default_route_manager_ip4_update_default_route (NMDefaultRouteManager *self, gpointer source)
+{
+ _ipx_update_default_route (&vtable_ip4, self, source);
+}
+
+void
+nm_default_route_manager_ip6_update_default_route (NMDefaultRouteManager *self, gpointer source)
+{
+ _ipx_update_default_route (&vtable_ip6, self, source);
+}
+
+/***********************************************************************************/
+
+static void
+_ipx_remove_default_route (const VTableIP *vtable, NMDefaultRouteManager *self, gpointer source)
+{
+ NMDefaultRouteManagerPrivate *priv;
+ guint entry_idx;
+
+ g_return_if_fail (NM_IS_DEFAULT_ROUTE_MANAGER (self));
+ g_return_if_fail (NM_IS_DEVICE (source) || NM_IS_VPN_CONNECTION (source));
+
+ priv = NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE (self);
+
+ if (_entry_find_by_source (vtable->get_entries (priv), source, &entry_idx))
+ _entry_at_idx_remove (vtable, self, entry_idx, TRUE);
+}
+
+void
+nm_default_route_manager_ip4_remove_default_route (NMDefaultRouteManager *self, gpointer source)
+{
+ _ipx_remove_default_route (&vtable_ip4, self, source);
+}
+
+void
+nm_default_route_manager_ip6_remove_default_route (NMDefaultRouteManager *self, gpointer source)
+{
+ _ipx_remove_default_route (&vtable_ip6, self, source);
+}
+
+/***********************************************************************************/
+
+static gboolean
+_ipx_connection_has_default_route (const VTableIP *vtable, NMDefaultRouteManager *self, NMConnection *connection)
+{
+ const char *method;
+ NMSettingIPConfig *s_ip;
+
+ g_return_val_if_fail (NM_IS_DEFAULT_ROUTE_MANAGER (self), FALSE);
+ g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
+
+ if (VTABLE_IS_IP4)
+ s_ip = nm_connection_get_setting_ip4_config (connection);
+ else
+ s_ip = nm_connection_get_setting_ip6_config (connection);
+ if (!s_ip || nm_setting_ip_config_get_never_default (s_ip))
+ return FALSE;
+
+ if (VTABLE_IS_IP4) {
+ method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG);
+ if ( !method
+ || !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)
+ || !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL))
+ return FALSE;
+ } else {
+ method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP6_CONFIG);
+ if ( !method
+ || !strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)
+ || !strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL))
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+gboolean
+nm_default_route_manager_ip4_connection_has_default_route (NMDefaultRouteManager *self, NMConnection *connection)
+{
+ return _ipx_connection_has_default_route (&vtable_ip4, self, connection);
+}
+
+gboolean
+nm_default_route_manager_ip6_connection_has_default_route (NMDefaultRouteManager *self, NMConnection *connection)
+{
+ return _ipx_connection_has_default_route (&vtable_ip6, self, connection);
+}
+
+/***********************************************************************************/
+
+static NMDevice *
+_ipx_get_best_device (const VTableIP *vtable, NMDefaultRouteManager *self, const GSList *devices)
+{
+ NMDefaultRouteManagerPrivate *priv;
+ GPtrArray *entries;
+ guint i;
+
+ g_return_val_if_fail (NM_IS_DEFAULT_ROUTE_MANAGER (self), NULL);
+
+ if (!devices)
+ return NULL;
+
+ priv = NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE (self);
+ entries = vtable->get_entries (priv);
+
+ for (i = 0; i < entries->len; i++) {
+ Entry *entry = g_ptr_array_index (entries, i);
+
+ if (!NM_IS_DEVICE (entry->source.pointer))
+ continue;
+
+ g_assert (!entry->never_default);
+
+ if (g_slist_find ((GSList *) devices, entry->source.device))
+ return entry->source.pointer;
+ }
+ return NULL;
+}
+
+/** _ipx_get_best_activating_device:
+ * @vtable: the virtual table
+ * @self: #NMDefaultRouteManager
+ * @devices: list of devices to be searched. Only devices from this list will be considered
+ * @fully_activated: if #TRUE, only search for devices that are fully activated. Otherwise,
+ * search if there is a best device going to be activated. In the latter case, this will
+ * return NULL if the best device is already activated.
+ * @preferred_device: if not-NULL, this device is preferred if there are more devices with
+ * the same priority.
+ **/
+static NMDevice *
+_ipx_get_best_activating_device (const VTableIP *vtable, NMDefaultRouteManager *self, const GSList *devices, NMDevice *preferred_device)
+{
+ NMDefaultRouteManagerPrivate *priv;
+ const GSList *iter;
+ NMDevice *best_device = NULL;
+ guint32 best_prio = G_MAXUINT32;
+ NMDevice *best_activated_device;
+
+ g_return_val_if_fail (NM_IS_DEFAULT_ROUTE_MANAGER (self), NULL);
+
+ priv = NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE (self);
+
+ best_activated_device = _ipx_get_best_device (vtable, self, devices);
+
+ for (iter = devices; iter; iter = g_slist_next (iter)) {
+ NMDevice *device = NM_DEVICE (iter->data);
+ guint32 prio;
+ Entry *entry;
+
+ entry = _entry_find_by_source (vtable->get_entries (priv), device, NULL);
+
+ if (entry) {
+ /* of all the device that have an entry, we already know that best_activated_device
+ * is the best. entry cannot be better. */
+ if (entry->source.device != best_activated_device)
+ continue;
+ prio = entry->effective_metric;
+ } else {
+ NMDeviceState state = nm_device_get_state (device);
+
+ if ( state <= NM_DEVICE_STATE_DISCONNECTED
+ || state >= NM_DEVICE_STATE_DEACTIVATING)
+ continue;
+
+ if (!_ipx_connection_has_default_route (vtable, self, nm_device_get_connection (device)))
+ continue;
+
+ prio = nm_device_get_ip4_route_metric (device);
+ }
+ prio = vtable->route_metric_normalize (prio);
+
+ if ( !best_device
+ || prio < best_prio
+ || (prio == best_prio && preferred_device == device)) {
+ best_device = device;
+ best_prio = prio;
+ }
+ }
+
+ /* There's only a best activating device if the best device
+ * among all activating and already-activated devices is a
+ * still-activating one.
+ */
+ if (best_device && nm_device_get_state (best_device) >= NM_DEVICE_STATE_SECONDARIES)
+ return NULL;
+ return best_device;
+}
+
+NMDevice *
+nm_default_route_manager_ip4_get_best_device (NMDefaultRouteManager *self, const GSList *devices, gboolean fully_activated, NMDevice *preferred_device)
+{
+ if (fully_activated)
+ return _ipx_get_best_device (&vtable_ip4, self, devices);
+ else
+ return _ipx_get_best_activating_device (&vtable_ip4, self, devices, preferred_device);
+}
+
+NMDevice *
+nm_default_route_manager_ip6_get_best_device (NMDefaultRouteManager *self, const GSList *devices, gboolean fully_activated, NMDevice *preferred_device)
+{
+ if (fully_activated)
+ return _ipx_get_best_device (&vtable_ip6, self, devices);
+ else
+ return _ipx_get_best_activating_device (&vtable_ip6, self, devices, preferred_device);
+}
+
+/***********************************************************************************/
+
+static gpointer
+_ipx_get_best_config (const VTableIP *vtable,
+ NMDefaultRouteManager *self,
+ gboolean ignore_never_default,
+ const char **out_ip_iface,
+ NMActiveConnection **out_ac,
+ NMDevice **out_device,
+ NMVpnConnection **out_vpn)
+{
+ NMDefaultRouteManagerPrivate *priv;
+ GPtrArray *entries;
+ guint i;
+ gpointer config_result = NULL;
+
+ g_return_val_if_fail (NM_IS_DEFAULT_ROUTE_MANAGER (self), NULL);
+
+ if (out_ip_iface)
+ *out_ip_iface = NULL;
+ if (out_ac)
+ *out_ac = NULL;
+ if (out_device)
+ *out_device = NULL;
+ if (out_vpn)
+ *out_vpn = NULL;
+
+ priv = NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE (self);
+
+ g_return_val_if_fail (NM_IS_DEFAULT_ROUTE_MANAGER (self), NULL);
+
+ priv = NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE (self);
+ entries = vtable->get_entries (priv);
+
+ for (i = 0; i < entries->len; i++) {
+ Entry *entry = g_ptr_array_index (entries, i);
+
+ if (!NM_IS_DEVICE (entry->source.pointer)) {
+ NMVpnConnection *vpn = NM_VPN_CONNECTION (entry->source.vpn);
+
+ if (entry->never_default && !ignore_never_default)
+ continue;
+
+ if (VTABLE_IS_IP4)
+ config_result = nm_vpn_connection_get_ip4_config (vpn);
+ else
+ config_result = nm_vpn_connection_get_ip6_config (vpn);
+ g_assert (config_result);
+
+ if (out_vpn)
+ *out_vpn = vpn;
+ if (out_ac)
+ *out_ac = NM_ACTIVE_CONNECTION (vpn);
+ if (out_ip_iface)
+ *out_ip_iface = nm_vpn_connection_get_ip_iface (vpn);
+ } else {
+ NMDevice *device = entry->source.device;
+ NMActRequest *req;
+
+ if (VTABLE_IS_IP4)
+ config_result = nm_device_get_ip4_config (device);
+ else
+ config_result = nm_device_get_ip6_config (device);
+ g_assert (config_result);
+ req = nm_device_get_act_request (device);
+ g_assert (req);
+
+ if (out_device)
+ *out_device = device;
+ if (out_ac)
+ *out_ac = NM_ACTIVE_CONNECTION (req);
+ if (out_ip_iface)
+ *out_ip_iface = nm_device_get_ip_iface (device);
+ }
+ break;
+ }
+
+ return config_result;
+}
+
+NMIP4Config *
+nm_default_route_manager_ip4_get_best_config (NMDefaultRouteManager *self,
+ gboolean ignore_never_default,
+ const char **out_ip_iface,
+ NMActiveConnection **out_ac,
+ NMDevice **out_device,
+ NMVpnConnection **out_vpn)
+{
+ return _ipx_get_best_config (&vtable_ip4,
+ self,
+ ignore_never_default,
+ out_ip_iface,
+ out_ac,
+ out_device,
+ out_vpn);
+}
+
+NMIP6Config *
+nm_default_route_manager_ip6_get_best_config (NMDefaultRouteManager *self,
+ gboolean ignore_never_default,
+ const char **out_ip_iface,
+ NMActiveConnection **out_ac,
+ NMDevice **out_device,
+ NMVpnConnection **out_vpn)
+{
+ return _ipx_get_best_config (&vtable_ip6,
+ self,
+ ignore_never_default,
+ out_ip_iface,
+ out_ac,
+ out_device,
+ out_vpn);
+}
+
+/***********************************************************************************/
+
+static GPtrArray *
+_v4_get_entries (NMDefaultRouteManagerPrivate *priv)
+{
+ return priv->entries_ip4;
+}
+
+static GPtrArray *
+_v6_get_entries (NMDefaultRouteManagerPrivate *priv)
+{
+ return priv->entries_ip6;
+}
+
+static gboolean
+_v4_platform_route_delete_default (int ifindex, guint32 metric)
+{
+ return nm_platform_ip4_route_delete (ifindex, 0, 0, metric);
+}
+
+static gboolean
+_v6_platform_route_delete_default (int ifindex, guint32 metric)
+{
+ return nm_platform_ip6_route_delete (ifindex, in6addr_any, 0, metric);
+}
+
+static guint32
+_v4_route_metric_normalize (guint32 metric)
+{
+ return metric;
+}
+
+static const VTableIP vtable_ip4 = {
+ .addr_family = AF_INET,
+ .get_entries = _v4_get_entries,
+ .platform_route_to_string = (const char *(*)(const NMPlatformIPRoute *)) nm_platform_ip4_route_to_string,
+ .platform_route_delete_default = _v4_platform_route_delete_default,
+ .route_metric_normalize = _v4_route_metric_normalize,
+};
+
+static const VTableIP vtable_ip6 = {
+ .addr_family = AF_INET6,
+ .get_entries = _v6_get_entries,
+ .platform_route_to_string = (const char *(*)(const NMPlatformIPRoute *)) nm_platform_ip6_route_to_string,
+ .platform_route_delete_default = _v6_platform_route_delete_default,
+ .route_metric_normalize = nm_utils_ip6_route_metric_normalize,
+};
+
+/***********************************************************************************/
+
+NMDefaultRouteManager *
+nm_default_route_manager_get ()
+{
+ if (G_UNLIKELY (!_instance)) {
+ _instance = NM_DEFAULT_ROUTE_MANAGER (g_object_new (NM_TYPE_DEFAULT_ROUTE_MANAGER, NULL));
+ g_object_add_weak_pointer (G_OBJECT (_instance), (gpointer *) &_instance);
+ }
+ return _instance;
+}
+
+/***********************************************************************************/
+
+static void
+nm_default_route_manager_init (NMDefaultRouteManager *self)
+{
+ NMDefaultRouteManagerPrivate *priv = NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE (self);
+
+ priv->entries_ip4 = g_ptr_array_new_full (0, (GDestroyNotify) _entry_free);
+ priv->entries_ip6 = g_ptr_array_new_full (0, (GDestroyNotify) _entry_free);
+}
+
+static void
+dispose (GObject *object)
+{
+ NMDefaultRouteManager *self = NM_DEFAULT_ROUTE_MANAGER (object);
+ NMDefaultRouteManagerPrivate *priv = NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE (self);
+
+ if (priv->entries_ip4) {
+ g_ptr_array_free (priv->entries_ip4, TRUE);
+ priv->entries_ip4 = NULL;
+ }
+ if (priv->entries_ip6) {
+ g_ptr_array_free (priv->entries_ip6, TRUE);
+ priv->entries_ip6 = NULL;
+ }
+
+ G_OBJECT_CLASS (nm_default_route_manager_parent_class)->dispose (object);
+}
+
+static void
+nm_default_route_manager_class_init (NMDefaultRouteManagerClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (NMDefaultRouteManagerPrivate));
+
+ /* virtual methods */
+ object_class->dispose = dispose;
+}
+
diff --git a/src/nm-default-route-manager.h b/src/nm-default-route-manager.h
new file mode 100644
index 0000000000..88fb59f0c9
--- /dev/null
+++ b/src/nm-default-route-manager.h
@@ -0,0 +1,77 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager -- Network link manager
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ */
+
+#include <glib-object.h>
+
+#include "nm-connection.h"
+#include "nm-types.h"
+
+#ifndef __NETWORKMANAGER_DEFAULT_ROUTE_MANAGER_H__
+#define __NETWORKMANAGER_DEFAULT_ROUTE_MANAGER_H__
+
+
+#define NM_TYPE_DEFAULT_ROUTE_MANAGER (nm_default_route_manager_get_type ())
+#define NM_DEFAULT_ROUTE_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEFAULT_ROUTE_MANAGER, NMDefaultRouteManager))
+#define NM_DEFAULT_ROUTE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEFAULT_ROUTE_MANAGER, NMDefaultRouteManagerClass))
+#define NM_IS_DEFAULT_ROUTE_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEFAULT_ROUTE_MANAGER))
+#define NM_IS_DEFAULT_ROUTE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEFAULT_ROUTE_MANAGER))
+#define NM_DEFAULT_ROUTE_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEFAULT_ROUTE_MANAGER, NMDefaultRouteManagerClass))
+
+
+
+struct _NMDefaultRouteManager {
+ GObject parent;
+};
+
+typedef struct {
+ GObjectClass parent;
+} NMDefaultRouteManagerClass;
+
+GType nm_default_route_manager_get_type (void);
+
+NMDefaultRouteManager *nm_default_route_manager_get (void);
+
+void nm_default_route_manager_ip4_update_default_route (NMDefaultRouteManager *manager, gpointer source);
+void nm_default_route_manager_ip6_update_default_route (NMDefaultRouteManager *manager, gpointer source);
+
+void nm_default_route_manager_ip4_remove_default_route (NMDefaultRouteManager *manager, gpointer source);
+void nm_default_route_manager_ip6_remove_default_route (NMDefaultRouteManager *manager, gpointer source);
+
+gboolean nm_default_route_manager_ip4_connection_has_default_route (NMDefaultRouteManager *manager, NMConnection *connection);
+gboolean nm_default_route_manager_ip6_connection_has_default_route (NMDefaultRouteManager *manager, NMConnection *connection);
+
+NMDevice *nm_default_route_manager_ip4_get_best_device (NMDefaultRouteManager *manager, const GSList *devices, gboolean fully_activated, NMDevice *preferred_device);
+NMDevice *nm_default_route_manager_ip6_get_best_device (NMDefaultRouteManager *manager, const GSList *devices, gboolean fully_activated, NMDevice *preferred_device);
+
+NMIP4Config *nm_default_route_manager_ip4_get_best_config (NMDefaultRouteManager *manager,
+ gboolean ignore_never_default,
+ const char **out_ip_iface,
+ NMActiveConnection **out_ac,
+ NMDevice **out_device,
+ NMVpnConnection **out_vpn);
+NMIP6Config *nm_default_route_manager_ip6_get_best_config (NMDefaultRouteManager *manager,
+ gboolean ignore_never_default,
+ const char **out_ip_iface,
+ NMActiveConnection **out_ac,
+ NMDevice **out_device,
+ NMVpnConnection **out_vpn);
+
+#endif /* NM_DEFAULT_ROUTE_MANAGER_H */
+
diff --git a/src/nm-iface-helper.c b/src/nm-iface-helper.c
new file mode 100644
index 0000000000..62f1b2aba4
--- /dev/null
+++ b/src/nm-iface-helper.c
@@ -0,0 +1,529 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager -- Network link manager
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ */
+
+#include <config.h>
+#include <glib.h>
+#include <glib-unix.h>
+#include <getopt.h>
+#include <locale.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <glib/gi18n.h>
+#include <string.h>
+#include <sys/resource.h>
+#include <sys/stat.h>
+#include <signal.h>
+
+#include "gsystem-local-alloc.h"
+#include "NetworkManagerUtils.h"
+#include "nm-linux-platform.h"
+#include "nm-dhcp-manager.h"
+#include "nm-logging.h"
+#include "main-utils.h"
+#include "nm-rdisc.h"
+#include "nm-lndp-rdisc.h"
+#include "nm-utils.h"
+
+#if !defined(NM_DIST_VERSION)
+# define NM_DIST_VERSION VERSION
+#endif
+
+#define NMIH_PID_FILE_FMT NMRUNDIR "/nm-iface-helper-%d.pid"
+
+static GMainLoop *main_loop = NULL;
+static char *ifname = NULL;
+static int ifindex = -1;
+static gboolean slaac_required = FALSE;
+static gboolean dhcp4_required = FALSE;
+static int tempaddr = NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN;
+static int priority = -1;
+
+static void
+dhcp4_state_changed (NMDhcpClient *client,
+ NMDhcpState state,
+ NMIP4Config *ip4_config,
+ GHashTable *options,
+ gpointer user_data)
+{
+ static NMIP4Config *last_config = NULL;
+ NMIP4Config *existing;
+
+ g_return_if_fail (!ip4_config || NM_IS_IP4_CONFIG (ip4_config));
+
+ nm_log_dbg (LOGD_DHCP4, "(%s): new DHCPv4 client state %d", ifname, state);
+
+ switch (state) {
+ case NM_DHCP_STATE_BOUND:
+ g_assert (ip4_config);
+ existing = nm_ip4_config_capture (ifindex, FALSE);
+ if (last_config)
+ nm_ip4_config_subtract (existing, last_config);
+
+ nm_ip4_config_merge (existing, ip4_config);
+ if (!nm_ip4_config_commit (existing, ifindex))
+ nm_log_warn (LOGD_DHCP4, "(%s): failed to apply DHCPv4 config", ifname);
+
+ if (last_config) {
+ g_object_unref (last_config);
+ last_config = nm_ip4_config_new ();
+ nm_ip4_config_replace (last_config, ip4_config, NULL);
+ }
+ break;
+ case NM_DHCP_STATE_TIMEOUT:
+ case NM_DHCP_STATE_DONE:
+ case NM_DHCP_STATE_FAIL:
+ if (dhcp4_required) {
+ nm_log_warn (LOGD_DHCP4, "(%s): DHCPv4 timed out or failed, quitting...", ifname);
+ g_main_loop_quit (main_loop);
+ } else
+ nm_log_warn (LOGD_DHCP4, "(%s): DHCPv4 timed out or failed", ifname);
+ break;
+ default:
+ break;
+ }
+}
+
+static void
+rdisc_config_changed (NMRDisc *rdisc, NMRDiscConfigMap changed, gpointer user_data)
+{
+ static NMIP6Config *last_config = NULL;
+ NMIP6Config *existing;
+ NMIP6Config *ip6_config;
+ static int system_support = -1;
+ guint ifa_flags = 0x00;
+ int i;
+
+ if (system_support == -1) {
+ /*
+ * Check, if both libnl and the kernel are recent enough,
+ * to help user space handling RA. If it's not supported,
+ * we have no ipv6-privacy and must add autoconf addresses
+ * as /128. The reason for the /128 is to prevent the kernel
+ * from adding a prefix route for this address.
+ **/
+ system_support = nm_platform_check_support_libnl_extended_ifa_flags () &&
+ nm_platform_check_support_kernel_extended_ifa_flags ();
+ }
+
+ if (system_support)
+ ifa_flags = IFA_F_NOPREFIXROUTE;
+ if (tempaddr == NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR
+ || tempaddr == NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR)
+ {
+ /* without system_support, this flag will be ignored. Still set it, doesn't seem to do any harm. */
+ ifa_flags |= IFA_F_MANAGETEMPADDR;
+ }
+
+ ip6_config = nm_ip6_config_new ();
+
+ if (changed & NM_RDISC_CONFIG_GATEWAYS) {
+ /* Use the first gateway as ordered in router discovery cache. */
+ if (rdisc->gateways->len) {
+ NMRDiscGateway *gateway = &g_array_index (rdisc->gateways, NMRDiscGateway, 0);
+
+ nm_ip6_config_set_gateway (ip6_config, &gateway->address);
+ } else
+ nm_ip6_config_set_gateway (ip6_config, NULL);
+ }
+
+ if (changed & NM_RDISC_CONFIG_ADDRESSES) {
+ /* Rebuild address list from router discovery cache. */
+ nm_ip6_config_reset_addresses (ip6_config);
+
+ /* rdisc->addresses contains at most max_addresses entries.
+ * This is different from what the kernel does, which
+ * also counts static and temporary addresses when checking
+ * max_addresses.
+ **/
+ for (i = 0; i < rdisc->addresses->len; i++) {
+ NMRDiscAddress *discovered_address = &g_array_index (rdisc->addresses, NMRDiscAddress, i);
+ NMPlatformIP6Address address;
+
+ memset (&address, 0, sizeof (address));
+ address.address = discovered_address->address;
+ address.plen = system_support ? 64 : 128;
+ address.timestamp = discovered_address->timestamp;
+ address.lifetime = discovered_address->lifetime;
+ address.preferred = discovered_address->preferred;
+ if (address.preferred > address.lifetime)
+ address.preferred = address.lifetime;
+ address.source = NM_IP_CONFIG_SOURCE_RDISC;
+ address.flags = ifa_flags;
+
+ nm_ip6_config_add_address (ip6_config, &address);
+ }
+ }
+
+ if (changed & NM_RDISC_CONFIG_ROUTES) {
+ /* Rebuild route list from router discovery cache. */
+ nm_ip6_config_reset_routes (ip6_config);
+
+ for (i = 0; i < rdisc->routes->len; i++) {
+ NMRDiscRoute *discovered_route = &g_array_index (rdisc->routes, NMRDiscRoute, i);
+ NMPlatformIP6Route route;
+
+ /* Only accept non-default routes. The router has no idea what the
+ * local configuration or user preferences are, so sending routes
+ * with a prefix length of 0 is quite rude and thus ignored.
+ */
+ if (discovered_route->plen > 0) {
+ memset (&route, 0, sizeof (route));
+ route.network = discovered_route->network;
+ route.plen = discovered_route->plen;
+ route.gateway = discovered_route->gateway;
+ route.source = NM_IP_CONFIG_SOURCE_RDISC;
+ route.metric = priority;
+
+ nm_ip6_config_add_route (ip6_config, &route);
+ }
+ }
+ }
+
+ if (changed & NM_RDISC_CONFIG_DHCP_LEVEL) {
+ /* Unsupported until systemd DHCPv6 is ready */
+ }
+
+ /* hop_limit == 0 is a special value "unspecified", so do not touch
+ * in this case */
+ if (changed & NM_RDISC_CONFIG_HOP_LIMIT && rdisc->hop_limit > 0) {
+ char val[16];
+
+ g_snprintf (val, sizeof (val), "%d", rdisc->hop_limit);
+ nm_platform_sysctl_set (nm_utils_ip6_property_path (ifname, "hop_limit"), val);
+ }
+
+ if (changed & NM_RDISC_CONFIG_MTU) {
+ char val[16];
+
+ g_snprintf (val, sizeof (val), "%d", rdisc->mtu);
+ nm_platform_sysctl_set (nm_utils_ip6_property_path (ifname, "mtu"), val);
+ }
+
+ existing = nm_ip6_config_capture (ifindex, FALSE, tempaddr);
+ if (last_config)
+ nm_ip6_config_subtract (existing, last_config);
+
+ nm_ip6_config_merge (existing, ip6_config);
+ if (!nm_ip6_config_commit (existing, ifindex))
+ nm_log_warn (LOGD_IP6, "(%s): failed to apply IPv6 config", ifname);
+
+ if (last_config) {
+ g_object_unref (last_config);
+ last_config = nm_ip6_config_new ();
+ nm_ip6_config_replace (last_config, ip6_config, NULL);
+ }
+}
+
+static void
+rdisc_ra_timeout (NMRDisc *rdisc, gpointer user_data)
+{
+ if (slaac_required) {
+ nm_log_warn (LOGD_IP6, "(%s): IPv6 timed out or failed, quitting...", ifname);
+ g_main_loop_quit (main_loop);
+ } else
+ nm_log_warn (LOGD_IP6, "(%s): IPv6 timed out or failed", ifname);
+}
+
+static gboolean
+quit_handler (gpointer user_data)
+{
+ gboolean *quit_early_ptr = user_data;
+
+ *quit_early_ptr = TRUE;
+ g_main_loop_quit (main_loop);
+ return G_SOURCE_CONTINUE;
+}
+
+static void
+setup_signals (gboolean *quit_early_ptr)
+{
+ sigset_t sigmask;
+
+ sigemptyset (&sigmask);
+ pthread_sigmask (SIG_SETMASK, &sigmask, NULL);
+
+ signal (SIGPIPE, SIG_IGN);
+ g_unix_signal_add (SIGINT, quit_handler, quit_early_ptr);
+ g_unix_signal_add (SIGTERM, quit_handler, quit_early_ptr);
+}
+
+int
+main (int argc, char *argv[])
+{
+ char *opt_log_level = NULL;
+ char *opt_log_domains = NULL;
+ gboolean debug = FALSE, g_fatal_warnings = FALSE, become_daemon = FALSE;
+ gboolean show_version = FALSE, slaac = FALSE;
+ char *bad_domains = NULL, *dhcp4_hostname = NULL, *uuid = NULL;
+ char *iid_str = NULL, *dhcp4_clientid = NULL, *dhcp4_address = NULL;
+ gs_unref_object NMDhcpManager *dhcp_mgr = NULL;
+ GError *error = NULL;
+ gboolean wrote_pidfile = FALSE;
+ gs_free char *pidfile = NULL;
+ gboolean quit_early = FALSE;
+ gs_unref_object NMDhcpClient *dhcp4_client = NULL;
+ gs_unref_object NMRDisc *rdisc = NULL;
+ GByteArray *hwaddr = NULL;
+ size_t hwaddr_len = 0;
+ gconstpointer tmp;
+ gs_free NMUtilsIPv6IfaceId *iid = NULL;
+
+ GOptionEntry options[] = {
+ /* Interface/IP config */
+ { "ifname", 'i', 0, G_OPTION_ARG_STRING, &ifname, N_("The interface to manage"), N_("eth0") },
+ { "uuid", 'u', 0, G_OPTION_ARG_STRING, &uuid, N_("Connection UUID"), N_("661e8cd0-b618-46b8-9dc9-31a52baaa16b") },
+ { "slaac", 's', 0, G_OPTION_ARG_NONE, &slaac, N_("Whether to manage IPv6 SLAAC"), NULL },
+ { "slaac-required", '6', 0, G_OPTION_ARG_NONE, &slaac_required, N_("Whether SLAAC must be successful"), NULL },
+ { "slaac-tempaddr", 't', 0, G_OPTION_ARG_INT, &tempaddr, N_("Use an IPv6 temporary privacy address"), NULL },
+ { "dhcp4", 'd', 0, G_OPTION_ARG_STRING, &dhcp4_address, N_("Current DHCPv4 address"), NULL },
+ { "dhcp4-required", '4', 0, G_OPTION_ARG_NONE, &dhcp4_required, N_("Whether DHCPv4 must be successful"), NULL },
+ { "dhcp4-clientid", 'c', 0, G_OPTION_ARG_STRING, &dhcp4_clientid, N_("Hex-encoded DHCPv4 client ID"), NULL },
+ { "dhcp4-hostname", 'h', 0, G_OPTION_ARG_STRING, &dhcp4_hostname, N_("Hostname to send to DHCP server"), N_("barbar") },
+ { "priority", 'p', 0, G_OPTION_ARG_INT, &priority, N_("Route priority"), N_("10") },
+ { "iid", 'e', 0, G_OPTION_ARG_STRING, &iid_str, N_("Hex-encoded Interface Identifier"), N_("") },
+
+ /* Logging/debugging */
+ { "version", 'V', 0, G_OPTION_ARG_NONE, &show_version, N_("Print NetworkManager version and exit"), NULL },
+ { "no-daemon", 'n', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &become_daemon, N_("Don't become a daemon"), NULL },
+ { "debug", 'b', 0, G_OPTION_ARG_NONE, &debug, N_("Don't become a daemon, and log to stderr"), NULL },
+ { "log-level", 0, 0, G_OPTION_ARG_STRING, &opt_log_level, N_("Log level: one of [%s]"), "INFO" },
+ { "log-domains", 0, 0, G_OPTION_ARG_STRING, &opt_log_domains,
+ N_("Log domains separated by ',': any combination of [%s]"),
+ "PLATFORM,RFKILL,WIFI" },
+ { "g-fatal-warnings", 0, 0, G_OPTION_ARG_NONE, &g_fatal_warnings, N_("Make all warnings fatal"), NULL },
+ {NULL}
+ };
+
+ setpgid (getpid (), getpid ());
+
+ if (!nm_main_utils_early_setup ("nm-iface-helper",
+ &argv,
+ &argc,
+ options,
+ NULL,
+ _("nm-iface-helper is a small, standalone process that manages a single network interface.")))
+ exit (1);
+
+ if (show_version) {
+ fprintf (stdout, NM_DIST_VERSION "\n");
+ exit (0);
+ }
+
+ if (!ifname || !uuid) {
+ fprintf (stderr, _("An interface name and UUID are required\n"));
+ exit (1);
+ }
+
+ if (!nm_logging_setup (opt_log_level,
+ opt_log_domains,
+ &bad_domains,
+ &error)) {
+ fprintf (stderr,
+ _("%s. Please use --help to see a list of valid options.\n"),
+ error->message);
+ exit (1);
+ } else if (bad_domains) {
+ fprintf (stderr,
+ _("Ignoring unrecognized log domain(s) '%s' passed on command line.\n"),
+ bad_domains);
+ g_clear_pointer (&bad_domains, g_free);
+ }
+
+ pidfile = g_strdup_printf (NMIH_PID_FILE_FMT, ifindex);
+ g_assert (pidfile);
+
+ /* check pid file */
+ if (nm_main_utils_check_pidfile (pidfile, "nm-iface-helper"))
+ exit (1);
+
+ if (become_daemon && !debug) {
+ if (daemon (0, 0) < 0) {
+ int saved_errno;
+
+ saved_errno = errno;
+ fprintf (stderr, _("Could not daemonize: %s [error %u]\n"),
+ g_strerror (saved_errno),
+ saved_errno);
+ exit (1);
+ }
+ if (nm_main_utils_write_pidfile (pidfile))
+ wrote_pidfile = TRUE;
+ }
+
+ /* Set up unix signal handling - before creating threads, but after daemonizing! */
+ main_loop = g_main_loop_new (NULL, FALSE);
+ setup_signals (&quit_early);
+
+ if (g_fatal_warnings) {
+ GLogLevelFlags fatal_mask;
+
+ fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
+ fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
+ g_log_set_always_fatal (fatal_mask);
+ }
+
+ nm_logging_syslog_openlog (debug);
+
+#if !GLIB_CHECK_VERSION (2, 35, 0)
+ g_type_init ();
+#endif
+
+ nm_log_info (LOGD_CORE, "nm-iface-helper (version " NM_DIST_VERSION ") is starting...");
+
+ /* Set up platform interaction layer */
+ nm_linux_platform_setup ();
+
+ ifindex = nm_platform_link_get_ifindex (ifname);
+ if (ifindex <= 0) {
+ fprintf (stderr, _("Failed to find interface index for %s\n"), ifname);
+ exit (1);
+ }
+
+ tmp = nm_platform_link_get_address (ifindex, &hwaddr_len);
+ if (tmp) {
+ hwaddr = g_byte_array_sized_new (hwaddr_len);
+ g_byte_array_append (hwaddr, tmp, hwaddr_len);
+ }
+
+ if (iid_str) {
+ GBytes *bytes;
+ gsize ignored = 0;
+
+ bytes = nm_utils_hexstr2bin (iid_str);
+ if (!bytes || g_bytes_get_size (bytes) != sizeof (*iid)) {
+ fprintf (stderr, _("(%s): Invalid IID %s\n"), ifname, iid_str);
+ exit (1);
+ }
+ iid = g_bytes_unref_to_data (bytes, &ignored);
+ }
+
+ priority = MAX (0, priority);
+
+ if (dhcp4_address) {
+ nm_platform_sysctl_set (nm_utils_ip4_property_path (ifname, "promote_secondaries"), "1");
+
+ /* Initialize DHCP manager */
+ dhcp_mgr = nm_dhcp_manager_get ();
+ g_assert (dhcp_mgr != NULL);
+
+ dhcp4_client = nm_dhcp_manager_start_ip4 (dhcp_mgr,
+ ifname,
+ ifindex,
+ hwaddr,
+ uuid,
+ priority,
+ !!dhcp4_hostname,
+ dhcp4_hostname,
+ dhcp4_clientid,
+ 45,
+ NULL,
+ dhcp4_address);
+ g_assert (dhcp4_client);
+ g_signal_connect (dhcp4_client,
+ NM_DHCP_CLIENT_SIGNAL_STATE_CHANGED,
+ G_CALLBACK (dhcp4_state_changed),
+ NULL);
+ }
+
+ if (slaac) {
+ nm_platform_link_set_user_ipv6ll_enabled (ifindex, TRUE);
+
+ rdisc = nm_lndp_rdisc_new (ifindex, ifname);
+ g_assert (rdisc);
+
+ if (iid)
+ nm_rdisc_set_iid (rdisc, *iid);
+
+ nm_platform_sysctl_set (nm_utils_ip6_property_path (ifname, "accept_ra"), "1");
+ nm_platform_sysctl_set (nm_utils_ip6_property_path (ifname, "accept_ra_defrtr"), "0");
+ nm_platform_sysctl_set (nm_utils_ip6_property_path (ifname, "accept_ra_pinfo"), "0");
+ nm_platform_sysctl_set (nm_utils_ip6_property_path (ifname, "accept_ra_rtr_pref"), "0");
+
+ g_signal_connect (rdisc,
+ NM_RDISC_CONFIG_CHANGED,
+ G_CALLBACK (rdisc_config_changed),
+ NULL);
+ g_signal_connect (rdisc,
+ NM_RDISC_RA_TIMEOUT,
+ G_CALLBACK (rdisc_ra_timeout),
+ NULL);
+ nm_rdisc_start (rdisc);
+ }
+
+ if (!quit_early)
+ g_main_loop_run (main_loop);
+
+ g_clear_pointer (&hwaddr, g_byte_array_unref);
+
+ nm_logging_syslog_closelog ();
+
+ if (pidfile && wrote_pidfile)
+ unlink (pidfile);
+
+ nm_log_info (LOGD_CORE, "exiting");
+ exit (0);
+}
+
+/*******************************************************/
+/* Stub functions */
+
+gconstpointer nm_config_get (void);
+const char *nm_config_get_dhcp_client (gpointer unused);
+gboolean nm_config_get_configure_and_quit (gpointer unused);
+gconstpointer nm_dbus_manager_get (void);
+void nm_dbus_manager_register_exported_type (gpointer unused, GType gtype, gconstpointer unused2);
+void nm_dbus_manager_register_object (gpointer unused, const char *path, gpointer object);
+
+gconstpointer
+nm_config_get (void)
+{
+ return GUINT_TO_POINTER (1);
+}
+
+const char *
+nm_config_get_dhcp_client (gpointer unused)
+{
+ return "internal";
+}
+
+gboolean
+nm_config_get_configure_and_quit (gpointer unused)
+{
+ return TRUE;
+}
+
+gconstpointer
+nm_dbus_manager_get (void)
+{
+ return GUINT_TO_POINTER (1);
+}
+
+void
+nm_dbus_manager_register_exported_type (gpointer unused, GType gtype, gconstpointer unused2)
+{
+}
+
+void
+nm_dbus_manager_register_object (gpointer unused, const char *path, gpointer object)
+{
+}
+
diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c
index 343aabcd0b..7b59160a36 100644
--- a/src/nm-ip4-config.c
+++ b/src/nm-ip4-config.c
@@ -20,10 +20,12 @@
*/
#include <string.h>
+#include <arpa/inet.h>
#include "nm-ip4-config.h"
#include "nm-utils.h"
+#include "nm-platform.h"
#include "nm-dbus-manager.h"
#include "nm-dbus-glib-types.h"
#include "nm-ip4-config-glue.h"
@@ -58,9 +60,11 @@ G_STATIC_ASSERT (G_MAXUINT >= 0xFFFFFFFF);
enum {
PROP_0,
- PROP_GATEWAY,
+ PROP_ADDRESS_DATA,
PROP_ADDRESSES,
+ PROP_ROUTE_DATA,
PROP_ROUTES,
+ PROP_GATEWAY,
PROP_NAMESERVERS,
PROP_DOMAINS,
PROP_SEARCHES,
@@ -79,6 +83,7 @@ nm_ip4_config_new (void)
}
+#ifndef NM_IFACE_HELPER
void
nm_ip4_config_export (NMIP4Config *config)
{
@@ -90,6 +95,7 @@ nm_ip4_config_export (NMIP4Config *config)
nm_dbus_manager_register_object (nm_dbus_manager_get (), priv->path, config);
}
}
+#endif
const char *
nm_ip4_config_get_dbus_path (const NMIP4Config *config)
@@ -175,7 +181,7 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf)
NMIP4Config *config;
NMIP4ConfigPrivate *priv;
guint i;
- guint lowest_metric = G_MAXUINT;
+ guint32 lowest_metric = G_MAXUINT32;
guint32 old_gateway = 0;
gboolean has_gateway = FALSE;
@@ -190,7 +196,7 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf)
g_array_unref (priv->routes);
priv->addresses = nm_platform_ip4_address_get_all (ifindex);
- priv->routes = nm_platform_ip4_route_get_all (ifindex, TRUE);
+ priv->routes = nm_platform_ip4_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL);
/* Extract gateway from default route */
old_gateway = priv->gateway;
@@ -234,6 +240,8 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf)
}
/* actually, nobody should be connected to the signal, just to be sure, notify */
+ _NOTIFY (config, PROP_ADDRESS_DATA);
+ _NOTIFY (config, PROP_ROUTE_DATA);
_NOTIFY (config, PROP_ADDRESSES);
_NOTIFY (config, PROP_ROUTES);
if (priv->gateway != old_gateway)
@@ -246,7 +254,7 @@ gboolean
nm_ip4_config_commit (const NMIP4Config *config, int ifindex)
{
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
- int mtu = nm_ip4_config_get_mtu (config);
+ guint32 mtu = nm_ip4_config_get_mtu (config);
int i;
g_return_val_if_fail (ifindex > 0, FALSE);
@@ -272,13 +280,6 @@ nm_ip4_config_commit (const NMIP4Config *config, int ifindex)
&& nm_ip4_config_destination_is_direct (config, route->network, route->plen))
continue;
- /* Don't add the default route if the connection
- * is never supposed to be the default connection.
- */
- if ( nm_ip4_config_get_never_default (config)
- && NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route))
- continue;
-
g_array_append_vals (routes, route, 1);
}
@@ -296,7 +297,7 @@ nm_ip4_config_commit (const NMIP4Config *config, int ifindex)
}
void
-nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIP4Config *setting, int default_route_metric)
+nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIPConfig *setting, guint32 default_route_metric)
{
guint naddresses, nroutes, nnameservers, nsearches;
int i;
@@ -304,65 +305,69 @@ nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIP4Config *setting, i
if (!setting)
return;
+ g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
+
g_object_freeze_notify (G_OBJECT (config));
- naddresses = nm_setting_ip4_config_get_num_addresses (setting);
- nroutes = nm_setting_ip4_config_get_num_routes (setting);
- nnameservers = nm_setting_ip4_config_get_num_dns (setting);
- nsearches = nm_setting_ip4_config_get_num_dns_searches (setting);
+ naddresses = nm_setting_ip_config_get_num_addresses (setting);
+ nroutes = nm_setting_ip_config_get_num_routes (setting);
+ nnameservers = nm_setting_ip_config_get_num_dns (setting);
+ nsearches = nm_setting_ip_config_get_num_dns_searches (setting);
/* Gateway */
- if (nm_setting_ip4_config_get_never_default (setting))
+ if (nm_setting_ip_config_get_never_default (setting))
nm_ip4_config_set_never_default (config, TRUE);
- else if (nm_setting_ip4_config_get_ignore_auto_routes (setting))
+ else if (nm_setting_ip_config_get_ignore_auto_routes (setting))
nm_ip4_config_set_never_default (config, FALSE);
- for (i = 0; i < naddresses; i++) {
- guint32 gateway = nm_ip4_address_get_gateway (nm_setting_ip4_config_get_address (setting, i));
+ if (nm_setting_ip_config_get_gateway (setting)) {
+ guint32 gateway;
- if (gateway) {
- nm_ip4_config_set_gateway (config, gateway);
- break;
- }
+ inet_pton (AF_INET, nm_setting_ip_config_get_gateway (setting), &gateway);
+ nm_ip4_config_set_gateway (config, gateway);
}
/* Addresses */
for (i = 0; i < naddresses; i++) {
- NMIP4Address *s_addr = nm_setting_ip4_config_get_address (setting, i);
- const char *label = _nm_setting_ip4_config_get_address_label (setting, i);
+ NMIPAddress *s_addr = nm_setting_ip_config_get_address (setting, i);
+ GVariant *label;
NMPlatformIP4Address address;
memset (&address, 0, sizeof (address));
- address.address = nm_ip4_address_get_address (s_addr);
- address.plen = nm_ip4_address_get_prefix (s_addr);
+ nm_ip_address_get_address_binary (s_addr, &address.address);
+ address.plen = nm_ip_address_get_prefix (s_addr);
address.lifetime = NM_PLATFORM_LIFETIME_PERMANENT;
address.preferred = NM_PLATFORM_LIFETIME_PERMANENT;
address.source = NM_IP_CONFIG_SOURCE_USER;
- g_strlcpy (address.label, label, sizeof (address.label));
+
+ label = nm_ip_address_get_attribute (s_addr, "label");
+ if (label)
+ g_strlcpy (address.label, g_variant_get_string (label, NULL), sizeof (address.label));
nm_ip4_config_add_address (config, &address);
}
/* Routes */
- if (nm_setting_ip4_config_get_ignore_auto_routes (setting))
+ if (nm_setting_ip_config_get_ignore_auto_routes (setting))
nm_ip4_config_reset_routes (config);
for (i = 0; i < nroutes; i++) {
- NMIP4Route *s_route = nm_setting_ip4_config_get_route (setting, i);
+ NMIPRoute *s_route = nm_setting_ip_config_get_route (setting, i);
NMPlatformIP4Route route;
memset (&route, 0, sizeof (route));
- route.network = nm_ip4_route_get_dest (s_route);
- route.plen = nm_ip4_route_get_prefix (s_route);
- route.gateway = nm_ip4_route_get_next_hop (s_route);
- route.metric = nm_ip4_route_get_metric (s_route);
- if (!route.metric)
+ nm_ip_route_get_dest_binary (s_route, &route.network);
+ route.plen = nm_ip_route_get_prefix (s_route);
+ nm_ip_route_get_next_hop_binary (s_route, &route.gateway);
+ if (nm_ip_route_get_metric (s_route) == -1)
route.metric = default_route_metric;
+ else
+ route.metric = nm_ip_route_get_metric (s_route);
route.source = NM_IP_CONFIG_SOURCE_USER;
nm_ip4_config_add_route (config, &route);
}
/* DNS */
- if (nm_setting_ip4_config_get_ignore_auto_dns (setting)) {
+ if (nm_setting_ip_config_get_ignore_auto_dns (setting)) {
nm_ip4_config_reset_nameservers (config);
nm_ip4_config_reset_domains (config);
nm_ip4_config_reset_searches (config);
@@ -370,11 +375,11 @@ nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIP4Config *setting, i
for (i = 0; i < nnameservers; i++) {
guint32 ip;
- if (inet_pton (AF_INET, nm_setting_ip4_config_get_dns (setting, i), &ip) == 1)
+ if (inet_pton (AF_INET, nm_setting_ip_config_get_dns (setting, i), &ip) == 1)
nm_ip4_config_add_nameserver (config, ip);
}
for (i = 0; i < nsearches; i++)
- nm_ip4_config_add_search (config, nm_setting_ip4_config_get_dns_search (setting, i));
+ nm_ip4_config_add_search (config, nm_setting_ip_config_get_dns_search (setting, i));
g_object_thaw_notify (G_OBJECT (config));
}
@@ -382,17 +387,17 @@ nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIP4Config *setting, i
NMSetting *
nm_ip4_config_create_setting (const NMIP4Config *config)
{
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
guint32 gateway;
guint naddresses, nroutes, nnameservers, nsearches;
const char *method = NULL;
int i;
- s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
+ s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ());
if (!config) {
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED,
NULL);
return NM_SETTING (s_ip4);
}
@@ -406,7 +411,7 @@ nm_ip4_config_create_setting (const NMIP4Config *config)
/* Addresses */
for (i = 0; i < naddresses; i++) {
const NMPlatformIP4Address *address = nm_ip4_config_get_address (config, i);
- NMIP4Address *s_addr;
+ NMIPAddress *s_addr;
/* Detect dynamic address */
if (address->lifetime != NM_PLATFORM_LIFETIME_PERMANENT) {
@@ -418,29 +423,31 @@ nm_ip4_config_create_setting (const NMIP4Config *config)
if (!method)
method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL;
- s_addr = nm_ip4_address_new ();
+ s_addr = nm_ip_address_new_binary (AF_INET, &address->address, address->plen, NULL);
+ if (*address->label)
+ nm_ip_address_set_attribute (s_addr, "label", g_variant_new_string (address->label));
- nm_ip4_address_set_address (s_addr, address->address);
- nm_ip4_address_set_prefix (s_addr, address->plen);
- /* For backwards compatibility, attach the gateway to an address if it's
- * in the same subnet.
- */
- if (same_prefix (address->address, gateway, address->plen))
- nm_ip4_address_set_gateway (s_addr, gateway);
+ nm_setting_ip_config_add_address (s_ip4, s_addr);
+ nm_ip_address_unref (s_addr);
+ }
- _nm_setting_ip4_config_add_address_with_label (s_ip4, s_addr, address->label);
- nm_ip4_address_unref (s_addr);
+ /* Gateway */
+ if ( gateway
+ && nm_setting_ip_config_get_num_addresses (s_ip4) > 0) {
+ g_object_set (s_ip4,
+ NM_SETTING_IP_CONFIG_GATEWAY, nm_utils_inet4_ntop (gateway, NULL),
+ NULL);
}
/* Use 'disabled' if the method wasn't previously set */
if (!method)
method = NM_SETTING_IP4_CONFIG_METHOD_DISABLED;
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, method, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, method, NULL);
/* Routes */
for (i = 0; i < nroutes; i++) {
const NMPlatformIP4Route *route = nm_ip4_config_get_route (config, i);
- NMIP4Route *s_route;
+ NMIPRoute *s_route;
/* Ignore default route. */
if (!route->plen)
@@ -450,26 +457,24 @@ nm_ip4_config_create_setting (const NMIP4Config *config)
if (route->source != NM_IP_CONFIG_SOURCE_USER)
continue;
- s_route = nm_ip4_route_new ();
- nm_ip4_route_set_dest (s_route, route->network);
- nm_ip4_route_set_prefix (s_route, route->plen);
- nm_ip4_route_set_next_hop (s_route, route->gateway);
- nm_ip4_route_set_metric (s_route, route->metric);
-
- nm_setting_ip4_config_add_route (s_ip4, s_route);
- nm_ip4_route_unref (s_route);
+ s_route = nm_ip_route_new_binary (AF_INET,
+ &route->network, route->plen,
+ &route->gateway, route->metric,
+ NULL);
+ nm_setting_ip_config_add_route (s_ip4, s_route);
+ nm_ip_route_unref (s_route);
}
/* DNS */
for (i = 0; i < nnameservers; i++) {
guint32 nameserver = nm_ip4_config_get_nameserver (config, i);
- nm_setting_ip4_config_add_dns (s_ip4, nm_utils_inet4_ntop (nameserver, NULL));
+ nm_setting_ip_config_add_dns (s_ip4, nm_utils_inet4_ntop (nameserver, NULL));
}
for (i = 0; i < nsearches; i++) {
const char *search = nm_ip4_config_get_search (config, i);
- nm_setting_ip4_config_add_dns_search (s_ip4, search);
+ nm_setting_ip_config_add_dns_search (s_ip4, search);
}
return NM_SETTING (s_ip4);
@@ -584,6 +589,9 @@ nm_ip4_config_subtract (NMIP4Config *dst, const NMIP4Config *src)
if (nm_ip4_config_get_gateway (src) == nm_ip4_config_get_gateway (dst))
nm_ip4_config_set_gateway (dst, 0);
+ if (!nm_ip4_config_get_num_addresses (dst))
+ nm_ip4_config_set_gateway (dst, 0);
+
/* routes */
for (i = 0; i < nm_ip4_config_get_num_routes (src); i++) {
const NMPlatformIP4Route *src_route = nm_ip4_config_get_route (src, i);
@@ -928,8 +936,8 @@ nm_ip4_config_dump (const NMIP4Config *config, const char *detail)
for (i = 0; i < nm_ip4_config_get_num_searches (config); i++)
g_message (" search: %s", nm_ip4_config_get_search (config, i));
- g_message (" mss: %u", nm_ip4_config_get_mss (config));
- g_message (" mtu: %u", nm_ip4_config_get_mtu (config));
+ g_message (" mss: %"G_GUINT32_FORMAT, nm_ip4_config_get_mss (config));
+ g_message (" mtu: %"G_GUINT32_FORMAT, nm_ip4_config_get_mtu (config));
/* NIS */
for (i = 0; i < nm_ip4_config_get_num_nis_servers (config); i++) {
@@ -937,7 +945,7 @@ nm_ip4_config_dump (const NMIP4Config *config, const char *detail)
g_message (" nis: %s", nm_utils_inet4_ntop (tmp, NULL));
}
- g_message (" nisdmn: %s", nm_ip4_config_get_nis_domain (config));
+ g_message (" nisdmn: %s", str_if_set (nm_ip4_config_get_nis_domain (config), "(none)"));
/* WINS */
for (i = 0; i < nm_ip4_config_get_num_wins (config); i++) {
@@ -1010,6 +1018,7 @@ nm_ip4_config_reset_addresses (NMIP4Config *config)
if (priv->addresses->len != 0) {
g_array_set_size (priv->addresses, 0);
+ _NOTIFY (config, PROP_ADDRESS_DATA);
_NOTIFY (config, PROP_ADDRESSES);
}
}
@@ -1067,6 +1076,7 @@ nm_ip4_config_add_address (NMIP4Config *config, const NMPlatformIP4Address *new)
g_array_append_val (priv->addresses, *new);
NOTIFY:
+ _NOTIFY (config, PROP_ADDRESS_DATA);
_NOTIFY (config, PROP_ADDRESSES);
}
@@ -1078,6 +1088,7 @@ nm_ip4_config_del_address (NMIP4Config *config, guint i)
g_return_if_fail (i < priv->addresses->len);
g_array_remove_index (priv->addresses, i);
+ _NOTIFY (config, PROP_ADDRESS_DATA);
_NOTIFY (config, PROP_ADDRESSES);
}
@@ -1122,6 +1133,7 @@ nm_ip4_config_reset_routes (NMIP4Config *config)
if (priv->routes->len != 0) {
g_array_set_size (priv->routes, 0);
+ _NOTIFY (config, PROP_ROUTE_DATA);
_NOTIFY (config, PROP_ROUTES);
}
}
@@ -1161,6 +1173,7 @@ nm_ip4_config_add_route (NMIP4Config *config, const NMPlatformIP4Route *new)
g_array_append_val (priv->routes, *new);
NOTIFY:
+ _NOTIFY (config, PROP_ROUTE_DATA);
_NOTIFY (config, PROP_ROUTES);
}
@@ -1172,6 +1185,7 @@ nm_ip4_config_del_route (NMIP4Config *config, guint i)
g_return_if_fail (i < priv->routes->len);
g_array_remove_index (priv->routes, i);
+ _NOTIFY (config, PROP_ROUTE_DATA);
_NOTIFY (config, PROP_ROUTES);
}
@@ -1195,12 +1209,12 @@ const NMPlatformIP4Route *
nm_ip4_config_get_direct_route_for_host (const NMIP4Config *config, guint32 host)
{
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
- int i;
+ guint i;
NMPlatformIP4Route *best_route = NULL;
g_return_val_if_fail (host, NULL);
- for (i = 0; i < priv->routes->len; i++ ) {
+ for (i = 0; i < priv->routes->len; i++) {
NMPlatformIP4Route *item = &g_array_index (priv->routes, NMPlatformIP4Route, i);
if (item->gateway != 0)
@@ -1221,6 +1235,28 @@ nm_ip4_config_get_direct_route_for_host (const NMIP4Config *config, guint32 host
return best_route;
}
+const NMPlatformIP4Address *
+nm_ip4_config_get_subnet_for_host (const NMIP4Config *config, guint32 host)
+{
+ NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
+ guint i;
+ NMPlatformIP4Address *subnet = NULL;
+
+ g_return_val_if_fail (host, NULL);
+
+ for (i = 0; i < priv->addresses->len; i++) {
+ NMPlatformIP4Address *item = &g_array_index (priv->addresses, NMPlatformIP4Address, i);
+
+ if (subnet && subnet->plen >= item->plen)
+ continue;
+ if (nm_utils_ip4_address_clear_host_address (host, item->plen) != nm_utils_ip4_address_clear_host_address (item->address, item->plen))
+ continue;
+ subnet = item;
+ }
+
+ return subnet;
+}
+
/******************************************************************/
void
@@ -1695,6 +1731,15 @@ finalize (GObject *object)
}
static void
+gvalue_destroy (gpointer data)
+{
+ GValue *value = (GValue *) data;
+
+ g_value_unset (value);
+ g_slice_free (GValue, value);
+}
+
+static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
@@ -1702,11 +1747,41 @@ get_property (GObject *object, guint prop_id,
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object);
switch (prop_id) {
- case PROP_GATEWAY:
- if (priv->gateway)
- g_value_set_string (value, nm_utils_inet4_ntop (priv->gateway, NULL));
- else
- g_value_set_string (value, NULL);
+ case PROP_ADDRESS_DATA:
+ {
+ GPtrArray *addresses = g_ptr_array_new ();
+ int naddr = nm_ip4_config_get_num_addresses (config);
+ int i;
+
+ for (i = 0; i < naddr; i++) {
+ const NMPlatformIP4Address *address = nm_ip4_config_get_address (config, i);
+ GHashTable *addr_hash;
+ GValue *val;
+
+ addr_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, gvalue_destroy);
+
+ val = g_slice_new0 (GValue);
+ g_value_init (val, G_TYPE_STRING);
+ g_value_set_string (val, nm_utils_inet4_ntop (address->address, NULL));
+ g_hash_table_insert (addr_hash, "address", val);
+
+ val = g_slice_new0 (GValue);
+ g_value_init (val, G_TYPE_UINT);
+ g_value_set_uint (val, address->plen);
+ g_hash_table_insert (addr_hash, "prefix", val);
+
+ if (*address->label) {
+ val = g_slice_new0 (GValue);
+ g_value_init (val, G_TYPE_STRING);
+ g_value_set_string (val, address->label);
+ g_hash_table_insert (addr_hash, "label", val);
+ }
+
+ g_ptr_array_add (addresses, addr_hash);
+ }
+
+ g_value_take_boxed (value, addresses);
+ }
break;
case PROP_ADDRESSES:
{
@@ -1717,10 +1792,11 @@ get_property (GObject *object, guint prop_id,
for (i = 0; i < naddr; i++) {
const NMPlatformIP4Address *address = nm_ip4_config_get_address (config, i);
GArray *array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3);
+ guint32 gateway = i == 0 ? priv->gateway : 0;
g_array_append_val (array, address->address);
g_array_append_val (array, address->plen);
- g_array_append_val (array, priv->gateway);
+ g_array_append_val (array, gateway);
g_ptr_array_add (addresses, array);
}
@@ -1728,6 +1804,47 @@ get_property (GObject *object, guint prop_id,
g_value_take_boxed (value, addresses);
}
break;
+ case PROP_ROUTE_DATA:
+ {
+ GPtrArray *routes = g_ptr_array_new ();
+ guint nroutes = nm_ip4_config_get_num_routes (config);
+ int i;
+
+ for (i = 0; i < nroutes; i++) {
+ const NMPlatformIP4Route *route = nm_ip4_config_get_route (config, i);
+ GHashTable *route_hash;
+ GValue *val;
+
+ route_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, gvalue_destroy);
+
+ val = g_slice_new0 (GValue);
+ g_value_init (val, G_TYPE_STRING);
+ g_value_set_string (val, nm_utils_inet4_ntop (route->network, NULL));
+ g_hash_table_insert (route_hash, "dest", val);
+
+ val = g_slice_new0 (GValue);
+ g_value_init (val, G_TYPE_UINT);
+ g_value_set_uint (val, route->plen);
+ g_hash_table_insert (route_hash, "prefix", val);
+
+ if (route->gateway) {
+ val = g_slice_new0 (GValue);
+ g_value_init (val, G_TYPE_STRING);
+ g_value_set_string (val, nm_utils_inet4_ntop (route->gateway, NULL));
+ g_hash_table_insert (route_hash, "gateway", val);
+ }
+
+ val = g_slice_new0 (GValue);
+ g_value_init (val, G_TYPE_UINT);
+ g_value_set_uint (val, route->metric);
+ g_hash_table_insert (route_hash, "metric", val);
+
+ g_ptr_array_add (routes, route_hash);
+ }
+
+ g_value_take_boxed (value, routes);
+ }
+ break;
case PROP_ROUTES:
{
GPtrArray *routes = g_ptr_array_new ();
@@ -1736,8 +1853,14 @@ get_property (GObject *object, guint prop_id,
for (i = 0; i < nroutes; i++) {
const NMPlatformIP4Route *route = nm_ip4_config_get_route (config, i);
- GArray *array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 4);
+ GArray *array;
+
+ /* legacy versions of nm_ip4_route_set_prefix() in libnm-util assert that the
+ * plen is positive. Skip the default routes not to break older clients. */
+ if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route))
+ continue;
+ array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 4);
g_array_append_val (array, route->network);
g_array_append_val (array, route->plen);
g_array_append_val (array, route->gateway);
@@ -1749,6 +1872,12 @@ get_property (GObject *object, guint prop_id,
g_value_take_boxed (value, routes);
}
break;
+ case PROP_GATEWAY:
+ if (priv->gateway)
+ g_value_set_string (value, nm_utils_inet4_ntop (priv->gateway, NULL));
+ else
+ g_value_set_string (value, NULL);
+ break;
case PROP_NAMESERVERS:
g_value_set_boxed (value, priv->nameservers);
break;
@@ -1777,19 +1906,29 @@ nm_ip4_config_class_init (NMIP4ConfigClass *config_class)
object_class->get_property = get_property;
object_class->finalize = finalize;
- obj_properties[PROP_GATEWAY] =
- g_param_spec_string (NM_IP4_CONFIG_GATEWAY, "", "",
- NULL,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS);
+ obj_properties[PROP_ADDRESS_DATA] =
+ g_param_spec_boxed (NM_IP4_CONFIG_ADDRESS_DATA, "", "",
+ DBUS_TYPE_NM_IP_ADDRESSES,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS);
obj_properties[PROP_ADDRESSES] =
- g_param_spec_boxed (NM_IP4_CONFIG_ADDRESSES, "", "",
- DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
+ g_param_spec_boxed (NM_IP4_CONFIG_ADDRESSES, "", "",
+ DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS);
+ obj_properties[PROP_ROUTE_DATA] =
+ g_param_spec_boxed (NM_IP4_CONFIG_ROUTE_DATA, "", "",
+ DBUS_TYPE_NM_IP_ROUTES,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_ROUTES] =
- g_param_spec_boxed (NM_IP4_CONFIG_ROUTES, "", "",
- DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
+ g_param_spec_boxed (NM_IP4_CONFIG_ROUTES, "", "",
+ DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS);
+ obj_properties[PROP_GATEWAY] =
+ g_param_spec_string (NM_IP4_CONFIG_GATEWAY, "", "",
+ NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_NAMESERVERS] =
@@ -1815,7 +1954,9 @@ nm_ip4_config_class_init (NMIP4ConfigClass *config_class)
g_object_class_install_properties (object_class, LAST_PROP, obj_properties);
+#ifndef NM_IFACE_HELPER
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (config_class),
&dbus_glib_nm_ip4_config_object_info);
+#endif
}
diff --git a/src/nm-ip4-config.h b/src/nm-ip4-config.h
index 16372be5cd..afdd8d09a2 100644
--- a/src/nm-ip4-config.h
+++ b/src/nm-ip4-config.h
@@ -41,14 +41,18 @@ typedef struct {
GObjectClass parent;
} NMIP4ConfigClass;
+#define NM_IP4_CONFIG_ADDRESS_DATA "address-data"
+#define NM_IP4_CONFIG_ROUTE_DATA "route-data"
#define NM_IP4_CONFIG_GATEWAY "gateway"
-#define NM_IP4_CONFIG_ADDRESSES "addresses"
-#define NM_IP4_CONFIG_ROUTES "routes"
#define NM_IP4_CONFIG_NAMESERVERS "nameservers"
#define NM_IP4_CONFIG_DOMAINS "domains"
#define NM_IP4_CONFIG_SEARCHES "searches"
#define NM_IP4_CONFIG_WINS_SERVERS "wins-servers"
+/* deprecated */
+#define NM_IP4_CONFIG_ADDRESSES "addresses"
+#define NM_IP4_CONFIG_ROUTES "routes"
+
GType nm_ip4_config_get_type (void);
@@ -61,7 +65,7 @@ const char * nm_ip4_config_get_dbus_path (const NMIP4Config *config);
/* Integration with nm-platform and nm-setting */
NMIP4Config *nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf);
gboolean nm_ip4_config_commit (const NMIP4Config *config, int ifindex);
-void nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIP4Config *setting, int default_route_metric);
+void nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIPConfig *setting, guint32 default_route_metric);
NMSetting *nm_ip4_config_create_setting (const NMIP4Config *config);
/* Utility functions */
@@ -93,6 +97,7 @@ guint32 nm_ip4_config_get_num_routes (const NMIP4Config *config);
const NMPlatformIP4Route *nm_ip4_config_get_route (const NMIP4Config *config, guint32 i);
const NMPlatformIP4Route *nm_ip4_config_get_direct_route_for_host (const NMIP4Config *config, guint32 host);
+const NMPlatformIP4Address *nm_ip4_config_get_subnet_for_host (const NMIP4Config *config, guint32 host);
/* Nameservers */
void nm_ip4_config_reset_nameservers (NMIP4Config *config);
diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c
index d18b35c6a3..60ed7672dc 100644
--- a/src/nm-ip6-config.c
+++ b/src/nm-ip6-config.c
@@ -20,11 +20,13 @@
*/
#include <string.h>
+#include <arpa/inet.h>
#include "nm-ip6-config.h"
#include "nm-glib-compat.h"
#include "nm-utils.h"
+#include "nm-platform.h"
#include "nm-dbus-manager.h"
#include "nm-dbus-glib-types.h"
#include "nm-ip6-config-glue.h"
@@ -50,9 +52,11 @@ typedef struct {
enum {
PROP_0,
- PROP_GATEWAY,
+ PROP_ADDRESS_DATA,
PROP_ADDRESSES,
+ PROP_ROUTE_DATA,
PROP_ROUTES,
+ PROP_GATEWAY,
PROP_NAMESERVERS,
PROP_DOMAINS,
PROP_SEARCHES,
@@ -69,6 +73,7 @@ nm_ip6_config_new (void)
return (NMIP6Config *) g_object_new (NM_TYPE_IP6_CONFIG, NULL);
}
+#ifndef NM_IFACE_HELPER
void
nm_ip6_config_export (NMIP6Config *config)
{
@@ -80,6 +85,7 @@ nm_ip6_config_export (NMIP6Config *config)
nm_dbus_manager_register_object (nm_dbus_manager_get (), priv->path, config);
}
}
+#endif
const char *
nm_ip6_config_get_dbus_path (const NMIP6Config *config)
@@ -167,7 +173,9 @@ static gboolean
routes_are_duplicate (const NMPlatformIP6Route *a, const NMPlatformIP6Route *b, gboolean consider_gateway_and_metric)
{
return IN6_ARE_ADDR_EQUAL (&a->network, &b->network) && a->plen == b->plen &&
- (!consider_gateway_and_metric || (IN6_ARE_ADDR_EQUAL (&a->gateway, &b->gateway) && a->metric == b->metric));
+ ( !consider_gateway_and_metric
+ || ( IN6_ARE_ADDR_EQUAL (&a->gateway, &b->gateway)
+ && nm_utils_ip6_route_metric_normalize (a->metric) == nm_utils_ip6_route_metric_normalize (b->metric)));
}
static gint
@@ -270,6 +278,7 @@ nm_ip6_config_addresses_sort (NMIP6Config *self, NMSettingIP6ConfigPrivacy use_t
g_free (data_pre);
if (changed) {
+ _NOTIFY (self, PROP_ADDRESS_DATA);
_NOTIFY (self, PROP_ADDRESSES);
return TRUE;
}
@@ -283,7 +292,7 @@ nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf, NMSettingIP6Co
NMIP6Config *config;
NMIP6ConfigPrivate *priv;
guint i;
- guint lowest_metric = G_MAXUINT;
+ guint32 lowest_metric = G_MAXUINT32;
struct in6_addr old_gateway = IN6ADDR_ANY_INIT;
gboolean has_gateway = FALSE;
gboolean notify_nameservers = FALSE;
@@ -299,7 +308,7 @@ nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf, NMSettingIP6Co
g_array_unref (priv->routes);
priv->addresses = nm_platform_ip6_address_get_all (ifindex);
- priv->routes = nm_platform_ip6_route_get_all (ifindex, TRUE);
+ priv->routes = nm_platform_ip6_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL);
/* Extract gateway from default route */
old_gateway = priv->gateway;
@@ -345,7 +354,9 @@ nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf, NMSettingIP6Co
/* actually, nobody should be connected to the signal, just to be sure, notify */
if (notify_nameservers)
_NOTIFY (config, PROP_NAMESERVERS);
+ _NOTIFY (config, PROP_ADDRESS_DATA);
_NOTIFY (config, PROP_ADDRESSES);
+ _NOTIFY (config, PROP_ROUTE_DATA);
_NOTIFY (config, PROP_ROUTES);
if (!IN6_ARE_ADDR_EQUAL (&priv->gateway, &old_gateway))
_NOTIFY (config, PROP_GATEWAY);
@@ -382,13 +393,6 @@ nm_ip6_config_commit (const NMIP6Config *config, int ifindex)
&& nm_ip6_config_destination_is_direct (config, &route->network, route->plen))
continue;
- /* Don't add the default route if the connection
- * is never supposed to be the default connection.
- */
- if ( nm_ip6_config_get_never_default (config)
- && NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route))
- continue;
-
g_array_append_vals (routes, route, 1);
}
@@ -400,43 +404,45 @@ nm_ip6_config_commit (const NMIP6Config *config, int ifindex)
}
void
-nm_ip6_config_merge_setting (NMIP6Config *config, NMSettingIP6Config *setting, int default_route_metric)
+nm_ip6_config_merge_setting (NMIP6Config *config, NMSettingIPConfig *setting, guint32 default_route_metric)
{
guint naddresses, nroutes, nnameservers, nsearches;
+ const char *gateway_str;
int i;
if (!setting)
return;
- naddresses = nm_setting_ip6_config_get_num_addresses (setting);
- nroutes = nm_setting_ip6_config_get_num_routes (setting);
- nnameservers = nm_setting_ip6_config_get_num_dns (setting);
- nsearches = nm_setting_ip6_config_get_num_dns_searches (setting);
+ g_return_if_fail (NM_IS_SETTING_IP6_CONFIG (setting));
+
+ naddresses = nm_setting_ip_config_get_num_addresses (setting);
+ nroutes = nm_setting_ip_config_get_num_routes (setting);
+ nnameservers = nm_setting_ip_config_get_num_dns (setting);
+ nsearches = nm_setting_ip_config_get_num_dns_searches (setting);
g_object_freeze_notify (G_OBJECT (config));
/* Gateway */
- if (nm_setting_ip6_config_get_never_default (setting))
+ if (nm_setting_ip_config_get_never_default (setting))
nm_ip6_config_set_never_default (config, TRUE);
- else if (nm_setting_ip6_config_get_ignore_auto_routes (setting))
+ else if (nm_setting_ip_config_get_ignore_auto_routes (setting))
nm_ip6_config_set_never_default (config, FALSE);
- for (i = 0; i < naddresses; i++) {
- const struct in6_addr *gateway = nm_ip6_address_get_gateway (nm_setting_ip6_config_get_address (setting, i));
+ gateway_str = nm_setting_ip_config_get_gateway (setting);
+ if (gateway_str) {
+ struct in6_addr gateway;
- if (gateway && !IN6_IS_ADDR_UNSPECIFIED (gateway)) {
- nm_ip6_config_set_gateway (config, gateway);
- break;
- }
+ inet_pton (AF_INET6, gateway_str, &gateway);
+ nm_ip6_config_set_gateway (config, &gateway);
}
/* Addresses */
for (i = 0; i < naddresses; i++) {
- NMIP6Address *s_addr = nm_setting_ip6_config_get_address (setting, i);
+ NMIPAddress *s_addr = nm_setting_ip_config_get_address (setting, i);
NMPlatformIP6Address address;
memset (&address, 0, sizeof (address));
- address.address = *nm_ip6_address_get_address (s_addr);
- address.plen = nm_ip6_address_get_prefix (s_addr);
+ nm_ip_address_get_address_binary (s_addr, &address.address);
+ address.plen = nm_ip_address_get_prefix (s_addr);
address.lifetime = NM_PLATFORM_LIFETIME_PERMANENT;
address.preferred = NM_PLATFORM_LIFETIME_PERMANENT;
address.source = NM_IP_CONFIG_SOURCE_USER;
@@ -445,26 +451,27 @@ nm_ip6_config_merge_setting (NMIP6Config *config, NMSettingIP6Config *setting, i
}
/* Routes */
- if (nm_setting_ip6_config_get_ignore_auto_routes (setting))
+ if (nm_setting_ip_config_get_ignore_auto_routes (setting))
nm_ip6_config_reset_routes (config);
for (i = 0; i < nroutes; i++) {
- NMIP6Route *s_route = nm_setting_ip6_config_get_route (setting, i);
+ NMIPRoute *s_route = nm_setting_ip_config_get_route (setting, i);
NMPlatformIP6Route route;
memset (&route, 0, sizeof (route));
- route.network = *nm_ip6_route_get_dest (s_route);
- route.plen = nm_ip6_route_get_prefix (s_route);
- route.gateway = *nm_ip6_route_get_next_hop (s_route);
- route.metric = nm_ip6_route_get_metric (s_route);
- if (!route.metric)
+ nm_ip_route_get_dest_binary (s_route, &route.network);
+ route.plen = nm_ip_route_get_prefix (s_route);
+ nm_ip_route_get_next_hop_binary (s_route, &route.gateway);
+ if (nm_ip_route_get_metric (s_route) == -1)
route.metric = default_route_metric;
+ else
+ route.metric = nm_ip_route_get_metric (s_route);
route.source = NM_IP_CONFIG_SOURCE_USER;
nm_ip6_config_add_route (config, &route);
}
/* DNS */
- if (nm_setting_ip6_config_get_ignore_auto_dns (setting)) {
+ if (nm_setting_ip_config_get_ignore_auto_dns (setting)) {
nm_ip6_config_reset_nameservers (config);
nm_ip6_config_reset_domains (config);
nm_ip6_config_reset_searches (config);
@@ -472,11 +479,11 @@ nm_ip6_config_merge_setting (NMIP6Config *config, NMSettingIP6Config *setting, i
for (i = 0; i < nnameservers; i++) {
struct in6_addr ip;
- if (inet_pton (AF_INET6, nm_setting_ip6_config_get_dns (setting, i), &ip) == 1)
+ if (inet_pton (AF_INET6, nm_setting_ip_config_get_dns (setting, i), &ip) == 1)
nm_ip6_config_add_nameserver (config, &ip);
}
for (i = 0; i < nsearches; i++)
- nm_ip6_config_add_search (config, nm_setting_ip6_config_get_dns_search (setting, i));
+ nm_ip6_config_add_search (config, nm_setting_ip_config_get_dns_search (setting, i));
g_object_thaw_notify (G_OBJECT (config));
}
@@ -484,17 +491,17 @@ nm_ip6_config_merge_setting (NMIP6Config *config, NMSettingIP6Config *setting, i
NMSetting *
nm_ip6_config_create_setting (const NMIP6Config *config)
{
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip6;
const struct in6_addr *gateway;
guint naddresses, nroutes, nnameservers, nsearches;
const char *method = NULL;
int i;
- s_ip6 = NM_SETTING_IP6_CONFIG (nm_setting_ip6_config_new ());
+ s_ip6 = NM_SETTING_IP_CONFIG (nm_setting_ip6_config_new ());
if (!config) {
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
NULL);
return NM_SETTING (s_ip6);
}
@@ -508,7 +515,7 @@ nm_ip6_config_create_setting (const NMIP6Config *config)
/* Addresses */
for (i = 0; i < naddresses; i++) {
const NMPlatformIP6Address *address = nm_ip6_config_get_address (config, i);
- NMIP6Address *s_addr;
+ NMIPAddress *s_addr;
/* Ignore link-local address. */
if (IN6_IS_ADDR_LINKLOCAL (&address->address)) {
@@ -527,26 +534,28 @@ nm_ip6_config_create_setting (const NMIP6Config *config)
if (!method || strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL) == 0)
method = NM_SETTING_IP6_CONFIG_METHOD_MANUAL;
- s_addr = nm_ip6_address_new ();
-
- nm_ip6_address_set_address (s_addr, &address->address);
- nm_ip6_address_set_prefix (s_addr, address->plen);
- if (gateway)
- nm_ip6_address_set_gateway (s_addr, gateway);
+ s_addr = nm_ip_address_new_binary (AF_INET6, &address->address, address->plen, NULL);
+ nm_setting_ip_config_add_address (s_ip6, s_addr);
+ nm_ip_address_unref (s_addr);
+ }
- nm_setting_ip6_config_add_address (s_ip6, s_addr);
- nm_ip6_address_unref (s_addr);
+ /* Gateway */
+ if ( gateway
+ && nm_setting_ip_config_get_num_addresses (s_ip6) > 0) {
+ g_object_set (s_ip6,
+ NM_SETTING_IP_CONFIG_GATEWAY, nm_utils_inet6_ntop (gateway, NULL),
+ NULL);
}
/* Use 'ignore' if the method wasn't previously set */
if (!method)
method = NM_SETTING_IP6_CONFIG_METHOD_IGNORE;
- g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_METHOD, method, NULL);
+ g_object_set (s_ip6, NM_SETTING_IP_CONFIG_METHOD, method, NULL);
/* Routes */
for (i = 0; i < nroutes; i++) {
const NMPlatformIP6Route *route = nm_ip6_config_get_route (config, i);
- NMIP6Route *s_route;
+ NMIPRoute *s_route;
/* Ignore link-local route. */
if (IN6_IS_ADDR_LINKLOCAL (&route->network))
@@ -560,26 +569,24 @@ nm_ip6_config_create_setting (const NMIP6Config *config)
if (route->source != NM_IP_CONFIG_SOURCE_USER)
continue;
- s_route = nm_ip6_route_new ();
- nm_ip6_route_set_dest (s_route, &route->network);
- nm_ip6_route_set_prefix (s_route, route->plen);
- nm_ip6_route_set_next_hop (s_route, &route->gateway);
- nm_ip6_route_set_metric (s_route, route->metric);
-
- nm_setting_ip6_config_add_route (s_ip6, s_route);
- nm_ip6_route_unref (s_route);
+ s_route = nm_ip_route_new_binary (AF_INET6,
+ &route->network, route->plen,
+ &route->gateway, route->metric,
+ NULL);
+ nm_setting_ip_config_add_route (s_ip6, s_route);
+ nm_ip_route_unref (s_route);
}
/* DNS */
for (i = 0; i < nnameservers; i++) {
const struct in6_addr *nameserver = nm_ip6_config_get_nameserver (config, i);
- nm_setting_ip6_config_add_dns (s_ip6, nm_utils_inet6_ntop (nameserver, NULL));
+ nm_setting_ip_config_add_dns (s_ip6, nm_utils_inet6_ntop (nameserver, NULL));
}
for (i = 0; i < nsearches; i++) {
const char *search = nm_ip6_config_get_search (config, i);
- nm_setting_ip6_config_add_dns_search (s_ip6, search);
+ nm_setting_ip_config_add_dns_search (s_ip6, search);
}
return NM_SETTING (s_ip6);
@@ -696,6 +703,9 @@ nm_ip6_config_subtract (NMIP6Config *dst, const NMIP6Config *src)
if (src_tmp && dst_tmp && IN6_ARE_ADDR_EQUAL (src_tmp, dst_tmp))
nm_ip6_config_set_gateway (dst, NULL);
+ if (!nm_ip6_config_get_num_addresses (dst))
+ nm_ip6_config_set_gateway (dst, NULL);
+
/* routes */
for (i = 0; i < nm_ip6_config_get_num_routes (src); i++) {
const NMPlatformIP6Route *src_route = nm_ip6_config_get_route (src, i);
@@ -958,7 +968,7 @@ nm_ip6_config_dump (const NMIP6Config *config, const char *detail)
for (i = 0; i < nm_ip6_config_get_num_searches (config); i++)
g_message (" search: %s", nm_ip6_config_get_search (config, i));
- g_message (" mss: %u", nm_ip6_config_get_mss (config));
+ g_message (" mss: %"G_GUINT32_FORMAT, nm_ip6_config_get_mss (config));
g_message (" n-dflt: %d", nm_ip6_config_get_never_default (config));
}
@@ -1014,6 +1024,7 @@ nm_ip6_config_reset_addresses (NMIP6Config *config)
if (priv->addresses->len != 0) {
g_array_set_size (priv->addresses, 0);
+ _NOTIFY (config, PROP_ADDRESS_DATA);
_NOTIFY (config, PROP_ADDRESSES);
}
}
@@ -1071,6 +1082,7 @@ nm_ip6_config_add_address (NMIP6Config *config, const NMPlatformIP6Address *new)
g_array_append_val (priv->addresses, *new);
NOTIFY:
+ _NOTIFY (config, PROP_ADDRESS_DATA);
_NOTIFY (config, PROP_ADDRESSES);
}
@@ -1082,6 +1094,7 @@ nm_ip6_config_del_address (NMIP6Config *config, guint i)
g_return_if_fail (i < priv->addresses->len);
g_array_remove_index (priv->addresses, i);
+ _NOTIFY (config, PROP_ADDRESS_DATA);
_NOTIFY (config, PROP_ADDRESSES);
}
@@ -1127,6 +1140,7 @@ nm_ip6_config_reset_routes (NMIP6Config *config)
if (priv->routes->len != 0) {
g_array_set_size (priv->routes, 0);
+ _NOTIFY (config, PROP_ROUTE_DATA);
_NOTIFY (config, PROP_ROUTES);
}
}
@@ -1166,6 +1180,7 @@ nm_ip6_config_add_route (NMIP6Config *config, const NMPlatformIP6Route *new)
g_array_append_val (priv->routes, *new);
NOTIFY:
+ _NOTIFY (config, PROP_ROUTE_DATA);
_NOTIFY (config, PROP_ROUTES);
}
@@ -1177,6 +1192,7 @@ nm_ip6_config_del_route (NMIP6Config *config, guint i)
g_return_if_fail (i < priv->routes->len);
g_array_remove_index (priv->routes, i);
+ _NOTIFY (config, PROP_ROUTE_DATA);
_NOTIFY (config, PROP_ROUTES);
}
@@ -1200,13 +1216,13 @@ const NMPlatformIP6Route *
nm_ip6_config_get_direct_route_for_host (const NMIP6Config *config, const struct in6_addr *host)
{
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config);
- int i;
+ guint i;
struct in6_addr network2, host2;
NMPlatformIP6Route *best_route = NULL;
g_return_val_if_fail (host && !IN6_IS_ADDR_UNSPECIFIED (host), NULL);
- for (i = 0; i < priv->routes->len; i++ ) {
+ for (i = 0; i < priv->routes->len; i++) {
NMPlatformIP6Route *item = &g_array_index (priv->routes, NMPlatformIP6Route, i);
if (!IN6_IS_ADDR_UNSPECIFIED (&item->gateway))
@@ -1231,6 +1247,33 @@ nm_ip6_config_get_direct_route_for_host (const NMIP6Config *config, const struct
return best_route;
}
+const NMPlatformIP6Address *
+nm_ip6_config_get_subnet_for_host (const NMIP6Config *config, const struct in6_addr *host)
+{
+ NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config);
+ guint i;
+ NMPlatformIP6Address *subnet = NULL;
+ struct in6_addr subnet2, host2;
+
+ g_return_val_if_fail (host && !IN6_IS_ADDR_UNSPECIFIED (host), NULL);
+
+ for (i = 0; i < priv->addresses->len; i++) {
+ NMPlatformIP6Address *item = &g_array_index (priv->addresses, NMPlatformIP6Address, i);
+
+ if (subnet && subnet->plen >= item->plen)
+ continue;
+
+ nm_utils_ip6_address_clear_host_address (&host2, host, item->plen);
+ nm_utils_ip6_address_clear_host_address (&subnet2, &item->address, item->plen);
+
+ if (IN6_ARE_ADDR_EQUAL (&subnet2, &host2))
+ subnet = item;
+ }
+
+ return subnet;
+}
+
+
/******************************************************************/
void
@@ -1569,6 +1612,15 @@ nameservers_to_gvalue (GArray *array, GValue *value)
}
static void
+gvalue_destroy (gpointer data)
+{
+ GValue *value = (GValue *) data;
+
+ g_value_unset (value);
+ g_slice_free (GValue, value);
+}
+
+static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
@@ -1576,11 +1628,34 @@ get_property (GObject *object, guint prop_id,
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object);
switch (prop_id) {
- case PROP_GATEWAY:
- if (!IN6_IS_ADDR_UNSPECIFIED (&priv->gateway))
- g_value_set_string (value, nm_utils_inet6_ntop (&priv->gateway, NULL));
- else
- g_value_set_string (value, NULL);
+ case PROP_ADDRESS_DATA:
+ {
+ GPtrArray *addresses = g_ptr_array_new ();
+ int naddr = nm_ip6_config_get_num_addresses (config);
+ int i;
+
+ for (i = 0; i < naddr; i++) {
+ const NMPlatformIP6Address *address = nm_ip6_config_get_address (config, i);
+ GHashTable *addr_hash;
+ GValue *val;
+
+ addr_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, gvalue_destroy);
+
+ val = g_slice_new0 (GValue);
+ g_value_init (val, G_TYPE_STRING);
+ g_value_set_string (val, nm_utils_inet6_ntop (&address->address, NULL));
+ g_hash_table_insert (addr_hash, "address", val);
+
+ val = g_slice_new0 (GValue);
+ g_value_init (val, G_TYPE_UINT);
+ g_value_set_uint (val, address->plen);
+ g_hash_table_insert (addr_hash, "prefix", val);
+
+ g_ptr_array_add (addresses, addr_hash);
+ }
+
+ g_value_take_boxed (value, addresses);
+ }
break;
case PROP_ADDRESSES:
{
@@ -1613,7 +1688,7 @@ get_property (GObject *object, guint prop_id,
/* Gateway */
g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
ba = g_byte_array_new ();
- g_byte_array_append (ba, (guint8 *) (gateway ? gateway : &in6addr_any), sizeof (*gateway));
+ g_byte_array_append (ba, (guint8 *) (i == 0 && gateway ? gateway : &in6addr_any), sizeof (*gateway));
g_value_take_boxed (&element, ba);
g_value_array_append (array, &element);
g_value_unset (&element);
@@ -1624,6 +1699,47 @@ get_property (GObject *object, guint prop_id,
g_value_take_boxed (value, addresses);
}
break;
+ case PROP_ROUTE_DATA:
+ {
+ GPtrArray *routes = g_ptr_array_new ();
+ guint nroutes = nm_ip6_config_get_num_routes (config);
+ int i;
+
+ for (i = 0; i < nroutes; i++) {
+ const NMPlatformIP6Route *route = nm_ip6_config_get_route (config, i);
+ GHashTable *route_hash;
+ GValue *val;
+
+ route_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, gvalue_destroy);
+
+ val = g_slice_new0 (GValue);
+ g_value_init (val, G_TYPE_STRING);
+ g_value_set_string (val, nm_utils_inet6_ntop (&route->network, NULL));
+ g_hash_table_insert (route_hash, "dest", val);
+
+ val = g_slice_new0 (GValue);
+ g_value_init (val, G_TYPE_UINT);
+ g_value_set_uint (val, route->plen);
+ g_hash_table_insert (route_hash, "prefix", val);
+
+ if (!IN6_IS_ADDR_UNSPECIFIED (&route->gateway)) {
+ val = g_slice_new0 (GValue);
+ g_value_init (val, G_TYPE_STRING);
+ g_value_set_string (val, nm_utils_inet6_ntop (&route->gateway, NULL));
+ g_hash_table_insert (route_hash, "gateway", val);
+ }
+
+ val = g_slice_new0 (GValue);
+ g_value_init (val, G_TYPE_UINT);
+ g_value_set_uint (val, route->metric);
+ g_hash_table_insert (route_hash, "metric", val);
+
+ g_ptr_array_add (routes, route_hash);
+ }
+
+ g_value_take_boxed (value, routes);
+ }
+ break;
case PROP_ROUTES:
{
GPtrArray *routes = g_ptr_array_new ();
@@ -1631,12 +1747,18 @@ get_property (GObject *object, guint prop_id,
int i;
for (i = 0; i < nroutes; i++) {
+ GValueArray *array;
const NMPlatformIP6Route *route = nm_ip6_config_get_route (config, i);
-
- GValueArray *array = g_value_array_new (4);
GByteArray *ba;
GValue element = G_VALUE_INIT;
+ /* legacy versions of nm_ip6_route_set_prefix() in libnm-util assert that the
+ * plen is positive. Skip the default routes not to break older clients. */
+ if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route))
+ continue;
+
+ array = g_value_array_new (4);
+
g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
ba = g_byte_array_new ();
g_byte_array_append (ba, (guint8 *) &route->network, sizeof (route->network));
@@ -1667,6 +1789,12 @@ get_property (GObject *object, guint prop_id,
g_value_take_boxed (value, routes);
}
break;
+ case PROP_GATEWAY:
+ if (!IN6_IS_ADDR_UNSPECIFIED (&priv->gateway))
+ g_value_set_string (value, nm_utils_inet6_ntop (&priv->gateway, NULL));
+ else
+ g_value_set_string (value, NULL);
+ break;
case PROP_NAMESERVERS:
nameservers_to_gvalue (priv->nameservers, value);
break;
@@ -1694,21 +1822,31 @@ nm_ip6_config_class_init (NMIP6ConfigClass *config_class)
object_class->finalize = finalize;
/* properties */
- obj_properties[PROP_GATEWAY] =
- g_param_spec_string (NM_IP6_CONFIG_GATEWAY, "", "",
- NULL,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS);
- obj_properties[PROP_ADDRESSES] =
- g_param_spec_boxed (NM_IP6_CONFIG_ADDRESSES, "", "",
- DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS,
+ obj_properties[PROP_ADDRESS_DATA] =
+ g_param_spec_boxed (NM_IP6_CONFIG_ADDRESS_DATA, "", "",
+ DBUS_TYPE_NM_IP_ADDRESSES,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
+ obj_properties[PROP_ADDRESSES] =
+ g_param_spec_boxed (NM_IP6_CONFIG_ADDRESSES, "", "",
+ DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS);
+ obj_properties[PROP_ROUTE_DATA] =
+ g_param_spec_boxed (NM_IP6_CONFIG_ROUTE_DATA, "", "",
+ DBUS_TYPE_NM_IP_ROUTES,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS);
obj_properties[PROP_ROUTES] =
g_param_spec_boxed (NM_IP6_CONFIG_ROUTES, "", "",
DBUS_TYPE_G_ARRAY_OF_IP6_ROUTE,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
+ obj_properties[PROP_GATEWAY] =
+ g_param_spec_string (NM_IP6_CONFIG_GATEWAY, "", "",
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS);
obj_properties[PROP_NAMESERVERS] =
g_param_spec_boxed (NM_IP6_CONFIG_NAMESERVERS, "", "",
DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UCHAR,
@@ -1727,7 +1865,9 @@ nm_ip6_config_class_init (NMIP6ConfigClass *config_class)
g_object_class_install_properties (object_class, LAST_PROP, obj_properties);
+#ifndef NM_IFACE_HELPER
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (config_class),
&dbus_glib_nm_ip6_config_object_info);
+#endif
}
diff --git a/src/nm-ip6-config.h b/src/nm-ip6-config.h
index 60a82b0f72..f1d2dc8dd9 100644
--- a/src/nm-ip6-config.h
+++ b/src/nm-ip6-config.h
@@ -22,6 +22,7 @@
#define __NETWORKMANAGER_IP6_CONFIG_H__
#include <glib-object.h>
+#include <netinet/in.h>
#include "nm-types.h"
#include "nm-setting-ip6-config.h"
@@ -41,13 +42,17 @@ typedef struct {
GObjectClass parent;
} NMIP6ConfigClass;
+#define NM_IP6_CONFIG_ADDRESS_DATA "address-data"
+#define NM_IP6_CONFIG_ROUTE_DATA "route-data"
#define NM_IP6_CONFIG_GATEWAY "gateway"
-#define NM_IP6_CONFIG_ADDRESSES "addresses"
-#define NM_IP6_CONFIG_ROUTES "routes"
#define NM_IP6_CONFIG_NAMESERVERS "nameservers"
#define NM_IP6_CONFIG_DOMAINS "domains"
#define NM_IP6_CONFIG_SEARCHES "searches"
+/* deprecated */
+#define NM_IP6_CONFIG_ADDRESSES "addresses"
+#define NM_IP6_CONFIG_ROUTES "routes"
+
GType nm_ip6_config_get_type (void);
@@ -60,7 +65,7 @@ const char * nm_ip6_config_get_dbus_path (const NMIP6Config *config);
/* Integration with nm-platform and nm-setting */
NMIP6Config *nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf, NMSettingIP6ConfigPrivacy use_temporary);
gboolean nm_ip6_config_commit (const NMIP6Config *config, int ifindex);
-void nm_ip6_config_merge_setting (NMIP6Config *config, NMSettingIP6Config *setting, int default_route_metric);
+void nm_ip6_config_merge_setting (NMIP6Config *config, NMSettingIPConfig *setting, guint32 default_route_metric);
NMSetting *nm_ip6_config_create_setting (const NMIP6Config *config);
/* Utility functions */
@@ -94,6 +99,7 @@ guint32 nm_ip6_config_get_num_routes (const NMIP6Config *config);
const NMPlatformIP6Route *nm_ip6_config_get_route (const NMIP6Config *config, guint32 i);
const NMPlatformIP6Route *nm_ip6_config_get_direct_route_for_host (const NMIP6Config *config, const struct in6_addr *host);
+const NMPlatformIP6Address *nm_ip6_config_get_subnet_for_host (const NMIP6Config *config, const struct in6_addr *host);
/* Nameservers */
void nm_ip6_config_reset_nameservers (NMIP6Config *config);
diff --git a/src/nm-manager.c b/src/nm-manager.c
index 459d531a97..d8973b7337 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -33,6 +33,7 @@
#include <gio/gio.h>
#include <glib/gi18n.h>
+#include "gsystem-local-alloc.h"
#include "nm-glib-compat.h"
#include "nm-manager.h"
#include "nm-logging.h"
@@ -58,6 +59,7 @@
#include "nm-session-monitor.h"
#include "nm-activation-request.h"
#include "nm-core-internal.h"
+#include "nm-config.h"
#define NM_AUTOIP_DBUS_SERVICE "org.freedesktop.nm_avahi_autoipd"
#define NM_AUTOIP_DBUS_IFACE "org.freedesktop.nm_avahi_autoipd"
@@ -213,6 +215,7 @@ enum {
USER_PERMISSIONS_CHANGED,
ACTIVE_CONNECTION_ADDED,
ACTIVE_CONNECTION_REMOVED,
+ CONFIGURE_QUIT,
LAST_SIGNAL
};
@@ -705,6 +708,9 @@ check_if_startup_complete (NMManager *self)
g_signal_handlers_disconnect_by_func (dev, G_CALLBACK (device_has_pending_action_changed), self);
}
+
+ if (nm_config_get_configure_and_quit (nm_config_get ()))
+ g_signal_emit (self, signals[CONFIGURE_QUIT], 0);
}
static void
@@ -744,6 +750,8 @@ remove_device (NMManager *manager,
nm_device_set_unmanaged_quitting (device);
else
nm_device_set_unmanaged (device, NM_UNMANAGED_INTERNAL, TRUE, NM_DEVICE_STATE_REASON_REMOVED);
+ } else if (quitting && nm_config_get_configure_and_quit (nm_config_get ())) {
+ nm_device_spawn_iface_helper (device);
}
}
@@ -4166,6 +4174,16 @@ nm_manager_start (NMManager *self)
check_if_startup_complete (self);
}
+void
+nm_manager_stop (NMManager *self)
+{
+ NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
+
+ /* Remove all devices */
+ while (priv->devices)
+ remove_device (self, NM_DEVICE (priv->devices->data), TRUE, TRUE);
+}
+
static gboolean
handle_firmware_changed (gpointer user_data)
{
@@ -4989,9 +5007,7 @@ dispose (GObject *object)
G_CALLBACK (authority_changed_cb),
manager);
- /* Remove all devices */
- while (priv->devices)
- remove_device (manager, NM_DEVICE (priv->devices->data), TRUE, TRUE);
+ g_assert (priv->devices == NULL);
if (priv->ac_cleanup_id) {
g_source_remove (priv->ac_cleanup_id);
@@ -5257,6 +5273,13 @@ nm_manager_class_init (NMManagerClass *manager_class)
0, NULL, NULL, NULL,
G_TYPE_NONE, 1, G_TYPE_OBJECT);
+ signals[CONFIGURE_QUIT] =
+ g_signal_new (NM_MANAGER_CONFIGURE_QUIT,
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ 0, NULL, NULL, NULL,
+ G_TYPE_NONE, 0);
+
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (manager_class),
&dbus_glib_nm_manager_object_info);
diff --git a/src/nm-manager.h b/src/nm-manager.h
index f623516159..3b00e8053a 100644
--- a/src/nm-manager.h
+++ b/src/nm-manager.h
@@ -59,6 +59,7 @@
/* Internal signals */
#define NM_MANAGER_ACTIVE_CONNECTION_ADDED "active-connection-added"
#define NM_MANAGER_ACTIVE_CONNECTION_REMOVED "active-connection-removed"
+#define NM_MANAGER_CONFIGURE_QUIT "configure-quit"
struct _NMManager {
@@ -88,6 +89,7 @@ NMManager * nm_manager_new (NMSettings *settings,
NMManager * nm_manager_get (void);
void nm_manager_start (NMManager *manager);
+void nm_manager_stop (NMManager *manager);
NMState nm_manager_get_state (NMManager *manager);
const GSList *nm_manager_get_active_connections (NMManager *manager);
GSList * nm_manager_get_activatable_connections (NMManager *manager);
diff --git a/src/nm-policy.c b/src/nm-policy.c
index e21df28a9c..963be3099b 100644
--- a/src/nm-policy.c
+++ b/src/nm-policy.c
@@ -32,6 +32,7 @@
#include "nm-activation-request.h"
#include "nm-logging.h"
#include "nm-device.h"
+#include "nm-default-route-manager.h"
#include "nm-dbus-manager.h"
#include "nm-setting-ip4-config.h"
#include "nm-setting-connection.h"
@@ -100,164 +101,22 @@ static NMDevice *
get_best_ip4_device (NMPolicy *self, gboolean fully_activated)
{
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
- const GSList *iter;
- NMDevice *best = NULL;
- int best_prio = G_MAXINT;
-
- for (iter = nm_manager_get_devices (priv->manager); iter; iter = g_slist_next (iter)) {
- NMDevice *dev = NM_DEVICE (iter->data);
- NMDeviceType devtype = nm_device_get_device_type (dev);
- NMDeviceState state = nm_device_get_state (dev);
- NMActRequest *req;
- NMConnection *connection;
- NMSettingIP4Config *s_ip4;
- int prio;
- const char *method = NULL;
-
- if ( state <= NM_DEVICE_STATE_DISCONNECTED
- || state >= NM_DEVICE_STATE_DEACTIVATING)
- continue;
-
- if (fully_activated && state < NM_DEVICE_STATE_SECONDARIES)
- continue;
-
- if (fully_activated) {
- NMIP4Config *ip4_config;
-
- ip4_config = nm_device_get_ip4_config (dev);
- if (!ip4_config)
- continue;
-
- /* Make sure the device has a gateway */
- if (!nm_ip4_config_get_gateway (ip4_config) && (devtype != NM_DEVICE_TYPE_MODEM))
- continue;
-
- /* 'never-default' devices can't ever be the default */
- if (nm_ip4_config_get_never_default (ip4_config))
- continue;
- }
- req = nm_device_get_act_request (dev);
- g_assert (req);
- connection = nm_act_request_get_connection (req);
- g_assert (connection);
-
- method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG);
- /* If IPv4 is disabled or link-local-only, it can't be the default */
- if ( !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)
- || !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL))
- continue;
-
- /* 'never-default' devices can't ever be the default */
- s_ip4 = nm_connection_get_setting_ip4_config (connection);
- g_assert (s_ip4);
- if (nm_setting_ip4_config_get_never_default (s_ip4))
- continue;
-
- prio = nm_device_get_priority (dev);
- if ( prio < best_prio
- || (priv->default_device4 == dev && prio == best_prio)
- || !best) {
- best = dev;
- best_prio = prio;
- }
- }
-
- if (!best)
- return NULL;
-
- if (!fully_activated) {
- NMDeviceState state = nm_device_get_state (best);
-
- /* There's only a best activating device if the best device
- * among all activating and already-activated devices is a
- * still-activating one.
- */
- if (state >= NM_DEVICE_STATE_SECONDARIES)
- return NULL;
- }
-
- return best;
+ return nm_default_route_manager_ip4_get_best_device (nm_default_route_manager_get (),
+ nm_manager_get_devices (priv->manager),
+ fully_activated,
+ priv->default_device4);
}
static NMDevice *
get_best_ip6_device (NMPolicy *self, gboolean fully_activated)
{
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
- const GSList *iter;
- NMDevice *best = NULL;
- int best_prio = G_MAXINT;
- for (iter = nm_manager_get_devices (priv->manager); iter; iter = g_slist_next (iter)) {
- NMDevice *dev = NM_DEVICE (iter->data);
- NMDeviceType devtype = nm_device_get_device_type (dev);
- NMDeviceState state = nm_device_get_state (dev);
- NMActRequest *req;
- NMConnection *connection;
- NMSettingIP6Config *s_ip6;
- int prio;
- const char *method = NULL;
-
- if ( state <= NM_DEVICE_STATE_DISCONNECTED
- || state >= NM_DEVICE_STATE_DEACTIVATING)
- continue;
-
- if (fully_activated && state < NM_DEVICE_STATE_SECONDARIES)
- continue;
-
- if (fully_activated) {
- NMIP6Config *ip6_config;
-
- ip6_config = nm_device_get_ip6_config (dev);
- if (!ip6_config)
- continue;
-
- if (!nm_ip6_config_get_gateway (ip6_config) && (devtype != NM_DEVICE_TYPE_MODEM))
- continue;
-
- if (nm_ip6_config_get_never_default (ip6_config))
- continue;
- }
-
- req = nm_device_get_act_request (dev);
- g_assert (req);
- connection = nm_act_request_get_connection (req);
- g_assert (connection);
-
- method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP6_CONFIG);
- if ( !strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)
- || !strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL))
- continue;
-
- s_ip6 = nm_connection_get_setting_ip6_config (connection);
- g_assert (s_ip6);
- if (nm_setting_ip6_config_get_never_default (s_ip6))
- continue;
-
- prio = nm_device_get_priority (dev);
- if ( prio < best_prio
- || (priv->default_device6 == dev && prio == best_prio)
- || !best) {
- best = dev;
- best_prio = prio;
- }
- }
-
- if (!best)
- return NULL;
-
- if (!fully_activated) {
- NMDeviceState state = nm_device_get_state (best);
-
- /* There's only a best activating device if the best device
- * among all activating and already-activated devices is an
- * activating one.
- */
- if (state >= NM_DEVICE_STATE_SECONDARIES)
- return NULL;
- }
-
- return best;
+ return nm_default_route_manager_ip6_get_best_device (nm_default_route_manager_get (),
+ nm_manager_get_devices (priv->manager),
+ fully_activated,
+ priv->default_device6);
}
#define FALLBACK_HOSTNAME4 "localhost.localdomain"
@@ -473,12 +332,14 @@ update_system_hostname (NMPolicy *policy, NMDevice *best4, NMDevice *best6)
const NMPlatformIP4Address *addr4;
addr4 = nm_ip4_config_get_address (ip4_config, 0);
+ g_clear_object (&priv->lookup_addr);
priv->lookup_addr = g_inet_address_new_from_bytes ((guint8 *) &addr4->address,
G_SOCKET_FAMILY_IPV4);
} else if (ip6_config && nm_ip6_config_get_num_addresses (ip6_config) > 0) {
const NMPlatformIP6Address *addr6;
addr6 = nm_ip6_config_get_address (ip6_config, 0);
+ g_clear_object (&priv->lookup_addr);
priv->lookup_addr = g_inet_address_new_from_bytes ((guint8 *) &addr6->address,
G_SOCKET_FAMILY_IPV6);
} else {
@@ -518,90 +379,19 @@ update_default_ac (NMPolicy *policy,
}
static NMIP4Config *
-get_best_ip4_config (NMPolicy *policy,
+get_best_ip4_config (NMPolicy *self,
gboolean ignore_never_default,
const char **out_ip_iface,
- int *out_ip_ifindex,
NMActiveConnection **out_ac,
NMDevice **out_device,
NMVpnConnection **out_vpn)
{
- NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
- const GSList *connections, *iter;
- NMDevice *device;
- NMActRequest *req = NULL;
- NMIP4Config *ip4_config = NULL;
-
- /* If a VPN connection is active, it is preferred */
- connections = nm_manager_get_active_connections (priv->manager);
- for (iter = connections; iter; iter = g_slist_next (iter)) {
- NMActiveConnection *active = NM_ACTIVE_CONNECTION (iter->data);
- NMVpnConnection *candidate;
- NMIP4Config *vpn_ip4;
- NMConnection *tmp;
- NMSettingIP4Config *s_ip4;
- NMVpnConnectionState vpn_state;
-
- if (!NM_IS_VPN_CONNECTION (active))
- continue;
-
- candidate = NM_VPN_CONNECTION (active);
-
- tmp = nm_active_connection_get_connection (active);
- g_assert (tmp);
-
- vpn_state = nm_vpn_connection_get_vpn_state (candidate);
- if (vpn_state != NM_VPN_CONNECTION_STATE_ACTIVATED)
- continue;
-
- vpn_ip4 = nm_vpn_connection_get_ip4_config (candidate);
- if (!vpn_ip4)
- continue;
-
- if (ignore_never_default == FALSE) {
- /* Check for a VPN-provided config never-default */
- if (nm_ip4_config_get_never_default (vpn_ip4))
- continue;
-
- /* Check the user's preference from the NMConnection */
- s_ip4 = nm_connection_get_setting_ip4_config (tmp);
- if (nm_setting_ip4_config_get_never_default (s_ip4))
- continue;
- }
-
- ip4_config = vpn_ip4;
- if (out_vpn)
- *out_vpn = candidate;
- if (out_ac)
- *out_ac = active;
- if (out_ip_iface)
- *out_ip_iface = nm_vpn_connection_get_ip_iface (candidate);
- if (out_ip_ifindex)
- *out_ip_ifindex = nm_vpn_connection_get_ip_ifindex (candidate);
- break;
- }
-
- /* If no VPN connections, we use the best device instead */
- if (!ip4_config) {
- device = get_best_ip4_device (policy, TRUE);
- if (device) {
- ip4_config = nm_device_get_ip4_config (device);
- g_assert (ip4_config);
- req = nm_device_get_act_request (device);
- g_assert (req);
-
- if (out_device)
- *out_device = device;
- if (out_ac)
- *out_ac = NM_ACTIVE_CONNECTION (req);
- if (out_ip_iface)
- *out_ip_iface = nm_device_get_ip_iface (device);
- if (out_ip_ifindex)
- *out_ip_ifindex = nm_device_get_ip_ifindex (device);
- }
- }
-
- return ip4_config;
+ return nm_default_route_manager_ip4_get_best_config (nm_default_route_manager_get (),
+ ignore_never_default,
+ out_ip_iface,
+ out_ac,
+ out_device,
+ out_vpn);
}
static void
@@ -612,7 +402,7 @@ update_ip4_dns (NMPolicy *policy, NMDnsManager *dns_mgr)
NMVpnConnection *vpn = NULL;
NMDnsIPConfigType dns_type = NM_DNS_IP_CONFIG_TYPE_BEST_DEVICE;
- ip4_config = get_best_ip4_config (policy, TRUE, &ip_iface, NULL, NULL, NULL, &vpn);
+ ip4_config = get_best_ip4_config (policy, TRUE, &ip_iface, NULL, NULL, &vpn);
if (ip4_config) {
if (vpn)
dns_type = NM_DNS_IP_CONFIG_TYPE_VPN;
@@ -632,16 +422,12 @@ update_ip4_routing (NMPolicy *policy, gboolean force_update)
NMConnection *connection = NULL;
NMVpnConnection *vpn = NULL;
NMActiveConnection *best_ac = NULL;
- NMIP4Config *ip4_config = NULL;
const char *ip_iface = NULL;
- int ip_ifindex = -1;
- guint32 gw_addr = 0;
/* Note that we might have an IPv4 VPN tunneled over an IPv6-only device,
* so we can get (vpn != NULL && best == NULL).
*/
- ip4_config = get_best_ip4_config (policy, FALSE, &ip_iface, &ip_ifindex, &best_ac, &best, &vpn);
- if (!ip4_config) {
+ if (!get_best_ip4_config (policy, FALSE, &ip_iface, &best_ac, &best, &vpn)) {
gboolean changed;
changed = (priv->default_device4 != NULL);
@@ -656,8 +442,6 @@ update_ip4_routing (NMPolicy *policy, gboolean force_update)
if (!force_update && best && (best == priv->default_device4))
return;
- gw_addr = nm_ip4_config_get_gateway (ip4_config);
-
if (best) {
const GSList *connections, *iter;
@@ -672,50 +456,10 @@ update_ip4_routing (NMPolicy *policy, gboolean force_update)
}
}
- if (vpn) {
- NMDevice *parent = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (vpn));
- int parent_ifindex = nm_device_get_ip_ifindex (parent);
- NMIP4Config *parent_ip4 = nm_device_get_ip4_config (parent);
- guint32 parent_mss = parent_ip4 ? nm_ip4_config_get_mss (parent_ip4) : 0;
- in_addr_t int_gw = nm_vpn_connection_get_ip4_internal_gateway (vpn);
- int mss = nm_ip4_config_get_mss (ip4_config);
-
- /* If no VPN interface, use the parent interface */
- if (ip_ifindex <= 0)
- ip_ifindex = parent_ifindex;
-
- if (!nm_platform_ip4_route_add (ip_ifindex, NM_IP_CONFIG_SOURCE_VPN,
- 0, 0, int_gw,
- NM_PLATFORM_ROUTE_METRIC_DEFAULT, mss)) {
- (void) nm_platform_ip4_route_add (parent_ifindex, NM_IP_CONFIG_SOURCE_VPN,
- gw_addr, 32, 0,
- NM_PLATFORM_ROUTE_METRIC_DEFAULT, parent_mss);
- if (!nm_platform_ip4_route_add (ip_ifindex, NM_IP_CONFIG_SOURCE_VPN,
- 0, 0, int_gw,
- NM_PLATFORM_ROUTE_METRIC_DEFAULT, mss))
- nm_log_err (LOGD_IP4 | LOGD_VPN, "Failed to set default route.");
- }
-
+ if (vpn)
default_device = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (vpn));
- } else {
- int mss = nm_ip4_config_get_mss (ip4_config);
-
- g_assert (ip_iface);
- if (!nm_platform_ip4_route_add (ip_ifindex, NM_IP_CONFIG_SOURCE_USER,
- 0, 0, gw_addr,
- NM_PLATFORM_ROUTE_METRIC_DEFAULT, mss)) {
- (void) nm_platform_ip4_route_add (ip_ifindex, NM_IP_CONFIG_SOURCE_USER,
- gw_addr, 32, 0,
- NM_PLATFORM_ROUTE_METRIC_DEFAULT, mss);
- if (!nm_platform_ip4_route_add (ip_ifindex, NM_IP_CONFIG_SOURCE_USER,
- 0, 0, gw_addr,
- NM_PLATFORM_ROUTE_METRIC_DEFAULT, mss)) {
- nm_log_err (LOGD_IP4, "Failed to set default route.");
- }
- }
-
+ else
default_device = best;
- }
update_default_ac (policy, best_ac, nm_active_connection_set_default);
@@ -730,90 +474,19 @@ update_ip4_routing (NMPolicy *policy, gboolean force_update)
}
static NMIP6Config *
-get_best_ip6_config (NMPolicy *policy,
+get_best_ip6_config (NMPolicy *self,
gboolean ignore_never_default,
const char **out_ip_iface,
- int *out_ip_ifindex,
NMActiveConnection **out_ac,
NMDevice **out_device,
NMVpnConnection **out_vpn)
{
- NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
- const GSList *connections, *iter;
- NMDevice *device;
- NMActRequest *req = NULL;
- NMIP6Config *ip6_config = NULL;
-
- /* If a VPN connection is active, it is preferred */
- connections = nm_manager_get_active_connections (priv->manager);
- for (iter = connections; iter; iter = g_slist_next (iter)) {
- NMActiveConnection *active = NM_ACTIVE_CONNECTION (iter->data);
- NMVpnConnection *candidate;
- NMIP6Config *vpn_ip6;
- NMConnection *tmp;
- NMSettingIP6Config *s_ip6;
- NMVpnConnectionState vpn_state;
-
- if (!NM_IS_VPN_CONNECTION (active))
- continue;
-
- candidate = NM_VPN_CONNECTION (active);
-
- tmp = nm_active_connection_get_connection (active);
- g_assert (tmp);
-
- vpn_state = nm_vpn_connection_get_vpn_state (candidate);
- if (vpn_state != NM_VPN_CONNECTION_STATE_ACTIVATED)
- continue;
-
- vpn_ip6 = nm_vpn_connection_get_ip6_config (candidate);
- if (!vpn_ip6)
- continue;
-
- if (ignore_never_default == FALSE) {
- /* Check for a VPN-provided config never-default */
- if (nm_ip6_config_get_never_default (vpn_ip6))
- continue;
-
- /* Check the user's preference from the NMConnection */
- s_ip6 = nm_connection_get_setting_ip6_config (tmp);
- if (nm_setting_ip6_config_get_never_default (s_ip6))
- continue;
- }
-
- ip6_config = vpn_ip6;
- if (out_vpn)
- *out_vpn = candidate;
- if (out_ac)
- *out_ac = NM_ACTIVE_CONNECTION (candidate);
- if (out_ip_iface)
- *out_ip_iface = nm_vpn_connection_get_ip_iface (candidate);
- if (out_ip_ifindex)
- *out_ip_ifindex = nm_vpn_connection_get_ip_ifindex (candidate);
- break;
- }
-
- /* If no VPN connections, we use the best device instead */
- if (!ip6_config) {
- device = get_best_ip6_device (policy, TRUE);
- if (device) {
- req = nm_device_get_act_request (device);
- g_assert (req);
- ip6_config = nm_device_get_ip6_config (device);
- g_assert (ip6_config);
-
- if (out_device)
- *out_device = device;
- if (out_ac)
- *out_ac = NM_ACTIVE_CONNECTION (req);
- if (out_ip_iface)
- *out_ip_iface = nm_device_get_ip_iface (device);
- if (out_ip_ifindex)
- *out_ip_ifindex = nm_device_get_ip_ifindex (device);
- }
- }
-
- return ip6_config;
+ return nm_default_route_manager_ip6_get_best_config (nm_default_route_manager_get (),
+ ignore_never_default,
+ out_ip_iface,
+ out_ac,
+ out_device,
+ out_vpn);
}
static void
@@ -824,7 +497,7 @@ update_ip6_dns (NMPolicy *policy, NMDnsManager *dns_mgr)
NMVpnConnection *vpn = NULL;
NMDnsIPConfigType dns_type = NM_DNS_IP_CONFIG_TYPE_BEST_DEVICE;
- ip6_config = get_best_ip6_config (policy, TRUE, &ip_iface, NULL, NULL, NULL, &vpn);
+ ip6_config = get_best_ip6_config (policy, TRUE, &ip_iface, NULL, NULL, &vpn);
if (ip6_config) {
if (vpn)
dns_type = NM_DNS_IP_CONFIG_TYPE_VPN;
@@ -844,16 +517,12 @@ update_ip6_routing (NMPolicy *policy, gboolean force_update)
NMConnection *connection = NULL;
NMVpnConnection *vpn = NULL;
NMActiveConnection *best_ac = NULL;
- NMIP6Config *ip6_config = NULL;
const char *ip_iface = NULL;
- int ip_ifindex = -1;
- const struct in6_addr *gw_addr;
/* Note that we might have an IPv6 VPN tunneled over an IPv4-only device,
* so we can get (vpn != NULL && best == NULL).
*/
- ip6_config = get_best_ip6_config (policy, FALSE, &ip_iface, &ip_ifindex, &best_ac, &best, &vpn);
- if (!ip6_config) {
+ if (!get_best_ip6_config (policy, FALSE, &ip_iface, &best_ac, &best, &vpn)) {
gboolean changed;
changed = (priv->default_device6 != NULL);
@@ -868,13 +537,6 @@ update_ip6_routing (NMPolicy *policy, gboolean force_update)
if (!force_update && best && (best == priv->default_device6))
return;
- /* If no better gateway is found, use ::; not all configurations will
- * have a gateway, especially WWAN/Point-to-Point connections.
- */
- gw_addr = nm_ip6_config_get_gateway (ip6_config);
- if (!gw_addr)
- gw_addr = &in6addr_any;
-
if (best) {
const GSList *connections, *iter;
@@ -889,52 +551,10 @@ update_ip6_routing (NMPolicy *policy, gboolean force_update)
}
}
- if (vpn) {
- NMDevice *parent = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (vpn));
- int parent_ifindex = nm_device_get_ip_ifindex (parent);
- NMIP6Config *parent_ip6 = nm_device_get_ip6_config (parent);
- guint32 parent_mss = parent_ip6 ? nm_ip6_config_get_mss (parent_ip6) : 0;
- const struct in6_addr *int_gw = nm_vpn_connection_get_ip6_internal_gateway (vpn);
- int mss = nm_ip6_config_get_mss (ip6_config);
-
- if (!int_gw)
- int_gw = &in6addr_any;
-
- /* If no VPN interface, use the parent interface */
- if (ip_ifindex <= 0)
- ip_ifindex = parent_ifindex;
-
- if (!nm_platform_ip6_route_add (ip_ifindex, NM_IP_CONFIG_SOURCE_VPN,
- in6addr_any, 0, *int_gw,
- NM_PLATFORM_ROUTE_METRIC_DEFAULT, mss)) {
- (void) nm_platform_ip6_route_add (parent_ifindex, NM_IP_CONFIG_SOURCE_VPN,
- *gw_addr, 128, in6addr_any,
- NM_PLATFORM_ROUTE_METRIC_DEFAULT, parent_mss);
- if (!nm_platform_ip6_route_add (ip_ifindex, NM_IP_CONFIG_SOURCE_VPN,
- in6addr_any, 0, *int_gw,
- NM_PLATFORM_ROUTE_METRIC_DEFAULT, mss)) {
- nm_log_err (LOGD_IP6 | LOGD_VPN, "Failed to set default route.");
- }
- }
-
+ if (vpn)
default_device6 = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (vpn));
- } else {
- int mss = nm_ip6_config_get_mss (ip6_config);
-
- if (!nm_platform_ip6_route_add (ip_ifindex, NM_IP_CONFIG_SOURCE_USER,
- in6addr_any, 0, *gw_addr,
- NM_PLATFORM_ROUTE_METRIC_DEFAULT, mss)) {
- (void) nm_platform_ip6_route_add (ip_ifindex, NM_IP_CONFIG_SOURCE_USER,
- *gw_addr, 128, in6addr_any,
- NM_PLATFORM_ROUTE_METRIC_DEFAULT, mss);
- if (!nm_platform_ip6_route_add (ip_ifindex, NM_IP_CONFIG_SOURCE_USER,
- in6addr_any, 0, *gw_addr,
- NM_PLATFORM_ROUTE_METRIC_DEFAULT, mss))
- nm_log_err (LOGD_IP6, "Failed to set default route.");
- }
-
+ else
default_device6 = best;
- }
update_default_ac (policy, best_ac, nm_active_connection_set_default6);
@@ -2015,9 +1635,10 @@ dns_config_changed (NMDnsManager *dns_manager, gpointer user_data)
/* Re-start the hostname lookup thread if we don't have hostname yet. */
if (priv->lookup_addr) {
- char *str = g_inet_address_to_string (priv->lookup_addr);
+ char *str = NULL;
- nm_log_dbg (LOGD_DNS, "restarting reverse-lookup thread for address %s", str);
+ nm_log_dbg (LOGD_DNS, "restarting reverse-lookup thread for address %s",
+ (str = g_inet_address_to_string (priv->lookup_addr)));
g_free (str);
priv->lookup_cancellable = g_cancellable_new ();
diff --git a/src/nm-types.h b/src/nm-types.h
index e67ae20527..4a93567e11 100644
--- a/src/nm-types.h
+++ b/src/nm-types.h
@@ -23,11 +23,13 @@
/* core */
typedef struct _NMActiveConnection NMActiveConnection;
+typedef struct _NMVpnConnection NMVpnConnection;
typedef struct _NMActRequest NMActRequest;
typedef struct _NMAuthSubject NMAuthSubject;
typedef struct _NMConnectionProvider NMConnectionProvider;
typedef struct _NMConnectivity NMConnectivity;
typedef struct _NMDBusManager NMDBusManager;
+typedef struct _NMDefaultRouteManager NMDefaultRouteManager;
typedef struct _NMDevice NMDevice;
typedef struct _NMDhcp4Config NMDhcp4Config;
typedef struct _NMDhcp6Config NMDhcp6Config;
@@ -60,6 +62,49 @@ typedef struct _NMPlatformIP6Address NMPlatformIP6Address;
typedef struct _NMPlatformIP6Route NMPlatformIP6Route;
typedef struct _NMPlatformLink NMPlatformLink;
+typedef enum {
+ /* Please don't interpret type numbers outside nm-platform and use functions
+ * like nm_platform_link_is_software() and nm_platform_supports_slaves().
+ *
+ * type & 0x10000 -> Software device type
+ * type & 0x20000 -> Type supports slaves
+ */
+
+ /* No type, used as error value */
+ NM_LINK_TYPE_NONE,
+
+ /* Unknown type */
+ NM_LINK_TYPE_UNKNOWN,
+
+ /* Hardware types */
+ NM_LINK_TYPE_ETHERNET,
+ NM_LINK_TYPE_INFINIBAND,
+ NM_LINK_TYPE_OLPC_MESH,
+ NM_LINK_TYPE_WIFI,
+ NM_LINK_TYPE_WWAN_ETHERNET, /* WWAN pseudo-ethernet */
+ NM_LINK_TYPE_WIMAX,
+
+ /* Software types */
+ NM_LINK_TYPE_DUMMY = 0x10000,
+ NM_LINK_TYPE_GRE,
+ NM_LINK_TYPE_GRETAP,
+ NM_LINK_TYPE_IFB,
+ NM_LINK_TYPE_LOOPBACK,
+ NM_LINK_TYPE_MACVLAN,
+ NM_LINK_TYPE_MACVTAP,
+ NM_LINK_TYPE_OPENVSWITCH,
+ NM_LINK_TYPE_TAP,
+ NM_LINK_TYPE_TUN,
+ NM_LINK_TYPE_VETH,
+ NM_LINK_TYPE_VLAN,
+ NM_LINK_TYPE_VXLAN,
+
+ /* Software types with slaves */
+ NM_LINK_TYPE_BRIDGE = 0x10000 | 0x20000,
+ NM_LINK_TYPE_BOND,
+ NM_LINK_TYPE_TEAM,
+} NMLinkType;
+
/* settings */
typedef struct _NMAgentManager NMAgentManager;
typedef struct _NMSecretAgent NMSecretAgent;
diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c
index 9e376e5035..17304544be 100644
--- a/src/platform/nm-fake-platform.c
+++ b/src/platform/nm-fake-platform.c
@@ -23,6 +23,7 @@
#include <netinet/icmp6.h>
#include <netinet/in.h>
+#include "gsystem-local-alloc.h"
#include "NetworkManagerUtils.h"
#include "nm-fake-platform.h"
#include "nm-logging.h"
@@ -982,28 +983,28 @@ ip6_address_exists (NMPlatform *platform, int ifindex, struct in6_addr addr, int
/******************************************************************/
static GArray *
-ip4_route_get_all (NMPlatform *platform, int ifindex, gboolean include_default)
+ip4_route_get_all (NMPlatform *platform, int ifindex, NMPlatformGetRouteMode mode)
{
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
GArray *routes;
NMPlatformIP4Route *route;
- int count = 0, i;
+ guint i;
- /* Count routes */
- for (i = 0; i < priv->ip4_routes->len; i++) {
- route = &g_array_index (priv->ip4_routes, NMPlatformIP4Route, i);
- if (route && route->ifindex == ifindex)
- count++;
- }
+ g_return_val_if_fail (NM_IN_SET (mode, NM_PLATFORM_GET_ROUTE_MODE_ALL, NM_PLATFORM_GET_ROUTE_MODE_NO_DEFAULT, NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT), NULL);
- routes = g_array_sized_new (TRUE, TRUE, sizeof (NMPlatformIP4Route), count);
+ routes = g_array_new (TRUE, TRUE, sizeof (NMPlatformIP4Route));
/* Fill routes */
for (i = 0; i < priv->ip4_routes->len; i++) {
route = &g_array_index (priv->ip4_routes, NMPlatformIP4Route, i);
- if (route && route->ifindex == ifindex) {
- if (route->plen != 0 || include_default)
- g_array_append_val (routes, *route);
+ if (route && (!ifindex || route->ifindex == ifindex)) {
+ if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route)) {
+ if (mode != NM_PLATFORM_GET_ROUTE_MODE_NO_DEFAULT)
+ g_array_append_val (routes, *route);
+ } else {
+ if (mode != NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT)
+ g_array_append_val (routes, *route);
+ }
}
}
@@ -1011,28 +1012,28 @@ ip4_route_get_all (NMPlatform *platform, int ifindex, gboolean include_default)
}
static GArray *
-ip6_route_get_all (NMPlatform *platform, int ifindex, gboolean include_default)
+ip6_route_get_all (NMPlatform *platform, int ifindex, NMPlatformGetRouteMode mode)
{
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
GArray *routes;
NMPlatformIP6Route *route;
- int count = 0, i;
+ guint i;
- /* Count routes */
- for (i = 0; i < priv->ip6_routes->len; i++) {
- route = &g_array_index (priv->ip6_routes, NMPlatformIP6Route, i);
- if (route && route->ifindex == ifindex)
- count++;
- }
+ g_return_val_if_fail (NM_IN_SET (mode, NM_PLATFORM_GET_ROUTE_MODE_ALL, NM_PLATFORM_GET_ROUTE_MODE_NO_DEFAULT, NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT), NULL);
- routes = g_array_sized_new (TRUE, TRUE, sizeof (NMPlatformIP6Route), count);
+ routes = g_array_new (TRUE, TRUE, sizeof (NMPlatformIP6Route));
/* Fill routes */
for (i = 0; i < priv->ip6_routes->len; i++) {
route = &g_array_index (priv->ip6_routes, NMPlatformIP6Route, i);
- if (route && route->ifindex == ifindex) {
- if (route->plen != 0 || include_default)
- g_array_append_val (routes, *route);
+ if (route && (!ifindex || route->ifindex == ifindex)) {
+ if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route)) {
+ if (mode != NM_PLATFORM_GET_ROUTE_MODE_NO_DEFAULT)
+ g_array_append_val (routes, *route);
+ } else {
+ if (mode != NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT)
+ g_array_append_val (routes, *route);
+ }
}
}
@@ -1042,7 +1043,7 @@ ip6_route_get_all (NMPlatform *platform, int ifindex, gboolean include_default)
static gboolean
ip4_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
in_addr_t network, int plen, in_addr_t gateway,
- int metric, int mss)
+ guint32 metric, guint32 mss)
{
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
NMPlatformIP4Route route;
@@ -1082,7 +1083,7 @@ ip4_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
static gboolean
ip6_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
struct in6_addr network, int plen, struct in6_addr gateway,
- int metric, int mss)
+ guint32 metric, guint32 mss)
{
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
NMPlatformIP6Route route;
@@ -1120,7 +1121,7 @@ ip6_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
}
static NMPlatformIP4Route *
-ip4_route_get (NMPlatform *platform, int ifindex, in_addr_t network, int plen, int metric)
+ip4_route_get (NMPlatform *platform, int ifindex, in_addr_t network, int plen, guint32 metric)
{
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
int i;
@@ -1139,7 +1140,7 @@ ip4_route_get (NMPlatform *platform, int ifindex, in_addr_t network, int plen, i
}
static NMPlatformIP6Route *
-ip6_route_get (NMPlatform *platform, int ifindex, struct in6_addr network, int plen, int metric)
+ip6_route_get (NMPlatform *platform, int ifindex, struct in6_addr network, int plen, guint32 metric)
{
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
int i;
@@ -1158,7 +1159,7 @@ ip6_route_get (NMPlatform *platform, int ifindex, struct in6_addr network, int p
}
static gboolean
-ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, int plen, int metric)
+ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, int plen, guint32 metric)
{
NMPlatformIP4Route *route = ip4_route_get (platform, ifindex, network, plen, metric);
NMPlatformIP4Route deleted_route;
@@ -1173,7 +1174,7 @@ ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, int plen
}
static gboolean
-ip6_route_delete (NMPlatform *platform, int ifindex, struct in6_addr network, int plen, int metric)
+ip6_route_delete (NMPlatform *platform, int ifindex, struct in6_addr network, int plen, guint32 metric)
{
NMPlatformIP6Route *route = ip6_route_get (platform, ifindex, network, plen, metric);
NMPlatformIP6Route deleted_route;
@@ -1188,13 +1189,13 @@ ip6_route_delete (NMPlatform *platform, int ifindex, struct in6_addr network, in
}
static gboolean
-ip4_route_exists (NMPlatform *platform, int ifindex, in_addr_t network, int plen, int metric)
+ip4_route_exists (NMPlatform *platform, int ifindex, in_addr_t network, int plen, guint32 metric)
{
return !!ip4_route_get (platform, ifindex, network, plen, metric);
}
static gboolean
-ip6_route_exists (NMPlatform *platform, int ifindex, struct in6_addr network, int plen, int metric)
+ip6_route_exists (NMPlatform *platform, int ifindex, struct in6_addr network, int plen, guint32 metric)
{
return !!ip6_route_get (platform, ifindex, network, plen, metric);
}
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index ef5537d897..37eb5c7cce 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -54,6 +54,7 @@
#endif
#endif
+#include "gsystem-local-alloc.h"
#include "NetworkManagerUtils.h"
#include "nm-linux-platform.h"
#include "NetworkManagerUtils.h"
@@ -1297,6 +1298,16 @@ rtprot_to_source (guint rtprot)
}
static gboolean
+_rtnl_route_is_default (const struct rtnl_route *rtnlroute)
+{
+ struct nl_addr *dst;
+
+ return rtnlroute
+ && (dst = rtnl_route_get_dst ((struct rtnl_route *) rtnlroute))
+ && nl_addr_get_prefixlen (dst) == 0;
+}
+
+static gboolean
init_ip4_route (NMPlatformIP4Route *route, struct rtnl_route *rtnlroute)
{
struct nl_addr *dst, *gw;
@@ -3646,21 +3657,28 @@ _route_match (struct rtnl_route *rtnlroute, int family, int ifindex)
}
static GArray *
-ip4_route_get_all (NMPlatform *platform, int ifindex, gboolean include_default)
+ip4_route_get_all (NMPlatform *platform, int ifindex, NMPlatformGetRouteMode mode)
{
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
GArray *routes;
NMPlatformIP4Route route;
struct nl_object *object;
+ g_return_val_if_fail (NM_IN_SET (mode, NM_PLATFORM_GET_ROUTE_MODE_ALL, NM_PLATFORM_GET_ROUTE_MODE_NO_DEFAULT, NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT), NULL);
+
routes = g_array_new (FALSE, FALSE, sizeof (NMPlatformIP4Route));
for (object = nl_cache_get_first (priv->route_cache); object; object = nl_cache_get_next (object)) {
if (_route_match ((struct rtnl_route *) object, AF_INET, ifindex)) {
- if (init_ip4_route (&route, (struct rtnl_route *) object)) {
- if (!NM_PLATFORM_IP_ROUTE_IS_DEFAULT (&route) || include_default)
- g_array_append_val (routes, route);
+ if (_rtnl_route_is_default ((struct rtnl_route *) object)) {
+ if (mode == NM_PLATFORM_GET_ROUTE_MODE_NO_DEFAULT)
+ continue;
+ } else {
+ if (mode == NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT)
+ continue;
}
+ if (init_ip4_route (&route, (struct rtnl_route *) object))
+ g_array_append_val (routes, route);
}
}
@@ -3668,21 +3686,28 @@ ip4_route_get_all (NMPlatform *platform, int ifindex, gboolean include_default)
}
static GArray *
-ip6_route_get_all (NMPlatform *platform, int ifindex, gboolean include_default)
+ip6_route_get_all (NMPlatform *platform, int ifindex, NMPlatformGetRouteMode mode)
{
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
GArray *routes;
NMPlatformIP6Route route;
struct nl_object *object;
+ g_return_val_if_fail (NM_IN_SET (mode, NM_PLATFORM_GET_ROUTE_MODE_ALL, NM_PLATFORM_GET_ROUTE_MODE_NO_DEFAULT, NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT), NULL);
+
routes = g_array_new (FALSE, FALSE, sizeof (NMPlatformIP6Route));
for (object = nl_cache_get_first (priv->route_cache); object; object = nl_cache_get_next (object)) {
if (_route_match ((struct rtnl_route *) object, AF_INET6, ifindex)) {
- if (init_ip6_route (&route, (struct rtnl_route *) object)) {
- if (!NM_PLATFORM_IP_ROUTE_IS_DEFAULT (&route) || include_default)
- g_array_append_val (routes, route);
+ if (_rtnl_route_is_default ((struct rtnl_route *) object)) {
+ if (mode == NM_PLATFORM_GET_ROUTE_MODE_NO_DEFAULT)
+ continue;
+ } else {
+ if (mode == NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT)
+ continue;
}
+ if (init_ip6_route (&route, (struct rtnl_route *) object))
+ g_array_append_val (routes, route);
}
}
@@ -3710,7 +3735,7 @@ clear_host_address (int family, const void *network, int plen, void *dst)
static struct nl_object *
build_rtnl_route (int family, int ifindex, NMIPConfigSource source,
gconstpointer network, int plen, gconstpointer gateway,
- int metric, int mss)
+ guint32 metric, guint32 mss)
{
guint32 network_clean[4];
struct rtnl_route *rtnlroute;
@@ -3751,7 +3776,7 @@ build_rtnl_route (int family, int ifindex, NMIPConfigSource source,
static gboolean
ip4_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
in_addr_t network, int plen, in_addr_t gateway,
- int metric, int mss)
+ guint32 metric, guint32 mss)
{
return add_object (platform, build_rtnl_route (AF_INET, ifindex, source, &network, plen, &gateway, metric, mss));
}
@@ -3759,13 +3784,13 @@ ip4_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
static gboolean
ip6_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
struct in6_addr network, int plen, struct in6_addr gateway,
- int metric, int mss)
+ guint32 metric, guint32 mss)
{
return add_object (platform, build_rtnl_route (AF_INET6, ifindex, source, &network, plen, &gateway, metric, mss));
}
static struct rtnl_route *
-route_search_cache (struct nl_cache *cache, int family, int ifindex, const void *network, int plen, int metric)
+route_search_cache (struct nl_cache *cache, int family, int ifindex, const void *network, int plen, guint32 metric)
{
guint32 network_clean[4], dst_clean[4];
struct nl_object *object;
@@ -3814,7 +3839,7 @@ refresh_route (NMPlatform *platform, int family, int ifindex, const void *networ
}
static gboolean
-ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, int plen, int metric)
+ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, int plen, guint32 metric)
{
in_addr_t gateway = 0;
struct rtnl_route *cached_object;
@@ -3874,7 +3899,7 @@ ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, int plen
}
static gboolean
-ip6_route_delete (NMPlatform *platform, int ifindex, struct in6_addr network, int plen, int metric)
+ip6_route_delete (NMPlatform *platform, int ifindex, struct in6_addr network, int plen, guint32 metric)
{
struct in6_addr gateway = IN6ADDR_ANY_INIT;
@@ -3883,7 +3908,7 @@ ip6_route_delete (NMPlatform *platform, int ifindex, struct in6_addr network, in
}
static gboolean
-ip_route_exists (NMPlatform *platform, int family, int ifindex, gpointer network, int plen, int metric)
+ip_route_exists (NMPlatform *platform, int family, int ifindex, gpointer network, int plen, guint32 metric)
{
auto_nl_object struct nl_object *object = build_rtnl_route (family, ifindex,
NM_IP_CONFIG_SOURCE_UNKNOWN,
@@ -3897,13 +3922,13 @@ ip_route_exists (NMPlatform *platform, int family, int ifindex, gpointer network
}
static gboolean
-ip4_route_exists (NMPlatform *platform, int ifindex, in_addr_t network, int plen, int metric)
+ip4_route_exists (NMPlatform *platform, int ifindex, in_addr_t network, int plen, guint32 metric)
{
return ip_route_exists (platform, AF_INET, ifindex, &network, plen, metric);
}
static gboolean
-ip6_route_exists (NMPlatform *platform, int ifindex, struct in6_addr network, int plen, int metric)
+ip6_route_exists (NMPlatform *platform, int ifindex, struct in6_addr network, int plen, guint32 metric)
{
return ip_route_exists (platform, AF_INET6, ifindex, &network, plen, metric);
}
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index 1aa72a4dba..b4d09ca073 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -26,6 +26,7 @@
#include <string.h>
#include <netlink/route/addr.h>
+#include "gsystem-local-alloc.h"
#include "NetworkManagerUtils.h"
#include "nm-utils.h"
#include "nm-platform.h"
@@ -1703,6 +1704,11 @@ _address_get_lifetime (const NMPlatformIPAddress *address, guint32 now, guint32
if (address->lifetime == 0) {
*out_lifetime = NM_PLATFORM_LIFETIME_PERMANENT;
*out_preferred = NM_PLATFORM_LIFETIME_PERMANENT;
+
+ /* We treat lifetime==0 as permanent addresses to allow easy creation of such addresses
+ * (without requiring to set the lifetime fields to NM_PLATFORM_LIFETIME_PERMANENT).
+ * In that case we also expect that the other fields (timestamp and preferred) are left unset. */
+ g_return_val_if_fail (address->timestamp == 0 && address->preferred == 0, TRUE);
} else {
lifetime = _rebase_relative_time_on_now (address->timestamp, address->lifetime, now, padding);
if (!lifetime)
@@ -1836,38 +1842,36 @@ nm_platform_address_flush (int ifindex)
/******************************************************************/
GArray *
-nm_platform_ip4_route_get_all (int ifindex, gboolean include_default)
+nm_platform_ip4_route_get_all (int ifindex, NMPlatformGetRouteMode mode)
{
reset_error ();
- g_return_val_if_fail (ifindex > 0, NULL);
+ g_return_val_if_fail (ifindex >= 0, NULL);
g_return_val_if_fail (klass->ip4_route_get_all, NULL);
- return klass->ip4_route_get_all (platform, ifindex, include_default);
+ return klass->ip4_route_get_all (platform, ifindex, mode);
}
GArray *
-nm_platform_ip6_route_get_all (int ifindex, gboolean include_default)
+nm_platform_ip6_route_get_all (int ifindex, NMPlatformGetRouteMode mode)
{
reset_error ();
- g_return_val_if_fail (ifindex > 0, NULL);
+ g_return_val_if_fail (ifindex >= 0, NULL);
g_return_val_if_fail (klass->ip6_route_get_all, NULL);
- return klass->ip6_route_get_all (platform, ifindex, include_default);
+ return klass->ip6_route_get_all (platform, ifindex, mode);
}
gboolean
nm_platform_ip4_route_add (int ifindex, NMIPConfigSource source,
in_addr_t network, int plen,
- in_addr_t gateway, int metric, int mss)
+ in_addr_t gateway, guint32 metric, guint32 mss)
{
reset_error ();
g_return_val_if_fail (platform, FALSE);
g_return_val_if_fail (0 <= plen && plen <= 32, FALSE);
- g_return_val_if_fail (metric >= 0, FALSE);
- g_return_val_if_fail (mss >= 0, FALSE);
g_return_val_if_fail (klass->ip4_route_add, FALSE);
if (nm_logging_enabled (LOGL_DEBUG, LOGD_PLATFORM)) {
@@ -1889,12 +1893,10 @@ nm_platform_ip4_route_add (int ifindex, NMIPConfigSource source,
gboolean
nm_platform_ip6_route_add (int ifindex, NMIPConfigSource source,
struct in6_addr network, int plen, struct in6_addr gateway,
- int metric, int mss)
+ guint32 metric, guint32 mss)
{
g_return_val_if_fail (platform, FALSE);
g_return_val_if_fail (0 <= plen && plen <= 128, FALSE);
- g_return_val_if_fail (metric >= 0, FALSE);
- g_return_val_if_fail (mss >= 0, FALSE);
g_return_val_if_fail (klass->ip6_route_add, FALSE);
if (nm_logging_enabled (LOGL_DEBUG, LOGD_PLATFORM)) {
@@ -1914,7 +1916,7 @@ nm_platform_ip6_route_add (int ifindex, NMIPConfigSource source,
}
gboolean
-nm_platform_ip4_route_delete (int ifindex, in_addr_t network, int plen, int metric)
+nm_platform_ip4_route_delete (int ifindex, in_addr_t network, int plen, guint32 metric)
{
char str_dev[TO_STRING_DEV_BUF_SIZE];
@@ -1923,14 +1925,14 @@ nm_platform_ip4_route_delete (int ifindex, in_addr_t network, int plen, int metr
g_return_val_if_fail (platform, FALSE);
g_return_val_if_fail (klass->ip4_route_delete, FALSE);
- debug ("route: deleting IPv4 route %s/%d, metric=%d, ifindex %d%s",
+ debug ("route: deleting IPv4 route %s/%d, metric=%"G_GUINT32_FORMAT", ifindex %d%s",
nm_utils_inet4_ntop (network, NULL), plen, metric, ifindex,
_to_string_dev (ifindex, str_dev, sizeof (str_dev)));
return klass->ip4_route_delete (platform, ifindex, network, plen, metric);
}
gboolean
-nm_platform_ip6_route_delete (int ifindex, struct in6_addr network, int plen, int metric)
+nm_platform_ip6_route_delete (int ifindex, struct in6_addr network, int plen, guint32 metric)
{
char str_dev[TO_STRING_DEV_BUF_SIZE];
@@ -1939,14 +1941,14 @@ nm_platform_ip6_route_delete (int ifindex, struct in6_addr network, int plen, in
g_return_val_if_fail (platform, FALSE);
g_return_val_if_fail (klass->ip6_route_delete, FALSE);
- debug ("route: deleting IPv6 route %s/%d, metric=%d, ifindex %d%s",
+ debug ("route: deleting IPv6 route %s/%d, metric=%"G_GUINT32_FORMAT", ifindex %d%s",
nm_utils_inet6_ntop (&network, NULL), plen, metric, ifindex,
_to_string_dev (ifindex, str_dev, sizeof (str_dev)));
return klass->ip6_route_delete (platform, ifindex, network, plen, metric);
}
gboolean
-nm_platform_ip4_route_exists (int ifindex, in_addr_t network, int plen, int metric)
+nm_platform_ip4_route_exists (int ifindex, in_addr_t network, int plen, guint32 metric)
{
reset_error ();
@@ -1957,7 +1959,7 @@ nm_platform_ip4_route_exists (int ifindex, in_addr_t network, int plen, int metr
}
gboolean
-nm_platform_ip6_route_exists (int ifindex, struct in6_addr network, int plen, int metric)
+nm_platform_ip6_route_exists (int ifindex, struct in6_addr network, int plen, guint32 metric)
{
reset_error ();
@@ -2013,9 +2015,8 @@ array_contains_ip6_route (const GArray *routes, const NMPlatformIP6Route *route)
* A convenience function to synchronize routes for a specific interface
* with the least possible disturbance. It simply removes routes that are
* not listed and adds routes that are.
- *
- * @known_routes should not contain a default route; if it does, it will be
- * ignored.
+ * Default routes are ignored (both in @known_routes and those already
+ * configured on the device).
*
* Returns: %TRUE on success.
*/
@@ -2029,7 +2030,7 @@ nm_platform_ip4_route_sync (int ifindex, const GArray *known_routes)
int i, i_type;
/* Delete unknown routes */
- routes = nm_platform_ip4_route_get_all (ifindex, FALSE);
+ routes = nm_platform_ip4_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_NO_DEFAULT);
for (i = 0; i < routes->len; i++) {
route = &g_array_index (routes, NMPlatformIP4Route, i);
@@ -2086,9 +2087,8 @@ nm_platform_ip4_route_sync (int ifindex, const GArray *known_routes)
* A convenience function to synchronize routes for a specific interface
* with the least possible disturbance. It simply removes routes that are
* not listed and adds routes that are.
- *
- * @known_routes should not contain a default route; if it does, it will be
- * ignored.
+ * Default routes are ignored (both in @known_routes and those already
+ * configured on the device).
*
* Returns: %TRUE on success.
*/
@@ -2102,7 +2102,7 @@ nm_platform_ip6_route_sync (int ifindex, const GArray *known_routes)
int i, i_type;
/* Delete unknown routes */
- routes = nm_platform_ip6_route_get_all (ifindex, FALSE);
+ routes = nm_platform_ip6_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_NO_DEFAULT);
for (i = 0; i < routes->len; i++) {
route = &g_array_index (routes, NMPlatformIP6Route, i);
route->ifindex = 0;
@@ -2427,7 +2427,7 @@ nm_platform_ip4_route_to_string (const NMPlatformIP4Route *route)
_to_string_dev (route->ifindex, str_dev, sizeof (str_dev));
- g_snprintf (to_string_buffer, sizeof (to_string_buffer), "%s/%d via %s%s metric %u mss %u src %s",
+ g_snprintf (to_string_buffer, sizeof (to_string_buffer), "%s/%d via %s%s metric %"G_GUINT32_FORMAT" mss %"G_GUINT32_FORMAT" src %s",
s_network, route->plen, s_gateway,
str_dev,
route->metric, route->mss,
@@ -2460,7 +2460,7 @@ nm_platform_ip6_route_to_string (const NMPlatformIP6Route *route)
_to_string_dev (route->ifindex, str_dev, sizeof (str_dev));
- g_snprintf (to_string_buffer, sizeof (to_string_buffer), "%s/%d via %s%s metric %u mss %u src %s",
+ g_snprintf (to_string_buffer, sizeof (to_string_buffer), "%s/%d via %s%s metric %"G_GUINT32_FORMAT" mss %"G_GUINT32_FORMAT" src %s",
s_network, route->plen, s_gateway,
str_dev,
route->metric, route->mss,
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index 13e25affbd..3514dd084d 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -28,7 +28,6 @@
#include <linux/if_addr.h>
#include <nm-dbus-interface.h>
-#include "gsystem-local-alloc.h"
#include "nm-types.h"
#define NM_TYPE_PLATFORM (nm_platform_get_type ())
@@ -73,49 +72,6 @@ typedef enum {
NM_PLATFORM_REASON_CACHE_CHECK
} NMPlatformReason;
-typedef enum {
- /* Please don't interpret type numbers outside nm-platform and use functions
- * like nm_platform_link_is_software() and nm_platform_supports_slaves().
- *
- * type & 0x10000 -> Software device type
- * type & 0x20000 -> Type supports slaves
- */
-
- /* No type, used as error value */
- NM_LINK_TYPE_NONE,
-
- /* Unknown type */
- NM_LINK_TYPE_UNKNOWN,
-
- /* Hardware types */
- NM_LINK_TYPE_ETHERNET,
- NM_LINK_TYPE_INFINIBAND,
- NM_LINK_TYPE_OLPC_MESH,
- NM_LINK_TYPE_WIFI,
- NM_LINK_TYPE_WWAN_ETHERNET, /* WWAN pseudo-ethernet */
- NM_LINK_TYPE_WIMAX,
-
- /* Software types */
- NM_LINK_TYPE_DUMMY = 0x10000,
- NM_LINK_TYPE_GRE,
- NM_LINK_TYPE_GRETAP,
- NM_LINK_TYPE_IFB,
- NM_LINK_TYPE_LOOPBACK,
- NM_LINK_TYPE_MACVLAN,
- NM_LINK_TYPE_MACVTAP,
- NM_LINK_TYPE_OPENVSWITCH,
- NM_LINK_TYPE_TAP,
- NM_LINK_TYPE_TUN,
- NM_LINK_TYPE_VETH,
- NM_LINK_TYPE_VLAN,
- NM_LINK_TYPE_VXLAN,
-
- /* Software types with slaves */
- NM_LINK_TYPE_BRIDGE = 0x10000 | 0x20000,
- NM_LINK_TYPE_BOND,
- NM_LINK_TYPE_TEAM,
-} NMLinkType;
-
#define __NMPlatformObject_COMMON \
int ifindex; \
;
@@ -143,6 +99,12 @@ typedef enum {
#define NM_PLATFORM_LIFETIME_PERMANENT G_MAXUINT32
+typedef enum {
+ NM_PLATFORM_GET_ROUTE_MODE_ALL,
+ NM_PLATFORM_GET_ROUTE_MODE_NO_DEFAULT,
+ NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT,
+} NMPlatformGetRouteMode;
+
typedef struct {
__NMPlatformObject_COMMON;
} NMPlatformObject;
@@ -224,8 +186,8 @@ G_STATIC_ASSERT (G_STRUCT_OFFSET (NMPlatformIPAddress, address_ptr) == G_STRUCT_
__NMPlatformObject_COMMON; \
NMIPConfigSource source; \
int plen; \
- guint metric; \
- guint mss; \
+ guint32 metric; \
+ guint32 mss; \
;
typedef struct {
@@ -439,18 +401,18 @@ typedef struct {
gboolean (*ip4_address_exists) (NMPlatform *, int ifindex, in_addr_t address, int plen);
gboolean (*ip6_address_exists) (NMPlatform *, int ifindex, struct in6_addr address, int plen);
- GArray * (*ip4_route_get_all) (NMPlatform *, int ifindex, gboolean include_default);
- GArray * (*ip6_route_get_all) (NMPlatform *, int ifindex, gboolean include_default);
+ GArray * (*ip4_route_get_all) (NMPlatform *, int ifindex, NMPlatformGetRouteMode mode);
+ GArray * (*ip6_route_get_all) (NMPlatform *, int ifindex, NMPlatformGetRouteMode mode);
gboolean (*ip4_route_add) (NMPlatform *, int ifindex, NMIPConfigSource source,
in_addr_t network, int plen, in_addr_t gateway,
- int prio, int mss);
+ guint32 metric, guint32 mss);
gboolean (*ip6_route_add) (NMPlatform *, int ifindex, NMIPConfigSource source,
struct in6_addr network, int plen, struct in6_addr gateway,
- int prio, int mss);
- gboolean (*ip4_route_delete) (NMPlatform *, int ifindex, in_addr_t network, int plen, int metric);
- gboolean (*ip6_route_delete) (NMPlatform *, int ifindex, struct in6_addr network, int plen, int metric);
- gboolean (*ip4_route_exists) (NMPlatform *, int ifindex, in_addr_t network, int plen, int metric);
- gboolean (*ip6_route_exists) (NMPlatform *, int ifindex, struct in6_addr network, int plen, int metric);
+ guint32 metric, guint32 mss);
+ gboolean (*ip4_route_delete) (NMPlatform *, int ifindex, in_addr_t network, int plen, guint32 metric);
+ gboolean (*ip6_route_delete) (NMPlatform *, int ifindex, struct in6_addr network, int plen, guint32 metric);
+ gboolean (*ip4_route_exists) (NMPlatform *, int ifindex, in_addr_t network, int plen, guint32 metric);
+ gboolean (*ip6_route_exists) (NMPlatform *, int ifindex, struct in6_addr network, int plen, guint32 metric);
gboolean (*check_support_kernel_extended_ifa_flags) (NMPlatform *);
gboolean (*check_support_user_ipv6ll) (NMPlatform *);
@@ -586,19 +548,18 @@ gboolean nm_platform_ip4_address_sync (int ifindex, const GArray *known_addresse
gboolean nm_platform_ip6_address_sync (int ifindex, const GArray *known_addresses);
gboolean nm_platform_address_flush (int ifindex);
-GArray *nm_platform_ip4_route_get_all (int ifindex, gboolean include_default);
-GArray *nm_platform_ip6_route_get_all (int ifindex, gboolean include_default);
-gboolean nm_platform_route_set_metric (int ifindex, int metric);
+GArray *nm_platform_ip4_route_get_all (int ifindex, NMPlatformGetRouteMode mode);
+GArray *nm_platform_ip6_route_get_all (int ifindex, NMPlatformGetRouteMode mode);
gboolean nm_platform_ip4_route_add (int ifindex, NMIPConfigSource source,
in_addr_t network, int plen, in_addr_t gateway,
- int metric, int mss);
+ guint32 metric, guint32 mss);
gboolean nm_platform_ip6_route_add (int ifindex, NMIPConfigSource source,
struct in6_addr network, int plen, struct in6_addr gateway,
- int metric, int mss);
-gboolean nm_platform_ip4_route_delete (int ifindex, in_addr_t network, int plen, int metric);
-gboolean nm_platform_ip6_route_delete (int ifindex, struct in6_addr network, int plen, int metric);
-gboolean nm_platform_ip4_route_exists (int ifindex, in_addr_t network, int plen, int metric);
-gboolean nm_platform_ip6_route_exists (int ifindex, struct in6_addr network, int plen, int metric);
+ guint32 metric, guint32 mss);
+gboolean nm_platform_ip4_route_delete (int ifindex, in_addr_t network, int plen, guint32 metric);
+gboolean nm_platform_ip6_route_delete (int ifindex, struct in6_addr network, int plen, guint32 metric);
+gboolean nm_platform_ip4_route_exists (int ifindex, in_addr_t network, int plen, guint32 metric);
+gboolean nm_platform_ip6_route_exists (int ifindex, struct in6_addr network, int plen, guint32 metric);
gboolean nm_platform_ip4_route_sync (int ifindex, const GArray *known_routes);
gboolean nm_platform_ip6_route_sync (int ifindex, const GArray *known_routes);
gboolean nm_platform_route_flush (int ifindex);
diff --git a/src/platform/tests/dump.c b/src/platform/tests/dump.c
index e97ef138cb..8aea3aec59 100644
--- a/src/platform/tests/dump.c
+++ b/src/platform/tests/dump.c
@@ -83,8 +83,8 @@ dump_interface (NMPlatformLink *link)
g_array_unref (ip4_addresses);
g_array_unref (ip6_addresses);
- ip4_routes = nm_platform_ip4_route_get_all (link->ifindex, TRUE);
- ip6_routes = nm_platform_ip6_route_get_all (link->ifindex, TRUE);
+ ip4_routes = nm_platform_ip4_route_get_all (link->ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL);
+ ip6_routes = nm_platform_ip6_route_get_all (link->ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL);
g_assert (ip4_routes);
g_assert (ip6_routes);
diff --git a/src/platform/tests/platform.c b/src/platform/tests/platform.c
index 469652c55f..a70d43601d 100644
--- a/src/platform/tests/platform.c
+++ b/src/platform/tests/platform.c
@@ -24,6 +24,7 @@
#include <arpa/inet.h>
#include <netlink/route/addr.h>
+#include "gsystem-local-alloc.h"
#include "nm-platform.h"
#include "nm-linux-platform.h"
#include "nm-fake-platform.h"
@@ -630,7 +631,7 @@ do_ip4_route_get_all (char **argv)
int i;
if (ifindex) {
- routes = nm_platform_ip4_route_get_all (ifindex, TRUE);
+ routes = nm_platform_ip4_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL);
for (i = 0; i < routes->len; i++) {
route = &g_array_index (routes, NMPlatformIP4Route, i);
inet_ntop (AF_INET, &route->network, networkstr, sizeof (networkstr));
@@ -654,7 +655,7 @@ do_ip6_route_get_all (char **argv)
int i;
if (ifindex) {
- routes = nm_platform_ip6_route_get_all (ifindex, TRUE);
+ routes = nm_platform_ip6_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL);
for (i = 0; i < routes->len; i++) {
route = &g_array_index (routes, NMPlatformIP6Route, i);
inet_ntop (AF_INET6, &route->network, networkstr, sizeof (networkstr));
diff --git a/src/platform/tests/test-cleanup.c b/src/platform/tests/test-cleanup.c
index 646fb8a8db..6bf7f12396 100644
--- a/src/platform/tests/test-cleanup.c
+++ b/src/platform/tests/test-cleanup.c
@@ -52,8 +52,8 @@ test_cleanup_internal (void)
addresses4 = nm_platform_ip4_address_get_all (ifindex);
addresses6 = nm_platform_ip6_address_get_all (ifindex);
- routes4 = nm_platform_ip4_route_get_all (ifindex, TRUE);
- routes6 = nm_platform_ip6_route_get_all (ifindex, TRUE);
+ routes4 = nm_platform_ip4_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL);
+ routes6 = nm_platform_ip6_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL);
g_assert_cmpint (addresses4->len, ==, 1);
g_assert_cmpint (addresses6->len, ==, 1);
@@ -70,8 +70,8 @@ test_cleanup_internal (void)
addresses4 = nm_platform_ip4_address_get_all (ifindex);
addresses6 = nm_platform_ip6_address_get_all (ifindex);
- routes4 = nm_platform_ip4_route_get_all (ifindex, TRUE);
- routes6 = nm_platform_ip6_route_get_all (ifindex, TRUE);
+ routes4 = nm_platform_ip4_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL);
+ routes6 = nm_platform_ip6_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL);
g_assert_cmpint (addresses4->len, ==, 0);
g_assert_cmpint (addresses6->len, ==, 0);
diff --git a/src/platform/tests/test-route.c b/src/platform/tests/test-route.c
index 44598f4c78..299eddda95 100644
--- a/src/platform/tests/test-route.c
+++ b/src/platform/tests/test-route.c
@@ -99,7 +99,7 @@ test_ip4_route (void)
accept_signal (route_changed);
/* Test route listing */
- routes = nm_platform_ip4_route_get_all (ifindex, TRUE);
+ routes = nm_platform_ip4_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL);
memset (rts, 0, sizeof (rts));
rts[0].source = NM_IP_CONFIG_SOURCE_USER;
rts[0].network = gateway;
@@ -194,7 +194,7 @@ test_ip6_route (void)
accept_signal (route_changed);
/* Test route listing */
- routes = nm_platform_ip6_route_get_all (ifindex, TRUE);
+ routes = nm_platform_ip6_route_get_all (ifindex, NM_PLATFORM_GET_ROUTE_MODE_ALL);
memset (rts, 0, sizeof (rts));
rts[0].source = NM_IP_CONFIG_SOURCE_USER;
rts[0].network = gateway;
diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c
index 6a71c02036..78a830bad6 100644
--- a/src/settings/nm-settings-connection.c
+++ b/src/settings/nm-settings-connection.c
@@ -37,6 +37,7 @@
#include "NetworkManagerUtils.h"
#include "nm-properties-changed-signal.h"
#include "nm-core-internal.h"
+#include "nm-glib-compat.h"
#define SETTINGS_TIMESTAMPS_FILE NMSTATEDIR "/timestamps"
#define SETTINGS_SEEN_BSSIDS_FILE NMSTATEDIR "/seen-bssids"
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c
index bd90668203..9ed03f69b9 100644
--- a/src/settings/nm-settings.c
+++ b/src/settings/nm-settings.c
@@ -34,6 +34,7 @@
#include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>
+#include "gsystem-local-alloc.h"
#include <nm-dbus-interface.h>
#include <nm-connection.h>
#include <nm-setting-8021x.h>
diff --git a/src/settings/plugins/ibft/reader.c b/src/settings/plugins/ibft/reader.c
index aac7715a7a..340e197bff 100644
--- a/src/settings/plugins/ibft/reader.c
+++ b/src/settings/plugins/ibft/reader.c
@@ -267,19 +267,15 @@ ip4_setting_add_from_block (const GPtrArray *block,
NMConnection *connection,
GError **error)
{
- NMSettingIP4Config *s_ip4 = NULL;
- NMIP4Address *addr;
+ NMSettingIPConfig *s_ip4 = NULL;
+ NMIPAddress *addr;
const char *s_method = NULL;
const char *s_ipaddr = NULL;
const char *s_gateway = NULL;
const char *s_dns1 = NULL;
const char *s_dns2 = NULL;
const char *s_netmask = NULL;
- guint32 ipaddr = 0;
guint32 netmask = 0;
- guint32 gateway = 0;
- guint32 dns1 = 0;
- guint32 dns2 = 0;
guint32 prefix;
g_assert (block);
@@ -300,10 +296,10 @@ ip4_setting_add_from_block (const GPtrArray *block,
goto error;
}
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
if (!g_ascii_strcasecmp (s_method, "dhcp")) {
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
goto success;
} else if (g_ascii_strcasecmp (s_method, "static") != 0) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
@@ -313,10 +309,10 @@ ip4_setting_add_from_block (const GPtrArray *block,
}
/* Static configuration stuff */
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, NULL);
/* IP address */
- if (!s_ipaddr || inet_pton (AF_INET, s_ipaddr, &ipaddr) != 1) {
+ if (!s_ipaddr || !nm_utils_ipaddr_valid (AF_INET, s_ipaddr)) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"iBFT: malformed iscsiadm record: invalid IP address '%s'.",
s_ipaddr);
@@ -332,38 +328,42 @@ ip4_setting_add_from_block (const GPtrArray *block,
}
prefix = nm_utils_ip4_netmask_to_prefix (netmask);
- if (s_gateway && inet_pton (AF_INET, s_gateway, &gateway) != 1) {
+ if (s_gateway && !nm_utils_ipaddr_valid (AF_INET, s_gateway)) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"iBFT: malformed iscsiadm record: invalid IP gateway '%s'.",
s_gateway);
goto error;
}
- if (s_dns1 && inet_pton (AF_INET, s_dns1, &dns1) != 1) {
+ if (s_dns1 && !nm_utils_ipaddr_valid (AF_INET, s_dns1)) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"iBFT: malformed iscsiadm record: invalid DNS1 address '%s'.",
s_dns1);
goto error;
}
- if (s_dns2 && inet_pton (AF_INET, s_dns2, &dns2) != 1) {
+ if (s_dns2 && !nm_utils_ipaddr_valid (AF_INET, s_dns2)) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"iBFT: malformed iscsiadm record: invalid DNS2 address '%s'.",
s_dns2);
goto error;
}
- addr = nm_ip4_address_new ();
- nm_ip4_address_set_address (addr, ipaddr);
- nm_ip4_address_set_prefix (addr, prefix);
- nm_ip4_address_set_gateway (addr, gateway);
- nm_setting_ip4_config_add_address (s_ip4, addr);
- nm_ip4_address_unref (addr);
+ addr = nm_ip_address_new (AF_INET, s_ipaddr, prefix, error);
+ if (!addr) {
+ g_prefix_error (error, "iBFT: malformed iscsiadm record: ");
+ goto error;
+ }
+
+ nm_setting_ip_config_add_address (s_ip4, addr);
+ nm_ip_address_unref (addr);
+
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_GATEWAY, s_gateway, NULL);
if (s_dns1)
- nm_setting_ip4_config_add_dns (s_ip4, s_dns1);
+ nm_setting_ip_config_add_dns (s_ip4, s_dns1);
if (s_dns2)
- nm_setting_ip4_config_add_dns (s_ip4, s_dns2);
+ nm_setting_ip_config_add_dns (s_ip4, s_dns2);
success:
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
diff --git a/src/settings/plugins/ibft/tests/test-ibft.c b/src/settings/plugins/ibft/tests/test-ibft.c
index 3fb64ac4bd..5fc63b1180 100644
--- a/src/settings/plugins/ibft/tests/test-ibft.c
+++ b/src/settings/plugins/ibft/tests/test-ibft.c
@@ -71,7 +71,7 @@ test_read_ibft_dhcp (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
GError *error = NULL;
const char *mac_address;
const char *expected_mac_address = "00:33:21:98:b9:f1";
@@ -105,7 +105,7 @@ test_read_ibft_dhcp (void)
/* ===== IPv4 SETTING ===== */
s_ip4 = nm_connection_get_setting_ip4_config (connection);
g_assert (s_ip4);
- g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
+ g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
g_object_unref (connection);
}
@@ -116,11 +116,11 @@ test_read_ibft_static (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
GError *error = NULL;
const char *mac_address;
const char *expected_mac_address = "00:33:21:98:b9:f0";
- NMIP4Address *ip4_addr;
+ NMIPAddress *ip4_addr;
GPtrArray *block;
block = read_block (TEST_IBFT_DIR "/iscsiadm-test-static", expected_mac_address);
@@ -151,18 +151,19 @@ test_read_ibft_static (void)
/* ===== IPv4 SETTING ===== */
s_ip4 = nm_connection_get_setting_ip4_config (connection);
g_assert (s_ip4);
- g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL);
+ g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL);
- g_assert_cmpint (nm_setting_ip4_config_get_num_dns (s_ip4), ==, 2);
- g_assert_cmpstr (nm_setting_ip4_config_get_dns (s_ip4, 0), ==, "10.16.255.2");
- g_assert_cmpstr (nm_setting_ip4_config_get_dns (s_ip4, 1), ==, "10.16.255.3");
+ g_assert_cmpint (nm_setting_ip_config_get_num_dns (s_ip4), ==, 2);
+ g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip4, 0), ==, "10.16.255.2");
+ g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip4, 1), ==, "10.16.255.3");
- g_assert_cmpint (nm_setting_ip4_config_get_num_addresses (s_ip4), ==, 1);
- ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 0);
+ g_assert_cmpint (nm_setting_ip_config_get_num_addresses (s_ip4), ==, 1);
+ ip4_addr = nm_setting_ip_config_get_address (s_ip4, 0);
g_assert (ip4_addr);
- nmtst_assert_ip4_address_equals (nm_ip4_address_get_address (ip4_addr), "192.168.32.72");
- g_assert_cmpint (nm_ip4_address_get_prefix (ip4_addr), ==, 22);
- nmtst_assert_ip4_address_equals (nm_ip4_address_get_gateway (ip4_addr), "192.168.35.254");
+ g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "192.168.32.72");
+ g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 22);
+
+ g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, "192.168.35.254");
g_object_unref (connection);
g_ptr_array_unref (block);
@@ -217,10 +218,10 @@ test_read_ibft_vlan (void)
NMSettingConnection *s_con;
NMSettingWired *s_wired;
NMSettingVlan *s_vlan;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
const char *mac_address;
const char *expected_mac_address = "00:33:21:98:b9:f0";
- NMIP4Address *ip4_addr;
+ NMIPAddress *ip4_addr;
GError *error = NULL;
GPtrArray *block;
@@ -250,16 +251,17 @@ test_read_ibft_vlan (void)
/* ===== IPv4 SETTING ===== */
s_ip4 = nm_connection_get_setting_ip4_config (connection);
g_assert (s_ip4);
- g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL);
+ g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL);
- g_assert_cmpint (nm_setting_ip4_config_get_num_dns (s_ip4), ==, 0);
+ g_assert_cmpint (nm_setting_ip_config_get_num_dns (s_ip4), ==, 0);
- g_assert_cmpint (nm_setting_ip4_config_get_num_addresses (s_ip4), ==, 1);
- ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 0);
+ g_assert_cmpint (nm_setting_ip_config_get_num_addresses (s_ip4), ==, 1);
+ ip4_addr = nm_setting_ip_config_get_address (s_ip4, 0);
g_assert (ip4_addr);
- nmtst_assert_ip4_address_equals (nm_ip4_address_get_address (ip4_addr), "192.168.6.200");
- g_assert_cmpint (nm_ip4_address_get_prefix (ip4_addr), ==, 24);
- nmtst_assert_ip4_address_equals (nm_ip4_address_get_gateway (ip4_addr), "0.0.0.0");
+ g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "192.168.6.200");
+ g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 24);
+
+ g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, NULL);
g_object_unref (connection);
g_ptr_array_ref (block);
diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c
index 6994f6af93..f97c84c782 100644
--- a/src/settings/plugins/ifcfg-rh/reader.c
+++ b/src/settings/plugins/ifcfg-rh/reader.c
@@ -255,12 +255,10 @@ make_connection_setting (const char *file,
static gboolean
read_ip4_address (shvarFile *ifcfg,
const char *tag,
- guint32 *out_addr,
+ char **out_addr,
GError **error)
{
char *value = NULL;
- guint32 ip4_addr;
- gboolean success = FALSE;
g_return_val_if_fail (ifcfg != NULL, FALSE);
g_return_val_if_fail (tag != NULL, FALSE);
@@ -268,45 +266,21 @@ read_ip4_address (shvarFile *ifcfg,
if (error)
g_return_val_if_fail (*error == NULL, FALSE);
- *out_addr = 0;
+ *out_addr = NULL;
value = svGetValue (ifcfg, tag, FALSE);
if (!value)
return TRUE;
- if (inet_pton (AF_INET, value, &ip4_addr) > 0) {
- *out_addr = ip4_addr;
- success = TRUE;
+ if (nm_utils_ipaddr_valid (AF_INET, value)) {
+ *out_addr = value;
+ return TRUE;
} else {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid %s IP4 address '%s'", tag, value);
- }
- g_free (value);
- return success;
-}
-
-/* Returns TRUE on valid address, including unspecified (::) */
-static gboolean
-parse_ip6_address (const char *value,
- struct in6_addr *out_addr,
- GError **error)
-{
- struct in6_addr ip6_addr;
-
- g_return_val_if_fail (value != NULL, FALSE);
- g_return_val_if_fail (out_addr != NULL, FALSE);
- if (error)
- g_return_val_if_fail (*error == NULL, FALSE);
-
- *out_addr = in6addr_any;
- if (inet_pton (AF_INET6, value, &ip6_addr) <= 0) {
- g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
- "Invalid IP6 address '%s'", value);
+ g_free (value);
return FALSE;
}
-
- *out_addr = ip6_addr;
- return TRUE;
}
static char *
@@ -358,19 +332,23 @@ static gboolean
read_full_ip4_address (shvarFile *ifcfg,
const char *network_file,
gint32 which,
- NMIP4Address *addr,
+ NMIPAddress *base_addr,
+ NMIPAddress **out_address,
+ char **out_gateway,
GError **error)
{
char *ip_tag, *prefix_tag, *netmask_tag, *gw_tag;
- guint32 tmp;
+ char *ip = NULL;
+ long prefix = 0;
gboolean success = FALSE;
- shvarFile *network_ifcfg;
char *value;
+ guint32 tmp;
g_return_val_if_fail (which >= -1, FALSE);
g_return_val_if_fail (ifcfg != NULL, FALSE);
g_return_val_if_fail (network_file != NULL, FALSE);
- g_return_val_if_fail (addr != NULL, FALSE);
+ g_return_val_if_fail (out_address != NULL, FALSE);
+ g_return_val_if_fail (*out_address == NULL, FALSE);
if (error)
g_return_val_if_fail (*error == NULL, FALSE);
@@ -380,82 +358,73 @@ read_full_ip4_address (shvarFile *ifcfg,
gw_tag = get_numbered_tag ("GATEWAY", which);
/* IP address */
- if (!read_ip4_address (ifcfg, ip_tag, &tmp, error))
- goto done;
- if (tmp)
- nm_ip4_address_set_address (addr, tmp);
- else if (!nm_ip4_address_get_address (addr)) {
- success = TRUE;
+ if (!read_ip4_address (ifcfg, ip_tag, &ip, error))
goto done;
+ if (!ip) {
+ if (base_addr)
+ ip = g_strdup (nm_ip_address_get_address (base_addr));
+ else {
+ success = TRUE;
+ goto done;
+ }
}
/* Gateway */
- if (!read_ip4_address (ifcfg, gw_tag, &tmp, error))
- goto done;
- if (tmp)
- nm_ip4_address_set_gateway (addr, tmp);
- else {
- gboolean read_success;
-
- /* If no gateway in the ifcfg, try /etc/sysconfig/network instead */
- network_ifcfg = svOpenFile (network_file, NULL);
- if (network_ifcfg) {
- read_success = read_ip4_address (network_ifcfg, "GATEWAY", &tmp, error);
- svCloseFile (network_ifcfg);
- if (!read_success)
- goto done;
- nm_ip4_address_set_gateway (addr, tmp);
- }
+ if (out_gateway && !*out_gateway) {
+ if (!read_ip4_address (ifcfg, gw_tag, out_gateway, error))
+ goto done;
}
/* Prefix */
value = svGetValue (ifcfg, prefix_tag, FALSE);
if (value) {
- long int prefix;
-
errno = 0;
prefix = strtol (value, NULL, 10);
- if (errno || prefix <= 0 || prefix > 32) {
+ if (errno || prefix < 0) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid IP4 prefix '%s'", value);
g_free (value);
goto done;
}
- nm_ip4_address_set_prefix (addr, (guint32) prefix);
g_free (value);
}
/* Fall back to NETMASK if no PREFIX was specified */
- if (!nm_ip4_address_get_prefix (addr)) {
- if (!read_ip4_address (ifcfg, netmask_tag, &tmp, error))
+ if (prefix == 0) {
+ if (!read_ip4_address (ifcfg, netmask_tag, &value, error))
goto done;
- if (tmp)
- nm_ip4_address_set_prefix (addr, nm_utils_ip4_netmask_to_prefix (tmp));
+ if (value) {
+ inet_pton (AF_INET, value, &tmp);
+ prefix = nm_utils_ip4_netmask_to_prefix (tmp);
+ g_free (value);
+ }
}
- /* Try to autodetermine the prefix for the address' class */
- if (!nm_ip4_address_get_prefix (addr)) {
- guint32 prefix = 0;
+ if (prefix == 0 && base_addr)
+ prefix = nm_ip_address_get_prefix (base_addr);
- prefix = nm_utils_ip4_get_default_prefix (nm_ip4_address_get_address (addr));
- nm_ip4_address_set_prefix (addr, prefix);
+ /* Try to autodetermine the prefix for the address' class */
+ if (prefix == 0) {
+ if (inet_pton (AF_INET, ip, &tmp) == 1) {
+ prefix = nm_utils_ip4_get_default_prefix (tmp);
- value = svGetValue (ifcfg, ip_tag, FALSE);
- PARSE_WARNING ("missing %s, assuming %s/%u", prefix_tag, value, prefix);
- g_free (value);
+ PARSE_WARNING ("missing %s, assuming %s/%ld", prefix_tag, ip, prefix);
+ }
}
/* Validate the prefix */
- if (nm_ip4_address_get_prefix (addr) > 32) {
+ if (prefix == 0) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
- "Missing or invalid IP4 prefix '%d'",
- nm_ip4_address_get_prefix (addr));
+ "Missing IP4 prefix");
goto done;
}
- success = TRUE;
+ *out_address = nm_ip_address_new (AF_INET, ip, prefix, error);
+ if (*out_address)
+ success = TRUE;
done:
+ g_free (ip);
g_free (ip_tag);
g_free (prefix_tag);
g_free (netmask_tag);
@@ -469,12 +438,12 @@ static gboolean
read_one_ip4_route (shvarFile *ifcfg,
const char *network_file,
guint32 which,
- NMIP4Route **out_route,
+ NMIPRoute **out_route,
GError **error)
{
- NMIP4Route *route;
char *ip_tag, *netmask_tag, *gw_tag, *metric_tag, *value;
- guint32 tmp;
+ char *dest = NULL, *next_hop = NULL;
+ gint64 prefix, metric;
gboolean success = FALSE;
g_return_val_if_fail (ifcfg != NULL, FALSE);
@@ -484,75 +453,72 @@ read_one_ip4_route (shvarFile *ifcfg,
if (error)
g_return_val_if_fail (*error == NULL, FALSE);
- route = nm_ip4_route_new ();
-
ip_tag = g_strdup_printf ("ADDRESS%u", which);
netmask_tag = g_strdup_printf ("NETMASK%u", which);
gw_tag = g_strdup_printf ("GATEWAY%u", which);
metric_tag = g_strdup_printf ("METRIC%u", which);
/* Destination */
- if (!read_ip4_address (ifcfg, ip_tag, &tmp, error))
+ if (!read_ip4_address (ifcfg, ip_tag, &dest, error))
goto out;
- if (!tmp) {
+ if (!dest) {
/* Check whether IP is missing or 0.0.0.0 */
char *val;
val = svGetValue (ifcfg, ip_tag, FALSE);
if (!val) {
- nm_ip4_route_unref (route);
- route = NULL;
+ *out_route = NULL;
success = TRUE; /* missing route = success */
goto out;
}
g_free (val);
}
- nm_ip4_route_set_dest (route, tmp);
/* Next hop */
- if (!read_ip4_address (ifcfg, gw_tag, &tmp, error))
+ if (!read_ip4_address (ifcfg, gw_tag, &next_hop, error))
goto out;
- /* No need to check tmp, because we don't make distinction between missing GATEWAY IP and 0.0.0.0 */
- nm_ip4_route_set_next_hop (route, tmp);
+ /* We don't make distinction between missing GATEWAY IP and 0.0.0.0 */
/* Prefix */
- if (!read_ip4_address (ifcfg, netmask_tag, &tmp, error))
+ if (!read_ip4_address (ifcfg, netmask_tag, &value, error))
goto out;
- if (tmp)
- nm_ip4_route_set_prefix (route, nm_utils_ip4_netmask_to_prefix (tmp));
+ if (value) {
+ guint32 netmask;
- /* Validate the prefix */
- if ( !nm_ip4_route_get_prefix (route)
- || nm_ip4_route_get_prefix (route) > 32) {
+ inet_pton (AF_INET, value, &netmask);
+ prefix = nm_utils_ip4_netmask_to_prefix (netmask);
+ g_free (value);
+ if (netmask != nm_utils_ip4_prefix_to_netmask (prefix)) {
+ g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
+ "Invalid IP4 netmask '%s' \"%s\"", netmask_tag, nm_utils_inet4_ntop (netmask, NULL));
+ goto out;
+ }
+ } else {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
- "Missing or invalid IP4 prefix '%d'",
- nm_ip4_route_get_prefix (route));
+ "Missing IP4 route element '%s'", netmask_tag);
goto out;
}
/* Metric */
value = svGetValue (ifcfg, metric_tag, FALSE);
if (value) {
- long int metric;
-
- errno = 0;
- metric = strtol (value, NULL, 10);
- if (errno || metric < 0) {
+ metric = nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXUINT32, -1);
+ if (metric < 0) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid IP4 route metric '%s'", value);
g_free (value);
goto out;
}
- nm_ip4_route_set_metric (route, (guint32) metric);
g_free (value);
- }
+ } else
+ metric = -1;
- *out_route = route;
- success = TRUE;
+ *out_route = nm_ip_route_new (AF_INET, dest, prefix, next_hop, metric, error);
+ if (*out_route)
+ success = TRUE;
out:
- if (!success && route)
- nm_ip4_route_unref (route);
-
+ g_free (dest);
+ g_free (next_hop);
g_free (ip_tag);
g_free (netmask_tag);
g_free (gw_tag);
@@ -561,17 +527,16 @@ out:
}
static gboolean
-read_route_file_legacy (const char *filename, NMSettingIP4Config *s_ip4, GError **error)
+read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError **error)
{
char *contents = NULL;
gsize len = 0;
char **lines = NULL, **iter;
GRegex *regex_to1, *regex_to2, *regex_via, *regex_metric;
GMatchInfo *match_info;
- NMIP4Route *route;
- guint32 ip4_addr;
- char *dest = NULL, *prefix = NULL, *metric = NULL;
- long int prefix_int, metric_int;
+ NMIPRoute *route = NULL;
+ char *dest = NULL, *prefix = NULL, *next_hop = NULL, *metric = NULL;
+ gint64 prefix_int, metric_int;
gboolean success = FALSE;
const char *pattern_empty = "^\\s*(\\#.*)?$";
@@ -599,9 +564,6 @@ read_route_file_legacy (const char *filename, NMSettingIP4Config *s_ip4, GError
regex_via = g_regex_new (pattern_via, 0, 0, NULL);
regex_metric = g_regex_new (pattern_metric, 0, 0, NULL);
- /* New NMIP4Route structure */
- route = nm_ip4_route_new ();
-
/* Iterate through file lines */
lines = g_strsplit_set (contents, "\n\r", -1);
for (iter = lines; iter && *iter; iter++) {
@@ -625,14 +587,13 @@ read_route_file_legacy (const char *filename, NMSettingIP4Config *s_ip4, GError
dest = g_match_info_fetch (match_info, 1);
if (!strcmp (dest, "default"))
strcpy (dest, "0.0.0.0");
- if (inet_pton (AF_INET, dest, &ip4_addr) != 1) {
+ if (!nm_utils_ipaddr_valid (AF_INET, dest)) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid IP4 route destination address '%s'", dest);
g_free (dest);
+ g_match_info_free (match_info);
goto error;
}
- nm_ip4_route_set_dest (route, ip4_addr);
- g_free (dest);
/* Prefix - is optional; 32 if missing */
prefix = g_match_info_fetch (match_info, 2);
@@ -644,36 +605,35 @@ read_route_file_legacy (const char *filename, NMSettingIP4Config *s_ip4, GError
if (errno || prefix_int <= 0 || prefix_int > 32) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid IP4 route destination prefix '%s'", prefix);
+ g_free (dest);
g_free (prefix);
goto error;
}
}
- nm_ip4_route_set_prefix (route, (guint32) prefix_int);
g_free (prefix);
/* Next hop */
g_regex_match (regex_via, *iter, 0, &match_info);
if (g_match_info_matches (match_info)) {
- char *next_hop = g_match_info_fetch (match_info, 1);
- if (inet_pton (AF_INET, next_hop, &ip4_addr) != 1) {
+ next_hop = g_match_info_fetch (match_info, 1);
+ if (!nm_utils_ipaddr_valid (AF_INET, next_hop)) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid IP4 route gateway address '%s'",
next_hop);
g_match_info_free (match_info);
+ g_free (dest);
g_free (next_hop);
goto error;
}
- g_free (next_hop);
} else {
/* we don't make distinction between missing GATEWAY IP and 0.0.0.0 */
- ip4_addr = 0;
+ next_hop = NULL;
}
- nm_ip4_route_set_next_hop (route, ip4_addr);
g_match_info_free (match_info);
/* Metric */
g_regex_match (regex_metric, *iter, 0, &match_info);
- metric_int = 0;
+ metric_int = -1;
if (g_match_info_matches (match_info)) {
metric = g_match_info_fetch (match_info, 1);
errno = 0;
@@ -682,18 +642,23 @@ read_route_file_legacy (const char *filename, NMSettingIP4Config *s_ip4, GError
g_match_info_free (match_info);
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid IP4 route metric '%s'", metric);
+ g_free (dest);
+ g_free (next_hop);
g_free (metric);
goto error;
}
g_free (metric);
}
-
- nm_ip4_route_set_metric (route, (guint32) metric_int);
g_match_info_free (match_info);
- if (!nm_setting_ip4_config_add_route (s_ip4, route))
+ route = nm_ip_route_new (AF_INET, dest, prefix_int, next_hop, metric_int, error);
+ if (!route) {
+ g_free (dest);
+ g_free (next_hop);
+ goto error;
+ }
+ if (!nm_setting_ip_config_add_route (s_ip4, route))
PARSE_WARNING ("duplicate IP4 route");
-
}
success = TRUE;
@@ -701,7 +666,8 @@ read_route_file_legacy (const char *filename, NMSettingIP4Config *s_ip4, GError
error:
g_free (contents);
g_strfreev (lines);
- nm_ip4_route_unref (route);
+ if (route)
+ nm_ip_route_unref (route);
g_regex_unref (regex_to1);
g_regex_unref (regex_to2);
g_regex_unref (regex_via);
@@ -715,15 +681,12 @@ parse_full_ip6_address (shvarFile *ifcfg,
const char *network_file,
const char *addr_str,
int i,
- NMIP6Address **out_address,
+ NMIPAddress **out_address,
GError **error)
{
- NMIP6Address *addr = NULL;
char **list;
char *ip_val, *prefix_val;
- shvarFile *network_ifcfg;
- char *value = NULL;
- struct in6_addr tmp = IN6ADDR_ANY_INIT;
+ long prefix;
gboolean success = FALSE;
g_return_val_if_fail (addr_str != NULL, FALSE);
@@ -741,23 +704,9 @@ parse_full_ip6_address (shvarFile *ifcfg,
}
ip_val = list[0];
- prefix_val = list[1];
-
- addr = nm_ip6_address_new ();
- /* IP address */
- if (!parse_ip6_address (ip_val, &tmp, error))
- goto error;
- if (IN6_IS_ADDR_UNSPECIFIED (&tmp)) {
- g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
- "Invalid IP6 address '%s'", ip_val);
- goto error;
- }
- nm_ip6_address_set_address (addr, &tmp);
- /* Prefix */
+ prefix_val = list[1];
if (prefix_val) {
- long int prefix;
-
errno = 0;
prefix = strtol (prefix_val, NULL, 10);
if (errno || prefix <= 0 || prefix > 128) {
@@ -765,47 +714,17 @@ parse_full_ip6_address (shvarFile *ifcfg,
"Invalid IP6 prefix '%s'", prefix_val);
goto error;
}
- nm_ip6_address_set_prefix (addr, (guint32) prefix);
} else {
/* Missing prefix is treated as prefix of 64 */
- nm_ip6_address_set_prefix (addr, 64);
- }
-
- /* Gateway */
- tmp = in6addr_any;
- value = svGetValue (ifcfg, "IPV6_DEFAULTGW", FALSE);
- if (i != 0) {
- /* We don't support gateways for IPV6ADDR_SECONDARIES yet */
- g_free (value);
- value = NULL;
- }
- if (!value) {
- /* If no gateway in the ifcfg, try global /etc/sysconfig/network instead */
- network_ifcfg = svOpenFile (network_file, NULL);
- if (network_ifcfg) {
- value = svGetValue (network_ifcfg, "IPV6_DEFAULTGW", FALSE);
- svCloseFile (network_ifcfg);
- }
- }
- if (value) {
- char *ptr;
-
- if ((ptr = strchr (value, '%')) != NULL)
- *ptr = '\0'; /* remove %interface prefix if present */
- if (!parse_ip6_address (value, &tmp, error))
- goto error;
- nm_ip6_address_set_gateway (addr, &tmp);
+ prefix = 64;
}
- *out_address = addr;
- success = TRUE;
+ *out_address = nm_ip_address_new (AF_INET6, ip_val, prefix, error);
+ if (*out_address)
+ success = TRUE;
error:
- if (!success && addr)
- nm_ip6_address_unref (addr);
-
g_strfreev (list);
- g_free (value);
return success;
}
@@ -817,17 +736,16 @@ error:
#define IPV6_ADDR_REGEX "[0-9A-Fa-f:.]+"
static gboolean
-read_route6_file (const char *filename, NMSettingIP6Config *s_ip6, GError **error)
+read_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error)
{
char *contents = NULL;
gsize len = 0;
char **lines = NULL, **iter;
GRegex *regex_to1, *regex_to2, *regex_via, *regex_metric;
GMatchInfo *match_info;
- NMIP6Route *route;
- struct in6_addr ip6_addr;
- char *dest = NULL, *prefix = NULL, *metric = NULL;
- long int prefix_int, metric_int;
+ NMIPRoute *route = NULL;
+ char *dest = NULL, *prefix = NULL, *next_hop = NULL, *metric = NULL;
+ gint64 prefix_int, metric_int;
gboolean success = FALSE;
const char *pattern_empty = "^\\s*(\\#.*)?$";
@@ -855,9 +773,6 @@ read_route6_file (const char *filename, NMSettingIP6Config *s_ip6, GError **erro
regex_via = g_regex_new (pattern_via, 0, 0, NULL);
regex_metric = g_regex_new (pattern_metric, 0, 0, NULL);
- /* New NMIP6Route structure */
- route = nm_ip6_route_new ();
-
/* Iterate through file lines */
lines = g_strsplit_set (contents, "\n\r", -1);
for (iter = lines; iter && *iter; iter++) {
@@ -881,19 +796,11 @@ read_route6_file (const char *filename, NMSettingIP6Config *s_ip6, GError **erro
dest = g_match_info_fetch (match_info, 1);
if (!g_strcmp0 (dest, "default")) {
/* Ignore default route - NM handles it internally */
- g_free (dest);
+ g_clear_pointer (&dest, g_free);
g_match_info_free (match_info);
PARSE_WARNING ("ignoring manual default route: '%s' (%s)", *iter, filename);
continue;
}
- if (inet_pton (AF_INET6, dest, &ip6_addr) != 1) {
- g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
- "Invalid IP6 route destination address '%s'", dest);
- g_free (dest);
- goto error;
- }
- nm_ip6_route_set_dest (route, &ip6_addr);
- g_free (dest);
/* Prefix - is optional; 128 if missing */
prefix = g_match_info_fetch (match_info, 2);
@@ -905,36 +812,35 @@ read_route6_file (const char *filename, NMSettingIP6Config *s_ip6, GError **erro
if (errno || prefix_int <= 0 || prefix_int > 128) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid IP6 route destination prefix '%s'", prefix);
+ g_free (dest);
g_free (prefix);
goto error;
}
}
- nm_ip6_route_set_prefix (route, (guint32) prefix_int);
g_free (prefix);
/* Next hop */
g_regex_match (regex_via, *iter, 0, &match_info);
if (g_match_info_matches (match_info)) {
- char *next_hop = g_match_info_fetch (match_info, 1);
- if (inet_pton (AF_INET6, next_hop, &ip6_addr) != 1) {
+ next_hop = g_match_info_fetch (match_info, 1);
+ if (!nm_utils_ipaddr_valid (AF_INET6, next_hop)) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid IPv6 route nexthop address '%s'",
next_hop);
g_match_info_free (match_info);
+ g_free (dest);
g_free (next_hop);
goto error;
}
- g_free (next_hop);
} else {
/* Missing "via" is taken as :: */
- ip6_addr = in6addr_any;
+ next_hop = NULL;
}
- nm_ip6_route_set_next_hop (route, &ip6_addr);
g_match_info_free (match_info);
/* Metric */
g_regex_match (regex_metric, *iter, 0, &match_info);
- metric_int = 0;
+ metric_int = -1;
if (g_match_info_matches (match_info)) {
metric = g_match_info_fetch (match_info, 1);
errno = 0;
@@ -943,16 +849,21 @@ read_route6_file (const char *filename, NMSettingIP6Config *s_ip6, GError **erro
g_match_info_free (match_info);
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid IP6 route metric '%s'", metric);
+ g_free (dest);
+ g_free (next_hop);
g_free (metric);
goto error;
}
g_free (metric);
}
-
- nm_ip6_route_set_metric (route, (guint32) metric_int);
g_match_info_free (match_info);
- if (!nm_setting_ip6_config_add_route (s_ip6, route))
+ route = nm_ip_route_new (AF_INET6, dest, prefix_int, next_hop, metric_int, error);
+ g_free (dest);
+ g_free (next_hop);
+ if (!route)
+ goto error;
+ if (!nm_setting_ip_config_add_route (s_ip6, route))
PARSE_WARNING ("duplicate IP6 route");
}
@@ -961,7 +872,8 @@ read_route6_file (const char *filename, NMSettingIP6Config *s_ip6, GError **erro
error:
g_free (contents);
g_strfreev (lines);
- nm_ip6_route_unref (route);
+ if (route)
+ nm_ip_route_unref (route);
g_regex_unref (regex_to1);
g_regex_unref (regex_to2);
g_regex_unref (regex_via);
@@ -976,16 +888,17 @@ make_ip4_setting (shvarFile *ifcfg,
const char *network_file,
GError **error)
{
- NMSettingIP4Config *s_ip4 = NULL;
+ NMSettingIPConfig *s_ip4 = NULL;
char *value = NULL;
char *route_path = NULL;
char *method;
+ char *gateway = NULL;
gint32 i;
shvarFile *network_ifcfg;
shvarFile *route_ifcfg;
gboolean never_default = FALSE;
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
/* First check if DEFROUTE is set for this device; DEFROUTE has the
* opposite meaning from never-default. The default if DEFROUTE is not
@@ -1028,15 +941,15 @@ make_ip4_setting (shvarFile *ifcfg,
} else if (!g_ascii_strcasecmp (value, "autoip")) {
g_free (value);
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL,
- NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, never_default,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL,
+ NM_SETTING_IP_CONFIG_NEVER_DEFAULT, never_default,
NULL);
return NM_SETTING (s_ip4);
} else if (!g_ascii_strcasecmp (value, "shared")) {
g_free (value);
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_SHARED,
- NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, never_default,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_SHARED,
+ NM_SETTING_IP_CONFIG_NEVER_DEFAULT, never_default,
NULL);
return NM_SETTING (s_ip4);
} else {
@@ -1048,11 +961,11 @@ make_ip4_setting (shvarFile *ifcfg,
g_free (value);
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, method,
- NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, !svTrueValue (ifcfg, "PEERDNS", TRUE),
- NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES, !svTrueValue (ifcfg, "PEERROUTES", TRUE),
- NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, never_default,
- NM_SETTING_IP4_CONFIG_MAY_FAIL, !svTrueValue (ifcfg, "IPV4_FAILURE_FATAL", FALSE),
+ NM_SETTING_IP_CONFIG_METHOD, method,
+ NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, !svTrueValue (ifcfg, "PEERDNS", TRUE),
+ NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, !svTrueValue (ifcfg, "PEERROUTES", TRUE),
+ NM_SETTING_IP_CONFIG_NEVER_DEFAULT, never_default,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, !svTrueValue (ifcfg, "IPV4_FAILURE_FATAL", FALSE),
NULL);
if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0)
@@ -1062,11 +975,11 @@ make_ip4_setting (shvarFile *ifcfg,
if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) {
value = svGetValue (ifcfg, "DHCP_HOSTNAME", FALSE);
if (value && strlen (value))
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, value, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, value, NULL);
g_free (value);
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME,
+ NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME,
svTrueValue (ifcfg, "DHCP_SEND_HOSTNAME", TRUE),
NULL);
@@ -1082,16 +995,12 @@ make_ip4_setting (shvarFile *ifcfg,
* the legacy 'network' service (ifup-eth).
*/
for (i = -1; i < 256; i++) {
- NMIP4Address *addr = NULL;
+ NMIPAddress *addr = NULL;
- addr = nm_ip4_address_new ();
- if (!read_full_ip4_address (ifcfg, network_file, i, addr, error)) {
- nm_ip4_address_unref (addr);
+ if (!read_full_ip4_address (ifcfg, network_file, i, NULL, &addr, &gateway, error))
goto done;
- }
- if (!nm_ip4_address_get_address (addr)) {
- nm_ip4_address_unref (addr);
+ if (!addr) {
/* The first mandatory variable is 2-indexed (IPADDR2)
* Variables IPADDR, IPADDR0 and IPADDR1 are optional */
if (i > 1)
@@ -1099,37 +1008,46 @@ make_ip4_setting (shvarFile *ifcfg,
continue;
}
- if (!nm_setting_ip4_config_add_address (s_ip4, addr))
+ if (!nm_setting_ip_config_add_address (s_ip4, addr))
PARSE_WARNING ("duplicate IP4 address");
- nm_ip4_address_unref (addr);
+ nm_ip_address_unref (addr);
+ }
+
+ /* Gateway */
+ if (!gateway) {
+ network_ifcfg = svOpenFile (network_file, NULL);
+ if (network_ifcfg) {
+ gboolean read_success;
+
+ read_success = read_ip4_address (network_ifcfg, "GATEWAY", &gateway, error);
+ svCloseFile (network_ifcfg);
+ if (!read_success)
+ goto done;
+ }
}
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_GATEWAY, gateway, NULL);
/* DNS servers
* Pick up just IPv4 addresses (IPv6 addresses are taken by make_ip6_setting())
*/
for (i = 1; i <= 10; i++) {
char *tag;
- guint32 dns;
- struct in6_addr ip6_dns;
tag = g_strdup_printf ("DNS%u", i);
value = svGetValue (ifcfg, tag, FALSE);
if (value) {
- if (!read_ip4_address (ifcfg, tag, &dns, error)) {
- gboolean valid = TRUE;
-
+ if (nm_utils_ipaddr_valid (AF_INET, value)) {
+ if (!nm_setting_ip_config_add_dns (s_ip4, value))
+ PARSE_WARNING ("duplicate DNS server %s", tag);
+ } else if (nm_utils_ipaddr_valid (AF_INET6, value)) {
/* Ignore IPv6 addresses */
- valid = parse_ip6_address (value, &ip6_dns, NULL);
- if (!valid) {
- g_free (tag);
- goto done;
- }
- g_clear_error (error);
- dns = 0;
+ } else {
+ PARSE_WARNING ("invalid DNS server address %s", value);
+ g_free (tag);
+ g_free (value);
+ goto done;
}
- if (dns && !nm_setting_ip4_config_add_dns (s_ip4, value))
- PARSE_WARNING ("duplicate DNS server %s", tag);
g_free (value);
}
@@ -1146,7 +1064,7 @@ make_ip4_setting (shvarFile *ifcfg,
char **item;
for (item = searches; *item; item++) {
if (strlen (*item)) {
- if (!nm_setting_ip4_config_add_dns_search (s_ip4, *item))
+ if (!nm_setting_ip_config_add_dns_search (s_ip4, *item))
PARSE_WARNING ("duplicate DNS domain '%s'", *item);
}
}
@@ -1169,7 +1087,7 @@ make_ip4_setting (shvarFile *ifcfg,
route_ifcfg = utils_get_route_ifcfg (ifcfg->fileName, FALSE);
if (route_ifcfg) {
for (i = 0; i < 256; i++) {
- NMIP4Route *route = NULL;
+ NMIPRoute *route = NULL;
if (!read_one_ip4_route (route_ifcfg, network_file, i, &route, error)) {
svCloseFile (route_ifcfg);
@@ -1179,9 +1097,9 @@ make_ip4_setting (shvarFile *ifcfg,
if (!route)
break;
- if (!nm_setting_ip4_config_add_route (s_ip4, route))
+ if (!nm_setting_ip_config_add_route (s_ip4, route))
PARSE_WARNING ("duplicate IP4 route");
- nm_ip4_route_unref (route);
+ nm_ip_route_unref (route);
}
svCloseFile (route_ifcfg);
}
@@ -1191,7 +1109,7 @@ make_ip4_setting (shvarFile *ifcfg,
}
/* Legacy value NM used for a while but is incorrect (rh #459370) */
- if (!nm_setting_ip4_config_get_num_dns_searches (s_ip4)) {
+ if (!nm_setting_ip_config_get_num_dns_searches (s_ip4)) {
value = svGetValue (ifcfg, "SEARCH", FALSE);
if (value) {
char **searches = NULL;
@@ -1201,7 +1119,7 @@ make_ip4_setting (shvarFile *ifcfg,
char **item;
for (item = searches; *item; item++) {
if (strlen (*item)) {
- if (!nm_setting_ip4_config_add_dns_search (s_ip4, *item))
+ if (!nm_setting_ip_config_add_dns_search (s_ip4, *item))
PARSE_WARNING ("duplicate DNS search '%s'", *item);
}
}
@@ -1214,27 +1132,28 @@ make_ip4_setting (shvarFile *ifcfg,
return NM_SETTING (s_ip4);
done:
+ g_free (gateway);
g_free (route_path);
g_object_unref (s_ip4);
return NULL;
}
static void
-read_aliases (NMSettingIP4Config *s_ip4, const char *filename, const char *network_file)
+read_aliases (NMSettingIPConfig *s_ip4, const char *filename, const char *network_file)
{
GDir *dir;
char *dirname, *base;
shvarFile *parsed;
- NMIP4Address *base_addr;
+ NMIPAddress *base_addr;
GError *err = NULL;
g_return_if_fail (s_ip4 != NULL);
g_return_if_fail (filename != NULL);
- if (nm_setting_ip4_config_get_num_addresses (s_ip4) == 0)
+ if (nm_setting_ip_config_get_num_addresses (s_ip4) == 0)
return;
- base_addr = nm_setting_ip4_config_get_address (s_ip4, 0);
+ base_addr = nm_setting_ip_config_get_address (s_ip4, 0);
dirname = g_path_get_dirname (filename);
g_return_if_fail (dirname != NULL);
@@ -1244,7 +1163,7 @@ read_aliases (NMSettingIP4Config *s_ip4, const char *filename, const char *netwo
dir = g_dir_open (dirname, 0, &err);
if (dir) {
const char *item;
- NMIP4Address *addr;
+ NMIPAddress *addr;
gboolean ok;
while ((item = g_dir_read_name (dir))) {
@@ -1293,18 +1212,19 @@ read_aliases (NMSettingIP4Config *s_ip4, const char *filename, const char *netwo
continue;
}
- addr = nm_ip4_address_dup (base_addr);
- ok = read_full_ip4_address (parsed, network_file, -1, addr, &err);
+ addr = NULL;
+ ok = read_full_ip4_address (parsed, network_file, -1, base_addr, &addr, NULL, &err);
svCloseFile (parsed);
if (ok) {
- if (!_nm_setting_ip4_config_add_address_with_label (s_ip4, addr, device))
+ nm_ip_address_set_attribute (addr, "label", g_variant_new_string (device));
+ if (!nm_setting_ip_config_add_address (s_ip4, addr))
PARSE_WARNING ("duplicate IP4 address in alias file %s", item);
} else {
PARSE_WARNING ("error reading IP4 address from alias file '%s': %s",
full_path, err ? err->message : "no address");
g_clear_error (&err);
}
- nm_ip4_address_unref (addr);
+ nm_ip_address_unref (addr);
g_free (device);
g_free (full_path);
@@ -1325,7 +1245,7 @@ make_ip6_setting (shvarFile *ifcfg,
const char *network_file,
GError **error)
{
- NMSettingIP6Config *s_ip6 = NULL;
+ NMSettingIPConfig *s_ip6 = NULL;
char *value = NULL;
char *str_value;
char *route6_path = NULL;
@@ -1340,7 +1260,7 @@ make_ip6_setting (shvarFile *ifcfg,
char *ip6_privacy_str;
NMSettingIP6ConfigPrivacy ip6_privacy_val;
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
/* First check if IPV6_DEFROUTE is set for this device; IPV6_DEFROUTE has the
* opposite meaning from never-default. The default if IPV6_DEFROUTE is not
@@ -1437,11 +1357,11 @@ make_ip6_setting (shvarFile *ifcfg,
g_free (ip6_privacy_str);
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, method,
- NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS, !svTrueValue (ifcfg, "IPV6_PEERDNS", TRUE),
- NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES, !svTrueValue (ifcfg, "IPV6_PEERROUTES", TRUE),
- NM_SETTING_IP6_CONFIG_NEVER_DEFAULT, never_default,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, !svTrueValue (ifcfg, "IPV6_FAILURE_FATAL", FALSE),
+ NM_SETTING_IP_CONFIG_METHOD, method,
+ NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, !svTrueValue (ifcfg, "IPV6_PEERDNS", TRUE),
+ NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, !svTrueValue (ifcfg, "IPV6_PEERROUTES", TRUE),
+ NM_SETTING_IP_CONFIG_NEVER_DEFAULT, never_default,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, !svTrueValue (ifcfg, "IPV6_FAILURE_FATAL", FALSE),
NM_SETTING_IP6_CONFIG_IP6_PRIVACY, ip6_privacy_val,
NULL);
@@ -1454,7 +1374,7 @@ make_ip6_setting (shvarFile *ifcfg,
/* METHOD_AUTO may trigger DHCPv6, so save the hostname to send to DHCP */
value = svGetValue (ifcfg, "DHCP_HOSTNAME", FALSE);
if (value && value[0])
- g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME, value, NULL);
+ g_object_set (s_ip6, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, value, NULL);
g_free (value);
}
@@ -1476,26 +1396,51 @@ make_ip6_setting (shvarFile *ifcfg,
list = g_strsplit_set (value, " ", 0);
g_free (value);
for (iter = list, i = 0; iter && *iter; iter++, i++) {
- NMIP6Address *addr = NULL;
+ NMIPAddress *addr = NULL;
if (!parse_full_ip6_address (ifcfg, network_file, *iter, i, &addr, error)) {
g_strfreev (list);
goto error;
}
- if (!nm_setting_ip6_config_add_address (s_ip6, addr))
+ if (!nm_setting_ip_config_add_address (s_ip6, addr))
PARSE_WARNING ("duplicate IP6 address");
- nm_ip6_address_unref (addr);
+ nm_ip_address_unref (addr);
}
g_strfreev (list);
+ /* Gateway */
+ if (nm_setting_ip_config_get_num_addresses (s_ip6)) {
+ value = svGetValue (ifcfg, "IPV6_DEFAULTGW", FALSE);
+ if (!value) {
+ /* If no gateway in the ifcfg, try global /etc/sysconfig/network instead */
+ network_ifcfg = svOpenFile (network_file, NULL);
+ if (network_ifcfg) {
+ value = svGetValue (network_ifcfg, "IPV6_DEFAULTGW", FALSE);
+ svCloseFile (network_ifcfg);
+ }
+ }
+ if (value) {
+ char *ptr;
+ if ((ptr = strchr (value, '%')) != NULL)
+ *ptr = '\0'; /* remove %interface prefix if present */
+ if (!nm_utils_ipaddr_valid (AF_INET6, value)) {
+ g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
+ "Invalid IP6 address '%s'", value);
+ g_free (value);
+ goto error;
+ }
+
+ g_object_set (s_ip6, NM_SETTING_IP_CONFIG_GATEWAY, value, NULL);
+ g_free (value);
+ }
+ }
+
/* DNS servers
* Pick up just IPv6 addresses (IPv4 addresses are taken by make_ip4_setting())
*/
for (i = 1; i <= 10; i++) {
char *tag;
- struct in6_addr ip6_dns;
- guint32 ip4_addr;
tag = g_strdup_printf ("DNS%u", i);
value = svGetValue (ifcfg, tag, FALSE);
@@ -1504,25 +1449,23 @@ make_ip6_setting (shvarFile *ifcfg,
break; /* all done */
}
- ip6_dns = in6addr_any;
- if (parse_ip6_address (value, &ip6_dns, NULL)) {
- if (!IN6_IS_ADDR_UNSPECIFIED (&ip6_dns) && !nm_setting_ip6_config_add_dns (s_ip6, value))
+ if (nm_utils_ipaddr_valid (AF_INET6, value)) {
+ if (!nm_setting_ip_config_add_dns (s_ip6, value))
PARSE_WARNING ("duplicate DNS server %s", tag);
+ } else if (nm_utils_ipaddr_valid (AF_INET, value)) {
+ /* Ignore IPv4 addresses */
} else {
- /* Maybe an IPv4 address? If so ignore it */
- if (inet_pton (AF_INET, value, &ip4_addr) != 1) {
- g_free (tag);
- g_free (value);
- PARSE_WARNING ("duplicate IP6 address");
- goto error;
- }
+ PARSE_WARNING ("invalid DNS server address %s", value);
+ g_free (tag);
+ g_free (value);
+ goto error;
}
g_free (tag);
g_free (value);
}
- /* DNS searches ('DOMAIN' key) are read by make_ip4_setting() and included in NMSettingIP4Config */
+ /* DNS searches ('DOMAIN' key) are read by make_ip4_setting() and included in NMSettingIPConfig */
/* Read static routes from route6-<interface> file */
route6_path = utils_get_route6_path (ifcfg->fileName);
@@ -3281,7 +3224,6 @@ make_wireless_setting (shvarFile *ifcfg,
GError **error)
{
NMSettingWireless *s_wireless;
- GBytes *bytes = NULL;
char *value = NULL;
gint64 chan = 0;
@@ -3313,19 +3255,19 @@ make_wireless_setting (shvarFile *ifcfg,
value = svGetValue (ifcfg, "ESSID", TRUE);
if (value) {
- gsize ssid_len = 0, value_len = strlen (value);
- char *p = value, *tmp;
- char buf[33];
+ GBytes *bytes = NULL;
+ gsize ssid_len = 0;
+ gsize value_len = strlen (value);
- ssid_len = value_len;
if ( (value_len >= 2)
&& (value[0] == '"')
&& (value[value_len - 1] == '"')) {
/* Strip the quotes and unescape */
- p = value + 1;
+ char *p = value + 1;
+
value[value_len - 1] = '\0';
svUnescape (p);
- ssid_len = strlen (p);
+ bytes = g_bytes_new (p, strlen (p));
} else if ((value_len > 2) && (strncmp (value, "0x", 2) == 0)) {
/* Hex representation */
if (value_len % 2) {
@@ -3336,34 +3278,27 @@ make_wireless_setting (shvarFile *ifcfg,
goto error;
}
- p = value + 2;
- while (*p) {
- if (!g_ascii_isxdigit (*p)) {
- g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
- "Invalid SSID '%s' character (looks like hex SSID but '%c' isn't a hex digit)",
- value, *p);
- g_free (value);
- goto error;
- }
- p++;
+ bytes = nm_utils_hexstr2bin (value);
+ if (!bytes) {
+ g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
+ "Invalid SSID '%s' (looks like hex SSID but isn't)",
+ value);
+ g_free (value);
+ goto error;
}
+ } else
+ bytes = g_bytes_new (value, value_len);
- tmp = nm_utils_hexstr2bin (value + 2, value_len - 2);
- ssid_len = (value_len - 2) / 2;
- memcpy (buf, tmp, ssid_len);
- p = &buf[0];
- g_free (tmp);
- }
-
+ ssid_len = g_bytes_get_size (bytes);
if (ssid_len > 32 || ssid_len == 0) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid SSID '%s' (size %zu not between 1 and 32 inclusive)",
value, ssid_len);
+ g_bytes_unref (bytes);
g_free (value);
goto error;
}
- bytes = g_bytes_new (p, ssid_len);
g_object_set (s_wireless, NM_SETTING_WIRELESS_SSID, bytes, NULL);
g_bytes_unref (bytes);
g_free (value);
@@ -4669,7 +4604,7 @@ check_dns_search_domains (shvarFile *ifcfg, NMSetting *s_ip4, NMSetting *s_ip6)
/* If there is no IPv4 config or it doesn't contain DNS searches,
* read DOMAIN and put the domains into IPv6.
*/
- if (!s_ip4 || nm_setting_ip4_config_get_num_dns_searches (NM_SETTING_IP4_CONFIG (s_ip4)) == 0) {
+ if (!s_ip4 || nm_setting_ip_config_get_num_dns_searches (NM_SETTING_IP_CONFIG (s_ip4)) == 0) {
/* DNS searches */
char *value = svGetValue (ifcfg, "DOMAIN", FALSE);
if (value) {
@@ -4678,7 +4613,7 @@ check_dns_search_domains (shvarFile *ifcfg, NMSetting *s_ip4, NMSetting *s_ip6)
char **item;
for (item = searches; *item; item++) {
if (strlen (*item)) {
- if (!nm_setting_ip6_config_add_dns_search (NM_SETTING_IP6_CONFIG (s_ip6), *item))
+ if (!nm_setting_ip_config_add_dns_search (NM_SETTING_IP_CONFIG (s_ip6), *item))
PARSE_WARNING ("duplicate DNS domain '%s'", *item);
}
}
@@ -4859,7 +4794,7 @@ connection_from_file (const char *filename,
connection = NULL;
goto done;
} else {
- read_aliases (NM_SETTING_IP4_CONFIG (s_ip4), filename, network_file);
+ read_aliases (NM_SETTING_IP_CONFIG (s_ip4), filename, network_file);
nm_connection_add_setting (connection, s_ip4);
}
diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c
index b4c911fb6d..bdfd40a31f 100644
--- a/src/settings/plugins/ifcfg-rh/shvar.c
+++ b/src/settings/plugins/ifcfg-rh/shvar.c
@@ -238,8 +238,7 @@ svEscape (const char *s)
new[j++] = s[i];
}
new[j++] = '"';
- new[j++] = '\0'
-;
+ new[j++] = '\0';
g_assert (j == slen + mangle - newline + 3);
return new;
@@ -266,7 +265,8 @@ svGetValue (shvarFile *s, const char *key, gboolean verbatim)
for (s->current = s->lineList; s->current; s->current = s->current->next) {
line = s->current->data;
if (!strncmp (keyString, line, len)) {
- value = g_strdup (line + len);
+ /* Strip trailing spaces before unescaping to preserve spaces quoted whitespace */
+ value = g_strchomp (g_strdup (line + len));
if (!verbatim)
svUnescape (value);
break;
diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am b/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am
index 9c9a3b13f8..8941da3a62 100644
--- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am
+++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am
@@ -119,7 +119,8 @@ EXTRA_DIST = \
ifcfg-test-fcoe-vn2vn \
ifcfg-test-team-master \
ifcfg-test-team-port \
- ifcfg-test-team-port-empty-config
+ ifcfg-test-team-port-empty-config \
+ ifcfg-test-vlan-trailing-spaces
# make target dependencies can't have colons in their names, which ends up
# meaning that we can't add the alias files to EXTRA_DIST
diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-trailing-spaces b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-trailing-spaces
new file mode 100644
index 0000000000..4a31e475ae
--- /dev/null
+++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-trailing-spaces
@@ -0,0 +1,11 @@
+DEVICE="vlan201"
+ONBOOT=yes
+NETBOOT=yes
+BOOTPROTO=none
+IPADDR="10.130.70.7"
+NETMASK="255.255.0.0"
+TYPE=Vlan
+NAME="vlan201"
+VLAN=yes
+PHYSDEV="enccw0.0.fb00"
+
diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
index b2d91e46f6..fbb0b9686a 100644
--- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
+++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
@@ -183,8 +183,8 @@ test_read_basic (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
GError *error = NULL;
const char *mac;
char expected_mac_address[ETH_ALEN] = { 0x00, 0x16, 0x41, 0x11, 0x22, 0x33 };
@@ -225,14 +225,14 @@ test_read_basic (void)
/* ===== IPv4 SETTING ===== */
s_ip4 = nm_connection_get_setting_ip4_config (connection);
g_assert (s_ip4);
- g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED);
- g_assert (nm_setting_ip4_config_get_never_default (s_ip4) == FALSE);
+ g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED);
+ g_assert (nm_setting_ip_config_get_never_default (s_ip4) == FALSE);
/* ===== IPv6 SETTING ===== */
s_ip6 = nm_connection_get_setting_ip6_config (connection);
g_assert (s_ip6);
- g_assert_cmpstr (nm_setting_ip6_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_IGNORE);
- g_assert (nm_setting_ip6_config_get_never_default (s_ip6) == FALSE);
+ g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_IGNORE);
+ g_assert (nm_setting_ip_config_get_never_default (s_ip6) == FALSE);
g_object_unref (connection);
}
@@ -243,7 +243,7 @@ test_read_miscellaneous_variables (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
GError *error = NULL;
char *expected_mac_blacklist[3] = { "00:16:41:11:22:88", "00:16:41:11:22:99", "6a:5d:5a:fa:dd:f0" };
int mac_blacklist_num, i;
@@ -281,8 +281,8 @@ test_read_miscellaneous_variables (void)
/* ===== IPv4 SETTING ===== */
s_ip4 = nm_connection_get_setting_ip4_config (connection);
g_assert (s_ip4);
- g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED);
- g_assert (nm_setting_ip4_config_get_never_default (s_ip4) == FALSE);
+ g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED);
+ g_assert (nm_setting_ip_config_get_never_default (s_ip4) == FALSE);
g_object_unref (connection);
}
@@ -293,7 +293,7 @@ test_read_variables_corner_cases (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
GError *error = NULL;
const char *mac;
char expected_mac_address[ETH_ALEN] = { 0x00, 0x16, 0x41, 0x11, 0x22, 0x33 };
@@ -331,8 +331,8 @@ test_read_variables_corner_cases (void)
/* ===== IPv4 SETTING ===== */
s_ip4 = nm_connection_get_setting_ip4_config (connection);
g_assert (s_ip4);
- g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED);
- g_assert (nm_setting_ip4_config_get_never_default (s_ip4) == FALSE);
+ g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED);
+ g_assert (nm_setting_ip_config_get_never_default (s_ip4) == FALSE);
g_object_unref (connection);
}
@@ -440,17 +440,14 @@ test_read_wired_static (const char *file,
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *unmanaged = NULL;
GError *error = NULL;
const char *mac;
char expected_mac_address[ETH_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0xee };
- struct in6_addr addr6;
- const char *expected6_address1 = "dead:beaf::1";
- const char *expected6_address2 = "dead:beaf::2";
- NMIP4Address *ip4_addr;
- NMIP6Address *ip6_addr;
+ NMIPAddress *ip4_addr;
+ NMIPAddress *ip6_addr;
gboolean success;
connection = connection_from_file (file, NULL, TYPE_ETHERNET,
@@ -482,50 +479,50 @@ test_read_wired_static (const char *file,
/* ===== IPv4 SETTING ===== */
s_ip4 = nm_connection_get_setting_ip4_config (connection);
g_assert (s_ip4);
- g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL);
- g_assert (nm_setting_ip4_config_get_may_fail (s_ip4));
+ g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL);
+ g_assert (nm_setting_ip_config_get_may_fail (s_ip4));
/* DNS Addresses */
- g_assert_cmpint (nm_setting_ip4_config_get_num_dns (s_ip4), ==, 2);
- g_assert_cmpstr (nm_setting_ip4_config_get_dns (s_ip4, 0), ==, "4.2.2.1");
- g_assert_cmpstr (nm_setting_ip4_config_get_dns (s_ip4, 1), ==, "4.2.2.2");
+ g_assert_cmpint (nm_setting_ip_config_get_num_dns (s_ip4), ==, 2);
+ g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip4, 0), ==, "4.2.2.1");
+ g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip4, 1), ==, "4.2.2.2");
/* IP addresses */
- g_assert_cmpint (nm_setting_ip4_config_get_num_addresses (s_ip4), ==, 1);
- ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 0);
+ g_assert_cmpint (nm_setting_ip_config_get_num_addresses (s_ip4), ==, 1);
+ ip4_addr = nm_setting_ip_config_get_address (s_ip4, 0);
g_assert (ip4_addr);
- g_assert_cmpint (nm_ip4_address_get_prefix (ip4_addr), ==, 24);
- nmtst_assert_ip4_address_equals (nm_ip4_address_get_address (ip4_addr), "192.168.1.5");
- nmtst_assert_ip4_address_equals (nm_ip4_address_get_gateway (ip4_addr), "192.168.1.1");
+ g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 24);
+ g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "192.168.1.5");
+
+ /* Gateway */
+ g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, "192.168.1.1");
/* ===== IPv6 SETTING ===== */
s_ip6 = nm_connection_get_setting_ip6_config (connection);
g_assert (s_ip6);
if (expect_ip6) {
- g_assert_cmpstr (nm_setting_ip6_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_MANUAL);
- g_assert (nm_setting_ip6_config_get_may_fail (s_ip6));
+ g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_MANUAL);
+ g_assert (nm_setting_ip_config_get_may_fail (s_ip6));
/* DNS Addresses */
- g_assert_cmpint (nm_setting_ip6_config_get_num_dns (s_ip6), ==, 2);
- g_assert_cmpstr (nm_setting_ip6_config_get_dns (s_ip6, 0), ==, "1:2:3:4::a");
- g_assert_cmpstr (nm_setting_ip6_config_get_dns (s_ip6, 1), ==, "1:2:3:4::b");
+ g_assert_cmpint (nm_setting_ip_config_get_num_dns (s_ip6), ==, 2);
+ g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip6, 0), ==, "1:2:3:4::a");
+ g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip6, 1), ==, "1:2:3:4::b");
/* IP addresses */
- g_assert_cmpint (nm_setting_ip6_config_get_num_addresses (s_ip6), ==, 2);
+ g_assert_cmpint (nm_setting_ip_config_get_num_addresses (s_ip6), ==, 2);
- ip6_addr = nm_setting_ip6_config_get_address (s_ip6, 0);
+ ip6_addr = nm_setting_ip_config_get_address (s_ip6, 0);
g_assert (ip6_addr);
- g_assert_cmpint (nm_ip6_address_get_prefix (ip6_addr), ==, 64);
- g_assert_cmpint (inet_pton (AF_INET6, expected6_address1, &addr6), >, 0);
- g_assert (IN6_ARE_ADDR_EQUAL (nm_ip6_address_get_address (ip6_addr), &addr6));
+ g_assert_cmpint (nm_ip_address_get_prefix (ip6_addr), ==, 64);
+ g_assert_cmpstr (nm_ip_address_get_address (ip6_addr), ==, "dead:beaf::1");
- ip6_addr = nm_setting_ip6_config_get_address (s_ip6, 1);
+ ip6_addr = nm_setting_ip_config_get_address (s_ip6, 1);
g_assert (ip6_addr);
- g_assert_cmpint (nm_ip6_address_get_prefix (ip6_addr), ==, 56);
- g_assert_cmpint (inet_pton (AF_INET6, expected6_address2, &addr6), >, 0);
- g_assert (IN6_ARE_ADDR_EQUAL (nm_ip6_address_get_address (ip6_addr), &addr6));
+ g_assert_cmpint (nm_ip_address_get_prefix (ip6_addr), ==, 56);
+ g_assert_cmpstr (nm_ip_address_get_address (ip6_addr), ==, "dead:beaf::2");
} else {
- g_assert_cmpstr (nm_setting_ip6_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_IGNORE);
+ g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_IGNORE);
}
g_free (unmanaged);
@@ -538,9 +535,9 @@ test_read_wired_static_no_prefix (gconstpointer user_data)
guint32 expected_prefix = GPOINTER_TO_UINT (user_data);
NMConnection *connection;
NMSettingConnection *s_con;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
GError *error = NULL;
- NMIP4Address *ip4_addr;
+ NMIPAddress *ip4_addr;
char *file, *expected_id;
file = g_strdup_printf (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wired-static-no-prefix-%u", expected_prefix);
@@ -563,12 +560,12 @@ test_read_wired_static_no_prefix (gconstpointer user_data)
/* ===== IPv4 SETTING ===== */
s_ip4 = nm_connection_get_setting_ip4_config (connection);
g_assert (s_ip4);
- g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL);
+ g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL);
- g_assert_cmpint (nm_setting_ip4_config_get_num_addresses (s_ip4), ==, 1);
- ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 0);
+ g_assert_cmpint (nm_setting_ip_config_get_num_addresses (s_ip4), ==, 1);
+ ip4_addr = nm_setting_ip_config_get_address (s_ip4, 0);
g_assert (ip4_addr);
- g_assert_cmpint (nm_ip4_address_get_prefix (ip4_addr), ==, expected_prefix);
+ g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, expected_prefix);
g_free (file);
g_free (expected_id);
@@ -583,7 +580,7 @@ test_read_wired_dhcp (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
char *unmanaged = NULL;
char *keyfile = NULL;
char *routefile = NULL;
@@ -679,49 +676,49 @@ test_read_wired_dhcp (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip4_config_get_method (s_ip4);
+ tmp = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0,
"wired-dhcp-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_DHCP,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
- tmp = nm_setting_ip4_config_get_dhcp_hostname (s_ip4);
+ tmp = nm_setting_ip_config_get_dhcp_hostname (s_ip4);
ASSERT (tmp != NULL,
"wired-dhcp-verify-ip4", "failed to verify %s: missing %s / %s key",
TEST_IFCFG_WIRED_DHCP,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME);
+ NM_SETTING_IP_CONFIG_DHCP_HOSTNAME);
ASSERT (strcmp (tmp, expected_dhcp_hostname) == 0,
"wired-dhcp-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_DHCP,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME);
+ NM_SETTING_IP_CONFIG_DHCP_HOSTNAME);
- ASSERT (nm_setting_ip4_config_get_ignore_auto_dns (s_ip4) == TRUE,
+ ASSERT (nm_setting_ip_config_get_ignore_auto_dns (s_ip4) == TRUE,
"wired-dhcp-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_DHCP,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS);
+ NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS);
/* DNS Addresses */
- ASSERT (nm_setting_ip4_config_get_num_dns (s_ip4) == 2,
+ ASSERT (nm_setting_ip_config_get_num_dns (s_ip4) == 2,
"wired-dhcp-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_DHCP,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
- ASSERT (strcmp (nm_setting_ip4_config_get_dns (s_ip4, 0), "4.2.2.1") == 0,
+ ASSERT (strcmp (nm_setting_ip_config_get_dns (s_ip4, 0), "4.2.2.1") == 0,
"wired-dhcp-verify-ip4", "failed to verify %s: unexpected %s / %s key value #1",
TEST_IFCFG_WIRED_DHCP,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
- ASSERT (strcmp (nm_setting_ip4_config_get_dns (s_ip4, 1), "4.2.2.2") == 0,
+ ASSERT (strcmp (nm_setting_ip_config_get_dns (s_ip4, 1), "4.2.2.2") == 0,
"wired-dhcp-verify-ip4", "failed to verify %s: unexpected %s / %s key value #2",
TEST_IFCFG_WIRED_DHCP,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
g_free (unmanaged);
g_free (keyfile);
@@ -734,13 +731,11 @@ static void
test_read_wired_dhcp_plus_ip (void)
{
NMConnection *connection;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
GError *error = NULL;
- guint32 addr4;
- struct in6_addr addr6;
- NMIP4Address *ip4_addr;
- NMIP6Address *ip6_addr;
+ NMIPAddress *ip4_addr;
+ NMIPAddress *ip6_addr;
gboolean success;
connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-dhcp-plus-ip",
@@ -755,60 +750,56 @@ test_read_wired_dhcp_plus_ip (void)
/* ===== IPv4 SETTING ===== */
s_ip4 = nm_connection_get_setting_ip4_config (connection);
g_assert (s_ip4);
- g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
- g_assert (nm_setting_ip4_config_get_may_fail (s_ip4));
+ g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
+ g_assert (nm_setting_ip_config_get_may_fail (s_ip4));
/* DNS Addresses */
- g_assert_cmpint (nm_setting_ip4_config_get_num_dns (s_ip4), ==, 2);
- g_assert_cmpstr (nm_setting_ip4_config_get_dns (s_ip4, 0), ==, "4.2.2.1");
- g_assert_cmpstr (nm_setting_ip4_config_get_dns (s_ip4, 1), ==, "4.2.2.2");
+ g_assert_cmpint (nm_setting_ip_config_get_num_dns (s_ip4), ==, 2);
+ g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip4, 0), ==, "4.2.2.1");
+ g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip4, 1), ==, "4.2.2.2");
/* IP addresses */
- g_assert_cmpint (nm_setting_ip4_config_get_num_addresses (s_ip4), ==, 2);
- ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 0);
+ g_assert_cmpint (nm_setting_ip_config_get_num_addresses (s_ip4), ==, 2);
+ ip4_addr = nm_setting_ip_config_get_address (s_ip4, 0);
g_assert (ip4_addr);
- g_assert_cmpint (nm_ip4_address_get_prefix (ip4_addr), ==, 24);
- g_assert_cmpint (inet_pton (AF_INET, "1.2.3.4", &addr4), >, 0);
- g_assert_cmpint (nm_ip4_address_get_address (ip4_addr), ==, addr4);
- g_assert_cmpint (inet_pton (AF_INET, "1.1.1.1", &addr4), >, 0);
- g_assert_cmpint (nm_ip4_address_get_gateway (ip4_addr), ==, addr4);
+ g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 24);
+ g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "1.2.3.4");
+
+ /* Gateway */
+ g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, "1.1.1.1");
- ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 1);
+ ip4_addr = nm_setting_ip_config_get_address (s_ip4, 1);
g_assert (ip4_addr);
- g_assert_cmpint (nm_ip4_address_get_prefix (ip4_addr), ==, 16);
- g_assert_cmpint (inet_pton (AF_INET, "9.8.7.6", &addr4), >, 0);
- g_assert_cmpint (nm_ip4_address_get_address (ip4_addr), ==, addr4);
+ g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 16);
+ g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "9.8.7.6");
/* ===== IPv6 SETTING ===== */
s_ip6 = nm_connection_get_setting_ip6_config (connection);
g_assert (s_ip6);
- g_assert_cmpstr (nm_setting_ip6_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO);
- g_assert (nm_setting_ip6_config_get_may_fail (s_ip6));
+ g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO);
+ g_assert (nm_setting_ip_config_get_may_fail (s_ip6));
/* DNS Addresses */
- g_assert_cmpint (nm_setting_ip6_config_get_num_dns (s_ip6), ==, 2);
- g_assert_cmpstr (nm_setting_ip6_config_get_dns (s_ip6, 0), ==, "1:2:3:4::a");
- g_assert_cmpstr (nm_setting_ip6_config_get_dns (s_ip6, 1), ==, "1:2:3:4::b");
+ g_assert_cmpint (nm_setting_ip_config_get_num_dns (s_ip6), ==, 2);
+ g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip6, 0), ==, "1:2:3:4::a");
+ g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip6, 1), ==, "1:2:3:4::b");
/* IP addresses */
- g_assert_cmpint (nm_setting_ip6_config_get_num_addresses (s_ip6), ==, 3);
- ip6_addr = nm_setting_ip6_config_get_address (s_ip6, 0);
+ g_assert_cmpint (nm_setting_ip_config_get_num_addresses (s_ip6), ==, 3);
+ ip6_addr = nm_setting_ip_config_get_address (s_ip6, 0);
g_assert (ip6_addr);
- g_assert_cmpint (nm_ip6_address_get_prefix (ip6_addr), ==, 56);
- g_assert_cmpint (inet_pton (AF_INET6, "1001:abba::1234", &addr6), >, 0);
- g_assert (IN6_ARE_ADDR_EQUAL (nm_ip6_address_get_address (ip6_addr), &addr6));
+ g_assert_cmpint (nm_ip_address_get_prefix (ip6_addr), ==, 56);
+ g_assert_cmpstr (nm_ip_address_get_address (ip6_addr), ==, "1001:abba::1234");
- ip6_addr = nm_setting_ip6_config_get_address (s_ip6, 1);
+ ip6_addr = nm_setting_ip_config_get_address (s_ip6, 1);
g_assert (ip6_addr);
- g_assert_cmpint (nm_ip6_address_get_prefix (ip6_addr), ==, 64);
- g_assert_cmpint (inet_pton (AF_INET6, "2001:abba::2234", &addr6), >, 0);
- g_assert (IN6_ARE_ADDR_EQUAL (nm_ip6_address_get_address (ip6_addr), &addr6));
+ g_assert_cmpint (nm_ip_address_get_prefix (ip6_addr), ==, 64);
+ g_assert_cmpstr (nm_ip_address_get_address (ip6_addr), ==, "2001:abba::2234");
- ip6_addr = nm_setting_ip6_config_get_address (s_ip6, 2);
+ ip6_addr = nm_setting_ip_config_get_address (s_ip6, 2);
g_assert (ip6_addr);
- g_assert_cmpint (nm_ip6_address_get_prefix (ip6_addr), ==, 96);
- g_assert_cmpint (inet_pton (AF_INET6, "3001:abba::3234", &addr6), >, 0);
- g_assert (IN6_ARE_ADDR_EQUAL (nm_ip6_address_get_address (ip6_addr), &addr6));
+ g_assert_cmpint (nm_ip_address_get_prefix (ip6_addr), ==, 96);
+ g_assert_cmpstr (nm_ip_address_get_address (ip6_addr), ==, "3001:abba::3234");
g_object_unref (connection);
}
@@ -819,9 +810,9 @@ test_read_wired_global_gateway (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
GError *error = NULL;
- NMIP4Address *ip4_addr;
+ NMIPAddress *ip4_addr;
char *unmanaged = NULL;
connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-global-gateway",
@@ -842,14 +833,16 @@ test_read_wired_global_gateway (void)
/* ===== IPv4 SETTING ===== */
s_ip4 = nm_connection_get_setting_ip4_config (connection);
g_assert (s_ip4);
- g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL);
+ g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL);
/* Address #1 */
- ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 0);
+ ip4_addr = nm_setting_ip_config_get_address (s_ip4, 0);
g_assert (ip4_addr);
- g_assert_cmpint (nm_ip4_address_get_prefix (ip4_addr), ==, 24);
- nmtst_assert_ip4_address_equals (nm_ip4_address_get_address (ip4_addr), "192.168.1.5");
- nmtst_assert_ip4_address_equals (nm_ip4_address_get_gateway (ip4_addr), "192.168.1.2");
+ g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 24);
+ g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "192.168.1.5");
+
+ /* Gateway */
+ g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, "192.168.1.2");
g_object_unref (connection);
}
@@ -858,8 +851,8 @@ static void
test_read_wired_never_default (void)
{
NMConnection *connection;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
GError *error = NULL;
connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-never-default",
@@ -873,15 +866,15 @@ test_read_wired_never_default (void)
/* ===== IPv4 SETTING ===== */
s_ip4 = nm_connection_get_setting_ip4_config (connection);
g_assert (s_ip4);
- g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
- g_assert (nm_setting_ip4_config_get_never_default (s_ip4));
- g_assert_cmpint (nm_setting_ip4_config_get_num_dns (s_ip4), ==, 0);
+ g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
+ g_assert (nm_setting_ip_config_get_never_default (s_ip4));
+ g_assert_cmpint (nm_setting_ip_config_get_num_dns (s_ip4), ==, 0);
/* ===== IPv6 SETTING ===== */
s_ip6 = nm_connection_get_setting_ip6_config (connection);
g_assert (s_ip6);
- g_assert_cmpstr (nm_setting_ip6_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO);
- g_assert (nm_setting_ip6_config_get_never_default (s_ip6));
+ g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO);
+ g_assert (nm_setting_ip_config_get_never_default (s_ip6));
g_object_unref (connection);
}
@@ -894,8 +887,8 @@ test_read_wired_defroute_no (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *unmanaged = NULL;
char *keyfile = NULL;
char *routefile = NULL;
@@ -961,18 +954,18 @@ test_read_wired_defroute_no (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip4_config_get_method (s_ip4);
+ tmp = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0,
"wired-defroute-no-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_DEFROUTE_NO,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
- ASSERT (nm_setting_ip4_config_get_never_default (s_ip4) == TRUE,
+ ASSERT (nm_setting_ip_config_get_never_default (s_ip4) == TRUE,
"wired-defroute-no-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_DEFROUTE_NO,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_NEVER_DEFAULT);
+ NM_SETTING_IP_CONFIG_NEVER_DEFAULT);
/* ===== IPv6 SETTING ===== */
@@ -983,18 +976,18 @@ test_read_wired_defroute_no (void)
NM_SETTING_IP6_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip6_config_get_method (s_ip6);
+ tmp = nm_setting_ip_config_get_method (s_ip6);
ASSERT (strcmp (tmp, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0,
"wired-defroute-no-verify-ip6", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_DEFROUTE_NO,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
- ASSERT (nm_setting_ip6_config_get_never_default (s_ip6) == TRUE,
+ ASSERT (nm_setting_ip_config_get_never_default (s_ip6) == TRUE,
"wired-defroute-no-verify-ip6", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_DEFROUTE_NO,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_NEVER_DEFAULT);
+ NM_SETTING_IP_CONFIG_NEVER_DEFAULT);
g_free (unmanaged);
g_free (keyfile);
@@ -1012,8 +1005,8 @@ test_read_wired_defroute_no_gatewaydev_yes (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *unmanaged = NULL;
char *keyfile = NULL;
char *routefile = NULL;
@@ -1087,18 +1080,18 @@ test_read_wired_defroute_no_gatewaydev_yes (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip4_config_get_method (s_ip4);
+ tmp = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0,
"wired-defroute-no-gatewaydev-yes-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_DEFROUTE_NO_GATEWAYDEV_YES,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
- ASSERT (nm_setting_ip4_config_get_never_default (s_ip4) == FALSE,
+ ASSERT (nm_setting_ip_config_get_never_default (s_ip4) == FALSE,
"wired-defroute-no-gatewaydev-yes-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_DEFROUTE_NO_GATEWAYDEV_YES,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_NEVER_DEFAULT);
+ NM_SETTING_IP_CONFIG_NEVER_DEFAULT);
/* ===== IPv6 SETTING ===== */
@@ -1109,18 +1102,18 @@ test_read_wired_defroute_no_gatewaydev_yes (void)
NM_SETTING_IP6_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip6_config_get_method (s_ip6);
- ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0,
- "wired-defroute-no-gatewaydev-yes-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
+ tmp = nm_setting_ip_config_get_method (s_ip6);
+ ASSERT (strcmp (tmp, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0,
+ "wired-defroute-no-gatewaydev-yes-verify-ip6", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_DEFROUTE_NO_GATEWAYDEV_YES,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
- ASSERT (nm_setting_ip6_config_get_never_default (s_ip6) == FALSE,
- "wired-defroute-no-gatewaydev-yes-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
+ ASSERT (nm_setting_ip_config_get_never_default (s_ip6) == FALSE,
+ "wired-defroute-no-gatewaydev-yes-verify-ip6", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_DEFROUTE_NO_GATEWAYDEV_YES,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_NEVER_DEFAULT);
+ NM_SETTING_IP_CONFIG_NEVER_DEFAULT);
g_free (unmanaged);
g_free (keyfile);
@@ -1135,9 +1128,9 @@ test_read_wired_static_routes (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
GError *error = NULL;
- NMIP4Route *ip4_route;
+ NMIPRoute *ip4_route;
connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-static-routes",
NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL);
@@ -1155,24 +1148,24 @@ test_read_wired_static_routes (void)
/* ===== IPv4 SETTING ===== */
s_ip4 = nm_connection_get_setting_ip4_config (connection);
g_assert (s_ip4);
- g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL);
+ g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL);
/* Routes */
- g_assert_cmpint (nm_setting_ip4_config_get_num_routes (s_ip4), ==, 2);
+ g_assert_cmpint (nm_setting_ip_config_get_num_routes (s_ip4), ==, 2);
- ip4_route = nm_setting_ip4_config_get_route (s_ip4, 0);
+ ip4_route = nm_setting_ip_config_get_route (s_ip4, 0);
g_assert (ip4_route);
- nmtst_assert_ip4_address_equals (nm_ip4_route_get_dest (ip4_route), "11.22.33.0");
- g_assert_cmpint (nm_ip4_route_get_prefix (ip4_route), ==, 24);
- nmtst_assert_ip4_address_equals (nm_ip4_route_get_next_hop (ip4_route), "192.168.1.5");
- g_assert_cmpint (nm_ip4_route_get_metric (ip4_route), ==, 0);
+ g_assert_cmpstr (nm_ip_route_get_dest (ip4_route), ==, "11.22.33.0");
+ g_assert_cmpint (nm_ip_route_get_prefix (ip4_route), ==, 24);
+ g_assert_cmpstr (nm_ip_route_get_next_hop (ip4_route), ==, "192.168.1.5");
+ g_assert_cmpint (nm_ip_route_get_metric (ip4_route), ==, -1);
- ip4_route = nm_setting_ip4_config_get_route (s_ip4, 1);
+ ip4_route = nm_setting_ip_config_get_route (s_ip4, 1);
g_assert (ip4_route);
- nmtst_assert_ip4_address_equals (nm_ip4_route_get_dest (ip4_route), "44.55.66.77");
- g_assert_cmpint (nm_ip4_route_get_prefix (ip4_route), ==, 32);
- nmtst_assert_ip4_address_equals (nm_ip4_route_get_next_hop (ip4_route), "192.168.1.7");
- g_assert_cmpint (nm_ip4_route_get_metric (ip4_route), ==, 3);
+ g_assert_cmpstr (nm_ip_route_get_dest (ip4_route), ==, "44.55.66.77");
+ g_assert_cmpint (nm_ip_route_get_prefix (ip4_route), ==, 32);
+ g_assert_cmpstr (nm_ip_route_get_next_hop (ip4_route), ==, "192.168.1.7");
+ g_assert_cmpint (nm_ip_route_get_metric (ip4_route), ==, 3);
g_object_unref (connection);
}
@@ -1185,7 +1178,7 @@ test_read_wired_static_routes_legacy (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
char *unmanaged = NULL;
char *keyfile = NULL;
char *routefile = NULL;
@@ -1193,15 +1186,8 @@ test_read_wired_static_routes_legacy (void)
gboolean ignore_error = FALSE;
GError *error = NULL;
const char *tmp;
- NMIP4Route *ip4_route;
- guint32 addr;
+ NMIPRoute *ip4_route;
const char *expected_id = "System test-wired-static-routes-legacy";
- const char *expected_dst1 = "21.31.41.0";
- const char *expected_dst2 = "32.42.52.62";
- const char *expected_dst3 = "43.53.0.0";
- const char *expected_gw1 = "9.9.9.9";
- const char *expected_gw2 = "8.8.8.8";
- const char *expected_gw3 = "7.7.7.7";
connection = connection_from_file (TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY,
NULL,
@@ -1265,115 +1251,43 @@ test_read_wired_static_routes_legacy (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip4_config_get_method (s_ip4);
+ tmp = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0,
"wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
/* Routes */
- ASSERT (nm_setting_ip4_config_get_num_routes (s_ip4) == 3,
+ ASSERT (nm_setting_ip_config_get_num_routes (s_ip4) == 3,
"wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_ROUTES);
+ NM_SETTING_IP_CONFIG_ROUTES);
/* Route #1 */
- ip4_route = nm_setting_ip4_config_get_route (s_ip4, 0);
- ASSERT (ip4_route,
- "wired-static-routes-legacy-verify-ip4", "failed to verify %s: missing IP4 route #1",
- TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY);
-
- ASSERT (inet_pton (AF_INET, expected_dst1, &addr) > 0,
- "wired-static-routes-legacy-verify-ip4", "failed to verify %s: couldn't convert destination IP address #1",
- TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY);
- ASSERT (nm_ip4_route_get_dest (ip4_route) == addr,
- "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected %s / %s key value #1",
- TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY,
- NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_ROUTES);
-
- ASSERT (nm_ip4_route_get_prefix (ip4_route) == 24,
- "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected destination route #1 prefix",
- TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY);
-
- ASSERT (inet_pton (AF_INET, expected_gw1, &addr) > 0,
- "wired-static-routes-legacy-verify-ip4", "failed to verify %s: couldn't convert next hop IP address #1",
- TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY);
- ASSERT (nm_ip4_route_get_next_hop (ip4_route) == addr,
- "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected %s / %s key value #1",
- TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY,
- NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_ROUTES);
-
- ASSERT (nm_ip4_route_get_metric (ip4_route) == 1,
- "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected destination route #1 metric",
- TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY);
+ ip4_route = nm_setting_ip_config_get_route (s_ip4, 0);
+ g_assert (ip4_route != NULL);
+ g_assert_cmpstr (nm_ip_route_get_dest (ip4_route), ==, "21.31.41.0");
+ g_assert_cmpint (nm_ip_route_get_prefix (ip4_route), ==, 24);
+ g_assert_cmpstr (nm_ip_route_get_next_hop (ip4_route), ==, "9.9.9.9");
+ g_assert_cmpint (nm_ip_route_get_metric (ip4_route), ==, 1);
/* Route #2 */
- ip4_route = nm_setting_ip4_config_get_route (s_ip4, 1);
- ASSERT (ip4_route,
- "wired-static-routes-legacy-verify-ip4", "failed to verify %s: missing IP4 route #2",
- TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY);
-
- ASSERT (inet_pton (AF_INET, expected_dst2, &addr) > 0,
- "wired-static-routes-legacy-verify-ip4", "failed to verify %s: couldn't convert destination IP address #2",
- TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY);
- ASSERT (nm_ip4_route_get_dest (ip4_route) == addr,
- "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected %s / %s key value #2",
- TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY,
- NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_ROUTES);
-
- ASSERT (nm_ip4_route_get_prefix (ip4_route) == 32,
- "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected destination route #2 prefix",
- TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY);
-
- ASSERT (inet_pton (AF_INET, expected_gw2, &addr) > 0,
- "wired-static-routes-legacy-verify-ip4", "failed to verify %s: couldn't convert next hop IP address #2",
- TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY);
- ASSERT (nm_ip4_route_get_next_hop (ip4_route) == addr,
- "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected %s / %s key value #2",
- TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY,
- NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_ROUTES);
-
- ASSERT (nm_ip4_route_get_metric (ip4_route) == 0,
- "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected destination route #2 metric",
- TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY);
+ ip4_route = nm_setting_ip_config_get_route (s_ip4, 1);
+ g_assert (ip4_route != NULL);
+ g_assert_cmpstr (nm_ip_route_get_dest (ip4_route), ==, "32.42.52.62");
+ g_assert_cmpint (nm_ip_route_get_prefix (ip4_route), ==, 32);
+ g_assert_cmpstr (nm_ip_route_get_next_hop (ip4_route), ==, "8.8.8.8");
+ g_assert_cmpint (nm_ip_route_get_metric (ip4_route), ==, -1);
/* Route #3 */
- ip4_route = nm_setting_ip4_config_get_route (s_ip4, 2);
- ASSERT (ip4_route,
- "wired-static-routes-legacy-verify-ip4", "failed to verify %s: missing IP4 route #3",
- TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY);
-
- ASSERT (inet_pton (AF_INET, expected_dst3, &addr) > 0,
- "wired-static-routes-legacy-verify-ip4", "failed to verify %s: couldn't convert destination IP address #3",
- TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY);
- ASSERT (nm_ip4_route_get_dest (ip4_route) == addr,
- "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected %s / %s key value #3",
- TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY,
- NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_ROUTES);
-
- ASSERT (nm_ip4_route_get_prefix (ip4_route) == 16,
- "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected destination route #3 prefix",
- TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY);
-
- ASSERT (inet_pton (AF_INET, expected_gw3, &addr) > 0,
- "wired-static-routes-legacy-verify-ip4", "failed to verify %s: couldn't convert next hop IP address #3",
- TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY);
- ASSERT (nm_ip4_route_get_next_hop (ip4_route) == addr,
- "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected %s / %s key value #3",
- TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY,
- NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_ROUTES);
-
- ASSERT (nm_ip4_route_get_metric (ip4_route) == 3,
- "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected destination route #3 metric",
- TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY);
+ ip4_route = nm_setting_ip_config_get_route (s_ip4, 2);
+ g_assert (ip4_route != NULL);
+ g_assert_cmpstr (nm_ip_route_get_dest (ip4_route), ==, "43.53.0.0");
+ g_assert_cmpint (nm_ip_route_get_prefix (ip4_route), ==, 16);
+ g_assert_cmpstr (nm_ip_route_get_next_hop (ip4_route), ==, "7.7.7.7");
+ g_assert_cmpint (nm_ip_route_get_metric (ip4_route), ==, 3);
g_free (unmanaged);
g_free (keyfile);
@@ -1388,7 +1302,7 @@ test_read_wired_ipv4_manual (const char *file, const char *expected_id)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
char *unmanaged = NULL;
char *keyfile = NULL;
char *routefile = NULL;
@@ -1396,14 +1310,7 @@ test_read_wired_ipv4_manual (const char *file, const char *expected_id)
gboolean ignore_error = FALSE;
GError *error = NULL;
const char *tmp;
- const char *expected_address1 = "1.2.3.4";
- const char *expected_address2 = "9.8.7.6";
- const char *expected_address3 = "3.3.3.3";
- guint32 expected_prefix1 = 24;
- guint32 expected_prefix2 = 16;
- guint32 expected_prefix3 = 8;
- NMIP4Address *ip4_addr;
- guint32 addr;
+ NMIPAddress *ip4_addr;
connection = connection_from_file (file,
NULL,
@@ -1461,70 +1368,37 @@ test_read_wired_ipv4_manual (const char *file, const char *expected_id)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip4_config_get_method (s_ip4);
+ tmp = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0,
"wired-ipv4-manual-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
file,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
/* IP addresses */
- ASSERT (nm_setting_ip4_config_get_num_addresses (s_ip4) == 3,
+ ASSERT (nm_setting_ip_config_get_num_addresses (s_ip4) == 3,
"wired-ipv4-manual-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
file,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_ADDRESSES);
+ NM_SETTING_IP_CONFIG_ADDRESSES);
/* Address #1 */
- ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 0);
- ASSERT (ip4_addr,
- "wired-ipv4-manual-verify-ip4", "failed to verify %s: missing IP4 address #1",
- file);
-
- ASSERT (nm_ip4_address_get_prefix (ip4_addr) == expected_prefix1,
- "wired-ipv4-manual-verify-ip4", "failed to verify %s: unexpected IP4 address #1 prefix",
- file);
-
- ASSERT (inet_pton (AF_INET, expected_address1, &addr) > 0,
- "wired-ipv4-manual-verify-ip4", "failed to verify %s: couldn't convert IP address #1",
- file);
- ASSERT (nm_ip4_address_get_address (ip4_addr) == addr,
- "wired-ipv4-manual-verify-ip4", "failed to verify %s: unexpected IP4 address #1",
- file);
+ ip4_addr = nm_setting_ip_config_get_address (s_ip4, 0);
+ g_assert (ip4_addr != NULL);
+ g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "1.2.3.4");
+ g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 24);
/* Address #2 */
- ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 1);
- ASSERT (ip4_addr,
- "wired-ipv4-manual-verify-ip4", "failed to verify %s: missing IP4 address #2",
- file);
-
- ASSERT (nm_ip4_address_get_prefix (ip4_addr) == expected_prefix2,
- "wired-ipv4-manual-verify-ip4", "failed to verify %s: unexpected IP4 address #2 prefix",
- file);
-
- ASSERT (inet_pton (AF_INET, expected_address2, &addr) > 0,
- "wired-ipv4-manual-verify-ip4", "failed to verify %s: couldn't convert IP address #2",
- file);
- ASSERT (nm_ip4_address_get_address (ip4_addr) == addr,
- "wired-ipv4-manual-verify-ip4", "failed to verify %s: unexpected IP4 address #2",
- file);
+ ip4_addr = nm_setting_ip_config_get_address (s_ip4, 1);
+ g_assert (ip4_addr != NULL);
+ g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "9.8.7.6");
+ g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 16);
/* Address #3 */
- ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 2);
- ASSERT (ip4_addr,
- "wired-ipv4-manual-verify-ip4", "failed to verify %s: missing IP4 address #3",
- file);
-
- ASSERT (nm_ip4_address_get_prefix (ip4_addr) == expected_prefix3,
- "wired-ipv4-manual-verify-ip4", "failed to verify %s: unexpected IP4 address #3 prefix",
- file);
-
- ASSERT (inet_pton (AF_INET, expected_address3, &addr) > 0,
- "wired-ipv4-manual-verify-ip4", "failed to verify %s: couldn't convert IP address #3",
- file);
- ASSERT (nm_ip4_address_get_address (ip4_addr) == addr,
- "wired-ipv4-manual-verify-ip4", "failed to verify %s: unexpected IP4 address #3",
- file);
+ ip4_addr = nm_setting_ip_config_get_address (s_ip4, 2);
+ g_assert (ip4_addr != NULL);
+ g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "3.3.3.3");
+ g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 8);
g_free (unmanaged);
g_free (keyfile);
@@ -1541,8 +1415,8 @@ test_read_wired_ipv6_manual (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *unmanaged = NULL;
char *keyfile = NULL;
char *routefile = NULL;
@@ -1551,15 +1425,8 @@ test_read_wired_ipv6_manual (void)
GError *error = NULL;
const char *tmp;
const char *expected_id = "System test-wired-ipv6-manual";
- const char *expected_address1 = "1001:abba::1234";
- const char *expected_address2 = "2001:abba::2234";
- const char *expected_address3 = "3001:abba::3234";
- guint32 expected_prefix1 = 56;
- guint32 expected_prefix2 = 64;
- guint32 expected_prefix3 = 96;
- NMIP6Address *ip6_addr;
- NMIP6Route *ip6_route;
- struct in6_addr addr;
+ NMIPAddress *ip6_addr;
+ NMIPRoute *ip6_route;
g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING,
"*ignoring manual default route*");
@@ -1621,54 +1488,54 @@ test_read_wired_ipv6_manual (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* DNS Addresses */
- ASSERT (nm_setting_ip4_config_get_num_dns (s_ip4) == 2,
+ ASSERT (nm_setting_ip_config_get_num_dns (s_ip4) == 2,
"wired-ipv6-manual-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
/* DNS search domains */
- ASSERT (nm_setting_ip4_config_get_num_dns_searches (s_ip4) == 3,
+ ASSERT (nm_setting_ip_config_get_num_dns_searches (s_ip4) == 3,
"wired-ipv6-manual-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
- tmp = nm_setting_ip4_config_get_dns_search (s_ip4, 0);
+ tmp = nm_setting_ip_config_get_dns_search (s_ip4, 0);
ASSERT (tmp != NULL,
"wired-ipv6-manual-verify-ip4", "failed to verify %s: missing %s / %s key",
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS_SEARCH);
+ NM_SETTING_IP_CONFIG_DNS_SEARCH);
ASSERT (strcmp (tmp, "lorem.com") == 0,
"wired-ipv6-manual-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS_SEARCH);
+ NM_SETTING_IP_CONFIG_DNS_SEARCH);
- tmp = nm_setting_ip4_config_get_dns_search (s_ip4, 1);
+ tmp = nm_setting_ip_config_get_dns_search (s_ip4, 1);
ASSERT (tmp != NULL,
"wired-ipv6-manual-verify-ip4", "failed to verify %s: missing %s / %s key",
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS_SEARCH);
+ NM_SETTING_IP_CONFIG_DNS_SEARCH);
ASSERT (strcmp (tmp, "ipsum.org") == 0,
"wired-ipv6-manual-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS_SEARCH);
+ NM_SETTING_IP_CONFIG_DNS_SEARCH);
- tmp = nm_setting_ip4_config_get_dns_search (s_ip4, 2);
+ tmp = nm_setting_ip_config_get_dns_search (s_ip4, 2);
ASSERT (tmp != NULL,
"wired-ipv6-manual-verify-ip4", "failed to verify %s: missing %s / %s key",
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS_SEARCH);
+ NM_SETTING_IP_CONFIG_DNS_SEARCH);
ASSERT (strcmp (tmp, "dolor.edu") == 0,
"wired-ipv6-manual-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS_SEARCH);
+ NM_SETTING_IP_CONFIG_DNS_SEARCH);
/* ===== IPv6 SETTING ===== */
@@ -1679,129 +1546,92 @@ test_read_wired_ipv6_manual (void)
NM_SETTING_IP6_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip6_config_get_method (s_ip6);
+ tmp = nm_setting_ip_config_get_method (s_ip6);
ASSERT (strcmp (tmp, NM_SETTING_IP6_CONFIG_METHOD_MANUAL) == 0,
"wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
- ASSERT (nm_setting_ip6_config_get_never_default (s_ip6) == FALSE,
+ ASSERT (nm_setting_ip_config_get_never_default (s_ip6) == FALSE,
"wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_NEVER_DEFAULT);
+ NM_SETTING_IP_CONFIG_NEVER_DEFAULT);
- ASSERT (nm_setting_ip6_config_get_may_fail (s_ip6) == TRUE,
+ ASSERT (nm_setting_ip_config_get_may_fail (s_ip6) == TRUE,
"wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_MAY_FAIL);
+ NM_SETTING_IP_CONFIG_MAY_FAIL);
/* IP addresses */
- ASSERT (nm_setting_ip6_config_get_num_addresses (s_ip6) == 3,
+ ASSERT (nm_setting_ip_config_get_num_addresses (s_ip6) == 3,
"wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_ADDRESSES);
+ NM_SETTING_IP_CONFIG_ADDRESSES);
/* Address #1 */
- ip6_addr = nm_setting_ip6_config_get_address (s_ip6, 0);
- ASSERT (ip6_addr,
- "wired-ipv6-manual-verify-ip6", "failed to verify %s: missing IP6 address #1",
- TEST_IFCFG_WIRED_IPV6_MANUAL);
-
- ASSERT (nm_ip6_address_get_prefix (ip6_addr) == expected_prefix1,
- "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected IP6 address #1 prefix",
- TEST_IFCFG_WIRED_IPV6_MANUAL);
-
- ASSERT (inet_pton (AF_INET6, expected_address1, &addr) > 0,
- "wired-ipv6-manual-verify-ip6", "failed to verify %s: couldn't convert IP address #1",
- TEST_IFCFG_WIRED_IPV6_MANUAL);
- ASSERT (IN6_ARE_ADDR_EQUAL (nm_ip6_address_get_address (ip6_addr), &addr),
- "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected IP6 address #1",
- TEST_IFCFG_WIRED_IPV6_MANUAL);
+ ip6_addr = nm_setting_ip_config_get_address (s_ip6, 0);
+ g_assert (ip6_addr != NULL);
+ g_assert_cmpstr (nm_ip_address_get_address (ip6_addr), ==, "1001:abba::1234");
+ g_assert_cmpint (nm_ip_address_get_prefix (ip6_addr), ==, 56);
/* Address #2 */
- ip6_addr = nm_setting_ip6_config_get_address (s_ip6, 1);
- ASSERT (ip6_addr,
- "wired-ipv6-manual-verify-ip6", "failed to verify %s: missing IP6 address #2",
- TEST_IFCFG_WIRED_IPV6_MANUAL);
-
- ASSERT (nm_ip6_address_get_prefix (ip6_addr) == expected_prefix2,
- "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected IP6 address #2 prefix",
- TEST_IFCFG_WIRED_IPV6_MANUAL);
-
- ASSERT (inet_pton (AF_INET6, expected_address2, &addr) > 0,
- "wired-ipv6-manual-verify-ip6", "failed to verify %s: couldn't convert IP address #2",
- TEST_IFCFG_WIRED_IPV6_MANUAL);
- ASSERT (IN6_ARE_ADDR_EQUAL (nm_ip6_address_get_address (ip6_addr), &addr),
- "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected IP6 address #2",
- TEST_IFCFG_WIRED_IPV6_MANUAL);
+ ip6_addr = nm_setting_ip_config_get_address (s_ip6, 1);
+ g_assert (ip6_addr != NULL);
+ g_assert_cmpstr (nm_ip_address_get_address (ip6_addr), ==, "2001:abba::2234");
+ g_assert_cmpint (nm_ip_address_get_prefix (ip6_addr), ==, 64);
/* Address #3 */
- ip6_addr = nm_setting_ip6_config_get_address (s_ip6, 2);
- ASSERT (ip6_addr,
- "wired-ipv6-manual-verify-ip6", "failed to verify %s: missing IP6 address #3",
- TEST_IFCFG_WIRED_IPV6_MANUAL);
-
- ASSERT (nm_ip6_address_get_prefix (ip6_addr) == expected_prefix3,
- "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected IP6 address #3 prefix",
- TEST_IFCFG_WIRED_IPV6_MANUAL);
-
- ASSERT (inet_pton (AF_INET6, expected_address3, &addr) > 0,
- "wired-ipv6-manual-verify-ip6", "failed to verify %s: couldn't convert IP address #3",
- TEST_IFCFG_WIRED_IPV6_MANUAL);
- ASSERT (IN6_ARE_ADDR_EQUAL (nm_ip6_address_get_address (ip6_addr), &addr),
- "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected IP6 address #3",
- TEST_IFCFG_WIRED_IPV6_MANUAL);
+ ip6_addr = nm_setting_ip_config_get_address (s_ip6, 2);
+ g_assert (ip6_addr != NULL);
+ g_assert_cmpstr (nm_ip_address_get_address (ip6_addr), ==, "3001:abba::3234");
+ g_assert_cmpint (nm_ip_address_get_prefix (ip6_addr), ==, 96);
/* Routes */
- g_assert_cmpint (nm_setting_ip6_config_get_num_routes (s_ip6), ==, 2);
+ g_assert_cmpint (nm_setting_ip_config_get_num_routes (s_ip6), ==, 2);
/* Route #1 */
- ip6_route = nm_setting_ip6_config_get_route (s_ip6, 0);
+ ip6_route = nm_setting_ip_config_get_route (s_ip6, 0);
g_assert (ip6_route);
- g_assert_cmpint (inet_pton (AF_INET6, "9876::1234", &addr), >, 0);
- g_assert_cmpint (memcmp (nm_ip6_route_get_dest (ip6_route), &addr, sizeof (struct in6_addr)), ==, 0);
- g_assert_cmpint (nm_ip6_route_get_prefix (ip6_route), ==, 96);
- g_assert_cmpint (inet_pton (AF_INET6, "9876::7777", &addr), >, 0);
- g_assert_cmpint (memcmp (nm_ip6_route_get_next_hop (ip6_route), &addr, sizeof (struct in6_addr)), ==, 0);
- g_assert_cmpint (nm_ip6_route_get_metric (ip6_route), ==, 2);
+ g_assert_cmpstr (nm_ip_route_get_dest (ip6_route), ==, "9876::1234");
+ g_assert_cmpint (nm_ip_route_get_prefix (ip6_route), ==, 96);
+ g_assert_cmpstr (nm_ip_route_get_next_hop (ip6_route), ==, "9876::7777");
+ g_assert_cmpint (nm_ip_route_get_metric (ip6_route), ==, 2);
/* Route #2 */
- ip6_route = nm_setting_ip6_config_get_route (s_ip6, 1);
+ ip6_route = nm_setting_ip_config_get_route (s_ip6, 1);
g_assert (ip6_route);
- g_assert_cmpint (inet_pton (AF_INET6, "abbe::cafe", &addr), >, 0);
- g_assert_cmpint (memcmp (nm_ip6_route_get_dest (ip6_route), &addr, sizeof (struct in6_addr)), ==, 0);
- g_assert_cmpint (nm_ip6_route_get_prefix (ip6_route), ==, 64);
- g_assert_cmpint (inet_pton (AF_INET6, "::", &addr), >, 0);
- g_assert_cmpint (memcmp (nm_ip6_route_get_next_hop (ip6_route), &addr, sizeof (struct in6_addr)), ==, 0);
- g_assert_cmpint (nm_ip6_route_get_metric (ip6_route), ==, 777);
+ g_assert_cmpstr (nm_ip_route_get_dest (ip6_route), ==, "abbe::cafe");
+ g_assert_cmpint (nm_ip_route_get_prefix (ip6_route), ==, 64);
+ g_assert_cmpstr (nm_ip_route_get_next_hop (ip6_route), ==, NULL);
+ g_assert_cmpint (nm_ip_route_get_metric (ip6_route), ==, 777);
/* DNS Addresses */
- ASSERT (nm_setting_ip6_config_get_num_dns (s_ip6) == 2,
+ ASSERT (nm_setting_ip_config_get_num_dns (s_ip6) == 2,
"wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
- ASSERT (strcmp (nm_setting_ip6_config_get_dns (s_ip6, 0), "1:2:3:4::a") == 0,
+ ASSERT (strcmp (nm_setting_ip_config_get_dns (s_ip6, 0), "1:2:3:4::a") == 0,
"wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected %s / %s key value #1",
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
- ASSERT (strcmp (nm_setting_ip6_config_get_dns (s_ip6, 1), "1:2:3:4::b") == 0,
+ ASSERT (strcmp (nm_setting_ip_config_get_dns (s_ip6, 1), "1:2:3:4::b") == 0,
"wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected %s / %s key value #2",
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
/* DNS domains - none as domains are stuffed to 'ipv4' setting */
- ASSERT (nm_setting_ip6_config_get_num_dns_searches (s_ip6) == 0,
+ ASSERT (nm_setting_ip_config_get_num_dns_searches (s_ip6) == 0,
"wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS_SEARCH);
+ NM_SETTING_IP_CONFIG_DNS_SEARCH);
g_free (unmanaged);
g_free (keyfile);
@@ -1818,8 +1648,8 @@ test_read_wired_ipv6_only (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *unmanaged = NULL;
char *keyfile = NULL;
char *routefile = NULL;
@@ -1828,10 +1658,7 @@ test_read_wired_ipv6_only (void)
GError *error = NULL;
const char *tmp;
const char *expected_id = "System test-wired-ipv6-only";
- const char *expected_address1 = "1001:abba::1234";
- guint32 expected_prefix1 = 56;
- NMIP6Address *ip6_addr;
- struct in6_addr addr;
+ NMIPAddress *ip6_addr;
const char *method;
connection = connection_from_file (TEST_IFCFG_WIRED_IPV6_ONLY,
@@ -1889,12 +1716,12 @@ test_read_wired_ipv6_only (void)
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP4_CONFIG_SETTING_NAME);
- method = nm_setting_ip4_config_get_method (s_ip4);
+ method = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0,
"wired-ipv6-only-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
/* ===== IPv6 SETTING ===== */
@@ -1905,55 +1732,44 @@ test_read_wired_ipv6_only (void)
NM_SETTING_IP6_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip6_config_get_method (s_ip6);
+ tmp = nm_setting_ip_config_get_method (s_ip6);
ASSERT (strcmp (tmp, NM_SETTING_IP6_CONFIG_METHOD_MANUAL) == 0,
"wired-ipv6-only-verify-ip6", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
/* IP addresses */
- ASSERT (nm_setting_ip6_config_get_num_addresses (s_ip6) == 1,
+ ASSERT (nm_setting_ip_config_get_num_addresses (s_ip6) == 1,
"wired-ipv6-only-verify-ip6", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_ADDRESSES);
+ NM_SETTING_IP_CONFIG_ADDRESSES);
/* Address #1 */
- ip6_addr = nm_setting_ip6_config_get_address (s_ip6, 0);
- ASSERT (ip6_addr,
- "wired-ipv6-only-verify-ip6", "failed to verify %s: missing IP6 address #1",
- TEST_IFCFG_WIRED_IPV6_MANUAL);
-
- ASSERT (nm_ip6_address_get_prefix (ip6_addr) == expected_prefix1,
- "wired-ipv6-only-verify-ip6", "failed to verify %s: unexpected IP6 address #1 prefix",
- TEST_IFCFG_WIRED_IPV6_MANUAL);
-
- ASSERT (inet_pton (AF_INET6, expected_address1, &addr) > 0,
- "wired-ipv6-only-verify-ip6", "failed to verify %s: couldn't convert IP address #1",
- TEST_IFCFG_WIRED_IPV6_MANUAL);
- ASSERT (IN6_ARE_ADDR_EQUAL (nm_ip6_address_get_address (ip6_addr), &addr),
- "wired-ipv6-only-verify-ip6", "failed to verify %s: unexpected IP6 address #1",
- TEST_IFCFG_WIRED_IPV6_MANUAL);
+ ip6_addr = nm_setting_ip_config_get_address (s_ip6, 0);
+ g_assert (ip6_addr != NULL);
+ g_assert_cmpstr (nm_ip_address_get_address (ip6_addr), ==, "1001:abba::1234");
+ g_assert_cmpint (nm_ip_address_get_prefix (ip6_addr), ==, 56);
/* DNS Addresses */
- ASSERT (nm_setting_ip6_config_get_num_dns (s_ip6) == 1,
+ ASSERT (nm_setting_ip_config_get_num_dns (s_ip6) == 1,
"wired-ipv6-only-verify-ip6", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
- ASSERT (strcmp (nm_setting_ip6_config_get_dns (s_ip6, 0), "1:2:3:4::a") == 0,
+ ASSERT (strcmp (nm_setting_ip_config_get_dns (s_ip6, 0), "1:2:3:4::a") == 0,
"wired-ipv6-only-verify-ip6", "failed to verify %s: unexpected %s / %s key value #1",
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
/* DNS domains should be in IPv6, because IPv4 is disabled */
- g_assert_cmpint (nm_setting_ip6_config_get_num_dns_searches (s_ip6), ==, 3);
- g_assert_cmpstr (nm_setting_ip6_config_get_dns_search (s_ip6, 0), ==, "lorem.com");
- g_assert_cmpstr (nm_setting_ip6_config_get_dns_search (s_ip6, 1), ==, "ipsum.org");
- g_assert_cmpstr (nm_setting_ip6_config_get_dns_search (s_ip6, 2), ==, "dolor.edu");
+ g_assert_cmpint (nm_setting_ip_config_get_num_dns_searches (s_ip6), ==, 3);
+ g_assert_cmpstr (nm_setting_ip_config_get_dns_search (s_ip6, 0), ==, "lorem.com");
+ g_assert_cmpstr (nm_setting_ip_config_get_dns_search (s_ip6, 1), ==, "ipsum.org");
+ g_assert_cmpstr (nm_setting_ip_config_get_dns_search (s_ip6, 2), ==, "dolor.edu");
g_free (unmanaged);
g_free (keyfile);
@@ -1970,8 +1786,8 @@ test_read_wired_dhcp6_only (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *unmanaged = NULL;
char *keyfile = NULL;
char *routefile = NULL;
@@ -2037,12 +1853,12 @@ test_read_wired_dhcp6_only (void)
TEST_IFCFG_WIRED_DHCP6_ONLY,
NM_SETTING_IP4_CONFIG_SETTING_NAME);
- method = nm_setting_ip4_config_get_method (s_ip4);
+ method = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0,
"wired-dhcp6-only-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_DHCP6_ONLY,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
/* ===== IPv6 SETTING ===== */
@@ -2053,12 +1869,12 @@ test_read_wired_dhcp6_only (void)
NM_SETTING_IP6_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip6_config_get_method (s_ip6);
+ tmp = nm_setting_ip_config_get_method (s_ip6);
ASSERT (strcmp (tmp, NM_SETTING_IP6_CONFIG_METHOD_DHCP) == 0,
"wired-dhcp6-only-verify-ip6", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_DHCP6_ONLY,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
g_free (unmanaged);
g_free (keyfile);
@@ -2127,8 +1943,8 @@ static void
test_read_noip (void)
{
NMConnection *connection;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *unmanaged = NULL;
char *keyfile = NULL;
char *routefile = NULL;
@@ -2151,13 +1967,13 @@ test_read_noip (void)
s_ip4 = nm_connection_get_setting_ip4_config (connection);
g_assert (s_ip4);
- g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED);
- g_assert (nm_setting_ip4_config_get_never_default (s_ip4) == FALSE);
+ g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED);
+ g_assert (nm_setting_ip_config_get_never_default (s_ip4) == FALSE);
s_ip6 = nm_connection_get_setting_ip6_config (connection);
g_assert (s_ip6);
- g_assert_cmpstr (nm_setting_ip6_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_IGNORE);
- g_assert (nm_setting_ip6_config_get_never_default (s_ip6) == FALSE);
+ g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_IGNORE);
+ g_assert (nm_setting_ip_config_get_never_default (s_ip6) == FALSE);
g_free (unmanaged);
g_free (keyfile);
@@ -2174,7 +1990,7 @@ test_read_wired_8021x_peap_mschapv2 (void)
{
NMConnection *connection;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
NMSetting8021x *s_8021x;
NMSetting8021x *tmp_8021x;
char *unmanaged = NULL;
@@ -2226,12 +2042,12 @@ test_read_wired_8021x_peap_mschapv2 (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip4_config_get_method (s_ip4);
+ tmp = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0,
"wired-8021x-peap-mschapv2-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_8021x_PEAP_MSCHAPV2,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
/* ===== 802.1x SETTING ===== */
s_8021x = nm_connection_get_setting_802_1x (connection);
@@ -2555,7 +2371,7 @@ test_read_wired_aliases_good (void)
{
NMConnection *connection;
NMSettingConnection *s_con;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
char *unmanaged = NULL;
char *keyfile = NULL;
char *routefile = NULL;
@@ -2564,10 +2380,10 @@ test_read_wired_aliases_good (void)
GError *error = NULL;
const char *tmp;
const char *expected_id = "System aliasem0";
- int expected_num_addresses = 4, expected_prefix = 24;
+ int expected_num_addresses = 4;
const char *expected_address[4] = { "192.168.1.5", "192.168.1.6", "192.168.1.9", "192.168.1.99" };
- const char *expected_label[4] = { "", "aliasem0:1", "aliasem0:2", "aliasem0:99" };
- const char *expected_gateway[4] = { "192.168.1.1", "192.168.1.1", "192.168.1.1", "192.168.1.1" };
+ const char *expected_label[4] = { NULL, "aliasem0:1", "aliasem0:2", "aliasem0:99" };
+ const char *expected_gateway = "192.168.1.1";
int i, j;
connection = connection_from_file (TEST_IFCFG_ALIASES_GOOD,
@@ -2615,74 +2431,51 @@ test_read_wired_aliases_good (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip4_config_get_method (s_ip4);
+ tmp = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0,
"aliases-good-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_ALIASES_GOOD,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
- ASSERT (nm_setting_ip4_config_get_num_addresses (s_ip4) == expected_num_addresses,
+ ASSERT (nm_setting_ip_config_get_num_addresses (s_ip4) == expected_num_addresses,
"aliases-good-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_ALIASES_GOOD,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_ADDRESSES);
+ NM_SETTING_IP_CONFIG_ADDRESSES);
/* Addresses */
for (i = 0; i < expected_num_addresses; i++) {
- NMIP4Address *ip4_addr;
- char buf[INET_ADDRSTRLEN];
- struct in_addr addr;
+ NMIPAddress *ip4_addr;
+ const char *addr;
+ GVariant *label;
- ip4_addr = nm_setting_ip4_config_get_address (s_ip4, i);
- ASSERT (ip4_addr,
- "aliases-good-verify-ip4", "failed to verify %s: missing IP4 address #%d",
- TEST_IFCFG_ALIASES_GOOD,
- i);
+ ip4_addr = nm_setting_ip_config_get_address (s_ip4, i);
+ g_assert (ip4_addr != NULL);
- addr.s_addr = nm_ip4_address_get_address (ip4_addr);
- ASSERT (inet_ntop (AF_INET, &addr, buf, sizeof (buf)) > 0,
- "aliases-good-verify-ip4", "failed to verify %s: couldn't convert IP address #%d",
- TEST_IFCFG_ALIASES_GOOD,
- i);
+ addr = nm_ip_address_get_address (ip4_addr);
+ g_assert (nm_utils_ipaddr_valid (AF_INET, addr));
for (j = 0; j < expected_num_addresses; j++) {
- if (!g_strcmp0 (buf, expected_address[j]))
+ if (!g_strcmp0 (addr, expected_address[j]))
break;
}
+ g_assert (j < expected_num_addresses);
- ASSERT (j < expected_num_addresses,
- "aliases-good-verify-ip4", "failed to verify %s: unexpected IP4 address #%d",
- TEST_IFCFG_ALIASES_GOOD,
- i);
-
- ASSERT (nm_ip4_address_get_prefix (ip4_addr) == expected_prefix,
- "aliases-good-verify-ip4", "failed to verify %s: unexpected IP4 address prefix #%d",
- TEST_IFCFG_ALIASES_GOOD,
- i);
-
- if (expected_gateway[j]) {
- ASSERT (inet_pton (AF_INET, expected_gateway[j], &addr) > 0,
- "aliases-good-verify-ip4", "failed to verify %s: couldn't convert IP address gateway #%d",
- TEST_IFCFG_ALIASES_GOOD,
- i);
- } else
- addr.s_addr = 0;
- ASSERT (nm_ip4_address_get_gateway (ip4_addr) == addr.s_addr,
- "aliases-good-verify-ip4", "failed to verify %s: unexpected IP4 address gateway #%d",
- TEST_IFCFG_ALIASES_GOOD,
- i);
-
- ASSERT (g_strcmp0 (_nm_setting_ip4_config_get_address_label (s_ip4, i), expected_label[j]) == 0,
- "aliases-good-verify-ip4", "failed to verify %s: unexpected IP4 address label #%d",
- TEST_IFCFG_ALIASES_GOOD,
- i);
+ g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 24);
+ label = nm_ip_address_get_attribute (ip4_addr, "label");
+ if (expected_label[j])
+ g_assert_cmpstr (g_variant_get_string (label, NULL), ==, expected_label[j]);
+ else
+ g_assert (label == NULL);
expected_address[j] = NULL;
- expected_gateway[j] = NULL;
expected_label[j] = NULL;
}
+ /* Gateway */
+ g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, expected_gateway);
+
for (i = 0; i < expected_num_addresses; i++) {
ASSERT (expected_address[i] == NULL,
"aliases-good-verify-ip4", "failed to verify %s: did not find IP4 address %s",
@@ -2701,7 +2494,7 @@ test_read_wired_aliases_bad (const char *base, const char *expected_id)
{
NMConnection *connection;
NMSettingConnection *s_con;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
char *unmanaged = NULL;
char *keyfile = NULL;
char *routefile = NULL;
@@ -2709,12 +2502,7 @@ test_read_wired_aliases_bad (const char *base, const char *expected_id)
gboolean ignore_error = FALSE;
GError *error = NULL;
const char *tmp;
- int expected_num_addresses = 1, expected_prefix = 24;
- const char *expected_address = "192.168.1.5";
- const char *expected_label = "";
- const char *expected_gateway = "192.168.1.1";
- NMIP4Address *ip4_addr;
- struct in_addr addr;
+ NMIPAddress *ip4_addr;
connection = connection_from_file (base,
NULL,
@@ -2762,46 +2550,28 @@ test_read_wired_aliases_bad (const char *base, const char *expected_id)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip4_config_get_method (s_ip4);
+ tmp = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0,
"aliases-bad-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
base,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
- ASSERT (nm_setting_ip4_config_get_num_addresses (s_ip4) == expected_num_addresses,
+ ASSERT (nm_setting_ip_config_get_num_addresses (s_ip4) == 1,
"aliases-bad-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
base,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_ADDRESSES);
+ NM_SETTING_IP_CONFIG_ADDRESSES);
/* Addresses */
- ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 0);
- ASSERT (ip4_addr,
- "aliases-bad-verify-ip4", "failed to verify %s: missing IP4 address",
- base);
-
- ASSERT (inet_pton (AF_INET, expected_address, &addr) > 0,
- "aliases-bad-verify-ip4", "failed to verify %s: couldn't convert IP address",
- base);
- ASSERT (nm_ip4_address_get_address (ip4_addr) == addr.s_addr,
- "aliases-bad-verify-ip4", "failed to verify %s: unexpected IP4 address",
- base);
-
- ASSERT (nm_ip4_address_get_prefix (ip4_addr) == expected_prefix,
- "aliases-bad-verify-ip4", "failed to verify %s: unexpected IP4 address prefix",
- base);
-
- ASSERT (inet_pton (AF_INET, expected_gateway, &addr) > 0,
- "aliases-bad-verify-ip4", "failed to verify %s: couldn't convert IP address gateway",
- base);
- ASSERT (nm_ip4_address_get_gateway (ip4_addr) == addr.s_addr,
- "aliases-bad-verify-ip4", "failed to verify %s: unexpected IP4 address gateway",
- base);
-
- ASSERT (g_strcmp0 (_nm_setting_ip4_config_get_address_label (s_ip4, 0), expected_label) == 0,
- "aliases-bad-verify-ip4", "failed to verify %s: unexpected IP4 address label",
- base);
+ ip4_addr = nm_setting_ip_config_get_address (s_ip4, 0);
+ g_assert (ip4_addr != NULL);
+ g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "192.168.1.5");
+ g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 24);
+ g_assert (nm_ip_address_get_attribute (ip4_addr, "label") == NULL);
+
+ /* Gateway */
+ g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, "192.168.1.1");
g_free (keyfile);
g_free (routefile);
@@ -2838,7 +2608,7 @@ test_read_wifi_open (void)
NMSettingConnection *s_con;
NMSettingWireless *s_wireless;
NMSettingWirelessSecurity *s_wsec;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
char *unmanaged = NULL;
char *keyfile = NULL;
char *routefile = NULL;
@@ -2993,12 +2763,12 @@ test_read_wifi_open (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip4_config_get_method (s_ip4);
+ tmp = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0,
"wifi-open-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIFI_OPEN,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
g_free (unmanaged);
g_free (keyfile);
@@ -3302,7 +3072,7 @@ test_read_wifi_wep (void)
NMSettingConnection *s_con;
NMSettingWireless *s_wireless;
NMSettingWirelessSecurity *s_wsec;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
char *unmanaged = NULL;
char *keyfile = NULL;
char *routefile = NULL;
@@ -3537,12 +3307,12 @@ test_read_wifi_wep (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip4_config_get_method (s_ip4);
+ tmp = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0,
"wifi-wep-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIFI_WEP,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
g_free (unmanaged);
g_free (keyfile);
@@ -3560,7 +3330,7 @@ test_read_wifi_wep_adhoc (void)
NMSettingConnection *s_con;
NMSettingWireless *s_wireless;
NMSettingWirelessSecurity *s_wsec;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
char *unmanaged = NULL;
char *keyfile = NULL;
char *routefile = NULL;
@@ -3751,38 +3521,38 @@ test_read_wifi_wep_adhoc (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip4_config_get_method (s_ip4);
+ tmp = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0,
"wifi-wep-adhoc-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIFI_WEP_ADHOC,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
/* Ignore auto DNS */
- ASSERT (nm_setting_ip4_config_get_ignore_auto_dns (s_ip4) == TRUE,
+ ASSERT (nm_setting_ip_config_get_ignore_auto_dns (s_ip4) == TRUE,
"wifi-wep-adhoc-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIFI_WEP_ADHOC,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS);
+ NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS);
/* DNS Addresses */
- ASSERT (nm_setting_ip4_config_get_num_dns (s_ip4) == 2,
+ ASSERT (nm_setting_ip_config_get_num_dns (s_ip4) == 2,
"wifi-wep-adhoc-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIFI_WEP_ADHOC,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
- ASSERT (strcmp (nm_setting_ip4_config_get_dns (s_ip4, 0), "4.2.2.1") == 0,
+ ASSERT (strcmp (nm_setting_ip_config_get_dns (s_ip4, 0), "4.2.2.1") == 0,
"wifi-wep-adhoc-verify-ip4", "failed to verify %s: unexpected %s / %s key value #1",
TEST_IFCFG_WIFI_WEP_ADHOC,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
- ASSERT (strcmp (nm_setting_ip4_config_get_dns (s_ip4, 1), "4.2.2.2") == 0,
+ ASSERT (strcmp (nm_setting_ip_config_get_dns (s_ip4, 1), "4.2.2.2") == 0,
"wifi-wep-adhoc-verify-ip4", "failed to verify %s: unexpected %s / %s key value #2",
TEST_IFCFG_WIFI_WEP_ADHOC,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
g_free (unmanaged);
g_free (keyfile);
@@ -4352,7 +4122,7 @@ test_read_wifi_wpa_psk (void)
NMSettingConnection *s_con;
NMSettingWireless *s_wireless;
NMSettingWirelessSecurity *s_wsec;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
char *unmanaged = NULL;
char *keyfile = NULL;
char *routefile = NULL;
@@ -4630,12 +4400,12 @@ test_read_wifi_wpa_psk (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip4_config_get_method (s_ip4);
+ tmp = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0,
"wifi-wpa-psk-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIFI_WPA_PSK,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
g_free (unmanaged);
g_free (keyfile);
@@ -4871,7 +4641,7 @@ test_read_wifi_wpa_psk_adhoc (void)
NMSettingConnection *s_con;
NMSettingWireless *s_wireless;
NMSettingWirelessSecurity *s_wsec;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
char *unmanaged = NULL;
char *keyfile = NULL;
char *routefile = NULL;
@@ -5026,12 +4796,12 @@ test_read_wifi_wpa_psk_adhoc (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip4_config_get_method (s_ip4);
+ tmp = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0,
"wifi-wpa-psk-adhoc-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIFI_WPA_PSK_ADHOC,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
g_free (unmanaged);
g_free (keyfile);
@@ -5049,7 +4819,7 @@ test_read_wifi_wpa_psk_hex (void)
NMSettingConnection *s_con;
NMSettingWireless *s_wireless;
NMSettingWirelessSecurity *s_wsec;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
char *unmanaged = NULL;
char *keyfile = NULL;
char *routefile = NULL;
@@ -5168,12 +4938,12 @@ test_read_wifi_wpa_psk_hex (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip4_config_get_method (s_ip4);
+ tmp = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0,
"wifi-wpa-psk-hex-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIFI_WPA_PSK_HEX,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
g_free (unmanaged);
g_free (keyfile);
@@ -5192,7 +4962,7 @@ test_read_wifi_wpa_eap_tls (void)
{
NMConnection *connection;
NMSettingWireless *s_wireless;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
NMSetting8021x *s_8021x;
char *unmanaged = NULL;
char *keyfile = NULL;
@@ -5239,12 +5009,12 @@ test_read_wifi_wpa_eap_tls (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip4_config_get_method (s_ip4);
+ tmp = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0,
"wifi-wpa-eap-tls-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIFI_WPA_EAP_TLS,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
/* ===== 802.1x SETTING ===== */
s_8021x = nm_connection_get_setting_802_1x (connection);
@@ -5332,7 +5102,7 @@ test_read_wifi_wpa_eap_ttls_tls (void)
{
NMConnection *connection;
NMSettingWireless *s_wireless;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
NMSetting8021x *s_8021x;
char *unmanaged = NULL;
char *keyfile = NULL;
@@ -5379,12 +5149,12 @@ test_read_wifi_wpa_eap_ttls_tls (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip4_config_get_method (s_ip4);
+ tmp = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0,
"wifi-wpa-eap-ttls-tls-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIFI_WPA_EAP_TTLS_TLS,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
/* ===== 802.1x SETTING ===== */
s_8021x = nm_connection_get_setting_802_1x (connection);
@@ -5563,7 +5333,7 @@ test_read_wifi_wep_eap_ttls_chap (void)
NMConnection *connection;
NMSettingWireless *s_wireless;
NMSettingWirelessSecurity *s_wsec;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
NMSetting8021x *s_8021x;
char *unmanaged = NULL;
char *keyfile = NULL;
@@ -5611,12 +5381,12 @@ test_read_wifi_wep_eap_ttls_chap (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip4_config_get_method (s_ip4);
+ tmp = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0,
"wifi-wep-eap-ttls-chap-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIFI_WEP_EAP_TTLS_CHAP,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
/* ===== 802.1x SETTING ===== */
s_wsec = nm_connection_get_setting_wireless_security (connection);
@@ -5975,7 +5745,7 @@ test_read_wired_qeth_static (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
char *unmanaged = NULL;
char *keyfile = NULL;
char *routefile = NULL;
@@ -6123,12 +5893,12 @@ test_read_wired_qeth_static (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip4_config_get_method (s_ip4);
+ tmp = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0,
"wired-qeth-static-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_QETH_STATIC,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
g_free (unmanaged);
g_free (keyfile);
@@ -6465,30 +6235,22 @@ test_write_wired_static (void)
NMConnection *reread;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4, *reread_s_ip4;
- NMSettingIP6Config *s_ip6, *reread_s_ip6;
+ NMSettingIPConfig *s_ip4, *reread_s_ip4;
+ NMSettingIPConfig *s_ip6, *reread_s_ip6;
static const char *mac = "31:33:33:37:be:cd";
guint32 mtu = 1492;
char *uuid;
- const guint32 ip1 = htonl (0x01010103);
- const guint32 ip2 = htonl (0x01010105);
- const guint32 gw = htonl (0x01010101);
const char *dns1 = "4.2.2.1";
const char *dns2 = "4.2.2.2";
- const guint32 prefix = 24;
const char *dns_search1 = "foobar.com";
const char *dns_search2 = "lab.foobar.com";
const char *dns_search3 = "foobar6.com";
const char *dns_search4 = "lab6.foobar.com";
- struct in6_addr ip6, ip6_1, ip6_2;
- struct in6_addr route1_dest, route2_dest, route1_nexthop, route2_nexthop;
const char *dns6_1 = "fade:0102:0103::face";
const char *dns6_2 = "cafe:ffff:eeee:dddd:cccc:bbbb:aaaa:feed";
- const guint32 route1_prefix = 64, route2_prefix = 128;
- const guint32 route1_metric = 99, route2_metric = 1;
- NMIP4Address *addr;
- NMIP6Address *addr6;
- NMIP6Route *route6;
+ NMIPAddress *addr;
+ NMIPAddress *addr6;
+ NMIPRoute *route6;
gboolean success;
GError *error = NULL;
char *testfile = NULL;
@@ -6498,14 +6260,6 @@ test_write_wired_static (void)
char *route6file = NULL;
gboolean ignore_error = FALSE;
- inet_pton (AF_INET6, "1003:1234:abcd::1", &ip6);
- inet_pton (AF_INET6, "2003:1234:abcd::2", &ip6_1);
- inet_pton (AF_INET6, "3003:1234:abcd::3", &ip6_2);
- inet_pton (AF_INET6, "2222:aaaa:bbbb:cccc::", &route1_dest);
- inet_pton (AF_INET6, "2222:aaaa:bbbb:cccc:dddd:eeee:5555:6666", &route1_nexthop);
- inet_pton (AF_INET6, "::", &route2_dest);
- inet_pton (AF_INET6, "2222:aaaa::9999", &route2_nexthop);
-
connection = nm_simple_connection_new ();
/* Connection setting */
@@ -6531,86 +6285,76 @@ test_write_wired_static (void)
NULL);
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
- NM_SETTING_IP4_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_GATEWAY, "1.1.1.1",
NULL);
- addr = nm_ip4_address_new ();
- nm_ip4_address_set_address (addr, ip1);
- nm_ip4_address_set_prefix (addr, prefix);
- nm_ip4_address_set_gateway (addr, gw);
- nm_setting_ip4_config_add_address (s_ip4, addr);
- nm_ip4_address_unref (addr);
+ addr = nm_ip_address_new (AF_INET, "1.1.1.3", 24, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_address (s_ip4, addr);
+ nm_ip_address_unref (addr);
- addr = nm_ip4_address_new ();
- nm_ip4_address_set_address (addr, ip2);
- nm_ip4_address_set_prefix (addr, prefix);
- nm_ip4_address_set_gateway (addr, gw);
- nm_setting_ip4_config_add_address (s_ip4, addr);
- nm_ip4_address_unref (addr);
+ addr = nm_ip_address_new (AF_INET, "1.1.1.5", 24, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_address (s_ip4, addr);
+ nm_ip_address_unref (addr);
- nm_setting_ip4_config_add_dns (s_ip4, dns1);
- nm_setting_ip4_config_add_dns (s_ip4, dns2);
+ nm_setting_ip_config_add_dns (s_ip4, dns1);
+ nm_setting_ip_config_add_dns (s_ip4, dns2);
- nm_setting_ip4_config_add_dns_search (s_ip4, dns_search1);
- nm_setting_ip4_config_add_dns_search (s_ip4, dns_search2);
+ nm_setting_ip_config_add_dns_search (s_ip4, dns_search1);
+ nm_setting_ip_config_add_dns_search (s_ip4, dns_search2);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
/* Add addresses */
- addr6 = nm_ip6_address_new ();
- nm_ip6_address_set_address (addr6, &ip6);
- nm_ip6_address_set_prefix (addr6, 11);
- nm_setting_ip6_config_add_address (s_ip6, addr6);
- nm_ip6_address_unref (addr6);
-
- addr6 = nm_ip6_address_new ();
- nm_ip6_address_set_address (addr6, &ip6_1);
- nm_ip6_address_set_prefix (addr6, 22);
- nm_setting_ip6_config_add_address (s_ip6, addr6);
- nm_ip6_address_unref (addr6);
-
- addr6 = nm_ip6_address_new ();
- nm_ip6_address_set_address (addr6, &ip6_2);
- nm_ip6_address_set_prefix (addr6, 33);
- nm_setting_ip6_config_add_address (s_ip6, addr6);
- nm_ip6_address_unref (addr6);
+ addr6 = nm_ip_address_new (AF_INET6, "1003:1234:abcd::1", 11, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_address (s_ip6, addr6);
+ nm_ip_address_unref (addr6);
+
+ addr6 = nm_ip_address_new (AF_INET6, "2003:1234:abcd::2", 22, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_address (s_ip6, addr6);
+ nm_ip_address_unref (addr6);
+
+ addr6 = nm_ip_address_new (AF_INET6, "3003:1234:abcd::3", 33, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_address (s_ip6, addr6);
+ nm_ip_address_unref (addr6);
/* Add routes */
- route6 = nm_ip6_route_new ();
- nm_ip6_route_set_dest (route6, &route1_dest);
- nm_ip6_route_set_prefix (route6, route1_prefix);
- nm_ip6_route_set_next_hop (route6, &route1_nexthop);
- nm_ip6_route_set_metric (route6, route1_metric);
- nm_setting_ip6_config_add_route (s_ip6, route6);
- nm_ip6_route_unref (route6);
-
- route6 = nm_ip6_route_new ();
- nm_ip6_route_set_dest (route6, &route2_dest);
- nm_ip6_route_set_prefix (route6, route2_prefix);
- nm_ip6_route_set_next_hop (route6, &route2_nexthop);
- nm_ip6_route_set_metric (route6, route2_metric);
- nm_setting_ip6_config_add_route (s_ip6, route6);
- nm_ip6_route_unref (route6);
+ route6 = nm_ip_route_new (AF_INET6,
+ "2222:aaaa:bbbb:cccc::", 64,
+ "2222:aaaa:bbbb:cccc:dddd:eeee:5555:6666", 99, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_route (s_ip6, route6);
+ nm_ip_route_unref (route6);
+
+ route6 = nm_ip_route_new (AF_INET6, "::", 128, "2222:aaaa::9999", 1, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_route (s_ip6, route6);
+ nm_ip_route_unref (route6);
/* DNS servers */
- nm_setting_ip6_config_add_dns (s_ip6, dns6_1);
- nm_setting_ip6_config_add_dns (s_ip6, dns6_2);
+ nm_setting_ip_config_add_dns (s_ip6, dns6_1);
+ nm_setting_ip_config_add_dns (s_ip6, dns6_2);
/* DNS domains */
- nm_setting_ip6_config_add_dns_search (s_ip6, dns_search3);
- nm_setting_ip6_config_add_dns_search (s_ip6, dns_search4);
+ nm_setting_ip_config_add_dns_search (s_ip6, dns_search3);
+ nm_setting_ip_config_add_dns_search (s_ip6, dns_search4);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
"wired-static-write", "failed to verify connection: %s",
@@ -6655,10 +6399,10 @@ test_write_wired_static (void)
*/
reread_s_ip4 = nm_connection_get_setting_ip4_config (reread);
reread_s_ip6 = nm_connection_get_setting_ip6_config (reread);
- nm_setting_ip6_config_add_dns_search (reread_s_ip6, nm_setting_ip4_config_get_dns_search (reread_s_ip4, 2));
- nm_setting_ip6_config_add_dns_search (reread_s_ip6, nm_setting_ip4_config_get_dns_search (reread_s_ip4, 3));
- nm_setting_ip4_config_remove_dns_search (reread_s_ip4, 3);
- nm_setting_ip4_config_remove_dns_search (reread_s_ip4, 2);
+ nm_setting_ip_config_add_dns_search (reread_s_ip6, nm_setting_ip_config_get_dns_search (reread_s_ip4, 2));
+ nm_setting_ip_config_add_dns_search (reread_s_ip6, nm_setting_ip_config_get_dns_search (reread_s_ip4, 3));
+ nm_setting_ip_config_remove_dns_search (reread_s_ip4, 3);
+ nm_setting_ip_config_remove_dns_search (reread_s_ip4, 2);
ASSERT (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT) == TRUE,
"wired-static-write", "written and re-read connection weren't the same.");
@@ -6682,8 +6426,8 @@ test_write_wired_dhcp (void)
NMConnection *reread;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
gboolean success;
GError *error = NULL;
@@ -6714,15 +6458,15 @@ test_write_wired_dhcp (void)
nm_connection_add_setting (connection, NM_SETTING (s_wired));
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, "random-client-id-00:22:33",
- NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, "awesome-hostname",
- NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES, TRUE,
- NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, TRUE,
+ NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, "awesome-hostname",
+ NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, TRUE,
+ NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, TRUE,
NULL);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
@@ -6730,12 +6474,12 @@ test_write_wired_dhcp (void)
(error && error->message) ? error->message : "(unknown)");
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
/* Save the ifcfg */
@@ -6830,8 +6574,8 @@ static void
test_read_write_wired_dhcp_send_hostname (void)
{
NMConnection *connection, *reread;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
const char * dhcp_hostname = "kamil-patka";
char *written = NULL;
GError *error = NULL;
@@ -6848,14 +6592,14 @@ test_read_write_wired_dhcp_send_hostname (void)
s_ip6 = nm_connection_get_setting_ip6_config (connection);
g_assert (s_ip4);
g_assert (s_ip6);
- g_assert (nm_setting_ip4_config_get_dhcp_send_hostname (s_ip4) == TRUE);
- g_assert_cmpstr (nm_setting_ip4_config_get_dhcp_hostname (s_ip4), ==, "svata-pulec");
- g_assert_cmpstr (nm_setting_ip6_config_get_dhcp_hostname (s_ip6), ==, "svata-pulec");
+ g_assert (nm_setting_ip_config_get_dhcp_send_hostname (s_ip4) == TRUE);
+ g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip4), ==, "svata-pulec");
+ g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip6), ==, "svata-pulec");
/* Set dhcp-send-hostname=false dhcp-hostname="kamil-patka" and write the connection. */
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME, FALSE, NULL);
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, dhcp_hostname, NULL);
- g_object_set (s_ip6, NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, dhcp_hostname, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, FALSE, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, dhcp_hostname, NULL);
+ g_object_set (s_ip6, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, dhcp_hostname, NULL);
success = writer_new_connection (connection,
TEST_SCRATCH_DIR "/network-scripts/",
@@ -6887,9 +6631,9 @@ test_read_write_wired_dhcp_send_hostname (void)
s_ip6 = nm_connection_get_setting_ip6_config (reread);
g_assert (s_ip4);
g_assert (s_ip6);
- g_assert (nm_setting_ip4_config_get_dhcp_send_hostname (s_ip4) == FALSE);
- g_assert_cmpstr (nm_setting_ip4_config_get_dhcp_hostname (s_ip4), ==, dhcp_hostname);
- g_assert_cmpstr (nm_setting_ip6_config_get_dhcp_hostname (s_ip6), ==, dhcp_hostname);
+ g_assert (nm_setting_ip_config_get_dhcp_send_hostname (s_ip4) == FALSE);
+ g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip4), ==, dhcp_hostname);
+ g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip6), ==, dhcp_hostname);
g_object_unref (connection);
g_object_unref (reread);
@@ -6902,13 +6646,12 @@ test_write_wired_static_ip6_only (void)
NMConnection *reread;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
static const char *mac = "31:33:33:37:be:cd";
char *uuid;
- struct in6_addr ip6;
const char *dns6 = "fade:0102:0103::face";
- NMIP6Address *addr6;
+ NMIPAddress *addr6;
gboolean success;
GError *error = NULL;
char *testfile = NULL;
@@ -6918,8 +6661,6 @@ test_write_wired_static_ip6_only (void)
char *route6file = NULL;
gboolean ignore_error = FALSE;
- inet_pton (AF_INET6, "1003:1234:abcd::1", &ip6);
-
connection = nm_simple_connection_new ();
/* Connection setting */
@@ -6942,30 +6683,29 @@ test_write_wired_static_ip6_only (void)
g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac, NULL);
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED,
NULL);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL,
NULL);
/* Add addresses */
- addr6 = nm_ip6_address_new ();
- nm_ip6_address_set_address (addr6, &ip6);
- nm_ip6_address_set_prefix (addr6, 11);
- nm_setting_ip6_config_add_address (s_ip6, addr6);
- nm_ip6_address_unref (addr6);
+ addr6 = nm_ip_address_new (AF_INET6, "1003:1234:abcd::1", 11, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_address (s_ip6, addr6);
+ nm_ip_address_unref (addr6);
/* DNS server */
- nm_setting_ip6_config_add_dns (s_ip6, dns6);
+ nm_setting_ip_config_add_dns (s_ip6, dns6);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
"wired-static-ip6-only-write", "failed to verify connection: %s",
@@ -7034,33 +6774,19 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data)
NMConnection *reread;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
static const char *mac = "31:33:33:37:be:cd";
char *uuid;
- struct in6_addr ip6;
const char *dns6 = "fade:0102:0103::face";
- NMIP6Address *addr6;
+ NMIPAddress *addr6;
gboolean success;
GError *error = NULL;
char *testfile = NULL;
char *id = NULL;
gboolean ignore_error = FALSE;
char *written_ifcfg_gateway;
- char s_gateway6[INET6_ADDRSTRLEN] = { 0 };
- struct in6_addr gateway6_autovar;
- const struct in6_addr *gateway6 = NULL;
-
- /* parsing the input argument and set the struct in6_addr "gateway6" to
- * the gateway address. NULL means "do not set the gateway explicitly". */
- if (user_data) {
- g_assert_cmpint (inet_pton (AF_INET6, user_data, &gateway6_autovar), ==, 1);
- gateway6 = &gateway6_autovar;
- }
-
- inet_pton (AF_INET6, "1003:1234:abcd::1", &ip6);
- if (gateway6)
- inet_ntop (AF_INET6, gateway6, s_gateway6, sizeof (s_gateway6));
+ const char *gateway6 = user_data;
connection = nm_simple_connection_new ();
@@ -7069,7 +6795,7 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data)
nm_connection_add_setting (connection, NM_SETTING (s_con));
uuid = nm_utils_uuid_generate ();
- id = g_strdup_printf ("Test Write Wired Static IP6 Only With Gateway %s", gateway6 ? s_gateway6 : "NULL");
+ id = g_strdup_printf ("Test Write Wired Static IP6 Only With Gateway %s", gateway6 ? gateway6 : "NULL");
g_object_set (s_con,
NM_SETTING_CONNECTION_ID, id,
NM_SETTING_CONNECTION_UUID, uuid,
@@ -7086,32 +6812,30 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data)
g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac, NULL);
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED,
NULL);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_GATEWAY, gateway6,
NULL);
/* Add addresses */
- addr6 = nm_ip6_address_new ();
- nm_ip6_address_set_address (addr6, &ip6);
- nm_ip6_address_set_prefix (addr6, 11);
- if (gateway6)
- nm_ip6_address_set_gateway (addr6, gateway6);
- nm_setting_ip6_config_add_address (s_ip6, addr6);
- nm_ip6_address_unref (addr6);
+ addr6 = nm_ip_address_new (AF_INET6, "1003:1234:abcd::1", 11, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_address (s_ip6, addr6);
+ nm_ip_address_unref (addr6);
/* DNS server */
- nm_setting_ip6_config_add_dns (s_ip6, dns6);
+ nm_setting_ip_config_add_dns (s_ip6, dns6);
g_assert (nm_connection_verify (connection, &error));
@@ -7154,18 +6878,18 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data)
/* access the gateway from the loaded connection. */
s_ip6 = nm_connection_get_setting_ip6_config (reread);
- g_assert (s_ip6 && nm_setting_ip6_config_get_num_addresses (s_ip6)==1);
- addr6 = nm_setting_ip6_config_get_address (s_ip6, 0);
+ g_assert (s_ip6 && nm_setting_ip_config_get_num_addresses (s_ip6)==1);
+ addr6 = nm_setting_ip_config_get_address (s_ip6, 0);
g_assert (addr6);
/* assert that the gateway was written and reloaded as expected */
- if (!gateway6 || IN6_IS_ADDR_UNSPECIFIED (gateway6)) {
- g_assert (IN6_IS_ADDR_UNSPECIFIED (nm_ip6_address_get_gateway (addr6)));
- g_assert (written_ifcfg_gateway==NULL);
+ if (!gateway6 || !strcmp (gateway6, "::")) {
+ g_assert (nm_setting_ip_config_get_gateway (s_ip6) == NULL);
+ g_assert (written_ifcfg_gateway == NULL);
} else {
- g_assert (!IN6_IS_ADDR_UNSPECIFIED (nm_ip6_address_get_gateway (addr6)));
- g_assert_cmpint (memcmp (nm_ip6_address_get_gateway (addr6), gateway6, sizeof (struct in6_addr)), ==, 0);
- g_assert_cmpstr (written_ifcfg_gateway, ==, s_gateway6);
+ g_assert (nm_setting_ip_config_get_gateway (s_ip6) != NULL);
+ g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip6), ==, gateway6);
+ g_assert_cmpstr (written_ifcfg_gateway, ==, gateway6);
}
g_free (testfile);
@@ -7182,7 +6906,7 @@ test_read_write_static_routes_legacy (void)
NMConnection *connection, *reread;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
char *unmanaged = NULL;
char *testfile = NULL;
char *keyfile = NULL;
@@ -7253,18 +6977,18 @@ test_read_write_static_routes_legacy (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip4_config_get_method (s_ip4);
+ tmp = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0,
"read-write-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_READ_WRITE_STATIC_ROUTES_LEGACY,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
- ASSERT (nm_setting_ip4_config_get_never_default (s_ip4) == FALSE,
+ ASSERT (nm_setting_ip_config_get_never_default (s_ip4) == FALSE,
"read-write-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_READ_WRITE_STATIC_ROUTES_LEGACY,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_NEVER_DEFAULT);
+ NM_SETTING_IP_CONFIG_NEVER_DEFAULT);
/* Save the ifcfg; use a special different scratch dir to ensure that
* we can clean up after the written connection in both the original
@@ -7329,25 +7053,17 @@ test_write_wired_static_routes (void)
NMConnection *reread;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
static const char *mac = "31:33:33:37:be:cd";
guint32 mtu = 1492;
char *uuid;
- const guint32 ip1 = htonl (0x01010103);
- const guint32 ip2 = htonl (0x01010105);
- const guint32 gw = htonl (0x01010101);
const char *dns1 = "4.2.2.1";
const char *dns2 = "4.2.2.2";
- const guint32 route_dst1 = htonl (0x01020300);
- const guint32 route_dst2= htonl (0x03020100);
- const guint32 route_gw1 = htonl (0xdeadbeef);
- const guint32 route_gw2 = htonl (0xcafeabbe);
- const guint32 prefix = 24;
const char *dns_search1 = "foobar.com";
const char *dns_search2 = "lab.foobar.com";
- NMIP4Address *addr;
- NMIP4Route *route;
+ NMIPAddress *addr;
+ NMIPRoute *route;
gboolean success;
GError *error = NULL;
char *testfile = NULL;
@@ -7382,56 +7098,48 @@ test_write_wired_static_routes (void)
NULL);
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_GATEWAY, "1.1.1.1",
NULL);
- addr = nm_ip4_address_new ();
- nm_ip4_address_set_address (addr, ip1);
- nm_ip4_address_set_prefix (addr, prefix);
- nm_ip4_address_set_gateway (addr, gw);
- nm_setting_ip4_config_add_address (s_ip4, addr);
- nm_ip4_address_unref (addr);
+ addr = nm_ip_address_new (AF_INET, "1.1.1.3", 24, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_address (s_ip4, addr);
+ nm_ip_address_unref (addr);
- addr = nm_ip4_address_new ();
- nm_ip4_address_set_address (addr, ip2);
- nm_ip4_address_set_prefix (addr, prefix);
- nm_ip4_address_set_gateway (addr, gw);
- nm_setting_ip4_config_add_address (s_ip4, addr);
- nm_ip4_address_unref (addr);
+ addr = nm_ip_address_new (AF_INET, "1.1.1.5", 24, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_address (s_ip4, addr);
+ nm_ip_address_unref (addr);
/* Write out routes */
- route = nm_ip4_route_new ();
- nm_ip4_route_set_dest (route, route_dst1);
- nm_ip4_route_set_prefix (route, prefix);
- nm_ip4_route_set_next_hop (route, route_gw1);
- nm_setting_ip4_config_add_route (s_ip4, route);
- nm_ip4_route_unref (route);
-
- route = nm_ip4_route_new ();
- nm_ip4_route_set_dest (route, route_dst2);
- nm_ip4_route_set_prefix (route, prefix);
- nm_ip4_route_set_next_hop (route, route_gw2);
- nm_ip4_route_set_metric (route, 77);
- nm_setting_ip4_config_add_route (s_ip4, route);
- nm_ip4_route_unref (route);
-
- nm_setting_ip4_config_add_dns (s_ip4, dns1);
- nm_setting_ip4_config_add_dns (s_ip4, dns2);
-
- nm_setting_ip4_config_add_dns_search (s_ip4, dns_search1);
- nm_setting_ip4_config_add_dns_search (s_ip4, dns_search2);
+ route = nm_ip_route_new (AF_INET, "1.2.3.0", 24, "222.173.190.239", 0, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_route (s_ip4, route);
+ nm_ip_route_unref (route);
+
+ route = nm_ip_route_new (AF_INET, "3.2.1.0", 24, "202.254.186.190", 77, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_route (s_ip4, route);
+ nm_ip_route_unref (route);
+
+ nm_setting_ip_config_add_dns (s_ip4, dns1);
+ nm_setting_ip_config_add_dns (s_ip4, dns2);
+
+ nm_setting_ip_config_add_dns_search (s_ip4, dns_search1);
+ nm_setting_ip_config_add_dns_search (s_ip4, dns_search2);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
@@ -7494,8 +7202,8 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void)
NMConnection *reread;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
NMSetting8021x *s_8021x;
char *uuid;
gboolean success;
@@ -7527,18 +7235,18 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void)
nm_connection_add_setting (connection, NM_SETTING (s_wired));
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
/* 802.1x setting */
@@ -7648,8 +7356,8 @@ test_write_wired_8021x_tls (NMSetting8021xCKScheme scheme,
NMConnection *reread;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
NMSetting8021x *s_8021x;
char *uuid;
gboolean success;
@@ -7687,17 +7395,17 @@ test_write_wired_8021x_tls (NMSetting8021xCKScheme scheme,
nm_connection_add_setting (connection, NM_SETTING (s_wired));
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
g_assert (s_ip4);
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
g_assert (s_ip6);
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
@@ -7862,14 +7570,12 @@ test_write_wired_aliases (void)
NMConnection *reread;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
char *uuid;
int num_addresses = 4;
- guint32 ip[] = { 0x01010101, 0x01010102, 0x01010103, 0x01010104 };
- const char *label[] = { "", "alias0:2", "", "alias0:3" };
- const guint32 gw = htonl (0x01010101);
- const guint32 prefix = 24;
- NMIP4Address *addr;
+ const char *ip[] = { "1.1.1.1", "1.1.1.2", "1.1.1.3", "1.1.1.4" };
+ const char *label[] = { NULL, "alias0:2", NULL, "alias0:3" };
+ NMIPAddress *addr;
gboolean success;
GError *error = NULL;
char *testfile = NULL;
@@ -7908,24 +7614,25 @@ test_write_wired_aliases (void)
nm_connection_add_setting (connection, NM_SETTING (s_wired));
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
ASSERT (s_ip4 != NULL,
"wired-aliases-write", "failed to allocate new %s setting",
NM_SETTING_IP4_CONFIG_SETTING_NAME);
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
- NM_SETTING_IP4_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_GATEWAY, "1.1.1.1",
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
for (i = 0; i < num_addresses; i++) {
- addr = nm_ip4_address_new ();
- nm_ip4_address_set_address (addr, ip[i]);
- nm_ip4_address_set_prefix (addr, prefix);
- nm_ip4_address_set_gateway (addr, gw);
- _nm_setting_ip4_config_add_address_with_label (s_ip4, addr, label[i]);
- nm_ip4_address_unref (addr);
+ addr = nm_ip_address_new (AF_INET, ip[i], 24, &error);
+ g_assert_no_error (error);
+ if (label[i])
+ nm_ip_address_set_attribute (addr, "label", g_variant_new_string (label[i]));
+ nm_setting_ip_config_add_address (s_ip4, addr);
+ nm_ip_address_unref (addr);
}
ASSERT (nm_connection_verify (connection, &error) == TRUE,
@@ -7994,49 +7701,33 @@ test_write_wired_aliases (void)
* verify the aliases manually.
*/
s_ip4 = nm_connection_get_setting_ip4_config (connection);
- ASSERT (nm_setting_ip4_config_get_num_addresses (s_ip4) == num_addresses,
+ ASSERT (nm_setting_ip_config_get_num_addresses (s_ip4) == num_addresses,
"wired-aliases-write-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
testfile,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_ADDRESSES);
+ NM_SETTING_IP_CONFIG_ADDRESSES);
/* Addresses */
for (i = 0; i < num_addresses; i++) {
- guint32 addrbytes;
+ const char *addrstr;
- addr = nm_setting_ip4_config_get_address (s_ip4, i);
- ASSERT (addr,
- "wired-aliases-write-verify-ip4", "failed to verify %s: missing IP4 address #%d",
- testfile,
- i);
+ addr = nm_setting_ip_config_get_address (s_ip4, i);
+ g_assert (addr != NULL);
- addrbytes = nm_ip4_address_get_address (addr);
+ addrstr = nm_ip_address_get_address (addr);
for (j = 0; j < num_addresses; j++) {
- if (addrbytes == ip[j])
+ if (!g_strcmp0 (addrstr, ip[j]))
break;
}
+ g_assert (j < num_addresses);
- ASSERT (j < num_addresses,
- "wired-aliases-write-verify-ip4", "failed to verify %s: unexpected IP4 address #%d",
- testfile,
- i);
-
- ASSERT (nm_ip4_address_get_prefix (addr) == prefix,
- "wired-aliases-write-verify-ip4", "failed to verify %s: unexpected IP4 address prefix #%d",
- testfile,
- i);
-
- ASSERT (nm_ip4_address_get_gateway (addr) == gw,
- "wired-aliases-write-verify-ip4", "failed to verify %s: unexpected IP4 address gateway #%d",
- testfile,
- i);
-
- ASSERT (g_strcmp0 (_nm_setting_ip4_config_get_address_label (s_ip4, i), label[j]) == 0,
- "wired-aliases-write-verify-ip4", "failed to verify %s: unexpected IP4 address label #%d",
- testfile,
- i);
+ g_assert_cmpint (nm_ip_address_get_prefix (addr), ==, 24);
+ if (label[j])
+ g_assert_cmpstr (g_variant_get_string (nm_ip_address_get_attribute (addr, "label"), NULL), ==, label[j]);
+ else
+ g_assert (nm_ip_address_get_attribute (addr, "label") == NULL);
- ip[j] = 0;
+ ip[j] = NULL;
}
for (i = 0; i < num_addresses; i++) {
@@ -8046,6 +7737,9 @@ test_write_wired_aliases (void)
ip[i]);
}
+ /* Gateway */
+ g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, "1.1.1.1");
+
g_free (testfile);
g_free (keyfile);
g_free (routefile);
@@ -8060,18 +7754,12 @@ test_write_gateway (void)
NMConnection *connection, *reread;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
char *uuid, *testfile = NULL, *val;
gboolean success;
GError *error = NULL;
shvarFile *f;
- NMIP4Address *addr;
- const char *ip1_str = "1.1.1.3";
- const char *ip2_str = "2.2.2.5";
- const char *gw1_str = "1.1.1.254";
- const char *gw2_str = "2.2.2.254";
- struct in_addr ip1, ip2, gw1, gw2;
- const guint32 prefix = 24;
+ NMIPAddress *addr;
connection = nm_simple_connection_new ();
@@ -8092,32 +7780,24 @@ test_write_gateway (void)
nm_connection_add_setting (connection, NM_SETTING (s_wired));
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
- NM_SETTING_IP4_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_GATEWAY, "1.1.1.254",
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
- inet_pton (AF_INET, ip1_str, &ip1);
- inet_pton (AF_INET, ip2_str, &ip2);
- inet_pton (AF_INET, gw1_str, &gw1);
- inet_pton (AF_INET, gw2_str, &gw2);
-
- addr = nm_ip4_address_new ();
- nm_ip4_address_set_address (addr, ip1.s_addr);
- nm_ip4_address_set_prefix (addr, prefix);
- nm_ip4_address_set_gateway (addr, gw1.s_addr);
- nm_setting_ip4_config_add_address (s_ip4, addr);
- nm_ip4_address_unref (addr);
+ addr = nm_ip_address_new (AF_INET, "1.1.1.3", 24, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_address (s_ip4, addr);
+ nm_ip_address_unref (addr);
- addr = nm_ip4_address_new ();
- nm_ip4_address_set_address (addr, ip2.s_addr);
- nm_ip4_address_set_prefix (addr, prefix);
- nm_ip4_address_set_gateway (addr, gw2.s_addr);
- nm_setting_ip4_config_add_address (s_ip4, addr);
- nm_ip4_address_unref (addr);
+ addr = nm_ip_address_new (AF_INET, "2.2.2.5", 24, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_address (s_ip4, addr);
+ nm_ip_address_unref (addr);
success = nm_connection_verify (connection, &error);
g_assert_no_error (error);
@@ -8138,12 +7818,12 @@ test_write_gateway (void)
/* re-read the file to check that the keys was written as IPADDR, GATEWAY and IPADDR1, GATEWAY1 */
val = svGetValue (f, "IPADDR", FALSE);
g_assert (val);
- g_assert_cmpstr (val, ==, ip1_str);
+ g_assert_cmpstr (val, ==, "1.1.1.3");
g_free (val);
val = svGetValue (f, "IPADDR1", FALSE);
g_assert (val);
- g_assert_cmpstr (val, ==, ip2_str);
+ g_assert_cmpstr (val, ==, "2.2.2.5");
g_free (val);
val = svGetValue (f, "IPADDR0", FALSE);
@@ -8164,17 +7844,14 @@ test_write_gateway (void)
val = svGetValue (f, "GATEWAY", FALSE);
g_assert (val);
- g_assert_cmpstr (val, ==, gw1_str);
- g_free (val);
-
- val = svGetValue (f, "GATEWAY1", FALSE);
- g_assert (val);
- g_assert_cmpstr (val, ==, gw2_str);
+ g_assert_cmpstr (val, ==, "1.1.1.254");
g_free (val);
val = svGetValue (f, "GATEWAY0", FALSE);
g_assert (val == NULL);
+ val = svGetValue (f, "GATEWAY1", FALSE);
+ g_assert (val == NULL);
svCloseFile (f);
@@ -8207,8 +7884,8 @@ test_write_wifi_open (void)
NMConnection *reread;
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
gboolean success;
GError *error = NULL;
@@ -8260,18 +7937,18 @@ test_write_wifi_open (void)
g_bytes_unref (ssid);
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
@@ -8347,8 +8024,8 @@ test_write_wifi_open_hex_ssid (void)
NMConnection *reread;
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
gboolean success;
GError *error = NULL;
@@ -8390,18 +8067,18 @@ test_write_wifi_open_hex_ssid (void)
g_bytes_unref (ssid);
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
@@ -8461,8 +8138,8 @@ test_write_wifi_wep (void)
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
NMSettingWirelessSecurity *s_wsec;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
gboolean success;
GError *error = NULL;
@@ -8519,18 +8196,18 @@ test_write_wifi_wep (void)
nm_setting_wireless_security_set_wep_key (s_wsec, 3, "BBBBBBBBBBBBBBBBBBBBBBBBBB");
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
@@ -8602,8 +8279,8 @@ test_write_wifi_wep_adhoc (void)
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
NMSettingWirelessSecurity *s_wsec;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
gboolean success;
GError *error = NULL;
@@ -8616,11 +8293,8 @@ test_write_wifi_wep_adhoc (void)
GBytes *ssid;
const char *ssid_data = "blahblah";
struct stat statbuf;
- NMIP4Address *addr;
- const guint32 ip1 = htonl (0x01010103);
- const guint32 gw = htonl (0x01010101);
+ NMIPAddress *addr;
const char *dns1 = "4.2.2.1";
- const guint32 prefix = 24;
connection = nm_simple_connection_new ();
@@ -8658,28 +8332,29 @@ test_write_wifi_wep_adhoc (void)
nm_setting_wireless_security_set_wep_key (s_wsec, 0, "0123456789abcdef0123456789");
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, NULL);
+ g_object_set (s_ip4,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_GATEWAY, "1.1.1.1",
+ NULL);
/* IP Address */
- addr = nm_ip4_address_new ();
- nm_ip4_address_set_address (addr, ip1);
- nm_ip4_address_set_prefix (addr, prefix);
- nm_ip4_address_set_gateway (addr, gw);
- nm_setting_ip4_config_add_address (s_ip4, addr);
- nm_ip4_address_unref (addr);
+ addr = nm_ip_address_new (AF_INET, "1.1.1.3", 24, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_address (s_ip4, addr);
+ nm_ip_address_unref (addr);
- nm_setting_ip4_config_add_dns (s_ip4, dns1);
+ nm_setting_ip_config_add_dns (s_ip4, dns1);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
@@ -8751,8 +8426,8 @@ test_write_wifi_wep_passphrase (void)
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
NMSettingWirelessSecurity *s_wsec;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
gboolean success;
GError *error = NULL;
@@ -8807,18 +8482,18 @@ test_write_wifi_wep_passphrase (void)
nm_setting_wireless_security_set_wep_key (s_wsec, 0, "asdfdjaslfjasd;flasjdfl;aksdf");
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
@@ -8890,8 +8565,8 @@ test_write_wifi_wep_40_ascii (void)
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
NMSettingWirelessSecurity *s_wsec;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
gboolean success;
GError *error = NULL;
@@ -8948,18 +8623,18 @@ test_write_wifi_wep_40_ascii (void)
nm_setting_wireless_security_set_wep_key (s_wsec, 3, "donec");
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
@@ -9031,8 +8706,8 @@ test_write_wifi_wep_104_ascii (void)
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
NMSettingWirelessSecurity *s_wsec;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
gboolean success;
GError *error = NULL;
@@ -9089,18 +8764,18 @@ test_write_wifi_wep_104_ascii (void)
nm_setting_wireless_security_set_wep_key (s_wsec, 3, "thisismyascii");
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
@@ -9172,8 +8847,8 @@ test_write_wifi_leap (void)
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
NMSettingWirelessSecurity *s_wsec;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
gboolean success;
GError *error = NULL;
@@ -9227,18 +8902,18 @@ test_write_wifi_leap (void)
NULL);
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
@@ -9310,8 +8985,8 @@ test_write_wifi_leap_secret_flags (NMSettingSecretFlags flags)
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
NMSettingWirelessSecurity *s_wsec;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
gboolean success;
GError *error = NULL;
@@ -9366,19 +9041,19 @@ test_write_wifi_leap_secret_flags (NMSettingSecretFlags flags)
NULL);
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
g_assert (s_ip4);
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
g_assert (s_ip6);
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
success = nm_connection_verify (connection, &error);
@@ -9449,8 +9124,8 @@ test_write_wifi_wpa_psk (const char *name,
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
NMSettingWirelessSecurity *s_wsec;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid, *tmp;
gboolean success;
GError *error = NULL;
@@ -9518,18 +9193,18 @@ test_write_wifi_wpa_psk (const char *name,
}
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
@@ -9595,8 +9270,8 @@ test_write_wifi_wpa_psk_adhoc (void)
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
NMSettingWirelessSecurity *s_wsec;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
gboolean success;
GError *error = NULL;
@@ -9608,11 +9283,8 @@ test_write_wifi_wpa_psk_adhoc (void)
gboolean ignore_error = FALSE;
GBytes *ssid;
const char *ssid_data = "blahblah";
- NMIP4Address *addr;
- const guint32 ip1 = htonl (0x01010103);
- const guint32 gw = htonl (0x01010101);
+ NMIPAddress *addr;
const char *dns1 = "4.2.2.1";
- const guint32 prefix = 24;
connection = nm_simple_connection_new ();
@@ -9657,28 +9329,29 @@ test_write_wifi_wpa_psk_adhoc (void)
nm_setting_wireless_security_add_group (s_wsec, "tkip");
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, NULL);
+ g_object_set (s_ip4,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_GATEWAY, "1.1.1.1",
+ NULL);
/* IP Address */
- addr = nm_ip4_address_new ();
- nm_ip4_address_set_address (addr, ip1);
- nm_ip4_address_set_prefix (addr, prefix);
- nm_ip4_address_set_gateway (addr, gw);
- nm_setting_ip4_config_add_address (s_ip4, addr);
- nm_ip4_address_unref (addr);
+ addr = nm_ip_address_new (AF_INET, "1.1.1.3", 25, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_address (s_ip4, addr);
+ nm_ip_address_unref (addr);
- nm_setting_ip4_config_add_dns (s_ip4, dns1);
+ nm_setting_ip_config_add_dns (s_ip4, dns1);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
@@ -9743,8 +9416,8 @@ test_write_wifi_wpa_eap_tls (void)
NMSettingWireless *s_wifi;
NMSettingWirelessSecurity *s_wsec;
NMSetting8021x *s_8021x;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
gboolean success;
GError *error = NULL;
@@ -9831,18 +9504,18 @@ test_write_wifi_wpa_eap_tls (void)
TEST_IFCFG_WIFI_WPA_EAP_TLS_PRIVATE_KEY, error->message);
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
@@ -9907,8 +9580,8 @@ test_write_wifi_wpa_eap_ttls_tls (void)
NMSettingWireless *s_wifi;
NMSettingWirelessSecurity *s_wsec;
NMSetting8021x *s_8021x;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
gboolean success;
GError *error = NULL;
@@ -10013,18 +9686,18 @@ test_write_wifi_wpa_eap_ttls_tls (void)
TEST_IFCFG_WIFI_WPA_EAP_TLS_PRIVATE_KEY, error->message);
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
@@ -10089,8 +9762,8 @@ test_write_wifi_wpa_eap_ttls_mschapv2 (void)
NMSettingWireless *s_wifi;
NMSettingWirelessSecurity *s_wsec;
NMSetting8021x *s_8021x;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
gboolean success;
GError *error = NULL;
@@ -10167,18 +9840,18 @@ test_write_wifi_wpa_eap_ttls_mschapv2 (void)
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
@@ -10242,8 +9915,8 @@ test_write_wifi_wpa_then_open (void)
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
NMSettingWirelessSecurity *s_wsec;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
gboolean success;
GError *error = NULL;
@@ -10310,20 +9983,20 @@ test_write_wifi_wpa_then_open (void)
nm_setting_wireless_security_add_group (s_wsec, "ccmp");
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
g_assert (s_ip4);
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
g_assert (s_ip6);
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
success = nm_connection_verify (connection, &error);
@@ -10432,8 +10105,8 @@ test_write_wifi_wpa_then_wep_with_perms (void)
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
NMSettingWirelessSecurity *s_wsec;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
gboolean success;
GError *error = NULL;
@@ -10506,20 +10179,20 @@ test_write_wifi_wpa_then_wep_with_perms (void)
nm_setting_wireless_security_add_group (s_wsec, "ccmp");
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
g_assert (s_ip4);
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
g_assert (s_ip6);
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
success = nm_connection_verify (connection, &error);
@@ -10636,8 +10309,8 @@ test_write_wifi_dynamic_wep_leap (void)
NMSettingWireless *s_wifi;
NMSettingWirelessSecurity *s_wsec;
NMSetting8021x *s_8021x;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
gboolean success;
GError *error = NULL;
@@ -10702,19 +10375,19 @@ test_write_wifi_dynamic_wep_leap (void)
NULL);
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
g_assert (s_ip4);
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
g_assert (s_ip6);
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
success = nm_connection_verify (connection, &error);
@@ -10789,8 +10462,8 @@ test_write_wired_qeth_dhcp (void)
NMConnection *reread;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
char **subchans;
gboolean success;
@@ -10834,20 +10507,20 @@ test_write_wired_qeth_dhcp (void)
nm_setting_wired_add_s390_option (s_wired, "protocol", "blahbalh");
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
NULL);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
/* Verify */
@@ -10910,8 +10583,8 @@ test_write_wired_ctc_dhcp (void)
NMConnection *reread;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
char **subchans;
gboolean success;
@@ -10955,19 +10628,19 @@ test_write_wired_ctc_dhcp (void)
nm_setting_wired_add_s390_option (s_wired, "ctcprot", "0");
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
g_assert (s_ip4);
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
g_assert (s_ip6);
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
/* Verify */
@@ -11043,8 +10716,8 @@ test_write_permissions (void)
NMConnection *reread;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
gboolean success;
GError *error = NULL;
@@ -11079,20 +10752,20 @@ test_write_permissions (void)
nm_connection_add_setting (connection, NM_SETTING (s_wired));
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
NULL);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
/* Verify */
@@ -11156,8 +10829,8 @@ test_write_wifi_wep_agent_keys (void)
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
NMSettingWirelessSecurity *s_wsec;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
const char *str_ssid = "foobarbaz";
GBytes *ssid;
@@ -11187,19 +10860,19 @@ test_write_wifi_wep_agent_keys (void)
g_free (uuid);
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
g_assert (s_ip4);
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
g_assert (s_ip6);
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
/* Wifi setting */
@@ -11294,7 +10967,7 @@ test_write_wired_pppoe (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
NMSettingPppoe *s_pppoe;
NMSettingPpp *s_ppp;
char *uuid;
@@ -11322,11 +10995,11 @@ test_write_wired_pppoe (void)
nm_connection_add_setting (connection, NM_SETTING (s_wired));
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
NULL);
/* PPPoE setting */
@@ -11363,7 +11036,7 @@ test_write_vpn (void)
{
NMConnection *connection;
NMSettingConnection *s_con;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
NMSettingVpn *s_vpn;
char *uuid;
gboolean success;
@@ -11398,11 +11071,11 @@ test_write_vpn (void)
nm_setting_vpn_add_secret (s_vpn, "password", "sup3rs3cr3t");
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
NULL);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
@@ -11425,7 +11098,7 @@ test_write_mobile_broadband (gboolean gsm)
{
NMConnection *connection;
NMSettingConnection *s_con;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
NMSettingGsm *s_gsm;
NMSettingCdma *s_cdma;
NMSettingPpp *s_ppp;
@@ -11476,11 +11149,11 @@ test_write_mobile_broadband (gboolean gsm)
NULL);
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
NULL);
/* PPP setting */
@@ -11563,13 +11236,10 @@ test_write_bridge_main (void)
NMConnection *reread;
NMSettingConnection *s_con;
NMSettingBridge *s_bridge;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
- const guint32 ip1 = htonl (0x01010103);
- const guint32 gw = htonl (0x01010101);
- const guint32 prefix = 24;
- NMIP4Address *addr;
+ NMIPAddress *addr;
static const char *mac = "31:33:33:37:be:cd";
gboolean success;
GError *error = NULL;
@@ -11608,29 +11278,28 @@ test_write_bridge_main (void)
NULL);
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
g_assert (s_ip4);
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
- NM_SETTING_IP4_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_GATEWAY, "1.1.1.1",
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
- addr = nm_ip4_address_new ();
- nm_ip4_address_set_address (addr, ip1);
- nm_ip4_address_set_prefix (addr, prefix);
- nm_ip4_address_set_gateway (addr, gw);
- nm_setting_ip4_config_add_address (s_ip4, addr);
- nm_ip4_address_unref (addr);
+ addr = nm_ip_address_new (AF_INET, "1.1.1.3", 24, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_address (s_ip4, addr);
+ nm_ip_address_unref (addr);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
g_assert (s_ip6);
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
NULL);
nmtst_assert_connection_verifies_without_normalization (connection);
@@ -12165,8 +11834,8 @@ test_write_ethernet_missing_ipv6 (void)
NMConnection *reread;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
gboolean success;
GError *error = NULL;
@@ -12200,14 +11869,14 @@ test_write_ethernet_missing_ipv6 (void)
nm_connection_add_setting (connection, NM_SETTING (s_wired));
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
g_assert (s_ip4);
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, "random-client-id-00:22:33",
- NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES, TRUE,
- NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, TRUE,
+ NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, TRUE,
+ NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, TRUE,
NULL);
/* IP6 setting */
@@ -12258,12 +11927,12 @@ test_write_ethernet_missing_ipv6 (void)
* the comparison can succeed. Missing IPv6 setting should have been
* written out (and re-read) as Automatic IPv6.
*/
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
g_assert (s_ip6);
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
ASSERT (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT) == TRUE,
@@ -12350,14 +12019,11 @@ test_write_bond_main (void)
NMConnection *reread;
NMSettingConnection *s_con;
NMSettingBond *s_bond;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
NMSettingWired *s_wired;
char *uuid;
- const guint32 ip1 = htonl (0x01010103);
- const guint32 gw = htonl (0x01010101);
- const guint32 prefix = 24;
- NMIP4Address *addr;
+ NMIPAddress *addr;
gboolean success;
GError *error = NULL;
char *testfile = NULL;
@@ -12392,27 +12058,26 @@ test_write_bond_main (void)
nm_connection_add_setting (connection, NM_SETTING (s_bond));
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
- NM_SETTING_IP4_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_GATEWAY, "1.1.1.1",
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
- addr = nm_ip4_address_new ();
- nm_ip4_address_set_address (addr, ip1);
- nm_ip4_address_set_prefix (addr, prefix);
- nm_ip4_address_set_gateway (addr, gw);
- nm_setting_ip4_config_add_address (s_ip4, addr);
- nm_ip4_address_unref (addr);
+ addr = nm_ip_address_new (AF_INET, "1.1.1.3", 24, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_address (s_ip4, addr);
+ nm_ip_address_unref (addr);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
NULL);
nmtst_assert_connection_verifies_without_normalization (connection);
@@ -12693,15 +12358,12 @@ test_write_infiniband (void)
NMConnection *reread;
NMSettingConnection *s_con;
NMSettingInfiniband *s_infiniband;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
const char *mac = "80:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22";
guint32 mtu = 65520;
char *uuid;
- const guint32 ip1 = htonl (0x01010103);
- const guint32 gw = htonl (0x01010101);
- const guint32 prefix = 24;
- NMIP4Address *addr;
+ NMIPAddress *addr;
gboolean success;
GError *error = NULL;
char *testfile = NULL;
@@ -12737,27 +12399,26 @@ test_write_infiniband (void)
NULL);
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
- NM_SETTING_IP4_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_GATEWAY, "1.1.1.1",
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
- addr = nm_ip4_address_new ();
- nm_ip4_address_set_address (addr, ip1);
- nm_ip4_address_set_prefix (addr, prefix);
- nm_ip4_address_set_gateway (addr, gw);
- nm_setting_ip4_config_add_address (s_ip4, addr);
- nm_ip4_address_unref (addr);
+ addr = nm_ip_address_new (AF_INET, "1.1.1.3", 24, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_address (s_ip4, addr);
+ nm_ip_address_unref (addr);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
NULL);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
@@ -13033,8 +12694,8 @@ test_write_dcb_basic (void)
NMSettingConnection *s_con;
NMSettingWired *s_wired;
NMSettingDcb *s_dcb;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
gboolean success, ignore_error;
guint i;
char *uuid, *testfile;
@@ -13063,12 +12724,12 @@ test_write_dcb_basic (void)
nm_connection_add_setting (connection, NM_SETTING (s_wired));
/* IP stuff */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
- g_object_set (G_OBJECT (s_ip4), NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
+ g_object_set (G_OBJECT (s_ip4), NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
- g_object_set (G_OBJECT (s_ip6), NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL);
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
+ g_object_set (G_OBJECT (s_ip6), NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL);
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
/* DCB */
@@ -13313,8 +12974,8 @@ test_write_fcoe_mode (gconstpointer user_data)
NMSettingConnection *s_con;
NMSettingWired *s_wired;
NMSettingDcb *s_dcb;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
gboolean success, ignore_error;
char *uuid, *testfile;
@@ -13336,12 +12997,12 @@ test_write_fcoe_mode (gconstpointer user_data)
nm_connection_add_setting (connection, NM_SETTING (s_wired));
/* IP stuff */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
- g_object_set (G_OBJECT (s_ip4), NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
+ g_object_set (G_OBJECT (s_ip4), NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
- g_object_set (G_OBJECT (s_ip6), NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL);
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
+ g_object_set (G_OBJECT (s_ip6), NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL);
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
/* DCB */
@@ -13435,8 +13096,8 @@ test_write_team_master (void)
NMSettingConnection *s_con;
NMSettingTeam *s_team;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid, *testfile = NULL, *val;
gboolean success;
GError *error = NULL;
@@ -13472,21 +13133,21 @@ test_write_team_master (void)
nm_connection_add_setting (connection, NM_SETTING (s_wired));
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
g_assert (s_ip4);
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
NULL);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
g_assert (s_ip6);
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
NULL);
nmtst_assert_connection_verifies_without_normalization (connection);
@@ -13791,6 +13452,43 @@ test_svUnescape (void)
g_rand_free (r);
}
+static void
+test_read_vlan_trailing_spaces (void)
+{
+ const char *testfile = TEST_IFCFG_DIR"/network-scripts/ifcfg-test-vlan-trailing-spaces";
+ NMConnection *connection;
+ gboolean success;
+ GError *error = NULL;
+ NMSettingVlan *s_vlan;
+ char *contents = NULL;
+
+ /* Ensure there is whitespace at the end of the VLAN interface name,
+ * to prevent the whitespace getting stripped off and committed mistakenly
+ * by something in the future.
+ */
+ success = g_file_get_contents (testfile, &contents, NULL, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+ g_assert (contents && contents[0]);
+ g_assert (strstr (contents, "DEVICE=\"vlan201\" \n"));
+ g_free (contents);
+
+ connection = connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL,
+ NULL, NULL, NULL, &error, NULL);
+ g_assert_no_error (error);
+ g_assert (connection != NULL);
+
+ s_vlan = nm_connection_get_setting_vlan (connection);
+ g_assert (s_vlan);
+
+ g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "vlan201");
+ g_assert_cmpstr (nm_setting_vlan_get_parent (s_vlan), ==, "enccw0.0.fb00");
+ g_assert_cmpint (nm_setting_vlan_get_id (s_vlan), ==, 201);
+ g_assert_cmpint (nm_setting_vlan_get_flags (s_vlan), ==, 0);
+
+ g_object_unref (connection);
+}
+
#define TEST_IFCFG_WIFI_OPEN_SSID_BAD_HEX TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-bad-hex"
#define TEST_IFCFG_WIFI_OPEN_SSID_LONG_QUOTED TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-long-quoted"
@@ -13816,6 +13514,7 @@ int main (int argc, char **argv)
nmtst_init_assert_logging (&argc, &argv);
g_test_add_func (TPATH "svUnescape", test_svUnescape);
+ g_test_add_func (TPATH "vlan-trailing-spaces", test_read_vlan_trailing_spaces);
g_test_add_func (TPATH "unmanaged", test_read_unmanaged);
g_test_add_func (TPATH "unmanaged-unrecognized", test_read_unmanaged_unrecognized);
@@ -13829,7 +13528,7 @@ int main (int argc, char **argv)
g_test_add_data_func (TPATH "static-ip6-only-gw/_NULL_", NULL, test_write_wired_static_ip6_only_gw);
g_test_add_data_func (TPATH "static-ip6-only-gw/::", "::", test_write_wired_static_ip6_only_gw);
g_test_add_data_func (TPATH "static-ip6-only-gw/2001:db8:8:4::2", "2001:db8:8:4::2", test_write_wired_static_ip6_only_gw);
- g_test_add_data_func (TPATH "static-ip6-only-gw/ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255", "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255", test_write_wired_static_ip6_only_gw);
+ g_test_add_data_func (TPATH "static-ip6-only-gw/::ffff:255.255.255.255", "::ffff:255.255.255.255", test_write_wired_static_ip6_only_gw);
test_read_wired_static (TEST_IFCFG_WIRED_STATIC, "System test-wired-static", TRUE);
test_read_wired_static (TEST_IFCFG_WIRED_STATIC_BOOTPROTO, "System test-wired-static-bootproto", FALSE);
diff --git a/src/settings/plugins/ifcfg-rh/writer.c b/src/settings/plugins/ifcfg-rh/writer.c
index 55dca87c82..6857c1f70a 100644
--- a/src/settings/plugins/ifcfg-rh/writer.c
+++ b/src/settings/plugins/ifcfg-rh/writer.c
@@ -1741,14 +1741,14 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg)
}
static gboolean
-write_route_file_legacy (const char *filename, NMSettingIP4Config *s_ip4, GError **error)
+write_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError **error)
{
- char dest[INET_ADDRSTRLEN];
- char next_hop[INET_ADDRSTRLEN];
+ const char *dest, *next_hop;
char **route_items;
char *route_contents;
- NMIP4Route *route;
- guint32 ip, prefix, metric;
+ NMIPRoute *route;
+ guint32 prefix;
+ gint64 metric;
guint32 i, num;
gboolean success = FALSE;
@@ -1757,7 +1757,7 @@ write_route_file_legacy (const char *filename, NMSettingIP4Config *s_ip4, GError
g_return_val_if_fail (error != NULL, FALSE);
g_return_val_if_fail (*error == NULL, FALSE);
- num = nm_setting_ip4_config_get_num_routes (s_ip4);
+ num = nm_setting_ip_config_get_num_routes (s_ip4);
if (num == 0) {
unlink (filename);
return TRUE;
@@ -1765,21 +1765,17 @@ write_route_file_legacy (const char *filename, NMSettingIP4Config *s_ip4, GError
route_items = g_malloc0 (sizeof (char*) * (num + 1));
for (i = 0; i < num; i++) {
- route = nm_setting_ip4_config_get_route (s_ip4, i);
+ route = nm_setting_ip_config_get_route (s_ip4, i);
- memset (dest, 0, sizeof (dest));
- ip = nm_ip4_route_get_dest (route);
- inet_ntop (AF_INET, (const void *) &ip, &dest[0], sizeof (dest));
+ dest = nm_ip_route_get_dest (route);
+ prefix = nm_ip_route_get_prefix (route);
+ next_hop = nm_ip_route_get_next_hop (route);
+ metric = nm_ip_route_get_metric (route);
- prefix = nm_ip4_route_get_prefix (route);
-
- memset (next_hop, 0, sizeof (next_hop));
- ip = nm_ip4_route_get_next_hop (route);
- inet_ntop (AF_INET, (const void *) &ip, &next_hop[0], sizeof (next_hop));
-
- metric = nm_ip4_route_get_metric (route);
-
- route_items[i] = g_strdup_printf ("%s/%u via %s metric %u\n", dest, prefix, next_hop, metric);
+ if (metric == -1)
+ route_items[i] = g_strdup_printf ("%s/%u via %s\n", dest, prefix, next_hop);
+ else
+ route_items[i] = g_strdup_printf ("%s/%u via %s metric %u\n", dest, prefix, next_hop, (guint32) metric);
}
route_items[num] = NULL;
route_contents = g_strjoinv (NULL, route_items);
@@ -1802,7 +1798,7 @@ error:
static gboolean
write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
{
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
const char *value;
char *addr_key, *prefix_key, *netmask_key, *gw_key, *metric_key, *tmp;
char *route_path = NULL;
@@ -1815,7 +1811,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
s_ip4 = nm_connection_get_setting_ip4_config (connection);
if (s_ip4)
- method = nm_setting_ip4_config_get_method (s_ip4);
+ method = nm_setting_ip_config_get_method (s_ip4);
/* Missing IP4 setting is assumed to be DHCP */
if (!method)
@@ -1858,7 +1854,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
/* Temporarily create fake IP4 setting if missing; method set to DHCP above */
if (!s_ip4) {
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
fake_ip4 = TRUE;
}
@@ -1885,17 +1881,17 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
/* Write out IPADDR<n>, PREFIX<n>, GATEWAY<n> for current IP addresses
* without labels. Unset obsolete NETMASK<n>.
*/
- num = nm_setting_ip4_config_get_num_addresses (s_ip4);
+ num = nm_setting_ip_config_get_num_addresses (s_ip4);
for (i = n = 0; i < num; i++) {
- char buf[INET_ADDRSTRLEN];
- NMIP4Address *addr;
- guint32 ip;
+ NMIPAddress *addr;
+
+ addr = nm_setting_ip_config_get_address (s_ip4, i);
if (i > 0) {
- const char *label;
+ GVariant *label;
- label = _nm_setting_ip4_config_get_address_label (s_ip4, i);
- if (*label)
+ label = nm_ip_address_get_attribute (addr, "label");
+ if (label)
continue;
}
@@ -1916,26 +1912,14 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
gw_key = g_strdup_printf ("GATEWAY%d", n);
}
- addr = nm_setting_ip4_config_get_address (s_ip4, i);
-
- memset (buf, 0, sizeof (buf));
- ip = nm_ip4_address_get_address (addr);
- inet_ntop (AF_INET, (const void *) &ip, &buf[0], sizeof (buf));
- svSetValue (ifcfg, addr_key, &buf[0], FALSE);
+ svSetValue (ifcfg, addr_key, nm_ip_address_get_address (addr), FALSE);
- tmp = g_strdup_printf ("%u", nm_ip4_address_get_prefix (addr));
+ tmp = g_strdup_printf ("%u", nm_ip_address_get_prefix (addr));
svSetValue (ifcfg, prefix_key, tmp, FALSE);
g_free (tmp);
svSetValue (ifcfg, netmask_key, NULL, FALSE);
-
- if (nm_ip4_address_get_gateway (addr)) {
- memset (buf, 0, sizeof (buf));
- ip = nm_ip4_address_get_gateway (addr);
- inet_ntop (AF_INET, (const void *) &ip, &buf[0], sizeof (buf));
- svSetValue (ifcfg, gw_key, &buf[0], FALSE);
- } else
- svSetValue (ifcfg, gw_key, NULL, FALSE);
+ svSetValue (ifcfg, gw_key, NULL, FALSE);
g_free (addr_key);
g_free (prefix_key);
@@ -1962,7 +1946,9 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
g_free (gw_key);
}
- num = nm_setting_ip4_config_get_num_dns (s_ip4);
+ svSetValue (ifcfg, "GATEWAY", nm_setting_ip_config_get_gateway (s_ip4), FALSE);
+
+ num = nm_setting_ip_config_get_num_dns (s_ip4);
for (i = 0; i < 254; i++) {
const char *dns;
@@ -1971,19 +1957,19 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
if (i >= num)
svSetValue (ifcfg, addr_key, NULL, FALSE);
else {
- dns = nm_setting_ip4_config_get_dns (s_ip4, i);
+ dns = nm_setting_ip_config_get_dns (s_ip4, i);
svSetValue (ifcfg, addr_key, dns, FALSE);
}
g_free (addr_key);
}
- num = nm_setting_ip4_config_get_num_dns_searches (s_ip4);
+ num = nm_setting_ip_config_get_num_dns_searches (s_ip4);
if (num > 0) {
searches = g_string_new (NULL);
for (i = 0; i < num; i++) {
if (i > 0)
g_string_append_c (searches, ' ');
- g_string_append (searches, nm_setting_ip4_config_get_dns_search (s_ip4, i));
+ g_string_append (searches, nm_setting_ip_config_get_dns_search (s_ip4, i));
}
svSetValue (ifcfg, "DOMAIN", searches->str, FALSE);
g_string_free (searches, TRUE);
@@ -1992,7 +1978,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
/* DEFROUTE; remember that it has the opposite meaning from never-default */
svSetValue (ifcfg, "DEFROUTE",
- nm_setting_ip4_config_get_never_default (s_ip4) ? "no" : "yes",
+ nm_setting_ip_config_get_never_default (s_ip4) ? "no" : "yes",
FALSE);
svSetValue (ifcfg, "PEERDNS", NULL, FALSE);
@@ -2000,14 +1986,14 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
svSetValue (ifcfg, "DHCP_CLIENT_ID", NULL, FALSE);
if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) {
svSetValue (ifcfg, "PEERDNS",
- nm_setting_ip4_config_get_ignore_auto_dns (s_ip4) ? "no" : "yes",
+ nm_setting_ip_config_get_ignore_auto_dns (s_ip4) ? "no" : "yes",
FALSE);
svSetValue (ifcfg, "PEERROUTES",
- nm_setting_ip4_config_get_ignore_auto_routes (s_ip4) ? "no" : "yes",
+ nm_setting_ip_config_get_ignore_auto_routes (s_ip4) ? "no" : "yes",
FALSE);
- value = nm_setting_ip4_config_get_dhcp_hostname (s_ip4);
+ value = nm_setting_ip_config_get_dhcp_hostname (s_ip4);
if (value)
svSetValue (ifcfg, "DHCP_HOSTNAME", value, FALSE);
@@ -2015,16 +2001,16 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
* in that case, because it is NM-specific variable
*/
svSetValue (ifcfg, "DHCP_SEND_HOSTNAME",
- nm_setting_ip4_config_get_dhcp_send_hostname (s_ip4) ? NULL : "no",
+ nm_setting_ip_config_get_dhcp_send_hostname (s_ip4) ? NULL : "no",
FALSE);
- value = nm_setting_ip4_config_get_dhcp_client_id (s_ip4);
+ value = nm_setting_ip4_config_get_dhcp_client_id (NM_SETTING_IP4_CONFIG (s_ip4));
if (value)
svSetValue (ifcfg, "DHCP_CLIENT_ID", value, FALSE);
}
svSetValue (ifcfg, "IPV4_FAILURE_FATAL",
- nm_setting_ip4_config_get_may_fail (s_ip4) ? "no" : "yes",
+ nm_setting_ip_config_get_may_fail (s_ip4) ? "no" : "yes",
FALSE);
/* Static routes - route-<name> file */
@@ -2047,11 +2033,12 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
}
g_free (route_path);
- num = nm_setting_ip4_config_get_num_routes (s_ip4);
+ num = nm_setting_ip_config_get_num_routes (s_ip4);
for (i = 0; i < 256; i++) {
char buf[INET_ADDRSTRLEN];
- NMIP4Route *route;
- guint32 ip, metric;
+ NMIPRoute *route;
+ guint32 netmask;
+ gint64 metric;
addr_key = g_strdup_printf ("ADDRESS%d", i);
netmask_key = g_strdup_printf ("NETMASK%d", i);
@@ -2064,29 +2051,23 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
svSetValue (routefile, gw_key, NULL, FALSE);
svSetValue (routefile, metric_key, NULL, FALSE);
} else {
- route = nm_setting_ip4_config_get_route (s_ip4, i);
+ route = nm_setting_ip_config_get_route (s_ip4, i);
- memset (buf, 0, sizeof (buf));
- ip = nm_ip4_route_get_dest (route);
- inet_ntop (AF_INET, (const void *) &ip, &buf[0], sizeof (buf));
- svSetValue (routefile, addr_key, &buf[0], FALSE);
+ svSetValue (routefile, addr_key, nm_ip_route_get_dest (route), FALSE);
memset (buf, 0, sizeof (buf));
- ip = nm_utils_ip4_prefix_to_netmask (nm_ip4_route_get_prefix (route));
- inet_ntop (AF_INET, (const void *) &ip, &buf[0], sizeof (buf));
+ netmask = nm_utils_ip4_prefix_to_netmask (nm_ip_route_get_prefix (route));
+ inet_ntop (AF_INET, (const void *) &netmask, &buf[0], sizeof (buf));
svSetValue (routefile, netmask_key, &buf[0], FALSE);
- memset (buf, 0, sizeof (buf));
- ip = nm_ip4_route_get_next_hop (route);
- inet_ntop (AF_INET, (const void *) &ip, &buf[0], sizeof (buf));
- svSetValue (routefile, gw_key, &buf[0], FALSE);
+ svSetValue (routefile, gw_key, nm_ip_route_get_next_hop (route), FALSE);
memset (buf, 0, sizeof (buf));
- metric = nm_ip4_route_get_metric (route);
- if (metric == 0)
+ metric = nm_ip_route_get_metric (route);
+ if (metric == -1)
svSetValue (routefile, metric_key, NULL, FALSE);
else {
- tmp = g_strdup_printf ("%u", metric);
+ tmp = g_strdup_printf ("%u", (guint32) metric);
svSetValue (routefile, metric_key, tmp, FALSE);
g_free (tmp);
}
@@ -2121,7 +2102,7 @@ out:
static void
write_ip4_aliases (NMConnection *connection, char *base_ifcfg_path)
{
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
char *base_ifcfg_dir, *base_ifcfg_name, *base_name;
int i, num, base_ifcfg_name_len, base_name_len;
GDir *dir;
@@ -2159,15 +2140,20 @@ write_ip4_aliases (NMConnection *connection, char *base_ifcfg_path)
if (!s_ip4)
return;
- num = nm_setting_ip4_config_get_num_addresses (s_ip4);
+ num = nm_setting_ip_config_get_num_addresses (s_ip4);
for (i = 0; i < num; i++) {
+ GVariant *label_var;
const char *label, *p;
- char buf[INET_ADDRSTRLEN], *path, *tmp;
- NMIP4Address *addr;
- guint32 ip;
+ char *path, *tmp;
+ NMIPAddress *addr;
shvarFile *ifcfg;
- label = _nm_setting_ip4_config_get_address_label (s_ip4, i);
+ addr = nm_setting_ip_config_get_address (s_ip4, i);
+
+ label_var = nm_ip_address_get_attribute (addr, "label");
+ if (!label_var)
+ continue;
+ label = g_variant_get_string (label_var, NULL);
if ( strncmp (label, base_name, base_name_len) != 0
|| label[base_name_len] != ':')
continue;
@@ -2185,24 +2171,13 @@ write_ip4_aliases (NMConnection *connection, char *base_ifcfg_path)
svSetValue (ifcfg, "DEVICE", label, FALSE);
- addr = nm_setting_ip4_config_get_address (s_ip4, i);
-
- memset (buf, 0, sizeof (buf));
- ip = nm_ip4_address_get_address (addr);
- inet_ntop (AF_INET, (const void *) &ip, &buf[0], sizeof (buf));
- svSetValue (ifcfg, "IPADDR", &buf[0], FALSE);
+ addr = nm_setting_ip_config_get_address (s_ip4, i);
+ svSetValue (ifcfg, "IPADDR", nm_ip_address_get_address (addr), FALSE);
- tmp = g_strdup_printf ("%u", nm_ip4_address_get_prefix (addr));
+ tmp = g_strdup_printf ("%u", nm_ip_address_get_prefix (addr));
svSetValue (ifcfg, "PREFIX", tmp, FALSE);
g_free (tmp);
- if (nm_ip4_address_get_gateway (addr)) {
- memset (buf, 0, sizeof (buf));
- ip = nm_ip4_address_get_gateway (addr);
- inet_ntop (AF_INET, (const void *) &ip, &buf[0], sizeof (buf));
- svSetValue (ifcfg, "GATEWAY", &buf[0], FALSE);
- }
-
svWriteFile (ifcfg, 0644, NULL);
svCloseFile (ifcfg);
}
@@ -2212,15 +2187,11 @@ write_ip4_aliases (NMConnection *connection, char *base_ifcfg_path)
}
static gboolean
-write_route6_file (const char *filename, NMSettingIP6Config *s_ip6, GError **error)
+write_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error)
{
- char dest[INET6_ADDRSTRLEN];
- char next_hop[INET6_ADDRSTRLEN];
char **route_items;
char *route_contents;
- NMIP6Route *route;
- const struct in6_addr *ip;
- guint32 prefix, metric;
+ NMIPRoute *route;
guint32 i, num;
gboolean success = FALSE;
@@ -2229,7 +2200,7 @@ write_route6_file (const char *filename, NMSettingIP6Config *s_ip6, GError **err
g_return_val_if_fail (error != NULL, FALSE);
g_return_val_if_fail (*error == NULL, FALSE);
- num = nm_setting_ip6_config_get_num_routes (s_ip6);
+ num = nm_setting_ip_config_get_num_routes (s_ip6);
if (num == 0) {
unlink (filename);
return TRUE;
@@ -2237,21 +2208,20 @@ write_route6_file (const char *filename, NMSettingIP6Config *s_ip6, GError **err
route_items = g_malloc0 (sizeof (char*) * (num + 1));
for (i = 0; i < num; i++) {
- route = nm_setting_ip6_config_get_route (s_ip6, i);
-
- memset (dest, 0, sizeof (dest));
- ip = nm_ip6_route_get_dest (route);
- inet_ntop (AF_INET6, (const void *) ip, &dest[0], sizeof (dest));
-
- prefix = nm_ip6_route_get_prefix (route);
+ route = nm_setting_ip_config_get_route (s_ip6, i);
- memset (next_hop, 0, sizeof (next_hop));
- ip = nm_ip6_route_get_next_hop (route);
- inet_ntop (AF_INET6, (const void *) ip, &next_hop[0], sizeof (next_hop));
-
- metric = nm_ip6_route_get_metric (route);
-
- route_items[i] = g_strdup_printf ("%s/%u via %s metric %u\n", dest, prefix, next_hop, metric);
+ if (nm_ip_route_get_metric (route) == -1) {
+ route_items[i] = g_strdup_printf ("%s/%u via %s\n",
+ nm_ip_route_get_dest (route),
+ nm_ip_route_get_prefix (route),
+ nm_ip_route_get_next_hop (route));
+ } else {
+ route_items[i] = g_strdup_printf ("%s/%u via %s metric %u\n",
+ nm_ip_route_get_dest (route),
+ nm_ip_route_get_prefix (route),
+ nm_ip_route_get_next_hop (route),
+ (guint32) nm_ip_route_get_metric (route));
+ }
}
route_items[num] = NULL;
route_contents = g_strjoinv (NULL, route_items);
@@ -2273,16 +2243,13 @@ error:
static gboolean
write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
{
- NMSettingIP6Config *s_ip6;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip6;
+ NMSettingIPConfig *s_ip4;
const char *value;
- char *addr_key, *prefix;
+ char *addr_key;
guint32 i, num, num4;
GString *searches;
- char buf[INET6_ADDRSTRLEN];
- char ipv6_defaultgw[INET6_ADDRSTRLEN];
- NMIP6Address *addr;
- const struct in6_addr *ip;
+ NMIPAddress *addr;
const char *dns;
GString *ip_str1, *ip_str2, *ip_ptr;
char *route6_path;
@@ -2300,7 +2267,7 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
return TRUE;
}
- value = nm_setting_ip6_config_get_method (s_ip6);
+ value = nm_setting_ip_config_get_method (s_ip6);
g_assert (value);
if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) {
svSetValue (ifcfg, "IPV6INIT", "no", FALSE);
@@ -2315,7 +2282,7 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
svSetValue (ifcfg, "IPV6INIT", "yes", FALSE);
svSetValue (ifcfg, "IPV6_AUTOCONF", "no", FALSE);
svSetValue (ifcfg, "DHCPV6C", "yes", FALSE);
- hostname = nm_setting_ip6_config_get_dhcp_hostname (s_ip6);
+ hostname = nm_setting_ip_config_get_dhcp_hostname (s_ip6);
if (hostname)
svSetValue (ifcfg, "DHCP_HOSTNAME", hostname, FALSE);
} else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) {
@@ -2333,59 +2300,47 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
}
/* Write out IP addresses */
- num = nm_setting_ip6_config_get_num_addresses (s_ip6);
+ num = nm_setting_ip_config_get_num_addresses (s_ip6);
ip_str1 = g_string_new (NULL);
ip_str2 = g_string_new (NULL);
- ipv6_defaultgw[0] = 0;
for (i = 0; i < num; i++) {
if (i == 0)
ip_ptr = ip_str1;
else
ip_ptr = ip_str2;
- addr = nm_setting_ip6_config_get_address (s_ip6, i);
- ip = nm_ip6_address_get_address (addr);
- prefix = g_strdup_printf ("%u", nm_ip6_address_get_prefix (addr));
- memset (buf, 0, sizeof (buf));
- inet_ntop (AF_INET6, (const void *) ip, buf, sizeof (buf));
+ addr = nm_setting_ip_config_get_address (s_ip6, i);
+
if (i > 1)
g_string_append_c (ip_ptr, ' '); /* separate addresses in IPV6ADDR_SECONDARIES */
- g_string_append (ip_ptr, buf);
- g_string_append_c (ip_ptr, '/');
- g_string_append (ip_ptr, prefix);
- g_free (prefix);
-
- /* We only support gateway for the first IP address for now */
- if (i == 0) {
- ip = nm_ip6_address_get_gateway (addr);
- if (!IN6_IS_ADDR_UNSPECIFIED (ip))
- inet_ntop (AF_INET6, ip, ipv6_defaultgw, sizeof (ipv6_defaultgw));
- }
+ g_string_append_printf (ip_ptr, "%s/%u",
+ nm_ip_address_get_address (addr),
+ nm_ip_address_get_prefix (addr));
}
svSetValue (ifcfg, "IPV6ADDR", ip_str1->str, FALSE);
svSetValue (ifcfg, "IPV6ADDR_SECONDARIES", ip_str2->str, FALSE);
- svSetValue (ifcfg, "IPV6_DEFAULTGW", ipv6_defaultgw, FALSE);
+ svSetValue (ifcfg, "IPV6_DEFAULTGW", nm_setting_ip_config_get_gateway (s_ip6), FALSE);
g_string_free (ip_str1, TRUE);
g_string_free (ip_str2, TRUE);
/* Write out DNS - 'DNS' key is used both for IPv4 and IPv6 */
s_ip4 = nm_connection_get_setting_ip4_config (connection);
- num4 = s_ip4 ? nm_setting_ip4_config_get_num_dns (s_ip4) : 0; /* from where to start with IPv6 entries */
- num = nm_setting_ip6_config_get_num_dns (s_ip6);
+ num4 = s_ip4 ? nm_setting_ip_config_get_num_dns (s_ip4) : 0; /* from where to start with IPv6 entries */
+ num = nm_setting_ip_config_get_num_dns (s_ip6);
for (i = 0; i < 254; i++) {
addr_key = g_strdup_printf ("DNS%d", i + num4 + 1);
if (i >= num)
svSetValue (ifcfg, addr_key, NULL, FALSE);
else {
- dns = nm_setting_ip6_config_get_dns (s_ip6, i);
+ dns = nm_setting_ip_config_get_dns (s_ip6, i);
svSetValue (ifcfg, addr_key, dns, FALSE);
}
g_free (addr_key);
}
/* Write out DNS domains - 'DOMAIN' key is shared for both IPv4 and IPv6 domains */
- num = nm_setting_ip6_config_get_num_dns_searches (s_ip6);
+ num = nm_setting_ip_config_get_num_dns_searches (s_ip6);
if (num > 0) {
char *ip4_domains;
ip4_domains = svGetValue (ifcfg, "DOMAIN", FALSE);
@@ -2393,7 +2348,7 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
for (i = 0; i < num; i++) {
if (searches->len > 0)
g_string_append_c (searches, ' ');
- g_string_append (searches, nm_setting_ip6_config_get_dns_search (s_ip6, i));
+ g_string_append (searches, nm_setting_ip_config_get_dns_search (s_ip6, i));
}
svSetValue (ifcfg, "DOMAIN", searches->str, FALSE);
g_string_free (searches, TRUE);
@@ -2402,7 +2357,7 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
/* handle IPV6_DEFROUTE */
/* IPV6_DEFROUTE has the opposite meaning from 'never-default' */
- if (nm_setting_ip6_config_get_never_default(s_ip6))
+ if (nm_setting_ip_config_get_never_default(s_ip6))
svSetValue (ifcfg, "IPV6_DEFROUTE", "no", FALSE);
else
svSetValue (ifcfg, "IPV6_DEFROUTE", "yes", FALSE);
@@ -2411,22 +2366,22 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
svSetValue (ifcfg, "IPV6_PEERROUTES", NULL, FALSE);
if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) {
svSetValue (ifcfg, "IPV6_PEERDNS",
- nm_setting_ip6_config_get_ignore_auto_dns (s_ip6) ? "no" : "yes",
+ nm_setting_ip_config_get_ignore_auto_dns (s_ip6) ? "no" : "yes",
FALSE);
svSetValue (ifcfg, "IPV6_PEERROUTES",
- nm_setting_ip6_config_get_ignore_auto_routes (s_ip6) ? "no" : "yes",
+ nm_setting_ip_config_get_ignore_auto_routes (s_ip6) ? "no" : "yes",
FALSE);
}
svSetValue (ifcfg, "IPV6_FAILURE_FATAL",
- nm_setting_ip6_config_get_may_fail (s_ip6) ? "no" : "yes",
+ nm_setting_ip_config_get_may_fail (s_ip6) ? "no" : "yes",
FALSE);
/* IPv6 Privacy Extensions */
svSetValue (ifcfg, "IPV6_PRIVACY", NULL, FALSE);
svSetValue (ifcfg, "IPV6_PRIVACY_PREFER_PUBLIC_IP", NULL, FALSE);
- switch (nm_setting_ip6_config_get_ip6_privacy (s_ip6)){
+ switch (nm_setting_ip6_config_get_ip6_privacy (NM_SETTING_IP6_CONFIG (s_ip6))){
case NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED:
svSetValue (ifcfg, "IPV6_PRIVACY", "no", FALSE);
break;
diff --git a/src/settings/plugins/ifnet/connection_parser.c b/src/settings/plugins/ifnet/connection_parser.c
index f76876f11f..651cd8ea71 100644
--- a/src/settings/plugins/ifnet/connection_parser.c
+++ b/src/settings/plugins/ifnet/connection_parser.c
@@ -30,6 +30,7 @@
#include "nm-system-config-interface.h"
#include "nm-logging.h"
#include "nm-core-internal.h"
+#include "NetworkManagerUtils.h"
#include "net_utils.h"
#include "wpa_parser.h"
@@ -42,8 +43,16 @@ connection_id_from_ifnet_name (const char *conn_name)
int name_len = strlen (conn_name);
/* Convert a hex-encoded conn_name (only used for wifi SSIDs) to human-readable one */
- if ((name_len > 2) && (g_str_has_prefix (conn_name, "0x")))
- return nm_utils_hexstr2bin (conn_name + 2, name_len - 2);
+ if ((name_len > 2) && (g_str_has_prefix (conn_name, "0x"))) {
+ GBytes *bytes = nm_utils_hexstr2bin (conn_name);
+ char *buf;
+
+ if (bytes) {
+ buf = g_strndup (g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes));
+ g_bytes_unref (bytes);
+ return buf;
+ }
+ }
return g_strdup (conn_name);
}
@@ -544,25 +553,25 @@ make_wired_connection_setting (NMConnection *connection,
nm_connection_add_setting (connection, NM_SETTING (s_wired));
}
-/* add NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME,
- * NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID in future*/
+/* add NM_SETTING_IP_CONFIG_DHCP_HOSTNAME,
+ * NM_SETTING_IP_CONFIG_DHCP_CLIENT_ID in future*/
static void
make_ip4_setting (NMConnection *connection,
const char *conn_name,
GError **error)
{
- NMSettingIP4Config *ip4_setting =
- NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
+ NMSettingIPConfig *ip4_setting =
+ NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ());
const char *value, *method = NULL;
gboolean is_static_block = is_static_ip4 (conn_name);
ip_block *iblock = NULL;
/* set dhcp options (dhcp_xxx) */
value = ifnet_get_data (conn_name, "dhcp");
- g_object_set (ip4_setting, NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, value
+ g_object_set (ip4_setting, NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, value
&& strstr (value, "nodns") ? TRUE : FALSE,
- NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES, value
+ NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, value
&& strstr (value, "nogateway") ? TRUE : FALSE, NULL);
if (!is_static_block) {
@@ -575,21 +584,21 @@ make_ip4_setting (NMConnection *connection,
}
if (strstr (method, "dhcp"))
g_object_set (ip4_setting,
- NM_SETTING_IP4_CONFIG_METHOD,
+ NM_SETTING_IP_CONFIG_METHOD,
NM_SETTING_IP4_CONFIG_METHOD_AUTO,
- NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, FALSE, NULL);
+ NM_SETTING_IP_CONFIG_NEVER_DEFAULT, FALSE, NULL);
else if (strstr (method, "autoip")) {
g_object_set (ip4_setting,
- NM_SETTING_IP4_CONFIG_METHOD,
+ NM_SETTING_IP_CONFIG_METHOD,
NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL,
- NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, FALSE, NULL);
+ NM_SETTING_IP_CONFIG_NEVER_DEFAULT, FALSE, NULL);
nm_connection_add_setting (connection, NM_SETTING (ip4_setting));
return;
} else if (strstr (method, "shared")) {
g_object_set (ip4_setting,
- NM_SETTING_IP4_CONFIG_METHOD,
+ NM_SETTING_IP_CONFIG_METHOD,
NM_SETTING_IP4_CONFIG_METHOD_SHARED,
- NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, FALSE, NULL);
+ NM_SETTING_IP_CONFIG_NEVER_DEFAULT, FALSE, NULL);
nm_connection_add_setting (connection, NM_SETTING (ip4_setting));
return;
} else {
@@ -611,29 +620,32 @@ make_ip4_setting (NMConnection *connection,
/************** add all ip settings to the connection**********/
while (iblock) {
ip_block *current_iblock;
- NMIP4Address *ip4_addr = nm_ip4_address_new ();
-
- nm_ip4_address_set_address (ip4_addr, iblock->ip);
- nm_ip4_address_set_prefix (ip4_addr,
- nm_utils_ip4_netmask_to_prefix
- (iblock->netmask));
- /* currently all the IPs has the same gateway */
- nm_ip4_address_set_gateway (ip4_addr, iblock->gateway);
- if (iblock->gateway)
+ NMIPAddress *ip4_addr;
+ GError *local = NULL;
+
+ ip4_addr = nm_ip_address_new (AF_INET, iblock->ip, iblock->prefix, &local);
+ if (iblock->next_hop)
g_object_set (ip4_setting,
- NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES,
+ NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES,
TRUE, NULL);
- if (!nm_setting_ip4_config_add_address (ip4_setting, ip4_addr))
- nm_log_warn (LOGD_SETTINGS, "ignoring duplicate IP4 address");
- nm_ip4_address_unref (ip4_addr);
+
+ if (ip4_addr) {
+ if (!nm_setting_ip_config_add_address (ip4_setting, ip4_addr))
+ nm_log_warn (LOGD_SETTINGS, "ignoring duplicate IP4 address");
+ nm_ip_address_unref (ip4_addr);
+ } else {
+ nm_log_warn (LOGD_SETTINGS, " ignoring invalid address entry: %s", local->message);
+ g_clear_error (&local);
+ }
+
current_iblock = iblock;
iblock = iblock->next;
destroy_ip_block (current_iblock);
}
g_object_set (ip4_setting,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
- NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, !has_default_ip4_route (conn_name),
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_NEVER_DEFAULT, !has_default_ip4_route (conn_name),
NULL);
}
@@ -644,7 +656,7 @@ make_ip4_setting (NMConnection *connection,
get_dhcp_hostname_and_client_id (&dhcp_hostname, &client_id);
if (dhcp_hostname) {
g_object_set (ip4_setting,
- NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME,
+ NM_SETTING_IP_CONFIG_DHCP_HOSTNAME,
dhcp_hostname, NULL);
nm_log_info (LOGD_SETTINGS, "DHCP hostname: %s", dhcp_hostname);
g_free (dhcp_hostname);
@@ -675,7 +687,7 @@ make_ip4_setting (NMConnection *connection,
for (item = searches; *item; item++) {
if (strlen (*item)) {
- if (!nm_setting_ip4_config_add_dns_search (ip4_setting, *item))
+ if (!nm_setting_ip_config_add_dns_search (ip4_setting, *item))
nm_log_warn (LOGD_SETTINGS, " duplicate DNS domain '%s'", *item);
}
}
@@ -689,34 +701,34 @@ make_ip4_setting (NMConnection *connection,
ip_block *current_iblock = iblock;
const char *metric_str;
char *stripped;
- long int metric;
- NMIP4Route *route = nm_ip4_route_new ();
-
- nm_ip4_route_set_dest (route, iblock->ip);
- nm_ip4_route_set_next_hop (route, iblock->gateway);
- nm_ip4_route_set_prefix (route,
- nm_utils_ip4_netmask_to_prefix
- (iblock->netmask));
+ gint64 metric;
+ NMIPRoute *route;
+ GError *local = NULL;
+
if ((metric_str = ifnet_get_data (conn_name, "metric")) != NULL) {
- metric = strtol (metric_str, NULL, 10);
- nm_ip4_route_set_metric (route, (guint32) metric);
+ metric = nm_utils_ascii_str_to_int64 (metric_str, 10, 0, G_MAXUINT32, -1);
} else {
metric_str = ifnet_get_global_data ("metric");
if (metric_str) {
stripped = g_strdup (metric_str);
strip_string (stripped, '"');
- metric = strtol (metric_str, NULL, 10);
- nm_ip4_route_set_metric (route,
- (guint32) metric);
+ metric = nm_utils_ascii_str_to_int64 (metric_str, 10, 0, G_MAXUINT32, -1);
g_free (stripped);
- }
+ } else
+ metric = -1;
}
- if (!nm_setting_ip4_config_add_route (ip4_setting, route))
- nm_log_warn (LOGD_SETTINGS, "duplicate IP4 route");
- nm_log_info (LOGD_SETTINGS, "new IP4 route:%d\n", iblock->ip);
-
- nm_ip4_route_unref (route);
+ route = nm_ip_route_new (AF_INET, iblock->ip, iblock->prefix, iblock->next_hop, metric, &local);
+ if (route) {
+ if (nm_setting_ip_config_add_route (ip4_setting, route))
+ nm_log_info (LOGD_SETTINGS, "new IP4 route:%s\n", iblock->ip);
+ else
+ nm_log_warn (LOGD_SETTINGS, "duplicate IP4 route");
+ nm_ip_route_unref (route);
+ } else {
+ nm_log_warn (LOGD_SETTINGS, " ignoring invalid route entry: %s", local->message);
+ g_clear_error (&local);
+ }
current_iblock = iblock;
iblock = iblock->next;
@@ -732,17 +744,17 @@ make_ip6_setting (NMConnection *connection,
const char *conn_name,
GError **error)
{
- NMSettingIP6Config *s_ip6 = NULL;
+ NMSettingIPConfig *s_ip6 = NULL;
gboolean is_static_block = is_static_ip6 (conn_name);
// used to disable IPv6
gboolean ipv6_enabled = FALSE;
gchar *method = NM_SETTING_IP6_CONFIG_METHOD_MANUAL;
const char *value;
- ip6_block *iblock;
+ ip_block *iblock;
gboolean never_default = !has_default_ip6_route (conn_name);
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
value = ifnet_get_data (conn_name, "enable_ipv6");
if (value && is_true (value))
@@ -752,7 +764,7 @@ make_ip6_setting (NMConnection *connection,
// Currently only Manual and DHCP are supported
if (!ipv6_enabled) {
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD,
+ NM_SETTING_IP_CONFIG_METHOD,
NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL);
goto done;
} else if (!is_static_block) {
@@ -769,14 +781,14 @@ make_ip6_setting (NMConnection *connection,
nm_log_info (LOGD_SETTINGS, "IPv6 for %s enabled, using %s", conn_name, method);
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, method,
- NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS, FALSE,
- NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES, FALSE,
- NM_SETTING_IP6_CONFIG_NEVER_DEFAULT, never_default, NULL);
+ NM_SETTING_IP_CONFIG_METHOD, method,
+ NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, FALSE,
+ NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, FALSE,
+ NM_SETTING_IP_CONFIG_NEVER_DEFAULT, never_default, NULL);
/* Make manual settings */
if (!strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) {
- ip6_block *current_iblock;
+ ip_block *current_iblock;
iblock = convert_ip6_config_block (conn_name);
if (!iblock) {
@@ -787,73 +799,80 @@ make_ip6_setting (NMConnection *connection,
}
/* add all IPv6 addresses */
while (iblock) {
- NMIP6Address *ip6_addr = nm_ip6_address_new ();
-
- nm_ip6_address_set_address (ip6_addr, iblock->ip);
- nm_ip6_address_set_prefix (ip6_addr, iblock->prefix);
- if (nm_setting_ip6_config_add_address (s_ip6, ip6_addr)) {
- nm_log_info (LOGD_SETTINGS, "ipv6 addresses count: %d",
- nm_setting_ip6_config_get_num_addresses (s_ip6));
+ NMIPAddress *ip6_addr;
+ GError *local = NULL;
+
+ ip6_addr = nm_ip_address_new (AF_INET6, iblock->ip, iblock->prefix, &local);
+ if (ip6_addr) {
+ if (nm_setting_ip_config_add_address (s_ip6, ip6_addr)) {
+ nm_log_info (LOGD_SETTINGS, "ipv6 addresses count: %d",
+ nm_setting_ip_config_get_num_addresses (s_ip6));
+ } else {
+ nm_log_warn (LOGD_SETTINGS, "ignoring duplicate IP6 address");
+ }
+ nm_ip_address_unref (ip6_addr);
} else {
- nm_log_warn (LOGD_SETTINGS, "ignoring duplicate IP4 address");
+ nm_log_warn (LOGD_SETTINGS, " ignoring invalid address entry: %s", local->message);
+ g_clear_error (&local);
}
- nm_ip6_address_unref (ip6_addr);
+
current_iblock = iblock;
iblock = iblock->next;
- destroy_ip6_block (current_iblock);
+ destroy_ip_block (current_iblock);
}
} else if (!strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) {
/* - autoconf or DHCPv6 stuff goes here */
}
- // DNS Servers, set NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS TRUE here
+ // DNS Servers, set NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS TRUE here
set_ip6_dns_servers (s_ip6, conn_name);
- /* DNS searches ('DOMAIN' key) are read by make_ip4_setting() and included in NMSettingIP4Config */
+ /* DNS searches ('DOMAIN' key) are read by make_ip4_setting() and included in NMSettingIPConfig */
// Add routes
iblock = convert_ip6_routes_block (conn_name);
if (iblock)
- g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES,
+ g_object_set (s_ip6, NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES,
TRUE, NULL);
/* Add all IPv6 routes */
while (iblock) {
- ip6_block *current_iblock = iblock;
+ ip_block *current_iblock = iblock;
const char *metric_str;
char *stripped;
- long int metric = 1;
- NMIP6Route *route = nm_ip6_route_new ();
+ gint64 metric;
+ NMIPRoute *route;
+ GError *local = NULL;
- nm_ip6_route_set_dest (route, iblock->ip);
- nm_ip6_route_set_next_hop (route, iblock->next_hop);
- nm_ip6_route_set_prefix (route, iblock->prefix);
/* metric is not per routes configuration right now
* global metric is also supported (metric="x") */
- if ((metric_str = ifnet_get_data (conn_name, "metric")) != NULL) {
- metric = strtol (metric_str, NULL, 10);
- nm_ip6_route_set_metric (route, (guint32) metric);
- } else {
+ if ((metric_str = ifnet_get_data (conn_name, "metric")) != NULL)
+ metric = nm_utils_ascii_str_to_int64 (metric_str, 10, 0, G_MAXUINT32, -1);
+ else {
metric_str = ifnet_get_global_data ("metric");
if (metric_str) {
stripped = g_strdup (metric_str);
strip_string (stripped, '"');
- metric = strtol (metric_str, NULL, 10);
- nm_ip6_route_set_metric (route,
- (guint32) metric);
+ metric = nm_utils_ascii_str_to_int64 (metric_str, 10, 0, G_MAXUINT32, -1);
g_free (stripped);
} else
- nm_ip6_route_set_metric (route, (guint32) 1);
+ metric = 1;
}
- if (nm_setting_ip6_config_add_route (s_ip6, route))
- nm_log_info (LOGD_SETTINGS, " new IP6 route");
- else
- nm_log_warn (LOGD_SETTINGS, " duplicate IP6 route");
- nm_ip6_route_unref (route);
+ route = nm_ip_route_new (AF_INET6, iblock->ip, iblock->prefix, iblock->next_hop, metric, &local);
+ if (route) {
+ if (nm_setting_ip_config_add_route (s_ip6, route))
+ nm_log_info (LOGD_SETTINGS, " new IP6 route");
+ else
+ nm_log_warn (LOGD_SETTINGS, " duplicate IP6 route");
+ nm_ip_route_unref (route);
+ } else {
+ nm_log_warn (LOGD_SETTINGS, " ignoring invalid route entry: %s", local->message);
+ g_clear_error (&local);
+ }
current_iblock = iblock;
iblock = iblock->next;
- destroy_ip6_block (current_iblock);
+ destroy_ip_block (current_iblock);
}
done:
@@ -871,7 +890,6 @@ make_wireless_connection_setting (const char *conn_name,
NMSetting8021x **s_8021x,
GError **error)
{
- GBytes *bytes;
const char *mac = NULL;
NMSettingWireless *wireless_setting = NULL;
gboolean adhoc = FALSE;
@@ -902,9 +920,8 @@ make_wireless_connection_setting (const char *conn_name,
/* handle ssid (hex and ascii) */
if (conn_name) {
+ GBytes *bytes;
gsize ssid_len = 0, value_len = strlen (conn_name);
- const char *p;
- char *tmp, *converted = NULL;
ssid_len = value_len;
if ((value_len > 2) && (g_str_has_prefix (conn_name, "0x"))) {
@@ -915,32 +932,27 @@ make_wireless_connection_setting (const char *conn_name,
conn_name);
goto error;
}
- // ignore "0x"
- p = conn_name + 2;
- if (!is_hex (p)) {
+
+ bytes = nm_utils_hexstr2bin (conn_name);
+ if (!bytes) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
- "Invalid SSID '%s' character (looks like hex SSID but '%c' isn't a hex digit)",
- conn_name, *p);
+ "Invalid SSID '%s' (looks like hex SSID but isn't)",
+ conn_name);
goto error;
-
}
- tmp = nm_utils_hexstr2bin (p, value_len - 2);
- ssid_len = (value_len - 2) / 2;
- converted = g_malloc0 (ssid_len + 1);
- memcpy (converted, tmp, ssid_len);
- g_free (tmp);
- }
+ } else
+ bytes = g_bytes_new (conn_name, value_len);
+ ssid_len = g_bytes_get_size (bytes);
if (ssid_len > 32 || ssid_len == 0) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid SSID '%s' (size %zu not between 1 and 32 inclusive)",
conn_name, ssid_len);
goto error;
}
- bytes = g_bytes_new (converted ? converted : conn_name, ssid_len);
+
g_object_set (wireless_setting, NM_SETTING_WIRELESS_SSID, bytes, NULL);
g_bytes_unref (bytes);
- g_free (converted);
} else {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Missing SSID");
@@ -1084,7 +1096,7 @@ add_one_wep_key (const char *ssid,
}
- converted = nm_utils_bin2hexstr (tmp, strlen (tmp), strlen (tmp) * 2);
+ converted = nm_utils_bin2hexstr (tmp, strlen (tmp), -1);
g_free (tmp);
} else {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
@@ -2359,15 +2371,13 @@ write_wired_setting (NMConnection *connection,
static gboolean
write_ip4_setting (NMConnection *connection, const char *conn_name, GError **error)
{
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
const char *value;
- char *tmp;
guint32 i, num;
GString *searches;
GString *ips;
GString *routes;
GString *dns;
- gboolean has_def_route = FALSE;
gboolean success = FALSE;
s_ip4 = nm_connection_get_setting_ip4_config (connection);
@@ -2379,42 +2389,27 @@ write_ip4_setting (NMConnection *connection, const char *conn_name, GError **err
}
routes = g_string_new (NULL);
- value = nm_setting_ip4_config_get_method (s_ip4);
+ value = nm_setting_ip_config_get_method (s_ip4);
g_assert (value);
if (!strcmp (value, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) {
- num = nm_setting_ip4_config_get_num_addresses (s_ip4);
+ num = nm_setting_ip_config_get_num_addresses (s_ip4);
ips = g_string_new (NULL);
/* IPv4 addresses */
for (i = 0; i < num; i++) {
- char buf[INET_ADDRSTRLEN + 1];
- NMIP4Address *addr;
- guint32 ip;
-
- addr = nm_setting_ip4_config_get_address (s_ip4, i);
-
- memset (buf, 0, sizeof (buf));
- ip = nm_ip4_address_get_address (addr);
- inet_ntop (AF_INET, (const void *) &ip, &buf[0],
- sizeof (buf));
- g_string_append_printf (ips, "\"%s", &buf[0]);
-
- tmp =
- g_strdup_printf ("%u",
- nm_ip4_address_get_prefix (addr));
- g_string_append_printf (ips, "/%s\" ", tmp);
- g_free (tmp);
+ NMIPAddress *addr;
+
+ addr = nm_setting_ip_config_get_address (s_ip4, i);
+
+ g_string_append_printf (ips, "\"%s/%u",
+ nm_ip_address_get_address (addr),
+ nm_ip_address_get_prefix (addr));
/* only the first gateway will be written */
- if (!has_def_route && nm_ip4_address_get_gateway (addr)) {
- memset (buf, 0, sizeof (buf));
- ip = nm_ip4_address_get_gateway (addr);
- inet_ntop (AF_INET, (const void *) &ip, &buf[0],
- sizeof (buf));
+ if (i == 0 && nm_setting_ip_config_get_gateway (s_ip4)) {
g_string_append_printf (routes,
- "\"default via %s\" ",
- &buf[0]);
- has_def_route = TRUE;
+ "\"default via %s\" ",
+ nm_setting_ip_config_get_gateway (s_ip4));
}
}
ifnet_set_data (conn_name, "config", ips->str);
@@ -2427,13 +2422,13 @@ write_ip4_setting (NMConnection *connection, const char *conn_name, GError **err
ifnet_set_data (conn_name, "config", "dhcp");
/* DNS Servers */
- num = nm_setting_ip4_config_get_num_dns (s_ip4);
+ num = nm_setting_ip_config_get_num_dns (s_ip4);
if (num > 0) {
dns = g_string_new (NULL);
for (i = 0; i < num; i++) {
const char *ip;
- ip = nm_setting_ip4_config_get_dns (s_ip4, i);
+ ip = nm_setting_ip_config_get_dns (s_ip4, i);
g_string_append_printf (dns, " %s", ip);
}
ifnet_set_data (conn_name, "dns_servers", dns->str);
@@ -2442,14 +2437,14 @@ write_ip4_setting (NMConnection *connection, const char *conn_name, GError **err
ifnet_set_data (conn_name, "dns_servers", NULL);
/* DNS Searches */
- num = nm_setting_ip4_config_get_num_dns_searches (s_ip4);
+ num = nm_setting_ip_config_get_num_dns_searches (s_ip4);
if (num > 0) {
searches = g_string_new (NULL);
for (i = 0; i < num; i++) {
if (i > 0)
g_string_append_c (searches, ' ');
g_string_append (searches,
- nm_setting_ip4_config_get_dns_search
+ nm_setting_ip_config_get_dns_search
(s_ip4, i));
}
ifnet_set_data (conn_name, "dns_search", searches->str);
@@ -2458,12 +2453,12 @@ write_ip4_setting (NMConnection *connection, const char *conn_name, GError **err
ifnet_set_data (conn_name, "dns_search", NULL);
/* FIXME Will be implemented when configuration supports it
if (!strcmp(value, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) {
- value = nm_setting_ip4_config_get_dhcp_hostname(s_ip4);
+ value = nm_setting_ip_config_get_dhcp_hostname(s_ip4);
if (value)
ifnet_set_data(conn_name, "DHCP_HOSTNAME", value,
FALSE);
- value = nm_setting_ip4_config_get_dhcp_client_id(s_ip4);
+ value = nm_setting_ip_config_get_dhcp_client_id(s_ip4);
if (value)
ifnet_set_data(conn_name, "DHCP_CLIENT_ID", value,
FALSE);
@@ -2471,32 +2466,22 @@ write_ip4_setting (NMConnection *connection, const char *conn_name, GError **err
*/
/* Static routes */
- num = nm_setting_ip4_config_get_num_routes (s_ip4);
+ num = nm_setting_ip_config_get_num_routes (s_ip4);
if (num > 0) {
for (i = 0; i < num; i++) {
- char buf[INET_ADDRSTRLEN + 1];
- NMIP4Route *route;
- guint32 ip;
-
- route = nm_setting_ip4_config_get_route (s_ip4, i);
-
- memset (buf, 0, sizeof (buf));
- ip = nm_ip4_route_get_dest (route);
- inet_ntop (AF_INET, (const void *) &ip, &buf[0],
- sizeof (buf));
- g_string_append_printf (routes, "\"%s", buf);
-
- tmp =
- g_strdup_printf ("%u",
- nm_ip4_route_get_prefix (route));
- g_string_append_printf (routes, "/%s via ", tmp);
- g_free (tmp);
+ NMIPRoute *route;
+ const char *next_hop;
- memset (buf, 0, sizeof (buf));
- ip = nm_ip4_route_get_next_hop (route);
- inet_ntop (AF_INET, (const void *) &ip, &buf[0],
- sizeof (buf));
- g_string_append_printf (routes, "%s\" ", buf);
+ route = nm_setting_ip_config_get_route (s_ip4, i);
+
+ next_hop = nm_ip_route_get_next_hop (route);
+ if (!next_hop)
+ next_hop = "0.0.0.0";
+
+ g_string_append_printf (routes, "\"%s/%u via %s\" ",
+ nm_ip_route_get_dest (route),
+ nm_ip_route_get_prefix (route),
+ next_hop);
}
}
if (routes->len > 0)
@@ -2511,19 +2496,16 @@ write_ip4_setting (NMConnection *connection, const char *conn_name, GError **err
}
static gboolean
-write_route6_file (NMSettingIP6Config *s_ip6, const char *conn_name, GError **error)
+write_route6_file (NMSettingIPConfig *s_ip6, const char *conn_name, GError **error)
{
- char dest[INET6_ADDRSTRLEN + 1];
- char next_hop[INET6_ADDRSTRLEN + 1];
- NMIP6Route *route;
- const struct in6_addr *ip;
- guint32 prefix;
+ NMIPRoute *route;
+ const char *next_hop;
guint32 i, num;
GString *routes_string;
const char *old_routes;
g_return_val_if_fail (s_ip6 != NULL, FALSE);
- num = nm_setting_ip6_config_get_num_routes (s_ip6);
+ num = nm_setting_ip_config_get_num_routes (s_ip6);
if (num == 0) {
return TRUE;
}
@@ -2533,22 +2515,16 @@ write_route6_file (NMSettingIP6Config *s_ip6, const char *conn_name, GError **er
if (old_routes)
g_string_append (routes_string, "\" ");
for (i = 0; i < num; i++) {
- route = nm_setting_ip6_config_get_route (s_ip6, i);
-
- memset (dest, 0, sizeof (dest));
- ip = nm_ip6_route_get_dest (route);
- inet_ntop (AF_INET6, (const void *) ip, &dest[0],
- sizeof (dest));
+ route = nm_setting_ip_config_get_route (s_ip6, i);
- prefix = nm_ip6_route_get_prefix (route);
-
- memset (next_hop, 0, sizeof (next_hop));
- ip = nm_ip6_route_get_next_hop (route);
- inet_ntop (AF_INET6, (const void *) ip, &next_hop[0],
- sizeof (next_hop));
+ next_hop = nm_ip_route_get_next_hop (route);
+ if (!next_hop)
+ next_hop = "::";
g_string_append_printf (routes_string, "\"%s/%u via %s\" ",
- dest, prefix, next_hop);
+ nm_ip_route_get_dest (route),
+ nm_ip_route_get_prefix (route),
+ next_hop);
}
if (num > 0)
ifnet_set_data (conn_name, "routes", routes_string->str);
@@ -2560,14 +2536,11 @@ write_route6_file (NMSettingIP6Config *s_ip6, const char *conn_name, GError **er
static gboolean
write_ip6_setting (NMConnection *connection, const char *conn_name, GError **error)
{
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip6;
const char *value;
- char *prefix;
guint32 i, num;
GString *searches;
- char buf[INET6_ADDRSTRLEN + 1];
- NMIP6Address *addr;
- const struct in6_addr *ip;
+ NMIPAddress *addr;
s_ip6 = nm_connection_get_setting_ip6_config (connection);
if (!s_ip6) {
@@ -2577,7 +2550,7 @@ write_ip6_setting (NMConnection *connection, const char *conn_name, GError **err
return FALSE;
}
- value = nm_setting_ip6_config_get_method (s_ip6);
+ value = nm_setting_ip_config_get_method (s_ip6);
g_assert (value);
if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) {
ifnet_set_data (conn_name, "enable_ipv6", "false");
@@ -2611,22 +2584,16 @@ write_ip6_setting (NMConnection *connection, const char *conn_name, GError **err
if (!config)
config = "";
- num = nm_setting_ip6_config_get_num_addresses (s_ip6);
+ num = nm_setting_ip_config_get_num_addresses (s_ip6);
/* IPv6 addresses */
ip_str = g_string_new (NULL);
for (i = 0; i < num; i++) {
- addr = nm_setting_ip6_config_get_address (s_ip6, i);
- ip = nm_ip6_address_get_address (addr);
- prefix =
- g_strdup_printf ("%u",
- nm_ip6_address_get_prefix (addr));
- memset (buf, 0, sizeof (buf));
- inet_ntop (AF_INET6, (const void *) ip, buf,
- sizeof (buf));
- g_string_append_printf (ip_str, "\"%s/", buf);
- g_string_append_printf (ip_str, "%s\" ", prefix);
- g_free (prefix);
+ addr = nm_setting_ip_config_get_address (s_ip6, i);
+
+ g_string_append_printf (ip_str, "\"%s/%u\"",
+ nm_ip_address_get_address (addr),
+ nm_ip_address_get_prefix (addr));
}
tmp = g_strdup_printf ("%s\" %s", config, ip_str->str);
ifnet_set_data (conn_name, "config", tmp);
@@ -2635,7 +2602,7 @@ write_ip6_setting (NMConnection *connection, const char *conn_name, GError **err
}
/* DNS Servers */
- num = nm_setting_ip6_config_get_num_dns (s_ip6);
+ num = nm_setting_ip_config_get_num_dns (s_ip6);
if (num > 0) {
const char *dns_servers = ifnet_get_data (conn_name, "dns_servers");
gchar *tmp;
@@ -2645,7 +2612,7 @@ write_ip6_setting (NMConnection *connection, const char *conn_name, GError **err
if (!dns_servers)
dns_servers = "";
for (i = 0; i < num; i++) {
- dns = nm_setting_ip6_config_get_dns (s_ip6, i);
+ dns = nm_setting_ip_config_get_dns (s_ip6, i);
if (!strstr (dns_servers, dns))
g_string_append_printf (dns_string, "%s ", dns);
@@ -2657,7 +2624,7 @@ write_ip6_setting (NMConnection *connection, const char *conn_name, GError **err
} else
/* DNS Searches */
- num = nm_setting_ip6_config_get_num_dns_searches (s_ip6);
+ num = nm_setting_ip_config_get_num_dns_searches (s_ip6);
if (num > 0) {
const char *ip4_domains;
@@ -2669,7 +2636,7 @@ write_ip6_setting (NMConnection *connection, const char *conn_name, GError **err
const gchar *search = NULL;
search =
- nm_setting_ip6_config_get_dns_search (s_ip6, i);
+ nm_setting_ip_config_get_dns_search (s_ip6, i);
if (search && !strstr (searches->str, search)) {
if (searches->len > 0)
g_string_append_c (searches, ' ');
@@ -2715,7 +2682,7 @@ ifnet_update_parsers_by_connection (NMConnection *connection,
GError **error)
{
NMSettingConnection *s_con;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip6;
gboolean success = FALSE;
const char *type;
gboolean no_8021x = FALSE;
diff --git a/src/settings/plugins/ifnet/net_utils.c b/src/settings/plugins/ifnet/net_utils.c
index be19134e96..c4302418ec 100644
--- a/src/settings/plugins/ifnet/net_utils.c
+++ b/src/settings/plugins/ifnet/net_utils.c
@@ -366,23 +366,21 @@ create_ip4_block (gchar * ip)
ip_mask = g_strsplit (ip, "/", 0);
length = g_strv_length (ip_mask);
- if (!inet_pton (AF_INET, ip_mask[0], &tmp_ip4_addr))
+ if (!nm_utils_ipaddr_valid (AF_INET, ip_mask[0]))
goto error;
- iblock->ip = tmp_ip4_addr;
+ iblock->ip = g_strdup (ip_mask[0]);
prefix = ip_mask[1];
i = 0;
while (i < length && g_ascii_isdigit (prefix[i]))
i++;
prefix[i] = '\0';
- iblock->netmask = nm_utils_ip4_prefix_to_netmask ((guint32)
- atoi (ip_mask
- [1]));
+ iblock->prefix = (guint32) atoi (ip_mask[1]);
} else if (strstr (ip, "netmask")) {
ip_mask = g_strsplit (ip, " ", 0);
length = g_strv_length (ip_mask);
- if (!inet_pton (AF_INET, ip_mask[0], &tmp_ip4_addr))
+ if (!nm_utils_ipaddr_valid (AF_INET, ip_mask[0]))
goto error;
- iblock->ip = tmp_ip4_addr;
+ iblock->ip = g_strdup (ip_mask[0]);
i = 0;
while (i < length && !strstr (ip_mask[++i], "netmask")) ;
while (i < length && ip_mask[++i][0] == '\0') ;
@@ -390,7 +388,7 @@ create_ip4_block (gchar * ip)
goto error;
if (!inet_pton (AF_INET, ip_mask[i], &tmp_ip4_addr))
goto error;
- iblock->netmask = tmp_ip4_addr;
+ iblock->prefix = nm_utils_ip4_netmask_to_prefix (tmp_ip4_addr);
} else {
g_slice_free (ip_block, iblock);
if (!is_ip6_address (ip) && !strstr (ip, "dhcp"))
@@ -403,26 +401,25 @@ error:
if (!is_ip6_address (ip))
nm_log_warn (LOGD_SETTINGS, "Can't handle IPv4 address: %s", ip);
g_strfreev (ip_mask);
+ g_free (iblock->ip);
g_slice_free (ip_block, iblock);
return NULL;
}
-static ip6_block *
-create_ip6_block (gchar * ip)
+static ip_block *
+create_ip_block (gchar * ip)
{
- ip6_block *iblock = g_slice_new0 (ip6_block);
+ ip_block *iblock = g_slice_new0 (ip_block);
gchar *dup_ip = g_strdup (ip);
- struct in6_addr *tmp_ip6_addr = g_slice_new0 (struct in6_addr);
gchar *prefix = NULL;
if ((prefix = strstr (dup_ip, "/")) != NULL) {
*prefix = '\0';
prefix++;
}
- if (!inet_pton (AF_INET6, dup_ip, tmp_ip6_addr)) {
+ if (!nm_utils_ipaddr_valid (AF_INET6, dup_ip))
goto error;
- }
- iblock->ip = tmp_ip6_addr;
+ iblock->ip = dup_ip;
if (prefix) {
errno = 0;
iblock->prefix = strtol (prefix, NULL, 10);
@@ -431,30 +428,26 @@ create_ip6_block (gchar * ip)
}
} else
iblock->prefix = 64;
- g_free (dup_ip);
return iblock;
error:
if (!is_ip4_address (ip))
nm_log_warn (LOGD_SETTINGS, "Can't handle IPv6 address: %s", ip);
- g_slice_free (ip6_block, iblock);
- g_slice_free (struct in6_addr, tmp_ip6_addr);
-
+ g_slice_free (ip_block, iblock);
g_free (dup_ip);
return NULL;
}
-static guint32
+static char *
get_ip4_gateway (gchar * gateway)
{
gchar *tmp, *split;
- guint32 tmp_ip4_addr;
if (!gateway)
- return 0;
+ return NULL;
tmp = find_gateway_str (gateway);
if (!tmp) {
nm_log_warn (LOGD_SETTINGS, "Couldn't obtain gateway in \"%s\"", gateway);
- return 0;
+ return NULL;
}
tmp = g_strdup (tmp);
strip_string (tmp, ' ');
@@ -464,43 +457,39 @@ get_ip4_gateway (gchar * gateway)
if ((split = strstr (tmp, "\"")) != NULL)
*split = '\0';
- if (!inet_pton (AF_INET, tmp, &tmp_ip4_addr))
+ if (!nm_utils_ipaddr_valid (AF_INET, tmp))
goto error;
- g_free (tmp);
- return tmp_ip4_addr;
+ return tmp;
error:
if (!is_ip6_address (tmp))
nm_log_warn (LOGD_SETTINGS, "Can't handle IPv4 gateway: %s", tmp);
g_free (tmp);
- return 0;
+ return NULL;
}
-static struct in6_addr *
+static char *
get_ip6_next_hop (gchar * next_hop)
{
gchar *tmp;
- struct in6_addr *tmp_ip6_addr = g_slice_new0 (struct in6_addr);
if (!next_hop)
- return 0;
+ return NULL;
tmp = find_gateway_str (next_hop);
if (!tmp) {
nm_log_warn (LOGD_SETTINGS, "Couldn't obtain next_hop in \"%s\"", next_hop);
- return 0;
+ return NULL;
}
tmp = g_strdup (tmp);
strip_string (tmp, ' ');
strip_string (tmp, '"');
g_strstrip (tmp);
- if (!inet_pton (AF_INET6, tmp, tmp_ip6_addr))
+ if (!nm_utils_ipaddr_valid (AF_INET6, tmp))
goto error;
- g_free (tmp);
- return tmp_ip6_addr;
+ return tmp;
error:
if (!is_ip4_address (tmp))
nm_log_warn (LOGD_SETTINGS, "Can't handle IPv6 next_hop: %s", tmp);
g_free (tmp);
- g_slice_free (struct in6_addr, tmp_ip6_addr);
return NULL;
}
@@ -512,7 +501,7 @@ convert_ip4_config_block (const char *conn_name)
guint length;
guint i;
gchar *ip;
- guint32 def_gateway = 0;
+ char *def_gateway = NULL;
const char *routes;
ip_block *start = NULL, *current = NULL, *iblock = NULL;
@@ -531,8 +520,8 @@ convert_ip4_config_block (const char *conn_name)
iblock = create_ip4_block (ip);
if (iblock == NULL)
continue;
- if (!iblock->gateway && def_gateway != 0)
- iblock->gateway = def_gateway;
+ if (!iblock->next_hop && def_gateway != NULL)
+ iblock->next_hop = g_strdup (def_gateway);
if (start == NULL)
start = current = iblock;
else {
@@ -541,17 +530,18 @@ convert_ip4_config_block (const char *conn_name)
}
}
g_strfreev (ipset);
+ g_free (def_gateway);
return start;
}
-ip6_block *
+ip_block *
convert_ip6_config_block (const char *conn_name)
{
gchar **ipset;
guint length;
guint i;
gchar *ip;
- ip6_block *start = NULL, *current = NULL, *iblock = NULL;
+ ip_block *start = NULL, *current = NULL, *iblock = NULL;
g_return_val_if_fail (conn_name != NULL, NULL);
ipset = split_addresses (ifnet_get_data (conn_name, "config"));
@@ -559,7 +549,7 @@ convert_ip6_config_block (const char *conn_name)
for (i = 0; i < length; i++) {
ip = ipset[i];
ip = strip_string (ip, '"');
- iblock = create_ip6_block (ip);
+ iblock = create_ip_block (ip);
if (iblock == NULL)
continue;
if (start == NULL)
@@ -595,7 +585,7 @@ convert_ip4_routes_block (const char *conn_name)
iblock = create_ip4_block (ip);
if (iblock == NULL)
continue;
- iblock->gateway = get_ip4_gateway (ip);
+ iblock->next_hop = get_ip4_gateway (ip);
if (start == NULL)
start = current = iblock;
else {
@@ -607,15 +597,14 @@ convert_ip4_routes_block (const char *conn_name)
return start;
}
-ip6_block *
+ip_block *
convert_ip6_routes_block (const char *conn_name)
{
gchar **ipset;
guint length;
guint i;
gchar *ip, *tmp_addr;
- ip6_block *start = NULL, *current = NULL, *iblock = NULL;
- struct in6_addr *tmp_ip6_addr;
+ ip_block *start = NULL, *current = NULL, *iblock = NULL;
g_return_val_if_fail (conn_name != NULL, NULL);
ipset = split_routes (ifnet_get_data (conn_name, "routes"));
@@ -629,25 +618,17 @@ convert_ip6_routes_block (const char *conn_name)
if (!is_ip6_address (tmp_addr))
continue;
else {
- tmp_ip6_addr = g_slice_new0 (struct in6_addr);
-
- if (inet_pton (AF_INET6, "::", tmp_ip6_addr)) {
- iblock = g_slice_new0 (ip6_block);
- iblock->ip = tmp_ip6_addr;
- iblock->prefix = 128;
- } else {
- g_slice_free (struct in6_addr,
- tmp_ip6_addr);
- continue;
- }
+ iblock = g_slice_new0 (ip_block);
+ iblock->ip = g_strdup ("::");
+ iblock->prefix = 128;
}
} else
- iblock = create_ip6_block (ip);
+ iblock = create_ip_block (ip);
if (iblock == NULL)
continue;
iblock->next_hop = get_ip6_next_hop (ip);
if (iblock->next_hop == NULL) {
- destroy_ip6_block (iblock);
+ destroy_ip_block (iblock);
continue;
}
if (start == NULL)
@@ -664,20 +645,13 @@ convert_ip6_routes_block (const char *conn_name)
void
destroy_ip_block (ip_block * iblock)
{
+ g_free (iblock->ip);
+ g_free (iblock->next_hop);
g_slice_free (ip_block, iblock);
}
void
-destroy_ip6_block (ip6_block * iblock)
-{
- g_slice_free (struct in6_addr, iblock->ip);
- g_slice_free (struct in6_addr, iblock->next_hop);
-
- g_slice_free (ip6_block, iblock);
-}
-
-void
-set_ip4_dns_servers (NMSettingIP4Config *s_ip4, const char *conn_name)
+set_ip4_dns_servers (NMSettingIPConfig *s_ip4, const char *conn_name)
{
const char *dns_servers;
gchar **server_list, *stripped;
@@ -694,7 +668,7 @@ set_ip4_dns_servers (NMSettingIP4Config *s_ip4, const char *conn_name)
length = g_strv_length (server_list);
if (length)
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS,
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS,
TRUE, NULL);
for (i = 0; i < length; i++) {
g_strstrip (server_list[i]);
@@ -705,14 +679,14 @@ set_ip4_dns_servers (NMSettingIP4Config *s_ip4, const char *conn_name)
nm_log_warn (LOGD_SETTINGS, "ignored dns: %s\n", server_list[i]);
continue;
}
- if (!nm_setting_ip4_config_add_dns (s_ip4, server_list[i]))
+ if (!nm_setting_ip_config_add_dns (s_ip4, server_list[i]))
nm_log_warn (LOGD_SETTINGS, "warning: duplicate DNS server %s", server_list[i]);
}
g_strfreev (server_list);
}
void
-set_ip6_dns_servers (NMSettingIP6Config *s_ip6, const char *conn_name)
+set_ip6_dns_servers (NMSettingIPConfig *s_ip6, const char *conn_name)
{
const char *dns_servers;
gchar **server_list, *stripped;
@@ -730,7 +704,7 @@ set_ip6_dns_servers (NMSettingIP6Config *s_ip6, const char *conn_name)
length = g_strv_length (server_list);
if (length)
- g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS,
+ g_object_set (s_ip6, NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS,
TRUE, NULL);
for (i = 0; i < length; i++) {
g_strstrip (server_list[i]);
@@ -741,7 +715,7 @@ set_ip6_dns_servers (NMSettingIP6Config *s_ip6, const char *conn_name)
nm_log_warn (LOGD_SETTINGS, "ignored dns: %s\n", server_list[i]);
continue;
}
- if (!nm_setting_ip6_config_add_dns (s_ip6, server_list[i]))
+ if (!nm_setting_ip_config_add_dns (s_ip6, server_list[i]))
nm_log_warn (LOGD_SETTINGS, "warning: duplicate DNS server %s", server_list[i]);
}
g_strfreev (server_list);
diff --git a/src/settings/plugins/ifnet/net_utils.h b/src/settings/plugins/ifnet/net_utils.h
index cee71d57e5..d58e7ec616 100644
--- a/src/settings/plugins/ifnet/net_utils.h
+++ b/src/settings/plugins/ifnet/net_utils.h
@@ -31,19 +31,12 @@
#define has_default_ip6_route(conn_name) has_default_route((conn_name), &is_ip6_address)
typedef struct _ip_block {
- guint32 ip;
- guint32 netmask;
- guint32 gateway;
+ char *ip;
+ guint32 prefix;
+ char *next_hop;
struct _ip_block *next;
} ip_block;
-typedef struct _ip6_block {
- struct in6_addr *ip;
- long int prefix;
- struct in6_addr *next_hop;
- struct _ip6_block *next;
-} ip6_block;
-
gchar *read_hostname (const char *path);
gboolean write_hostname (const char *path, const char *hostname);
gboolean is_static_ip4 (const char *conn_name);
@@ -55,14 +48,13 @@ gboolean has_default_route (const char *conn_name, gboolean (*check_fn) (const c
gboolean reload_parsers (void);
ip_block *convert_ip4_config_block (const char *conn_name);
-ip6_block *convert_ip6_config_block (const char *conn_name);
+ip_block *convert_ip6_config_block (const char *conn_name);
ip_block *convert_ip4_routes_block (const char *conn_name);
-ip6_block *convert_ip6_routes_block (const char *conn_name);
+ip_block *convert_ip6_routes_block (const char *conn_name);
void destroy_ip_block (ip_block * iblock);
-void destroy_ip6_block (ip6_block * iblock);
-void set_ip4_dns_servers (NMSettingIP4Config * s_ip4, const char *conn_name);
-void set_ip6_dns_servers (NMSettingIP6Config * s_ip6, const char *conn_name);
+void set_ip4_dns_servers (NMSettingIPConfig * s_ip4, const char *conn_name);
+void set_ip6_dns_servers (NMSettingIPConfig * s_ip6, const char *conn_name);
gchar *strip_string (gchar *str, gchar t);
gboolean is_managed (const char *conn_name);
diff --git a/src/settings/plugins/ifnet/tests/test_all.c b/src/settings/plugins/ifnet/tests/test_all.c
index 163cf6ede3..ed44a01cf8 100644
--- a/src/settings/plugins/ifnet/tests/test_all.c
+++ b/src/settings/plugins/ifnet/tests/test_all.c
@@ -160,25 +160,14 @@ test_is_ip6_address (void)
}
static void
-check_ip_block (ip_block * iblock, gchar * ip, gchar * netmask, gchar * gateway)
+check_ip_block (ip_block * iblock, gchar * ip, guint32 prefix, gchar * gateway)
{
- char *str;
- guint32 tmp_ip4_addr;
-
- str = malloc (INET_ADDRSTRLEN);
- tmp_ip4_addr = iblock->ip;
- inet_ntop (AF_INET, &tmp_ip4_addr, str, INET_ADDRSTRLEN);
- ASSERT (strcmp (ip, str) == 0, "check ip",
- "ip expected:%s, find:%s", ip, str);
- tmp_ip4_addr = iblock->netmask;
- inet_ntop (AF_INET, &tmp_ip4_addr, str, INET_ADDRSTRLEN);
- ASSERT (strcmp (netmask, str) == 0, "check netmask",
- "netmask expected:%s, find:%s", netmask, str);
- tmp_ip4_addr = iblock->gateway;
- inet_ntop (AF_INET, &tmp_ip4_addr, str, INET_ADDRSTRLEN);
- ASSERT (strcmp (gateway, str) == 0, "check gateway",
- "gateway expected:%s, find:%s", gateway, str);
- free (str);
+ ASSERT (strcmp (ip, iblock->ip) == 0, "check ip",
+ "ip expected:%s, find:%s", ip, iblock->ip);
+ ASSERT (prefix == iblock->prefix, "check netmask",
+ "prefix expected:%d, find:%d", prefix, iblock->prefix);
+ ASSERT (g_strcmp0 (gateway, iblock->next_hop) == 0, "check gateway",
+ "gateway expected:%s, find:%s", gateway, iblock->next_hop);
}
static void
@@ -189,14 +178,12 @@ test_convert_ipv4_config_block (void)
ASSERT (iblock != NULL, "convert ipv4 block",
"block eth0 should not be NULL");
- check_ip_block (iblock, "202.117.16.121", "255.255.255.0",
- "202.117.16.1");
+ check_ip_block (iblock, "202.117.16.121", 24, "202.117.16.1");
iblock = iblock->next;
destroy_ip_block (tmp);
ASSERT (iblock != NULL, "convert ipv4 block",
"block eth0 should have a second IP address");
- check_ip_block (iblock, "192.168.4.121", "255.255.255.0",
- "202.117.16.1");
+ check_ip_block (iblock, "192.168.4.121", 24, "202.117.16.1");
destroy_ip_block (iblock);
g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING,
@@ -206,7 +193,7 @@ test_convert_ipv4_config_block (void)
ASSERT (iblock != NULL
&& iblock->next == NULL,
"convert error IPv4 address", "should only get one address");
- check_ip_block (iblock, "192.168.4.121", "255.255.255.0", "0.0.0.0");
+ check_ip_block (iblock, "192.168.4.121", 24, NULL);
destroy_ip_block (iblock);
g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING,
@@ -214,7 +201,6 @@ test_convert_ipv4_config_block (void)
iblock = convert_ip4_config_block ("eth3");
ASSERT (iblock == NULL, "convert config_block",
"convert error configuration");
- destroy_ip_block (iblock);
}
static void
@@ -224,7 +210,7 @@ test_convert_ipv4_routes_block (void)
ip_block *tmp = iblock;
ASSERT (iblock != NULL, "convert ip4 routes", "should get one route");
- check_ip_block (iblock, "192.168.4.0", "255.255.255.0", "192.168.4.1");
+ check_ip_block (iblock, "192.168.4.0", 24, "192.168.4.1");
iblock = iblock->next;
destroy_ip_block (tmp);
ASSERT (iblock == NULL, "convert ip4 routes",
@@ -234,7 +220,7 @@ test_convert_ipv4_routes_block (void)
tmp = iblock;
ASSERT (iblock != NULL, "convert ip4 routes", "should get one route");
- check_ip_block (iblock, "10.0.0.0", "255.0.0.0", "192.168.0.1");
+ check_ip_block (iblock, "10.0.0.0", 8, "192.168.0.1");
iblock = iblock->next;
destroy_ip_block (tmp);
ASSERT (iblock == NULL, "convert ip4 routes",
diff --git a/src/settings/plugins/ifupdown/parser.c b/src/settings/plugins/ifupdown/parser.c
index 415cfcc755..4ccfb62f8a 100644
--- a/src/settings/plugins/ifupdown/parser.c
+++ b/src/settings/plugins/ifupdown/parser.c
@@ -410,7 +410,7 @@ update_wired_setting_from_if_block(NMConnection *connection,
}
static void
-ifupdown_ip4_add_dns (NMSettingIP4Config *s_ip4, const char *dns)
+ifupdown_ip4_add_dns (NMSettingIPConfig *s_ip4, const char *dns)
{
guint32 addr;
char **list, **iter;
@@ -428,7 +428,7 @@ ifupdown_ip4_add_dns (NMSettingIP4Config *s_ip4, const char *dns)
continue;
}
- if (!nm_setting_ip4_config_add_dns (s_ip4, *iter))
+ if (!nm_setting_ip_config_add_dns (s_ip4, *iter))
nm_log_warn (LOGD_SETTINGS, " duplicate DNS domain '%s'", *iter);
}
g_strfreev (list);
@@ -440,15 +440,15 @@ update_ip4_setting_from_if_block(NMConnection *connection,
GError **error)
{
- NMSettingIP4Config *s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new());
+ NMSettingIPConfig *s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new());
const char *type = ifparser_getkey(block, "inet");
gboolean is_static = type && !strcmp("static", type);
if (!is_static) {
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
} else {
- guint32 tmp_addr, tmp_mask, tmp_gw;
- NMIP4Address *addr;
+ guint32 tmp_mask;
+ NMIPAddress *addr;
const char *address_v;
const char *netmask_v;
const char *gateway_v;
@@ -460,10 +460,9 @@ update_ip4_setting_from_if_block(NMConnection *connection,
/* Address */
address_v = ifparser_getkey (block, "address");
- if (!address_v || !inet_pton (AF_INET, address_v, &tmp_addr)) {
+ if (!address_v) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
- "Missing IPv4 address '%s'",
- address_v ? address_v : "(none)");
+ "Missing IPv4 address");
goto error;
}
@@ -472,11 +471,6 @@ update_ip4_setting_from_if_block(NMConnection *connection,
if (netmask_v) {
if (strlen (netmask_v) < 7) {
netmask_int = atoi (netmask_v);
- if (netmask_int > 32) {
- g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
- "Invalid IPv4 netmask '%s'", netmask_v);
- goto error;
- }
} else if (!inet_pton (AF_INET, netmask_v, &tmp_mask)) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid IPv4 netmask '%s'", netmask_v);
@@ -486,29 +480,30 @@ update_ip4_setting_from_if_block(NMConnection *connection,
}
}
- /* gateway */
- gateway_v = ifparser_getkey (block, "gateway");
- if (!gateway_v)
- gateway_v = address_v; /* dcbw: whaaa?? */
- if (!inet_pton (AF_INET, gateway_v, &tmp_gw)) {
- g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
- "Invalid IPv4 gateway '%s'", gateway_v);
- goto error;
- }
-
/* Add the new address to the setting */
- addr = nm_ip4_address_new ();
- nm_ip4_address_set_address (addr, tmp_addr);
- nm_ip4_address_set_prefix (addr, netmask_int);
- nm_ip4_address_set_gateway (addr, tmp_gw);
+ addr = nm_ip_address_new (AF_INET, address_v, netmask_int, error);
+ if (!addr)
+ goto error;
- if (nm_setting_ip4_config_add_address (s_ip4, addr)) {
+ if (nm_setting_ip_config_add_address (s_ip4, addr)) {
nm_log_info (LOGD_SETTINGS, "addresses count: %d",
- nm_setting_ip4_config_get_num_addresses (s_ip4));
+ nm_setting_ip_config_get_num_addresses (s_ip4));
} else {
nm_log_info (LOGD_SETTINGS, "ignoring duplicate IP4 address");
}
- nm_ip4_address_unref (addr);
+ nm_ip_address_unref (addr);
+
+ /* gateway */
+ gateway_v = ifparser_getkey (block, "gateway");
+ if (gateway_v) {
+ if (!nm_utils_ipaddr_valid (AF_INET, gateway_v)) {
+ g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
+ "Invalid IPv4 gateway '%s'", gateway_v);
+ goto error;
+ }
+ if (!nm_setting_ip_config_get_gateway (s_ip4))
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_GATEWAY, gateway_v, NULL);
+ }
nameserver_v = ifparser_getkey (block, "dns-nameserver");
ifupdown_ip4_add_dns (s_ip4, nameserver_v);
@@ -516,7 +511,7 @@ update_ip4_setting_from_if_block(NMConnection *connection,
nameservers_v = ifparser_getkey (block, "dns-nameservers");
ifupdown_ip4_add_dns (s_ip4, nameservers_v);
- if (!nm_setting_ip4_config_get_num_dns (s_ip4))
+ if (!nm_setting_ip_config_get_num_dns (s_ip4))
nm_log_info (LOGD_SETTINGS, "No dns-nameserver configured in /etc/network/interfaces");
/* DNS searches */
@@ -527,13 +522,13 @@ update_ip4_setting_from_if_block(NMConnection *connection,
g_strstrip (*iter);
if (g_ascii_isspace (*iter[0]))
continue;
- if (!nm_setting_ip4_config_add_dns_search (s_ip4, *iter))
+ if (!nm_setting_ip_config_add_dns_search (s_ip4, *iter))
nm_log_warn (LOGD_SETTINGS, " duplicate DNS domain '%s'", *iter);
}
g_strfreev (list);
}
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, NULL);
}
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
@@ -545,7 +540,7 @@ error:
}
static void
-ifupdown_ip6_add_dns (NMSettingIP6Config *s_ip6, const char *dns)
+ifupdown_ip6_add_dns (NMSettingIPConfig *s_ip6, const char *dns)
{
struct in6_addr addr;
char **list, **iter;
@@ -563,7 +558,7 @@ ifupdown_ip6_add_dns (NMSettingIP6Config *s_ip6, const char *dns)
continue;
}
- if (!nm_setting_ip6_config_add_dns (s_ip6, *iter))
+ if (!nm_setting_ip_config_add_dns (s_ip6, *iter))
nm_log_warn (LOGD_SETTINGS, " duplicate DNS domain '%s'", *iter);
}
g_strfreev (list);
@@ -574,16 +569,15 @@ update_ip6_setting_from_if_block(NMConnection *connection,
if_block *block,
GError **error)
{
- NMSettingIP6Config *s_ip6 = NM_SETTING_IP6_CONFIG (nm_setting_ip6_config_new());
+ NMSettingIPConfig *s_ip6 = NM_SETTING_IP_CONFIG (nm_setting_ip6_config_new());
const char *type = ifparser_getkey(block, "inet6");
gboolean is_static = type && (!strcmp("static", type) ||
!strcmp("v4tunnel", type));
if (!is_static) {
- g_object_set(s_ip6, NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL);
+ g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL);
} else {
- struct in6_addr tmp_addr, tmp_gw;
- NMIP6Address *addr;
+ NMIPAddress *addr;
const char *address_v;
const char *prefix_v;
const char *gateway_v;
@@ -595,10 +589,9 @@ update_ip6_setting_from_if_block(NMConnection *connection,
/* Address */
address_v = ifparser_getkey(block, "address");
- if (!address_v || !inet_pton (AF_INET6, address_v, &tmp_addr)) {
+ if (!address_v) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
- "Missing IPv6 address '%s'",
- address_v ? address_v : "(none)");
+ "Missing IPv6 address");
goto error;
}
@@ -607,29 +600,30 @@ update_ip6_setting_from_if_block(NMConnection *connection,
if (prefix_v)
prefix_int = g_ascii_strtoll (prefix_v, NULL, 10);
- /* Gateway */
- gateway_v = ifparser_getkey (block, "gateway");
- if (!gateway_v)
- gateway_v = address_v; /* dcbw: whaaa?? */
- if (!inet_pton (AF_INET6, gateway_v, &tmp_gw)) {
- g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
- "Invalid IPv6 gateway '%s'", gateway_v);
- goto error;
- }
-
/* Add the new address to the setting */
- addr = nm_ip6_address_new ();
- nm_ip6_address_set_address (addr, &tmp_addr);
- nm_ip6_address_set_prefix (addr, prefix_int);
- nm_ip6_address_set_gateway (addr, &tmp_gw);
+ addr = nm_ip_address_new (AF_INET6, address_v, prefix_int, error);
+ if (!addr)
+ goto error;
- if (nm_setting_ip6_config_add_address (s_ip6, addr)) {
+ if (nm_setting_ip_config_add_address (s_ip6, addr)) {
nm_log_info (LOGD_SETTINGS, "addresses count: %d",
- nm_setting_ip6_config_get_num_addresses (s_ip6));
+ nm_setting_ip_config_get_num_addresses (s_ip6));
} else {
nm_log_info (LOGD_SETTINGS, "ignoring duplicate IP6 address");
}
- nm_ip6_address_unref (addr);
+ nm_ip_address_unref (addr);
+
+ /* gateway */
+ gateway_v = ifparser_getkey (block, "gateway");
+ if (gateway_v) {
+ if (!nm_utils_ipaddr_valid (AF_INET6, gateway_v)) {
+ g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
+ "Invalid IPv6 gateway '%s'", gateway_v);
+ goto error;
+ }
+ if (!nm_setting_ip_config_get_gateway (s_ip6))
+ g_object_set (s_ip6, NM_SETTING_IP_CONFIG_GATEWAY, gateway_v, NULL);
+ }
nameserver_v = ifparser_getkey(block, "dns-nameserver");
ifupdown_ip6_add_dns (s_ip6, nameserver_v);
@@ -637,7 +631,7 @@ update_ip6_setting_from_if_block(NMConnection *connection,
nameservers_v = ifparser_getkey(block, "dns-nameservers");
ifupdown_ip6_add_dns (s_ip6, nameservers_v);
- if (!nm_setting_ip6_config_get_num_dns (s_ip6))
+ if (!nm_setting_ip_config_get_num_dns (s_ip6))
nm_log_info (LOGD_SETTINGS, "No dns-nameserver configured in /etc/network/interfaces");
/* DNS searches */
@@ -648,14 +642,14 @@ update_ip6_setting_from_if_block(NMConnection *connection,
g_strstrip (*iter);
if (isblank (*iter[0]))
continue;
- if (!nm_setting_ip6_config_add_dns_search (s_ip6, *iter))
+ if (!nm_setting_ip_config_add_dns_search (s_ip6, *iter))
nm_log_warn (LOGD_SETTINGS, " duplicate DNS domain '%s'", *iter);
}
g_strfreev (list);
}
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL,
NULL);
}
diff --git a/src/settings/plugins/ifupdown/tests/test-ifupdown.c b/src/settings/plugins/ifupdown/tests/test-ifupdown.c
index 8100676d79..0752ec4bbc 100644
--- a/src/settings/plugins/ifupdown/tests/test-ifupdown.c
+++ b/src/settings/plugins/ifupdown/tests/test-ifupdown.c
@@ -459,18 +459,15 @@ test17_read_static_ipv4 (const char *path)
{
NMConnection *connection;
NMSettingConnection *s_con;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
NMSettingWired *s_wired;
char *unmanaged = NULL;
GError *error = NULL;
const char* tmp;
- const char *expected_address = "10.0.0.3";
const char *expected_id = "Ifupdown (eth0)";
const char *expected_search1 = "example.com";
const char *expected_search2 = "foo.example.com";
- guint32 expected_prefix = 8;
- NMIP4Address *ip4_addr;
- guint32 addr;
+ NMIPAddress *ip4_addr;
#define TEST17_NAME "wired-static-verify-ip4"
if_block *block = NULL;
@@ -521,10 +518,6 @@ test17_read_static_ipv4 (const char *path)
/* ===== IPv4 SETTING ===== */
- ASSERT (inet_pton (AF_INET, expected_address, &addr) > 0,
- TEST17_NAME, "failed to verify %s: couldn't convert IP address #1",
- file);
-
s_ip4 = nm_connection_get_setting_ip4_config (connection);
ASSERT (s_ip4 != NULL,
TEST17_NAME, "failed to verify %s: missing %s setting",
@@ -532,89 +525,81 @@ test17_read_static_ipv4 (const char *path)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip4_config_get_method (s_ip4);
+ tmp = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0,
TEST17_NAME, "failed to verify %s: unexpected %s / %s key value",
file,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
/* IP addresses */
- ASSERT (nm_setting_ip4_config_get_num_addresses (s_ip4) == 1,
+ ASSERT (nm_setting_ip_config_get_num_addresses (s_ip4) == 1,
TEST17_NAME, "failed to verify %s: unexpected %s / %s key value",
file,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_ADDRESSES);
-
- ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 0);
- ASSERT (ip4_addr,
- TEST17_NAME, "failed to verify %s: missing IP4 address #1",
- file);
-
- ASSERT (nm_ip4_address_get_prefix (ip4_addr) == expected_prefix,
- TEST17_NAME, "failed to verify %s: unexpected IP4 address prefix",
- file);
+ NM_SETTING_IP_CONFIG_ADDRESSES);
- ASSERT (nm_ip4_address_get_address (ip4_addr) == addr,
- TEST17_NAME, "failed to verify %s: unexpected IP4 address: %s",
- file, addr);
+ ip4_addr = nm_setting_ip_config_get_address (s_ip4, 0);
+ g_assert (ip4_addr != NULL);
+ g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "10.0.0.3");
+ g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 8);
/* DNS Addresses */
- ASSERT (nm_setting_ip4_config_get_num_dns (s_ip4) == 2,
+ ASSERT (nm_setting_ip_config_get_num_dns (s_ip4) == 2,
TEST17_NAME, "failed to verify %s: unexpected %s / %s key value",
file,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
- ASSERT (!strcmp (nm_setting_ip4_config_get_dns (s_ip4, 0), "10.0.0.1"),
+ ASSERT (!strcmp (nm_setting_ip_config_get_dns (s_ip4, 0), "10.0.0.1"),
TEST17_NAME, "failed to verify %s: unexpected %s / %s key value #1",
file,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
- ASSERT (!strcmp (nm_setting_ip4_config_get_dns (s_ip4, 1), "10.0.0.2"),
+ ASSERT (!strcmp (nm_setting_ip_config_get_dns (s_ip4, 1), "10.0.0.2"),
TEST17_NAME, "failed to verify %s: unexpected %s / %s key value #2",
file,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
- ASSERT (nm_setting_ip4_config_get_num_addresses (s_ip4) == 1,
+ ASSERT (nm_setting_ip_config_get_num_addresses (s_ip4) == 1,
TEST17_NAME, "failed to verify %s: unexpected %s / %s key value",
file,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
/* DNS search domains */
- ASSERT (nm_setting_ip4_config_get_num_dns_searches (s_ip4) == 2,
+ ASSERT (nm_setting_ip_config_get_num_dns_searches (s_ip4) == 2,
TEST17_NAME, "failed to verify %s: unexpected %s / %s key value",
file,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
- tmp = nm_setting_ip4_config_get_dns_search (s_ip4, 0);
+ tmp = nm_setting_ip_config_get_dns_search (s_ip4, 0);
ASSERT (tmp != NULL,
TEST17_NAME, "failed to verify %s: missing %s / %s key",
file,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS_SEARCH);
+ NM_SETTING_IP_CONFIG_DNS_SEARCH);
ASSERT (strcmp (tmp, expected_search1) == 0,
TEST17_NAME, "failed to verify %s: unexpected %s / %s key value",
file,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS_SEARCH);
+ NM_SETTING_IP_CONFIG_DNS_SEARCH);
- tmp = nm_setting_ip4_config_get_dns_search (s_ip4, 1);
+ tmp = nm_setting_ip_config_get_dns_search (s_ip4, 1);
ASSERT (tmp != NULL,
TEST17_NAME, "failed to verify %s: missing %s / %s key",
file,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS_SEARCH);
+ NM_SETTING_IP_CONFIG_DNS_SEARCH);
ASSERT (strcmp (tmp, expected_search2) == 0,
TEST17_NAME, "failed to verify %s: unexpected %s / %s key value",
file,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS_SEARCH);
+ NM_SETTING_IP_CONFIG_DNS_SEARCH);
g_object_unref (connection);
}
@@ -624,18 +609,15 @@ test18_read_static_ipv6 (const char *path)
{
NMConnection *connection;
NMSettingConnection *s_con;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip6;
NMSettingWired *s_wired;
char *unmanaged = NULL;
GError *error = NULL;
const char* tmp;
- const char *expected_address = "fc00::1";
const char *expected_id = "Ifupdown (myip6tunnel)";
const char *expected_search1 = "example.com";
const char *expected_search2 = "foo.example.com";
- guint32 expected_prefix = 64;
- NMIP6Address *ip6_addr;
- struct in6_addr addr;
+ NMIPAddress *ip6_addr;
if_block *block = NULL;
#define TEST18_NAME "wired-static-verify-ip6"
const char* file = "test18-" TEST18_NAME;
@@ -691,11 +673,6 @@ test18_read_static_ipv6 (const char *path)
/* ===== IPv6 SETTING ===== */
- ASSERT (inet_pton (AF_INET6, expected_address, &addr) > 0,
- TEST18_NAME,
- "failed to verify %s: couldn't convert IP address #1",
- file);
-
s_ip6 = nm_connection_get_setting_ip6_config (connection);
ASSERT (s_ip6 != NULL,
TEST18_NAME,
@@ -704,103 +681,85 @@ test18_read_static_ipv6 (const char *path)
NM_SETTING_IP6_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip6_config_get_method (s_ip6);
+ tmp = nm_setting_ip_config_get_method (s_ip6);
ASSERT (strcmp (tmp, NM_SETTING_IP6_CONFIG_METHOD_MANUAL) == 0,
TEST18_NAME,
"failed to verify %s: unexpected %s / %s key value",
file,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
/* IP addresses */
- ASSERT (nm_setting_ip6_config_get_num_addresses (s_ip6) == 1,
+ ASSERT (nm_setting_ip_config_get_num_addresses (s_ip6) == 1,
TEST18_NAME,
"failed to verify %s: unexpected number of %s / %s",
file,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_ADDRESSES);
-
- ip6_addr = nm_setting_ip6_config_get_address (s_ip6, 0);
- ASSERT (ip6_addr,
- TEST18_NAME,
- "failed to verify %s: missing %s / %s #1",
- file,
- NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_ADDRESSES);
+ NM_SETTING_IP_CONFIG_ADDRESSES);
- ASSERT (nm_ip6_address_get_prefix (ip6_addr) == expected_prefix,
- TEST18_NAME
- "failed to verify %s: unexpected %s / %s prefix",
- file,
- NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_ADDRESSES);
-
- ASSERT (IN6_ARE_ADDR_EQUAL (nm_ip6_address_get_address (ip6_addr),
- &addr),
- TEST18_NAME,
- "failed to verify %s: unexpected %s / %s",
- file,
- NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_ADDRESSES);
+ ip6_addr = nm_setting_ip_config_get_address (s_ip6, 0);
+ g_assert (ip6_addr != NULL);
+ g_assert_cmpstr (nm_ip_address_get_address (ip6_addr), ==, "fc00::1");
+ g_assert_cmpint (nm_ip_address_get_prefix (ip6_addr), ==, 64);
/* DNS Addresses */
- ASSERT (nm_setting_ip6_config_get_num_dns (s_ip6) == 2,
+ ASSERT (nm_setting_ip_config_get_num_dns (s_ip6) == 2,
TEST18_NAME,
"failed to verify %s: unexpected number of %s / %s values",
file,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
- ASSERT (!strcmp (nm_setting_ip6_config_get_dns (s_ip6, 0), "fc00::2"),
+ ASSERT (!strcmp (nm_setting_ip_config_get_dns (s_ip6, 0), "fc00::2"),
TEST18_NAME,
"failed to verify %s: unexpected %s / %s #1",
file,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
- ASSERT (!strcmp (nm_setting_ip6_config_get_dns (s_ip6, 1), "fc00::3"),
+ ASSERT (!strcmp (nm_setting_ip_config_get_dns (s_ip6, 1), "fc00::3"),
TEST18_NAME, "failed to verify %s: unexpected %s / %s #2",
file,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
/* DNS search domains */
- ASSERT (nm_setting_ip6_config_get_num_dns_searches (s_ip6) == 2,
+ ASSERT (nm_setting_ip_config_get_num_dns_searches (s_ip6) == 2,
TEST18_NAME,
"failed to verify %s: unexpected number of %s / %s values",
file,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS_SEARCH);
+ NM_SETTING_IP_CONFIG_DNS_SEARCH);
- tmp = nm_setting_ip6_config_get_dns_search (s_ip6, 0);
+ tmp = nm_setting_ip_config_get_dns_search (s_ip6, 0);
ASSERT (tmp != NULL,
"wired-ipv6-manual-verify-ip6",
"failed to verify %s: missing %s / %s #1",
file,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS_SEARCH);
+ NM_SETTING_IP_CONFIG_DNS_SEARCH);
ASSERT (strcmp (tmp, expected_search1) == 0,
"wired-ipv6-manual-verify-ip6",
"failed to verify %s: unexpected %s / %s #1",
file,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS_SEARCH);
+ NM_SETTING_IP_CONFIG_DNS_SEARCH);
- tmp = nm_setting_ip6_config_get_dns_search (s_ip6, 1);
+ tmp = nm_setting_ip_config_get_dns_search (s_ip6, 1);
ASSERT (tmp != NULL,
TEST18_NAME,
"failed to verify %s: missing %s / %s #2",
file,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS_SEARCH);
+ NM_SETTING_IP_CONFIG_DNS_SEARCH);
ASSERT (strcmp (tmp, expected_search2) == 0,
TEST18_NAME,
"failed to verify %s: unexpected %s / %s #2",
file,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS_SEARCH);
+ NM_SETTING_IP_CONFIG_DNS_SEARCH);
g_free (unmanaged);
g_object_unref (connection);
@@ -810,13 +769,10 @@ static void
test19_read_static_ipv4_plen (const char *path)
{
NMConnection *connection;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
char *unmanaged = NULL;
GError *error = NULL;
- const char *expected_address = "10.0.0.3";
- guint32 expected_prefix = 8;
- NMIP4Address *ip4_addr;
- guint32 addr;
+ NMIPAddress *ip4_addr;
#define TEST19_NAME "wired-static-verify-ip4-plen"
if_block *block = NULL;
@@ -838,10 +794,6 @@ test19_read_static_ipv4_plen (const char *path)
/* ===== IPv4 SETTING ===== */
- ASSERT (inet_pton (AF_INET, expected_address, &addr) > 0,
- TEST19_NAME, "failed to verify %s: couldn't convert IP address #1",
- file);
-
s_ip4 = nm_connection_get_setting_ip4_config (connection);
ASSERT (s_ip4 != NULL,
TEST19_NAME, "failed to verify %s: missing %s setting",
@@ -849,24 +801,16 @@ test19_read_static_ipv4_plen (const char *path)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* IP addresses */
- ASSERT (nm_setting_ip4_config_get_num_addresses (s_ip4) == 1,
+ ASSERT (nm_setting_ip_config_get_num_addresses (s_ip4) == 1,
TEST19_NAME, "failed to verify %s: unexpected %s / %s key value",
file,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_ADDRESSES);
-
- ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 0);
- ASSERT (ip4_addr,
- TEST19_NAME, "failed to verify %s: missing IP4 address #1",
- file);
-
- ASSERT (nm_ip4_address_get_prefix (ip4_addr) == expected_prefix,
- TEST19_NAME, "failed to verify %s: unexpected IP4 address prefix",
- file);
+ NM_SETTING_IP_CONFIG_ADDRESSES);
- ASSERT (nm_ip4_address_get_address (ip4_addr) == addr,
- TEST19_NAME, "failed to verify %s: unexpected IP4 address: %s",
- file, addr);
+ ip4_addr = nm_setting_ip_config_get_address (s_ip4, 0);
+ g_assert (ip4_addr != NULL);
+ g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "10.0.0.3");
+ g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 8);
g_object_unref (connection);
}
diff --git a/src/settings/plugins/keyfile/reader.c b/src/settings/plugins/keyfile/reader.c
index cbd6e49ab1..c4a2a5d9bc 100644
--- a/src/settings/plugins/keyfile/reader.c
+++ b/src/settings/plugins/keyfile/reader.c
@@ -36,6 +36,7 @@
#include "common.h"
#include "utils.h"
#include "nm-core-internal.h"
+#include "NetworkManagerUtils.h"
/* Some setting properties also contain setting names, such as
* NMSettingConnection's 'type' property (which specifies the base type of the
@@ -108,130 +109,76 @@ get_one_int (const char *str, guint32 max_val, const char *key_name, guint32 *ou
}
static gpointer
-build_ip4_address_or_route (const char *key_name, const char *address_str, guint32 plen, const char *gateway_str, const char *metric_str, gboolean route)
+build_address (int family, const char *address_str, guint32 plen)
{
- gpointer result;
- guint32 addr;
- guint32 address = 0;
- guint32 gateway = 0;
- guint32 metric = 0;
- int err;
+ NMIPAddress *addr;
+ GError *error = NULL;
g_return_val_if_fail (address_str, NULL);
- /* Address */
- err = inet_pton (AF_INET, address_str, &addr);
- if (err <= 0) {
- nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid IPv4 address '%s'", __func__, address_str);
- return NULL;
- }
- address = addr;
-
- /* Gateway */
- if (gateway_str && gateway_str[0]) {
- err = inet_pton (AF_INET, gateway_str, &addr);
- if (err <= 0) {
- nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid IPv4 gateway '%s'", __func__, gateway_str);
- return NULL;
- }
- gateway = addr;
- }
- else
- gateway = 0;
-
- /* parse metric, default to 0 */
- if (metric_str) {
- if (!get_one_int (metric_str, G_MAXUINT32, key_name, &metric))
- return NULL;
- }
-
- if (route) {
- result = nm_ip4_route_new ();
- nm_ip4_route_set_dest (result, address);
- nm_ip4_route_set_prefix (result, plen);
- nm_ip4_route_set_next_hop (result, gateway);
- nm_ip4_route_set_metric (result, metric);
- } else {
- result = nm_ip4_address_new ();
- nm_ip4_address_set_address (result, address);
- nm_ip4_address_set_prefix (result, plen);
- nm_ip4_address_set_gateway (result, gateway);
+ addr = nm_ip_address_new (family, address_str, plen, &error);
+ if (!addr) {
+ nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid %s address: %s", __func__,
+ family == AF_INET ? "IPv4" : "IPv6",
+ error->message);
+ g_error_free (error);
}
- return result;
+ return addr;
}
static gpointer
-build_ip6_address_or_route (const char *key_name, const char *address_str, guint32 plen, const char *gateway_str, const char *metric_str, gboolean route)
+build_route (int family,
+ const char *dest_str, guint32 plen,
+ const char *gateway_str, const char *metric_str,
+ const char *key_name)
{
- gpointer result;
- struct in6_addr addr;
+ NMIPRoute *route;
guint32 metric = 0;
- int err;
-
- g_return_val_if_fail (address_str, NULL);
-
- if (route)
- result = nm_ip6_route_new ();
- else
- result = nm_ip6_address_new ();
+ GError *error = NULL;
- /* add address and prefix length */
- err = inet_pton (AF_INET6, address_str, &addr);
- if (err <= 0) {
- nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid IPv6 address '%s'", __func__, address_str);
- goto error_out;
- }
- if (route) {
- nm_ip6_route_set_dest (result, &addr);
- nm_ip6_route_set_prefix (result, plen);
- } else {
- nm_ip6_address_set_address (result, &addr);
- nm_ip6_address_set_prefix (result, plen);
- }
+ g_return_val_if_fail (dest_str, NULL);
- /* add gateway */
+ /* Next hop */
if (gateway_str && gateway_str[0]) {
- err = inet_pton (AF_INET6, gateway_str, &addr);
- if (err <= 0) {
+ if (!nm_utils_ipaddr_valid (family, gateway_str)) {
/* Try workaround for routes written by broken keyfile writer.
* Due to bug bgo#719851, an older version of writer would have
* written "a:b:c:d::/plen,metric" if the gateway was ::, instead
* of "a:b:c:d::/plen,,metric" or "a:b:c:d::/plen,::,metric"
- * Try workaround by interepeting gateway_str as metric to accept such
+ * Try workaround by interpreting gateway_str as metric to accept such
* invalid routes. This broken syntax should not be not officially
* supported.
**/
- if (route && !metric_str && get_one_int (gateway_str, G_MAXUINT32, NULL, &metric))
- addr = in6addr_any;
+ if ( family == AF_INET6
+ && !metric_str
+ && get_one_int (gateway_str, G_MAXUINT32, NULL, &metric))
+ gateway_str = NULL;
else {
- nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid IPv6 gateway '%s'", __func__, gateway_str);
- goto error_out;
+ nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid gateway '%s'", __func__, gateway_str);
+ return NULL;
}
}
} else
- addr = in6addr_any;
-
- if (route) {
- nm_ip6_route_set_next_hop (result, &addr);
+ gateway_str = NULL;
- /* parse metric, default to 0 */
- if (metric_str) {
- if (!get_one_int (metric_str, G_MAXUINT32, key_name, &metric))
- goto error_out;
- }
- nm_ip6_route_set_metric (result, metric);
- } else
- nm_ip6_address_set_gateway (result, &addr);
+ /* parse metric, default to 0 */
+ if (metric_str) {
+ if (!get_one_int (metric_str, G_MAXUINT32, key_name, &metric))
+ return NULL;
+ }
- return result;
+ route = nm_ip_route_new (family, dest_str, plen, gateway_str,
+ metric ? (gint64) metric : -1,
+ &error);
+ if (!route) {
+ nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid %s route: %s", __func__,
+ family == AF_INET ? "IPv4" : "IPv6",
+ error->message);
+ g_error_free (error);
+ }
-error_out:
- if (route)
- nm_ip6_route_unref (result);
- else
- nm_ip4_route_unref (result);
- return NULL;
+ return route;
}
/* On success, returns pointer to the zero-terminated field (original @current).
@@ -324,7 +271,8 @@ read_one_ip_address_or_route (GKeyFile *file,
const char *setting_name,
const char *key_name,
gboolean ipv6,
- gboolean route)
+ gboolean route,
+ char **out_gateway)
{
guint32 plen;
gpointer result;
@@ -376,22 +324,32 @@ read_one_ip_address_or_route (GKeyFile *file,
}
}
+#define DEFAULT_PREFIX(for_route, for_ipv6) ( (for_route) ? ( (for_ipv6) ? 128 : 24 ) : ( (for_ipv6) ? 64 : 24 ) )
+
/* parse plen, fallback to defaults */
- if (plen_str)
- g_return_val_if_fail (get_one_int (plen_str, ipv6 ? 128 : 32,
- key_name, &plen), NULL);
- else {
- if (route)
- plen = ipv6 ? 128 : 24;
- else
- plen = ipv6 ? 64 : 24;
+ if (plen_str) {
+ if (!get_one_int (plen_str, ipv6 ? 128 : 32, key_name, &plen)) {
+ plen = DEFAULT_PREFIX (route, ipv6);
+ nm_log_warn (LOGD_SETTINGS, "keyfile: invalid prefix length '%s' in '%s.%s', defaulting to %d",
+ plen_str, setting_name, key_name, plen);
+ }
+ } else {
+ plen = DEFAULT_PREFIX (route, ipv6);
nm_log_warn (LOGD_SETTINGS, "keyfile: Missing prefix length in '%s.%s', defaulting to %d",
setting_name, key_name, plen);
}
/* build the appropriate data structure for NetworkManager settings */
- result = (ipv6 ? build_ip6_address_or_route : build_ip4_address_or_route) (
- key_name, address_str, plen, gateway_str, metric_str, route);
+ if (route) {
+ result = build_route (ipv6 ? AF_INET6 : AF_INET,
+ address_str, plen, gateway_str, metric_str,
+ key_name);
+ } else {
+ result = build_address (ipv6 ? AF_INET6 : AF_INET,
+ address_str, plen);
+ if (out_gateway && gateway_str)
+ *out_gateway = g_strdup (gateway_str);
+ }
g_free (value);
return result;
@@ -409,21 +367,15 @@ ip_address_or_route_parser (NMSetting *setting, const char *key, GKeyFile *keyfi
static const char *key_names_routes[] = { "route", "routes", NULL };
static const char *key_names_addresses[] = { "address", "addresses", NULL };
const char **key_names = routes ? key_names_routes : key_names_addresses;
+ char *gateway = NULL;
GPtrArray *list;
GDestroyNotify free_func;
int i;
- if (ipv6) {
- if (routes)
- free_func = (GDestroyNotify) nm_ip6_route_unref;
- else
- free_func = (GDestroyNotify) nm_ip6_address_unref;
- } else {
- if (routes)
- free_func = (GDestroyNotify) nm_ip4_route_unref;
- else
- free_func = (GDestroyNotify) nm_ip4_address_unref;
- }
+ if (routes)
+ free_func = (GDestroyNotify) nm_ip_route_unref;
+ else
+ free_func = (GDestroyNotify) nm_ip_address_unref;
list = g_ptr_array_new_with_free_func (free_func);
for (i = -1; i < 1000; i++) {
@@ -439,8 +391,8 @@ ip_address_or_route_parser (NMSetting *setting, const char *key, GKeyFile *keyfi
else
key_name = g_strdup (*key_basename);
- item = read_one_ip_address_or_route (keyfile, setting_name, key_name, ipv6, routes);
-
+ item = read_one_ip_address_or_route (keyfile, setting_name, key_name, ipv6, routes,
+ gateway ? NULL : &gateway);
if (item)
g_ptr_array_add (list, item);
@@ -451,6 +403,11 @@ ip_address_or_route_parser (NMSetting *setting, const char *key, GKeyFile *keyfi
if (list->len >= 1)
g_object_set (setting, key, list, NULL);
+ if (gateway) {
+ g_object_set (setting, "gateway", gateway, NULL);
+ g_free (gateway);
+ }
+
g_ptr_array_unref (list);
}
@@ -959,27 +916,27 @@ static KeyParser key_parsers[] = {
TRUE,
mac_address_parser_ETHER },
{ NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_ADDRESSES,
+ NM_SETTING_IP_CONFIG_ADDRESSES,
FALSE,
ip_address_or_route_parser },
{ NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_ADDRESSES,
+ NM_SETTING_IP_CONFIG_ADDRESSES,
FALSE,
ip_address_or_route_parser },
{ NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_ROUTES,
+ NM_SETTING_IP_CONFIG_ROUTES,
FALSE,
ip_address_or_route_parser },
{ NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_ROUTES,
+ NM_SETTING_IP_CONFIG_ROUTES,
FALSE,
ip_address_or_route_parser },
{ NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS,
+ NM_SETTING_IP_CONFIG_DNS,
FALSE,
ip4_dns_parser },
{ NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS,
+ NM_SETTING_IP_CONFIG_DNS,
FALSE,
ip6_dns_parser },
{ NM_SETTING_WIRED_SETTING_NAME,
@@ -1067,6 +1024,7 @@ read_one_setting_value (NMSetting *setting,
{
ReadInfo *info = user_data;
const char *setting_name;
+ int errsv;
GType type;
GError *err = NULL;
gboolean check_for_key = TRUE;
@@ -1167,6 +1125,18 @@ read_one_setting_value (NMSetting *setting,
uint_val = g_ascii_strtoull (tmp_str, NULL, 10);
g_free (tmp_str);
g_object_set (setting, key, uint_val, NULL);
+ } else if (type == G_TYPE_INT64) {
+ char *tmp_str;
+ gint64 int_val;
+
+ tmp_str = nm_keyfile_plugin_kf_get_value (info->keyfile, setting_name, key, NULL);
+ int_val = nm_utils_ascii_str_to_int64 (tmp_str, 10, G_MININT64, G_MAXINT64, 0);
+ errsv = errno;
+ if (errsv)
+ nm_log_warn (LOGD_SETTINGS, "Invalid int64 value (%s)", tmp_str);
+ else
+ g_object_set (setting, key, int_val, NULL);
+ g_free (tmp_str);
} else if (type == G_TYPE_BYTES) {
gint *tmp;
GByteArray *array;
diff --git a/src/settings/plugins/keyfile/tests/test-keyfile.c b/src/settings/plugins/keyfile/tests/test-keyfile.c
index e37f7c8a90..a38a3bd0f0 100644
--- a/src/settings/plugins/keyfile/tests/test-keyfile.c
+++ b/src/settings/plugins/keyfile/tests/test-keyfile.c
@@ -38,69 +38,26 @@
#define TEST_WIRELESS_FILE TEST_KEYFILES_DIR"/Test_Wireless_Connection"
static void
-check_ip4_address (NMSettingIP4Config *config, int idx, const char *address_str, int plen, const char *gateway_str)
+check_ip_address (NMSettingIPConfig *config, int idx, const char *address, int plen)
{
- NMIP4Address *ip4 = nm_setting_ip4_config_get_address (config, idx);
- guint32 address, gateway;
-
- g_assert (inet_pton (AF_INET, address_str, &address) == 1);
- g_assert (inet_pton (AF_INET, gateway_str, &gateway) == 1);
+ NMIPAddress *ip4 = nm_setting_ip_config_get_address (config, idx);
g_assert (ip4);
- g_assert (nm_ip4_address_get_address (ip4) == address);
- g_assert (nm_ip4_address_get_prefix (ip4) == plen);
- g_assert (nm_ip4_address_get_gateway (ip4) == gateway);
-}
-
-static void
-check_ip6_address (NMSettingIP6Config *config, int idx, const char *address_str, int plen, const char *gateway_str)
-{
- NMIP6Address *ip6 = nm_setting_ip6_config_get_address (config, idx);
- struct in6_addr address;
- struct in6_addr gateway;
-
- g_assert (inet_pton (AF_INET6, address_str, &address) == 1);
- g_assert (inet_pton (AF_INET6, gateway_str, &gateway) == 1);
-
- g_assert (ip6);
- g_assert (!memcmp (nm_ip6_address_get_address (ip6), &address, sizeof(address)));
- g_assert (nm_ip6_address_get_prefix (ip6) == plen);
- g_assert (!memcmp (nm_ip6_address_get_gateway (ip6), &gateway, sizeof(gateway)));
-}
-
-static void
-check_ip4_route (NMSettingIP4Config *config, int idx, const char *destination_str, int plen,
- const char *nexthop_str, int metric)
-{
- NMIP4Route *route = nm_setting_ip4_config_get_route (config, idx);
- guint32 destination, nexthop;
-
- g_assert (inet_pton (AF_INET, destination_str, &destination) == 1);
- g_assert (inet_pton (AF_INET, nexthop_str, &nexthop) == 1);
-
- g_assert (route);
- g_assert (nm_ip4_route_get_dest (route) == destination);
- g_assert (nm_ip4_route_get_prefix (route) == plen);
- g_assert (nm_ip4_route_get_next_hop (route) == nexthop);
- g_assert (nm_ip4_route_get_metric (route) == metric);
+ g_assert_cmpstr (nm_ip_address_get_address (ip4), ==, address);
+ g_assert_cmpint (nm_ip_address_get_prefix (ip4), ==, plen);
}
static void
-check_ip6_route (NMSettingIP6Config *config, int idx, const char *destination_str, int plen,
- const char *next_hop_str, int metric)
+check_ip_route (NMSettingIPConfig *config, int idx, const char *destination, int plen,
+ const char *next_hop, gint64 metric)
{
- NMIP6Route *route = nm_setting_ip6_config_get_route (config, idx);
- struct in6_addr destination;
- struct in6_addr next_hop;
-
- g_assert (inet_pton (AF_INET6, destination_str, &destination) == 1);
- g_assert (inet_pton (AF_INET6, next_hop_str, &next_hop) == 1);
+ NMIPRoute *route = nm_setting_ip_config_get_route (config, idx);
g_assert (route);
- g_assert (!memcmp (nm_ip6_route_get_dest (route), &destination, sizeof(destination)));
- g_assert (nm_ip6_route_get_prefix (route) == plen);
- g_assert (!memcmp (nm_ip6_route_get_next_hop (route), &next_hop, sizeof(next_hop)));
- g_assert (nm_ip6_route_get_metric (route) == metric);
+ g_assert_cmpstr (nm_ip_route_get_dest (route), ==, destination);
+ g_assert_cmpint (nm_ip_route_get_prefix (route), ==, plen);
+ g_assert_cmpstr (nm_ip_route_get_next_hop (route), ==, next_hop);
+ g_assert_cmpint (nm_ip_route_get_metric (route), ==, metric);
}
static NMConnection *
@@ -125,8 +82,8 @@ test_read_valid_wired_connection (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
GError *error = NULL;
const char *mac;
char expected_mac_address[ETH_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 };
@@ -260,55 +217,62 @@ test_read_valid_wired_connection (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip4_config_get_method (s_ip4);
+ tmp = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0,
"connection-verify-wired", "failed to verify %s: unexpected %s / %s key value",
TEST_WIRED_FILE,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
/* DNS Addresses */
- ASSERT (nm_setting_ip4_config_get_num_dns (s_ip4) == 2,
+ ASSERT (nm_setting_ip_config_get_num_dns (s_ip4) == 2,
"connection-verify-wired", "failed to verify %s: unexpected %s / %s key value",
TEST_WIRED_FILE,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
- ASSERT (strcmp (nm_setting_ip4_config_get_dns (s_ip4, 0), "4.2.2.1") == 0,
+ ASSERT (strcmp (nm_setting_ip_config_get_dns (s_ip4, 0), "4.2.2.1") == 0,
"connection-verify-wired", "failed to verify %s: unexpected %s / %s key value #1",
TEST_WIRED_FILE,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
- ASSERT (strcmp (nm_setting_ip4_config_get_dns (s_ip4, 1), "4.2.2.2") == 0,
+ ASSERT (strcmp (nm_setting_ip_config_get_dns (s_ip4, 1), "4.2.2.2") == 0,
"connection-verify-wired", "failed to verify %s: unexpected %s / %s key value #2",
TEST_WIRED_FILE,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
/* IPv4 addresses */
- g_assert (nm_setting_ip4_config_get_num_addresses (s_ip4) == 6);
- check_ip4_address (s_ip4, 0, "2.3.4.5", 24, "2.3.4.6");
- check_ip4_address (s_ip4, 1, "192.168.0.5", 24, "192.168.0.1");
- check_ip4_address (s_ip4, 2, "1.2.3.4", 16, "1.2.1.1");
- check_ip4_address (s_ip4, 3, "3.4.5.6", 16, "0.0.0.0");
- check_ip4_address (s_ip4, 4, "4.5.6.7", 24, "1.2.3.4");
- check_ip4_address (s_ip4, 5, "5.6.7.8", 24, "0.0.0.0");
+ g_assert (nm_setting_ip_config_get_num_addresses (s_ip4) == 6);
+ check_ip_address (s_ip4, 0, "2.3.4.5", 24);
+ check_ip_address (s_ip4, 1, "192.168.0.5", 24);
+ check_ip_address (s_ip4, 2, "1.2.3.4", 16);
+ check_ip_address (s_ip4, 3, "3.4.5.6", 16);
+ check_ip_address (s_ip4, 4, "4.5.6.7", 24);
+ check_ip_address (s_ip4, 5, "5.6.7.8", 24);
+
+ /* IPv4 gateway */
+ ASSERT (strcmp (nm_setting_ip_config_get_gateway (s_ip4), "2.3.4.6") == 0,
+ "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value",
+ TEST_WIRED_FILE,
+ NM_SETTING_IP4_CONFIG_SETTING_NAME,
+ NM_SETTING_IP_CONFIG_GATEWAY);
/* IPv4 routes */
- g_assert (nm_setting_ip4_config_get_num_routes (s_ip4) == 12);
- check_ip4_route (s_ip4, 0, "5.6.7.8", 32, "0.0.0.0", 0);
- check_ip4_route (s_ip4, 1, "1.2.3.0", 24, "2.3.4.8", 99);
- check_ip4_route (s_ip4, 2, "1.1.1.2", 12, "0.0.0.0", 0);
- check_ip4_route (s_ip4, 3, "1.1.1.3", 13, "0.0.0.0", 0);
- check_ip4_route (s_ip4, 4, "1.1.1.4", 14, "2.2.2.4", 0);
- check_ip4_route (s_ip4, 5, "1.1.1.5", 15, "2.2.2.5", 0);
- check_ip4_route (s_ip4, 6, "1.1.1.6", 16, "2.2.2.6", 0);
- check_ip4_route (s_ip4, 7, "1.1.1.7", 17, "0.0.0.0", 0);
- check_ip4_route (s_ip4, 8, "1.1.1.8", 18, "0.0.0.0", 0);
- check_ip4_route (s_ip4, 9, "1.1.1.9", 19, "0.0.0.0", 0);
- check_ip4_route (s_ip4, 10, "1.1.1.10", 20, "0.0.0.0", 0);
- check_ip4_route (s_ip4, 11, "1.1.1.11", 21, "0.0.0.0", 21);
+ g_assert (nm_setting_ip_config_get_num_routes (s_ip4) == 12);
+ check_ip_route (s_ip4, 0, "5.6.7.8", 32, NULL, -1);
+ check_ip_route (s_ip4, 1, "1.2.3.0", 24, "2.3.4.8", 99);
+ check_ip_route (s_ip4, 2, "1.1.1.2", 12, NULL, -1);
+ check_ip_route (s_ip4, 3, "1.1.1.3", 13, NULL, -1);
+ check_ip_route (s_ip4, 4, "1.1.1.4", 14, "2.2.2.4", -1);
+ check_ip_route (s_ip4, 5, "1.1.1.5", 15, "2.2.2.5", -1);
+ check_ip_route (s_ip4, 6, "1.1.1.6", 16, "2.2.2.6", -1);
+ check_ip_route (s_ip4, 7, "1.1.1.7", 17, NULL, -1);
+ check_ip_route (s_ip4, 8, "1.1.1.8", 18, NULL, -1);
+ check_ip_route (s_ip4, 9, "1.1.1.9", 19, NULL, -1);
+ check_ip_route (s_ip4, 10, "1.1.1.10", 20, NULL, -1);
+ check_ip_route (s_ip4, 11, "1.1.1.11", 21, NULL, 21);
/* ===== IPv6 SETTING ===== */
@@ -319,172 +283,117 @@ test_read_valid_wired_connection (void)
NM_SETTING_IP6_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip6_config_get_method (s_ip6);
+ tmp = nm_setting_ip_config_get_method (s_ip6);
ASSERT (strcmp (tmp, NM_SETTING_IP6_CONFIG_METHOD_MANUAL) == 0,
"connection-verify-wired", "failed to verify %s: unexpected %s / %s key value",
TEST_WIRED_FILE,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
/* DNS Addresses */
- ASSERT (nm_setting_ip6_config_get_num_dns (s_ip6) == 2,
+ ASSERT (nm_setting_ip_config_get_num_dns (s_ip6) == 2,
"connection-verify-wired", "failed to verify %s: unexpected %s / %s key value",
TEST_WIRED_FILE,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
- ASSERT (strcmp (nm_setting_ip6_config_get_dns (s_ip6, 0), "1111:dddd::aaaa") == 0,
+ ASSERT (strcmp (nm_setting_ip_config_get_dns (s_ip6, 0), "1111:dddd::aaaa") == 0,
"connection-verify-wired", "failed to verify %s: unexpected %s / %s key value #1",
TEST_WIRED_FILE,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
- ASSERT (strcmp (nm_setting_ip6_config_get_dns (s_ip6, 1), "1::cafe") == 0,
+ ASSERT (strcmp (nm_setting_ip_config_get_dns (s_ip6, 1), "1::cafe") == 0,
"connection-verify-wired", "failed to verify %s: unexpected %s / %s key value #2",
TEST_WIRED_FILE,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
/* DNS Searches */
- ASSERT (nm_setting_ip6_config_get_num_dns_searches (s_ip6) == 3,
+ ASSERT (nm_setting_ip_config_get_num_dns_searches (s_ip6) == 3,
"connection-verify-wired", "failed to verify %s: unexpected %s / %s key value",
TEST_WIRED_FILE,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS_SEARCH);
+ NM_SETTING_IP_CONFIG_DNS_SEARCH);
- ASSERT (!strcmp (nm_setting_ip6_config_get_dns_search (s_ip6, 0), expected6_dnssearch1),
+ ASSERT (!strcmp (nm_setting_ip_config_get_dns_search (s_ip6, 0), expected6_dnssearch1),
"connection-verify-wired", "failed to verify %s: unexpected %s / %s key value #1",
TEST_WIRED_FILE,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS_SEARCH);
- ASSERT (!strcmp (nm_setting_ip6_config_get_dns_search (s_ip6, 1), expected6_dnssearch2),
+ NM_SETTING_IP_CONFIG_DNS_SEARCH);
+ ASSERT (!strcmp (nm_setting_ip_config_get_dns_search (s_ip6, 1), expected6_dnssearch2),
"connection-verify-wired", "failed to verify %s: unexpected %s / %s key value #2",
TEST_WIRED_FILE,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS_SEARCH);
- ASSERT (!strcmp (nm_setting_ip6_config_get_dns_search (s_ip6, 2), expected6_dnssearch3),
+ NM_SETTING_IP_CONFIG_DNS_SEARCH);
+ ASSERT (!strcmp (nm_setting_ip_config_get_dns_search (s_ip6, 2), expected6_dnssearch3),
"connection-verify-wired", "failed to verify %s: unexpected %s / %s key value #3",
TEST_WIRED_FILE,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS_SEARCH);
+ NM_SETTING_IP_CONFIG_DNS_SEARCH);
/* IPv6 addresses */
- g_assert (nm_setting_ip6_config_get_num_addresses (s_ip6) == 10);
- check_ip6_address (s_ip6, 0, "2:3:4:5:6:7:8:9", 64, "2:3:4:5:1:2:3:4");
- check_ip6_address (s_ip6, 1, "abcd:1234:ffff::cdde", 64, "::");
- check_ip6_address (s_ip6, 2, "1:2:3:4:5:6:7:8", 96, "::");
- check_ip6_address (s_ip6, 3, "3:4:5:6:7:8:9:0", 128, "::");
- check_ip6_address (s_ip6, 4, "3:4:5:6:7:8:9:14", 64, "::");
- check_ip6_address (s_ip6, 5, "3:4:5:6:7:8:9:15", 64, "::");
- check_ip6_address (s_ip6, 6, "3:4:5:6:7:8:9:16", 66, "::");
- check_ip6_address (s_ip6, 7, "3:4:5:6:7:8:9:17", 67, "::");
- check_ip6_address (s_ip6, 8, "3:4:5:6:7:8:9:18", 68, "::");
- check_ip6_address (s_ip6, 9, "3:4:5:6:7:8:9:19", 69, "1::09");
+ g_assert (nm_setting_ip_config_get_num_addresses (s_ip6) == 10);
+ check_ip_address (s_ip6, 0, "2:3:4:5:6:7:8:9", 64);
+ check_ip_address (s_ip6, 1, "abcd:1234:ffff::cdde", 64);
+ check_ip_address (s_ip6, 2, "1:2:3:4:5:6:7:8", 96);
+ check_ip_address (s_ip6, 3, "3:4:5:6:7:8:9:0", 128);
+ check_ip_address (s_ip6, 4, "3:4:5:6:7:8:9:14", 64);
+ check_ip_address (s_ip6, 5, "3:4:5:6:7:8:9:15", 64);
+ check_ip_address (s_ip6, 6, "3:4:5:6:7:8:9:16", 66);
+ check_ip_address (s_ip6, 7, "3:4:5:6:7:8:9:17", 67);
+ check_ip_address (s_ip6, 8, "3:4:5:6:7:8:9:18", 68);
+ check_ip_address (s_ip6, 9, "3:4:5:6:7:8:9:19", 69);
+
+ /* IPv6 gateway */
+ ASSERT (strcmp (nm_setting_ip_config_get_gateway (s_ip6), "2:3:4:5:1:2:3:4") == 0,
+ "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value",
+ TEST_WIRED_FILE,
+ NM_SETTING_IP6_CONFIG_SETTING_NAME,
+ NM_SETTING_IP_CONFIG_GATEWAY);
/* Route #1 */
- g_assert (nm_setting_ip6_config_get_num_routes (s_ip6) == 7);
- check_ip6_route (s_ip6, 0, "d:e:f:0:1:2:3:4", 64, "f:e:d:c:1:2:3:4", 0);
- check_ip6_route (s_ip6, 1, "a:b:c:d::", 64, "f:e:d:c:1:2:3:4", 99);
- check_ip6_route (s_ip6, 2, "8:7:6:5:4:3:2:1", 128, "::", 0);
- check_ip6_route (s_ip6, 3, "6:7:8:9:0:1:2:3", 126, "::", 1);
- check_ip6_route (s_ip6, 4, "7:8:9:0:1:2:3:4", 125, "::", 5);
- check_ip6_route (s_ip6, 5, "8:9:0:1:2:3:4:5", 124, "::", 6);
- check_ip6_route (s_ip6, 6, "8:9:0:1:2:3:4:6", 123, "::", 0);
+ g_assert (nm_setting_ip_config_get_num_routes (s_ip6) == 7);
+ check_ip_route (s_ip6, 0, "d:e:f:0:1:2:3:4", 64, "f:e:d:c:1:2:3:4", -1);
+ check_ip_route (s_ip6, 1, "a:b:c:d::", 64, "f:e:d:c:1:2:3:4", 99);
+ check_ip_route (s_ip6, 2, "8:7:6:5:4:3:2:1", 128, NULL, -1);
+ check_ip_route (s_ip6, 3, "6:7:8:9:0:1:2:3", 126, NULL, 1);
+ check_ip_route (s_ip6, 4, "7:8:9:0:1:2:3:4", 125, NULL, 5);
+ check_ip_route (s_ip6, 5, "8:9:0:1:2:3:4:5", 124, NULL, 6);
+ check_ip_route (s_ip6, 6, "8:9:0:1:2:3:4:6", 123, NULL, -1);
g_object_unref (connection);
}
static void
-add_one_ip4_address (NMSettingIP4Config *s_ip4,
- const char *addr,
- const char *gw,
- guint32 prefix)
-{
- guint32 tmp;
- NMIP4Address *ip4_addr;
-
- ip4_addr = nm_ip4_address_new ();
- nm_ip4_address_set_prefix (ip4_addr, prefix);
-
- inet_pton (AF_INET, addr, &tmp);
- nm_ip4_address_set_address (ip4_addr, tmp);
-
- inet_pton (AF_INET, gw, &tmp);
- nm_ip4_address_set_gateway (ip4_addr, tmp);
-
- nm_setting_ip4_config_add_address (s_ip4, ip4_addr);
- nm_ip4_address_unref (ip4_addr);
-}
-
-static void
-add_one_ip4_route (NMSettingIP4Config *s_ip4,
- const char *dest,
- const char *nh,
- guint32 prefix,
- guint32 metric)
+add_one_ip_address (NMSettingIPConfig *s_ip,
+ const char *addr,
+ guint32 prefix)
{
- guint32 addr;
- NMIP4Route *route;
-
- route = nm_ip4_route_new ();
- nm_ip4_route_set_prefix (route, prefix);
- nm_ip4_route_set_metric (route, metric);
-
- inet_pton (AF_INET, dest, &addr);
- nm_ip4_route_set_dest (route, addr);
-
- inet_pton (AF_INET, nh, &addr);
- nm_ip4_route_set_next_hop (route, addr);
-
- nm_setting_ip4_config_add_route (s_ip4, route);
- nm_ip4_route_unref (route);
-}
-
-static void
-add_one_ip6_address (NMSettingIP6Config *s_ip6,
- const char *addr,
- guint32 prefix,
- const char *gw)
-{
- struct in6_addr tmp;
- NMIP6Address *ip6_addr;
-
- ip6_addr = nm_ip6_address_new ();
- nm_ip6_address_set_prefix (ip6_addr, prefix);
-
- inet_pton (AF_INET6, addr, &tmp);
- nm_ip6_address_set_address (ip6_addr, &tmp);
-
- if (gw) {
- inet_pton (AF_INET6, gw, &tmp);
- nm_ip6_address_set_gateway (ip6_addr, &tmp);
- }
+ NMIPAddress *ip_addr;
+ GError *error = NULL;
- nm_setting_ip6_config_add_address (s_ip6, ip6_addr);
- nm_ip6_address_unref (ip6_addr);
+ ip_addr = nm_ip_address_new (NM_IS_SETTING_IP4_CONFIG (s_ip) ? AF_INET : AF_INET6,
+ addr, prefix, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_address (s_ip, ip_addr);
+ nm_ip_address_unref (ip_addr);
}
static void
-add_one_ip6_route (NMSettingIP6Config *s_ip6,
- const char *dest,
- const char *nh,
- guint32 prefix,
- guint32 metric)
+add_one_ip_route (NMSettingIPConfig *s_ip,
+ const char *dest,
+ const char *nh,
+ guint32 prefix,
+ gint64 metric)
{
- struct in6_addr addr;
- NMIP6Route *route;
-
- route = nm_ip6_route_new ();
- nm_ip6_route_set_prefix (route, prefix);
- nm_ip6_route_set_metric (route, metric);
-
- inet_pton (AF_INET6, dest, &addr);
- nm_ip6_route_set_dest (route, &addr);
-
- inet_pton (AF_INET6, nh, &addr);
- nm_ip6_route_set_next_hop (route, &addr);
+ NMIPRoute *route;
+ GError *error = NULL;
- nm_setting_ip6_config_add_route (s_ip6, route);
- nm_ip6_route_unref (route);
+ route = nm_ip_route_new (NM_IS_SETTING_IP4_CONFIG (s_ip) ? AF_INET : AF_INET6,
+ dest, prefix, nh, metric, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_route (s_ip, route);
+ nm_ip_route_unref (route);
}
@@ -494,8 +403,8 @@ test_write_wired_connection (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
const char *mac = "99:88:77:66:55:44";
gboolean success;
@@ -507,17 +416,16 @@ test_write_wired_connection (void)
const char *dns1 = "4.2.2.1";
const char *dns2 = "4.2.2.2";
const char *address1 = "192.168.0.5";
- const char *address1_gw = "192.168.0.1";
const char *address2 = "1.2.3.4";
- const char *address2_gw = "1.2.1.1";
+ const char *gw = "192.168.0.1";
const char *route1 = "10.10.10.2";
const char *route1_nh = "10.10.10.1";
const char *route2 = "1.1.1.1";
const char *route2_nh = "1.2.1.1";
const char *route3 = "2.2.2.2";
- const char *route3_nh = "0.0.0.0";
+ const char *route3_nh = NULL;
const char *route4 = "3.3.3.3";
- const char *route4_nh = "0.0.0.0";
+ const char *route4_nh = NULL;
const char *dns6_1 = "1::cafe";
const char *dns6_2 = "2::cafe";
const char *address6_1 = "abcd::beef";
@@ -561,52 +469,53 @@ test_write_wired_connection (void)
/* IP4 setting */
- s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
+ s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ());
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_GATEWAY, gw,
NULL);
/* Addresses */
- add_one_ip4_address (s_ip4, address1, address1_gw, 24);
- add_one_ip4_address (s_ip4, address2, address2_gw, 8);
+ add_one_ip_address (s_ip4, address1, 24);
+ add_one_ip_address (s_ip4, address2, 8);
/* Routes */
- add_one_ip4_route (s_ip4, route1, route1_nh, 24, 3);
- add_one_ip4_route (s_ip4, route2, route2_nh, 8, 1);
- add_one_ip4_route (s_ip4, route3, route3_nh, 7, 0);
- add_one_ip4_route (s_ip4, route4, route4_nh, 6, 4);
+ add_one_ip_route (s_ip4, route1, route1_nh, 24, 3);
+ add_one_ip_route (s_ip4, route2, route2_nh, 8, 1);
+ add_one_ip_route (s_ip4, route3, route3_nh, 7, -1);
+ add_one_ip_route (s_ip4, route4, route4_nh, 6, 4);
/* DNS servers */
- nm_setting_ip4_config_add_dns (s_ip4, dns1);
- nm_setting_ip4_config_add_dns (s_ip4, dns2);
+ nm_setting_ip_config_add_dns (s_ip4, dns1);
+ nm_setting_ip_config_add_dns (s_ip4, dns2);
/* IP6 setting */
- s_ip6 = NM_SETTING_IP6_CONFIG (nm_setting_ip6_config_new ());
+ s_ip6 = NM_SETTING_IP_CONFIG (nm_setting_ip6_config_new ());
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL,
NULL);
/* Addresses */
- add_one_ip6_address (s_ip6, address6_1, 64, NULL);
- add_one_ip6_address (s_ip6, address6_2, 56, NULL);
+ add_one_ip_address (s_ip6, address6_1, 64);
+ add_one_ip_address (s_ip6, address6_2, 56);
/* Routes */
- add_one_ip6_route (s_ip6, route6_1, route6_1_nh, 64, 3);
- add_one_ip6_route (s_ip6, route6_2, route6_2_nh, 56, 1);
- add_one_ip6_route (s_ip6, route6_3, route6_3_nh, 63, 5);
- add_one_ip6_route (s_ip6, route6_4, route6_4_nh, 62, 0);
+ add_one_ip_route (s_ip6, route6_1, route6_1_nh, 64, 3);
+ add_one_ip_route (s_ip6, route6_2, route6_2_nh, 56, 1);
+ add_one_ip_route (s_ip6, route6_3, route6_3_nh, 63, 5);
+ add_one_ip_route (s_ip6, route6_4, route6_4_nh, 62, -1);
/* DNS servers */
- nm_setting_ip6_config_add_dns (s_ip6, dns6_1);
- nm_setting_ip6_config_add_dns (s_ip6, dns6_2);
+ nm_setting_ip_config_add_dns (s_ip6, dns6_1);
+ nm_setting_ip_config_add_dns (s_ip6, dns6_2);
/* DNS searches */
- nm_setting_ip6_config_add_dns_search (s_ip6, "wallaceandgromit.com");
+ nm_setting_ip_config_add_dns_search (s_ip6, "wallaceandgromit.com");
/* Write out the connection */
owner_uid = geteuid ();
@@ -642,8 +551,8 @@ test_read_ip6_wired_connection (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
GError *error = NULL;
const char *tmp;
const char *expected_id = "Test Wired Connection IP6";
@@ -707,18 +616,18 @@ test_read_ip6_wired_connection (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip4_config_get_method (s_ip4);
+ tmp = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0,
"connection-verify-wired", "failed to verify %s: unexpected %s / %s key value",
TEST_WIRED_IP6_FILE,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
- ASSERT (nm_setting_ip4_config_get_num_addresses (s_ip4) == 0,
+ ASSERT (nm_setting_ip_config_get_num_addresses (s_ip4) == 0,
"connection-verify-wired", "failed to verify %s: unexpected %s / %s key value",
TEST_WIRED_IP6_FILE,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
+ NM_SETTING_IP_CONFIG_DNS);
/* ===== IPv6 SETTING ===== */
@@ -729,16 +638,23 @@ test_read_ip6_wired_connection (void)
NM_SETTING_IP6_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip6_config_get_method (s_ip6);
+ tmp = nm_setting_ip_config_get_method (s_ip6);
ASSERT (strcmp (tmp, NM_SETTING_IP6_CONFIG_METHOD_MANUAL) == 0,
"connection-verify-wired", "failed to verify %s: unexpected %s / %s key value",
TEST_WIRED_IP6_FILE,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
/* IPv6 address */
- g_assert (nm_setting_ip6_config_get_num_addresses (s_ip6) == 1);
- check_ip6_address (s_ip6, 0, "abcd:1234:ffff::cdde", 64, "abcd:1234:ffff::cdd1");
+ g_assert (nm_setting_ip_config_get_num_addresses (s_ip6) == 1);
+ check_ip_address (s_ip6, 0, "abcd:1234:ffff::cdde", 64);
+
+ /* IPv6 gateway */
+ ASSERT (strcmp (nm_setting_ip_config_get_gateway (s_ip6), "abcd:1234:ffff::cdd1") == 0,
+ "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value",
+ TEST_WIRED_IP6_FILE,
+ NM_SETTING_IP6_CONFIG_SETTING_NAME,
+ NM_SETTING_IP_CONFIG_GATEWAY);
g_object_unref (connection);
}
@@ -749,8 +665,8 @@ test_write_ip6_wired_connection (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
gboolean success;
NMConnection *reread;
@@ -785,30 +701,31 @@ test_write_ip6_wired_connection (void)
/* IP4 setting */
- s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
+ s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ());
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED,
NULL);
/* IP6 setting */
- s_ip6 = NM_SETTING_IP6_CONFIG (nm_setting_ip6_config_new ());
+ s_ip6 = NM_SETTING_IP_CONFIG (nm_setting_ip6_config_new ());
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_GATEWAY, gw,
NULL);
/* Addresses */
- add_one_ip6_address (s_ip6, address, 64, gw);
+ add_one_ip_address (s_ip6, address, 64);
/* DNS servers */
- nm_setting_ip6_config_add_dns (s_ip6, dns);
+ nm_setting_ip_config_add_dns (s_ip6, dns);
/* DNS searches */
- nm_setting_ip6_config_add_dns_search (s_ip6, "wallaceandgromit.com");
+ nm_setting_ip_config_add_dns_search (s_ip6, "wallaceandgromit.com");
/* Write out the connection */
owner_uid = geteuid ();
@@ -999,7 +916,7 @@ test_read_valid_wireless_connection (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWireless *s_wireless;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
GError *error = NULL;
const char *bssid;
const guint8 expected_bssid[ETH_ALEN] = { 0x00, 0x1a, 0x33, 0x44, 0x99, 0x82 };
@@ -1095,12 +1012,12 @@ test_read_valid_wireless_connection (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
- tmp = nm_setting_ip4_config_get_method (s_ip4);
+ tmp = nm_setting_ip_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0,
"connection-verify-wireless", "failed to verify %s: unexpected %s / %s key value",
TEST_WIRELESS_FILE,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_METHOD);
+ NM_SETTING_IP_CONFIG_METHOD);
g_object_unref (connection);
}
@@ -1111,8 +1028,8 @@ test_write_wireless_connection (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWireless *s_wireless;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
const char *bssid = "aa:b9:a1:74:55:44";
GBytes *ssid;
@@ -1159,20 +1076,20 @@ test_write_wireless_connection (void)
/* IP4 setting */
- s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
+ s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ());
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
NULL);
/* IP6 setting */
- s_ip6 = NM_SETTING_IP6_CONFIG (nm_setting_ip6_config_new ());
+ s_ip6 = NM_SETTING_IP_CONFIG (nm_setting_ip6_config_new ());
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
NULL);
/* Write out the connection */
@@ -1249,7 +1166,7 @@ test_write_string_ssid (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWireless *s_wireless;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
char *uuid, *testfile = NULL, *tmp;
GBytes *ssid;
unsigned char tmpssid[] = { 65, 49, 50, 51, 32, 46, 92, 46, 36, 37, 126, 93 };
@@ -1286,11 +1203,11 @@ test_write_string_ssid (void)
/* IP4 setting */
- s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
+ s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ());
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
NULL);
/* Write out the connection */
@@ -1372,7 +1289,7 @@ test_write_intlist_ssid (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
char *uuid, *testfile = NULL;
GBytes *ssid;
unsigned char tmpssid[] = { 65, 49, 50, 51, 0, 50, 50 };
@@ -1412,10 +1329,10 @@ test_write_intlist_ssid (void)
g_bytes_unref (ssid);
/* IP4 setting */
- s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
+ s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ());
g_assert (s_ip4);
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
/* Write out the connection */
owner_uid = geteuid ();
@@ -1533,7 +1450,7 @@ test_write_intlike_ssid (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
char *uuid, *testfile = NULL;
GBytes *ssid;
unsigned char tmpssid[] = { 49, 48, 49 };
@@ -1572,10 +1489,10 @@ test_write_intlike_ssid (void)
g_bytes_unref (ssid);
/* IP4 setting */
- s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
+ s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ());
g_assert (s_ip4);
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
/* Write out the connection */
owner_uid = geteuid ();
@@ -1619,7 +1536,7 @@ test_write_intlike_ssid_2 (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
char *uuid, *testfile = NULL;
GBytes *ssid;
unsigned char tmpssid[] = { 49, 49, 59, 49, 50, 59, 49, 51, 59};
@@ -1658,10 +1575,10 @@ test_write_intlike_ssid_2 (void)
g_bytes_unref (ssid);
/* IP4 setting */
- s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
+ s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ());
g_assert (s_ip4);
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
/* Write out the connection */
owner_uid = geteuid ();
@@ -1866,7 +1783,7 @@ test_write_bt_dun_connection (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingBluetooth *s_bt;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
NMSettingGsm *s_gsm;
char *uuid;
const char *bdaddr = "aa:b9:a1:74:55:44";
@@ -1907,11 +1824,11 @@ test_write_bt_dun_connection (void)
/* IP4 setting */
- s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
+ s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ());
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
NULL);
/* GSM setting */
@@ -2115,7 +2032,7 @@ test_write_gsm_connection (void)
{
NMConnection *connection;
NMSettingConnection *s_con;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
NMSettingGsm *s_gsm;
char *uuid;
gboolean success;
@@ -2145,11 +2062,11 @@ test_write_gsm_connection (void)
/* IP4 setting */
- s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
+ s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ());
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
NULL);
/* GSM setting */
@@ -2451,7 +2368,7 @@ create_wired_tls_connection (NMSetting8021xCKScheme scheme)
{
NMConnection *connection;
NMSettingConnection *s_con;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
NMSetting *s_wired;
NMSetting8021x *s_8021x;
char *uuid;
@@ -2475,9 +2392,9 @@ create_wired_tls_connection (NMSetting8021xCKScheme scheme)
g_free (uuid);
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
g_assert (s_ip4);
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
/* Wired setting */
@@ -2754,8 +2671,8 @@ test_write_infiniband_connection (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingInfiniband *s_ib;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
const char *mac = "99:88:77:66:55:44:ab:bc:cd:de:ef:f0:0a:1b:2c:3d:4e:5f:6f:ba";
gboolean success;
@@ -2795,16 +2712,16 @@ test_write_infiniband_connection (void)
NULL);
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
g_assert (s_ip4);
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
g_assert (s_ip6);
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
- g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL);
/* Write out the connection */
owner_uid = geteuid ();
@@ -2835,7 +2752,7 @@ test_read_bridge_main (void)
{
NMConnection *connection;
NMSettingConnection *s_con;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
NMSettingBridge *s_bridge;
GError *error = NULL;
const char *expected_id = "Test Bridge Main";
@@ -2859,7 +2776,7 @@ test_read_bridge_main (void)
/* IPv4 setting */
s_ip4 = nm_connection_get_setting_ip4_config (connection);
g_assert (s_ip4);
- g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
+ g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
/* Bridge setting */
s_bridge = nm_connection_get_setting_bridge (connection);
@@ -2880,8 +2797,8 @@ test_write_bridge_main (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingBridge *s_bridge;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ NMSettingIPConfig *s_ip6;
char *uuid;
gboolean success;
NMConnection *reread;
@@ -2914,21 +2831,22 @@ test_write_bridge_main (void)
nm_connection_add_setting (connection, NM_SETTING (s_bridge));
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
g_assert (s_ip4);
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
- NM_SETTING_IP4_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_GATEWAY, "1.1.1.1",
NULL);
- add_one_ip4_address (s_ip4, "1.2.3.4", "1.1.1.1", 24);
+ add_one_ip_address (s_ip4, "1.2.3.4", 24);
/* IP6 setting */
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
g_assert (s_ip6);
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
- g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL);
/* Write out the connection */
owner_uid = geteuid ();
@@ -3451,7 +3369,7 @@ static void
test_read_enum_property (void)
{
NMConnection *connection;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip6;
GError *error = NULL;
gboolean success;
@@ -3465,7 +3383,7 @@ test_read_enum_property (void)
/* IPv6 setting */
s_ip6 = nm_connection_get_setting_ip6_config (connection);
g_assert (s_ip6);
- g_assert_cmpint (nm_setting_ip6_config_get_ip6_privacy (s_ip6), ==, NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR);
+ g_assert_cmpint (nm_setting_ip6_config_get_ip6_privacy (NM_SETTING_IP6_CONFIG (s_ip6)), ==, NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR);
g_object_unref (connection);
}
@@ -3476,7 +3394,7 @@ test_write_enum_property (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip6;
char *uuid;
gboolean success;
NMConnection *reread;
@@ -3505,10 +3423,10 @@ test_write_enum_property (void)
nm_connection_add_setting (connection, NM_SETTING (s_wired));
/* IP6 setting */
- s_ip6 = NM_SETTING_IP6_CONFIG (nm_setting_ip6_config_new ());
+ s_ip6 = NM_SETTING_IP_CONFIG (nm_setting_ip6_config_new ());
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6,
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
NM_SETTING_IP6_CONFIG_IP6_PRIVACY, NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR,
NULL);
diff --git a/src/settings/plugins/keyfile/writer.c b/src/settings/plugins/keyfile/writer.c
index 17d4d9581a..02f2d7ff77 100644
--- a/src/settings/plugins/keyfile/writer.c
+++ b/src/settings/plugins/keyfile/writer.c
@@ -97,12 +97,12 @@ write_array_of_uint (GKeyFile *file,
}
static void
-ip4_dns_writer (GKeyFile *file,
- const char *keyfile_dir,
- const char *uuid,
- NMSetting *setting,
- const char *key,
- const GValue *value)
+dns_writer (GKeyFile *file,
+ const char *keyfile_dir,
+ const char *uuid,
+ NMSetting *setting,
+ const char *key,
+ const GValue *value)
{
char **list;
@@ -114,51 +114,60 @@ ip4_dns_writer (GKeyFile *file,
}
static void
-write_ip4_values (GKeyFile *file,
- const char *setting_name,
- GPtrArray *array,
- gboolean is_route)
+write_ip_values (GKeyFile *file,
+ const char *setting_name,
+ GPtrArray *array,
+ const char *gateway,
+ gboolean is_route)
{
GString *output;
- int i;
- guint32 addr, gw, plen, metric;
+ int family, i;
+ const char *addr, *gw;
+ guint32 plen, metric;
char key_name[30], *key_name_idx;
if (!array->len)
return;
+ family = !strcmp (setting_name, NM_SETTING_IP4_CONFIG_SETTING_NAME) ? AF_INET : AF_INET6;
+
strcpy (key_name, is_route ? "route" : "address");
key_name_idx = key_name + strlen (key_name);
output = g_string_sized_new (2*INET_ADDRSTRLEN + 10);
for (i = 0; i < array->len; i++) {
if (is_route) {
- NMIP4Route *route = array->pdata[i];
+ NMIPRoute *route = array->pdata[i];
- addr = nm_ip4_route_get_dest (route);
- plen = nm_ip4_route_get_prefix (route);
- gw = nm_ip4_route_get_next_hop (route);
- metric = nm_ip4_route_get_metric (route);
+ addr = nm_ip_route_get_dest (route);
+ plen = nm_ip_route_get_prefix (route);
+ gw = nm_ip_route_get_next_hop (route);
+ metric = MAX (0, nm_ip_route_get_metric (route));
} else {
- NMIP4Address *address = array->pdata[i];
+ NMIPAddress *address = array->pdata[i];
- addr = nm_ip4_address_get_address (address);
- plen = nm_ip4_address_get_prefix (address);
- gw = nm_ip4_address_get_gateway (address);
+ addr = nm_ip_address_get_address (address);
+ plen = nm_ip_address_get_prefix (address);
+ gw = i == 0 ? gateway : NULL;
metric = 0;
}
g_string_set_size (output, 0);
- g_string_append_printf (output, "%s/%u",
- nm_utils_inet4_ntop (addr, NULL),
- (unsigned) plen);
+ g_string_append_printf (output, "%s/%u", addr, plen);
if (metric || gw) {
/* Older versions of the plugin do not support the form
* "a.b.c.d/plen,,metric", so, we always have to write the
- * gateway, even if it's 0.0.0.0.
- * The current version support reading of the above form. */
- g_string_append_c (output, ',');
- g_string_append (output, nm_utils_inet4_ntop (gw, NULL));
+ * gateway, even if there isn't one.
+ * The current version supports reading of the above form.
+ */
+ if (!gw) {
+ if (family == AF_INET)
+ gw = "0.0.0.0";
+ else
+ gw = "::";
+ }
+
+ g_string_append_printf (output, ",%s", gw);
if (metric)
g_string_append_printf (output, ",%lu", (unsigned long) metric);
}
@@ -170,19 +179,20 @@ write_ip4_values (GKeyFile *file,
}
static void
-ip4_addr_writer (GKeyFile *file,
- const char *keyfile_dir,
- const char *uuid,
- NMSetting *setting,
- const char *key,
- const GValue *value)
+addr_writer (GKeyFile *file,
+ const char *keyfile_dir,
+ const char *uuid,
+ NMSetting *setting,
+ const char *key,
+ const GValue *value)
{
GPtrArray *array;
const char *setting_name = nm_setting_get_name (setting);
+ const char *gateway = nm_setting_ip_config_get_gateway (NM_SETTING_IP_CONFIG (setting));
array = (GPtrArray *) g_value_get_boxed (value);
if (array && array->len)
- write_ip4_values (file, setting_name, array, FALSE);
+ write_ip_values (file, setting_name, array, gateway, FALSE);
}
static void
@@ -197,154 +207,32 @@ ip4_addr_label_writer (GKeyFile *file,
}
static void
-ip4_route_writer (GKeyFile *file,
- const char *keyfile_dir,
- const char *uuid,
- NMSetting *setting,
- const char *key,
- const GValue *value)
-{
- GPtrArray *array;
- const char *setting_name = nm_setting_get_name (setting);
-
- array = (GPtrArray *) g_value_get_boxed (value);
- if (array && array->len)
- write_ip4_values (file, setting_name, array, TRUE);
-}
-
-static void
-ip6_dns_writer (GKeyFile *file,
+gateway_writer (GKeyFile *file,
const char *keyfile_dir,
const char *uuid,
NMSetting *setting,
const char *key,
const GValue *value)
{
- char **list;
-
- list = g_value_get_boxed (value);
- if (list && list[0]) {
- nm_keyfile_plugin_kf_set_string_list (file, nm_setting_get_name (setting), key,
- (const char **) list, g_strv_length (list));
- }
-}
-
-static char *
-ip6_values_to_addr_prefix (const struct in6_addr *addr, guint prefix, const struct in6_addr *gw,
- gboolean force_write_gateway)
-{
- GString *ip6_str;
- char buf[INET6_ADDRSTRLEN];
-
- /* address */
- nm_utils_inet6_ntop (addr, buf);
-
- /* Enough space for the address, '/', and the prefix */
- ip6_str = g_string_sized_new ((INET6_ADDRSTRLEN * 2) + 5);
-
- /* prefix */
- g_string_append (ip6_str, buf);
- g_string_append_printf (ip6_str, "/%u", prefix);
-
- /* gateway */
- nm_utils_inet6_ntop (gw, buf);
- if (force_write_gateway || !IN6_IS_ADDR_UNSPECIFIED (gw))
- g_string_append_printf (ip6_str, ",%s", buf);
-
- return g_string_free (ip6_str, FALSE);
-}
-
-static void
-ip6_addr_writer (GKeyFile *file,
- const char *keyfile_dir,
- const char *uuid,
- NMSetting *setting,
- const char *key,
- const GValue *value)
-{
- GPtrArray *array;
- const char *setting_name = nm_setting_get_name (setting);
- int i, j;
-
- array = (GPtrArray *) g_value_get_boxed (value);
- if (!array || !array->len)
- return;
-
- for (i = 0, j = 1; i < array->len; i++) {
- NMIP6Address *addr = array->pdata[i];
- char *key_name, *ip6_addr;
-
- ip6_addr = ip6_values_to_addr_prefix (nm_ip6_address_get_address (addr),
- nm_ip6_address_get_prefix (addr),
- nm_ip6_address_get_gateway (addr),
- /* we allow omitting the gateway if it's :: */
- FALSE);
- /* Write it out */
- key_name = g_strdup_printf ("address%d", j++);
- nm_keyfile_plugin_kf_set_string (file, setting_name, key_name, ip6_addr);
- g_free (key_name);
- g_free (ip6_addr);
- }
+ /* skip */
}
static void
-ip6_route_writer (GKeyFile *file,
- const char *keyfile_dir,
- const char *uuid,
- NMSetting *setting,
- const char *key,
- const GValue *value)
+route_writer (GKeyFile *file,
+ const char *keyfile_dir,
+ const char *uuid,
+ NMSetting *setting,
+ const char *key,
+ const GValue *value)
{
GPtrArray *array;
const char *setting_name = nm_setting_get_name (setting);
- GString *output;
- int i, j;
array = (GPtrArray *) g_value_get_boxed (value);
- if (!array || !array->len)
- return;
-
- for (i = 0, j = 1; i < array->len; i++) {
- NMIP6Route *route = array->pdata[i];
- char *key_name;
- char *addr_str;
- guint metric;
-
- output = g_string_new ("");
-
- /* Metric */
- metric = nm_ip6_route_get_metric (route);
-
- /* Address, prefix and next hop
- * We allow omitting the gateway ::, if we also omit the metric
- * and force writing of the gateway, if we add a non zero metric.
- * The current version of the reader also supports the syntax
- * "a:b:c::/plen,,metric" for a gateway ::.
- * As older versions of the plugin, cannot read this form,
- * we always write the gateway, whenever we also write the metric.
- * But if possible, we omit them both (",::,0") or only the metric
- * (",0").
- **/
- addr_str = ip6_values_to_addr_prefix (nm_ip6_route_get_dest (route),
- nm_ip6_route_get_prefix (route),
- nm_ip6_route_get_next_hop (route),
- metric != 0);
- g_string_append (output, addr_str);
- g_free (addr_str);
-
- if (metric != 0)
- g_string_append_printf (output, ",%u", metric);
-
- /* Write it out */
- key_name = g_strdup_printf ("route%d", j++);
- nm_keyfile_plugin_kf_set_string (file, setting_name, key_name, output->str);
- g_free (key_name);
-
- g_string_free (output, TRUE);
- }
+ if (array && array->len)
+ write_ip_values (file, setting_name, array, NULL, TRUE);
}
-
static void
write_hash_of_string (GKeyFile *file,
NMSetting *setting,
@@ -703,26 +591,32 @@ static KeyWriter key_writers[] = {
NM_SETTING_CONNECTION_TYPE,
setting_alias_writer },
{ NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_ADDRESSES,
- ip4_addr_writer },
+ NM_SETTING_IP_CONFIG_ADDRESSES,
+ addr_writer },
{ NM_SETTING_IP4_CONFIG_SETTING_NAME,
"address-labels",
ip4_addr_label_writer },
{ NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_ADDRESSES,
- ip6_addr_writer },
+ NM_SETTING_IP_CONFIG_ADDRESSES,
+ addr_writer },
+ { NM_SETTING_IP4_CONFIG_SETTING_NAME,
+ NM_SETTING_IP_CONFIG_GATEWAY,
+ gateway_writer },
+ { NM_SETTING_IP6_CONFIG_SETTING_NAME,
+ NM_SETTING_IP_CONFIG_GATEWAY,
+ gateway_writer },
{ NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_ROUTES,
- ip4_route_writer },
+ NM_SETTING_IP_CONFIG_ROUTES,
+ route_writer },
{ NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_ROUTES,
- ip6_route_writer },
+ NM_SETTING_IP_CONFIG_ROUTES,
+ route_writer },
{ NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS,
- ip4_dns_writer },
+ NM_SETTING_IP_CONFIG_DNS,
+ dns_writer },
{ NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS,
- ip6_dns_writer },
+ NM_SETTING_IP_CONFIG_DNS,
+ dns_writer },
{ NM_SETTING_WIRELESS_SETTING_NAME,
NM_SETTING_WIRELESS_SSID,
ssid_writer },
@@ -828,6 +722,12 @@ write_setting_value (NMSetting *setting,
numstr = g_strdup_printf ("%" G_GUINT64_FORMAT, g_value_get_uint64 (value));
nm_keyfile_plugin_kf_set_value (info->keyfile, setting_name, key, numstr);
g_free (numstr);
+ } else if (type == G_TYPE_INT64) {
+ char *numstr;
+
+ numstr = g_strdup_printf ("%" G_GINT64_FORMAT, g_value_get_int64 (value));
+ nm_keyfile_plugin_kf_set_value (info->keyfile, setting_name, key, numstr);
+ g_free (numstr);
} else if (type == G_TYPE_BOOLEAN) {
nm_keyfile_plugin_kf_set_boolean (info->keyfile, setting_name, key, g_value_get_boolean (value));
} else if (type == G_TYPE_CHAR) {
diff --git a/src/supplicant-manager/nm-supplicant-config.c b/src/supplicant-manager/nm-supplicant-config.c
index f4ee4c3a2c..2b857517a3 100644
--- a/src/supplicant-manager/nm-supplicant-config.c
+++ b/src/supplicant-manager/nm-supplicant-config.c
@@ -542,8 +542,8 @@ add_wep_key (NMSupplicantConfig *self,
const char *name,
NMWepKeyType wep_type)
{
- char *value;
- gboolean success;
+ GBytes *bytes;
+ gboolean success = FALSE;
size_t key_len = key ? strlen (key) : 0;
if (!key || !key_len)
@@ -552,9 +552,15 @@ add_wep_key (NMSupplicantConfig *self,
if ( (wep_type == NM_WEP_KEY_TYPE_UNKNOWN)
|| (wep_type == NM_WEP_KEY_TYPE_KEY)) {
if ((key_len == 10) || (key_len == 26)) {
- value = nm_utils_hexstr2bin (key, strlen (key));
- success = nm_supplicant_config_add_option (self, name, value, key_len / 2, TRUE);
- g_free (value);
+ bytes = nm_utils_hexstr2bin (key);
+ if (bytes) {
+ success = nm_supplicant_config_add_option (self,
+ name,
+ g_bytes_get_data (bytes, NULL),
+ g_bytes_get_size (bytes),
+ TRUE);
+ g_bytes_unref (bytes);
+ }
if (!success) {
nm_log_warn (LOGD_SUPPLICANT, "Error adding %s to supplicant config.", name);
return FALSE;
@@ -590,8 +596,7 @@ nm_supplicant_config_add_setting_wireless_security (NMSupplicantConfig *self,
NMSetting8021x *setting_8021x,
const char *con_uuid)
{
- char *value;
- gboolean success;
+ gboolean success = FALSE;
const char *key_mgmt, *auth_alg;
const char *psk;
@@ -612,10 +617,18 @@ nm_supplicant_config_add_setting_wireless_security (NMSupplicantConfig *self,
size_t psk_len = strlen (psk);
if (psk_len == 64) {
+ GBytes *bytes;
+
/* Hex PSK */
- value = nm_utils_hexstr2bin (psk, psk_len);
- success = nm_supplicant_config_add_option (self, "psk", value, psk_len / 2, TRUE);
- g_free (value);
+ bytes = nm_utils_hexstr2bin (psk);
+ if (bytes) {
+ success = nm_supplicant_config_add_option (self,
+ "psk",
+ g_bytes_get_data (bytes, NULL),
+ g_bytes_get_size (bytes),
+ TRUE);
+ g_bytes_unref (bytes);
+ }
if (!success) {
nm_log_warn (LOGD_SUPPLICANT, "Error adding 'psk' to supplicant config.");
return FALSE;
@@ -653,6 +666,7 @@ nm_supplicant_config_add_setting_wireless_security (NMSupplicantConfig *self,
const char *wep1 = nm_setting_wireless_security_get_wep_key (setting, 1);
const char *wep2 = nm_setting_wireless_security_get_wep_key (setting, 2);
const char *wep3 = nm_setting_wireless_security_get_wep_key (setting, 3);
+ char *value;
if (!add_wep_key (self, wep0, "wep_key0", wep_type))
return FALSE;
diff --git a/src/supplicant-manager/tests/test-supplicant-config.c b/src/supplicant-manager/tests/test-supplicant-config.c
index 2d16eecfd6..4f1950128f 100644
--- a/src/supplicant-manager/tests/test-supplicant-config.c
+++ b/src/supplicant-manager/tests/test-supplicant-config.c
@@ -108,7 +108,7 @@ test_wifi_open (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
NMSupplicantConfig *config;
GHashTable *hash;
char *uuid;
@@ -149,10 +149,10 @@ test_wifi_open (void)
g_bytes_unref (ssid);
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
"wifi-open", "failed to verify connection: %s",
@@ -203,7 +203,7 @@ test_wifi_wep_key (const char *detail,
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
NMSettingWirelessSecurity *s_wsec;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
NMSupplicantConfig *config;
GHashTable *hash;
char *uuid;
@@ -254,10 +254,10 @@ test_wifi_wep_key (const char *detail,
nm_setting_wireless_security_set_wep_key (s_wsec, 0, key_data);
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
detail, "failed to verify connection: %s",
@@ -340,7 +340,7 @@ test_wifi_wpa_psk (const char *detail,
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
NMSettingWirelessSecurity *s_wsec;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
NMSupplicantConfig *config;
GHashTable *hash;
char *uuid;
@@ -397,10 +397,10 @@ test_wifi_wpa_psk (const char *detail,
nm_setting_wireless_security_add_group (s_wsec, "ccmp");
/* IP4 setting */
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
detail, "failed to verify connection: %s",
diff --git a/src/tests/test-general.c b/src/tests/test-general.c
index e6bc207bd7..968a4bae87 100644
--- a/src/tests/test-general.c
+++ b/src/tests/test-general.c
@@ -288,8 +288,7 @@ _match_connection_new (void)
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip4, *s_ip6;
char *uuid;
connection = nm_simple_connection_new ();
@@ -308,16 +307,16 @@ _match_connection_new (void)
s_wired = (NMSettingWired *) nm_setting_wired_new ();
nm_connection_add_setting (connection, (NMSetting *) s_wired);
- s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, (NMSetting *) s_ip4);
g_object_set (G_OBJECT (s_ip4),
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
NULL);
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, (NMSetting *) s_ip6);
g_object_set (G_OBJECT (s_ip6),
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
NULL);
return connection;
@@ -328,7 +327,7 @@ test_connection_match_basic (void)
{
NMConnection *orig, *copy, *matched;
GSList *connections = NULL;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
orig = _match_connection_new ();
copy = nm_simple_connection_new_clone (orig);
@@ -341,7 +340,7 @@ test_connection_match_basic (void)
s_ip4 = nm_connection_get_setting_ip4_config (orig);
g_assert (s_ip4);
g_object_set (G_OBJECT (s_ip4),
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL,
NULL);
matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL);
g_assert (matched == NULL);
@@ -356,7 +355,7 @@ test_connection_match_ip6_method (void)
{
NMConnection *orig, *copy, *matched;
GSList *connections = NULL;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip6;
orig = _match_connection_new ();
copy = nm_simple_connection_new_clone (orig);
@@ -369,14 +368,14 @@ test_connection_match_ip6_method (void)
s_ip6 = nm_connection_get_setting_ip6_config (orig);
g_assert (s_ip6);
g_object_set (G_OBJECT (s_ip6),
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL,
NULL);
s_ip6 = nm_connection_get_setting_ip6_config (copy);
g_assert (s_ip6);
g_object_set (G_OBJECT (s_ip6),
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
- NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL);
@@ -392,7 +391,7 @@ test_connection_match_ip6_method_ignore (void)
{
NMConnection *orig, *copy, *matched;
GSList *connections = NULL;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip6;
orig = _match_connection_new ();
copy = nm_simple_connection_new_clone (orig);
@@ -404,13 +403,13 @@ test_connection_match_ip6_method_ignore (void)
s_ip6 = nm_connection_get_setting_ip6_config (orig);
g_assert (s_ip6);
g_object_set (G_OBJECT (s_ip6),
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL,
NULL);
s_ip6 = nm_connection_get_setting_ip6_config (copy);
g_assert (s_ip6);
g_object_set (G_OBJECT (s_ip6),
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
NULL);
matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL);
@@ -426,7 +425,7 @@ test_connection_match_ip6_method_ignore_auto (void)
{
NMConnection *orig, *copy, *matched;
GSList *connections = NULL;
- NMSettingIP6Config *s_ip6;
+ NMSettingIPConfig *s_ip6;
orig = _match_connection_new ();
copy = nm_simple_connection_new_clone (orig);
@@ -438,13 +437,13 @@ test_connection_match_ip6_method_ignore_auto (void)
s_ip6 = nm_connection_get_setting_ip6_config (orig);
g_assert (s_ip6);
g_object_set (G_OBJECT (s_ip6),
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
NULL);
s_ip6 = nm_connection_get_setting_ip6_config (copy);
g_assert (s_ip6);
g_object_set (G_OBJECT (s_ip6),
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
NULL);
matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL);
@@ -461,7 +460,7 @@ test_connection_match_ip4_method (void)
{
NMConnection *orig, *copy, *matched;
GSList *connections = NULL;
- NMSettingIP4Config *s_ip4;
+ NMSettingIPConfig *s_ip4;
orig = _match_connection_new ();
copy = nm_simple_connection_new_clone (orig);
@@ -474,14 +473,14 @@ test_connection_match_ip4_method (void)
s_ip4 = nm_connection_get_setting_ip4_config (orig);
g_assert (s_ip4);
g_object_set (G_OBJECT (s_ip4),
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED,
NULL);
s_ip4 = nm_connection_get_setting_ip4_config (copy);
g_assert (s_ip4);
g_object_set (G_OBJECT (s_ip4),
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
- NM_SETTING_IP4_CONFIG_MAY_FAIL, TRUE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NULL);
matched = nm_utils_match_connection (connections, orig, FALSE, NULL, NULL);
@@ -574,10 +573,9 @@ test_connection_no_match_ip4_addr (void)
{
NMConnection *orig, *copy, *matched;
GSList *connections = NULL;
- NMSettingIP4Config *s_ip4;
- NMSettingIP6Config *s_ip6;
- NMIP4Address *nm_addr;
- guint32 addr, gw;
+ NMSettingIPConfig *s_ip4, *s_ip6;
+ NMIPAddress *nm_addr;
+ GError *error = NULL;
orig = _match_connection_new ();
copy = nm_simple_connection_new_clone (orig);
@@ -589,43 +587,37 @@ test_connection_no_match_ip4_addr (void)
s_ip6 = nm_connection_get_setting_ip6_config (orig);
g_assert (s_ip6);
g_object_set (G_OBJECT (s_ip6),
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL,
NULL);
s_ip6 = nm_connection_get_setting_ip6_config (copy);
g_assert (s_ip6);
g_object_set (G_OBJECT (s_ip6),
- NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
NULL);
s_ip4 = nm_connection_get_setting_ip4_config (orig);
g_assert (s_ip4);
g_object_set (G_OBJECT (s_ip4),
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_GATEWAY, "1.1.1.254",
NULL);
- nm_addr = nm_ip4_address_new ();
- inet_pton (AF_INET, "1.1.1.4", &addr);
- inet_pton (AF_INET, "1.1.1.254", &gw);
- nm_ip4_address_set_address (nm_addr, addr);
- nm_ip4_address_set_prefix (nm_addr, 24);
- nm_ip4_address_set_gateway (nm_addr, gw);
- nm_setting_ip4_config_add_address (s_ip4, nm_addr);
- nm_ip4_address_unref (nm_addr);
+ nm_addr = nm_ip_address_new (AF_INET, "1.1.1.4", 24, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_address (s_ip4, nm_addr);
+ nm_ip_address_unref (nm_addr);
s_ip4 = nm_connection_get_setting_ip4_config (copy);
g_assert (s_ip4);
g_object_set (G_OBJECT (s_ip4),
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
+ NM_SETTING_IP_CONFIG_GATEWAY, "2.2.2.254",
NULL);
- nm_addr = nm_ip4_address_new ();
- inet_pton (AF_INET, "2.2.2.4", &addr);
- inet_pton (AF_INET, "2.2.2.254", &gw);
- nm_ip4_address_set_address (nm_addr, addr);
- nm_ip4_address_set_prefix (nm_addr, 24);
- nm_ip4_address_set_gateway (nm_addr, gw);
- nm_setting_ip4_config_add_address (s_ip4, nm_addr);
- nm_ip4_address_unref (nm_addr);
+ nm_addr = nm_ip_address_new (AF_INET, "2.2.2.4", 24, &error);
+ g_assert_no_error (error);
+ nm_setting_ip_config_add_address (s_ip4, nm_addr);
+ nm_ip_address_unref (nm_addr);
matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL);
g_assert (matched != copy);
diff --git a/src/tests/test-resolvconf-capture.c b/src/tests/test-resolvconf-capture.c
index 2d787b7188..555f10c016 100644
--- a/src/tests/test-resolvconf-capture.c
+++ b/src/tests/test-resolvconf-capture.c
@@ -20,6 +20,7 @@
#include <glib.h>
#include <string.h>
+#include <arpa/inet.h>
#include "NetworkManagerUtils.h"
#include "nm-ip4-config.h"
diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c
index a348ab7182..c581874880 100644
--- a/src/vpn-manager/nm-vpn-connection.c
+++ b/src/vpn-manager/nm-vpn-connection.c
@@ -41,6 +41,7 @@
#include "nm-dispatcher.h"
#include "nm-agent-manager.h"
#include "nm-core-internal.h"
+#include "nm-default-route-manager.h"
#include "nm-vpn-connection-glue.h"
@@ -234,6 +235,9 @@ vpn_cleanup (NMVpnConnection *connection, NMDevice *parent_dev)
nm_platform_address_flush (priv->ip_ifindex);
}
+ nm_default_route_manager_ip4_remove_default_route (nm_default_route_manager_get (), connection);
+ nm_default_route_manager_ip6_remove_default_route (nm_default_route_manager_get (), connection);
+
nm_device_set_vpn4_config (parent_dev, NULL);
nm_device_set_vpn6_config (parent_dev, NULL);
@@ -321,6 +325,11 @@ _set_vpn_state (NMVpnConnection *connection,
dispatcher_cleanup (connection);
+ if (vpn_state >= STATE_DISCONNECTED && vpn_state <= STATE_FAILED) {
+ nm_default_route_manager_ip4_remove_default_route (nm_default_route_manager_get (), connection);
+ nm_default_route_manager_ip6_remove_default_route (nm_default_route_manager_get (), connection);
+ }
+
/* The connection gets destroyed by the VPN manager when it enters the
* disconnected/failed state, but we need to keep it around for a bit
* to send out signals and handle the dispatcher. So ref it.
@@ -487,6 +496,7 @@ add_ip4_vpn_gateway_route (NMIP4Config *config, NMDevice *parent_device, guint32
NMIP4Config *parent_config;
guint32 parent_gw;
NMPlatformIP4Route route;
+ guint32 route_metric;
g_return_if_fail (NM_IS_IP4_CONFIG (config));
g_return_if_fail (NM_IS_DEVICE (parent_device));
@@ -502,6 +512,8 @@ add_ip4_vpn_gateway_route (NMIP4Config *config, NMDevice *parent_device, guint32
if (!parent_gw)
return;
+ route_metric = nm_device_get_ip4_route_metric (parent_device);
+
memset (&route, 0, sizeof (route));
route.network = vpn_gw;
route.plen = 32;
@@ -515,7 +527,7 @@ add_ip4_vpn_gateway_route (NMIP4Config *config, NMDevice *parent_device, guint32
route.gateway = 0;
route.source = NM_IP_CONFIG_SOURCE_VPN;
- route.metric = nm_device_get_priority (parent_device);
+ route.metric = route_metric;
nm_ip4_config_add_route (config, &route);
/* Ensure there's a route to the parent device's gateway through the
@@ -527,7 +539,7 @@ add_ip4_vpn_gateway_route (NMIP4Config *config, NMDevice *parent_device, guint32
route.network = parent_gw;
route.plen = 32;
route.source = NM_IP_CONFIG_SOURCE_VPN;
- route.metric = nm_device_get_priority (parent_device);
+ route.metric = route_metric;
nm_ip4_config_add_route (config, &route);
}
@@ -540,6 +552,7 @@ add_ip6_vpn_gateway_route (NMIP6Config *config,
NMIP6Config *parent_config;
const struct in6_addr *parent_gw;
NMPlatformIP6Route route;
+ guint32 route_metric;
g_return_if_fail (NM_IS_IP6_CONFIG (config));
g_return_if_fail (NM_IS_DEVICE (parent_device));
@@ -551,6 +564,8 @@ add_ip6_vpn_gateway_route (NMIP6Config *config,
if (!parent_gw)
return;
+ route_metric = nm_device_get_ip6_route_metric (parent_device);
+
memset (&route, 0, sizeof (route));
route.network = *vpn_gw;
route.plen = 128;
@@ -564,7 +579,7 @@ add_ip6_vpn_gateway_route (NMIP6Config *config,
route.gateway = in6addr_any;
route.source = NM_IP_CONFIG_SOURCE_VPN;
- route.metric = nm_device_get_priority (parent_device);
+ route.metric = route_metric;
nm_ip6_config_add_route (config, &route);
/* Ensure there's a route to the parent device's gateway through the
@@ -576,7 +591,7 @@ add_ip6_vpn_gateway_route (NMIP6Config *config,
route.network = *parent_gw;
route.plen = 128;
route.source = NM_IP_CONFIG_SOURCE_VPN;
- route.metric = nm_device_get_priority (parent_device);
+ route.metric = route_metric;
nm_ip6_config_add_route (config, &route);
}
@@ -936,6 +951,9 @@ nm_vpn_connection_apply_config (NMVpnConnection *connection)
apply_parent_device_config (connection);
+ nm_default_route_manager_ip4_update_default_route (nm_default_route_manager_get (), connection);
+ nm_default_route_manager_ip6_update_default_route (nm_default_route_manager_get (), connection);
+
nm_log_info (LOGD_VPN, "VPN connection '%s' (IP Config Get) complete.",
nm_connection_get_id (priv->connection));
_set_vpn_state (connection, STATE_PRE_UP, NM_VPN_CONNECTION_STATE_REASON_NONE, FALSE);
@@ -959,7 +977,7 @@ nm_vpn_connection_config_maybe_complete (NMVpnConnection *connection,
}
}
- if (priv->connect_timeout == 0) {
+ if (priv->connect_timeout) {
g_source_remove (priv->connect_timeout);
priv->connect_timeout = 0;
}
@@ -1104,18 +1122,44 @@ nm_vpn_connection_config_get (DBusGProxy *proxy,
g_clear_object (&priv->ip6_config);
}
-static guint
-vpn_routing_metric (NMVpnConnection *connection)
+guint32
+nm_vpn_connection_get_ip4_route_metric (NMVpnConnection *connection)
+{
+ NMDevice *parent_dev;
+ NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);
+
+ if (priv->connection) {
+ gint64 route_metric = nm_setting_ip_config_get_route_metric (nm_connection_get_setting_ip4_config (priv->connection));
+
+ if (route_metric >= 0)
+ return route_metric;
+ }
+
+ if ( priv->ip_ifindex
+ || !(parent_dev = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (connection))))
+ return NM_VPN_ROUTE_METRIC_DEFAULT;
+
+ return nm_device_get_ip4_route_metric (parent_dev);
+}
+
+guint32
+nm_vpn_connection_get_ip6_route_metric (NMVpnConnection *connection)
{
+ NMDevice *parent_dev;
NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);
- if (priv->ip_ifindex)
- return NM_PLATFORM_ROUTE_METRIC_DEFAULT;
- else {
- NMDevice *parent_dev = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (connection));
+ if (priv->connection) {
+ gint64 route_metric = nm_setting_ip_config_get_route_metric (nm_connection_get_setting_ip6_config (priv->connection));
- return nm_device_get_priority (parent_dev);
+ if (route_metric >= 0)
+ return route_metric;
}
+
+ if ( priv->ip_ifindex
+ || !(parent_dev = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (connection))))
+ return NM_VPN_ROUTE_METRIC_DEFAULT;
+
+ return nm_device_get_ip6_route_metric (parent_dev);
}
static void
@@ -1129,6 +1173,7 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy,
NMIP4Config *config;
GValue *val;
int i;
+ guint32 route_metric;
if (priv->vpn_state == STATE_CONNECT)
_set_vpn_state (connection, STATE_IP_CONFIG_GET, NM_VPN_CONNECTION_STATE_REASON_NONE, FALSE);
@@ -1226,6 +1271,8 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy,
nm_ip4_config_add_domain (config, *domain);
}
+ route_metric = nm_vpn_connection_get_ip4_route_metric (connection);
+
val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP4_CONFIG_ROUTES);
if (val) {
GSList *routes;
@@ -1233,15 +1280,15 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy,
routes = nm_utils_ip4_routes_from_gvalue (val);
for (iter = routes; iter; iter = iter->next) {
- NMIP4Route *item = iter->data;
+ NMIPRoute *item = iter->data;
NMPlatformIP4Route route;
memset (&route, 0, sizeof (route));
- route.network = nm_ip4_route_get_dest (item);
- route.plen = nm_ip4_route_get_prefix (item);
- route.gateway = nm_ip4_route_get_next_hop (item);
+ nm_ip_route_get_dest_binary (item, &route.network);
+ route.plen = nm_ip_route_get_prefix (item);
+ nm_ip_route_get_next_hop_binary (item, &route.gateway);
route.source = NM_IP_CONFIG_SOURCE_VPN;
- route.metric = vpn_routing_metric (connection);
+ route.metric = route_metric;
/* Ignore host routes to the VPN gateway since NM adds one itself
* below. Since NM knows more about the routing situation than
@@ -1255,7 +1302,7 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy,
nm_ip4_config_add_route (config, &route);
}
- g_slist_free_full (routes, (GDestroyNotify) nm_ip4_route_unref);
+ g_slist_free_full (routes, (GDestroyNotify) nm_ip_route_unref);
}
val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP4_CONFIG_NEVER_DEFAULT);
@@ -1265,7 +1312,7 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy,
/* Merge in user overrides from the NMConnection's IPv4 setting */
nm_ip4_config_merge_setting (config,
nm_connection_get_setting_ip4_config (priv->connection),
- vpn_routing_metric (connection));
+ route_metric);
g_clear_object (&priv->ip4_config);
priv->ip4_config = config;
@@ -1285,6 +1332,7 @@ nm_vpn_connection_ip6_config_get (DBusGProxy *proxy,
NMIP6Config *config;
GValue *val;
int i;
+ guint32 route_metric;
nm_log_info (LOGD_VPN, "VPN connection '%s' (IP6 Config Get) reply received.",
nm_connection_get_id (priv->connection));
@@ -1373,6 +1421,8 @@ nm_vpn_connection_ip6_config_get (DBusGProxy *proxy,
nm_ip6_config_add_domain (config, *domain);
}
+ route_metric = nm_vpn_connection_get_ip6_route_metric (connection);
+
val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP6_CONFIG_ROUTES);
if (val) {
GSList *routes;
@@ -1380,15 +1430,15 @@ nm_vpn_connection_ip6_config_get (DBusGProxy *proxy,
routes = nm_utils_ip6_routes_from_gvalue (val);
for (iter = routes; iter; iter = iter->next) {
- NMIP6Route *item = iter->data;
+ NMIPRoute *item = iter->data;
NMPlatformIP6Route route;
memset (&route, 0, sizeof (route));
- route.network = *nm_ip6_route_get_dest (item);
- route.plen = nm_ip6_route_get_prefix (item);
- route.gateway = *nm_ip6_route_get_next_hop (item);
+ nm_ip_route_get_dest_binary (item, &route.network);
+ route.plen = nm_ip_route_get_prefix (item);
+ nm_ip_route_get_next_hop_binary (item, &route.gateway);
route.source = NM_IP_CONFIG_SOURCE_VPN;
- route.metric = vpn_routing_metric (connection);
+ route.metric = route_metric;
/* Ignore host routes to the VPN gateway since NM adds one itself
* below. Since NM knows more about the routing situation than
@@ -1402,7 +1452,7 @@ nm_vpn_connection_ip6_config_get (DBusGProxy *proxy,
nm_ip6_config_add_route (config, &route);
}
- g_slist_free_full (routes, (GDestroyNotify) nm_ip6_route_unref);
+ g_slist_free_full (routes, (GDestroyNotify) nm_ip_route_unref);
}
val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP6_CONFIG_NEVER_DEFAULT);
@@ -1412,7 +1462,7 @@ nm_vpn_connection_ip6_config_get (DBusGProxy *proxy,
/* Merge in user overrides from the NMConnection's IPv6 setting */
nm_ip6_config_merge_setting (config,
nm_connection_get_setting_ip6_config (priv->connection),
- vpn_routing_metric (connection));
+ route_metric);
g_clear_object (&priv->ip6_config);
priv->ip6_config = config;
@@ -1665,6 +1715,17 @@ nm_vpn_connection_get_connection (NMVpnConnection *connection)
return NM_VPN_CONNECTION_GET_PRIVATE (connection)->connection;
}
+const char*
+nm_vpn_connection_get_connection_id (NMVpnConnection *connection)
+{
+ NMConnection *c;
+
+ g_return_val_if_fail (NM_IS_VPN_CONNECTION (connection), NULL);
+
+ c = NM_VPN_CONNECTION_GET_PRIVATE (connection)->connection;
+ return c ? nm_connection_get_id (c) : NULL;
+}
+
NMVpnConnectionState
nm_vpn_connection_get_vpn_state (NMVpnConnection *connection)
{
diff --git a/src/vpn-manager/nm-vpn-connection.h b/src/vpn-manager/nm-vpn-connection.h
index 74ea38a5db..c444bc13db 100644
--- a/src/vpn-manager/nm-vpn-connection.h
+++ b/src/vpn-manager/nm-vpn-connection.h
@@ -46,9 +46,12 @@
#define NM_VPN_CONNECTION_INTERNAL_RETRY_AFTER_FAILURE "internal-retry-after-failure"
-typedef struct {
+#define NM_VPN_ROUTE_METRIC_DEFAULT 10
+
+
+struct _NMVpnConnection {
NMActiveConnection parent;
-} NMVpnConnection;
+};
typedef struct {
NMActiveConnectionClass parent;
@@ -76,6 +79,7 @@ NMVpnConnection * nm_vpn_connection_new (NMConnection *connection,
void nm_vpn_connection_activate (NMVpnConnection *connection);
NMConnection * nm_vpn_connection_get_connection (NMVpnConnection *connection);
+const char* nm_vpn_connection_get_connection_id (NMVpnConnection *connection);
NMVpnConnectionState nm_vpn_connection_get_vpn_state (NMVpnConnection *connection);
const char * nm_vpn_connection_get_banner (NMVpnConnection *connection);
@@ -93,4 +97,7 @@ int nm_vpn_connection_get_ip_ifindex (NMVpnConnection *connect
guint32 nm_vpn_connection_get_ip4_internal_gateway (NMVpnConnection *connection);
struct in6_addr * nm_vpn_connection_get_ip6_internal_gateway (NMVpnConnection *connection);
+guint32 nm_vpn_connection_get_ip4_route_metric (NMVpnConnection *connection);
+guint32 nm_vpn_connection_get_ip6_route_metric (NMVpnConnection *connection);
+
#endif /* __NETWORKMANAGER_VPN_CONNECTION_H__ */