From 2f94dba7385fd0e0ef19a06eb4a2fcf6c43d7946 Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Mon, 14 Feb 2022 19:23:28 +0100 Subject: New upstream version 1.35.91 --- src/core/NetworkManagerUtils.c | 358 +- src/core/NetworkManagerUtils.h | 70 +- src/core/devices/adsl/nm-atm-manager.c | 38 +- src/core/devices/adsl/nm-device-adsl.c | 373 +- src/core/devices/bluetooth/nm-bluez-manager.c | 320 +- src/core/devices/bluetooth/nm-bluez-manager.h | 12 +- src/core/devices/bluetooth/nm-bluez5-dun.c | 48 +- src/core/devices/bluetooth/nm-bluez5-dun.h | 12 +- src/core/devices/bluetooth/nm-device-bt.c | 225 +- src/core/devices/bluetooth/nm-device-bt.h | 14 +- src/core/devices/bluetooth/tests/nm-bt-test.c | 18 +- src/core/devices/nm-acd-manager.c | 497 - src/core/devices/nm-acd-manager.h | 34 - src/core/devices/nm-device-6lowpan.c | 34 +- src/core/devices/nm-device-bond.c | 77 +- src/core/devices/nm-device-bridge.c | 120 +- src/core/devices/nm-device-dummy.c | 29 +- src/core/devices/nm-device-ethernet.c | 641 +- src/core/devices/nm-device-factory.c | 50 +- src/core/devices/nm-device-factory.h | 40 +- src/core/devices/nm-device-generic.c | 12 +- src/core/devices/nm-device-infiniband.c | 41 +- src/core/devices/nm-device-ip-tunnel.c | 75 +- src/core/devices/nm-device-macsec.c | 122 +- src/core/devices/nm-device-macvlan.c | 57 +- src/core/devices/nm-device-ppp.c | 288 +- src/core/devices/nm-device-private.h | 139 +- src/core/devices/nm-device-tun.c | 51 +- src/core/devices/nm-device-utils.c | 25 +- src/core/devices/nm-device-utils.h | 13 +- src/core/devices/nm-device-veth.c | 24 +- src/core/devices/nm-device-vlan.c | 84 +- src/core/devices/nm-device-vrf.c | 42 +- src/core/devices/nm-device-vxlan.c | 49 +- src/core/devices/nm-device-wireguard.c | 261 +- src/core/devices/nm-device-wpan.c | 31 +- src/core/devices/nm-device.c | 9677 +++++++++----------- src/core/devices/nm-device.h | 231 +- src/core/devices/nm-lldp-listener.c | 70 +- src/core/devices/nm-lldp-listener.h | 2 +- src/core/devices/ovs/nm-device-ovs-bridge.c | 28 +- src/core/devices/ovs/nm-device-ovs-interface.c | 100 +- src/core/devices/ovs/nm-device-ovs-port.c | 51 +- src/core/devices/ovs/nm-ovs-factory.c | 62 +- src/core/devices/ovs/nm-ovsdb.c | 339 +- src/core/devices/ovs/nm-ovsdb.h | 26 +- src/core/devices/team/nm-device-team.c | 145 +- src/core/devices/team/nm-team-factory.c | 10 +- src/core/devices/tests/meson.build | 1 - src/core/devices/tests/test-acd.c | 259 - src/core/devices/tests/test-lldp.c | 32 +- src/core/devices/wifi/meson.build | 1 + src/core/devices/wifi/nm-device-iwd-p2p.c | 1262 +++ src/core/devices/wifi/nm-device-iwd-p2p.h | 36 + src/core/devices/wifi/nm-device-iwd.c | 462 +- src/core/devices/wifi/nm-device-iwd.h | 4 +- src/core/devices/wifi/nm-device-olpc-mesh.c | 46 +- src/core/devices/wifi/nm-device-wifi-p2p.c | 212 +- src/core/devices/wifi/nm-device-wifi.c | 559 +- src/core/devices/wifi/nm-device-wifi.h | 4 +- src/core/devices/wifi/nm-iwd-manager.c | 497 +- src/core/devices/wifi/nm-iwd-manager.h | 40 +- src/core/devices/wifi/nm-wifi-ap.c | 48 +- src/core/devices/wifi/nm-wifi-ap.h | 14 +- src/core/devices/wifi/nm-wifi-common.c | 44 +- src/core/devices/wifi/nm-wifi-factory.c | 77 +- src/core/devices/wifi/nm-wifi-p2p-peer.c | 128 +- src/core/devices/wifi/nm-wifi-p2p-peer.h | 21 +- src/core/devices/wifi/nm-wifi-utils.c | 256 +- src/core/devices/wifi/nm-wifi-utils.h | 25 +- src/core/devices/wifi/tests/test-devices-wifi.c | 122 +- src/core/devices/wwan/libnm-wwan.ver | 5 +- src/core/devices/wwan/nm-device-modem.c | 296 +- src/core/devices/wwan/nm-modem-broadband.c | 606 +- src/core/devices/wwan/nm-modem-manager.c | 92 +- src/core/devices/wwan/nm-modem-ofono.c | 278 +- src/core/devices/wwan/nm-modem.c | 985 +- src/core/devices/wwan/nm-modem.h | 137 +- src/core/devices/wwan/nm-service-providers.c | 82 +- src/core/devices/wwan/nm-service-providers.h | 18 +- src/core/devices/wwan/nm-wwan-factory.c | 20 +- .../devices/wwan/tests/test-service-providers.c | 36 +- src/core/dhcp/nm-dhcp-client-logging.h | 4 +- src/core/dhcp/nm-dhcp-client.c | 1331 ++- src/core/dhcp/nm-dhcp-client.h | 265 +- src/core/dhcp/nm-dhcp-dhclient-utils.c | 91 +- src/core/dhcp/nm-dhcp-dhclient-utils.h | 18 +- src/core/dhcp/nm-dhcp-dhclient.c | 209 +- src/core/dhcp/nm-dhcp-dhcpcanon.c | 42 +- src/core/dhcp/nm-dhcp-dhcpcd.c | 30 +- src/core/dhcp/nm-dhcp-helper.c | 20 +- src/core/dhcp/nm-dhcp-listener.c | 32 +- src/core/dhcp/nm-dhcp-manager.c | 382 +- src/core/dhcp/nm-dhcp-manager.h | 48 +- src/core/dhcp/nm-dhcp-nettools.c | 420 +- src/core/dhcp/nm-dhcp-options.c | 23 +- src/core/dhcp/nm-dhcp-options.h | 5 +- src/core/dhcp/nm-dhcp-systemd.c | 513 +- src/core/dhcp/nm-dhcp-utils.c | 367 +- src/core/dhcp/nm-dhcp-utils.h | 35 +- src/core/dhcp/tests/test-dhcp-dhclient.c | 45 +- src/core/dhcp/tests/test-dhcp-utils.c | 581 +- src/core/dns/nm-dns-dnsmasq.c | 109 +- src/core/dns/nm-dns-manager.c | 784 +- src/core/dns/nm-dns-manager.h | 20 +- src/core/dns/nm-dns-plugin.c | 8 +- src/core/dns/nm-dns-plugin.h | 16 +- src/core/dns/nm-dns-systemd-resolved.c | 193 +- src/core/dns/nm-dns-systemd-resolved.h | 10 +- src/core/dns/nm-dns-unbound.c | 12 +- src/core/dnsmasq/nm-dnsmasq-manager.c | 73 +- src/core/dnsmasq/nm-dnsmasq-manager.h | 10 +- src/core/dnsmasq/nm-dnsmasq-utils.c | 6 +- src/core/dnsmasq/nm-dnsmasq-utils.h | 6 +- src/core/main-utils.c | 25 +- src/core/main-utils.h | 11 +- src/core/main.c | 40 +- src/core/meson.build | 41 +- src/core/ndisc/nm-fake-ndisc.c | 90 +- src/core/ndisc/nm-fake-ndisc.h | 18 +- src/core/ndisc/nm-lndp-ndisc.c | 112 +- src/core/ndisc/nm-lndp-ndisc.h | 13 +- src/core/ndisc/nm-ndisc-private.h | 2 +- src/core/ndisc/nm-ndisc.c | 587 +- src/core/ndisc/nm-ndisc.h | 66 +- src/core/ndisc/tests/test-ndisc-fake.c | 138 +- src/core/ndisc/tests/test-ndisc-linux.c | 55 +- src/core/nm-act-request.c | 88 +- src/core/nm-act-request.h | 30 +- src/core/nm-active-connection.c | 84 +- src/core/nm-active-connection.h | 33 +- src/core/nm-audit-manager.c | 86 +- src/core/nm-audit-manager.h | 34 +- src/core/nm-auth-manager.c | 80 +- src/core/nm-auth-manager.h | 10 +- src/core/nm-auth-utils.c | 36 +- src/core/nm-auth-utils.h | 20 +- src/core/nm-checkpoint-manager.c | 30 +- src/core/nm-checkpoint-manager.h | 18 +- src/core/nm-checkpoint.c | 76 +- src/core/nm-checkpoint.h | 6 +- src/core/nm-config-data.c | 250 +- src/core/nm-config-data.h | 95 +- src/core/nm-config.c | 326 +- src/core/nm-config.h | 49 +- src/core/nm-connectivity.c | 81 +- src/core/nm-connectivity.h | 8 +- src/core/nm-core-utils.c | 290 +- src/core/nm-core-utils.h | 134 +- src/core/nm-dbus-manager.c | 222 +- src/core/nm-dbus-manager.h | 42 +- src/core/nm-dbus-object.c | 14 +- src/core/nm-dbus-object.h | 14 +- src/core/nm-dbus-utils.c | 20 +- src/core/nm-dbus-utils.h | 26 +- src/core/nm-dcb.c | 18 +- src/core/nm-dcb.h | 12 +- src/core/nm-dhcp-config.c | 99 +- src/core/nm-dhcp-config.h | 5 +- src/core/nm-dispatcher.c | 263 +- src/core/nm-dispatcher.h | 30 +- src/core/nm-firewall-utils.c | 40 +- src/core/nm-firewalld-manager.c | 76 +- src/core/nm-firewalld-manager.h | 16 +- src/core/nm-hostname-manager.c | 129 +- src/core/nm-hostname-manager.h | 8 +- src/core/nm-iface-helper.c | 857 -- src/core/nm-ip-config.c | 857 +- src/core/nm-ip-config.h | 60 +- src/core/nm-ip4-config.c | 3337 ------- src/core/nm-ip4-config.h | 673 -- src/core/nm-ip6-config.c | 2675 ------ src/core/nm-ip6-config.h | 205 - src/core/nm-keep-alive.c | 30 +- src/core/nm-keep-alive.h | 6 +- src/core/nm-l3-config-data.c | 539 +- src/core/nm-l3-config-data.h | 90 +- src/core/nm-l3-ipv4ll.c | 28 +- src/core/nm-l3-ipv6ll.c | 24 +- src/core/nm-l3-ipv6ll.h | 21 +- src/core/nm-l3cfg.c | 753 +- src/core/nm-l3cfg.h | 55 +- src/core/nm-manager.c | 1256 ++- src/core/nm-manager.h | 52 +- src/core/nm-netns.c | 80 +- src/core/nm-netns.h | 10 +- src/core/nm-pacrunner-manager.c | 149 +- src/core/nm-pacrunner-manager.h | 7 +- src/core/nm-policy.c | 655 +- src/core/nm-priv-helper-call.c | 12 +- src/core/nm-priv-helper-call.h | 2 +- src/core/nm-proxy-config.c | 172 - src/core/nm-proxy-config.h | 41 - src/core/nm-rfkill-manager.c | 34 +- src/core/nm-session-monitor.c | 16 +- src/core/nm-sleep-monitor.c | 14 +- src/core/nm-test-utils-core.h | 32 +- src/core/nm-types.h | 9 +- src/core/platform/nm-fake-platform.c | 131 +- src/core/platform/tests/test-address.c | 26 +- src/core/platform/tests/test-cleanup.c | 12 +- src/core/platform/tests/test-common.c | 134 +- src/core/platform/tests/test-common.h | 88 +- src/core/platform/tests/test-link.c | 136 +- src/core/platform/tests/test-nmp-object.c | 52 +- src/core/platform/tests/test-platform-general.c | 42 +- src/core/platform/tests/test-route.c | 388 +- src/core/platform/tests/test-tc.c | 24 +- src/core/ppp/nm-ppp-manager-call.c | 32 +- src/core/ppp/nm-ppp-manager-call.h | 14 +- src/core/ppp/nm-ppp-manager.c | 436 +- src/core/ppp/nm-ppp-manager.h | 5 +- src/core/ppp/nm-ppp-mgr.c | 620 ++ src/core/ppp/nm-ppp-mgr.h | 131 + src/core/ppp/nm-ppp-plugin-api.h | 14 +- src/core/ppp/nm-ppp-status.h | 5 +- src/core/ppp/nm-pppd-plugin.c | 12 +- src/core/settings/nm-agent-manager.c | 202 +- src/core/settings/nm-agent-manager.h | 44 +- src/core/settings/nm-secret-agent.c | 116 +- src/core/settings/nm-secret-agent.h | 36 +- src/core/settings/nm-settings-connection.c | 392 +- src/core/settings/nm-settings-connection.h | 62 +- src/core/settings/nm-settings-plugin.c | 30 +- src/core/settings/nm-settings-plugin.h | 64 +- src/core/settings/nm-settings-storage.h | 6 +- src/core/settings/nm-settings-utils.c | 8 +- src/core/settings/nm-settings.c | 579 +- src/core/settings/nm-settings.h | 44 +- .../plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c | 208 +- .../plugins/ifcfg-rh/nms-ifcfg-rh-reader.c | 754 +- .../plugins/ifcfg-rh/nms-ifcfg-rh-reader.h | 10 +- .../plugins/ifcfg-rh/nms-ifcfg-rh-storage.c | 14 +- .../plugins/ifcfg-rh/nms-ifcfg-rh-storage.h | 12 +- .../settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c | 14 +- .../settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h | 8 +- .../plugins/ifcfg-rh/nms-ifcfg-rh-writer.c | 370 +- .../plugins/ifcfg-rh/nms-ifcfg-rh-writer.h | 12 +- src/core/settings/plugins/ifcfg-rh/shvar.c | 46 +- src/core/settings/plugins/ifcfg-rh/shvar.h | 4 +- .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 1668 ++-- .../ifupdown/nms-ifupdown-interface-parser.c | 10 +- .../ifupdown/nms-ifupdown-interface-parser.h | 4 +- .../plugins/ifupdown/nms-ifupdown-parser.c | 70 +- .../plugins/ifupdown/nms-ifupdown-plugin.c | 40 +- .../plugins/ifupdown/tests/test-ifupdown.c | 100 +- .../settings/plugins/keyfile/nms-keyfile-plugin.c | 258 +- .../settings/plugins/keyfile/nms-keyfile-plugin.h | 30 +- .../settings/plugins/keyfile/nms-keyfile-reader.c | 40 +- .../settings/plugins/keyfile/nms-keyfile-reader.h | 20 +- .../settings/plugins/keyfile/nms-keyfile-storage.c | 28 +- .../settings/plugins/keyfile/nms-keyfile-storage.h | 18 +- .../settings/plugins/keyfile/nms-keyfile-utils.c | 42 +- .../settings/plugins/keyfile/nms-keyfile-utils.h | 32 +- .../settings/plugins/keyfile/nms-keyfile-writer.c | 98 +- .../settings/plugins/keyfile/nms-keyfile-writer.h | 28 +- .../plugins/keyfile/tests/test-keyfile-settings.c | 534 +- src/core/supplicant/nm-supplicant-config.c | 172 +- src/core/supplicant/nm-supplicant-config.h | 20 +- src/core/supplicant/nm-supplicant-interface.c | 441 +- src/core/supplicant/nm-supplicant-interface.h | 38 +- src/core/supplicant/nm-supplicant-manager.c | 170 +- src/core/supplicant/nm-supplicant-manager.h | 16 +- .../supplicant/nm-supplicant-settings-verify.c | 4 +- src/core/supplicant/nm-supplicant-types.h | 4 +- src/core/supplicant/tests/test-supplicant-config.c | 196 +- src/core/tests/config/nm-test-device.c | 2 +- src/core/tests/config/test-config.c | 192 +- src/core/tests/meson.build | 2 - src/core/tests/test-core-with-expect.c | 12 +- src/core/tests/test-core.c | 142 +- src/core/tests/test-dcb.c | 20 +- src/core/tests/test-ip4-config.c | 380 - src/core/tests/test-ip6-config.c | 538 -- src/core/tests/test-l3cfg.c | 87 +- src/core/tests/test-systemd.c | 14 +- src/core/tests/test-utils.c | 12 +- src/core/tests/test-wired-defname.c | 8 +- src/core/vpn/nm-vpn-connection.c | 4012 ++++---- src/core/vpn/nm-vpn-connection.h | 25 +- src/core/vpn/nm-vpn-manager.c | 36 +- 281 files changed, 25992 insertions(+), 33233 deletions(-) delete mode 100644 src/core/devices/nm-acd-manager.c delete mode 100644 src/core/devices/nm-acd-manager.h delete mode 100644 src/core/devices/tests/test-acd.c create mode 100644 src/core/devices/wifi/nm-device-iwd-p2p.c create mode 100644 src/core/devices/wifi/nm-device-iwd-p2p.h delete mode 100644 src/core/nm-iface-helper.c delete mode 100644 src/core/nm-ip4-config.c delete mode 100644 src/core/nm-ip4-config.h delete mode 100644 src/core/nm-ip6-config.c delete mode 100644 src/core/nm-ip6-config.h delete mode 100644 src/core/nm-proxy-config.c delete mode 100644 src/core/nm-proxy-config.h create mode 100644 src/core/ppp/nm-ppp-mgr.c create mode 100644 src/core/ppp/nm-ppp-mgr.h delete mode 100644 src/core/tests/test-ip4-config.c delete mode 100644 src/core/tests/test-ip6-config.c (limited to 'src/core') diff --git a/src/core/NetworkManagerUtils.c b/src/core/NetworkManagerUtils.c index 0da8e0a9..c50dbada 100644 --- a/src/core/NetworkManagerUtils.c +++ b/src/core/NetworkManagerUtils.c @@ -28,6 +28,7 @@ #include "libnm-platform/nm-platform.h" #include "libnm-platform/nm-linux-platform.h" +#include "libnm-platform/nm-platform-utils.h" #include "nm-auth-utils.h" #include "libnm-systemd-shared/nm-sd-utils-shared.h" @@ -42,9 +43,9 @@ const char * nm_utils_get_shared_wifi_permission(NMConnection *connection) { - NMSettingWireless * s_wifi; + NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; - const char * method; + const char *method; method = nm_utils_get_ip_config_method(connection, AF_INET); if (!nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)) @@ -66,8 +67,8 @@ nm_utils_get_shared_wifi_permission(NMConnection *connection) static char * get_new_connection_name(NMConnection *const *existing_connections, - const char * preferred, - const char * fallback_prefix) + const char *preferred, + const char *fallback_prefix) { gs_free const char **existing_names = NULL; guint i, existing_len = 0; @@ -79,7 +80,7 @@ get_new_connection_name(NMConnection *const *existing_connections, existing_names = g_new(const char *, existing_len); for (i = 0; i < existing_len; i++) { NMConnection *candidate; - const char * id; + const char *id; candidate = existing_connections[i]; nm_assert(NM_IS_CONNECTION(candidate)); @@ -121,9 +122,9 @@ get_new_connection_name(NMConnection *const *existing_connections, } static char * -get_new_connection_ifname(NMPlatform * platform, +get_new_connection_ifname(NMPlatform *platform, NMConnection *const *existing_connections, - const char * prefix) + const char *prefix) { guint i, j; @@ -153,8 +154,8 @@ const char * nm_utils_get_ip_config_method(NMConnection *connection, int addr_family) { NMSettingConnection *s_con; - NMSettingIPConfig * s_ip; - const char * method; + NMSettingIPConfig *s_ip; + const char *method; s_con = nm_connection_get_setting_connection(connection); @@ -184,9 +185,9 @@ nm_utils_get_ip_config_method(NMConnection *connection, int addr_family) gboolean nm_utils_connection_has_default_route(NMConnection *connection, int addr_family, - gboolean * out_is_never_default) + gboolean *out_is_never_default) { - const char * method; + const char *method; NMSettingIPConfig *s_ip; gboolean is_never_default = FALSE; gboolean has_default_route = FALSE; @@ -228,23 +229,38 @@ out: /*****************************************************************************/ void -_nm_utils_complete_generic_with_params(NMPlatform * platform, - NMConnection * connection, - const char * ctype, +nm_utils_ppp_ip_methods_enabled(NMConnection *connection, + gboolean *out_ip4_enabled, + gboolean *out_ip6_enabled) +{ + NM_SET_OUT(out_ip4_enabled, + nm_streq0(nm_utils_get_ip_config_method(connection, AF_INET), + NM_SETTING_IP4_CONFIG_METHOD_AUTO)); + NM_SET_OUT(out_ip6_enabled, + nm_streq0(nm_utils_get_ip_config_method(connection, AF_INET6), + NM_SETTING_IP6_CONFIG_METHOD_AUTO)); +} + +/*****************************************************************************/ + +void +_nm_utils_complete_generic_with_params(NMPlatform *platform, + NMConnection *connection, + const char *ctype, NMConnection *const *existing_connections, - const char * preferred_id, - const char * fallback_id_prefix, - const char * ifname_prefix, - const char * ifname, + const char *preferred_id, + const char *fallback_id_prefix, + const char *ifname_prefix, + const char *ifname, ...) { - NMSettingConnection *s_con; - char * id; - char * generated_ifname; + NMSettingConnection *s_con; + char *id; + char *generated_ifname; gs_unref_hashtable GHashTable *parameters = NULL; va_list ap; - const char * p_val; - const char * p_key; + const char *p_val; + const char *p_key; g_assert(fallback_id_prefix); g_return_if_fail(ifname_prefix == NULL || ifname == NULL); @@ -324,8 +340,8 @@ remove_from_hash(GHashTable *s_hash, GHashTable *p_hash, const char *s_name, con static gboolean check_ip6_method(NMConnection *orig, NMConnection *candidate, GHashTable *settings) { - GHashTable * props; - const char * orig_ip6_method, *candidate_ip6_method; + GHashTable *props; + const char *orig_ip6_method, *candidate_ip6_method; NMSettingIPConfig *candidate_ip6; gboolean allow = FALSE; @@ -415,16 +431,16 @@ route_ptr_compare(const void *a, const void *b, gpointer metric) static gboolean check_ip_routes(NMConnection *orig, NMConnection *candidate, - GHashTable * settings, + GHashTable *settings, gint64 default_metric, gboolean v4) { gs_free NMIPRoute **routes1 = NULL; - NMIPRoute ** routes2; - NMSettingIPConfig * s_ip1, *s_ip2; + NMIPRoute **routes2; + NMSettingIPConfig *s_ip1, *s_ip2; gint64 m; - const char * s_name; - GHashTable * props; + const char *s_name; + GHashTable *props; guint i, i1, i2, num1, num2; const guint8 PLEN = v4 ? 32 : 128; @@ -493,11 +509,11 @@ check_ip_routes(NMConnection *orig, static gboolean check_ip4_method(NMConnection *orig, NMConnection *candidate, - GHashTable * settings, + GHashTable *settings, gboolean device_has_carrier) { - GHashTable * props; - const char * orig_ip4_method, *candidate_ip4_method; + GHashTable *props; + const char *orig_ip4_method, *candidate_ip4_method; NMSettingIPConfig *candidate_ip4; props = check_property_in_hash(settings, @@ -531,8 +547,8 @@ check_ip4_method(NMConnection *orig, static gboolean check_connection_interface_name(NMConnection *orig, NMConnection *candidate, GHashTable *settings) { - GHashTable * props; - const char * orig_ifname, *cand_ifname; + GHashTable *props; + const char *orig_ifname, *cand_ifname; NMSettingConnection *s_con_orig, *s_con_cand; props = check_property_in_hash(settings, @@ -560,8 +576,8 @@ check_connection_interface_name(NMConnection *orig, NMConnection *candidate, GHa static gboolean check_connection_mac_address(NMConnection *orig, NMConnection *candidate, GHashTable *settings) { - GHashTable * props; - const char * orig_mac = NULL, *cand_mac = NULL; + GHashTable *props; + const char *orig_mac = NULL, *cand_mac = NULL; NMSettingWired *s_wired_orig, *s_wired_cand; props = check_property_in_hash(settings, @@ -592,10 +608,10 @@ check_connection_mac_address(NMConnection *orig, NMConnection *candidate, GHashT static gboolean check_connection_infiniband_mac_address(NMConnection *orig, NMConnection *candidate, - GHashTable * settings) + GHashTable *settings) { - GHashTable * props; - const char * orig_mac = NULL, *cand_mac = NULL; + GHashTable *props; + const char *orig_mac = NULL, *cand_mac = NULL; NMSettingInfiniband *s_infiniband_orig, *s_infiniband_cand; props = check_property_in_hash(settings, @@ -626,10 +642,10 @@ check_connection_infiniband_mac_address(NMConnection *orig, static gboolean check_connection_cloned_mac_address(NMConnection *orig, NMConnection *candidate, - GHashTable * settings) + GHashTable *settings) { - GHashTable * props; - const char * orig_mac = NULL, *cand_mac = NULL; + GHashTable *props; + const char *orig_mac = NULL, *cand_mac = NULL; NMSettingWired *s_wired_orig, *s_wired_cand; props = check_property_in_hash(settings, @@ -666,7 +682,7 @@ check_connection_cloned_mac_address(NMConnection *orig, static gboolean check_connection_s390_props(NMConnection *orig, NMConnection *candidate, GHashTable *settings) { - GHashTable * props1, *props2, *props3; + GHashTable *props1, *props2, *props3; NMSettingWired *s_wired_orig, *s_wired_cand; props1 = check_property_in_hash(settings, @@ -688,7 +704,7 @@ check_connection_s390_props(NMConnection *orig, NMConnection *candidate, GHashTa s_wired_cand = nm_connection_get_setting_wired(candidate); if (!s_wired_orig && s_wired_cand) { const char *const *subchans = nm_setting_wired_get_s390_subchannels(s_wired_cand); - const char * nettype = nm_setting_wired_get_s390_nettype(s_wired_cand); + const char *nettype = nm_setting_wired_get_s390_nettype(s_wired_cand); guint32 num_options = nm_setting_wired_get_num_s390_options(s_wired_cand); if ((!subchans || !*subchans) && !nettype && num_options == 0) { @@ -713,7 +729,7 @@ check_connection_s390_props(NMConnection *orig, NMConnection *candidate, GHashTa static NMConnection * check_possible_match(NMConnection *orig, NMConnection *candidate, - GHashTable * settings, + GHashTable *settings, gboolean device_has_carrier, gint64 default_v4_metric, gint64 default_v6_metric) @@ -779,8 +795,8 @@ check_possible_match(NMConnection *orig, * matches well enough. */ NMConnection * -nm_utils_match_connection(NMConnection *const * connections, - NMConnection * original, +nm_utils_match_connection(NMConnection *const *connections, + NMConnection *original, gboolean indicated, gboolean device_has_carrier, gint64 default_v4_metric, @@ -795,7 +811,7 @@ nm_utils_match_connection(NMConnection *const * connections, for (; *connections; connections++) { NMConnection *candidate = *connections; - GHashTable * diffs = NULL; + GHashTable *diffs = NULL; nm_assert(NM_IS_CONNECTION(candidate)); @@ -835,7 +851,7 @@ nm_utils_match_connection(NMConnection *const * connections, } if (!best_match && nm_logging_enabled(LOGL_DEBUG, LOGD_CORE)) { - GString * diff_string; + GString *diff_string; GHashTableIter s_iter, p_iter; gpointer setting_name, setting; gpointer property_name, value; @@ -878,9 +894,9 @@ nm_utils_match_connection(NMConnection *const * connections, int nm_match_spec_device_by_pllink(const NMPlatformLink *pllink, - const char * match_device_type, - const char * match_dhcp_plugin, - const GSList * specs, + const char *match_device_type, + const char *match_dhcp_plugin, + const GSList *specs, int no_match_value) { NMMatchSpecMatchType m; @@ -971,7 +987,7 @@ nm_ip_routing_rule_to_platform(const NMIPRoutingRule *rule, NMPlatformRoutingRul struct _NMShutdownWaitObjHandle { CList lst; gpointer watched_obj; - char * msg_reason; + char *msg_reason; bool free_msg_reason : 1; bool is_cancellable : 1; }; @@ -1044,7 +1060,7 @@ _shutdown_waitobj_cb(gpointer user_data, GObject *where_the_object_was) NMShutdownWaitObjHandle * nm_shutdown_wait_obj_register_full(gpointer watched_obj, NMShutdownWaitType wait_type, - char * msg_reason, + char *msg_reason, gboolean free_msg_reason) { NMShutdownWaitObjHandle *handle; @@ -1164,8 +1180,8 @@ nm_utils_qdiscs_from_tc_setting(NMPlatform *platform, NMSettingTCConfig *s_tc, i qdiscs = g_ptr_array_new_full(nqdiscs, (GDestroyNotify) nmp_object_unref); for (i = 0; i < nqdiscs; i++) { - NMTCQdisc * s_qdisc = nm_setting_tc_config_get_qdisc(s_tc, i); - NMPObject * q = nmp_object_new(NMP_OBJECT_TYPE_QDISC, NULL); + NMTCQdisc *s_qdisc = nm_setting_tc_config_get_qdisc(s_tc, i); + NMPObject *q = nmp_object_new(NMP_OBJECT_TYPE_QDISC, NULL); NMPlatformQdisc *qdisc = NMP_OBJECT_CAST_QDISC(q); qdisc->ifindex = ip_ifindex; @@ -1238,9 +1254,9 @@ nm_utils_tfilters_from_tc_setting(NMPlatform *platform, NMSettingTCConfig *s_tc, tfilters = g_ptr_array_new_full(ntfilters, (GDestroyNotify) nmp_object_unref); for (i = 0; i < ntfilters; i++) { - NMTCTfilter * s_tfilter = nm_setting_tc_config_get_tfilter(s_tc, i); - NMTCAction * action; - NMPObject * t = nmp_object_new(NMP_OBJECT_TYPE_TFILTER, NULL); + NMTCTfilter *s_tfilter = nm_setting_tc_config_get_tfilter(s_tc, i); + NMTCAction *action; + NMPObject *t = nmp_object_new(NMP_OBJECT_TYPE_TFILTER, NULL); NMPlatformTfilter *tfilter = NMP_OBJECT_CAST_TFILTER(t); tfilter->ifindex = ip_ifindex; @@ -1296,11 +1312,12 @@ nm_utils_tfilters_from_tc_setting(NMPlatform *platform, NMSettingTCConfig *s_tc, void nm_utils_ip_route_attribute_to_platform(int addr_family, - NMIPRoute * s_route, + NMIPRoute *s_route, NMPlatformIPRoute *r, - guint32 route_table) + gint64 route_table) { - GVariant * variant; + const int IS_IPv4 = NM_IS_IPv4(addr_family); + GVariant *variant; guint32 table; NMIPAddr addr; NMPlatformIP4Route *r4 = (NMPlatformIP4Route *) r; @@ -1308,8 +1325,10 @@ nm_utils_ip_route_attribute_to_platform(int addr_family, gboolean onlink; nm_assert(s_route); - nm_assert_addr_family(addr_family); + nm_assert(addr_family == nm_ip_route_get_family(s_route)); nm_assert(r); + nm_assert(route_table >= -1); + nm_assert(route_table <= (gint64) G_MAXUINT32); #define GET_ATTR(name, dst, variant_type, type, dflt) \ G_STMT_START \ @@ -1328,7 +1347,8 @@ nm_utils_ip_route_attribute_to_platform(int addr_family, int type; type = nm_net_aux_rtnl_rtntype_a2n(g_variant_get_string(variant, NULL)); - nm_assert(NM_IN_SET(type, RTN_UNICAST, RTN_LOCAL)); + nm_assert( + NM_IN_SET(type, RTN_UNICAST, RTN_LOCAL, RTN_BLACKHOLE, RTN_UNREACHABLE, RTN_PROHIBIT)); r->type_coerced = nm_platform_route_type_coerce(type); } else @@ -1336,12 +1356,18 @@ nm_utils_ip_route_attribute_to_platform(int addr_family, GET_ATTR(NM_IP_ROUTE_ATTRIBUTE_TABLE, table, UINT32, uint32, 0); - if (!table && r->type_coerced == nm_platform_route_type_coerce(RTN_LOCAL)) + if (table != 0) + r->table_coerced = nm_platform_route_table_coerce(table); + else if (r->type_coerced == nm_platform_route_type_coerce(RTN_LOCAL)) r->table_coerced = nm_platform_route_table_coerce(RT_TABLE_LOCAL); + else if (route_table == 0) + r->table_coerced = nm_platform_route_table_coerce(RT_TABLE_MAIN); + else if (route_table > 0) + r->table_coerced = nm_platform_route_table_coerce(route_table); else - r->table_coerced = nm_platform_route_table_coerce(table ?: (route_table ?: RT_TABLE_MAIN)); + r->table_any = TRUE; - if (NM_IS_IPv4(addr_family)) { + if (IS_IPv4) { guint8 scope; GET_ATTR(NM_IP_ROUTE_ATTRIBUTE_TOS, r4->tos, BYTE, byte, 0); @@ -1367,15 +1393,14 @@ nm_utils_ip_route_attribute_to_platform(int addr_family, if ((variant = nm_ip_route_get_attribute(s_route, NM_IP_ROUTE_ATTRIBUTE_SRC)) && g_variant_is_of_type(variant, G_VARIANT_TYPE_STRING)) { if (inet_pton(addr_family, g_variant_get_string(variant, NULL), &addr) == 1) { - if (NM_IS_IPv4(addr_family)) + if (IS_IPv4) r4->pref_src = addr.addr4; else r6->pref_src = addr.addr6; } } - if (!NM_IS_IPv4(addr_family) - && (variant = nm_ip_route_get_attribute(s_route, NM_IP_ROUTE_ATTRIBUTE_FROM)) + if (!IS_IPv4 && (variant = nm_ip_route_get_attribute(s_route, NM_IP_ROUTE_ATTRIBUTE_FROM)) && g_variant_is_of_type(variant, G_VARIANT_TYPE_STRING)) { int prefix; @@ -1395,39 +1420,20 @@ nm_utils_ip_route_attribute_to_platform(int addr_family, /*****************************************************************************/ -static int -_addresses_sort_cmp_4(gconstpointer a, gconstpointer b, gpointer user_data) -{ - return nm_platform_ip4_address_pretty_sort_cmp( - NMP_OBJECT_CAST_IP4_ADDRESS(*((const NMPObject **) a)), - NMP_OBJECT_CAST_IP4_ADDRESS(*((const NMPObject **) b))); -} - -static int -_addresses_sort_cmp_6(gconstpointer a, gconstpointer b, gpointer user_data) -{ - return nm_platform_ip6_address_pretty_sort_cmp( - NMP_OBJECT_CAST_IP6_ADDRESS(*((const NMPObject **) a)), - NMP_OBJECT_CAST_IP6_ADDRESS(*((const NMPObject **) b)), - (((NMSettingIP6ConfigPrivacy) GPOINTER_TO_INT(user_data)) - == NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR)); -} - void nm_utils_ip_addresses_to_dbus(int addr_family, const NMDedupMultiHeadEntry *head_entry, - const NMPObject * best_default_route, - NMSettingIP6ConfigPrivacy ipv6_privacy, - GVariant ** out_address_data, - GVariant ** out_addresses) + const NMPObject *best_default_route, + GVariant **out_address_data, + GVariant **out_addresses) { - const int IS_IPv4 = NM_IS_IPv4(addr_family); - GVariantBuilder builder_data; - GVariantBuilder builder_legacy; - char addr_str[NM_UTILS_INET_ADDRSTRLEN]; - gs_free const NMPObject **addresses = NULL; - guint naddr; - guint i; + const int IS_IPv4 = NM_IS_IPv4(addr_family); + GVariantBuilder builder_data; + GVariantBuilder builder_legacy; + char addr_str[NM_UTILS_INET_ADDRSTRLEN]; + NMDedupMultiIter iter; + const NMPObject *obj; + guint i; nm_assert_addr_family(addr_family); @@ -1443,19 +1449,11 @@ nm_utils_ip_addresses_to_dbus(int addr_family, if (!head_entry) goto out; - addresses = - (const NMPObject **) nm_dedup_multi_objs_to_array_head(head_entry, NULL, NULL, &naddr); - - nm_assert(addresses && naddr); - - g_qsort_with_data(addresses, - naddr, - sizeof(addresses[0]), - IS_IPv4 ? _addresses_sort_cmp_4 : _addresses_sort_cmp_6, - GINT_TO_POINTER(ipv6_privacy)); - - for (i = 0; i < naddr; i++) { - const NMPlatformIPXAddress *address = NMP_OBJECT_CAST_IPX_ADDRESS(addresses[i]); + i = 0; + nm_dedup_multi_iter_init(&iter, head_entry); + while ( + nm_platform_dedup_multi_iter_next_obj(&iter, &obj, NMP_OBJECT_TYPE_IP_ADDRESS(IS_IPv4))) { + const NMPlatformIPXAddress *address = NMP_OBJECT_CAST_IPX_ADDRESS(obj); if (out_address_data) { GVariantBuilder addr_builder; @@ -1527,6 +1525,8 @@ nm_utils_ip_addresses_to_dbus(int addr_family, : &in6addr_any)); } } + + i++; } out: @@ -1537,8 +1537,8 @@ out: void nm_utils_ip_routes_to_dbus(int addr_family, const NMDedupMultiHeadEntry *head_entry, - GVariant ** out_route_data, - GVariant ** out_routes) + GVariant **out_route_data, + GVariant **out_routes) { const int IS_IPv4 = NM_IS_IPv4(addr_family); NMDedupMultiIter iter; @@ -1654,6 +1654,134 @@ nm_utils_ip_routes_to_dbus(int addr_family, /*****************************************************************************/ +NMSetting * +nm_utils_platform_capture_ip_setting(NMPlatform *platform, + int addr_family, + int ifindex, + gboolean maybe_ipv6_disabled) +{ + const int IS_IPv4 = NM_IS_IPv4(addr_family); + gs_unref_object NMSettingIPConfig *s_ip = NULL; + NMPLookup lookup; + NMDedupMultiIter iter; + const NMPObject *obj; + const char *method = NULL; + char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + const NMPlatformIPXRoute *best_default_route = NULL; + + s_ip = + NM_SETTING_IP_CONFIG(IS_IPv4 ? nm_setting_ip4_config_new() : nm_setting_ip6_config_new()); + + if (ifindex <= 0 || !nm_platform_link_get(platform, ifindex)) { + g_object_set(s_ip, + NM_SETTING_IP_CONFIG_METHOD, + IS_IPv4 ? NM_SETTING_IP4_CONFIG_METHOD_DISABLED + : NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NULL); + return NM_SETTING(g_steal_pointer(&s_ip)); + } + + nmp_lookup_init_object(&lookup, NMP_OBJECT_TYPE_IP_ADDRESS(IS_IPv4), ifindex); + nm_platform_iter_obj_for_each (&iter, platform, &lookup, &obj) { + const NMPlatformIPXAddress *address = NMP_OBJECT_CAST_IPX_ADDRESS(obj); + nm_auto_unref_ip_address NMIPAddress *s_addr = NULL; + + if (!IS_IPv4) { + /* Ignore link-local address. */ + if (IN6_IS_ADDR_LINKLOCAL(address->ax.address_ptr)) { + if (!method) + method = NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL; + continue; + } + } + + /* Detect dynamic address */ + if (address->ax.lifetime != NM_PLATFORM_LIFETIME_PERMANENT) { + method = + IS_IPv4 ? NM_SETTING_IP4_CONFIG_METHOD_AUTO : NM_SETTING_IP6_CONFIG_METHOD_AUTO; + continue; + } + + /* Static address found. */ + if (IS_IPv4) { + if (!method) + method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL; + } else { + if (NM_IN_STRSET(method, NULL, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL)) + method = NM_SETTING_IP6_CONFIG_METHOD_MANUAL; + } + + s_addr = + nm_ip_address_new_binary(addr_family, address->ax.address_ptr, address->ax.plen, NULL); + + if (IS_IPv4) { + if (address->a4.label[0]) { + nm_ip_address_set_attribute(s_addr, + NM_IP_ADDRESS_ATTRIBUTE_LABEL, + g_variant_new_string(address->a4.label)); + } + } + + nm_setting_ip_config_add_address(s_ip, s_addr); + } + + if (!method) { + /* Use 'disabled/ignore' if the method wasn't previously set */ + if (IS_IPv4) + method = NM_SETTING_IP4_CONFIG_METHOD_DISABLED; + else + method = maybe_ipv6_disabled ? NM_SETTING_IP6_CONFIG_METHOD_DISABLED + : NM_SETTING_IP6_CONFIG_METHOD_IGNORE; + } + g_object_set(s_ip, NM_SETTING_IP_CONFIG_METHOD, method, NULL); + + nmp_lookup_init_object(&lookup, NMP_OBJECT_TYPE_IP_ROUTE(IS_IPv4), ifindex); + nm_platform_iter_obj_for_each (&iter, platform, &lookup, &obj) { + const NMPlatformIPXRoute *route = NMP_OBJECT_CAST_IPX_ROUTE(obj); + nm_auto_unref_ip_route NMIPRoute *s_route = NULL; + + if (!IS_IPv4) { + /* Ignore link-local route. */ + if (IN6_IS_ADDR_LINKLOCAL(route->rx.network_ptr)) + continue; + } + + if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT(route)) { + if (!best_default_route) + best_default_route = route; + continue; + } + + if (route->rx.rt_source + != nmp_utils_ip_config_source_round_trip_rtprot(NM_IP_CONFIG_SOURCE_USER)) { + /* Ignore routes provided by external sources */ + continue; + } + + s_route = nm_ip_route_new_binary(addr_family, + route->rx.network_ptr, + route->rx.plen, + nm_platform_ip_route_get_gateway(addr_family, &route->rx), + route->rx.metric, + NULL); + nm_setting_ip_config_add_route(s_ip, s_route); + } + + if (best_default_route && nm_setting_ip_config_get_num_addresses(s_ip) > 0) { + g_object_set(s_ip, + NM_SETTING_IP_CONFIG_GATEWAY, + nm_utils_inet_ntop( + addr_family, + nm_platform_ip_route_get_gateway(addr_family, &best_default_route->rx), + sbuf), + NULL); + } + + return NM_SETTING(g_steal_pointer(&s_ip)); +} + +/*****************************************************************************/ + /* Singleton NMPlatform subclass instance and cached class object */ NM_DEFINE_SINGLETON_INSTANCE(NMPlatform); diff --git a/src/core/NetworkManagerUtils.h b/src/core/NetworkManagerUtils.h index a2ac732e..c9210ba8 100644 --- a/src/core/NetworkManagerUtils.h +++ b/src/core/NetworkManagerUtils.h @@ -19,14 +19,18 @@ const char *nm_utils_get_ip_config_method(NMConnection *connection, int addr_fam const char *nm_utils_get_shared_wifi_permission(NMConnection *connection); -void _nm_utils_complete_generic_with_params(NMPlatform * platform, - NMConnection * connection, - const char * ctype, +void nm_utils_ppp_ip_methods_enabled(NMConnection *connection, + gboolean *out_ip4_enabled, + gboolean *out_ip6_enabled); + +void _nm_utils_complete_generic_with_params(NMPlatform *platform, + NMConnection *connection, + const char *ctype, NMConnection *const *existing_connections, - const char * preferred_id, - const char * fallback_id_prefix, - const char * ifname_prefix, - const char * ifname, + const char *preferred_id, + const char *fallback_id_prefix, + const char *ifname_prefix, + const char *ifname, ...) G_GNUC_NULL_TERMINATED; #define nm_utils_complete_generic_with_params(platform, \ @@ -50,14 +54,14 @@ void _nm_utils_complete_generic_with_params(NMPlatform * platform, NULL) static inline void -nm_utils_complete_generic(NMPlatform * platform, - NMConnection * connection, - const char * ctype, +nm_utils_complete_generic(NMPlatform *platform, + NMConnection *connection, + const char *ctype, NMConnection *const *existing_connections, - const char * preferred_id, - const char * fallback_id_prefix, - const char * ifname_prefix, - const char * ifname, + const char *preferred_id, + const char *fallback_id_prefix, + const char *ifname_prefix, + const char *ifname, gboolean default_enable_ipv6) { nm_utils_complete_generic_with_params(platform, @@ -76,8 +80,8 @@ nm_utils_complete_generic(NMPlatform * platform, typedef gboolean(NMUtilsMatchFilterFunc)(NMConnection *connection, gpointer user_data); -NMConnection *nm_utils_match_connection(NMConnection *const * connections, - NMConnection * original, +NMConnection *nm_utils_match_connection(NMConnection *const *connections, + NMConnection *original, gboolean indicated, gboolean device_has_carrier, gint64 default_v4_metric, @@ -86,9 +90,9 @@ NMConnection *nm_utils_match_connection(NMConnection *const * connections, gpointer match_filter_data); int nm_match_spec_device_by_pllink(const NMPlatformLink *pllink, - const char * match_device_type, - const char * match_dhcp_plugin, - const GSList * specs, + const char *match_device_type, + const char *match_dhcp_plugin, + const GSList *specs, int no_match_value); /*****************************************************************************/ @@ -136,12 +140,12 @@ typedef struct _NMShutdownWaitObjHandle NMShutdownWaitObjHandle; NMShutdownWaitObjHandle *nm_shutdown_wait_obj_register_full(gpointer watched_obj, NMShutdownWaitType wait_type, - char * msg_reason, + char *msg_reason, gboolean free_msg_reason); static inline NMShutdownWaitObjHandle * nm_shutdown_wait_obj_register_object_full(gpointer watched_obj, - char * msg_reason, + char *msg_reason, gboolean free_msg_reason) { return nm_shutdown_wait_obj_register_full(watched_obj, @@ -167,7 +171,7 @@ nm_shutdown_wait_obj_register_handle_full(char *msg_reason, gboolean free_msg_re static inline NMShutdownWaitObjHandle * nm_shutdown_wait_obj_register_cancellable_full(GCancellable *watched_obj, - char * msg_reason, + char *msg_reason, gboolean free_msg_reason) { return nm_shutdown_wait_obj_register_full(watched_obj, @@ -193,21 +197,20 @@ GPtrArray * nm_utils_tfilters_from_tc_setting(NMPlatform *platform, NMSettingTCConfig *s_tc, int ip_ifindex); void nm_utils_ip_route_attribute_to_platform(int addr_family, - NMIPRoute * s_route, + NMIPRoute *s_route, NMPlatformIPRoute *r, - guint32 route_table); + gint64 route_table); void nm_utils_ip_addresses_to_dbus(int addr_family, const NMDedupMultiHeadEntry *head_entry, - const NMPObject * best_default_route, - NMSettingIP6ConfigPrivacy ipv6_privacy, - GVariant ** out_address_data, - GVariant ** out_addresses); + const NMPObject *best_default_route, + GVariant **out_address_data, + GVariant **out_addresses); void nm_utils_ip_routes_to_dbus(int addr_family, const NMDedupMultiHeadEntry *head_entry, - GVariant ** out_route_data, - GVariant ** out_routes); + GVariant **out_route_data, + GVariant **out_routes); /*****************************************************************************/ @@ -271,6 +274,13 @@ NM_AUTO_DEFINE_FCN(NMDhcpLease *, _nm_auto_unref_dhcplease, nm_dhcp_lease_unref) /*****************************************************************************/ +NMSetting *nm_utils_platform_capture_ip_setting(NMPlatform *platform, + int addr_family, + int ifindex, + gboolean maybe_ipv6_disabled); + +/*****************************************************************************/ + void nm_platform_setup(NMPlatform *instance); NMPlatform *nm_platform_get(void); diff --git a/src/core/devices/adsl/nm-atm-manager.c b/src/core/devices/adsl/nm-atm-manager.c index bd9ed8cc..cc8d37e6 100644 --- a/src/core/devices/adsl/nm-atm-manager.c +++ b/src/core/devices/adsl/nm-atm-manager.c @@ -27,7 +27,7 @@ typedef struct { NMUdevClient *udev_client; - GSList * devices; + GSList *devices; } NMAtmManagerPrivate; typedef struct { @@ -51,7 +51,7 @@ NM_DEVICE_FACTORY_DECLARE_TYPES( NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES(NM_SETTING_ADSL_SETTING_NAME)); G_MODULE_EXPORT NMDeviceFactory * - nm_device_factory_create(GError **error) +nm_device_factory_create(GError **error) { return g_object_new(NM_TYPE_ATM_MANAGER, NULL); } @@ -62,7 +62,7 @@ static gboolean dev_get_attrs(struct udev_device *udev_device, const char **out_path, char **out_driver) { struct udev_device *parent = NULL; - const char * driver, *path; + const char *driver, *path; g_return_val_if_fail(udev_device != NULL, FALSE); g_return_val_if_fail(out_path != NULL, FALSE); @@ -91,7 +91,7 @@ dev_get_attrs(struct udev_device *udev_device, const char **out_path, char **out static void device_destroyed(gpointer user_data, GObject *dead) { - NMAtmManager * self = NM_ATM_MANAGER(user_data); + NMAtmManager *self = NM_ATM_MANAGER(user_data); NMAtmManagerPrivate *priv = NM_ATM_MANAGER_GET_PRIVATE(self); priv->devices = g_slist_remove(priv->devices, dead); @@ -101,11 +101,11 @@ static void adsl_add(NMAtmManager *self, struct udev_device *udev_device) { NMAtmManagerPrivate *priv = NM_ATM_MANAGER_GET_PRIVATE(self); - const char * ifname, *sysfs_path = NULL; - char * driver = NULL; - gs_free char * atm_index_path = NULL; + const char *ifname, *sysfs_path = NULL; + char *driver = NULL; + gs_free char *atm_index_path = NULL; int atm_index; - NMDevice * device; + NMDevice *device; g_return_if_fail(udev_device != NULL); @@ -153,8 +153,8 @@ static void adsl_remove(NMAtmManager *self, struct udev_device *udev_device) { NMAtmManagerPrivate *priv = NM_ATM_MANAGER_GET_PRIVATE(self); - const char * iface = udev_device_get_sysname(udev_device); - GSList * iter; + const char *iface = udev_device_get_sysname(udev_device); + GSList *iter; nm_log_dbg(LOGD_PLATFORM, "(%s): removing ATM device", iface); @@ -177,9 +177,9 @@ adsl_remove(NMAtmManager *self, struct udev_device *udev_device) static void start(NMDeviceFactory *factory) { - NMAtmManager * self = NM_ATM_MANAGER(factory); - NMAtmManagerPrivate * priv = NM_ATM_MANAGER_GET_PRIVATE(self); - struct udev_enumerate * enumerate; + NMAtmManager *self = NM_ATM_MANAGER(factory); + NMAtmManagerPrivate *priv = NM_ATM_MANAGER_GET_PRIVATE(self); + struct udev_enumerate *enumerate; struct udev_list_entry *devices; enumerate = nm_udev_client_enumerate_new(priv->udev_client); @@ -203,10 +203,10 @@ static void handle_uevent(NMUdevClient *client, struct udev_device *device, gpointer user_data) { NMAtmManager *self = NM_ATM_MANAGER(user_data); - const char * subsys; - const char * ifindex; + const char *subsys; + const char *ifindex; guint64 seqnum; - const char * action; + const char *action; action = udev_device_get_action(device); @@ -245,9 +245,9 @@ nm_atm_manager_init(NMAtmManager *self) static void dispose(GObject *object) { - NMAtmManager * self = NM_ATM_MANAGER(object); + NMAtmManager *self = NM_ATM_MANAGER(object); NMAtmManagerPrivate *priv = NM_ATM_MANAGER_GET_PRIVATE(self); - GSList * iter; + GSList *iter; for (iter = priv->devices; iter; iter = iter->next) g_object_weak_unref(G_OBJECT(iter->data), device_destroyed, self); @@ -261,7 +261,7 @@ dispose(GObject *object) static void nm_atm_manager_class_init(NMAtmManagerClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDeviceFactoryClass *factory_class = NM_DEVICE_FACTORY_CLASS(klass); object_class->dispose = dispose; diff --git a/src/core/devices/adsl/nm-device-adsl.c b/src/core/devices/adsl/nm-device-adsl.c index adcf8785..79705c28 100644 --- a/src/core/devices/adsl/nm-device-adsl.c +++ b/src/core/devices/adsl/nm-device-adsl.c @@ -15,13 +15,12 @@ #include #include -#include "nm-ip4-config.h" #include "devices/nm-device-private.h" #include "libnm-platform/nm-platform.h" -#include "ppp/nm-ppp-manager-call.h" -#include "ppp/nm-ppp-status.h" +#include "nm-manager.h" #include "nm-setting-adsl.h" #include "nm-utils.h" +#include "ppp/nm-ppp-mgr.h" #define _NMLOG_DEVICE_TYPE NMDeviceAdsl #include "devices/nm-device-logging.h" @@ -34,15 +33,14 @@ typedef struct { guint carrier_poll_id; int atm_index; - /* PPP */ - NMPPPManager *ppp_manager; + NMPppMgr *ppp_mgr; /* RFC 2684 bridging (PPPoE over ATM) */ - int brfd; - int nas_ifindex; - char *nas_ifname; - guint nas_update_id; - guint nas_update_count; + int brfd; + int nas_ifindex; + char *nas_ifname; + GSource *nas_update_source; + guint nas_update_count; } NMDeviceAdslPrivate; struct _NMDeviceAdsl { @@ -72,7 +70,7 @@ static gboolean check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error) { NMSettingAdsl *s_adsl; - const char * protocol; + const char *protocol; if (!NM_DEVICE_CLASS(nm_device_adsl_parent_class) ->check_connection_compatible(device, connection, error)) @@ -93,11 +91,11 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError * } static gboolean -complete_connection(NMDevice * device, - NMConnection * connection, - const char * specific_object, +complete_connection(NMDevice *device, + NMConnection *connection, + const char *specific_object, NMConnection *const *existing_connections, - GError ** error) + GError **error) { NMSettingAdsl *s_adsl; @@ -126,12 +124,12 @@ complete_connection(NMDevice * device, static gboolean br2684_assign_vcc(NMDeviceAdsl *self, NMSettingAdsl *s_adsl) { - NMDeviceAdslPrivate * priv = NM_DEVICE_ADSL_GET_PRIVATE(self); + NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE(self); struct sockaddr_atmpvc addr; struct atm_backend_br2684 be; struct atm_qos qos; int errsv, err, bufsize = 8192; - const char * encapsulation; + const char *encapsulation; gboolean is_llc; g_return_val_if_fail(priv->brfd == -1, FALSE); @@ -216,18 +214,18 @@ error: } static void -link_changed_cb(NMPlatform * platform, +link_changed_cb(NMPlatform *platform, int obj_type_i, int ifindex, NMPlatformLink *info, int change_type_i, - NMDeviceAdsl * self) + NMDeviceAdsl *self) { const NMPlatformSignalChangeType change_type = change_type_i; if (change_type == NM_PLATFORM_SIGNAL_REMOVED) { NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE(self); - NMDevice * device = NM_DEVICE(self); + NMDevice *device = NM_DEVICE(self); /* This only gets called for PPPoE connections and "nas" interfaces */ @@ -245,8 +243,8 @@ static gboolean pppoe_vcc_config(NMDeviceAdsl *self) { NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE(self); - NMDevice * device = NM_DEVICE(self); - NMSettingAdsl * s_adsl; + NMDevice *device = NM_DEVICE(self); + NMSettingAdsl *s_adsl; s_adsl = nm_device_get_applied_setting(device, NM_TYPE_SETTING_ADSL); @@ -271,11 +269,11 @@ pppoe_vcc_config(NMDeviceAdsl *self) } static gboolean -nas_update_cb(gpointer user_data) +nas_update_timeout_cb(gpointer user_data) { - NMDeviceAdsl * self = NM_DEVICE_ADSL(user_data); + NMDeviceAdsl *self = NM_DEVICE_ADSL(user_data); NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE(self); - NMDevice * device = NM_DEVICE(self); + NMDevice *device = NM_DEVICE(self); nm_assert(priv->nas_ifname); @@ -284,46 +282,48 @@ nas_update_cb(gpointer user_data) nm_assert(priv->nas_ifindex <= 0); priv->nas_ifindex = nm_platform_link_get_ifindex(nm_device_get_platform(device), priv->nas_ifname); + + if (priv->nas_ifindex <= 0 && priv->nas_update_count <= 10) { + /* Keep waiting for it to appear */ + return G_SOURCE_CONTINUE; + } + + nm_clear_g_source_inst(&priv->nas_update_source); + if (priv->nas_ifindex <= 0) { - if (priv->nas_update_count <= 10) { - /* Keep waiting for it to appear */ - return G_SOURCE_CONTINUE; - } - priv->nas_update_id = 0; _LOGW(LOGD_ADSL, "failed to find br2684 interface %s ifindex after timeout", priv->nas_ifname); nm_device_state_changed(device, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_BR2684_FAILED); - return G_SOURCE_REMOVE; + return G_SOURCE_CONTINUE; } - priv->nas_update_id = 0; _LOGD(LOGD_ADSL, "using br2684 iface '%s' index %d", priv->nas_ifname, priv->nas_ifindex); if (!pppoe_vcc_config(self)) { nm_device_state_changed(device, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_BR2684_FAILED); - return G_SOURCE_REMOVE; + return G_SOURCE_CONTINUE; } nm_device_activate_schedule_stage2_device_config(device, TRUE); - return G_SOURCE_REMOVE; + return G_SOURCE_CONTINUE; } static gboolean br2684_create_iface(NMDeviceAdsl *self) { - NMDeviceAdslPrivate * priv = NM_DEVICE_ADSL_GET_PRIVATE(self); + NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE(self); struct atm_newif_br2684 ni; nm_auto_close int fd = -1; - int err, errsv; + int err; + int errsv; guint num = 0; - if (nm_clear_g_source(&priv->nas_update_id)) - nm_assert_not_reached(); + nm_assert(!priv->nas_update_source); fd = socket(PF_ATMPVC, SOCK_DGRAM | SOCK_CLOEXEC, ATM_AAL5); if (fd < 0) { @@ -358,174 +358,187 @@ br2684_create_iface(NMDeviceAdsl *self) nm_strdup_reset(&priv->nas_ifname, ni.ifname); _LOGD(LOGD_ADSL, "waiting for br2684 iface '%s' to appear", priv->nas_ifname); - priv->nas_update_count = 0; - priv->nas_update_id = g_timeout_add(100, nas_update_cb, self); + priv->nas_update_count = 0; + priv->nas_update_source = nm_g_timeout_add_source(100, nas_update_timeout_cb, self); return TRUE; } } -static NMActStageReturn -act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) +/*****************************************************************************/ + +static void +_ppp_mgr_cleanup(NMDeviceAdsl *self) { - NMDeviceAdsl * self = NM_DEVICE_ADSL(device); NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE(self); - NMSettingAdsl * s_adsl; - const char * protocol; - s_adsl = nm_device_get_applied_setting(device, NM_TYPE_SETTING_ADSL); - - g_return_val_if_fail(s_adsl, NM_ACT_STAGE_RETURN_FAILURE); + nm_clear_pointer(&priv->ppp_mgr, nm_ppp_mgr_destroy); +} - protocol = nm_setting_adsl_get_protocol(s_adsl); - _LOGD(LOGD_ADSL, "using ADSL protocol '%s'", protocol); +static void +_ppp_mgr_stage3_maybe_ready(NMDeviceAdsl *self) +{ + NMDevice *device = NM_DEVICE(self); + NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE(self); + int IS_IPv4; - if (nm_streq0(protocol, NM_SETTING_ADSL_PROTOCOL_PPPOA)) { - /* PPPoA doesn't need anything special */ - return NM_ACT_STAGE_RETURN_SUCCESS; - } + for (IS_IPv4 = 1; IS_IPv4 >= 0; IS_IPv4--) { + const int addr_family = IS_IPv4 ? AF_INET : AF_INET6; + const NMPppMgrIPData *ip_data; - if (nm_streq0(protocol, NM_SETTING_ADSL_PROTOCOL_PPPOE)) { - /* PPPoE needs RFC2684 bridging before we can do PPP over it */ - if (priv->nas_ifindex <= 0) { - if (priv->nas_update_id == 0) { - if (!br2684_create_iface(self)) { - NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_BR2684_FAILED); - return NM_ACT_STAGE_RETURN_FAILURE; - } - } - return NM_ACT_STAGE_RETURN_POSTPONE; - } - return NM_ACT_STAGE_RETURN_SUCCESS; + ip_data = nm_ppp_mgr_get_ip_data(priv->ppp_mgr, addr_family); + if (ip_data->ip_received) + nm_device_devip_set_state(device, addr_family, NM_DEVICE_IP_STATE_READY, ip_data->l3cd); } - _LOGW(LOGD_ADSL, "unhandled ADSL protocol '%s'", protocol); - return NM_ACT_STAGE_RETURN_SUCCESS; + if (nm_ppp_mgr_get_state(priv->ppp_mgr) >= NM_PPP_MGR_STATE_HAVE_IP_CONFIG) + nm_device_devip_set_state(device, AF_UNSPEC, NM_DEVICE_IP_STATE_READY, NULL); } static void -ppp_state_changed(NMPPPManager *ppp_manager, NMPPPStatus status, gpointer user_data) +_ppp_mgr_callback(NMPppMgr *ppp_mgr, const NMPppMgrCallbackData *callback_data, gpointer user_data) { - NMDevice *device = NM_DEVICE(user_data); + NMDeviceAdsl *self = NM_DEVICE_ADSL(user_data); + NMDevice *device = NM_DEVICE(self); + NMDeviceState device_state; - switch (status) { - case NM_PPP_STATUS_DISCONNECT: - nm_device_state_changed(device, - NM_DEVICE_STATE_FAILED, - NM_DEVICE_STATE_REASON_PPP_DISCONNECT); - break; - case NM_PPP_STATUS_DEAD: - nm_device_state_changed(device, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_PPP_FAILED); - break; - default: - break; - } -} + if (callback_data->callback_type != NM_PPP_MGR_CALLBACK_TYPE_STATE_CHANGED) + return; -static void -ppp_ifindex_set(NMPPPManager *ppp_manager, int ifindex, const char *iface, gpointer user_data) -{ - NMDevice *device = NM_DEVICE(user_data); + device_state = nm_device_get_state(device); - if (!nm_device_set_ip_ifindex(device, ifindex)) { - nm_device_state_changed(device, - NM_DEVICE_STATE_FAILED, - NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); + if (callback_data->data.state >= _NM_PPP_MGR_STATE_FAILED_START) { + if (device_state <= NM_DEVICE_STATE_ACTIVATED) + nm_device_state_changed(device, NM_DEVICE_STATE_FAILED, callback_data->data.reason); + return; } -} -static void -ppp_ip4_config(NMPPPManager *ppp_manager, NMIP4Config *config, gpointer user_data) -{ - NMDevice *device = NM_DEVICE(user_data); + if (device_state < NM_DEVICE_STATE_IP_CONFIG) { + if (callback_data->data.state >= NM_PPP_MGR_STATE_HAVE_IFINDEX) { + gs_free char *old_name = NULL; + gs_free_error GError *error = NULL; + + if (!nm_device_take_over_link(device, callback_data->data.ifindex, &old_name, &error)) { + _LOGW(LOGD_DEVICE | LOGD_PPP, + "could not take control of link %d: %s", + callback_data->data.ifindex, + error->message); + _ppp_mgr_cleanup(self); + nm_device_state_changed(device, + NM_DEVICE_STATE_FAILED, + NM_DEVICE_STATE_REASON_CONFIG_FAILED); + return; + } - /* Ignore PPP IP4 events that come in after initial configuration */ - if (nm_device_activate_ip4_state_in_conf(device)) - nm_device_activate_schedule_ip_config_result(device, AF_INET, NM_IP_CONFIG_CAST(config)); + if (old_name) + nm_manager_remove_device(NM_MANAGER_GET, old_name, NM_DEVICE_TYPE_ADSL); + + nm_device_activate_schedule_stage2_device_config(device, FALSE); + } + return; + } + + _ppp_mgr_stage3_maybe_ready(self); } +/*****************************************************************************/ + static NMActStageReturn -act_stage3_ip4_config_start(NMDevice * device, - NMIP4Config ** out_config, - NMDeviceStateReason *out_failure_reason) +act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) { - NMDeviceAdsl * self = NM_DEVICE_ADSL(device); + NMDeviceAdsl *self = NM_DEVICE_ADSL(device); NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE(self); - NMSettingAdsl * s_adsl; - NMActRequest * req; - GError * err = NULL; - const char * ppp_iface; - - req = nm_device_get_act_request(device); - g_return_val_if_fail(req, NM_ACT_STAGE_RETURN_FAILURE); + if (!priv->ppp_mgr) { + gs_free_error GError *error = NULL; + NMSettingAdsl *s_adsl; + const char *protocol; + NMActRequest *req; + const char *ppp_iface; + + req = nm_device_get_act_request(device); + g_return_val_if_fail(req, NM_ACT_STAGE_RETURN_FAILURE); + + s_adsl = nm_device_get_applied_setting(device, NM_TYPE_SETTING_ADSL); + g_return_val_if_fail(s_adsl, NM_ACT_STAGE_RETURN_FAILURE); + + protocol = nm_setting_adsl_get_protocol(s_adsl); + + _LOGD(LOGD_ADSL, "using ADSL protocol '%s'", protocol); + + if (nm_streq0(protocol, NM_SETTING_ADSL_PROTOCOL_PPPOA)) { + /* PPPoA doesn't need anything special */ + } else if (nm_streq0(protocol, NM_SETTING_ADSL_PROTOCOL_PPPOE)) { + /* PPPoE needs RFC2684 bridging before we can do PPP over it */ + if (priv->nas_ifindex <= 0) { + if (!priv->nas_update_source) { + if (!br2684_create_iface(self)) { + NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_BR2684_FAILED); + return NM_ACT_STAGE_RETURN_FAILURE; + } + } + return NM_ACT_STAGE_RETURN_POSTPONE; + } + } else + nm_assert(nm_streq0(protocol, NM_SETTING_ADSL_PROTOCOL_IPOATM)); + + /* PPPoE uses the NAS interface, not the ATM interface */ + if (nm_streq0(protocol, NM_SETTING_ADSL_PROTOCOL_PPPOE)) { + nm_assert(priv->nas_ifname); + ppp_iface = priv->nas_ifname; + _LOGD(LOGD_ADSL, "starting PPPoE on br2684 interface %s", priv->nas_ifname); + } else { + ppp_iface = nm_device_get_iface(device); + _LOGD(LOGD_ADSL, "starting PPPoA"); + } - s_adsl = nm_device_get_applied_setting(device, NM_TYPE_SETTING_ADSL); + priv->ppp_mgr = nm_ppp_mgr_start(&((const NMPppMgrConfig){ + .netns = nm_device_get_netns(device), + .parent_iface = ppp_iface, + .callback = _ppp_mgr_callback, + .user_data = self, + .act_req = req, + .ppp_username = nm_setting_adsl_get_username(s_adsl), + .timeout_secs = 30, + .baud_override = 0, + }), + &error); + if (!priv->ppp_mgr) { + _LOGW(LOGD_DEVICE | LOGD_PPP, "PPPoE failed to start: %s", error->message); + *out_failure_reason = NM_DEVICE_STATE_REASON_PPP_START_FAILED; + return NM_ACT_STAGE_RETURN_FAILURE; + } - g_return_val_if_fail(s_adsl, NM_ACT_STAGE_RETURN_FAILURE); + return NM_ACT_STAGE_RETURN_POSTPONE; + } - /* PPPoE uses the NAS interface, not the ATM interface */ - if (nm_streq0(nm_setting_adsl_get_protocol(s_adsl), NM_SETTING_ADSL_PROTOCOL_PPPOE)) { - nm_assert(priv->nas_ifname); - ppp_iface = priv->nas_ifname; + if (nm_ppp_mgr_get_state(priv->ppp_mgr) < NM_PPP_MGR_STATE_HAVE_IFINDEX) + return NM_ACT_STAGE_RETURN_POSTPONE; - _LOGD(LOGD_ADSL, "starting PPPoE on br2684 interface %s", priv->nas_ifname); - } else { - ppp_iface = nm_device_get_iface(device); - _LOGD(LOGD_ADSL, "starting PPPoA"); - } + return NM_ACT_STAGE_RETURN_SUCCESS; +} - priv->ppp_manager = nm_ppp_manager_create(ppp_iface, &err); +static void +act_stage3_ip_config(NMDevice *device, int addr_family) +{ + NMDeviceAdsl *self = NM_DEVICE_ADSL(device); + NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE(self); + NMPppMgrState ppp_state; - if (priv->ppp_manager) { - nm_ppp_manager_set_route_parameters(priv->ppp_manager, - nm_device_get_route_table(device, AF_INET), - nm_device_get_route_metric(device, AF_INET), - nm_device_get_route_table(device, AF_INET6), - nm_device_get_route_metric(device, AF_INET6)); + if (!priv->ppp_mgr) { + nm_assert_not_reached(); + return; } - if (!priv->ppp_manager - || !nm_ppp_manager_start(priv->ppp_manager, - req, - nm_setting_adsl_get_username(s_adsl), - 30, - 0, - &err)) { - _LOGW(LOGD_ADSL, "PPP failed to start: %s", err->message); - g_error_free(err); + ppp_state = nm_ppp_mgr_get_state(priv->ppp_mgr); - g_clear_object(&priv->ppp_manager); + nm_assert(NM_IN_SET(ppp_state, NM_PPP_MGR_STATE_HAVE_IFINDEX, NM_PPP_MGR_STATE_HAVE_IP_CONFIG)); - NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_PPP_START_FAILED); - return NM_ACT_STAGE_RETURN_FAILURE; + if (ppp_state < NM_PPP_MGR_STATE_HAVE_IP_CONFIG) { + nm_device_devip_set_state(device, AF_UNSPEC, NM_DEVICE_IP_STATE_PENDING, NULL); + return; } - g_signal_connect(priv->ppp_manager, - NM_PPP_MANAGER_SIGNAL_STATE_CHANGED, - G_CALLBACK(ppp_state_changed), - self); - g_signal_connect(priv->ppp_manager, - NM_PPP_MANAGER_SIGNAL_IFINDEX_SET, - G_CALLBACK(ppp_ifindex_set), - self); - g_signal_connect(priv->ppp_manager, - NM_PPP_MANAGER_SIGNAL_IP4_CONFIG, - G_CALLBACK(ppp_ip4_config), - self); - return NM_ACT_STAGE_RETURN_POSTPONE; -} - -static NMActStageReturn -act_stage3_ip_config_start(NMDevice * device, - int addr_family, - gpointer * out_config, - NMDeviceStateReason *out_failure_reason) -{ - if (addr_family == AF_INET) - return act_stage3_ip4_config_start(device, (NMIP4Config **) out_config, out_failure_reason); - - return NM_DEVICE_CLASS(nm_device_adsl_parent_class) - ->act_stage3_ip_config_start(device, addr_family, out_config, out_failure_reason); + _ppp_mgr_stage3_maybe_ready(self); } static void @@ -533,23 +546,15 @@ adsl_cleanup(NMDeviceAdsl *self) { NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE(self); - if (priv->ppp_manager) { - g_signal_handlers_disconnect_by_func(priv->ppp_manager, - G_CALLBACK(ppp_state_changed), - self); - g_signal_handlers_disconnect_by_func(priv->ppp_manager, G_CALLBACK(ppp_ip4_config), self); - nm_ppp_manager_stop(priv->ppp_manager, NULL, NULL, NULL); - g_clear_object(&priv->ppp_manager); - } + _ppp_mgr_cleanup(self); g_signal_handlers_disconnect_by_func(nm_device_get_platform(NM_DEVICE(self)), G_CALLBACK(link_changed_cb), self); - nm_close(priv->brfd); - priv->brfd = -1; + nm_clear_fd(&priv->brfd); - nm_clear_g_source(&priv->nas_update_id); + nm_clear_g_source_inst(&priv->nas_update_source); /* FIXME: kernel has no way of explicitly deleting the 'nasX' interface yet, * so it gets leaked. It does get destroyed when it's no longer in use, @@ -572,7 +577,7 @@ carrier_update_cb(gpointer user_data) { NMDeviceAdsl *self = NM_DEVICE_ADSL(user_data); int carrier; - char * path; + char *path; path = g_strdup_printf("/sys/class/atm/%s/carrier", NM_ASSERT_VALID_PATH_COMPONENT(nm_device_get_iface(NM_DEVICE(self)))); @@ -627,7 +632,7 @@ nm_device_adsl_init(NMDeviceAdsl *self) static void constructed(GObject *object) { - NMDeviceAdsl * self = NM_DEVICE_ADSL(object); + NMDeviceAdsl *self = NM_DEVICE_ADSL(object); NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE(self); G_OBJECT_CLASS(nm_device_adsl_parent_class)->constructed(object); @@ -681,9 +686,9 @@ static const NMDBusInterfaceInfoExtended interface_info_device_adsl = { static void nm_device_adsl_class_init(NMDeviceAdslClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->constructed = constructed; object_class->dispose = dispose; @@ -699,9 +704,9 @@ nm_device_adsl_class_init(NMDeviceAdslClass *klass) device_class->check_connection_compatible = check_connection_compatible; device_class->complete_connection = complete_connection; - device_class->act_stage2_config = act_stage2_config; - device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; - device_class->deactivate = deactivate; + device_class->act_stage2_config = act_stage2_config; + device_class->act_stage3_ip_config = act_stage3_ip_config; + device_class->deactivate = deactivate; obj_properties[PROP_ATM_INDEX] = g_param_spec_int(NM_DEVICE_ADSL_ATM_INDEX, diff --git a/src/core/devices/bluetooth/nm-bluez-manager.c b/src/core/devices/bluetooth/nm-bluez-manager.c index 36e442ad..05f85297 100644 --- a/src/core/devices/bluetooth/nm-bluez-manager.c +++ b/src/core/devices/bluetooth/nm-bluez-manager.c @@ -38,7 +38,7 @@ #define _NM_BT_CAPABILITY_SUPPORTED (NM_BT_CAPABILITY_NAP | _NM_BT_CAPABILITY_SUPPORTED_DUN) typedef struct { - const char * bdaddr; + const char *bdaddr; CList lst_head; NMBluetoothCapabilities bt_type : 8; char bdaddr_data[]; @@ -46,24 +46,24 @@ typedef struct { typedef struct { NMSettingsConnection *sett_conn; - ConnDataHead * cdata_hd; + ConnDataHead *cdata_hd; CList lst; } ConnDataElem; typedef struct { - GCancellable * ext_cancellable; - GCancellable * int_cancellable; + GCancellable *ext_cancellable; + GCancellable *int_cancellable; NMBtVTableRegisterCallback callback; gpointer callback_user_data; gulong ext_cancelled_id; } NetworkServerRegisterReqData; typedef struct { - GCancellable * ext_cancellable; - GCancellable * int_cancellable; + GCancellable *ext_cancellable; + GCancellable *int_cancellable; NMBluezManagerConnectCb callback; gpointer callback_user_data; - char * device_name; + char *device_name; gulong ext_cancelled_id; guint timeout_id; guint timeout_wait_connect_id; @@ -97,16 +97,16 @@ typedef struct { struct { CList lst; - char * adapter_address; - NMDevice * device_br; + char *adapter_address; + NMDevice *device_br; NetworkServerRegisterReqData *r_req_data; } x_network_server; struct { NMSettingsConnection *panu_connection; - NMDeviceBt * device_bt; + NMDeviceBt *device_bt; DeviceConnectReqData *c_req_data; - NMBluez5DunContext * connect_dun_context; + NMBluez5DunContext *connect_dun_context; gulong device_bt_signal_id; } x_device; @@ -142,7 +142,7 @@ typedef struct { } BzDBusObj; typedef struct { - NMManager * manager; + NMManager *manager; NMSettings *settings; GDBusConnection *dbus_connection; @@ -194,7 +194,7 @@ NM_DEVICE_FACTORY_DECLARE_TYPES(NM_DEVICE_FACTORY_DECLARE_LINK_TYPES( NM_LINK_TYPE_BNEP) NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES(NM_SETTING_BLUETOOTH_SETTING_NAME)) G_MODULE_EXPORT NMDeviceFactory * - nm_device_factory_create(GError **error) +nm_device_factory_create(GError **error) { return g_object_new(NM_TYPE_BLUEZ_MANAGER, NULL); } @@ -214,8 +214,8 @@ convert_uuids_to_capabilities(const char *const *strv) if (strv) { for (; strv[0]; strv++) { gs_free char *s_part1 = NULL; - const char * str = strv[0]; - const char * s; + const char *str = strv[0]; + const char *s; s = strchr(str, '-'); if (!s) @@ -245,8 +245,8 @@ static void _connect_disconnect(NMBluezManager *self, BzDBusObj *bzobj, cons static gboolean _bzobjs_network_server_is_usable(const BzDBusObj *bzobj, gboolean require_powered); static gboolean _bzobjs_is_dead(const BzDBusObj *bzobj); static gboolean _bzobjs_device_is_usable(const BzDBusObj *bzobj, - BzDBusObj ** out_adapter_bzobj, - gboolean * out_create_panu_connection); + BzDBusObj **out_adapter_bzobj, + gboolean *out_create_panu_connection); static gboolean _bzobjs_adapter_is_usable_for_device(const BzDBusObj *bzobj); static ConnDataHead * _conn_track_find_head(NMBluezManager *self, NMBluetoothCapabilities bt_type, const char *bdaddr); @@ -293,9 +293,9 @@ _network_server_register_req_data_complete(NetworkServerRegisterReqData *r_req_d static void _device_connect_req_data_complete(DeviceConnectReqData *c_req_data, - NMBluezManager * self, - const char * device_name, - GError * error) + NMBluezManager *self, + const char *device_name, + GError *error) { nm_assert((!!device_name) != (!!error)); @@ -371,7 +371,7 @@ _bz_dbus_obj_free(BzDBusObj *bzobj) static const char * _bzobj_to_string(const BzDBusObj *bzobj, char *buf, gsize len) { - char * buf0 = buf; + char *buf0 = buf; const char *prefix = ""; gboolean device_is_usable; gboolean create_panu_connection = FALSE; @@ -591,7 +591,7 @@ static BzDBusObj * _bzobjs_add(NMBluezManager *self, const char *object_path) { NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE(self); - BzDBusObj * bzobj; + BzDBusObj *bzobj; bzobj = _bz_dbus_obj_new(self, object_path); if (!g_hash_table_add(priv->bzobjs, bzobj)) @@ -642,14 +642,14 @@ _bzobjs_adapter_is_usable_for_device(const BzDBusObj *bzobj) static gboolean _bzobjs_device_is_usable(const BzDBusObj *bzobj, - BzDBusObj ** out_adapter_bzobj, - gboolean * out_create_panu_connection) + BzDBusObj **out_adapter_bzobj, + gboolean *out_create_panu_connection) { - NMBluezManager * self; + NMBluezManager *self; NMBluezManagerPrivate *priv; gboolean usable_dun = FALSE; gboolean usable_nap = FALSE; - BzDBusObj * bzobj_adapter; + BzDBusObj *bzobj_adapter; gboolean create_panu_connection = FALSE; if (!bzobj->d_has_device_iface @@ -805,14 +805,14 @@ _conn_track_find_elem(NMBluezManager *self, NMSettingsConnection *sett_conn) } static gboolean -_conn_track_is_relevant_connection(NMConnection * connection, +_conn_track_is_relevant_connection(NMConnection *connection, NMBluetoothCapabilities *out_bt_type, - const char ** out_bdaddr) + const char **out_bdaddr) { - NMSettingBluetooth * s_bt; + NMSettingBluetooth *s_bt; NMBluetoothCapabilities bt_type; - const char * bdaddr; - const char * b_type; + const char *bdaddr; + const char *b_type; s_bt = nm_connection_get_setting_bluetooth(connection); if (!s_bt) @@ -840,9 +840,9 @@ _conn_track_is_relevant_connection(NMConnection * connection, } static gboolean -_conn_track_is_relevant_sett_conn(NMSettingsConnection * sett_conn, +_conn_track_is_relevant_sett_conn(NMSettingsConnection *sett_conn, NMBluetoothCapabilities *out_bt_type, - const char ** out_bdaddr) + const char **out_bdaddr) { NMConnection *connection; @@ -854,25 +854,25 @@ _conn_track_is_relevant_sett_conn(NMSettingsConnection * sett_conn, } static gboolean -_conn_track_is_relevant_for_sett_conn(NMSettingsConnection * sett_conn, +_conn_track_is_relevant_for_sett_conn(NMSettingsConnection *sett_conn, NMBluetoothCapabilities bt_type, - const char * bdaddr) + const char *bdaddr) { NMBluetoothCapabilities x_bt_type; - const char * x_bdaddr; + const char *x_bdaddr; return bdaddr && _conn_track_is_relevant_sett_conn(sett_conn, &x_bt_type, &x_bdaddr) && x_bt_type == bt_type && nm_streq(x_bdaddr, bdaddr); } static void -_conn_track_schedule_notify(NMBluezManager * self, +_conn_track_schedule_notify(NMBluezManager *self, NMBluetoothCapabilities bt_type, - const char * bdaddr) + const char *bdaddr) { NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE(self); GHashTableIter iter; - BzDBusObj * bzobj; + BzDBusObj *bzobj; g_hash_table_iter_init(&iter, priv->bzobjs); while (g_hash_table_iter_next(&iter, (gpointer *) &bzobj, NULL)) { @@ -885,19 +885,19 @@ _conn_track_schedule_notify(NMBluezManager * self, } static void -_conn_track_update(NMBluezManager * self, +_conn_track_update(NMBluezManager *self, NMSettingsConnection *sett_conn, gboolean track, - gboolean * out_changed, - gboolean * out_changed_usable, - ConnDataElem ** out_conn_data_elem) -{ - NMBluezManagerPrivate * priv = NM_BLUEZ_MANAGER_GET_PRIVATE(self); - ConnDataHead * cdata_hd; - ConnDataElem * cdata_el; - ConnDataElem * cdata_el_remove = NULL; + gboolean *out_changed, + gboolean *out_changed_usable, + ConnDataElem **out_conn_data_elem) +{ + NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE(self); + ConnDataHead *cdata_hd; + ConnDataElem *cdata_el; + ConnDataElem *cdata_el_remove = NULL; NMBluetoothCapabilities bt_type; - const char * bdaddr; + const char *bdaddr; gboolean changed = FALSE; gboolean changed_usable = FALSE; char sbuf_cap[100]; @@ -946,7 +946,7 @@ _conn_track_update(NMBluezManager * self, out_remove: if (cdata_el_remove) { GHashTableIter iter; - BzDBusObj * bzobj; + BzDBusObj *bzobj; _LOGT("connection: untrack for %s, %s: %s (%s)", nm_bluetooth_capability_to_string(cdata_el_remove->cdata_hd->bt_type, @@ -989,10 +989,10 @@ cp_connection_added(NMSettings *settings, NMSettingsConnection *sett_conn, NMBlu } static void -cp_connection_updated(NMSettings * settings, +cp_connection_updated(NMSettings *settings, NMSettingsConnection *sett_conn, guint update_reason_u, - NMBluezManager * self) + NMBluezManager *self) { _conn_track_update(self, sett_conn, TRUE, NULL, NULL, NULL); } @@ -1032,8 +1032,8 @@ _network_server_find_has_device(NMBluezManagerPrivate *priv, NMDevice *device) static BzDBusObj * _network_server_find_available(NMBluezManagerPrivate *priv, - const char * addr, - NMDevice * device_accept_busy) + const char *addr, + NMDevice *device_accept_busy) { BzDBusObj *bzobj; @@ -1052,10 +1052,10 @@ _network_server_find_available(NMBluezManagerPrivate *priv, static gboolean _network_server_vt_is_available(const NMBtVTableNetworkServer *vtable, - const char * addr, - NMDevice * device_accept_busy) + const char *addr, + NMDevice *device_accept_busy) { - NMBluezManager * self = _network_server_get_bluez_manager(vtable); + NMBluezManager *self = _network_server_get_bluez_manager(vtable); NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE(self); return !!_network_server_find_available(priv, addr, device_accept_busy); @@ -1064,9 +1064,9 @@ _network_server_vt_is_available(const NMBtVTableNetworkServer *vtable, static void _network_server_register_cb(GObject *source_object, GAsyncResult *res, gpointer user_data) { - gs_unref_variant GVariant *ret = NULL; - gs_free_error GError *error = NULL; - BzDBusObj * bzobj; + gs_unref_variant GVariant *ret = NULL; + gs_free_error GError *error = NULL; + BzDBusObj *bzobj; ret = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source_object), res, &error); if (!ret && nm_utils_error_is_cancelled(error)) @@ -1092,18 +1092,18 @@ _network_server_register_cancelled_cb(GCancellable *cancellable, BzDBusObj *bzob static gboolean _network_server_vt_register_bridge(const NMBtVTableNetworkServer *vtable, - const char * addr, - NMDevice * device, - GCancellable * cancellable, + const char *addr, + NMDevice *device, + GCancellable *cancellable, NMBtVTableRegisterCallback callback, gpointer callback_user_data, - GError ** error) + GError **error) { - NMBluezManager * self = _network_server_get_bluez_manager(vtable); - NMBluezManagerPrivate * priv = NM_BLUEZ_MANAGER_GET_PRIVATE(self); + NMBluezManager *self = _network_server_get_bluez_manager(vtable); + NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE(self); NetworkServerRegisterReqData *r_req_data; - BzDBusObj * bzobj; - const char * ifname; + BzDBusObj *bzobj; + const char *ifname; g_return_val_if_fail(NM_IS_DEVICE(device), FALSE); g_return_val_if_fail(G_IS_CANCELLABLE(cancellable), FALSE); @@ -1174,8 +1174,8 @@ _network_server_vt_register_bridge(const NMBtVTableNetworkServer *vtable, static void _network_server_unregister_bridge_complete_on_idle_cb(gpointer user_data, GCancellable *cancellable) { - gs_free_error GError * error = NULL; - gs_free char * reason = NULL; + gs_free_error GError *error = NULL; + gs_free char *reason = NULL; NetworkServerRegisterReqData *r_req_data; nm_utils_user_data_unpack(user_data, &r_req_data, &reason); @@ -1190,9 +1190,9 @@ _network_server_unregister_bridge_complete_on_idle_cb(gpointer user_data, GCance static void _network_server_unregister_bridge(NMBluezManager *self, BzDBusObj *bzobj, const char *reason) { - NMBluezManagerPrivate * priv = NM_BLUEZ_MANAGER_GET_PRIVATE(self); + NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE(self); _nm_unused gs_unref_object NMDevice *device = NULL; - NetworkServerRegisterReqData * r_req_data; + NetworkServerRegisterReqData *r_req_data; nm_assert(NM_IS_DEVICE(bzobj->x_network_server.device_br)); @@ -1242,9 +1242,9 @@ _network_server_unregister_bridge(NMBluezManager *self, BzDBusObj *bzobj, const static gboolean _network_server_vt_unregister_bridge(const NMBtVTableNetworkServer *vtable, NMDevice *device) { - NMBluezManager * self = _network_server_get_bluez_manager(vtable); + NMBluezManager *self = _network_server_get_bluez_manager(vtable); NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE(self); - BzDBusObj * bzobj; + BzDBusObj *bzobj; g_return_val_if_fail(NM_IS_DEVICE(device), FALSE); @@ -1258,7 +1258,7 @@ _network_server_vt_unregister_bridge(const NMBtVTableNetworkServer *vtable, NMDe static void _network_server_process_change(BzDBusObj *bzobj, gboolean *out_emit_device_availability_changed) { - NMBluezManager * self = bzobj->self; + NMBluezManager *self = bzobj->self; NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE(self); gboolean network_server_is_usable; gboolean emit_device_availability_changed = FALSE; @@ -1303,13 +1303,13 @@ _network_server_process_change(BzDBusObj *bzobj, gboolean *out_emit_device_avail static void _conn_create_panu_connection(NMBluezManager *self, BzDBusObj *bzobj) { - NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE(self); + NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE(self); gs_unref_object NMConnection *connection = NULL; - NMSettingsConnection * added; - NMSetting * setting; - gs_free char * id = NULL; + NMSettingsConnection *added; + NMSetting *setting; + gs_free char *id = NULL; char uuid[37]; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; nm_uuid_generate_random_str_arr(uuid); id = g_strdup_printf(_("%s Network"), bzobj->d_device.name); @@ -1398,7 +1398,7 @@ _device_state_changed_cb(NMDevice *device, static void _device_process_change(BzDBusObj *bzobj) { - NMBluezManager *self = bzobj->self; + NMBluezManager *self = bzobj->self; gs_unref_object NMDeviceBt *device_added = NULL; gs_unref_object NMDeviceBt *device_deleted = NULL; gboolean device_is_usable; @@ -1513,7 +1513,7 @@ static void _process_change_idle_all(NMBluezManager *self, gboolean *out_emit_device_availability_changed) { NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE(self); - BzDBusObj * bzobj; + BzDBusObj *bzobj; while ( (bzobj = @@ -1537,7 +1537,7 @@ _process_change_idle_all(NMBluezManager *self, gboolean *out_emit_device_availab static gboolean _process_change_idle_cb(gpointer user_data) { - NMBluezManager * self = user_data; + NMBluezManager *self = user_data; NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE(self); gboolean emit_device_availability_changed = FALSE; @@ -1622,7 +1622,7 @@ _dbus_process_changes(NMBluezManager *self, BzDBusObj *bzobj, const char *log_re if (recheck_devices_for_adapter) { GHashTableIter iter; - BzDBusObj * bzobj2; + BzDBusObj *bzobj2; /* we got a change to the availability of an adapter. We might need to recheck * all devices that use this adapter... */ @@ -1651,17 +1651,17 @@ _dbus_process_changes(NMBluezManager *self, BzDBusObj *bzobj, const char *log_re NM_BLUEZ5_NETWORK_SERVER_INTERFACE) static gboolean -_dbus_handle_properties_changed(NMBluezManager * self, - const char * object_path, - const char * interface_name, - GVariant * changed_properties, +_dbus_handle_properties_changed(NMBluezManager *self, + const char *object_path, + const char *interface_name, + GVariant *changed_properties, const char *const *invalidated_properties, - BzDBusObj ** inout_bzobj) + BzDBusObj **inout_bzobj) { - BzDBusObj * bzobj = NULL; + BzDBusObj *bzobj = NULL; gboolean changed = FALSE; - const char * property_name; - GVariant * property_value; + const char *property_name; + GVariant *property_value; GVariantIter iter_prop; gsize i; @@ -1933,14 +1933,14 @@ _dbus_handle_properties_changed(NMBluezManager * self, static void _dbus_handle_interface_added(NMBluezManager *self, - const char * object_path, - GVariant * ifaces, + const char *object_path, + GVariant *ifaces, gboolean initial_get_managed_objects) { - BzDBusObj * bzobj = NULL; + BzDBusObj *bzobj = NULL; gboolean changed = FALSE; - const char * interface_name; - GVariant * changed_properties; + const char *interface_name; + GVariant *changed_properties; GVariantIter iter_ifaces; nm_assert(g_variant_is_of_type(ifaces, G_VARIANT_TYPE("a{sa{sv}}"))); @@ -1966,9 +1966,9 @@ _dbus_handle_interface_added(NMBluezManager *self, } static gboolean -_dbus_handle_interface_removed(NMBluezManager * self, - const char * object_path, - BzDBusObj ** inout_bzobj, +_dbus_handle_interface_removed(NMBluezManager *self, + const char *object_path, + BzDBusObj **inout_bzobj, const char *const *removed_interfaces) { gboolean changed = FALSE; @@ -2056,16 +2056,16 @@ _dbus_handle_interface_removed(NMBluezManager * self, static void _dbus_managed_objects_changed_cb(GDBusConnection *connection, - const char * sender_name, - const char * arg_object_path, - const char * interface_name, - const char * signal_name, - GVariant * parameters, + const char *sender_name, + const char *arg_object_path, + const char *interface_name, + const char *signal_name, + GVariant *parameters, gpointer user_data) { - NMBluezManager * self = user_data; + NMBluezManager *self = user_data; NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE(self); - BzDBusObj * bzobj = NULL; + BzDBusObj *bzobj = NULL; gboolean changed; nm_assert(nm_streq0(interface_name, DBUS_INTERFACE_OBJECT_MANAGER)); @@ -2077,7 +2077,7 @@ _dbus_managed_objects_changed_cb(GDBusConnection *connection, if (nm_streq(signal_name, "InterfacesAdded")) { gs_unref_variant GVariant *interfaces_and_properties = NULL; - const char * object_path; + const char *object_path; if (!g_variant_is_of_type(parameters, G_VARIANT_TYPE("(oa{sa{sv}})"))) return; @@ -2090,7 +2090,7 @@ _dbus_managed_objects_changed_cb(GDBusConnection *connection, if (nm_streq(signal_name, "InterfacesRemoved")) { gs_free const char **interfaces = NULL; - const char * object_path; + const char *object_path; if (!g_variant_is_of_type(parameters, G_VARIANT_TYPE("(oas)"))) return; @@ -2106,19 +2106,19 @@ _dbus_managed_objects_changed_cb(GDBusConnection *connection, static void _dbus_properties_changed_cb(GDBusConnection *connection, - const char * sender_name, - const char * object_path, - const char * signal_interface_name, - const char * signal_name, - GVariant * parameters, + const char *sender_name, + const char *object_path, + const char *signal_interface_name, + const char *signal_name, + GVariant *parameters, gpointer user_data) { - NMBluezManager * self = user_data; - NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE(self); - const char * interface_name; + NMBluezManager *self = user_data; + NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE(self); + const char *interface_name; gs_unref_variant GVariant *changed_properties = NULL; - gs_free const char ** invalidated_properties = NULL; - BzDBusObj * bzobj = NULL; + gs_free const char **invalidated_properties = NULL; + BzDBusObj *bzobj = NULL; if (priv->get_managed_objects_cancellable) { /* we still wait for the initial GetManagedObjects(). Ignore the event. */ @@ -2146,11 +2146,11 @@ _dbus_properties_changed_cb(GDBusConnection *connection, static void _dbus_get_managed_objects_cb(GVariant *result, GError *error, gpointer user_data) { - NMBluezManager * self; + NMBluezManager *self; NMBluezManagerPrivate *priv; GVariantIter iter; - const char * object_path; - GVariant * ifaces; + const char *object_path; + GVariant *ifaces; if (!result && nm_utils_error_is_cancelled(error)) return; @@ -2184,7 +2184,7 @@ _cleanup_for_name_owner(NMBluezManager *self) NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE(self); gboolean emit_device_availability_changed = FALSE; GHashTableIter iter; - BzDBusObj * bzobj; + BzDBusObj *bzobj; gboolean first = TRUE; nm_clear_g_cancellable(&priv->get_managed_objects_cancellable); @@ -2217,7 +2217,7 @@ static void name_owner_changed(NMBluezManager *self, const char *owner) { _nm_unused gs_unref_object NMBluezManager *self_keep_alive = g_object_ref(self); - NMBluezManagerPrivate * priv = NM_BLUEZ_MANAGER_GET_PRIVATE(self); + NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE(self); owner = nm_str_not_empty(owner); @@ -2270,15 +2270,15 @@ name_owner_changed(NMBluezManager *self, const char *owner) static void name_owner_changed_cb(GDBusConnection *connection, - const char * sender_name, - const char * object_path, - const char * interface_name, - const char * signal_name, - GVariant * parameters, + const char *sender_name, + const char *object_path, + const char *interface_name, + const char *signal_name, + GVariant *parameters, gpointer user_data) { NMBluezManager *self = user_data; - const char * new_owner; + const char *new_owner; if (!g_variant_is_of_type(parameters, G_VARIANT_TYPE("(sss)"))) return; @@ -2321,8 +2321,8 @@ _cleanup_all(NMBluezManager *self) static void start(NMDeviceFactory *factory) { - NMBluezManager * self; - NMBluezManagerPrivate * priv; + NMBluezManager *self; + NMBluezManagerPrivate *priv; NMSettingsConnection *const *sett_conns; guint n_sett_conns; guint i; @@ -2378,12 +2378,12 @@ start(NMDeviceFactory *factory) /*****************************************************************************/ static void -_connect_returned(NMBluezManager * self, - BzDBusObj * bzobj, +_connect_returned(NMBluezManager *self, + BzDBusObj *bzobj, NMBluetoothCapabilities bt_type, - const char * device_name, - NMBluez5DunContext * dun_context, - GError * error) + const char *device_name, + NMBluez5DunContext *dun_context, + GError *error) { char sbuf_cap[100]; @@ -2449,8 +2449,8 @@ _connect_dun_notify_tty_hangup_cb(NMBluez5DunContext *context, gpointer user_dat static void _connect_dun_step2_cb(NMBluez5DunContext *context, - const char * rfcomm_dev, - GError * error, + const char *rfcomm_dev, + GError *error, gpointer user_data) { BzDBusObj *bzobj; @@ -2491,10 +2491,10 @@ _connect_dun_step2_cb(NMBluez5DunContext *context, static void _connect_dun_step1_cb(GObject *source_object, GAsyncResult *res, gpointer user_data) { - gs_unref_variant GVariant *ret = NULL; - gs_free_error GError *error = NULL; - BzDBusObj * bzobj_adapter; - BzDBusObj * bzobj; + gs_unref_variant GVariant *ret = NULL; + gs_free_error GError *error = NULL; + BzDBusObj *bzobj_adapter; + BzDBusObj *bzobj; ret = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source_object), res, &error); @@ -2537,9 +2537,9 @@ static void _connect_nap_cb(GObject *source_object, GAsyncResult *res, gpointer user_data) { gs_unref_variant GVariant *ret = NULL; - const char * network_iface_name = NULL; - gs_free_error GError *error = NULL; - BzDBusObj * bzobj; + const char *network_iface_name = NULL; + gs_free_error GError *error = NULL; + BzDBusObj *bzobj; ret = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source_object), res, &error); @@ -2584,7 +2584,7 @@ static void _connect_disconnect(NMBluezManager *self, BzDBusObj *bzobj, const char *reason) { NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE(self); - DeviceConnectReqData * c_req_data; + DeviceConnectReqData *c_req_data; char sbuf_cap[100]; gboolean bt_type; @@ -2655,19 +2655,19 @@ _connect_disconnect(NMBluezManager *self, BzDBusObj *bzobj, const char *reason) } gboolean -nm_bluez_manager_connect(NMBluezManager * self, - const char * object_path, +nm_bluez_manager_connect(NMBluezManager *self, + const char *object_path, NMBluetoothCapabilities connection_bt_type, int timeout_msec, - GCancellable * cancellable, + GCancellable *cancellable, NMBluezManagerConnectCb callback, gpointer callback_user_data, - GError ** error) + GError **error) { gs_unref_object GCancellable *int_cancellable = NULL; - DeviceConnectReqData * c_req_data; - NMBluezManagerPrivate * priv; - BzDBusObj * bzobj; + DeviceConnectReqData *c_req_data; + NMBluezManagerPrivate *priv; + BzDBusObj *bzobj; char sbuf_cap[100]; g_return_val_if_fail(NM_IS_BLUEZ_MANAGER(self), FALSE); @@ -2781,11 +2781,11 @@ nm_bluez_manager_disconnect(NMBluezManager *self, const char *object_path) /*****************************************************************************/ static NMDevice * -create_device(NMDeviceFactory * factory, - const char * iface, +create_device(NMDeviceFactory *factory, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore) + NMConnection *connection, + gboolean *out_ignore) { *out_ignore = TRUE; g_return_val_if_fail(plink->type == NM_LINK_TYPE_BNEP, NULL); @@ -2845,7 +2845,7 @@ nm_bluez_manager_init(NMBluezManager *self) static void dispose(GObject *object) { - NMBluezManager * self = NM_BLUEZ_MANAGER(object); + NMBluezManager *self = NM_BLUEZ_MANAGER(object); NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE(self); /* FIXME(shutdown): we need a nm_device_factory_stop() hook to first unregister all @@ -2877,7 +2877,7 @@ dispose(GObject *object) static void nm_bluez_manager_class_init(NMBluezManagerClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDeviceFactoryClass *factory_class = NM_DEVICE_FACTORY_CLASS(klass); object_class->dispose = dispose; diff --git a/src/core/devices/bluetooth/nm-bluez-manager.h b/src/core/devices/bluetooth/nm-bluez-manager.h index 04bfea7d..299f5c3b 100644 --- a/src/core/devices/bluetooth/nm-bluez-manager.h +++ b/src/core/devices/bluetooth/nm-bluez-manager.h @@ -24,18 +24,18 @@ GType nm_bluez_manager_get_type(void); typedef void (*NMBluezManagerConnectCb)( NMBluezManager *self, gboolean is_completed /* or else is early notification with DUN path */, - const char * device_name, - GError * error, + const char *device_name, + GError *error, gpointer user_data); -gboolean nm_bluez_manager_connect(NMBluezManager * self, - const char * object_path, +gboolean nm_bluez_manager_connect(NMBluezManager *self, + const char *object_path, NMBluetoothCapabilities connection_bt_type, int timeout_msec, - GCancellable * cancellable, + GCancellable *cancellable, NMBluezManagerConnectCb callback, gpointer callback_user_data, - GError ** error); + GError **error); void nm_bluez_manager_disconnect(NMBluezManager *self, const char *object_path); diff --git a/src/core/devices/bluetooth/nm-bluez5-dun.c b/src/core/devices/bluetooth/nm-bluez5-dun.c index 7efbfaf4..426bab0c 100644 --- a/src/core/devices/bluetooth/nm-bluez5-dun.c +++ b/src/core/devices/bluetooth/nm-bluez5-dun.c @@ -23,7 +23,7 @@ /*****************************************************************************/ typedef struct { - GCancellable * cancellable; + GCancellable *cancellable; NMBluez5DunConnectCb callback; gpointer callback_user_data; @@ -265,10 +265,10 @@ _connect_create_rfcomm(NMBluez5DunContext *context) static gboolean _connect_socket_connect_cb(int fd, GIOCondition condition, gpointer user_data) { - NMBluez5DunContext *context = user_data; - gs_free_error GError *error = NULL; - int errsv = 0; - socklen_t slen = sizeof(errsv); + NMBluez5DunContext *context = user_data; + gs_free_error GError *error = NULL; + int errsv = 0; + socklen_t slen = sizeof(errsv); int r; nm_clear_g_source_inst(&context->cdat->source); @@ -415,7 +415,7 @@ _connect_sdp_search_cb(uint8_t type, uint16_t status, uint8_t *rsp, size_t size, do { sdp_record_t *rec; int recsize = 0; - sdp_list_t * protos; + sdp_list_t *protos; rec = sdp_extract_pdu(rsp, bytesleft, &recsize); if (!rec) @@ -454,8 +454,8 @@ _connect_sdp_search_cb(uint8_t type, uint16_t status, uint8_t *rsp, size_t size, static gboolean _connect_sdp_search_io_cb(int fd, GIOCondition condition, gpointer user_data) { - NMBluez5DunContext *context = user_data; - gs_free_error GError *error = NULL; + NMBluez5DunContext *context = user_data; + gs_free_error GError *error = NULL; int errsv; if (condition & (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) { @@ -505,8 +505,8 @@ _connect_sdp_search_io_cb(int fd, GIOCondition condition, gpointer user_data) static gboolean _connect_sdp_session_start_on_idle_cb(gpointer user_data) { - NMBluez5DunContext *context = user_data; - gs_free_error GError *error = NULL; + NMBluez5DunContext *context = user_data; + gs_free_error GError *error = NULL; nm_clear_g_source_inst(&context->cdat->source); @@ -521,15 +521,15 @@ _connect_sdp_session_start_on_idle_cb(gpointer user_data) static gboolean _connect_sdp_io_cb(int fd, GIOCondition condition, gpointer user_data) { - NMBluez5DunContext *context = user_data; - sdp_list_t * search; - sdp_list_t * attrs; - uuid_t svclass; - uint16_t attr; - int errsv; - int fd_err = 0; - int r; - socklen_t len = sizeof(fd_err); + NMBluez5DunContext *context = user_data; + sdp_list_t *search; + sdp_list_t *attrs; + uuid_t svclass; + uint16_t attr; + int errsv; + int fd_err = 0; + int r; + socklen_t len = sizeof(fd_err); gs_free_error GError *error = NULL; nm_clear_g_source_inst(&context->cdat->source); @@ -657,17 +657,17 @@ _connect_sdp_session_start(NMBluez5DunContext *context, GError **error) /*****************************************************************************/ gboolean -nm_bluez5_dun_connect(const char * adapter, - const char * remote, - GCancellable * cancellable, +nm_bluez5_dun_connect(const char *adapter, + const char *remote, + GCancellable *cancellable, NMBluez5DunConnectCb callback, gpointer callback_user_data, NMBluez5DunNotifyTtyHangupCb notify_tty_hangup_cb, gpointer notify_tty_hangup_user_data, - GError ** error) + GError **error) { nm_auto_free_context NMBluez5DunContext *context = NULL; - ConnectData * cdat; + ConnectData *cdat; gsize src_l; gsize dst_l; diff --git a/src/core/devices/bluetooth/nm-bluez5-dun.h b/src/core/devices/bluetooth/nm-bluez5-dun.h index 020d4119..72ca1380 100644 --- a/src/core/devices/bluetooth/nm-bluez5-dun.h +++ b/src/core/devices/bluetooth/nm-bluez5-dun.h @@ -11,20 +11,20 @@ typedef struct _NMBluez5DunContext NMBluez5DunContext; #if WITH_BLUEZ5_DUN typedef void (*NMBluez5DunConnectCb)(NMBluez5DunContext *context, - const char * rfcomm_dev, - GError * error, + const char *rfcomm_dev, + GError *error, gpointer user_data); typedef void (*NMBluez5DunNotifyTtyHangupCb)(NMBluez5DunContext *context, gpointer user_data); -gboolean nm_bluez5_dun_connect(const char * adapter, - const char * remote, - GCancellable * cancellable, +gboolean nm_bluez5_dun_connect(const char *adapter, + const char *remote, + GCancellable *cancellable, NMBluez5DunConnectCb callback, gpointer callback_user_data, NMBluez5DunNotifyTtyHangupCb notify_tty_hangup_cb, gpointer notify_tty_hangup_user_data, - GError ** error); + GError **error); void nm_bluez5_dun_disconnect(NMBluez5DunContext *context); diff --git a/src/core/devices/bluetooth/nm-device-bt.c b/src/core/devices/bluetooth/nm-device-bt.c index 3dbfbbe0..39b5c4ec 100644 --- a/src/core/devices/bluetooth/nm-device-bt.c +++ b/src/core/devices/bluetooth/nm-device-bt.c @@ -26,7 +26,6 @@ #include "settings/nm-settings-connection.h" #include "nm-utils.h" #include "nm-bt-error.h" -#include "nm-ip4-config.h" #include "libnm-platform/nm-platform.h" #include "devices/wwan/nm-modem-manager.h" @@ -115,7 +114,7 @@ static NMBluetoothCapabilities get_connection_bt_type(NMConnection *connection) { NMSettingBluetooth *s_bt; - const char * bt_type; + const char *bt_type; s_bt = nm_connection_get_setting_bluetooth(connection); @@ -133,10 +132,10 @@ get_connection_bt_type(NMConnection *connection) } static gboolean -get_connection_bt_type_check(NMDeviceBt * self, - NMConnection * connection, +get_connection_bt_type_check(NMDeviceBt *self, + NMConnection *connection, NMBluetoothCapabilities *out_bt_type, - GError ** error) + GError **error) { NMBluetoothCapabilities bt_type; @@ -170,8 +169,8 @@ get_generic_capabilities(NMDevice *device) static gboolean can_auto_connect(NMDevice *device, NMSettingsConnection *sett_conn, char **specific_object) { - NMDeviceBt * self = NM_DEVICE_BT(device); - NMDeviceBtPrivate * priv = NM_DEVICE_BT_GET_PRIVATE(self); + NMDeviceBt *self = NM_DEVICE_BT(device); + NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE(self); NMBluetoothCapabilities bt_type; nm_assert(!specific_object || !*specific_object); @@ -195,10 +194,10 @@ can_auto_connect(NMDevice *device, NMSettingsConnection *sett_conn, char **speci static gboolean check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error) { - NMDeviceBt * self = NM_DEVICE_BT(device); - NMDeviceBtPrivate * priv = NM_DEVICE_BT_GET_PRIVATE(self); + NMDeviceBt *self = NM_DEVICE_BT(device); + NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE(self); NMSettingBluetooth *s_bt; - const char * bdaddr; + const char *bdaddr; if (!NM_DEVICE_CLASS(nm_device_bt_parent_class) ->check_connection_compatible(device, connection, error)) @@ -227,14 +226,14 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError * } static gboolean -check_connection_available(NMDevice * device, - NMConnection * connection, +check_connection_available(NMDevice *device, + NMConnection *connection, NMDeviceCheckConAvailableFlags flags, - const char * specific_object, - GError ** error) + const char *specific_object, + GError **error) { - NMDeviceBt * self = NM_DEVICE_BT(device); - NMDeviceBtPrivate * priv = NM_DEVICE_BT_GET_PRIVATE(self); + NMDeviceBt *self = NM_DEVICE_BT(device); + NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE(self); NMBluetoothCapabilities bt_type; if (!get_connection_bt_type_check(self, connection, &bt_type, error)) @@ -251,23 +250,23 @@ check_connection_available(NMDevice * device, } static gboolean -complete_connection(NMDevice * device, - NMConnection * connection, - const char * specific_object, +complete_connection(NMDevice *device, + NMConnection *connection, + const char *specific_object, NMConnection *const *existing_connections, - GError ** error) + GError **error) { - NMDeviceBtPrivate * priv = NM_DEVICE_BT_GET_PRIVATE(device); + NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE(device); NMSettingBluetooth *s_bt; - const char * setting_bdaddr; - const char * ctype; + const char *setting_bdaddr; + const char *ctype; gboolean is_dun = FALSE; gboolean is_pan = FALSE; - NMSettingGsm * s_gsm; - NMSettingCdma * s_cdma; - NMSettingSerial * s_serial; - NMSettingPpp * s_ppp; - const char * fallback_prefix = NULL, *preferred = NULL; + NMSettingGsm *s_gsm; + NMSettingCdma *s_cdma; + NMSettingSerial *s_serial; + NMSettingPpp *s_ppp; + const char *fallback_prefix = NULL, *preferred = NULL; s_gsm = nm_connection_get_setting_gsm(connection); s_cdma = nm_connection_get_setting_cdma(connection); @@ -424,44 +423,10 @@ ppp_stats(NMModem *modem, guint i_in_bytes, guint i_out_bytes, gpointer user_dat static void ppp_failed(NMModem *modem, guint i_reason, gpointer user_data) { - NMDevice * device = NM_DEVICE(user_data); - NMDeviceBt * self = NM_DEVICE_BT(user_data); + NMDevice *device = NM_DEVICE(user_data); NMDeviceStateReason reason = i_reason; - switch (nm_device_get_state(device)) { - case NM_DEVICE_STATE_PREPARE: - case NM_DEVICE_STATE_CONFIG: - case NM_DEVICE_STATE_NEED_AUTH: - nm_device_state_changed(device, NM_DEVICE_STATE_FAILED, reason); - break; - case NM_DEVICE_STATE_IP_CONFIG: - case NM_DEVICE_STATE_IP_CHECK: - case NM_DEVICE_STATE_SECONDARIES: - case NM_DEVICE_STATE_ACTIVATED: - if (nm_device_activate_ip4_state_in_conf(device)) - nm_device_activate_schedule_ip_config_timeout(device, AF_INET); - else if (nm_device_activate_ip6_state_in_conf(device)) - nm_device_activate_schedule_ip_config_timeout(device, AF_INET6); - else if (nm_device_activate_ip4_state_done(device)) { - nm_device_ip_method_failed(device, - AF_INET, - NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); - } else if (nm_device_activate_ip6_state_done(device)) { - nm_device_ip_method_failed(device, - AF_INET6, - NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); - } else { - _LOGW(LOGD_MB, - "PPP failure in unexpected state %u", - (guint) nm_device_get_state(device)); - nm_device_state_changed(device, - NM_DEVICE_STATE_FAILED, - NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); - } - break; - default: - break; - } + nm_device_state_changed(device, NM_DEVICE_STATE_FAILED, reason); } static void @@ -481,7 +446,7 @@ modem_auth_requested(NMModem *modem, gpointer user_data) static void modem_auth_result(NMModem *modem, GError *error, gpointer user_data) { - NMDevice * device = NM_DEVICE(user_data); + NMDevice *device = NM_DEVICE(user_data); NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE(device); g_return_if_fail(nm_device_get_state(device) == NM_DEVICE_STATE_NEED_AUTH); @@ -498,8 +463,8 @@ modem_auth_result(NMModem *modem, GError *error, gpointer user_data) static void modem_prepare_result(NMModem *modem, gboolean success, guint i_reason, gpointer user_data) { - NMDeviceBt * self = user_data; - NMDeviceBtPrivate * priv = NM_DEVICE_BT_GET_PRIVATE(self); + NMDeviceBt *self = user_data; + NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE(self); NMDeviceStateReason reason = i_reason; NMDeviceState state; @@ -528,7 +493,7 @@ modem_prepare_result(NMModem *modem, gboolean success, guint i_reason, gpointer } static void -device_state_changed(NMDevice * device, +device_state_changed(NMDevice *device, NMDeviceState new_state, NMDeviceState old_state, NMDeviceStateReason reason) @@ -547,22 +512,35 @@ device_state_changed(NMDevice * device, } static void -modem_ip4_config_result(NMModem *modem, NMIP4Config *config, GError *error, gpointer user_data) +modem_new_config(NMModem *modem, + int addr_family, + const NML3ConfigData *l3cd, + gboolean do_auto, + const NMUtilsIPv6IfaceId *iid, + int failure_reason_i, + GError *error, + gpointer user_data) { - NMDeviceBt *self = NM_DEVICE_BT(user_data); - NMDevice * device = NM_DEVICE(self); + const int IS_IPv4 = NM_IS_IPv4(addr_family); + NMDeviceBt *self = NM_DEVICE_BT(user_data); + NMDevice *device = NM_DEVICE(self); - g_return_if_fail(nm_device_activate_ip4_state_in_conf(device) == TRUE); + g_return_if_fail(nm_device_devip_get_state(device, addr_family) == NM_DEVICE_IP_STATE_PENDING); if (error) { - _LOGW(LOGD_MB | LOGD_IP4 | LOGD_BT, - "retrieving IP4 configuration failed: %s", - error->message); - nm_device_ip_method_failed(device, AF_INET, NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); + _LOGW(LOGD_MB | LOGD_IP4, "retrieving IP configuration failed: %s", error->message); + nm_device_devip_set_failed(device, addr_family, failure_reason_i); return; } - nm_device_activate_schedule_ip_config_result(device, AF_INET, NM_IP_CONFIG_CAST(config)); + if (do_auto) { + if (IS_IPv4) + nm_device_ip_method_dhcp4_start(device); + else + nm_device_ip_method_autoconf6_start(device); + } + + nm_device_devip_set_state(device, addr_family, NM_DEVICE_IP_STATE_READY, l3cd); } static void @@ -604,7 +582,7 @@ modem_state_cb(NMModem *modem, int new_state_i, int old_state_i, gpointer user_d { NMModemState new_state = new_state_i; NMModemState old_state = old_state_i; - NMDevice * device = NM_DEVICE(user_data); + NMDevice *device = NM_DEVICE(user_data); NMDeviceState dev_state = nm_device_get_state(device); if (new_state <= NM_MODEM_STATE_DISABLING && old_state > NM_MODEM_STATE_DISABLING) { @@ -633,7 +611,7 @@ modem_state_cb(NMModem *modem, int new_state_i, int old_state_i, gpointer user_d static void modem_removed_cb(NMModem *modem, gpointer user_data) { - NMDeviceBt * self = NM_DEVICE_BT(user_data); + NMDeviceBt *self = NM_DEVICE_BT(user_data); NMDeviceState state; state = nm_device_get_state(NM_DEVICE(self)); @@ -651,7 +629,7 @@ static gboolean modem_try_claim(NMDeviceBt *self, NMModem *modem) { NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE(self); - gs_free char * rfcomm_base_name = NULL; + gs_free char *rfcomm_base_name = NULL; NMDeviceState state; if (priv->modem) { @@ -687,7 +665,7 @@ modem_try_claim(NMDeviceBt *self, NMModem *modem) g_signal_connect(modem, NM_MODEM_PPP_STATS, G_CALLBACK(ppp_stats), self); g_signal_connect(modem, NM_MODEM_PPP_FAILED, G_CALLBACK(ppp_failed), self); g_signal_connect(modem, NM_MODEM_PREPARE_RESULT, G_CALLBACK(modem_prepare_result), self); - g_signal_connect(modem, NM_MODEM_IP4_CONFIG_RESULT, G_CALLBACK(modem_ip4_config_result), self); + g_signal_connect(modem, NM_MODEM_NEW_CONFIG, G_CALLBACK(modem_new_config), self); g_signal_connect(modem, NM_MODEM_AUTH_REQUESTED, G_CALLBACK(modem_auth_requested), self); g_signal_connect(modem, NM_MODEM_AUTH_RESULT, G_CALLBACK(modem_auth_result), self); g_signal_connect(modem, NM_MODEM_STATE_CHANGED, G_CALLBACK(modem_state_cb), self); @@ -705,7 +683,7 @@ modem_try_claim(NMDeviceBt *self, NMModem *modem) static void mm_modem_added_cb(NMModemManager *manager, NMModem *modem, gpointer user_data) { - NMDeviceBt * self = user_data; + NMDeviceBt *self = user_data; NMDeviceBtPrivate *priv; if (!modem_try_claim(user_data, modem)) @@ -745,7 +723,7 @@ _nm_device_bt_notify_set_connected(NMDeviceBt *self, gboolean connected) static gboolean connect_watch_link_idle_cb(gpointer user_data) { - NMDeviceBt * self = user_data; + NMDeviceBt *self = user_data; NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE(self); int ifindex; @@ -766,15 +744,15 @@ connect_watch_link_idle_cb(gpointer user_data) } static void -connect_watch_link_cb(NMPlatform * platform, +connect_watch_link_cb(NMPlatform *platform, int obj_type_i, int ifindex, NMPlatformLink *info, int change_type_i, - NMDevice * self) + NMDevice *self) { const NMPlatformSignalChangeType change_type = change_type_i; - NMDeviceBtPrivate * priv; + NMDeviceBtPrivate *priv; /* bluez doesn't notify us when the connection disconnects. * Neither does NMManager (or NMDevice) tell us when the ip-ifindex goes away. @@ -790,7 +768,7 @@ connect_watch_link_cb(NMPlatform * platform, static gboolean connect_wait_modem_timeout(gpointer user_data) { - NMDeviceBt * self = NM_DEVICE_BT(user_data); + NMDeviceBt *self = NM_DEVICE_BT(user_data); NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE(self); /* since this timeout is longer than the connect timeout, we must have already @@ -814,11 +792,11 @@ connect_wait_modem_timeout(gpointer user_data) static void connect_bz_cb(NMBluezManager *bz_mgr, gboolean is_complete, - const char * device_name, - GError * error, + const char *device_name, + GError *error, gpointer user_data) { - NMDeviceBt * self; + NMDeviceBt *self; NMDeviceBtPrivate *priv; char sbuf[100]; @@ -906,10 +884,10 @@ connect_bz_cb(NMBluezManager *bz_mgr, static NMActStageReturn act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) { - NMDeviceBt * self = NM_DEVICE_BT(device); - NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE(self); + NMDeviceBt *self = NM_DEVICE_BT(device); + NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE(self); gs_free_error GError *error = NULL; - NMConnection * connection; + NMConnection *connection; connection = nm_device_get_applied_connection(device); g_return_val_if_fail(connection, NM_ACT_STAGE_RETURN_FAILURE); @@ -989,38 +967,25 @@ act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) static NMActStageReturn act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) { - NMDeviceBt * self = NM_DEVICE_BT(device); + NMDeviceBt *self = NM_DEVICE_BT(device); NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE(self); - if (priv->connect_bt_type == NM_BT_CAPABILITY_DUN) - nm_modem_act_stage2_config(priv->modem); + if (priv->connect_bt_type != NM_BT_CAPABILITY_DUN) + return NM_ACT_STAGE_RETURN_SUCCESS; - return NM_ACT_STAGE_RETURN_SUCCESS; + return nm_modem_act_stage2_config(priv->modem, device, out_failure_reason); } -static NMActStageReturn -act_stage3_ip_config_start(NMDevice * device, - int addr_family, - gpointer * out_config, - NMDeviceStateReason *out_failure_reason) +static void +act_stage3_ip_config(NMDevice *device, int addr_family) { - NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE(device); - gboolean autoip4 = FALSE; - NMActStageReturn ret; + NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE(device); if (priv->connect_bt_type != NM_BT_CAPABILITY_DUN) - goto out_chain_up; - - if (!NM_IS_IPv4(addr_family)) - return nm_modem_stage3_ip6_config_start(priv->modem, device, out_failure_reason); - - ret = nm_modem_stage3_ip4_config_start(priv->modem, device, &autoip4, out_failure_reason); - if (ret != NM_ACT_STAGE_RETURN_SUCCESS || !autoip4) - return ret; + return; -out_chain_up: - return NM_DEVICE_CLASS(nm_device_bt_parent_class) - ->act_stage3_ip_config_start(device, addr_family, out_config, out_failure_reason); + if (nm_modem_stage3_ip_config_start(priv->modem, addr_family, device)) + nm_device_devip_set_state(device, addr_family, NM_DEVICE_IP_STATE_PENDING, NULL); } static void @@ -1070,10 +1035,10 @@ _nm_device_bt_notify_removed(NMDeviceBt *self) /*****************************************************************************/ gboolean -_nm_device_bt_for_same_device(NMDeviceBt * self, - const char * dbus_path, - const char * bdaddr, - const char * name, +_nm_device_bt_for_same_device(NMDeviceBt *self, + const char *dbus_path, + const char *bdaddr, + const char *name, NMBluetoothCapabilities capabilities) { NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE(self); @@ -1102,7 +1067,7 @@ _nm_device_bt_notify_set_name(NMDeviceBt *self, const char *name) static gboolean is_available(NMDevice *dev, NMDeviceCheckDevAvailableFlags flags) { - NMDeviceBt * self = NM_DEVICE_BT(dev); + NMDeviceBt *self = NM_DEVICE_BT(dev); NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE(self); /* PAN doesn't need ModemManager, so devices that support it are always available */ @@ -1206,7 +1171,7 @@ nm_device_bt_init(NMDeviceBt *self) static void constructed(GObject *object) { - NMDeviceBt * self = NM_DEVICE_BT(object); + NMDeviceBt *self = NM_DEVICE_BT(object); NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE(self); G_OBJECT_CLASS(nm_device_bt_parent_class)->constructed(object); @@ -1229,10 +1194,10 @@ constructed(GObject *object) } NMDeviceBt * -nm_device_bt_new(NMBluezManager * bz_mgr, - const char * dbus_path, - const char * bdaddr, - const char * name, +nm_device_bt_new(NMBluezManager *bz_mgr, + const char *dbus_path, + const char *bdaddr, + const char *name, NMBluetoothCapabilities capabilities) { g_return_val_if_fail(NM_IS_BLUEZ_MANAGER(bz_mgr), NULL); @@ -1270,7 +1235,7 @@ nm_device_bt_new(NMBluezManager * bz_mgr, static void dispose(GObject *object) { - NMDeviceBt * self = NM_DEVICE_BT(object); + NMDeviceBt *self = NM_DEVICE_BT(object); NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE(self); nm_clear_g_signal_handler(nm_device_get_platform(NM_DEVICE(self)), @@ -1325,9 +1290,9 @@ static const NMDBusInterfaceInfoExtended interface_info_device_bluetooth = { static void nm_device_bt_class_init(NMDeviceBtClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->constructed = constructed; object_class->get_property = get_property; @@ -1344,7 +1309,7 @@ nm_device_bt_class_init(NMDeviceBtClass *klass) device_class->deactivate = deactivate; device_class->act_stage1_prepare = act_stage1_prepare; device_class->act_stage2_config = act_stage2_config; - device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; + device_class->act_stage3_ip_config = act_stage3_ip_config; device_class->check_connection_compatible = check_connection_compatible; device_class->check_connection_available = check_connection_available; device_class->complete_connection = complete_connection; diff --git a/src/core/devices/bluetooth/nm-device-bt.h b/src/core/devices/bluetooth/nm-device-bt.h index c2d3bc18..59457fba 100644 --- a/src/core/devices/bluetooth/nm-device-bt.h +++ b/src/core/devices/bluetooth/nm-device-bt.h @@ -33,15 +33,15 @@ GType nm_device_bt_get_type(void); struct _NMBluezManager; NMDeviceBt *nm_device_bt_new(struct _NMBluezManager *bz_mgr, - const char * dbus_path, - const char * bdaddr, - const char * name, + const char *dbus_path, + const char *bdaddr, + const char *name, NMBluetoothCapabilities capabilities); -gboolean _nm_device_bt_for_same_device(NMDeviceBt * device, - const char * dbus_path, - const char * bdaddr, - const char * name, +gboolean _nm_device_bt_for_same_device(NMDeviceBt *device, + const char *dbus_path, + const char *bdaddr, + const char *name, NMBluetoothCapabilities capabilities); NMBluetoothCapabilities nm_device_bt_get_capabilities(NMDeviceBt *device); diff --git a/src/core/devices/bluetooth/tests/nm-bt-test.c b/src/core/devices/bluetooth/tests/nm-bt-test.c index 548e7249..5aab48a5 100644 --- a/src/core/devices/bluetooth/tests/nm-bt-test.c +++ b/src/core/devices/bluetooth/tests/nm-bt-test.c @@ -23,8 +23,8 @@ struct { int argc; const char *const *argv; - const char * argv_cmd; - GMainLoop * loop; + const char *argv_cmd; + GMainLoop *loop; } gl; typedef struct _MainCmdInfo { @@ -38,7 +38,7 @@ typedef struct _MainCmdInfo { typedef struct { NMBluez5DunContext *dun_context; - GCancellable * cancellable; + GCancellable *cancellable; guint timeout_id; guint sig_term_id; guint sig_int_id; @@ -46,8 +46,8 @@ typedef struct { static void _dun_connect_cb(NMBluez5DunContext *context, - const char * rfcomm_dev, - GError * error, + const char *rfcomm_dev, + GError *error, gpointer user_data) { DunConnectData *dun_connect_data = user_data; @@ -118,10 +118,10 @@ do_dun_connect(const MainCmdInfo *main_cmd_info) { #if WITH_BLUEZ5_DUN gs_unref_object GCancellable *cancellable = NULL; - gs_free_error GError *error = NULL; - const char * adapter; - const char * remote; - DunConnectData dun_connect_data = {}; + gs_free_error GError *error = NULL; + const char *adapter; + const char *remote; + DunConnectData dun_connect_data = {}; if (gl.argc < 4) { _LOGE("missing arguments \"adapter\" and \"remote\""); diff --git a/src/core/devices/nm-acd-manager.c b/src/core/devices/nm-acd-manager.c deleted file mode 100644 index c041163e..00000000 --- a/src/core/devices/nm-acd-manager.c +++ /dev/null @@ -1,497 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2015 - 2018 Red Hat, Inc. - */ - -#include "src/core/nm-default-daemon.h" - -#include "nm-acd-manager.h" - -#include -#include -#include -#include - -#include "libnm-platform/nm-platform.h" -#include "nm-utils.h" -#include "NetworkManagerUtils.h" -#include "n-acd/src/n-acd.h" - -/*****************************************************************************/ - -typedef enum { - STATE_INIT, - STATE_PROBING, - STATE_PROBE_DONE, - STATE_ANNOUNCING, -} State; - -typedef struct { - in_addr_t address; - gboolean duplicate; - NAcdProbe *probe; -} AddressInfo; - -struct _NMAcdManager { - int ifindex; - guint8 hwaddr[ETH_ALEN]; - State state; - GHashTable *addresses; - guint completed; - NAcd * acd; - GSource * event_source; - - NMAcdCallbacks callbacks; - gpointer user_data; -}; - -/*****************************************************************************/ - -#define _NMLOG_DOMAIN LOGD_IP4 -#define _NMLOG_PREFIX_NAME "acd" -#define _NMLOG(level, ...) \ - G_STMT_START \ - { \ - char _sbuf[64]; \ - \ - nm_log((level), \ - _NMLOG_DOMAIN, \ - self && self->ifindex > 0 \ - ? nm_platform_link_get_name(NM_PLATFORM_GET, self->ifindex) \ - : NULL, \ - NULL, \ - "%s%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ - _NMLOG_PREFIX_NAME, \ - self ? nm_sprintf_buf(_sbuf, "[%p,%d]", self, self->ifindex) \ - : "" _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ - } \ - G_STMT_END - -/*****************************************************************************/ - -static const char * -_acd_event_to_string(unsigned int event) -{ - switch (event) { - case N_ACD_EVENT_READY: - return "ready"; - case N_ACD_EVENT_USED: - return "used"; - case N_ACD_EVENT_DEFENDED: - return "defended"; - case N_ACD_EVENT_CONFLICT: - return "conflict"; - case N_ACD_EVENT_DOWN: - return "down"; - } - return NULL; -} - -#define ACD_EVENT_TO_STRING_BUF_SIZE 50 - -static const char * -_acd_event_to_string_buf(unsigned event, char buffer[static ACD_EVENT_TO_STRING_BUF_SIZE]) -{ - const char *s; - - s = _acd_event_to_string(event); - if (s) - return s; - - g_snprintf(buffer, ACD_EVENT_TO_STRING_BUF_SIZE, "(%u)", event); - return buffer; -} - -static const char * -acd_error_to_string(int error) -{ - if (error < 0) - return nm_strerror_native(-error); - - switch (error) { - case _N_ACD_E_SUCCESS: - return "success"; - case N_ACD_E_PREEMPTED: - return "preempted"; - case N_ACD_E_INVALID_ARGUMENT: - return "invalid argument"; - } - - g_return_val_if_reached(NULL); -} - -static int -acd_error_to_nmerr(int error, gboolean always_fail) -{ - if (error < 0) - return -nm_errno_native(error); - - if (always_fail) { - if (NM_IN_SET(error, N_ACD_E_PREEMPTED, N_ACD_E_INVALID_ARGUMENT)) - return -NME_UNSPEC; - g_return_val_if_reached(-NME_UNSPEC); - } - - /* so, @error is either zero (indicating success) or one - * of the special status codes like N_ACD_E_*. In both cases, - * return the positive value here. */ - if (NM_IN_SET(error, _N_ACD_E_SUCCESS, N_ACD_E_PREEMPTED, N_ACD_E_INVALID_ARGUMENT)) - return error; - - g_return_val_if_reached(error); -} - -/*****************************************************************************/ - -/** - * nm_acd_manager_add_address: - * @self: a #NMAcdManager - * @address: an IP address - * - * Add @address to the list of IP addresses to probe. - - * Returns: %TRUE on success, %FALSE if the address was already in the list - */ -gboolean -nm_acd_manager_add_address(NMAcdManager *self, in_addr_t address) -{ - AddressInfo *info; - - g_return_val_if_fail(self, FALSE); - g_return_val_if_fail(self->state == STATE_INIT, FALSE); - - if (g_hash_table_lookup(self->addresses, GUINT_TO_POINTER(address))) - return FALSE; - - info = g_slice_new0(AddressInfo); - info->address = address; - - g_hash_table_insert(self->addresses, GUINT_TO_POINTER(address), info); - - return TRUE; -} - -static gboolean -acd_event(int fd, GIOCondition condition, gpointer data) -{ - NMAcdManager *self = data; - NAcdEvent * event; - AddressInfo * info; - gboolean emit_probe_terminated = FALSE; - char address_str[INET_ADDRSTRLEN]; - int r; - - if (n_acd_dispatch(self->acd)) - return G_SOURCE_CONTINUE; - - while (!n_acd_pop_event(self->acd, &event) && event) { - char to_string_buffer[ACD_EVENT_TO_STRING_BUF_SIZE]; - gs_free char *hwaddr_str = NULL; - gboolean check_probing_done = FALSE; - char buf[ETH_ALEN * 3]; - - switch (event->event) { - case N_ACD_EVENT_READY: - n_acd_probe_get_userdata(event->ready.probe, (void **) &info); - info->duplicate = FALSE; - if (self->state == STATE_ANNOUNCING) { - /* fake probe ended, start announcing */ - r = n_acd_probe_announce(info->probe, N_ACD_DEFEND_ONCE); - if (r) { - _LOGW("couldn't announce address %s on interface '%s': %s", - _nm_utils_inet4_ntop(info->address, address_str), - nm_platform_link_get_name(NM_PLATFORM_GET, self->ifindex), - acd_error_to_string(r)); - } else { - _LOGD("announcing address %s (hw-addr %s)", - _nm_utils_inet4_ntop(info->address, address_str), - _nm_utils_hwaddr_ntoa(self->hwaddr, ETH_ALEN, TRUE, buf, sizeof(buf))); - } - } - check_probing_done = TRUE; - break; - case N_ACD_EVENT_USED: - n_acd_probe_get_userdata(event->used.probe, (void **) &info); - info->duplicate = TRUE; - check_probing_done = TRUE; - break; - case N_ACD_EVENT_DEFENDED: - n_acd_probe_get_userdata(event->defended.probe, (void **) &info); - _LOGD("defended address %s from host %s", - _nm_utils_inet4_ntop(info->address, address_str), - (hwaddr_str = - nm_utils_hwaddr_ntoa(event->defended.sender, event->defended.n_sender))); - break; - case N_ACD_EVENT_CONFLICT: - n_acd_probe_get_userdata(event->conflict.probe, (void **) &info); - _LOGW("conflict for address %s detected with host %s on interface '%s'", - _nm_utils_inet4_ntop(info->address, address_str), - (hwaddr_str = - nm_utils_hwaddr_ntoa(event->defended.sender, event->defended.n_sender)), - nm_platform_link_get_name(NM_PLATFORM_GET, self->ifindex)); - break; - default: - _LOGD("unhandled event '%s'", _acd_event_to_string_buf(event->event, to_string_buffer)); - break; - } - - if (check_probing_done && self->state == STATE_PROBING - && ++self->completed == g_hash_table_size(self->addresses)) { - self->state = STATE_PROBE_DONE; - emit_probe_terminated = TRUE; - } - } - - if (emit_probe_terminated) { - if (self->callbacks.probe_terminated_callback) { - self->callbacks.probe_terminated_callback(self, self->user_data); - } - } - - return G_SOURCE_CONTINUE; -} - -static gboolean -acd_probe_add(NMAcdManager *self, AddressInfo *info, guint64 timeout) -{ - NAcdProbeConfig *probe_config; - int r; - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; - - r = n_acd_probe_config_new(&probe_config); - if (r) { - _LOGW("could not create probe config for %s on interface '%s': %s", - _nm_utils_inet4_ntop(info->address, sbuf), - nm_platform_link_get_name(NM_PLATFORM_GET, self->ifindex), - acd_error_to_string(r)); - return FALSE; - } - - n_acd_probe_config_set_ip(probe_config, (struct in_addr){info->address}); - n_acd_probe_config_set_timeout(probe_config, timeout); - - r = n_acd_probe(self->acd, &info->probe, probe_config); - if (r) { - _LOGW("could not start probe for %s on interface '%s': %s", - _nm_utils_inet4_ntop(info->address, sbuf), - nm_platform_link_get_name(NM_PLATFORM_GET, self->ifindex), - acd_error_to_string(r)); - n_acd_probe_config_free(probe_config); - return FALSE; - } - - n_acd_probe_set_userdata(info->probe, info); - n_acd_probe_config_free(probe_config); - - return TRUE; -} - -static int -acd_init(NMAcdManager *self) -{ - NAcdConfig *config; - int r; - - if (self->acd) - return 0; - - r = n_acd_config_new(&config); - if (r) - return r; - - n_acd_config_set_ifindex(config, self->ifindex); - n_acd_config_set_transport(config, N_ACD_TRANSPORT_ETHERNET); - n_acd_config_set_mac(config, self->hwaddr, ETH_ALEN); - - r = n_acd_new(&self->acd, config); - n_acd_config_free(config); - return r; -} - -/** - * nm_acd_manager_start_probe: - * @self: a #NMAcdManager - * @timeout: maximum probe duration in milliseconds - * @error: location to store error, or %NULL - * - * Start probing IP addresses for duplicates; when the probe terminates a - * PROBE_TERMINATED signal is emitted. - * - * Returns: 0 on success or a negative NetworkManager error code (NME_*). - */ -int -nm_acd_manager_start_probe(NMAcdManager *self, guint timeout) -{ - GHashTableIter iter; - AddressInfo * info; - gboolean success = FALSE; - int fd, r; - - g_return_val_if_fail(self, FALSE); - g_return_val_if_fail(self->state == STATE_INIT, FALSE); - - r = acd_init(self); - if (r) { - _LOGW("couldn't init ACD for probing on interface '%s': %s", - nm_platform_link_get_name(NM_PLATFORM_GET, self->ifindex), - acd_error_to_string(r)); - return acd_error_to_nmerr(r, TRUE); - } - - self->completed = 0; - - g_hash_table_iter_init(&iter, self->addresses); - while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &info)) - success |= acd_probe_add(self, info, timeout); - - if (success) - self->state = STATE_PROBING; - - nm_assert(!self->event_source); - n_acd_get_fd(self->acd, &fd); - self->event_source = nm_g_unix_fd_add_source(fd, G_IO_IN, acd_event, self); - - return success ? 0 : -NME_UNSPEC; -} - -/** - * nm_acd_manager_check_address: - * @self: a #NMAcdManager - * @address: an IP address - * - * Check if an IP address is duplicate. @address must have been added with - * nm_acd_manager_add_address(). - * - * Returns: %TRUE if the address is not duplicate, %FALSE otherwise - */ -gboolean -nm_acd_manager_check_address(NMAcdManager *self, in_addr_t address) -{ - AddressInfo *info; - - g_return_val_if_fail(self, FALSE); - g_return_val_if_fail(NM_IN_SET(self->state, STATE_INIT, STATE_PROBE_DONE), FALSE); - - info = g_hash_table_lookup(self->addresses, GUINT_TO_POINTER(address)); - g_return_val_if_fail(info, FALSE); - - return !info->duplicate; -} - -/** - * nm_acd_manager_announce_addresses: - * @self: a #NMAcdManager - * - * Start announcing addresses. - * - * Returns: a negative NetworkManager error number or zero on success. - */ -int -nm_acd_manager_announce_addresses(NMAcdManager *self) -{ - GHashTableIter iter; - AddressInfo * info; - int r; - int fd; - gboolean success = TRUE; - char buf[ETH_ALEN * 3]; - - r = acd_init(self); - if (r) { - _LOGW("couldn't init ACD for announcing addresses on interface '%s': %s", - nm_platform_link_get_name(NM_PLATFORM_GET, self->ifindex), - acd_error_to_string(r)); - return acd_error_to_nmerr(r, TRUE); - } - - if (self->state == STATE_INIT) { - /* n-acd can't announce without probing, therefore let's - * start a fake probe with zero timeout and then perform - * the announcement. */ - g_hash_table_iter_init(&iter, self->addresses); - while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &info)) { - if (!acd_probe_add(self, info, 0)) - success = FALSE; - } - self->state = STATE_ANNOUNCING; - } else if (self->state == STATE_ANNOUNCING) { - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; - - g_hash_table_iter_init(&iter, self->addresses); - while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &info)) { - if (info->duplicate) - continue; - r = n_acd_probe_announce(info->probe, N_ACD_DEFEND_ONCE); - if (r) { - _LOGW("couldn't announce address %s on interface '%s': %s", - _nm_utils_inet4_ntop(info->address, sbuf), - nm_platform_link_get_name(NM_PLATFORM_GET, self->ifindex), - acd_error_to_string(r)); - success = FALSE; - } else - _LOGD("announcing address %s (hw-addr %s)", - _nm_utils_inet4_ntop(info->address, sbuf), - _nm_utils_hwaddr_ntoa(self->hwaddr, ETH_ALEN, TRUE, buf, sizeof(buf))); - } - } - - if (!self->event_source) { - n_acd_get_fd(self->acd, &fd); - self->event_source = nm_g_unix_fd_add_source(fd, G_IO_IN, acd_event, self); - } - - return success ? 0 : -NME_UNSPEC; -} - -static void -destroy_address_info(gpointer data) -{ - AddressInfo *info = (AddressInfo *) data; - - n_acd_probe_free(info->probe); - - g_slice_free(AddressInfo, info); -} - -/*****************************************************************************/ - -NMAcdManager * -nm_acd_manager_new(int ifindex, - const guint8 * hwaddr, - guint hwaddr_len, - const NMAcdCallbacks *callbacks, - gpointer user_data) -{ - NMAcdManager *self; - - g_return_val_if_fail(ifindex > 0, NULL); - g_return_val_if_fail(hwaddr, NULL); - g_return_val_if_fail(hwaddr_len == ETH_ALEN, NULL); - - self = g_slice_new0(NMAcdManager); - - if (callbacks) - self->callbacks = *callbacks; - self->user_data = user_data; - - self->addresses = g_hash_table_new_full(nm_direct_hash, NULL, NULL, destroy_address_info); - self->state = STATE_INIT; - self->ifindex = ifindex; - memcpy(self->hwaddr, hwaddr, ETH_ALEN); - return self; -} - -void -nm_acd_manager_free(NMAcdManager *self) -{ - g_return_if_fail(self); - - if (self->callbacks.user_data_destroy) - self->callbacks.user_data_destroy(self->user_data); - - nm_clear_pointer(&self->addresses, g_hash_table_destroy); - nm_clear_g_source_inst(&self->event_source); - nm_clear_pointer(&self->acd, n_acd_unref); - - g_slice_free(NMAcdManager, self); -} diff --git a/src/core/devices/nm-acd-manager.h b/src/core/devices/nm-acd-manager.h deleted file mode 100644 index e8ef6f2b..00000000 --- a/src/core/devices/nm-acd-manager.h +++ /dev/null @@ -1,34 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2015 - 2018 Red Hat, Inc. - */ - -#ifndef __NM_ACD_MANAGER__ -#define __NM_ACD_MANAGER__ - -#include - -typedef struct _NMAcdManager NMAcdManager; - -typedef struct { - void (*probe_terminated_callback)(NMAcdManager *self, gpointer user_data); - GDestroyNotify user_data_destroy; -} NMAcdCallbacks; - -NMAcdManager *nm_acd_manager_new(int ifindex, - const guint8 * hwaddr, - guint hwaddr_len, - const NMAcdCallbacks *callbacks, - gpointer user_data); - -void nm_acd_manager_free(NMAcdManager *self); - -gboolean nm_acd_manager_add_address(NMAcdManager *self, in_addr_t address); -int nm_acd_manager_start_probe(NMAcdManager *self, guint timeout); -gboolean nm_acd_manager_check_address(NMAcdManager *self, in_addr_t address); -int nm_acd_manager_announce_addresses(NMAcdManager *self); - -NM_AUTO_DEFINE_FCN0(NMAcdManager *, _nm_auto_free_acdmgr, nm_acd_manager_free); -#define nm_auto_free_acdmgr nm_auto(_nm_auto_free_acdmgr) - -#endif /* __NM_ACD_MANAGER__ */ diff --git a/src/core/devices/nm-device-6lowpan.c b/src/core/devices/nm-device-6lowpan.c index 8b77c22c..d6543356 100644 --- a/src/core/devices/nm-device-6lowpan.c +++ b/src/core/devices/nm-device-6lowpan.c @@ -41,7 +41,7 @@ G_DEFINE_TYPE(NMDevice6Lowpan, nm_device_6lowpan, NM_TYPE_DEVICE) /*****************************************************************************/ static void -parent_state_changed(NMDevice * parent, +parent_state_changed(NMDevice *parent, NMDeviceState new_state, NMDeviceState old_state, NMDeviceStateReason reason, @@ -62,7 +62,7 @@ parent_changed_notify(NMDevice *device, int new_ifindex, NMDevice *new_parent) { - NMDevice6Lowpan * self = NM_DEVICE_6LOWPAN(device); + NMDevice6Lowpan *self = NM_DEVICE_6LOWPAN(device); NMDevice6LowpanPrivate *priv = NM_DEVICE_6LOWPAN_GET_PRIVATE(self); NM_DEVICE_CLASS(nm_device_6lowpan_parent_class) @@ -95,13 +95,13 @@ parent_changed_notify(NMDevice *device, } static gboolean -create_and_realize(NMDevice * device, - NMConnection * connection, - NMDevice * parent, +create_and_realize(NMDevice *device, + NMConnection *connection, + NMDevice *parent, const NMPlatformLink **out_plink, - GError ** error) + GError **error) { - const char * iface = nm_device_get_iface(device); + const char *iface = nm_device_get_iface(device); NMSetting6Lowpan *s_6lowpan; int parent_ifindex; int r; @@ -175,11 +175,11 @@ is_available(NMDevice *device, NMDeviceCheckDevAvailableFlags flags) } static gboolean -complete_connection(NMDevice * device, - NMConnection * connection, - const char * specific_object, +complete_connection(NMDevice *device, + NMConnection *connection, + const char *specific_object, NMConnection *const *existing_connections, - GError ** error) + GError **error) { NMSetting6Lowpan *s_6lowpan; @@ -249,7 +249,7 @@ static void nm_device_6lowpan_class_init(NMDevice6LowpanClass *klass) { NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS(&interface_info_device_6lowpan); @@ -275,11 +275,11 @@ nm_device_6lowpan_class_init(NMDevice6LowpanClass *klass) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_6LOWPAN_DEVICE_FACTORY, NM6LowpanDeviceFactory)) static NMDevice * -create_device(NMDeviceFactory * factory, - const char * iface, +create_device(NMDeviceFactory *factory, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore) + NMConnection *connection, + gboolean *out_ignore) { return g_object_new(NM_TYPE_DEVICE_6LOWPAN, NM_DEVICE_IFACE, @@ -310,7 +310,7 @@ static char * get_connection_iface(NMDeviceFactory *factory, NMConnection *connection, const char *parent_iface) { NMSetting6Lowpan *s_6lowpan; - const char * ifname; + const char *ifname; g_return_val_if_fail(nm_connection_is_type(connection, NM_SETTING_6LOWPAN_SETTING_NAME), NULL); diff --git a/src/core/devices/nm-device-bond.c b/src/core/devices/nm-device-bond.c index f7d78f57..56b729e9 100644 --- a/src/core/devices/nm-device-bond.c +++ b/src/core/devices/nm-device-bond.c @@ -16,7 +16,6 @@ #include "nm-device-factory.h" #include "libnm-core-aux-intern/nm-libnm-core-utils.h" #include "libnm-core-intern/nm-core-internal.h" -#include "nm-ip4-config.h" #include "nm-setting-bond-port.h" #define _NMLOG_DEVICE_TYPE NMDeviceBond @@ -75,11 +74,11 @@ get_generic_capabilities(NMDevice *dev) } static gboolean -complete_connection(NMDevice * device, - NMConnection * connection, - const char * specific_object, +complete_connection(NMDevice *device, + NMConnection *connection, + const char *specific_object, NMConnection *const *existing_connections, - GError ** error) + GError **error) { nm_utils_complete_generic(nm_device_get_platform(device), connection, @@ -163,18 +162,18 @@ ignore_option(NMSettingBond *s_bond, const char *option, const char *value) static void update_connection(NMDevice *device, NMConnection *connection) { - NMDeviceBond * self = NM_DEVICE_BOND(device); + NMDeviceBond *self = NM_DEVICE_BOND(device); NMSettingBond *s_bond = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_BOND); int ifindex = nm_device_get_ifindex(device); NMBondMode mode = NM_BOND_MODE_UNKNOWN; - const char ** options; + const char **options; /* Read bond options from sysfs and update the Bond setting to match */ options = nm_setting_bond_get_valid_options(NULL); for (; options[0]; options++) { - const char * option = options[0]; + const char *option = options[0]; gs_free char *value = NULL; - char * p; + char *p; if (NM_IN_STRSET(option, NM_SETTING_BOND_OPTION_ACTIVE_SLAVE)) continue; @@ -216,15 +215,15 @@ update_connection(NMDevice *device, NMConnection *connection) } static gboolean -controller_update_port_connection(NMDevice * self, - NMDevice * port, +controller_update_port_connection(NMDevice *self, + NMDevice *port, NMConnection *connection, - GError ** error) + GError **error) { NMSettingBondPort *s_port; int ifindex_port = nm_device_get_ifindex(port); uint queue_id = NM_BOND_PORT_QUEUE_ID_DEF; - gs_free char * queue_id_str = NULL; + gs_free char *queue_id_str = NULL; g_return_val_if_fail(ifindex_port > 0, FALSE); @@ -252,8 +251,8 @@ static void set_arp_targets(NMDevice *device, const char *cur_arp_ip_target, const char *new_arp_ip_target) { gs_unref_ptrarray GPtrArray *free_list = NULL; - gs_free const char ** cur_strv = NULL; - gs_free const char ** new_strv = NULL; + gs_free const char **cur_strv = NULL; + gs_free const char **new_strv = NULL; gsize cur_len; gsize new_len; gsize i; @@ -311,7 +310,7 @@ static void set_bond_attr_or_default(NMDevice *device, NMSettingBond *s_bond, const char *opt) { NMDeviceBond *self = NM_DEVICE_BOND(device); - const char * value; + const char *value; value = nm_setting_bond_get_option_or_default(s_bond, opt); if (!value) { @@ -353,11 +352,11 @@ set_bond_arp_ip_targets(NMDevice *device, NMSettingBond *s_bond) static gboolean apply_bonding_config(NMDeviceBond *self) { - NMDevice * device = NM_DEVICE(self); + NMDevice *device = NM_DEVICE(self); NMSettingBond *s_bond; NMBondMode mode; - const char * mode_str; - gs_free char * device_bond_mode = NULL; + const char *mode_str; + gs_free char *device_bond_mode = NULL; s_bond = nm_device_get_applied_setting(device, NM_TYPE_SETTING_BOND); g_return_val_if_fail(s_bond, FALSE); @@ -387,7 +386,7 @@ apply_bonding_config(NMDeviceBond *self) static NMActStageReturn act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) { - NMDeviceBond * self = NM_DEVICE_BOND(device); + NMDeviceBond *self = NM_DEVICE_BOND(device); NMActStageReturn ret = NM_ACT_STAGE_RETURN_SUCCESS; /* Interface must be down to set bond options */ @@ -428,7 +427,7 @@ commit_port_options(NMDevice *bond_device, NMDevice *port, NMSettingBondPort *s_ static gboolean enslave_slave(NMDevice *device, NMDevice *port, NMConnection *connection, gboolean configure) { - NMDeviceBond * self = NM_DEVICE_BOND(device); + NMDeviceBond *self = NM_DEVICE_BOND(device); NMSettingBondPort *s_port; nm_device_master_check_slave_physical_port(device, port, LOGD_BOND); @@ -479,9 +478,9 @@ release_slave(NMDevice *device, NMDevice *slave, gboolean configure) _LOGD(LOGD_BOND, "bond slave %s is already released", nm_device_get_ip_iface(slave)); if (configure) { - NMConnection * applied; + NMConnection *applied; NMSettingWired *s_wired; - const char * cloned_mac; + const char *cloned_mac; address = g_strdup(nm_device_get_hw_address(device)); @@ -524,11 +523,11 @@ release_slave(NMDevice *device, NMDevice *slave, gboolean configure) } static gboolean -create_and_realize(NMDevice * device, - NMConnection * connection, - NMDevice * parent, +create_and_realize(NMDevice *device, + NMConnection *connection, + NMDevice *parent, const NMPlatformLink **out_plink, - GError ** error) + GError **error) { const char *iface = nm_device_get_iface(device); int r; @@ -550,12 +549,12 @@ create_and_realize(NMDevice * device, } static gboolean -can_reapply_change(NMDevice * device, +can_reapply_change(NMDevice *device, const char *setting_name, - NMSetting * s_old, - NMSetting * s_new, + NMSetting *s_old, + NMSetting *s_new, GHashTable *diffs, - GError ** error) + GError **error) { NMDeviceClass *device_class; @@ -563,7 +562,7 @@ can_reapply_change(NMDevice * device, if (nm_streq(setting_name, NM_SETTING_BOND_SETTING_NAME)) { NMSettingBond *s_a = NM_SETTING_BOND(s_old); NMSettingBond *s_b = NM_SETTING_BOND(s_new); - const char ** option_list; + const char **option_list; if (!nm_device_hash_check_invalid_keys(diffs, NM_SETTING_BOND_SETTING_NAME, @@ -602,9 +601,9 @@ can_reapply_change(NMDevice * device, static void reapply_connection(NMDevice *device, NMConnection *con_old, NMConnection *con_new) { - NMDeviceBond * self = NM_DEVICE_BOND(device); + NMDeviceBond *self = NM_DEVICE_BOND(device); NMSettingBond *s_bond; - const char * value; + const char *value; NMBondMode mode; NM_DEVICE_CLASS(nm_device_bond_parent_class)->reapply_connection(device, con_old, con_new); @@ -646,7 +645,7 @@ static void nm_device_bond_class_init(NMDeviceBondClass *klass) { NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS(&interface_info_device_bond); @@ -677,11 +676,11 @@ nm_device_bond_class_init(NMDeviceBondClass *klass) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_BOND_DEVICE_FACTORY, NMBondDeviceFactory)) static NMDevice * -create_device(NMDeviceFactory * factory, - const char * iface, +create_device(NMDeviceFactory *factory, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore) + NMConnection *connection, + gboolean *out_ignore) { return g_object_new(NM_TYPE_DEVICE_BOND, NM_DEVICE_IFACE, diff --git a/src/core/devices/nm-device-bridge.c b/src/core/devices/nm-device-bridge.c index 36a73978..4e4c2637 100644 --- a/src/core/devices/nm-device-bridge.c +++ b/src/core/devices/nm-device-bridge.c @@ -48,13 +48,13 @@ get_generic_capabilities(NMDevice *dev) } static gboolean -check_connection_available(NMDevice * device, - NMConnection * connection, +check_connection_available(NMDevice *device, + NMConnection *connection, NMDeviceCheckConAvailableFlags flags, - const char * specific_object, - GError ** error) + const char *specific_object, + GError **error) { - NMDeviceBridge * self = NM_DEVICE_BRIDGE(device); + NMDeviceBridge *self = NM_DEVICE_BRIDGE(device); NMSettingBluetooth *s_bt; if (!NM_DEVICE_CLASS(nm_device_bridge_parent_class) @@ -97,7 +97,7 @@ static gboolean check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error) { NMSettingBridge *s_bridge; - const char * mac_address; + const char *mac_address; if (!NM_DEVICE_CLASS(nm_device_bridge_parent_class) ->check_connection_compatible(device, connection, error)) @@ -140,11 +140,11 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError * } static gboolean -complete_connection(NMDevice * device, - NMConnection * connection, - const char * specific_object, +complete_connection(NMDevice *device, + NMConnection *connection, + const char *specific_object, NMConnection *const *existing_connections, - GError ** error) + GError **error) { nm_utils_complete_generic(nm_device_get_platform(device), connection, @@ -290,8 +290,8 @@ typedef struct { #define OPTION(_name, _sysname, ...) \ { \ - .name = ""_name \ - "", \ + .name = ""_name \ + "", \ .sysname = ""_sysname \ "", \ __VA_ARGS__ \ @@ -339,7 +339,6 @@ static const Option master_options[] = { OPTION_TYPE_INT(NM_BRIDGE_AGEING_TIME_MIN, NM_BRIDGE_AGEING_TIME_MAX, NM_BRIDGE_AGEING_TIME_DEF), - .default_if_zero = TRUE, .user_hz_compensate = TRUE, ), OPTION(NM_SETTING_BRIDGE_GROUP_FORWARD_MASK, "group_fwd_mask", OPTION_TYPE_INT(0, 0xFFFF, 0), ), OPTION(NM_SETTING_BRIDGE_MULTICAST_HASH_MAX, @@ -433,8 +432,8 @@ commit_option(NMDevice *device, NMSetting *setting, const Option *option, gboole { int ifindex = nm_device_get_ifindex(device); nm_auto_unset_gvalue GValue val = G_VALUE_INIT; - GParamSpec * pspec; - const char * value; + GParamSpec *pspec; + const char *value; char value_buf[100]; if (slave) @@ -522,7 +521,7 @@ static const NMPlatformBridgeVlan ** setting_vlans_to_platform(GPtrArray *array) { NMPlatformBridgeVlan **arr; - NMPlatformBridgeVlan * p_data; + NMPlatformBridgeVlan *p_data; guint i; if (!array || !array->len) @@ -554,8 +553,8 @@ setting_vlans_to_platform(GPtrArray *array) static void commit_slave_options(NMDevice *device, NMSettingBridgePort *setting) { - const Option * option; - NMSetting * s; + const Option *option; + NMSetting *s; gs_unref_object NMSetting *s_clear = NULL; if (setting) @@ -570,11 +569,11 @@ commit_slave_options(NMDevice *device, NMSettingBridgePort *setting) static void update_connection(NMDevice *device, NMConnection *connection) { - NMDeviceBridge * self = NM_DEVICE_BRIDGE(device); + NMDeviceBridge *self = NM_DEVICE_BRIDGE(device); NMSettingBridge *s_bridge = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_BRIDGE); int ifindex = nm_device_get_ifindex(device); - const Option * option; - gs_free char * stp = NULL; + const Option *option; + gs_free char *stp = NULL; int stp_value; option = master_options; @@ -590,8 +589,8 @@ update_connection(NMDevice *device, NMConnection *connection) for (; option->name; option++) { nm_auto_unset_gvalue GValue value = G_VALUE_INIT; - gs_free char * str = NULL; - GParamSpec * pspec; + gs_free char *str = NULL; + GParamSpec *pspec; str = nm_platform_sysctl_master_get_option(nm_device_get_platform(device), ifindex, @@ -665,17 +664,17 @@ out: } static gboolean -master_update_slave_connection(NMDevice * device, - NMDevice * slave, +master_update_slave_connection(NMDevice *device, + NMDevice *slave, NMConnection *connection, - GError ** error) + GError **error) { - NMDeviceBridge * self = NM_DEVICE_BRIDGE(device); + NMDeviceBridge *self = NM_DEVICE_BRIDGE(device); NMSettingConnection *s_con; NMSettingBridgePort *s_port; int ifindex_slave = nm_device_get_ifindex(slave); - const char * iface = nm_device_get_iface(device); - const Option * option; + const char *iface = nm_device_get_iface(device); + const Option *option; g_return_val_if_fail(ifindex_slave > 0, FALSE); @@ -721,14 +720,14 @@ master_update_slave_connection(NMDevice * device, static gboolean bridge_set_vlan_options(NMDevice *device, NMSettingBridge *s_bridge) { - NMDeviceBridge * self = NM_DEVICE_BRIDGE(device); - gconstpointer hwaddr; - size_t length; - gboolean enabled; - guint16 pvid; - NMPlatform * plat; - int ifindex; - gs_unref_ptrarray GPtrArray *vlans = NULL; + NMDeviceBridge *self = NM_DEVICE_BRIDGE(device); + gconstpointer hwaddr; + size_t length; + gboolean enabled; + guint16 pvid; + NMPlatform *plat; + int ifindex; + gs_unref_ptrarray GPtrArray *vlans = NULL; gs_free const NMPlatformBridgeVlan **plat_vlans = NULL; if (self->vlan_configured) @@ -796,7 +795,7 @@ static NMActStageReturn act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) { NMConnection *connection; - NMSetting * s_bridge; + NMSetting *s_bridge; const Option *option; connection = nm_device_get_applied_connection(device); @@ -860,9 +859,9 @@ _nm_device_bridge_notify_unregister_bt_nap(NMDevice *device, const char *reason) static NMActStageReturn act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) { - NMDeviceBridge * self = NM_DEVICE_BRIDGE(device); - NMConnection * connection; - NMSettingBluetooth *s_bt; + NMDeviceBridge *self = NM_DEVICE_BRIDGE(device); + NMConnection *connection; + NMSettingBluetooth *s_bt; gs_free_error GError *error = NULL; connection = nm_device_get_applied_connection(device); @@ -922,9 +921,9 @@ deactivate(NMDevice *device) static gboolean enslave_slave(NMDevice *device, NMDevice *slave, NMConnection *connection, gboolean configure) { - NMDeviceBridge * self = NM_DEVICE_BRIDGE(device); - NMConnection * master_connection; - NMSettingBridge * s_bridge; + NMDeviceBridge *self = NM_DEVICE_BRIDGE(device); + NMConnection *master_connection; + NMSettingBridge *s_bridge; NMSettingBridgePort *s_port; if (configure) { @@ -943,7 +942,7 @@ enslave_slave(NMDevice *device, NMDevice *slave, NMConnection *connection, gbool if (nm_setting_bridge_get_vlan_filtering(s_bridge)) { gs_free const NMPlatformBridgeVlan **plat_vlans = NULL; - gs_unref_ptrarray GPtrArray *vlans = NULL; + gs_unref_ptrarray GPtrArray *vlans = NULL; if (s_port) g_object_get(s_port, NM_SETTING_BRIDGE_PORT_VLANS, &vlans, NULL); @@ -1008,17 +1007,17 @@ release_slave(NMDevice *device, NMDevice *slave, gboolean configure) } static gboolean -create_and_realize(NMDevice * device, - NMConnection * connection, - NMDevice * parent, +create_and_realize(NMDevice *device, + NMConnection *connection, + NMDevice *parent, const NMPlatformLink **out_plink, - GError ** error) + GError **error) { - NMSettingWired * s_wired; - NMSettingBridge * s_bridge; - const char * iface = nm_device_get_iface(device); - const char * hwaddr; - gs_free char * hwaddr_cloned = NULL; + NMSettingWired *s_wired; + NMSettingBridge *s_bridge; + const char *iface = nm_device_get_iface(device); + const char *hwaddr; + gs_free char *hwaddr_cloned = NULL; guint8 mac_address[_NM_UTILS_HWADDR_LEN_MAX]; NMPlatformLnkBridge props; int r; @@ -1062,8 +1061,7 @@ create_and_realize(NMDevice * device, NM_BRIDGE_HELLO_TIME_DEF_SYS), .max_age = _DEFAULT_IF_ZERO(nm_setting_bridge_get_max_age(s_bridge) * 100u, NM_BRIDGE_MAX_AGE_DEF_SYS), - .ageing_time = _DEFAULT_IF_ZERO(nm_setting_bridge_get_ageing_time(s_bridge) * 100u, - NM_BRIDGE_AGEING_TIME_DEF_SYS), + .ageing_time = nm_setting_bridge_get_ageing_time(s_bridge) * 100u, .stp_state = nm_setting_bridge_get_stp(s_bridge), .priority = nm_setting_bridge_get_priority(s_bridge), .vlan_protocol = to_sysfs_vlan_protocol_sys(nm_setting_bridge_get_vlan_protocol(s_bridge)), @@ -1138,7 +1136,7 @@ static void nm_device_bridge_class_init(NMDeviceBridgeClass *klass) { NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS(&interface_info_device_bridge); @@ -1172,11 +1170,11 @@ nm_device_bridge_class_init(NMDeviceBridgeClass *klass) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_BRIDGE_DEVICE_FACTORY, NMBridgeDeviceFactory)) static NMDevice * -create_device(NMDeviceFactory * factory, - const char * iface, +create_device(NMDeviceFactory *factory, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore) + NMConnection *connection, + gboolean *out_ignore) { return g_object_new(NM_TYPE_DEVICE_BRIDGE, NM_DEVICE_IFACE, diff --git a/src/core/devices/nm-device-dummy.c b/src/core/devices/nm-device-dummy.c index 4c12648f..de701a0d 100644 --- a/src/core/devices/nm-device-dummy.c +++ b/src/core/devices/nm-device-dummy.c @@ -12,7 +12,6 @@ #include "nm-act-request.h" #include "nm-device-private.h" -#include "nm-ip4-config.h" #include "libnm-platform/nm-platform.h" #include "nm-device-factory.h" #include "nm-setting-dummy.h" @@ -43,11 +42,11 @@ get_generic_capabilities(NMDevice *dev) } static gboolean -complete_connection(NMDevice * device, - NMConnection * connection, - const char * specific_object, +complete_connection(NMDevice *device, + NMConnection *connection, + const char *specific_object, NMConnection *const *existing_connections, - GError ** error) + GError **error) { nm_utils_complete_generic_with_params(nm_device_get_platform(device), connection, @@ -70,13 +69,13 @@ update_connection(NMDevice *device, NMConnection *connection) } static gboolean -create_and_realize(NMDevice * device, - NMConnection * connection, - NMDevice * parent, +create_and_realize(NMDevice *device, + NMConnection *connection, + NMDevice *parent, const NMPlatformLink **out_plink, - GError ** error) + GError **error) { - const char * iface = nm_device_get_iface(device); + const char *iface = nm_device_get_iface(device); NMSettingDummy *s_dummy; int r; @@ -117,7 +116,7 @@ static void nm_device_dummy_class_init(NMDeviceDummyClass *klass) { NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS(&interface_info_device_dummy); @@ -140,11 +139,11 @@ nm_device_dummy_class_init(NMDeviceDummyClass *klass) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_DUMMY_DEVICE_FACTORY, NMDummyDeviceFactory)) static NMDevice * -create_device(NMDeviceFactory * factory, - const char * iface, +create_device(NMDeviceFactory *factory, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore) + NMConnection *connection, + gboolean *out_ignore) { return g_object_new(NM_TYPE_DEVICE_DUMMY, NM_DEVICE_IFACE, diff --git a/src/core/devices/nm-device-ethernet.c b/src/core/devices/nm-device-ethernet.c index 667ea9b9..6e18d119 100644 --- a/src/core/devices/nm-device-ethernet.c +++ b/src/core/devices/nm-device-ethernet.c @@ -14,38 +14,36 @@ #include #include -#include "libnm-glib-aux/nm-uuid.h" -#include "nm-device-private.h" -#include "nm-act-request.h" -#include "nm-ip4-config.h" #include "NetworkManagerUtils.h" -#include "supplicant/nm-supplicant-manager.h" -#include "supplicant/nm-supplicant-interface.h" -#include "supplicant/nm-supplicant-config.h" -#include "ppp/nm-ppp-manager.h" -#include "ppp/nm-ppp-manager-call.h" -#include "ppp/nm-ppp-status.h" -#include "libnm-platform/nm-platform.h" +#include "NetworkManagerUtils.h" +#include "libnm-core-aux-intern/nm-libnm-core-utils.h" +#include "libnm-core-intern/nm-core-internal.h" +#include "libnm-glib-aux/nm-uuid.h" #include "libnm-platform/nm-platform-utils.h" -#include "nm-dcb.h" -#include "settings/nm-settings-connection.h" +#include "libnm-platform/nm-platform.h" +#include "libnm-udev-aux/nm-udev-utils.h" +#include "nm-act-request.h" #include "nm-config.h" +#include "nm-dcb.h" #include "nm-device-ethernet-utils.h" -#include "settings/nm-settings.h" #include "nm-device-factory.h" -#include "libnm-core-aux-intern/nm-libnm-core-utils.h" -#include "libnm-core-intern/nm-core-internal.h" -#include "NetworkManagerUtils.h" -#include "libnm-udev-aux/nm-udev-utils.h" +#include "nm-device-private.h" #include "nm-device-veth.h" +#include "nm-manager.h" +#include "ppp/nm-ppp-mgr.h" +#include "settings/nm-settings-connection.h" +#include "settings/nm-settings.h" +#include "supplicant/nm-supplicant-config.h" +#include "supplicant/nm-supplicant-interface.h" +#include "supplicant/nm-supplicant-manager.h" #define _NMLOG_DEVICE_TYPE NMDeviceEthernet #include "nm-device-logging.h" /*****************************************************************************/ -#define PPPOE_RECONNECT_DELAY 7 -#define PPPOE_ENCAP_OVERHEAD 8 /* 2 bytes for PPP, 6 for PPPoE */ +#define PPPOE_RECONNECT_DELAY_MSEC 7000 +#define PPPOE_ENCAP_OVERHEAD 8 /* 2 bytes for PPP, 6 for PPPoE */ #define SUPPLICANT_LNK_TIMEOUT_SEC 15 @@ -67,21 +65,21 @@ typedef enum { typedef struct _NMDeviceEthernetPrivate { /* s390 */ - char * subchan1; - char * subchan2; - char * subchan3; - char * subchannels; /* Composite used for checking unmanaged specs */ - char ** subchannels_dbus; /* Array exported on D-Bus */ - char * s390_nettype; + char *subchan1; + char *subchan2; + char *subchan3; + char *subchannels; /* Composite used for checking unmanaged specs */ + char **subchannels_dbus; /* Array exported on D-Bus */ + char *s390_nettype; GHashTable *s390_options; guint32 speed; gulong carrier_id; struct { - NMSupplicantManager * mgr; + NMSupplicantManager *mgr; NMSupplMgrCreateIfaceHandle *create_handle; - NMSupplicantInterface * iface; + NMSupplicantInterface *iface; gulong iface_state_id; gulong auth_state_id; @@ -91,14 +89,16 @@ typedef struct _NMDeviceEthernetPrivate { guint lnk_timeout_id; bool is_associated : 1; + bool ready : 1; } supplicant; NMActRequestGetSecretsCallId *wired_secrets_id; - /* PPPoE */ - NMPPPManager *ppp_manager; - gint32 last_pppoe_time; - guint pppoe_wait_id; + struct { + NMPppMgr *ppp_mgr; + GSource *wait_source; + gint64 last_pppoe_time_msec; + } ppp_data; /* DCB */ DcbWait dcb_wait; @@ -113,6 +113,8 @@ typedef struct _NMDeviceEthernetPrivate { bool ethtool_prev_set : 1; bool ethtool_prev_autoneg : 1; + bool stage2_ready_dcb : 1; + } NMDeviceEthernetPrivate; NM_GOBJECT_PROPERTIES_DEFINE(NMDeviceEthernet, PROP_SPEED, PROP_S390_SUBCHANNELS, ); @@ -150,12 +152,12 @@ static void _update_s390_subchannels(NMDeviceEthernet *self) { NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); - struct udev_device * dev = NULL; - struct udev_device * parent = NULL; - const char * parent_path, *item; + struct udev_device *dev = NULL; + struct udev_device *parent = NULL; + const char *parent_path, *item; int ifindex; - GDir * dir; - GError * error = NULL; + GDir *dir; + GError *error = NULL; if (priv->subchannels) { /* only read the subchannels once. For one, we don't expect them to change @@ -251,7 +253,7 @@ _update_s390_subchannels(NMDeviceEthernet *self) } static void -device_state_changed(NMDevice * device, +device_state_changed(NMDevice *device, NMDeviceState new_state, NMDeviceState old_state, NMDeviceStateReason reason) @@ -306,7 +308,7 @@ static gboolean match_subchans(NMDeviceEthernet *self, NMSettingWired *s_wired, gboolean *try_mac) { NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); - const char *const * subchans; + const char *const *subchans; guint32 num1, num2; int i; @@ -345,7 +347,7 @@ static gboolean check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error) { NMDeviceEthernet *self = NM_DEVICE_ETHERNET(device); - NMSettingWired * s_wired; + NMSettingWired *s_wired; if (!NM_DEVICE_CLASS(nm_device_ethernet_parent_class) ->check_connection_compatible(device, connection, error)) @@ -363,7 +365,7 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError * } if (s_wired) { - const char * mac, *perm_hw_addr; + const char *mac, *perm_hw_addr; gboolean try_mac = TRUE; const char *const *mac_blacklist; int i; @@ -428,6 +430,7 @@ supplicant_interface_release(NMDeviceEthernet *self) nm_clear_g_source(&priv->supplicant.con_timeout_id); nm_clear_g_signal_handler(priv->supplicant.iface, &priv->supplicant.iface_state_id); nm_clear_g_signal_handler(priv->supplicant.iface, &priv->supplicant.auth_state_id); + priv->supplicant.ready = FALSE; if (priv->supplicant.iface) { nm_supplicant_interface_disconnect(priv->supplicant.iface); @@ -437,8 +440,8 @@ supplicant_interface_release(NMDeviceEthernet *self) static void supplicant_auth_state_changed(NMSupplicantInterface *iface, - GParamSpec * pspec, - NMDeviceEthernet * self) + GParamSpec *pspec, + NMDeviceEthernet *self) { NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); NMSupplicantAuthState state; @@ -466,40 +469,39 @@ static void wired_auth_cond_fail(NMDeviceEthernet *self, NMDeviceStateReason reason) { NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); - NMDevice * device = NM_DEVICE(self); - - if (wired_auth_is_optional(self)) { - _LOGI( - LOGD_DEVICE | LOGD_ETHER, - "Activation: (ethernet) 802.1X authentication is optional, continuing after a failure"); - if (NM_IN_SET(nm_device_get_state(device), - NM_DEVICE_STATE_CONFIG, - NM_DEVICE_STATE_NEED_AUTH)) - nm_device_activate_schedule_stage3_ip_config_start(device); - - if (!priv->supplicant.auth_state_id) { - priv->supplicant.auth_state_id = - g_signal_connect(priv->supplicant.iface, - "notify::" NM_SUPPLICANT_INTERFACE_AUTH_STATE, - G_CALLBACK(supplicant_auth_state_changed), - self); - } + NMDevice *device = NM_DEVICE(self); + + if (!wired_auth_is_optional(self)) { + supplicant_interface_release(self); + nm_device_state_changed(NM_DEVICE(self), NM_DEVICE_STATE_FAILED, reason); return; } - supplicant_interface_release(self); - nm_device_state_changed(NM_DEVICE(self), NM_DEVICE_STATE_FAILED, reason); + _LOGI(LOGD_DEVICE | LOGD_ETHER, + "Activation: (ethernet) 802.1X authentication is optional, continuing after a failure"); + priv->supplicant.ready = TRUE; + + if (NM_IN_SET(nm_device_get_state(device), NM_DEVICE_STATE_CONFIG, NM_DEVICE_STATE_NEED_AUTH)) + nm_device_activate_schedule_stage2_device_config(device, FALSE); + + if (!priv->supplicant.auth_state_id) { + priv->supplicant.auth_state_id = + g_signal_connect(priv->supplicant.iface, + "notify::" NM_SUPPLICANT_INTERFACE_AUTH_STATE, + G_CALLBACK(supplicant_auth_state_changed), + self); + } } static void -wired_secrets_cb(NMActRequest * req, +wired_secrets_cb(NMActRequest *req, NMActRequestGetSecretsCallId *call_id, - NMSettingsConnection * connection, - GError * error, + NMSettingsConnection *connection, + GError *error, gpointer user_data) { - NMDeviceEthernet * self = user_data; - NMDevice * device = user_data; + NMDeviceEthernet *self = user_data; + NMDevice *device = user_data; NMDeviceEthernetPrivate *priv; g_return_if_fail(NM_IS_DEVICE_ETHERNET(self)); @@ -539,12 +541,12 @@ wired_secrets_cancel(NMDeviceEthernet *self) } static void -wired_secrets_get_secrets(NMDeviceEthernet * self, - const char * setting_name, +wired_secrets_get_secrets(NMDeviceEthernet *self, + const char *setting_name, NMSecretAgentGetSecretsFlags flags) { NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); - NMActRequest * req; + NMActRequest *req; wired_secrets_cancel(self); @@ -559,12 +561,12 @@ wired_secrets_get_secrets(NMDeviceEthernet * self, static gboolean supplicant_lnk_timeout_cb(gpointer user_data) { - NMDeviceEthernet * self = NM_DEVICE_ETHERNET(user_data); + NMDeviceEthernet *self = NM_DEVICE_ETHERNET(user_data); NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); - NMDevice * device = NM_DEVICE(self); - NMActRequest * req; - NMConnection * applied_connection; - const char * setting_name; + NMDevice *device = NM_DEVICE(self); + NMActRequest *req; + NMConnection *applied_connection; + const char *setting_name; priv->supplicant.lnk_timeout_id = 0; @@ -611,10 +613,10 @@ time_out: static NMSupplicantConfig * build_supplicant_config(NMDeviceEthernet *self, GError **error) { - const char * con_uuid; + const char *con_uuid; NMSupplicantConfig *config = NULL; - NMSetting8021x * security; - NMConnection * connection; + NMSetting8021x *security; + NMConnection *connection; guint32 mtu; connection = nm_device_get_applied_connection(NM_DEVICE(self)); @@ -644,14 +646,15 @@ supplicant_iface_state_is_completed(NMDeviceEthernet *self, NMSupplicantInterfac if (state == NM_SUPPLICANT_INTERFACE_STATE_COMPLETED) { nm_clear_g_source(&priv->supplicant.lnk_timeout_id); nm_clear_g_source(&priv->supplicant.con_timeout_id); + priv->supplicant.ready = TRUE; /* If this is the initial association during device activation, - * schedule the next activation stage. + * schedule the activation stage again to proceed. */ if (nm_device_get_state(NM_DEVICE(self)) == NM_DEVICE_STATE_CONFIG) { _LOGI(LOGD_DEVICE | LOGD_ETHER, "Activation: (ethernet) Stage 2 of 5 (Device Configure) successful."); - nm_device_activate_schedule_stage3_ip_config_start(NM_DEVICE(self)); + nm_device_activate_schedule_stage2_device_config(NM_DEVICE(self), FALSE); } return; } @@ -664,7 +667,7 @@ supplicant_iface_state_is_completed(NMDeviceEthernet *self, NMSupplicantInterfac static void supplicant_iface_assoc_cb(NMSupplicantInterface *iface, GError *error, gpointer user_data) { - NMDeviceEthernet * self; + NMDeviceEthernet *self; NMDeviceEthernetPrivate *priv; if (nm_utils_error_is_cancelled_or_disposing(error)) @@ -692,9 +695,9 @@ supplicant_iface_assoc_cb(NMSupplicantInterface *iface, GError *error, gpointer static gboolean supplicant_iface_start(NMDeviceEthernet *self) { - NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); + NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); gs_unref_object NMSupplicantConfig *config = NULL; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; config = build_supplicant_config(self, &error); if (!config) { @@ -720,8 +723,8 @@ supplicant_iface_state_cb(NMSupplicantInterface *iface, int disconnect_reason, gpointer user_data) { - NMDeviceEthernet * self = NM_DEVICE_ETHERNET(user_data); - NMDeviceEthernetPrivate * priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); + NMDeviceEthernet *self = NM_DEVICE_ETHERNET(user_data); + NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); NMSupplicantInterfaceState new_state = new_state_i; NMSupplicantInterfaceState old_state = old_state_i; @@ -750,7 +753,7 @@ supplicant_iface_state_cb(NMSupplicantInterface *iface, static gboolean handle_auth_or_fail(NMDeviceEthernet *self, NMActRequest *req, gboolean new_secrets) { - const char * setting_name; + const char *setting_name; NMConnection *applied_connection; if (!nm_device_auth_retries_try_next(NM_DEVICE(self))) @@ -789,11 +792,11 @@ handle_auth_or_fail(NMDeviceEthernet *self, NMActRequest *req, gboolean new_secr static gboolean supplicant_connection_timeout_cb(gpointer user_data) { - NMDeviceEthernet * self = NM_DEVICE_ETHERNET(user_data); + NMDeviceEthernet *self = NM_DEVICE_ETHERNET(user_data); NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); - NMDevice * device = NM_DEVICE(self); - NMActRequest * req; - NMSettingsConnection * connection; + NMDevice *device = NM_DEVICE(self); + NMActRequest *req; + NMSettingsConnection *connection; guint64 timestamp = 0; gboolean new_secrets = TRUE; @@ -833,13 +836,13 @@ supplicant_connection_timeout_cb(gpointer user_data) } static void -supplicant_interface_create_cb(NMSupplicantManager * supplicant_manager, +supplicant_interface_create_cb(NMSupplicantManager *supplicant_manager, NMSupplMgrCreateIfaceHandle *handle, - NMSupplicantInterface * iface, - GError * error, + NMSupplicantInterface *iface, + GError *error, gpointer user_data) { - NMDeviceEthernet * self; + NMDeviceEthernet *self; NMDeviceEthernetPrivate *priv; guint timeout; @@ -894,9 +897,9 @@ link_duplex_to_platform(const char *duplex) static void link_negotiation_set(NMDevice *device) { - NMDeviceEthernet * self = NM_DEVICE_ETHERNET(device); + NMDeviceEthernet *self = NM_DEVICE_ETHERNET(device); NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); - NMSettingWired * s_wired; + NMSettingWired *s_wired; gboolean autoneg = TRUE; gboolean link_autoneg; NMPlatformLinkDuplexType duplex = NM_PLATFORM_LINK_DUPLEX_UNKNOWN; @@ -966,20 +969,20 @@ link_negotiation_set(NMDevice *device) static gboolean pppoe_reconnect_delay(gpointer user_data) { - NMDeviceEthernet * self = NM_DEVICE_ETHERNET(user_data); + NMDeviceEthernet *self = NM_DEVICE_ETHERNET(user_data); NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); - priv->pppoe_wait_id = 0; - priv->last_pppoe_time = 0; + nm_clear_g_source_inst(&priv->ppp_data.wait_source); + priv->ppp_data.last_pppoe_time_msec = 0; _LOGI(LOGD_DEVICE, "PPPoE reconnect delay complete, resuming connection..."); nm_device_activate_schedule_stage1_device_prepare(NM_DEVICE(self), FALSE); - return G_SOURCE_REMOVE; + return G_SOURCE_CONTINUE; } static NMActStageReturn act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) { - NMDeviceEthernet * self = NM_DEVICE_ETHERNET(device); + NMDeviceEthernet *self = NM_DEVICE_ETHERNET(device); NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); if (nm_device_sys_iface_state_is_external_or_assume(device)) { @@ -1014,21 +1017,24 @@ act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) * at least for additional NM_SHUTDOWN_TIMEOUT_MS seconds because * otherwise after restart the device won't work for the first seconds. */ - if (priv->last_pppoe_time != 0) { - gint32 delay = nm_utils_get_monotonic_timestamp_sec() - priv->last_pppoe_time; + if (priv->ppp_data.last_pppoe_time_msec != 0) { + gint64 delay = + nm_utils_get_monotonic_timestamp_msec() - priv->ppp_data.last_pppoe_time_msec; - if (delay < PPPOE_RECONNECT_DELAY + if (delay < PPPOE_RECONNECT_DELAY_MSEC && nm_device_get_applied_setting(device, NM_TYPE_SETTING_PPPOE)) { - if (priv->pppoe_wait_id == 0) { + if (!priv->ppp_data.wait_source) { _LOGI(LOGD_DEVICE, - "delaying PPPoE reconnect for %d seconds to ensure peer is ready...", - delay); - priv->pppoe_wait_id = g_timeout_add_seconds(delay, pppoe_reconnect_delay, self); + "delaying PPPoE reconnect for %d.%03d seconds to ensure peer is ready...", + (int) (delay / 1000), + (int) (delay % 1000)); + priv->ppp_data.wait_source = + nm_g_timeout_add_source(delay, pppoe_reconnect_delay, self); } return NM_ACT_STAGE_RETURN_POSTPONE; } - nm_clear_g_source(&priv->pppoe_wait_id); - priv->last_pppoe_time = 0; + nm_clear_g_source_inst(&priv->ppp_data.wait_source); + priv->ppp_data.last_pppoe_time_msec = 0; } return NM_ACT_STAGE_RETURN_SUCCESS; @@ -1038,9 +1044,9 @@ static NMActStageReturn supplicant_check_secrets_needed(NMDeviceEthernet *self, NMDeviceStateReason *out_failure_reason) { NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); - NMConnection * connection; - NMSetting8021x * security; - const char * setting_name; + NMConnection *connection; + NMSetting8021x *security; + const char *setting_name; connection = nm_device_get_applied_connection(NM_DEVICE(self)); g_return_val_if_fail(connection, NM_ACT_STAGE_RETURN_FAILURE); @@ -1105,105 +1111,79 @@ carrier_changed(NMSupplicantInterface *iface, GParamSpec *pspec, NMDeviceEtherne } /*****************************************************************************/ -/* PPPoE */ static void -ppp_state_changed(NMPPPManager *ppp_manager, NMPPPStatus status, gpointer user_data) +_ppp_mgr_cleanup(NMDeviceEthernet *self) { - NMDevice *device = NM_DEVICE(user_data); + NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); - switch (status) { - case NM_PPP_STATUS_DISCONNECT: - nm_device_state_changed(device, - NM_DEVICE_STATE_FAILED, - NM_DEVICE_STATE_REASON_PPP_DISCONNECT); - break; - case NM_PPP_STATUS_DEAD: - nm_device_state_changed(device, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_PPP_FAILED); - break; - default: - break; - } + nm_clear_pointer(&priv->ppp_data.ppp_mgr, nm_ppp_mgr_destroy); } static void -ppp_ifindex_set(NMPPPManager *ppp_manager, int ifindex, const char *iface, gpointer user_data) +_ppp_mgr_stage3_maybe_ready(NMDeviceEthernet *self) { - NMDevice *device = NM_DEVICE(user_data); + NMDevice *device = NM_DEVICE(self); + NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); + int IS_IPv4; - if (!nm_device_set_ip_ifindex(device, ifindex)) { - nm_device_state_changed(device, - NM_DEVICE_STATE_FAILED, - NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); - } -} + for (IS_IPv4 = 1; IS_IPv4 >= 0; IS_IPv4--) { + const int addr_family = IS_IPv4 ? AF_INET : AF_INET6; + const NMPppMgrIPData *ip_data; -static void -ppp_ip4_config(NMPPPManager *ppp_manager, NMIP4Config *config, gpointer user_data) -{ - NMDevice *device = NM_DEVICE(user_data); + ip_data = nm_ppp_mgr_get_ip_data(priv->ppp_data.ppp_mgr, addr_family); + if (ip_data->ip_received) + nm_device_devip_set_state(device, addr_family, NM_DEVICE_IP_STATE_READY, ip_data->l3cd); + } - /* Ignore PPP IP4 events that come in after initial configuration */ - if (nm_device_activate_ip4_state_in_conf(device)) - nm_device_activate_schedule_ip_config_result(device, AF_INET, NM_IP_CONFIG_CAST(config)); + if (nm_ppp_mgr_get_state(priv->ppp_data.ppp_mgr) >= NM_PPP_MGR_STATE_HAVE_IP_CONFIG) + nm_device_devip_set_state(device, AF_UNSPEC, NM_DEVICE_IP_STATE_READY, NULL); } -static NMActStageReturn -pppoe_stage3_ip4_config_start(NMDeviceEthernet *self, NMDeviceStateReason *out_failure_reason) +static void +_ppp_mgr_callback(NMPppMgr *ppp_mgr, const NMPppMgrCallbackData *callback_data, gpointer user_data) { - NMDevice * device = NM_DEVICE(self); - NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); - NMSettingPppoe * s_pppoe; - NMActRequest * req; - GError * err = NULL; - - req = nm_device_get_act_request(device); - - g_return_val_if_fail(req, NM_ACT_STAGE_RETURN_FAILURE); - - s_pppoe = nm_device_get_applied_setting(device, NM_TYPE_SETTING_PPPOE); + NMDeviceEthernet *self = NM_DEVICE_ETHERNET(user_data); + NMDevice *device = NM_DEVICE(self); + NMDeviceState device_state; - g_return_val_if_fail(s_pppoe, NM_ACT_STAGE_RETURN_FAILURE); + if (callback_data->callback_type != NM_PPP_MGR_CALLBACK_TYPE_STATE_CHANGED) + return; - priv->ppp_manager = nm_ppp_manager_create(nm_device_get_iface(device), &err); + device_state = nm_device_get_state(device); - if (priv->ppp_manager) { - nm_ppp_manager_set_route_parameters(priv->ppp_manager, - nm_device_get_route_table(device, AF_INET), - nm_device_get_route_metric(device, AF_INET), - nm_device_get_route_table(device, AF_INET6), - nm_device_get_route_metric(device, AF_INET6)); + if (callback_data->data.state >= _NM_PPP_MGR_STATE_FAILED_START) { + if (device_state <= NM_DEVICE_STATE_ACTIVATED) + nm_device_state_changed(device, NM_DEVICE_STATE_FAILED, callback_data->data.reason); + return; } - if (!priv->ppp_manager - || !nm_ppp_manager_start(priv->ppp_manager, - req, - nm_setting_pppoe_get_username(s_pppoe), - 30, - 0, - &err)) { - _LOGW(LOGD_DEVICE, "PPPoE failed to start: %s", err->message); - g_error_free(err); + if (device_state < NM_DEVICE_STATE_IP_CONFIG) { + if (callback_data->data.state >= NM_PPP_MGR_STATE_HAVE_IFINDEX) { + gs_free char *old_name = NULL; + gs_free_error GError *error = NULL; + + if (!nm_device_take_over_link(device, callback_data->data.ifindex, &old_name, &error)) { + _LOGW(LOGD_DEVICE | LOGD_PPP, + "could not take control of link %d: %s", + callback_data->data.ifindex, + error->message); + _ppp_mgr_cleanup(self); + nm_device_state_changed(device, + NM_DEVICE_STATE_FAILED, + NM_DEVICE_STATE_REASON_CONFIG_FAILED); + return; + } - g_clear_object(&priv->ppp_manager); + if (old_name) + nm_manager_remove_device(NM_MANAGER_GET, old_name, NM_DEVICE_TYPE_PPP); - NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_PPP_START_FAILED); - return NM_ACT_STAGE_RETURN_FAILURE; + nm_device_activate_schedule_stage2_device_config(device, FALSE); + } + return; } - g_signal_connect(priv->ppp_manager, - NM_PPP_MANAGER_SIGNAL_STATE_CHANGED, - G_CALLBACK(ppp_state_changed), - self); - g_signal_connect(priv->ppp_manager, - NM_PPP_MANAGER_SIGNAL_IFINDEX_SET, - G_CALLBACK(ppp_ifindex_set), - self); - g_signal_connect(priv->ppp_manager, - NM_PPP_MANAGER_SIGNAL_IP4_CONFIG, - G_CALLBACK(ppp_ip4_config), - self); - return NM_ACT_STAGE_RETURN_POSTPONE; + _ppp_mgr_stage3_maybe_ready(self); } /*****************************************************************************/ @@ -1213,9 +1193,9 @@ static void dcb_state(NMDevice *device, gboolean timeout); static gboolean dcb_carrier_timeout(gpointer user_data) { - NMDeviceEthernet * self = NM_DEVICE_ETHERNET(user_data); + NMDeviceEthernet *self = NM_DEVICE_ETHERNET(user_data); NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); - NMDevice * device = NM_DEVICE(user_data); + NMDevice *device = NM_DEVICE(user_data); g_return_val_if_fail(nm_device_get_state(device) == NM_DEVICE_STATE_CONFIG, G_SOURCE_REMOVE); @@ -1230,10 +1210,10 @@ dcb_carrier_timeout(gpointer user_data) static gboolean dcb_configure(NMDevice *device) { - NMDeviceEthernet * self = (NMDeviceEthernet *) device; + NMDeviceEthernet *self = (NMDeviceEthernet *) device; NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); - NMSettingDcb * s_dcb; - GError * error = NULL; + NMSettingDcb *s_dcb; + GError *error = NULL; nm_clear_g_source(&priv->dcb_timeout_id); @@ -1259,9 +1239,9 @@ dcb_configure(NMDevice *device) static gboolean dcb_enable(NMDevice *device) { - NMDeviceEthernet * self = NM_DEVICE_ETHERNET(device); + NMDeviceEthernet *self = NM_DEVICE_ETHERNET(device); NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); - GError * error = NULL; + GError *error = NULL; nm_clear_g_source(&priv->dcb_timeout_id); if (!nm_dcb_enable(nm_device_get_iface(device), TRUE, &error)) { @@ -1286,7 +1266,7 @@ dcb_enable(NMDevice *device) static void dcb_state(NMDevice *device, gboolean timeout) { - NMDeviceEthernet * self = NM_DEVICE_ETHERNET(device); + NMDeviceEthernet *self = NM_DEVICE_ETHERNET(device); NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); gboolean carrier; @@ -1351,7 +1331,7 @@ dcb_state(NMDevice *device, gboolean timeout) nm_clear_g_source(&priv->dcb_timeout_id); priv->dcb_handle_carrier_changes = FALSE; priv->dcb_wait = DCB_WAIT_UNKNOWN; - nm_device_activate_schedule_stage3_ip_config_start(device); + nm_device_activate_schedule_stage2_device_config(device, FALSE); } break; default: @@ -1365,8 +1345,8 @@ static gboolean wake_on_lan_enable(NMDevice *device) { NMSettingWiredWakeOnLan wol; - NMSettingWired * s_wired; - const char * password = NULL; + NMSettingWired *s_wired; + const char *password = NULL; s_wired = nm_device_get_applied_setting(device, NM_TYPE_SETTING_WIRED); @@ -1407,31 +1387,98 @@ found: static NMActStageReturn act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) { - NMDeviceEthernet * self = (NMDeviceEthernet *) device; + NMDeviceEthernet *self = NM_DEVICE_ETHERNET(device); NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); - NMSettingConnection * s_con; - const char * connection_type; - gboolean do_postpone = FALSE; - NMSettingDcb * s_dcb; + NMConnection *connection; + NMSettingConnection *s_con; + const char *connection_type; + NMSettingDcb *s_dcb; + NMActRequest *req; - s_con = nm_device_get_applied_setting(device, NM_TYPE_SETTING_CONNECTION); + connection = nm_device_get_applied_connection(device); + g_return_val_if_fail(connection, NM_ACT_STAGE_RETURN_FAILURE); + s_con = _nm_connection_get_setting(connection, NM_TYPE_SETTING_CONNECTION); g_return_val_if_fail(s_con, NM_ACT_STAGE_RETURN_FAILURE); nm_clear_g_source(&priv->dcb_timeout_id); priv->dcb_handle_carrier_changes = FALSE; + connection_type = nm_setting_connection_get_connection_type(s_con); + + if (nm_streq(connection_type, NM_SETTING_PPPOE_SETTING_NAME)) { + if (!priv->ppp_data.ppp_mgr) { + gs_free_error GError *error = NULL; + NMSettingPppoe *s_pppoe; + NMSettingPpp *s_ppp; + + s_ppp = nm_device_get_applied_setting(device, NM_TYPE_SETTING_PPP); + if (s_ppp) { + guint32 mtu; + guint32 mru; + guint32 mxu; + + mtu = nm_setting_ppp_get_mtu(s_ppp); + mru = nm_setting_ppp_get_mru(s_ppp); + mxu = MAX(mru, mtu); + if (mxu) { + _LOGD(LOGD_PPP, + "set MTU to %u (PPP interface MRU %u, MTU %u)", + mxu + PPPOE_ENCAP_OVERHEAD, + mru, + mtu); + nm_platform_link_set_mtu(nm_device_get_platform(device), + nm_device_get_ifindex(device), + mxu + PPPOE_ENCAP_OVERHEAD); + } + } + + req = nm_device_get_act_request(device); + g_return_val_if_fail(req, NM_ACT_STAGE_RETURN_FAILURE); + + s_pppoe = _nm_connection_get_setting(connection, NM_TYPE_SETTING_PPPOE); + g_return_val_if_fail(s_pppoe, NM_ACT_STAGE_RETURN_FAILURE); + + priv->ppp_data.ppp_mgr = + nm_ppp_mgr_start(&((const NMPppMgrConfig){ + .netns = nm_device_get_netns(device), + .parent_iface = nm_device_get_iface(device), + .callback = _ppp_mgr_callback, + .user_data = self, + .act_req = req, + .ppp_username = nm_setting_pppoe_get_username(s_pppoe), + .timeout_secs = 30, + .baud_override = 0, + }), + &error); + if (!priv->ppp_data.ppp_mgr) { + _LOGW(LOGD_DEVICE | LOGD_PPP, "PPPoE failed to start: %s", error->message); + *out_failure_reason = NM_DEVICE_STATE_REASON_PPP_START_FAILED; + return NM_ACT_STAGE_RETURN_FAILURE; + } + + return NM_ACT_STAGE_RETURN_POSTPONE; + } + + if (nm_ppp_mgr_get_state(priv->ppp_data.ppp_mgr) < NM_PPP_MGR_STATE_HAVE_IFINDEX) + return NM_ACT_STAGE_RETURN_POSTPONE; + } + /* 802.1x has to run before any IP configuration since the 802.1x auth * process opens the port up for normal traffic. */ - connection_type = nm_setting_connection_get_connection_type(s_con); if (nm_streq(connection_type, NM_SETTING_WIRED_SETTING_NAME)) { NMSetting8021x *security; security = nm_device_get_applied_setting(device, NM_TYPE_SETTING_802_1X); if (security) { - /* FIXME: for now 802.1x is mutually exclusive with DCB */ + /* FIXME: we always return from this. stage2 must be re-entrant, and + * process all the necessary steps. Just returning for 8021x is wrong. */ + + if (priv->supplicant.ready) + return NM_ACT_STAGE_RETURN_SUCCESS; + if (!nm_device_has_carrier(NM_DEVICE(self))) { _LOGD(LOGD_DEVICE | LOGD_ETHER, "delay supplicant initialization until carrier goes up"); @@ -1450,7 +1497,7 @@ act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) /* DCB and FCoE setup */ s_dcb = nm_device_get_applied_setting(device, NM_TYPE_SETTING_DCB); - if (s_dcb) { + if (!priv->stage2_ready_dcb && s_dcb) { /* lldpad really really wants the carrier to be up */ if (nm_platform_link_is_connected(nm_device_get_platform(device), nm_device_get_ifindex(device))) { @@ -1465,100 +1512,66 @@ act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) } priv->dcb_handle_carrier_changes = TRUE; - do_postpone = TRUE; - } - - /* PPPoE setup */ - if (nm_connection_is_type(nm_device_get_applied_connection(device), - NM_SETTING_PPPOE_SETTING_NAME)) { - NMSettingPpp *s_ppp; - - s_ppp = nm_device_get_applied_setting(device, NM_TYPE_SETTING_PPP); - if (s_ppp) { - guint32 mtu; - guint32 mru; - guint32 mxu; - - mtu = nm_setting_ppp_get_mtu(s_ppp); - mru = nm_setting_ppp_get_mru(s_ppp); - mxu = MAX(mru, mtu); - if (mxu) { - _LOGD(LOGD_PPP, - "set MTU to %u (PPP interface MRU %u, MTU %u)", - mxu + PPPOE_ENCAP_OVERHEAD, - mru, - mtu); - nm_platform_link_set_mtu(nm_device_get_platform(device), - nm_device_get_ifindex(device), - mxu + PPPOE_ENCAP_OVERHEAD); - } - } + return NM_ACT_STAGE_RETURN_POSTPONE; } - return do_postpone ? NM_ACT_STAGE_RETURN_POSTPONE : NM_ACT_STAGE_RETURN_SUCCESS; + return NM_ACT_STAGE_RETURN_SUCCESS; } -static NMActStageReturn -act_stage3_ip_config_start(NMDevice * device, - int addr_family, - gpointer * out_config, - NMDeviceStateReason *out_failure_reason) +static guint32 +get_configured_mtu(NMDevice *device, NMDeviceMtuSource *out_source, gboolean *out_force) { - NMSettingConnection *s_con; - const char * connection_type; - int ifindex; + NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(device); - ifindex = nm_device_get_ifindex(device); + /* MTU only set for plain ethernet */ + if (priv->ppp_data.ppp_mgr) + return 0; - if (ifindex <= 0) - return NM_ACT_STAGE_RETURN_FAILURE; + return nm_device_get_configured_mtu_for_wired(device, out_source, out_force); +} - if (addr_family == AF_INET) { - s_con = nm_device_get_applied_setting(device, NM_TYPE_SETTING_CONNECTION); +static void +act_stage3_ip_config(NMDevice *device, int addr_family) +{ + NMDeviceEthernet *self = NM_DEVICE_ETHERNET(device); + NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); + NMPppMgrState ppp_state; - g_return_val_if_fail(s_con, NM_ACT_STAGE_RETURN_FAILURE); + if (!priv->ppp_data.ppp_mgr) + return; - connection_type = nm_setting_connection_get_connection_type(s_con); - if (!strcmp(connection_type, NM_SETTING_PPPOE_SETTING_NAME)) - return pppoe_stage3_ip4_config_start(NM_DEVICE_ETHERNET(device), out_failure_reason); - } + ppp_state = nm_ppp_mgr_get_state(priv->ppp_data.ppp_mgr); - return NM_DEVICE_CLASS(nm_device_ethernet_parent_class) - ->act_stage3_ip_config_start(device, addr_family, out_config, out_failure_reason); -} + nm_assert(NM_IN_SET(ppp_state, NM_PPP_MGR_STATE_HAVE_IFINDEX, NM_PPP_MGR_STATE_HAVE_IP_CONFIG)); -static guint32 -get_configured_mtu(NMDevice *device, NMDeviceMtuSource *out_source, gboolean *out_force) -{ - /* MTU only set for plain ethernet */ - if (NM_DEVICE_ETHERNET_GET_PRIVATE(device)->ppp_manager) - return 0; + if (ppp_state < NM_PPP_MGR_STATE_HAVE_IP_CONFIG) { + nm_device_devip_set_state(device, AF_UNSPEC, NM_DEVICE_IP_STATE_PENDING, NULL); + return; + } - return nm_device_get_configured_mtu_for_wired(device, out_source, out_force); + _ppp_mgr_stage3_maybe_ready(self); } static void deactivate(NMDevice *device) { - NMDeviceEthernet * self = NM_DEVICE_ETHERNET(device); + NMDeviceEthernet *self = NM_DEVICE_ETHERNET(device); NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); - NMSettingDcb * s_dcb; - GError * error = NULL; + NMSettingDcb *s_dcb; + GError *error = NULL; int ifindex; - nm_clear_g_source(&priv->pppoe_wait_id); + nm_clear_g_source_inst(&priv->ppp_data.wait_source); nm_clear_g_signal_handler(self, &priv->carrier_id); - if (priv->ppp_manager) { - nm_ppp_manager_stop(priv->ppp_manager, NULL, NULL, NULL); - g_clear_object(&priv->ppp_manager); - } + _ppp_mgr_cleanup(self); supplicant_interface_release(self); priv->dcb_wait = DCB_WAIT_UNKNOWN; nm_clear_g_source(&priv->dcb_timeout_id); priv->dcb_handle_carrier_changes = FALSE; + priv->stage2_ready_dcb = FALSE; /* Tear down DCB/FCoE if it was enabled */ s_dcb = nm_device_get_applied_setting(device, NM_TYPE_SETTING_DCB); @@ -1571,7 +1584,7 @@ deactivate(NMDevice *device) /* Set last PPPoE connection time */ if (nm_device_get_applied_setting(device, NM_TYPE_SETTING_PPPOE)) - priv->last_pppoe_time = nm_utils_get_monotonic_timestamp_sec(); + priv->ppp_data.last_pppoe_time_msec = nm_utils_get_monotonic_timestamp_msec(); ifindex = nm_device_get_ifindex(device); if (ifindex > 0 && priv->ethtool_prev_set) { @@ -1594,19 +1607,19 @@ deactivate(NMDevice *device) } static gboolean -complete_connection(NMDevice * device, - NMConnection * connection, - const char * specific_object, +complete_connection(NMDevice *device, + NMConnection *connection, + const char *specific_object, NMConnection *const *existing_connections, - GError ** error) + GError **error) { NMSettingWired *s_wired; NMSettingPppoe *s_pppoe; if (nm_streq0(nm_connection_get_connection_type(connection), NM_SETTING_VETH_SETTING_NAME)) { NMSettingVeth *s_veth; - const char * peer_name = NULL; - const char * con_peer_name = NULL; + const char *peer_name = NULL; + const char *con_peer_name = NULL; int ifindex; nm_utils_complete_generic(nm_device_get_platform(device), @@ -1683,16 +1696,16 @@ complete_connection(NMDevice * device, static NMConnection * new_default_connection(NMDevice *self) { - NMConnection * connection; - NMSettingsConnection *const *connections; - NMSetting * setting; + NMConnection *connection; + NMSettingsConnection *const *connections; + NMSetting *setting; gs_unref_hashtable GHashTable *existing_ids = NULL; - struct udev_device * dev; - const char * perm_hw_addr; - const char * iface; - const char * uprop = "0"; - gs_free char * defname = NULL; - gs_free char * uuid = NULL; + struct udev_device *dev; + const char *perm_hw_addr; + const char *iface; + const char *uprop = "0"; + gs_free char *defname = NULL; + gs_free char *uuid = NULL; guint i, n_connections; perm_hw_addr = nm_device_get_permanent_hw_address(self); @@ -1778,12 +1791,12 @@ update_connection(NMDevice *device, NMConnection *connection) NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(device); NMSettingWired *s_wired = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_WIRED); gboolean perm_hw_addr_is_fake; - const char * perm_hw_addr; - const char * mac = nm_device_get_hw_address(device); - const char * mac_prop = NM_SETTING_WIRED_MAC_ADDRESS; + const char *perm_hw_addr; + const char *mac = nm_device_get_hw_address(device); + const char *mac_prop = NM_SETTING_WIRED_MAC_ADDRESS; GHashTableIter iter; - const char * key; - const char * value; + const char *key; + const char *value; g_object_set(nm_connection_get_setting_connection(connection), NM_SETTING_CONNECTION_TYPE, @@ -1823,7 +1836,7 @@ update_connection(NMDevice *device, NMConnection *connection) static void link_speed_update(NMDevice *device) { - NMDeviceEthernet * self = NM_DEVICE_ETHERNET(device); + NMDeviceEthernet *self = NM_DEVICE_ETHERNET(device); NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); guint32 speed; @@ -1844,7 +1857,7 @@ link_speed_update(NMDevice *device) static void carrier_changed_notify(NMDevice *device, gboolean carrier) { - NMDeviceEthernet * self = NM_DEVICE_ETHERNET(device); + NMDeviceEthernet *self = NM_DEVICE_ETHERNET(device); NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); if (priv->dcb_handle_carrier_changes) { @@ -1880,12 +1893,12 @@ is_available(NMDevice *device, NMDeviceCheckDevAvailableFlags flags) } static gboolean -can_reapply_change(NMDevice * device, +can_reapply_change(NMDevice *device, const char *setting_name, - NMSetting * s_old, - NMSetting * s_new, + NMSetting *s_old, + NMSetting *s_new, GHashTable *diffs, - GError ** error) + GError **error) { NMDeviceClass *device_class; @@ -1926,14 +1939,14 @@ reapply_connection(NMDevice *device, NMConnection *con_old, NMConnection *con_ne static void dispose(GObject *object) { - NMDeviceEthernet * self = NM_DEVICE_ETHERNET(object); + NMDeviceEthernet *self = NM_DEVICE_ETHERNET(object); NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); wired_secrets_cancel(self); supplicant_interface_release(self); - nm_clear_g_source(&priv->pppoe_wait_id); + nm_clear_g_source_inst(&priv->ppp_data.wait_source); nm_clear_g_source(&priv->dcb_timeout_id); @@ -1945,7 +1958,7 @@ dispose(GObject *object) static void finalize(GObject *object) { - NMDeviceEthernet * self = NM_DEVICE_ETHERNET(object); + NMDeviceEthernet *self = NM_DEVICE_ETHERNET(object); NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); g_clear_object(&priv->supplicant.mgr); @@ -1963,7 +1976,7 @@ finalize(GObject *object) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMDeviceEthernet * self = NM_DEVICE_ETHERNET(object); + NMDeviceEthernet *self = NM_DEVICE_ETHERNET(object); NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); switch (prop_id) { @@ -2007,9 +2020,9 @@ static const NMDBusInterfaceInfoExtended interface_info_device_wired = { static void nm_device_ethernet_class_init(NMDeviceEthernetClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); g_type_class_add_private(object_class, sizeof(NMDeviceEthernetPrivate)); @@ -2032,7 +2045,7 @@ nm_device_ethernet_class_init(NMDeviceEthernetClass *klass) device_class->act_stage1_prepare = act_stage1_prepare; device_class->act_stage1_prepare_set_hwaddr_ethernet = TRUE; device_class->act_stage2_config = act_stage2_config; - device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; + device_class->act_stage3_ip_config = act_stage3_ip_config; device_class->get_configured_mtu = get_configured_mtu; device_class->deactivate = deactivate; device_class->get_s390_subchannels = get_s390_subchannels; @@ -2070,11 +2083,11 @@ nm_device_ethernet_class_init(NMDeviceEthernetClass *klass) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_ETHERNET_DEVICE_FACTORY, NMEthernetDeviceFactory)) static NMDevice * -create_device(NMDeviceFactory * factory, - const char * iface, +create_device(NMDeviceFactory *factory, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore) + NMConnection *connection, + gboolean *out_ignore) { return g_object_new(NM_TYPE_DEVICE_ETHERNET, NM_DEVICE_IFACE, @@ -2091,7 +2104,7 @@ create_device(NMDeviceFactory * factory, static gboolean match_connection(NMDeviceFactory *factory, NMConnection *connection) { - const char * type = nm_connection_get_connection_type(connection); + const char *type = nm_connection_get_connection_type(connection); NMSettingPppoe *s_pppoe; if (nm_streq(type, NM_SETTING_WIRED_SETTING_NAME)) diff --git a/src/core/devices/nm-device-factory.c b/src/core/devices/nm-device-factory.c index bdc64135..41e9480f 100644 --- a/src/core/devices/nm-device-factory.c +++ b/src/core/devices/nm-device-factory.c @@ -29,8 +29,8 @@ G_DEFINE_ABSTRACT_TYPE(NMDeviceFactory, nm_device_factory, G_TYPE_OBJECT) /*****************************************************************************/ static void -nm_device_factory_get_supported_types(NMDeviceFactory * factory, - const NMLinkType ** out_link_types, +nm_device_factory_get_supported_types(NMDeviceFactory *factory, + const NMLinkType **out_link_types, const char *const **out_setting_types) { g_return_if_fail(NM_IS_DEVICE_FACTORY(factory)); @@ -50,15 +50,15 @@ nm_device_factory_start(NMDeviceFactory *factory) } NMDevice * -nm_device_factory_create_device(NMDeviceFactory * factory, - const char * iface, +nm_device_factory_create_device(NMDeviceFactory *factory, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore, - GError ** error) + NMConnection *connection, + gboolean *out_ignore, + GError **error) { NMDeviceFactoryClass *klass; - NMDevice * device; + NMDevice *device; gboolean ignore = FALSE; g_return_val_if_fail(factory, NULL); @@ -121,12 +121,12 @@ nm_device_factory_get_connection_parent(NMDeviceFactory *factory, NMConnection * char * nm_device_factory_get_connection_iface(NMDeviceFactory *factory, - NMConnection * connection, - const char * parent_iface, - GError ** error) + NMConnection *connection, + const char *parent_iface, + GError **error) { NMDeviceFactoryClass *klass; - char * ifname; + char *ifname; g_return_val_if_fail(factory != NULL, NULL); g_return_val_if_fail(connection != NULL, NULL); @@ -196,9 +196,9 @@ NMDeviceFactory * nm_device_factory_manager_find_factory_for_connection(NMConnection *connection) { NMDeviceFactoryClass *klass; - NMDeviceFactory * factory; - const char * type; - GSList * list; + NMDeviceFactory *factory; + const char *type; + GSList *list; g_return_val_if_fail(factories_by_setting, NULL); @@ -221,7 +221,7 @@ nm_device_factory_manager_for_each_factory(NMDeviceFactoryManagerFactoryFunc cal { GHashTableIter iter; NMDeviceFactory *factory; - GSList * list_iter, *list = NULL; + GSList *list_iter, *list = NULL; if (factories_by_link) { g_hash_table_iter_init(&iter, factories_by_link); @@ -248,14 +248,14 @@ nm_device_factory_manager_for_each_factory(NMDeviceFactoryManagerFactoryFunc cal } static gboolean -_add_factory(NMDeviceFactory * factory, - const char * path, +_add_factory(NMDeviceFactory *factory, + const char *path, NMDeviceFactoryManagerFactoryFunc callback, gpointer user_data) { - const NMLinkType * link_types = NULL; + const NMLinkType *link_types = NULL; const char *const *setting_types = NULL; - GSList * list, *list2; + GSList *list, *list2; int i; g_return_val_if_fail(factories_by_link, FALSE); @@ -312,22 +312,22 @@ factories_list_unref(GSList *list) } static void -load_factories_from_dir(const char * dirname, +load_factories_from_dir(const char *dirname, NMDeviceFactoryManagerFactoryFunc callback, gpointer user_data) { NMDeviceFactory *factory; - GError * error = NULL; - char ** path, **paths; + GError *error = NULL; + char **path, **paths; paths = nm_utils_read_plugin_paths(dirname, PLUGIN_PREFIX); if (!paths) return; for (path = paths; *path; path++) { - GModule * plugin; + GModule *plugin; NMDeviceFactoryCreateFunc create_func; - const char * item; + const char *item; item = strrchr(*path, '/'); g_assert(item); diff --git a/src/core/devices/nm-device-factory.h b/src/core/devices/nm-device-factory.h index d9b50563..51d64767 100644 --- a/src/core/devices/nm-device-factory.h +++ b/src/core/devices/nm-device-factory.h @@ -45,8 +45,8 @@ typedef struct { * Returns the #NMLinkType and #NMSetting names that this plugin * supports. This function MUST be implemented. */ - void (*get_supported_types)(NMDeviceFactory * factory, - const NMLinkType ** out_link_types, + void (*get_supported_types)(NMDeviceFactory *factory, + const NMLinkType **out_link_types, const char *const **out_setting_types); /** @@ -91,8 +91,8 @@ typedef struct { * Returns: the interface name, or %NULL */ char *(*get_connection_iface)(NMDeviceFactory *factory, - NMConnection * connection, - const char * parent_iface); + NMConnection *connection, + const char *parent_iface); /** * create_device: @@ -112,11 +112,11 @@ typedef struct { * * Returns: the new unrealized #NMDevice, or %NULL */ - NMDevice *(*create_device)(NMDeviceFactory * factory, - const char * iface, + NMDevice *(*create_device)(NMDeviceFactory *factory, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore); + NMConnection *connection, + gboolean *out_ignore); } NMDeviceFactoryClass; @@ -143,21 +143,21 @@ typedef NMDeviceFactory *(*NMDeviceFactoryCreateFunc)(GError **error); /*****************************************************************************/ const char *nm_device_factory_get_connection_parent(NMDeviceFactory *factory, - NMConnection * connection); + NMConnection *connection); char *nm_device_factory_get_connection_iface(NMDeviceFactory *factory, - NMConnection * connection, - const char * parent_iface, - GError ** error); + NMConnection *connection, + const char *parent_iface, + GError **error); void nm_device_factory_start(NMDeviceFactory *factory); -NMDevice *nm_device_factory_create_device(NMDeviceFactory * factory, - const char * iface, +NMDevice *nm_device_factory_create_device(NMDeviceFactory *factory, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore, - GError ** error); + NMConnection *connection, + gboolean *out_ignore, + GError **error); #define NM_DEVICE_FACTORY_DECLARE_LINK_TYPES(...) \ { \ @@ -171,14 +171,14 @@ NMDevice *nm_device_factory_create_device(NMDeviceFactory * factory, } #define NM_DEVICE_FACTORY_DECLARE_TYPES(...) \ - static void get_supported_types(NMDeviceFactory * factory, \ - const NMLinkType ** out_link_types, \ + static void get_supported_types(NMDeviceFactory *factory, \ + const NMLinkType **out_link_types, \ const char *const **out_setting_types) \ { \ static NMLinkType const _link_types_null[1] = {NM_LINK_TYPE_NONE}; \ static const char *const _setting_types_null[1] = {NULL}; \ \ - const NMLinkType * _link_types = _link_types_null; \ + const NMLinkType *_link_types = _link_types_null; \ const char *const *_setting_types = _setting_types_null; \ \ { \ diff --git a/src/core/devices/nm-device-generic.c b/src/core/devices/nm-device-generic.c index 08ea5ac5..9f85925b 100644 --- a/src/core/devices/nm-device-generic.c +++ b/src/core/devices/nm-device-generic.c @@ -58,7 +58,7 @@ get_type_description(NMDevice *device) static void realize_start_notify(NMDevice *device, const NMPlatformLink *plink) { - NMDeviceGeneric * self = NM_DEVICE_GENERIC(device); + NMDeviceGeneric *self = NM_DEVICE_GENERIC(device); NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE(self); int ifindex; @@ -112,7 +112,7 @@ update_connection(NMDevice *device, NMConnection *connection) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMDeviceGeneric * self = NM_DEVICE_GENERIC(object); + NMDeviceGeneric *self = NM_DEVICE_GENERIC(object); NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE(self); switch (prop_id) { @@ -128,7 +128,7 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - NMDeviceGeneric * self = NM_DEVICE_GENERIC(object); + NMDeviceGeneric *self = NM_DEVICE_GENERIC(object); NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE(self); switch (prop_id) { @@ -180,7 +180,7 @@ nm_device_generic_new(const NMPlatformLink *plink, gboolean nm_plugin_missing) static void dispose(GObject *object) { - NMDeviceGeneric * self = NM_DEVICE_GENERIC(object); + NMDeviceGeneric *self = NM_DEVICE_GENERIC(object); NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE(self); nm_clear_g_free(&priv->type_description); @@ -202,9 +202,9 @@ static const NMDBusInterfaceInfoExtended interface_info_device_generic = { static void nm_device_generic_class_init(NMDeviceGenericClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->constructor = constructor; object_class->dispose = dispose; diff --git a/src/core/devices/nm-device-infiniband.c b/src/core/devices/nm-device-infiniband.c index df14dfa8..aef61222 100644 --- a/src/core/devices/nm-device-infiniband.c +++ b/src/core/devices/nm-device-infiniband.c @@ -13,7 +13,6 @@ #include "NetworkManagerUtils.h" #include "nm-device-private.h" #include "nm-act-request.h" -#include "nm-ip4-config.h" #include "libnm-platform/nm-platform.h" #include "nm-device-factory.h" #include "libnm-core-aux-intern/nm-libnm-core-utils.h" @@ -64,7 +63,7 @@ act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) nm_auto_close int dirfd = -1; NMSettingInfiniband *s_infiniband; char ifname_verified[IFNAMSIZ]; - const char * transport_mode; + const char *transport_mode; gboolean ok; s_infiniband = nm_device_get_applied_setting(device, NM_TYPE_SETTING_INFINIBAND); @@ -139,11 +138,11 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError * } static gboolean -complete_connection(NMDevice * device, - NMConnection * connection, - const char * specific_object, +complete_connection(NMDevice *device, + NMConnection *connection, + const char *specific_object, NMConnection *const *existing_connections, - GError ** error) + GError **error) { NMSettingInfiniband *s_infiniband; @@ -197,12 +196,12 @@ update_connection(NMDevice *device, NMConnection *connection) } static gboolean -can_reapply_change(NMDevice * device, +can_reapply_change(NMDevice *device, const char *setting_name, - NMSetting * s_old, - NMSetting * s_new, + NMSetting *s_old, + NMSetting *s_new, GHashTable *diffs, - GError ** error) + GError **error) { NMDeviceClass *device_class; @@ -219,14 +218,14 @@ can_reapply_change(NMDevice * device, } static gboolean -create_and_realize(NMDevice * device, - NMConnection * connection, - NMDevice * parent, +create_and_realize(NMDevice *device, + NMConnection *connection, + NMDevice *parent, const NMPlatformLink **out_plink, - GError ** error) + GError **error) { NMDeviceInfinibandPrivate *priv = NM_DEVICE_INFINIBAND_GET_PRIVATE(device); - NMSettingInfiniband * s_infiniband; + NMSettingInfiniband *s_infiniband; int r; s_infiniband = nm_connection_get_setting_infiniband(connection); @@ -367,9 +366,9 @@ static const NMDBusInterfaceInfoExtended interface_info_device_infiniband = { static void nm_device_infiniband_class_init(NMDeviceInfinibandClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->get_property = get_property; object_class->set_property = set_property; @@ -410,11 +409,11 @@ nm_device_infiniband_class_init(NMDeviceInfinibandClass *klass) NMInfinibandDeviceFactory)) static NMDevice * -create_device(NMDeviceFactory * factory, - const char * iface, +create_device(NMDeviceFactory *factory, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore) + NMConnection *connection, + gboolean *out_ignore) { gboolean is_partition = FALSE; diff --git a/src/core/devices/nm-device-ip-tunnel.c b/src/core/devices/nm-device-ip-tunnel.c index fe2e2023..02680dd7 100644 --- a/src/core/devices/nm-device-ip-tunnel.c +++ b/src/core/devices/nm-device-ip-tunnel.c @@ -22,7 +22,6 @@ #include "libnm-core-intern/nm-core-internal.h" #include "settings/nm-settings.h" #include "nm-act-request.h" -#include "nm-ip4-config.h" #define _NMLOG_DEVICE_TYPE NMDeviceIPTunnel #include "nm-device-logging.h" @@ -44,14 +43,14 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMDeviceIPTunnel, typedef struct { NMIPTunnelMode mode; - char * local; - char * remote; + char *local; + char *remote; guint8 ttl; guint8 tos; gboolean path_mtu_discovery; int addr_family; - char * input_key; - char * output_key; + char *input_key; + char *output_key; guint8 encap_limit; guint32 flow_label; NMIPTunnelFlags flags; @@ -153,7 +152,7 @@ address_set(int addr_family, char **p_addr, const NMIPAddr *addr_new) static void update_properties_from_ifindex(NMDevice *device, int ifindex) { - NMDeviceIPTunnel * self = NM_DEVICE_IP_TUNNEL(device); + NMDeviceIPTunnel *self = NM_DEVICE_IP_TUNNEL(device); NMDeviceIPTunnelPrivate *priv = NM_DEVICE_IP_TUNNEL_GET_PRIVATE(self); int parent_ifindex = 0; NMIPAddr local = NM_IP_ADDR_INIT; @@ -164,7 +163,7 @@ update_properties_from_ifindex(NMDevice *device, int ifindex) gboolean pmtud = FALSE; guint32 flow_label = 0; NMIPTunnelFlags flags = NM_IP_TUNNEL_FLAG_NONE; - char * key; + char *key; if (ifindex <= 0) { clear: @@ -273,7 +272,7 @@ clear: NM_IP_TUNNEL_MODE_IP6GRE, NM_IP_TUNNEL_MODE_IP6GRETAP)) { const NMPlatformLnkIp6Tnl *lnk; - NMPlatform * plat = nm_device_get_platform(device); + NMPlatform *plat = nm_device_get_platform(device); if (priv->mode == NM_IP_TUNNEL_MODE_IP6GRE) lnk = nm_platform_link_get_lnk_ip6gre(plat, ifindex, NULL); @@ -384,11 +383,11 @@ link_changed(NMDevice *device, const NMPlatformLink *pllink) } static gboolean -complete_connection(NMDevice * device, - NMConnection * connection, - const char * specific_object, +complete_connection(NMDevice *device, + NMConnection *connection, + const char *specific_object, NMConnection *const *existing_connections, - GError ** error) + GError **error) { NMSettingIPTunnel *s_ip_tunnel; @@ -417,9 +416,9 @@ complete_connection(NMDevice * device, static void update_connection(NMDevice *device, NMConnection *connection) { - NMDeviceIPTunnel * self = NM_DEVICE_IP_TUNNEL(device); + NMDeviceIPTunnel *self = NM_DEVICE_IP_TUNNEL(device); NMDeviceIPTunnelPrivate *priv = NM_DEVICE_IP_TUNNEL_GET_PRIVATE(self); - NMSettingIPTunnel * s_ip_tunnel = + NMSettingIPTunnel *s_ip_tunnel = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_IP_TUNNEL); if (nm_setting_ip_tunnel_get_mode(s_ip_tunnel) != priv->mode) @@ -491,10 +490,10 @@ update_connection(NMDevice *device, NMConnection *connection) static gboolean check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error) { - NMDeviceIPTunnel * self = NM_DEVICE_IP_TUNNEL(device); + NMDeviceIPTunnel *self = NM_DEVICE_IP_TUNNEL(device); NMDeviceIPTunnelPrivate *priv = NM_DEVICE_IP_TUNNEL_GET_PRIVATE(self); - NMSettingIPTunnel * s_ip_tunnel; - const char * parent; + NMSettingIPTunnel *s_ip_tunnel; + const char *parent; if (!NM_DEVICE_CLASS(nm_device_ip_tunnel_parent_class) ->check_connection_compatible(device, connection, error)) @@ -643,23 +642,23 @@ tunnel_mode_to_link_type(NMIPTunnelMode tunnel_mode) /*****************************************************************************/ static gboolean -create_and_realize(NMDevice * device, - NMConnection * connection, - NMDevice * parent, +create_and_realize(NMDevice *device, + NMConnection *connection, + NMDevice *parent, const NMPlatformLink **out_plink, - GError ** error) + GError **error) { - const char * iface = nm_device_get_iface(device); - NMSettingIPTunnel * s_ip_tunnel; + const char *iface = nm_device_get_iface(device); + NMSettingIPTunnel *s_ip_tunnel; NMPlatformLnkGre lnk_gre = {}; NMPlatformLnkSit lnk_sit = {}; NMPlatformLnkIpIp lnk_ipip = {}; NMPlatformLnkIp6Tnl lnk_ip6tnl = {}; - const char * str; + const char *str; gint64 val; NMIPTunnelMode mode; int r; - gs_free char * hwaddr = NULL; + gs_free char *hwaddr = NULL; guint8 mac_address[ETH_ALEN]; gboolean mac_address_valid = FALSE; @@ -909,12 +908,12 @@ unrealize_notify(NMDevice *device) } static gboolean -can_reapply_change(NMDevice * device, +can_reapply_change(NMDevice *device, const char *setting_name, - NMSetting * s_old, - NMSetting * s_new, + NMSetting *s_old, + NMSetting *s_new, GHashTable *diffs, - GError ** error) + GError **error) { NMDeviceClass *device_class; @@ -934,7 +933,7 @@ can_reapply_change(NMDevice * device, static NMActStageReturn act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) { - NMDeviceIPTunnel * self = NM_DEVICE_IP_TUNNEL(device); + NMDeviceIPTunnel *self = NM_DEVICE_IP_TUNNEL(device); NMDeviceIPTunnelPrivate *priv = NM_DEVICE_IP_TUNNEL_GET_PRIVATE(self); if (_nm_ip_tunnel_mode_is_layer2(priv->mode) @@ -1033,7 +1032,7 @@ constructed(GObject *object) static void dispose(GObject *object) { - NMDeviceIPTunnel * self = NM_DEVICE_IP_TUNNEL(object); + NMDeviceIPTunnel *self = NM_DEVICE_IP_TUNNEL(object); NMDeviceIPTunnelPrivate *priv = NM_DEVICE_IP_TUNNEL_GET_PRIVATE(self); nm_clear_g_free(&priv->local); @@ -1079,9 +1078,9 @@ static const NMDBusInterfaceInfoExtended interface_info_device_ip_tunnel = { static void nm_device_ip_tunnel_class_init(NMDeviceIPTunnelClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->constructed = constructed; object_class->dispose = dispose; @@ -1203,11 +1202,11 @@ nm_device_ip_tunnel_class_init(NMDeviceIPTunnelClass *klass) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_IP_TUNNEL_DEVICE_FACTORY, NMIPTunnelDeviceFactory)) static NMDevice * -create_device(NMDeviceFactory * factory, - const char * iface, +create_device(NMDeviceFactory *factory, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore) + NMConnection *connection, + gboolean *out_ignore) { NMSettingIPTunnel *s_ip_tunnel; NMIPTunnelMode mode; @@ -1256,7 +1255,7 @@ get_connection_parent(NMDeviceFactory *factory, NMConnection *connection) static char * get_connection_iface(NMDeviceFactory *factory, NMConnection *connection, const char *parent_iface) { - const char * ifname; + const char *ifname; NMSettingIPTunnel *s_ip_tunnel; g_return_val_if_fail(nm_connection_is_type(connection, NM_SETTING_IP_TUNNEL_SETTING_NAME), diff --git a/src/core/devices/nm-device-macsec.c b/src/core/devices/nm-device-macsec.c index 51b7225b..5cc0b8da 100644 --- a/src/core/devices/nm-device-macsec.c +++ b/src/core/devices/nm-device-macsec.c @@ -49,9 +49,9 @@ typedef struct { gulong parent_mtu_id; struct { - NMSupplicantManager * mgr; + NMSupplicantManager *mgr; NMSupplMgrCreateIfaceHandle *create_handle; - NMSupplicantInterface * iface; + NMSupplicantInterface *iface; gulong iface_state_id; @@ -92,7 +92,7 @@ static NM_UTILS_LOOKUP_STR_DEFINE(validation_mode_to_string, NM_UTILS_LOOKUP_STR_ITEM(2, "strict"), ); static void -parent_state_changed(NMDevice * parent, +parent_state_changed(NMDevice *parent, NMDeviceState new_state, NMDeviceState old_state, NMDeviceStateReason reason, @@ -126,7 +126,7 @@ parent_changed_notify(NMDevice *device, int new_ifindex, NMDevice *new_parent) { - NMDeviceMacsec * self = NM_DEVICE_MACSEC(device); + NMDeviceMacsec *self = NM_DEVICE_MACSEC(device); NMDeviceMacsecPrivate *priv = NM_DEVICE_MACSEC_GET_PRIVATE(self); NM_DEVICE_CLASS(nm_device_macsec_parent_class) @@ -166,9 +166,9 @@ parent_changed_notify(NMDevice *device, static void update_properties(NMDevice *device) { - NMDeviceMacsec * self; - NMDeviceMacsecPrivate * priv; - const NMPlatformLink * plink = NULL; + NMDeviceMacsec *self; + NMDeviceMacsecPrivate *priv; + const NMPlatformLink *plink = NULL; const NMPlatformLnkMacsec *props = NULL; int ifindex; @@ -220,10 +220,10 @@ static NMSupplicantConfig * build_supplicant_config(NMDeviceMacsec *self, GError **error) { gs_unref_object NMSupplicantConfig *config = NULL; - NMSettingMacsec * s_macsec; - NMSetting8021x * s_8021x; - NMConnection * connection; - const char * con_uuid; + NMSettingMacsec *s_macsec; + NMSetting8021x *s_8021x; + NMConnection *connection; + const char *con_uuid; guint32 mtu; connection = nm_device_get_applied_connection(NM_DEVICE(self)); @@ -275,14 +275,14 @@ supplicant_interface_release(NMDeviceMacsec *self) } static void -macsec_secrets_cb(NMActRequest * req, +macsec_secrets_cb(NMActRequest *req, NMActRequestGetSecretsCallId *call_id, - NMSettingsConnection * connection, - GError * error, + NMSettingsConnection *connection, + GError *error, gpointer user_data) { - NMDeviceMacsec * self = NM_DEVICE_MACSEC(user_data); - NMDevice * device = NM_DEVICE(self); + NMDeviceMacsec *self = NM_DEVICE_MACSEC(user_data); + NMDevice *device = NM_DEVICE(self); NMDeviceMacsecPrivate *priv; g_return_if_fail(NM_IS_DEVICE_MACSEC(self)); @@ -321,12 +321,12 @@ macsec_secrets_cancel(NMDeviceMacsec *self) } static void -macsec_secrets_get_secrets(NMDeviceMacsec * self, - const char * setting_name, +macsec_secrets_get_secrets(NMDeviceMacsec *self, + const char *setting_name, NMSecretAgentGetSecretsFlags flags) { NMDeviceMacsecPrivate *priv = NM_DEVICE_MACSEC_GET_PRIVATE(self); - NMActRequest * req; + NMActRequest *req; macsec_secrets_cancel(self); @@ -341,12 +341,12 @@ macsec_secrets_get_secrets(NMDeviceMacsec * self, static gboolean supplicant_lnk_timeout_cb(gpointer user_data) { - NMDeviceMacsec * self = NM_DEVICE_MACSEC(user_data); + NMDeviceMacsec *self = NM_DEVICE_MACSEC(user_data); NMDeviceMacsecPrivate *priv = NM_DEVICE_MACSEC_GET_PRIVATE(self); - NMDevice * dev = NM_DEVICE(self); - NMActRequest * req; - NMConnection * applied_connection; - const char * setting_name; + NMDevice *dev = NM_DEVICE(self); + NMActRequest *req; + NMConnection *applied_connection; + const char *setting_name; priv->supplicant.lnk_timeout_id = 0; @@ -409,7 +409,7 @@ supplicant_iface_state_is_completed(NMDeviceMacsec *self, NMSupplicantInterfaceS */ if (nm_device_get_state(NM_DEVICE(self)) == NM_DEVICE_STATE_CONFIG) { _LOGI(LOGD_DEVICE, "Activation: Stage 2 of 5 (Device Configure) successful."); - nm_device_activate_schedule_stage3_ip_config_start(NM_DEVICE(self)); + nm_device_activate_schedule_stage3_ip_config(NM_DEVICE(self), FALSE); } return; } @@ -422,7 +422,7 @@ supplicant_iface_state_is_completed(NMDeviceMacsec *self, NMSupplicantInterfaceS static void supplicant_iface_assoc_cb(NMSupplicantInterface *iface, GError *error, gpointer user_data) { - NMDeviceMacsec * self; + NMDeviceMacsec *self; NMDeviceMacsecPrivate *priv; if (nm_utils_error_is_cancelled_or_disposing(error)) @@ -450,9 +450,9 @@ supplicant_iface_assoc_cb(NMSupplicantInterface *iface, GError *error, gpointer static gboolean supplicant_iface_start(NMDeviceMacsec *self) { - NMDeviceMacsecPrivate *priv = NM_DEVICE_MACSEC_GET_PRIVATE(self); + NMDeviceMacsecPrivate *priv = NM_DEVICE_MACSEC_GET_PRIVATE(self); gs_unref_object NMSupplicantConfig *config = NULL; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; config = build_supplicant_config(self, &error); if (!config) { @@ -476,8 +476,8 @@ supplicant_iface_state_cb(NMSupplicantInterface *iface, int disconnect_reason, gpointer user_data) { - NMDeviceMacsec * self = NM_DEVICE_MACSEC(user_data); - NMDeviceMacsecPrivate * priv = NM_DEVICE_MACSEC_GET_PRIVATE(self); + NMDeviceMacsec *self = NM_DEVICE_MACSEC(user_data); + NMDeviceMacsecPrivate *priv = NM_DEVICE_MACSEC_GET_PRIVATE(self); NMSupplicantInterfaceState new_state = new_state_i; NMSupplicantInterfaceState old_state = old_state_i; @@ -506,7 +506,7 @@ supplicant_iface_state_cb(NMSupplicantInterface *iface, static gboolean handle_auth_or_fail(NMDeviceMacsec *self, NMActRequest *req, gboolean new_secrets) { - const char * setting_name; + const char *setting_name; NMConnection *applied_connection; if (!nm_device_auth_retries_try_next(NM_DEVICE(self))) @@ -536,11 +536,11 @@ handle_auth_or_fail(NMDeviceMacsec *self, NMActRequest *req, gboolean new_secret static gboolean supplicant_connection_timeout_cb(gpointer user_data) { - NMDeviceMacsec * self = NM_DEVICE_MACSEC(user_data); + NMDeviceMacsec *self = NM_DEVICE_MACSEC(user_data); NMDeviceMacsecPrivate *priv = NM_DEVICE_MACSEC_GET_PRIVATE(self); - NMDevice * device = NM_DEVICE(self); - NMActRequest * req; - NMSettingsConnection * connection; + NMDevice *device = NM_DEVICE(self); + NMActRequest *req; + NMSettingsConnection *connection; guint64 timestamp = 0; gboolean new_secrets = TRUE; @@ -585,13 +585,13 @@ supplicant_connection_timeout_cb(gpointer user_data) } static void -supplicant_interface_create_cb(NMSupplicantManager * supplicant_manager, +supplicant_interface_create_cb(NMSupplicantManager *supplicant_manager, NMSupplMgrCreateIfaceHandle *handle, - NMSupplicantInterface * iface, - GError * error, + NMSupplicantInterface *iface, + GError *error, gpointer user_data) { - NMDeviceMacsec * self; + NMDeviceMacsec *self; NMDeviceMacsecPrivate *priv; guint timeout; @@ -633,11 +633,11 @@ supplicant_interface_create_cb(NMSupplicantManager * supplicant_manager, static NMActStageReturn act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) { - NMDeviceMacsec * self = NM_DEVICE_MACSEC(device); + NMDeviceMacsec *self = NM_DEVICE_MACSEC(device); NMDeviceMacsecPrivate *priv = NM_DEVICE_MACSEC_GET_PRIVATE(self); - NMConnection * connection; - NMDevice * parent; - const char * setting_name; + NMConnection *connection; + NMDevice *parent; + const char *setting_name; int ifindex; connection = nm_device_get_applied_connection(NM_DEVICE(self)); @@ -712,17 +712,17 @@ is_available(NMDevice *device, NMDeviceCheckDevAvailableFlags flags) } static gboolean -create_and_realize(NMDevice * device, - NMConnection * connection, - NMDevice * parent, +create_and_realize(NMDevice *device, + NMConnection *connection, + NMDevice *parent, const NMPlatformLink **out_plink, - GError ** error) + GError **error) { - const char * iface = nm_device_get_iface(device); - NMSettingMacsec * s_macsec; + const char *iface = nm_device_get_iface(device); + NMSettingMacsec *s_macsec; NMPlatformLnkMacsec lnk = {}; int parent_ifindex; - const char * hw_addr; + const char *hw_addr; union { struct { guint8 mac[6]; @@ -789,7 +789,7 @@ link_changed(NMDevice *device, const NMPlatformLink *pllink) } static void -device_state_changed(NMDevice * device, +device_state_changed(NMDevice *device, NMDeviceState new_state, NMDeviceState old_state, NMDeviceStateReason reason) @@ -803,7 +803,7 @@ device_state_changed(NMDevice * device, static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMDeviceMacsec * self = NM_DEVICE_MACSEC(object); + NMDeviceMacsec *self = NM_DEVICE_MACSEC(object); NMDeviceMacsecPrivate *priv = NM_DEVICE_MACSEC_GET_PRIVATE(self); switch (prop_id) { @@ -905,9 +905,9 @@ static const NMDBusInterfaceInfoExtended interface_info_device_macsec = { static void nm_device_macsec_class_init(NMDeviceMacsecClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->get_property = get_property; object_class->dispose = dispose; @@ -1015,11 +1015,11 @@ nm_device_macsec_class_init(NMDeviceMacsecClass *klass) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_MACSEC_DEVICE_FACTORY, NMMacsecDeviceFactory)) static NMDevice * -create_device(NMDeviceFactory * factory, - const char * iface, +create_device(NMDeviceFactory *factory, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore) + NMConnection *connection, + gboolean *out_ignore) { return g_object_new(NM_TYPE_DEVICE_MACSEC, NM_DEVICE_IFACE, @@ -1037,8 +1037,8 @@ static const char * get_connection_parent(NMDeviceFactory *factory, NMConnection *connection) { NMSettingMacsec *s_macsec; - NMSettingWired * s_wired; - const char * parent = NULL; + NMSettingWired *s_wired; + const char *parent = NULL; g_return_val_if_fail(nm_connection_is_type(connection, NM_SETTING_MACSEC_SETTING_NAME), NULL); @@ -1061,7 +1061,7 @@ static char * get_connection_iface(NMDeviceFactory *factory, NMConnection *connection, const char *parent_iface) { NMSettingMacsec *s_macsec; - const char * ifname; + const char *ifname; g_return_val_if_fail(nm_connection_is_type(connection, NM_SETTING_MACSEC_SETTING_NAME), NULL); diff --git a/src/core/devices/nm-device-macvlan.c b/src/core/devices/nm-device-macvlan.c index 937ba9e4..40ecc5fd 100644 --- a/src/core/devices/nm-device-macvlan.c +++ b/src/core/devices/nm-device-macvlan.c @@ -19,7 +19,6 @@ #include "nm-setting-macvlan.h" #include "nm-setting-wired.h" #include "nm-active-connection.h" -#include "nm-ip4-config.h" #include "nm-utils.h" #define _NMLOG_DEVICE_TYPE NMDeviceMacvlan @@ -104,7 +103,7 @@ platform_mode_to_string(guint mode) /*****************************************************************************/ static void -parent_state_changed(NMDevice * parent, +parent_state_changed(NMDevice *parent, NMDeviceState new_state, NMDeviceState old_state, NMDeviceStateReason reason, @@ -138,7 +137,7 @@ parent_changed_notify(NMDevice *device, int new_ifindex, NMDevice *new_parent) { - NMDeviceMacvlan * self = NM_DEVICE_MACVLAN(device); + NMDeviceMacvlan *self = NM_DEVICE_MACVLAN(device); NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE(self); NM_DEVICE_CLASS(nm_device_macvlan_parent_class) @@ -178,11 +177,11 @@ parent_changed_notify(NMDevice *device, static void update_properties(NMDevice *device) { - NMDeviceMacvlan * self = NM_DEVICE_MACVLAN(device); - NMDeviceMacvlanPrivate * priv = NM_DEVICE_MACVLAN_GET_PRIVATE(self); - GObject * object = G_OBJECT(device); + NMDeviceMacvlan *self = NM_DEVICE_MACVLAN(device); + NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE(self); + GObject *object = G_OBJECT(device); const NMPlatformLnkMacvlan *props; - const NMPlatformLink * plink; + const NMPlatformLink *plink; if (priv->props.tap) props = nm_platform_link_get_lnk_macvtap(nm_device_get_platform(device), @@ -228,14 +227,14 @@ link_changed(NMDevice *device, const NMPlatformLink *pllink) } static gboolean -create_and_realize(NMDevice * device, - NMConnection * connection, - NMDevice * parent, +create_and_realize(NMDevice *device, + NMConnection *connection, + NMDevice *parent, const NMPlatformLink **out_plink, - GError ** error) + GError **error) { - const char * iface = nm_device_get_iface(device); - NMSettingMacvlan * s_macvlan; + const char *iface = nm_device_get_iface(device); + NMSettingMacvlan *s_macvlan; NMPlatformLnkMacvlan lnk = {}; int parent_ifindex; int r; @@ -312,8 +311,8 @@ static gboolean check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error) { NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE(device); - NMSettingMacvlan * s_macvlan; - const char * parent = NULL; + NMSettingMacvlan *s_macvlan; + const char *parent = NULL; if (!NM_DEVICE_CLASS(nm_device_macvlan_parent_class) ->check_connection_compatible(device, connection, error)) @@ -374,11 +373,11 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError * } static gboolean -complete_connection(NMDevice * device, - NMConnection * connection, - const char * specific_object, +complete_connection(NMDevice *device, + NMConnection *connection, + const char *specific_object, NMConnection *const *existing_connections, - GError ** error) + GError **error) { NMSettingMacvlan *s_macvlan; @@ -421,7 +420,7 @@ static void update_connection(NMDevice *device, NMConnection *connection) { NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE(device); - NMSettingMacvlan * s_macvlan = + NMSettingMacvlan *s_macvlan = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_MACVLAN); int new_mode; @@ -511,9 +510,9 @@ static const NMDBusInterfaceInfoExtended interface_info_device_macvlan = { static void nm_device_macvlan_class_init(NMDeviceMacvlanClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); #if NM_MORE_ASSERTS object_class->dispose = dispose; @@ -570,11 +569,11 @@ nm_device_macvlan_class_init(NMDeviceMacvlanClass *klass) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_MACVLAN_DEVICE_FACTORY, NMMacvlanDeviceFactory)) static NMDevice * -create_device(NMDeviceFactory * factory, - const char * iface, +create_device(NMDeviceFactory *factory, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore) + NMConnection *connection, + gboolean *out_ignore) { NMSettingMacvlan *s_macvlan; NMLinkType link_type; @@ -609,8 +608,8 @@ static const char * get_connection_parent(NMDeviceFactory *factory, NMConnection *connection) { NMSettingMacvlan *s_macvlan; - NMSettingWired * s_wired; - const char * parent = NULL; + NMSettingWired *s_wired; + const char *parent = NULL; g_return_val_if_fail(nm_connection_is_type(connection, NM_SETTING_MACVLAN_SETTING_NAME), NULL); @@ -633,7 +632,7 @@ static char * get_connection_iface(NMDeviceFactory *factory, NMConnection *connection, const char *parent_iface) { NMSettingMacvlan *s_macvlan; - const char * ifname; + const char *ifname; g_return_val_if_fail(nm_connection_is_type(connection, NM_SETTING_MACVLAN_SETTING_NAME), NULL); diff --git a/src/core/devices/nm-device-ppp.c b/src/core/devices/nm-device-ppp.c index 04051bec..5ff32401 100644 --- a/src/core/devices/nm-device-ppp.c +++ b/src/core/devices/nm-device-ppp.c @@ -7,16 +7,14 @@ #include "nm-device-ppp.h" -#include "nm-ip4-config.h" +#include "nm-l3-config-data.h" #include "nm-act-request.h" #include "nm-device-factory.h" #include "nm-device-private.h" #include "nm-manager.h" #include "nm-setting-pppoe.h" #include "libnm-platform/nm-platform.h" -#include "ppp/nm-ppp-manager.h" -#include "ppp/nm-ppp-manager-call.h" -#include "ppp/nm-ppp-status.h" +#include "ppp/nm-ppp-mgr.h" #define _NMLOG_DEVICE_TYPE NMDevicePpp #include "nm-device-logging.h" @@ -24,8 +22,7 @@ /*****************************************************************************/ typedef struct _NMDevicePppPrivate { - NMPPPManager *ppp_manager; - NMIP4Config * ip4_config; + NMPppMgr *ppp_mgr; } NMDevicePppPrivate; struct _NMDevicePpp { @@ -42,86 +39,92 @@ G_DEFINE_TYPE(NMDevicePpp, nm_device_ppp, NM_TYPE_DEVICE) #define NM_DEVICE_PPP_GET_PRIVATE(self) \ _NM_GET_PRIVATE(self, NMDevicePpp, NM_IS_DEVICE_PPP, NMDevice) +/*****************************************************************************/ + static NMDeviceCapabilities get_generic_capabilities(NMDevice *device) { return NM_DEVICE_CAP_IS_SOFTWARE; } +/*****************************************************************************/ + static void -ppp_state_changed(NMPPPManager *ppp_manager, NMPPPStatus status, gpointer user_data) +_ppp_mgr_cleanup(NMDevicePpp *self) { - NMDevice *device = NM_DEVICE(user_data); - - switch (status) { - case NM_PPP_STATUS_DISCONNECT: - nm_device_state_changed(device, - NM_DEVICE_STATE_FAILED, - NM_DEVICE_STATE_REASON_PPP_DISCONNECT); - break; - case NM_PPP_STATUS_DEAD: - nm_device_state_changed(device, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_PPP_FAILED); - break; - default: - break; - } + NMDevicePppPrivate *priv = NM_DEVICE_PPP_GET_PRIVATE(self); + + nm_clear_pointer(&priv->ppp_mgr, nm_ppp_mgr_destroy); } static void -ppp_ifindex_set(NMPPPManager *ppp_manager, int ifindex, const char *iface, gpointer user_data) +_ppp_mgr_stage3_maybe_ready(NMDevicePpp *self) { - NMDevice * device = NM_DEVICE(user_data); - NMDevicePpp * self = NM_DEVICE_PPP(device); - gs_free char *old_name = NULL; - gs_free_error GError *error = NULL; - - if (!nm_device_take_over_link(device, ifindex, &old_name, &error)) { - _LOGW(LOGD_DEVICE | LOGD_PPP, - "could not take control of link %d: %s", - ifindex, - error->message); - nm_device_state_changed(device, - NM_DEVICE_STATE_FAILED, - NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); - return; - } + NMDevice *device = NM_DEVICE(self); + NMDevicePppPrivate *priv = NM_DEVICE_PPP_GET_PRIVATE(self); + int IS_IPv4; + + for (IS_IPv4 = 1; IS_IPv4 >= 0; IS_IPv4--) { + const int addr_family = IS_IPv4 ? AF_INET : AF_INET6; + const NMPppMgrIPData *ip_data; - if (old_name) - nm_manager_remove_device(NM_MANAGER_GET, old_name, NM_DEVICE_TYPE_PPP); + ip_data = nm_ppp_mgr_get_ip_data(priv->ppp_mgr, addr_family); + if (ip_data->ip_received) + nm_device_devip_set_state(device, addr_family, NM_DEVICE_IP_STATE_READY, ip_data->l3cd); + } - nm_device_activate_schedule_stage3_ip_config_start(device); + if (nm_ppp_mgr_get_state(priv->ppp_mgr) >= NM_PPP_MGR_STATE_HAVE_IP_CONFIG) + nm_device_devip_set_state(device, AF_UNSPEC, NM_DEVICE_IP_STATE_READY, NULL); } static void -_ppp_ip4_config_handle(NMDevicePpp *self) +_ppp_mgr_callback(NMPppMgr *ppp_mgr, const NMPppMgrCallbackData *callback_data, gpointer user_data) { - NMDevice * device = NM_DEVICE(self); - NMDevicePppPrivate *priv = NM_DEVICE_PPP_GET_PRIVATE(self); + NMDevicePpp *self = NM_DEVICE_PPP(user_data); + NMDevice *device = NM_DEVICE(self); + NMDeviceState device_state; - if (!priv->ip4_config) + if (callback_data->callback_type != NM_PPP_MGR_CALLBACK_TYPE_STATE_CHANGED) return; - if (nm_device_get_state(device) == NM_DEVICE_STATE_IP_CONFIG - && nm_device_activate_ip4_state_in_conf(device)) { - nm_device_activate_schedule_ip_config_result( - device, - AF_INET, - NM_IP_CONFIG_CAST(g_steal_pointer(&priv->ip4_config))); + device_state = nm_device_get_state(device); + + if (callback_data->data.state >= _NM_PPP_MGR_STATE_FAILED_START) { + if (device_state <= NM_DEVICE_STATE_ACTIVATED) + nm_device_state_changed(device, NM_DEVICE_STATE_FAILED, callback_data->data.reason); return; } -} -static void -ppp_ip4_config(NMPPPManager *ppp_manager, NMIP4Config *config, gpointer user_data) -{ - NMDevicePpp * self = NM_DEVICE_PPP(user_data); - NMDevicePppPrivate *priv = NM_DEVICE_PPP_GET_PRIVATE(self); + if (device_state < NM_DEVICE_STATE_IP_CONFIG) { + if (callback_data->data.state >= NM_PPP_MGR_STATE_HAVE_IFINDEX) { + gs_free char *old_name = NULL; + gs_free_error GError *error = NULL; + + if (!nm_device_take_over_link(device, callback_data->data.ifindex, &old_name, &error)) { + _LOGW(LOGD_DEVICE | LOGD_PPP, + "could not take control of link %d: %s", + callback_data->data.ifindex, + error->message); + _ppp_mgr_cleanup(self); + nm_device_state_changed(device, + NM_DEVICE_STATE_FAILED, + NM_DEVICE_STATE_REASON_CONFIG_FAILED); + return; + } + + if (old_name) + nm_manager_remove_device(NM_MANAGER_GET, old_name, NM_DEVICE_TYPE_PPP); + + nm_device_activate_schedule_stage2_device_config(device, FALSE); + } + return; + } - _LOGT(LOGD_DEVICE | LOGD_PPP, "received IPv4 config from pppd"); - nm_g_object_ref_set(&priv->ip4_config, config); - _ppp_ip4_config_handle(self); + _ppp_mgr_stage3_maybe_ready(self); } +/*****************************************************************************/ + static gboolean check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error) { @@ -145,97 +148,92 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError * static NMActStageReturn act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) { - NMDevicePpp * self = NM_DEVICE_PPP(device); + NMDevicePpp *self = NM_DEVICE_PPP(device); NMDevicePppPrivate *priv = NM_DEVICE_PPP_GET_PRIVATE(self); - NMSettingPppoe * s_pppoe; - NMActRequest * req; - GError * error = NULL; + NMSettingPppoe *s_pppoe; + NMActRequest *req; + + if (!priv->ppp_mgr) { + gs_free_error GError *error = NULL; + + req = nm_device_get_act_request(device); + g_return_val_if_fail(req, NM_ACT_STAGE_RETURN_FAILURE); + + s_pppoe = nm_device_get_applied_setting(device, NM_TYPE_SETTING_PPPOE); + g_return_val_if_fail(s_pppoe, NM_ACT_STAGE_RETURN_FAILURE); + + priv->ppp_mgr = nm_ppp_mgr_start(&((const NMPppMgrConfig){ + .netns = nm_device_get_netns(device), + .parent_iface = nm_setting_pppoe_get_parent(s_pppoe), + .callback = _ppp_mgr_callback, + .user_data = self, + .act_req = req, + .ppp_username = nm_setting_pppoe_get_username(s_pppoe), + .timeout_secs = 30, + .baud_override = 0, + }), + &error); + if (!priv->ppp_mgr) { + _LOGW(LOGD_DEVICE | LOGD_PPP, "PPPoE failed to start: %s", error->message); + *out_failure_reason = NM_DEVICE_STATE_REASON_PPP_START_FAILED; + return NM_ACT_STAGE_RETURN_FAILURE; + } - req = nm_device_get_act_request(device); - g_return_val_if_fail(req, NM_ACT_STAGE_RETURN_FAILURE); + return NM_ACT_STAGE_RETURN_POSTPONE; + } - s_pppoe = nm_device_get_applied_setting(device, NM_TYPE_SETTING_PPPOE); - g_return_val_if_fail(s_pppoe, NM_ACT_STAGE_RETURN_FAILURE); + if (nm_ppp_mgr_get_state(priv->ppp_mgr) < NM_PPP_MGR_STATE_HAVE_IFINDEX) + return NM_ACT_STAGE_RETURN_POSTPONE; - g_clear_object(&priv->ip4_config); + return NM_ACT_STAGE_RETURN_SUCCESS; +} - priv->ppp_manager = nm_ppp_manager_create(nm_setting_pppoe_get_parent(s_pppoe), &error); +static void +act_stage3_ip_config(NMDevice *device, int addr_family) +{ + NMDevicePpp *self = NM_DEVICE_PPP(device); + NMDevicePppPrivate *priv = NM_DEVICE_PPP_GET_PRIVATE(self); + NMPppMgrState ppp_state; - if (priv->ppp_manager) { - nm_ppp_manager_set_route_parameters(priv->ppp_manager, - nm_device_get_route_table(device, AF_INET), - nm_device_get_route_metric(device, AF_INET), - nm_device_get_route_table(device, AF_INET6), - nm_device_get_route_metric(device, AF_INET6)); + if (!priv->ppp_mgr) { + nm_assert_not_reached(); + return; } - if (!priv->ppp_manager - || !nm_ppp_manager_start(priv->ppp_manager, - req, - nm_setting_pppoe_get_username(s_pppoe), - 30, - 0, - &error)) { - _LOGW(LOGD_DEVICE | LOGD_PPP, "PPPoE failed to start: %s", error->message); - g_error_free(error); + ppp_state = nm_ppp_mgr_get_state(priv->ppp_mgr); - g_clear_object(&priv->ppp_manager); + nm_assert(NM_IN_SET(ppp_state, NM_PPP_MGR_STATE_HAVE_IFINDEX, NM_PPP_MGR_STATE_HAVE_IP_CONFIG)); - NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_PPP_START_FAILED); - return NM_ACT_STAGE_RETURN_FAILURE; + if (ppp_state < NM_PPP_MGR_STATE_HAVE_IP_CONFIG) { + nm_device_devip_set_state(device, AF_UNSPEC, NM_DEVICE_IP_STATE_PENDING, NULL); + return; } - g_signal_connect(priv->ppp_manager, - NM_PPP_MANAGER_SIGNAL_STATE_CHANGED, - G_CALLBACK(ppp_state_changed), - self); - g_signal_connect(priv->ppp_manager, - NM_PPP_MANAGER_SIGNAL_IFINDEX_SET, - G_CALLBACK(ppp_ifindex_set), - self); - g_signal_connect(priv->ppp_manager, - NM_PPP_MANAGER_SIGNAL_IP4_CONFIG, - G_CALLBACK(ppp_ip4_config), - self); - return NM_ACT_STAGE_RETURN_POSTPONE; -} - -static gboolean -_schedule_ip_config_result(gpointer user_data) -{ - gs_unref_object NMDevicePpp *self = user_data; - - _ppp_ip4_config_handle(self); - return G_SOURCE_REMOVE; + _ppp_mgr_stage3_maybe_ready(self); } -static NMActStageReturn -act_stage3_ip_config_start(NMDevice * device, - int addr_family, - gpointer * out_config, - NMDeviceStateReason *out_failure_reason) +static const char * +get_ip_method_auto(NMDevice *device, int addr_family) { - if (addr_family == AF_INET) { - NMDevicePpp * self = NM_DEVICE_PPP(device); - NMDevicePppPrivate *priv = NM_DEVICE_PPP_GET_PRIVATE(self); - - if (priv->ip4_config) - nm_g_idle_add(_schedule_ip_config_result, g_object_ref(self)); - - /* Wait IPCP termination */ - return NM_ACT_STAGE_RETURN_POSTPONE; + if (NM_IS_IPv4(addr_family)) { + /* We cannot do DHCPv4 on a PPP link, instead we get "auto" IP addresses + * by pppd. Return "manual" here, which has the suitable effect to a + * (zero) manual addresses in addition. */ + return NM_SETTING_IP6_CONFIG_METHOD_MANUAL; } - return NM_DEVICE_CLASS(nm_device_ppp_parent_class) - ->act_stage3_ip_config_start(device, addr_family, out_config, out_failure_reason); + /* We can do autoconf6 on an PPP link, but we should already get an IPv6 + * address from pppd. Use that instead. We however do want to generate our + * (own) IPv6 link local address, so return "link-local". */ + return NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL; } static gboolean -create_and_realize(NMDevice * device, - NMConnection * connection, - NMDevice * parent, +create_and_realize(NMDevice *device, + NMConnection *connection, + NMDevice *parent, const NMPlatformLink **out_plink, - GError ** error) + GError **error) { int parent_ifindex; @@ -260,17 +258,13 @@ create_and_realize(NMDevice * device, static void deactivate(NMDevice *device) { - NMDevicePpp * self = NM_DEVICE_PPP(device); - NMDevicePppPrivate *priv = NM_DEVICE_PPP_GET_PRIVATE(self); + NMDevicePpp *self = NM_DEVICE_PPP(device); - if (priv->ppp_manager) { - nm_ppp_manager_stop(priv->ppp_manager, NULL, NULL, NULL); - g_clear_object(&priv->ppp_manager); - } - - g_clear_object(&priv->ip4_config); + _ppp_mgr_cleanup(self); } +/*****************************************************************************/ + static void nm_device_ppp_init(NMDevicePpp *self) {} @@ -278,10 +272,9 @@ nm_device_ppp_init(NMDevicePpp *self) static void dispose(GObject *object) { - NMDevicePpp * self = NM_DEVICE_PPP(object); - NMDevicePppPrivate *priv = NM_DEVICE_PPP_GET_PRIVATE(self); + NMDevicePpp *self = NM_DEVICE_PPP(object); - g_clear_object(&priv->ip4_config); + _ppp_mgr_cleanup(self); G_OBJECT_CLASS(nm_device_ppp_parent_class)->dispose(object); } @@ -293,9 +286,9 @@ static const NMDBusInterfaceInfoExtended interface_info_device_ppp = { static void nm_device_ppp_class_init(NMDevicePppClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->dispose = dispose; @@ -306,7 +299,8 @@ nm_device_ppp_class_init(NMDevicePppClass *klass) device_class->link_types = NM_DEVICE_DEFINE_LINK_TYPES(NM_LINK_TYPE_PPP); device_class->act_stage2_config = act_stage2_config; - device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; + device_class->act_stage3_ip_config = act_stage3_ip_config; + device_class->get_ip_method_auto = get_ip_method_auto; device_class->check_connection_compatible = check_connection_compatible; device_class->create_and_realize = create_and_realize; device_class->deactivate = deactivate; @@ -320,11 +314,11 @@ nm_device_ppp_class_init(NMDevicePppClass *klass) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_PPP_DEVICE_FACTORY, NMPppDeviceFactory)) static NMDevice * -create_device(NMDeviceFactory * factory, - const char * iface, +create_device(NMDeviceFactory *factory, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore) + NMConnection *connection, + gboolean *out_ignore) { return g_object_new(NM_TYPE_DEVICE_PPP, NM_DEVICE_IFACE, diff --git a/src/core/devices/nm-device-private.h b/src/core/devices/nm-device-private.h index b55e8b43..790bb823 100644 --- a/src/core/devices/nm-device-private.h +++ b/src/core/devices/nm-device-private.h @@ -8,6 +8,7 @@ #define __NETWORKMANAGER_DEVICE_PRIVATE_H__ #include "nm-device.h" +#include "nm-l3-config-data.h" /* This file should only be used by subclasses of NMDevice */ @@ -21,12 +22,6 @@ enum NMActStageReturn { NM_ACT_STAGE_RETURN_FAILURE = 0, /* Hard failure of activation */ NM_ACT_STAGE_RETURN_SUCCESS, /* Activation stage done */ NM_ACT_STAGE_RETURN_POSTPONE, /* Long-running operation in progress */ - NM_ACT_STAGE_RETURN_IP_WAIT, /* IP config stage is waiting (state IP_WAIT) */ - NM_ACT_STAGE_RETURN_IP_DONE, /* IP config stage is done (state IP_DONE), - * For the ip-config stage, this is similar to - * NM_ACT_STAGE_RETURN_SUCCESS, except that no - * IP config should be committed. */ - NM_ACT_STAGE_RETURN_IP_FAIL, /* IP config stage failed (state IP_FAIL), activation may proceed */ }; #define NM_DEVICE_CAP_NONSTANDARD_CARRIER 0x80000000 @@ -34,8 +29,6 @@ enum NMActStageReturn { #define NM_DEVICE_CAP_INTERNAL_MASK 0xc0000000 -void nm_device_arp_announce(NMDevice *self); - NMSettings *nm_device_get_settings(NMDevice *self); NMManager *nm_device_get_manager(NMDevice *self); @@ -44,17 +37,13 @@ gboolean nm_device_set_ip_ifindex(NMDevice *self, int ifindex); gboolean nm_device_set_ip_iface(NMDevice *self, const char *iface); -void nm_device_activate_schedule_stage3_ip_config_start(NMDevice *device); - -gboolean nm_device_activate_stage3_ip_start(NMDevice *self, int addr_family); - gboolean nm_device_bring_up(NMDevice *self, gboolean wait, gboolean *no_firmware); void nm_device_take_down(NMDevice *self, gboolean block); gboolean nm_device_take_over_link(NMDevice *self, int ifindex, char **old_name, GError **error); -gboolean nm_device_hw_addr_set(NMDevice * device, +gboolean nm_device_hw_addr_set(NMDevice *device, const char *addr, const char *detail, gboolean set_permanent); @@ -65,52 +54,7 @@ void nm_device_set_firmware_missing(NMDevice *self, gboolean missing); void nm_device_activate_schedule_stage1_device_prepare(NMDevice *device, gboolean do_sync); void nm_device_activate_schedule_stage2_device_config(NMDevice *device, gboolean do_sync); - -void -nm_device_activate_schedule_ip_config_result(NMDevice *device, int addr_family, NMIPConfig *config); - -void nm_device_activate_schedule_ip_config_timeout(NMDevice *device, int addr_family); - -NMDeviceIPState nm_device_activate_get_ip_state(NMDevice *self, int addr_family); - -static inline gboolean -nm_device_activate_ip4_state_in_conf(NMDevice *self) -{ - return nm_device_activate_get_ip_state(self, AF_INET) == NM_DEVICE_IP_STATE_CONF; -} - -static inline gboolean -nm_device_activate_ip4_state_in_wait(NMDevice *self) -{ - return nm_device_activate_get_ip_state(self, AF_INET) == NM_DEVICE_IP_STATE_WAIT; -} - -static inline gboolean -nm_device_activate_ip4_state_done(NMDevice *self) -{ - return nm_device_activate_get_ip_state(self, AF_INET) == NM_DEVICE_IP_STATE_DONE; -} - -static inline gboolean -nm_device_activate_ip6_state_in_conf(NMDevice *self) -{ - return nm_device_activate_get_ip_state(self, AF_INET6) == NM_DEVICE_IP_STATE_CONF; -} - -static inline gboolean -nm_device_activate_ip6_state_in_wait(NMDevice *self) -{ - return nm_device_activate_get_ip_state(self, AF_INET6) == NM_DEVICE_IP_STATE_WAIT; -} - -static inline gboolean -nm_device_activate_ip6_state_done(NMDevice *self) -{ - return nm_device_activate_get_ip_state(self, AF_INET6) == NM_DEVICE_IP_STATE_DONE; -} - -gboolean nm_device_dhcp4_renew(NMDevice *device, gboolean release); -gboolean nm_device_dhcp6_renew(NMDevice *device, gboolean release); +void nm_device_activate_schedule_stage3_ip_config(NMDevice *device, gboolean do_sync); void nm_device_recheck_available_connections(NMDevice *device); @@ -122,46 +66,75 @@ void nm_device_master_release_slaves(NMDevice *self); void nm_device_set_carrier(NMDevice *self, gboolean carrier); void nm_device_queue_recheck_assume(NMDevice *device); -void nm_device_queue_recheck_available(NMDevice * device, +void nm_device_queue_recheck_available(NMDevice *device, NMDeviceStateReason available_reason, NMDeviceStateReason unavailable_reason); -void nm_device_set_dev2_ip_config(NMDevice *device, int addr_family, NMIPConfig *config); - gboolean nm_device_hw_addr_is_explict(NMDevice *device); -void nm_device_ip_method_failed(NMDevice *self, int addr_family, NMDeviceStateReason reason); +NMDeviceIPState nm_device_devip_get_state(NMDevice *self, int addr_family); -gboolean nm_device_sysctl_ip_conf_set(NMDevice * self, +void nm_device_devip_set_state_full(NMDevice *self, + int addr_family, + NMDeviceIPState ip_state, + const NML3ConfigData *l3cd, + NMDeviceStateReason failed_reason); + +static inline void +nm_device_devip_set_state(NMDevice *self, + int addr_family, + NMDeviceIPState ip_state, + const NML3ConfigData *l3cd) +{ + nm_assert(NM_IS_DEVICE(self)); + nm_assert_addr_family_or_unspec(addr_family); + nm_assert(!l3cd || NM_IS_L3_CONFIG_DATA(l3cd)); + nm_assert(NM_IN_SET(ip_state, NM_DEVICE_IP_STATE_PENDING, NM_DEVICE_IP_STATE_READY)); + + nm_device_devip_set_state_full(self, addr_family, ip_state, l3cd, NM_DEVICE_STATE_REASON_NONE); +} + +static inline void +nm_device_devip_set_failed(NMDevice *self, int addr_family, NMDeviceStateReason reason) +{ + nm_assert(NM_IS_DEVICE(self)); + nm_assert_addr_family_or_unspec(addr_family); + nm_assert(reason != NM_DEVICE_STATE_REASON_NONE); + + nm_device_devip_set_state_full(self, addr_family, NM_DEVICE_IP_STATE_FAILED, NULL, reason); +} + +gboolean nm_device_sysctl_ip_conf_set(NMDevice *self, int addr_family, const char *property, const char *value); -NMIP4Config *nm_device_ip4_config_new(NMDevice *self); +NML3ConfigData *nm_device_create_l3_config_data(NMDevice *self, NMIPConfigSource source); -NMIP6Config *nm_device_ip6_config_new(NMDevice *self); +const NML3ConfigData *nm_device_create_l3_config_data_from_connection(NMDevice *self, + NMConnection *connection); -NMIPConfig *nm_device_ip_config_new(NMDevice *self, int addr_family); +void nm_device_ip_method_dhcp4_start(NMDevice *self); -NML3ConfigData *nm_device_create_l3_config_data(NMDevice *self, NMIPConfigSource source); +void nm_device_ip_method_autoconf6_start(NMDevice *self); /*****************************************************************************/ -gint64 nm_device_get_configured_mtu_from_connection_default(NMDevice * self, +gint64 nm_device_get_configured_mtu_from_connection_default(NMDevice *self, const char *property_name, guint32 max_mtu); -guint32 nm_device_get_configured_mtu_from_connection(NMDevice * device, +guint32 nm_device_get_configured_mtu_from_connection(NMDevice *device, GType setting_type, NMDeviceMtuSource *out_source); -guint32 nm_device_get_configured_mtu_for_wired(NMDevice * self, +guint32 nm_device_get_configured_mtu_for_wired(NMDevice *self, NMDeviceMtuSource *out_source, - gboolean * out_force); + gboolean *out_force); -guint32 nm_device_get_configured_mtu_wired_parent(NMDevice * self, +guint32 nm_device_get_configured_mtu_wired_parent(NMDevice *self, NMDeviceMtuSource *out_source, - gboolean * out_force); + gboolean *out_force); void nm_device_commit_mtu(NMDevice *self); @@ -177,26 +150,26 @@ void nm_device_commit_mtu(NMDevice *self); _types; \ })) -gboolean _nm_device_hash_check_invalid_keys(GHashTable * hash, - const char * setting_name, - GError ** error, +gboolean _nm_device_hash_check_invalid_keys(GHashTable *hash, + const char *setting_name, + GError **error, const char *const *whitelist); #define nm_device_hash_check_invalid_keys(hash, setting_name, error, ...) \ _nm_device_hash_check_invalid_keys(hash, setting_name, error, NM_MAKE_STRV(__VA_ARGS__)) gboolean nm_device_match_parent(NMDevice *device, const char *parent); -gboolean nm_device_match_parent_hwaddr(NMDevice * device, +gboolean nm_device_match_parent_hwaddr(NMDevice *device, NMConnection *connection, gboolean fail_if_no_hwaddr); /*****************************************************************************/ -void nm_device_auth_request(NMDevice * self, - GDBusMethodInvocation * context, - NMConnection * connection, - const char * permission, +void nm_device_auth_request(NMDevice *self, + GDBusMethodInvocation *context, + NMConnection *connection, + const char *permission, gboolean allow_interaction, - GCancellable * cancellable, + GCancellable *cancellable, NMManagerDeviceAuthRequestFunc callback, gpointer user_data); diff --git a/src/core/devices/nm-device-tun.c b/src/core/devices/nm-device-tun.c index 0ab08f65..b6c4f88b 100644 --- a/src/core/devices/nm-device-tun.c +++ b/src/core/devices/nm-device-tun.c @@ -13,7 +13,6 @@ #include "nm-act-request.h" #include "nm-device-private.h" -#include "nm-ip4-config.h" #include "libnm-platform/nm-platform.h" #include "nm-device-factory.h" #include "nm-setting-tun.h" @@ -56,7 +55,7 @@ G_DEFINE_TYPE(NMDeviceTun, nm_device_tun, NM_TYPE_DEVICE) static void update_properties_from_struct(NMDeviceTun *self, const NMPlatformLnkTun *props) { - NMDeviceTunPrivate * priv = NM_DEVICE_TUN_GET_PRIVATE(self); + NMDeviceTunPrivate *priv = NM_DEVICE_TUN_GET_PRIVATE(self); const NMPlatformLnkTun props0 = {}; if (!props) { @@ -129,11 +128,11 @@ link_changed(NMDevice *device, const NMPlatformLink *pllink) } static gboolean -complete_connection(NMDevice * device, - NMConnection * connection, - const char * specific_object, +complete_connection(NMDevice *device, + NMConnection *connection, + const char *specific_object, NMConnection *const *existing_connections, - GError ** error) + GError **error) { NMSettingTun *s_tun; @@ -162,12 +161,12 @@ complete_connection(NMDevice * device, static void update_connection(NMDevice *device, NMConnection *connection) { - NMDeviceTun * self = NM_DEVICE_TUN(device); + NMDeviceTun *self = NM_DEVICE_TUN(device); NMDeviceTunPrivate *priv = NM_DEVICE_TUN_GET_PRIVATE(self); - NMSettingTun * s_tun; + NMSettingTun *s_tun; NMSettingTunMode mode; char s_buf[100]; - const char * str; + const char *str; /* Note: since we read tun properties from sysctl for older kernels, * we don't get proper change notifications. Make sure that all our @@ -217,15 +216,15 @@ update_connection(NMDevice *device, NMConnection *connection) } static gboolean -create_and_realize(NMDevice * device, - NMConnection * connection, - NMDevice * parent, +create_and_realize(NMDevice *device, + NMConnection *connection, + NMDevice *parent, const NMPlatformLink **out_plink, - GError ** error) + GError **error) { - const char * iface = nm_device_get_iface(device); + const char *iface = nm_device_get_iface(device); NMPlatformLnkTun props = {}; - NMSettingTun * s_tun; + NMSettingTun *s_tun; gint64 owner; gint64 group; int r; @@ -287,10 +286,10 @@ _same_og(const char *str, gboolean og_valid, guint32 og_num) static gboolean check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error) { - NMDeviceTun * self = NM_DEVICE_TUN(device); + NMDeviceTun *self = NM_DEVICE_TUN(device); NMDeviceTunPrivate *priv = NM_DEVICE_TUN_GET_PRIVATE(self); NMSettingTunMode mode; - NMSettingTun * s_tun; + NMSettingTun *s_tun; if (!NM_DEVICE_CLASS(nm_device_tun_parent_class) ->check_connection_compatible(device, connection, error)) @@ -361,7 +360,7 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError * static NMActStageReturn act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) { - NMDeviceTun * self = NM_DEVICE_TUN(device); + NMDeviceTun *self = NM_DEVICE_TUN(device); NMDeviceTunPrivate *priv = NM_DEVICE_TUN_GET_PRIVATE(self); if (priv->props.type == IFF_TUN) { @@ -390,9 +389,9 @@ unrealize_notify(NMDevice *device) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMDeviceTun * self = NM_DEVICE_TUN(object); + NMDeviceTun *self = NM_DEVICE_TUN(object); NMDeviceTunPrivate *priv = NM_DEVICE_TUN_GET_PRIVATE(self); - const char * s; + const char *s; switch (prop_id) { case PROP_OWNER: @@ -458,9 +457,9 @@ static const NMDBusInterfaceInfoExtended interface_info_device_tun = { static void nm_device_tun_class_init(NMDeviceTunClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->get_property = get_property; @@ -531,11 +530,11 @@ nm_device_tun_class_init(NMDeviceTunClass *klass) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_TUN_DEVICE_FACTORY, NMTunDeviceFactory)) static NMDevice * -create_device(NMDeviceFactory * factory, - const char * iface, +create_device(NMDeviceFactory *factory, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore) + NMConnection *connection, + gboolean *out_ignore) { g_return_val_if_fail(!plink || plink->type == NM_LINK_TYPE_TUN, NULL); g_return_val_if_fail(!connection diff --git a/src/core/devices/nm-device-utils.c b/src/core/devices/nm-device-utils.c index 2a6ab04e..170922eb 100644 --- a/src/core/devices/nm-device-utils.c +++ b/src/core/devices/nm-device-utils.c @@ -151,10 +151,9 @@ NM_UTILS_LOOKUP_STR_DEFINE(nm_device_ip_state_to_string, NMDeviceIPState, NM_UTILS_LOOKUP_DEFAULT_WARN("unknown"), NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_IP_STATE_NONE, "none"), - NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_IP_STATE_WAIT, "wait"), - NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_IP_STATE_CONF, "conf"), - NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_IP_STATE_DONE, "done"), - NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_IP_STATE_FAIL, "fail"), ); + NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_IP_STATE_PENDING, "pending"), + NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_IP_STATE_READY, "done"), + NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_IP_STATE_FAILED, "fail"), ); /*****************************************************************************/ @@ -166,7 +165,7 @@ typedef struct { int addr_family; NMIPAddr address; gulong cancellable_id; - GTask * task; + GTask *task; NMDnsSystemdResolvedResolveHandle *resolved_handle; } ResolveAddrInfo; @@ -219,9 +218,9 @@ resolve_addr_complete(ResolveAddrInfo *info, char *hostname_take, GError *error_ static void resolve_addr_helper_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - ResolveAddrInfo *info = user_data; + ResolveAddrInfo *info = user_data; gs_free_error GError *error = NULL; - gs_free char * output = NULL; + gs_free char *output = NULL; output = nm_utils_spawn_helper_finish(result, &error); if (nm_utils_error_is_cancelled(error)) @@ -246,12 +245,12 @@ resolve_addr_spawn_helper(ResolveAddrInfo *info) } static void -resolve_addr_resolved_cb(NMDnsSystemdResolved * resolved, - NMDnsSystemdResolvedResolveHandle * handle, +resolve_addr_resolved_cb(NMDnsSystemdResolved *resolved, + NMDnsSystemdResolvedResolveHandle *handle, const NMDnsSystemdResolvedAddressResult *names, guint names_len, guint64 flags, - GError * error, + GError *error, gpointer user_data) { ResolveAddrInfo *info = user_data; @@ -301,7 +300,7 @@ static void resolve_addr_cancelled(GObject *object, gpointer user_data) { ResolveAddrInfo *info = user_data; - GError * error = NULL; + GError *error = NULL; nm_clear_g_signal_handler(g_task_get_cancellable(info->task), &info->cancellable_id); nm_clear_pointer(&info->resolved_handle, nm_dns_systemd_resolved_resolve_cancel); @@ -312,11 +311,11 @@ resolve_addr_cancelled(GObject *object, gpointer user_data) void nm_device_resolve_address(int addr_family, gconstpointer address, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer cb_data) { - ResolveAddrInfo * info; + ResolveAddrInfo *info; NMDnsSystemdResolved *resolved; info = g_new(ResolveAddrInfo, 1); diff --git a/src/core/devices/nm-device-utils.h b/src/core/devices/nm-device-utils.h index 7200b0ea..7b879c90 100644 --- a/src/core/devices/nm-device-utils.h +++ b/src/core/devices/nm-device-utils.h @@ -73,23 +73,20 @@ const char *nm_device_sys_iface_state_to_string(NMDeviceSysIfaceState sys_iface_ /*****************************************************************************/ -typedef enum { +typedef enum _nm_packed { NM_DEVICE_IP_STATE_NONE, - NM_DEVICE_IP_STATE_WAIT, - NM_DEVICE_IP_STATE_CONF, - NM_DEVICE_IP_STATE_DONE, - NM_DEVICE_IP_STATE_FAIL, + NM_DEVICE_IP_STATE_PENDING, + NM_DEVICE_IP_STATE_READY, + NM_DEVICE_IP_STATE_FAILED, } NMDeviceIPState; const char *nm_device_ip_state_to_string(NMDeviceIPState ip_state); /*****************************************************************************/ -/*****************************************************************************/ - void nm_device_resolve_address(int addr_family, gconstpointer address, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer cb_data); diff --git a/src/core/devices/nm-device-veth.c b/src/core/devices/nm-device-veth.c index 28831b75..8c95a293 100644 --- a/src/core/devices/nm-device-veth.c +++ b/src/core/devices/nm-device-veth.c @@ -75,13 +75,13 @@ link_changed(NMDevice *device, const NMPlatformLink *pllink) } static gboolean -create_and_realize(NMDevice * device, - NMConnection * connection, - NMDevice * parent, +create_and_realize(NMDevice *device, + NMConnection *connection, + NMDevice *parent, const NMPlatformLink **out_plink, - GError ** error) + GError **error) { - const char * iface = nm_device_get_iface(device); + const char *iface = nm_device_get_iface(device); NMSettingVeth *s_veth; int r; @@ -143,7 +143,7 @@ static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { NMDeviceVeth *self = NM_DEVICE_VETH(object); - NMDevice * peer; + NMDevice *peer; switch (prop_id) { case PROP_PEER: @@ -168,9 +168,9 @@ static const NMDBusInterfaceInfoExtended interface_info_device_veth = { static void nm_device_veth_class_init(NMDeviceVethClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->get_property = get_property; @@ -201,11 +201,11 @@ nm_device_veth_class_init(NMDeviceVethClass *klass) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_VETH_DEVICE_FACTORY, NMVethDeviceFactory)) static NMDevice * -create_device(NMDeviceFactory * factory, - const char * iface, +create_device(NMDeviceFactory *factory, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore) + NMConnection *connection, + gboolean *out_ignore) { return g_object_new(NM_TYPE_DEVICE_VETH, NM_DEVICE_IFACE, diff --git a/src/core/devices/nm-device-vlan.c b/src/core/devices/nm-device-vlan.c index d1e57411..0c101c70 100644 --- a/src/core/devices/nm-device-vlan.c +++ b/src/core/devices/nm-device-vlan.c @@ -15,7 +15,6 @@ #include "nm-device-private.h" #include "settings/nm-settings.h" #include "nm-act-request.h" -#include "nm-ip4-config.h" #include "libnm-platform/nm-platform.h" #include "nm-device-factory.h" #include "nm-manager.h" @@ -55,7 +54,7 @@ G_DEFINE_TYPE(NMDeviceVlan, nm_device_vlan, NM_TYPE_DEVICE) /*****************************************************************************/ static void -parent_state_changed(NMDevice * parent, +parent_state_changed(NMDevice *parent, NMDeviceState new_state, NMDeviceState old_state, NMDeviceStateReason reason, @@ -85,11 +84,11 @@ parent_mtu_maybe_changed(NMDevice *parent, GParamSpec *pspec, gpointer user_data static void parent_hwaddr_maybe_changed(NMDevice *parent, GParamSpec *pspec, gpointer user_data) { - NMDevice * device = NM_DEVICE(user_data); - NMDeviceVlan * self = NM_DEVICE_VLAN(device); - NMConnection * connection; - const char * new_mac, *old_mac; - NMSettingIPConfig *s_ip6; + NMDevice *device = NM_DEVICE(user_data); + NMDeviceVlan *self = NM_DEVICE_VLAN(device); + NMConnection *connection; + const char *old_mac; + const char *new_mac; /* Never touch assumed devices */ if (nm_device_sys_iface_state_is_external_or_assume(device)) @@ -113,13 +112,10 @@ parent_hwaddr_maybe_changed(NMDevice *parent, GParamSpec *pspec, gpointer user_d NM_PRINT_FMT_QUOTE_STRING(new_mac)); if (new_mac) { nm_device_hw_addr_set(device, new_mac, "vlan-parent", TRUE); - nm_device_arp_announce(device); /* When changing the hw address the interface is taken down, * removing the IPv6 configuration; reapply it. */ - s_ip6 = nm_connection_get_setting_ip6_config(connection); - if (s_ip6) - nm_device_reactivate_ip_config(device, AF_INET6, s_ip6, s_ip6); + nm_device_l3cfg_commit(device, NM_L3_CFG_COMMIT_TYPE_UPDATE, FALSE); } } @@ -130,7 +126,7 @@ parent_changed_notify(NMDevice *device, int new_ifindex, NMDevice *new_parent) { - NMDeviceVlan * self = NM_DEVICE_VLAN(device); + NMDeviceVlan *self = NM_DEVICE_VLAN(device); NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE(self); NM_DEVICE_CLASS(nm_device_vlan_parent_class) @@ -179,8 +175,8 @@ parent_changed_notify(NMDevice *device, static void update_properties(NMDevice *device) { - NMDeviceVlanPrivate * priv; - const NMPlatformLink * plink = NULL; + NMDeviceVlanPrivate *priv; + const NMPlatformLink *plink = NULL; const NMPlatformLnkVlan *plnk = NULL; int ifindex; int parent_ifindex = 0; @@ -219,15 +215,15 @@ link_changed(NMDevice *device, const NMPlatformLink *pllink) } static gboolean -create_and_realize(NMDevice * device, - NMConnection * connection, - NMDevice * parent, +create_and_realize(NMDevice *device, + NMConnection *connection, + NMDevice *parent, const NMPlatformLink **out_plink, - GError ** error) + GError **error) { NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE(device); - const char * iface = nm_device_get_iface(device); - NMSettingVlan * s_vlan; + const char *iface = nm_device_get_iface(device); + NMSettingVlan *s_vlan; int parent_ifindex; guint vlan_id; int r; @@ -295,7 +291,7 @@ create_and_realize(NMDevice * device, static void unrealize_notify(NMDevice *device) { - NMDeviceVlan * self = NM_DEVICE_VLAN(device); + NMDeviceVlan *self = NM_DEVICE_VLAN(device); NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE(self); NM_DEVICE_CLASS(nm_device_vlan_parent_class)->unrealize_notify(device); @@ -331,8 +327,8 @@ static gboolean check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error) { NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE(device); - NMSettingVlan * s_vlan; - const char * parent; + NMSettingVlan *s_vlan; + const char *parent; if (!NM_DEVICE_CLASS(nm_device_vlan_parent_class) ->check_connection_compatible(device, connection, error)) @@ -372,11 +368,11 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError * } static gboolean -check_connection_available(NMDevice * device, - NMConnection * connection, +check_connection_available(NMDevice *device, + NMConnection *connection, NMDeviceCheckConAvailableFlags flags, - const char * specific_object, - GError ** error) + const char *specific_object, + GError **error) { if (!nm_device_is_real(device)) return TRUE; @@ -386,11 +382,11 @@ check_connection_available(NMDevice * device, } static gboolean -complete_connection(NMDevice * device, - NMConnection * connection, - const char * specific_object, +complete_connection(NMDevice *device, + NMConnection *connection, + const char *specific_object, NMConnection *const *existing_connections, - GError ** error) + GError **error) { NMSettingVlan *s_vlan; @@ -432,11 +428,11 @@ complete_connection(NMDevice * device, static void update_connection(NMDevice *device, NMConnection *connection) { - NMDeviceVlanPrivate * priv = NM_DEVICE_VLAN_GET_PRIVATE(device); - NMSettingVlan * s_vlan = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_VLAN); + NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE(device); + NMSettingVlan *s_vlan = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_VLAN); int ifindex = nm_device_get_ifindex(device); const NMPlatformLink *plink; - const NMPObject * polnk; + const NMPObject *polnk; guint vlan_id; _NMVlanFlags vlan_flags; @@ -482,7 +478,7 @@ update_connection(NMDevice *device, NMConnection *connection) static NMActStageReturn act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) { - NMDevice * parent_device; + NMDevice *parent_device; NMSettingVlan *s_vlan; /* Change MAC address to parent's one if needed */ @@ -553,9 +549,9 @@ static const NMDBusInterfaceInfoExtended interface_info_device_vlan = { static void nm_device_vlan_class_init(NMDeviceVlanClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->get_property = get_property; @@ -599,11 +595,11 @@ nm_device_vlan_class_init(NMDeviceVlanClass *klass) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_VLAN_DEVICE_FACTORY, NMVlanDeviceFactory)) static NMDevice * -create_device(NMDeviceFactory * factory, - const char * iface, +create_device(NMDeviceFactory *factory, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore) + NMConnection *connection, + gboolean *out_ignore) { return g_object_new(NM_TYPE_DEVICE_VLAN, NM_DEVICE_IFACE, @@ -622,9 +618,9 @@ create_device(NMDeviceFactory * factory, static const char * get_connection_parent(NMDeviceFactory *factory, NMConnection *connection) { - NMSettingVlan * s_vlan; + NMSettingVlan *s_vlan; NMSettingWired *s_wired; - const char * parent = NULL; + const char *parent = NULL; g_return_val_if_fail(nm_connection_is_type(connection, NM_SETTING_VLAN_SETTING_NAME), NULL); @@ -646,7 +642,7 @@ get_connection_parent(NMDeviceFactory *factory, NMConnection *connection) static char * get_connection_iface(NMDeviceFactory *factory, NMConnection *connection, const char *parent_iface) { - const char * ifname; + const char *ifname; NMSettingVlan *s_vlan; g_return_val_if_fail(nm_connection_is_type(connection, NM_SETTING_VLAN_SETTING_NAME), NULL); diff --git a/src/core/devices/nm-device-vrf.c b/src/core/devices/nm-device-vrf.c index c752fa0a..ae80e1d4 100644 --- a/src/core/devices/nm-device-vrf.c +++ b/src/core/devices/nm-device-vrf.c @@ -44,7 +44,7 @@ static void do_update_properties(NMDeviceVrf *self, const NMPlatformLnkVrf *props) { NMDeviceVrfPrivate *priv = NM_DEVICE_VRF_GET_PRIVATE(self); - GObject * object = G_OBJECT(self); + GObject *object = G_OBJECT(self); NMPlatformLnkVrf props_null; if (!props) { @@ -72,7 +72,7 @@ do_update_properties(NMDeviceVrf *self, const NMPlatformLnkVrf *props) static void update_properties(NMDevice *device) { - NMDeviceVrf * self = NM_DEVICE_VRF(device); + NMDeviceVrf *self = NM_DEVICE_VRF(device); const NMPlatformLnkVrf *props; props = nm_platform_link_get_lnk_vrf(nm_device_get_platform(device), @@ -110,15 +110,15 @@ unrealize_notify(NMDevice *device) } static gboolean -create_and_realize(NMDevice * device, - NMConnection * connection, - NMDevice * parent, +create_and_realize(NMDevice *device, + NMConnection *connection, + NMDevice *parent, const NMPlatformLink **out_plink, - GError ** error) + GError **error) { - const char * iface = nm_device_get_iface(device); + const char *iface = nm_device_get_iface(device); NMPlatformLnkVrf props = {}; - NMSettingVrf * s_vrf; + NMSettingVrf *s_vrf; int r; s_vrf = _nm_connection_get_setting(connection, NM_TYPE_SETTING_VRF); @@ -145,7 +145,7 @@ static gboolean check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error) { NMDeviceVrfPrivate *priv = NM_DEVICE_VRF_GET_PRIVATE(device); - NMSettingVrf * s_vrf; + NMSettingVrf *s_vrf; if (!NM_DEVICE_CLASS(nm_device_vrf_parent_class) ->check_connection_compatible(device, connection, error)) @@ -166,11 +166,11 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError * } static gboolean -complete_connection(NMDevice * device, - NMConnection * connection, - const char * specific_object, +complete_connection(NMDevice *device, + NMConnection *connection, + const char *specific_object, NMConnection *const *existing_connections, - GError ** error) + GError **error) { NMSettingVrf *s_vrf; @@ -200,7 +200,7 @@ static void update_connection(NMDevice *device, NMConnection *connection) { NMDeviceVrfPrivate *priv = NM_DEVICE_VRF_GET_PRIVATE(device); - NMSettingVrf * s_vrf = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_VRF); + NMSettingVrf *s_vrf = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_VRF); if (priv->props.table != nm_setting_vrf_get_table(s_vrf)) g_object_set(G_OBJECT(s_vrf), NM_SETTING_VRF_TABLE, priv->props.table, NULL); @@ -211,7 +211,7 @@ enslave_slave(NMDevice *device, NMDevice *slave, NMConnection *connection, gbool { NMDeviceVrf *self = NM_DEVICE_VRF(device); gboolean success = TRUE; - const char * slave_iface = nm_device_get_ip_iface(slave); + const char *slave_iface = nm_device_get_ip_iface(slave); nm_device_master_check_slave_physical_port(device, slave, LOGD_DEVICE); @@ -303,9 +303,9 @@ static const NMDBusInterfaceInfoExtended interface_info_device_vrf = { static void nm_device_vrf_class_init(NMDeviceVrfClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->get_property = get_property; @@ -344,11 +344,11 @@ nm_device_vrf_class_init(NMDeviceVrfClass *klass) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_VRF_DEVICE_FACTORY, NMVrfDeviceFactory)) static NMDevice * -create_device(NMDeviceFactory * factory, - const char * iface, +create_device(NMDeviceFactory *factory, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore) + NMConnection *connection, + gboolean *out_ignore) { return g_object_new(NM_TYPE_DEVICE_VRF, NM_DEVICE_IFACE, diff --git a/src/core/devices/nm-device-vxlan.c b/src/core/devices/nm-device-vxlan.c index fcd6950b..bf7c94c0 100644 --- a/src/core/devices/nm-device-vxlan.c +++ b/src/core/devices/nm-device-vxlan.c @@ -16,7 +16,6 @@ #include "nm-setting-wired.h" #include "settings/nm-settings.h" #include "nm-act-request.h" -#include "nm-ip4-config.h" #include "libnm-core-aux-intern/nm-libnm-core-utils.h" #include "libnm-core-intern/nm-core-internal.h" @@ -65,9 +64,9 @@ G_DEFINE_TYPE(NMDeviceVxlan, nm_device_vxlan, NM_TYPE_DEVICE) static void update_properties(NMDevice *device) { - NMDeviceVxlan * self = NM_DEVICE_VXLAN(device); - NMDeviceVxlanPrivate * priv = NM_DEVICE_VXLAN_GET_PRIVATE(self); - GObject * object = G_OBJECT(device); + NMDeviceVxlan *self = NM_DEVICE_VXLAN(device); + NMDeviceVxlanPrivate *priv = NM_DEVICE_VXLAN_GET_PRIVATE(self); + GObject *object = G_OBJECT(device); const NMPlatformLnkVxlan *props; props = nm_platform_link_get_lnk_vxlan(nm_device_get_platform(device), @@ -140,7 +139,7 @@ link_changed(NMDevice *device, const NMPlatformLink *pllink) static void unrealize_notify(NMDevice *device) { - NMDeviceVxlan * self = NM_DEVICE_VXLAN(device); + NMDeviceVxlan *self = NM_DEVICE_VXLAN(device); NMDeviceVxlanPrivate *priv = NM_DEVICE_VXLAN_GET_PRIVATE(self); guint i; @@ -153,16 +152,16 @@ unrealize_notify(NMDevice *device) } static gboolean -create_and_realize(NMDevice * device, - NMConnection * connection, - NMDevice * parent, +create_and_realize(NMDevice *device, + NMConnection *connection, + NMDevice *parent, const NMPlatformLink **out_plink, - GError ** error) + GError **error) { - const char * iface = nm_device_get_iface(device); + const char *iface = nm_device_get_iface(device); NMPlatformLnkVxlan props = {}; - NMSettingVxlan * s_vxlan; - const char * str; + NMSettingVxlan *s_vxlan; + const char *str; int r; s_vxlan = nm_connection_get_setting_vxlan(connection); @@ -242,8 +241,8 @@ static gboolean check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error) { NMDeviceVxlanPrivate *priv = NM_DEVICE_VXLAN_GET_PRIVATE(device); - NMSettingVxlan * s_vxlan; - const char * parent; + NMSettingVxlan *s_vxlan; + const char *parent; if (!NM_DEVICE_CLASS(nm_device_vxlan_parent_class) ->check_connection_compatible(device, connection, error)) @@ -367,11 +366,11 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError * } static gboolean -complete_connection(NMDevice * device, - NMConnection * connection, - const char * specific_object, +complete_connection(NMDevice *device, + NMConnection *connection, + const char *specific_object, NMConnection *const *existing_connections, - GError ** error) + GError **error) { NMSettingVxlan *s_vxlan; @@ -605,9 +604,9 @@ static const NMDBusInterfaceInfoExtended interface_info_device_vxlan = { static void nm_device_vxlan_class_init(NMDeviceVxlanClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->get_property = get_property; @@ -745,11 +744,11 @@ nm_device_vxlan_class_init(NMDeviceVxlanClass *klass) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_VXLAN_DEVICE_FACTORY, NMVxlanDeviceFactory)) static NMDevice * -create_device(NMDeviceFactory * factory, - const char * iface, +create_device(NMDeviceFactory *factory, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore) + NMConnection *connection, + gboolean *out_ignore) { return g_object_new(NM_TYPE_DEVICE_VXLAN, NM_DEVICE_IFACE, @@ -779,7 +778,7 @@ get_connection_parent(NMDeviceFactory *factory, NMConnection *connection) static char * get_connection_iface(NMDeviceFactory *factory, NMConnection *connection, const char *parent_iface) { - const char * ifname; + const char *ifname; NMSettingVxlan *s_vxlan; g_return_val_if_fail(nm_connection_is_type(connection, NM_SETTING_VXLAN_SETTING_NAME), NULL); diff --git a/src/core/devices/nm-device-wireguard.c b/src/core/devices/nm-device-wireguard.c index f129478f..bdb96cb2 100644 --- a/src/core/devices/nm-device-wireguard.c +++ b/src/core/devices/nm-device-wireguard.c @@ -12,12 +12,13 @@ #include "nm-setting-wireguard.h" #include "libnm-core-aux-intern/nm-libnm-core-utils.h" +#include "nm-l3-config-data.h" #include "libnm-core-intern/nm-core-internal.h" #include "libnm-glib-aux/nm-secret-utils.h" #include "nm-device-private.h" #include "libnm-platform/nm-platform.h" #include "libnm-platform/nmp-object.h" -#include "libnm-platform/nmp-rules-manager.h" +#include "libnm-platform/nmp-route-manager.h" #include "nm-device-factory.h" #include "nm-active-connection.h" #include "nm-act-request.h" @@ -178,9 +179,9 @@ static NM_UTILS_LOOKUP_STR_DEFINE(_link_config_mode_to_string, static void _auto_default_route_get_enabled(NMSettingWireGuard *s_wg, - NMConnection * connection, - gboolean * out_enabled_v4, - gboolean * out_enabled_v6) + NMConnection *connection, + gboolean *out_enabled_v4, + gboolean *out_enabled_v6) { NMTernary enabled_v4; NMTernary enabled_v6; @@ -326,7 +327,7 @@ static void _auto_default_route_init(NMDeviceWireGuard *self) { NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE(self); - NMConnection * connection; + NMConnection *connection; gboolean enabled_v4 = FALSE; gboolean enabled_v6 = FALSE; gboolean refreshing_only; @@ -379,12 +380,12 @@ _auto_default_route_init(NMDeviceWireGuard *self) static GPtrArray * get_extra_rules(NMDevice *device) { - NMDeviceWireGuard * self = NM_DEVICE_WIREGUARD(device); - NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE(self); + NMDeviceWireGuard *self = NM_DEVICE_WIREGUARD(device); + NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE(self); gs_unref_ptrarray GPtrArray *extra_rules = NULL; guint32 priority = 0; int is_ipv4; - NMConnection * connection; + NMConnection *connection; _auto_default_route_init(self); @@ -456,7 +457,7 @@ get_extra_rules(NMDevice *device) static guint32 coerce_route_table(NMDevice *device, int addr_family, guint32 route_table, gboolean is_user_config) { - NMDeviceWireGuard * self = NM_DEVICE_WIREGUARD(device); + NMDeviceWireGuard *self = NM_DEVICE_WIREGUARD(device); NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE(self); gboolean auto_default_route_enabled; @@ -580,7 +581,7 @@ static PeerData * _peers_add(NMDeviceWireGuard *self, NMWireGuardPeer *peer) { NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE(self); - PeerData * peer_data; + PeerData *peer_data; nm_assert(peer); nm_assert(nm_wireguard_peer_is_sealed(peer)); @@ -605,9 +606,9 @@ _peers_add(NMDeviceWireGuard *self, NMWireGuardPeer *peer) static gboolean _peers_resolve_retry_timeout(gpointer user_data) { - NMDeviceWireGuard * self = user_data; + NMDeviceWireGuard *self = user_data; NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE(self); - PeerData * peer_data; + PeerData *peer_data; gint64 now; gint64 next; @@ -683,7 +684,7 @@ _peers_resolve_retry_reschedule(NMDeviceWireGuard *self, gint64 new_next_try_at_ static void _peers_resolve_retry_reschedule_for_peer(NMDeviceWireGuard *self, - PeerData * peer_data, + PeerData *peer_data, gint64 retry_in_msec) { nm_assert(retry_in_msec >= 0); @@ -725,16 +726,16 @@ _peers_retry_in_msec(PeerData *peer_data, gboolean after_failure) static void _peers_resolve_cb(GObject *source_object, GAsyncResult *res, gpointer user_data) { - NMDeviceWireGuard * self; + NMDeviceWireGuard *self; NMDeviceWireGuardPrivate *priv; - PeerData * peer_data; - gs_free_error GError *resolv_error = NULL; - GList * list; - gboolean changed; - NMSockAddrUnion sockaddr; - gint64 retry_in_msec; - char s_sockaddr[100]; - char s_retry[100]; + PeerData *peer_data; + gs_free_error GError *resolv_error = NULL; + GList *list; + gboolean changed; + NMSockAddrUnion sockaddr; + gint64 retry_in_msec; + char s_sockaddr[100]; + char s_retry[100]; list = g_resolver_lookup_by_name_finish(G_RESOLVER(source_object), res, &resolv_error); @@ -782,7 +783,7 @@ _peers_resolve_cb(GObject *source_object, GAsyncResult *res, gpointer user_data) GList *iter; for (iter = list; iter; iter = iter->next) { - GInetAddress * a = iter->data; + GInetAddress *a = iter->data; NMSockAddrUnion sockaddr_tmp; NMSockAddrUnion *s; @@ -874,9 +875,9 @@ _peers_resolve_cb(GObject *source_object, GAsyncResult *res, gpointer user_data) static void _peers_resolve_start(NMDeviceWireGuard *self, PeerData *peer_data) { - NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE(self); + NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE(self); gs_unref_object GResolver *resolver = NULL; - const char * host; + const char *host; resolver = g_resolver_get_default(); @@ -913,7 +914,7 @@ static void _peers_resolve_reresolve_all(NMDeviceWireGuard *self) { NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE(self); - PeerData * peer_data; + PeerData *peer_data; c_list_for_each_entry (peer_data, &priv->lst_peers_head, lst_peers) { if (peer_data->ep_resolv.cancellable) { @@ -931,13 +932,13 @@ _peers_resolve_reresolve_all(NMDeviceWireGuard *self) static gboolean _peers_update(NMDeviceWireGuard *self, - PeerData * peer_data, - NMWireGuardPeer * peer, + PeerData *peer_data, + NMWireGuardPeer *peer, gboolean force_update) { nm_auto_unref_wgpeer NMWireGuardPeer *old_peer = NULL; - NMSockAddrEndpoint * old_endpoint; - NMSockAddrEndpoint * endpoint; + NMSockAddrEndpoint *old_endpoint; + NMSockAddrEndpoint *endpoint; gboolean endpoint_changed = FALSE; gboolean changed; NMSockAddrUnion sockaddr; @@ -1018,7 +1019,7 @@ static void _peers_remove_all(NMDeviceWireGuard *self) { NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE(self); - PeerData * peer_data; + PeerData *peer_data; while ((peer_data = c_list_first_entry(&priv->lst_peers_head, PeerData, lst_peers))) _peers_remove(self, peer_data); @@ -1028,8 +1029,8 @@ static void _peers_update_all(NMDeviceWireGuard *self, NMSettingWireGuard *s_wg, gboolean *out_peers_removed) { NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE(self); - PeerData * peer_data_safe; - PeerData * peer_data; + PeerData *peer_data_safe; + PeerData *peer_data; guint i, n; gboolean peers_removed = FALSE; @@ -1061,22 +1062,22 @@ _peers_update_all(NMDeviceWireGuard *self, NMSettingWireGuard *s_wg, gboolean *o } static void -_peers_get_platform_list(NMDeviceWireGuardPrivate * priv, +_peers_get_platform_list(NMDeviceWireGuardPrivate *priv, LinkConfigMode config_mode, - NMPWireGuardPeer ** out_peers, + NMPWireGuardPeer **out_peers, NMPlatformWireGuardChangePeerFlags **out_peer_flags, - guint * out_len, - GArray ** out_allowed_ips_data) + guint *out_len, + GArray **out_allowed_ips_data) { - gs_free NMPWireGuardPeer *plpeers = NULL; + gs_free NMPWireGuardPeer *plpeers = NULL; gs_free NMPlatformWireGuardChangePeerFlags *plpeer_flags = NULL; - gs_unref_array GArray *allowed_ips = NULL; - PeerData * peer_data; - guint i_good; - guint n_aip; - guint i_aip; - guint len; - guint i; + gs_unref_array GArray *allowed_ips = NULL; + PeerData *peer_data; + guint i_good; + guint n_aip; + guint i_aip; + guint len; + guint i; nm_assert(out_peers && !*out_peers); nm_assert(out_peer_flags && !*out_peer_flags); @@ -1096,7 +1097,7 @@ _peers_get_platform_list(NMDeviceWireGuardPrivate * priv, i_good = 0; c_list_for_each_entry (peer_data, &priv->lst_peers_head, lst_peers) { NMPlatformWireGuardChangePeerFlags *plf = &plpeer_flags[i_good]; - NMPWireGuardPeer * plp = &plpeers[i_good]; + NMPWireGuardPeer *plp = &plpeers[i_good]; NMSettingSecretFlags psk_secret_flags; if (!nm_utils_base64secret_decode(nm_wireguard_peer_get_public_key(peer_data->peer), @@ -1211,9 +1212,9 @@ skip: static void update_properties(NMDevice *device) { - NMDeviceWireGuard * self; - NMDeviceWireGuardPrivate * priv; - const NMPlatformLink * plink; + NMDeviceWireGuard *self; + NMDeviceWireGuardPrivate *priv; + const NMPlatformLink *plink; const NMPlatformLnkWireGuard *props = NULL; int ifindex; @@ -1273,11 +1274,11 @@ get_generic_capabilities(NMDevice *dev) /*****************************************************************************/ static gboolean -create_and_realize(NMDevice * device, - NMConnection * connection, - NMDevice * parent, +create_and_realize(NMDevice *device, + NMConnection *connection, + NMDevice *parent, const NMPlatformLink **out_plink, - GError ** error) + GError **error) { const char *iface = nm_device_get_iface(device); int r; @@ -1312,14 +1313,14 @@ _secrets_cancel(NMDeviceWireGuard *self) } static void -_secrets_cb(NMActRequest * req, +_secrets_cb(NMActRequest *req, NMActRequestGetSecretsCallId *call_id, - NMSettingsConnection * connection, - GError * error, + NMSettingsConnection *connection, + GError *error, gpointer user_data) { - NMDeviceWireGuard * self = NM_DEVICE_WIREGUARD(user_data); - NMDevice * device = NM_DEVICE(self); + NMDeviceWireGuard *self = NM_DEVICE_WIREGUARD(user_data); + NMDevice *device = NM_DEVICE(self); NMDeviceWireGuardPrivate *priv; g_return_if_fail(NM_IS_DEVICE_WIREGUARD(self)); @@ -1348,13 +1349,13 @@ _secrets_cb(NMActRequest * req, } static void -_secrets_get_secrets(NMDeviceWireGuard * self, - const char * setting_name, +_secrets_get_secrets(NMDeviceWireGuard *self, + const char *setting_name, NMSecretAgentGetSecretsFlags flags, - const char *const * hints) + const char *const *hints) { NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE(self); - NMActRequest * req; + NMActRequest *req; _secrets_cancel(self); @@ -1369,8 +1370,8 @@ _secrets_get_secrets(NMDeviceWireGuard * self, static NMActStageReturn _secrets_handle_auth_or_fail(NMDeviceWireGuard *self, NMActRequest *req, gboolean new_secrets) { - NMConnection * applied_connection; - const char * setting_name; + NMConnection *applied_connection; + const char *setting_name; gs_unref_ptrarray GPtrArray *hints = NULL; if (!nm_device_auth_retries_try_next(NM_DEVICE(self))) @@ -1415,22 +1416,22 @@ _dns_config_changed(NMDnsManager *dns_manager, NMDeviceWireGuard *self) /*****************************************************************************/ static NMActStageReturn -link_config(NMDeviceWireGuard * self, - const char * reason, +link_config(NMDeviceWireGuard *self, + const char *reason, LinkConfigMode config_mode, NMDeviceStateReason *out_failure_reason) { - NMDeviceWireGuardPrivate * priv = NM_DEVICE_WIREGUARD_GET_PRIVATE(self); - nm_auto_bzero_secret_ptr NMSecretPtr wg_lnk_clear_private_key = NM_SECRET_PTR_INIT(); - NMSettingWireGuard * s_wg; - NMConnection * connection; - NMActStageReturn ret; - gs_unref_array GArray *allowed_ips_data = NULL; - NMPlatformLnkWireGuard wg_lnk; - gs_free NMPWireGuardPeer *plpeers = NULL; + NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE(self); + nm_auto_bzero_secret_ptr NMSecretPtr wg_lnk_clear_private_key = NM_SECRET_PTR_INIT(); + NMSettingWireGuard *s_wg; + NMConnection *connection; + NMActStageReturn ret; + gs_unref_array GArray *allowed_ips_data = NULL; + NMPlatformLnkWireGuard wg_lnk; + gs_free NMPWireGuardPeer *plpeers = NULL; gs_free NMPlatformWireGuardChangePeerFlags *plpeer_flags = NULL; guint plpeers_len = 0; - const char * setting_name; + const char *setting_name; gboolean peers_removed; NMPlatformWireGuardChangeFlags wg_change_flags; int ifindex; @@ -1583,7 +1584,7 @@ link_config_delayed_resolver_cb(gpointer user_data) static NMActStageReturn act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) { - NMDeviceWireGuard * self = NM_DEVICE_WIREGUARD(device); + NMDeviceWireGuard *self = NM_DEVICE_WIREGUARD(device); NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE(self); NMDeviceSysIfaceState sys_iface_state; NMDeviceStateReason failure_reason; @@ -1625,19 +1626,19 @@ act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) return ret; } -static NMIPConfig * +static const NML3ConfigData * _get_dev2_ip_config(NMDeviceWireGuard *self, int addr_family) { - NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE(self); - gs_unref_object NMIPConfig *ip_config = NULL; - NMConnection * connection; - NMSettingWireGuard * s_wg; - guint n_peers; - guint i; - int ip_ifindex; - guint32 route_metric; - guint32 route_table_coerced; - gboolean auto_default_route_enabled; + NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE(self); + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + NMConnection *connection; + NMSettingWireGuard *s_wg; + guint n_peers; + guint i; + int ip_ifindex; + guint32 route_metric; + guint32 route_table_coerced; + gboolean auto_default_route_enabled; _auto_default_route_init(self); @@ -1693,7 +1694,7 @@ _get_dev2_ip_config(NMDeviceWireGuard *self, int addr_family) for (j = 0; j < n_aips; j++) { NMPlatformIPXRoute rt; NMIPAddr addrbin; - const char * aip; + const char *aip; gboolean valid; int prefix; guint32 rtable_coerced; @@ -1715,11 +1716,10 @@ _get_dev2_ip_config(NMDeviceWireGuard *self, int addr_family) continue; } - if (!ip_config) { - ip_config = nm_device_ip_config_new(NM_DEVICE(self), addr_family); - nm_ip_config_set_config_flags(ip_config, - NM_IP_CONFIG_FLAGS_IGNORE_MERGE_NO_DEFAULT_ROUTES, - 0); + if (!l3cd) { + l3cd = nm_device_create_l3_config_data(NM_DEVICE(self), NM_IP_CONFIG_SOURCE_USER); + nm_l3_config_data_set_flags(l3cd, + NM_L3_CONFIG_DAT_FLAGS_IGNORE_MERGE_NO_DEFAULT_ROUTES); } nm_utils_ipx_address_clear_host_address(addr_family, &addrbin, NULL, prefix); @@ -1754,27 +1754,23 @@ _get_dev2_ip_config(NMDeviceWireGuard *self, int addr_family) }; } - nm_ip_config_add_route(ip_config, &rt.rx, NULL); + nm_l3_config_data_add_route(l3cd, addr_family, NULL, &rt.rx); } } - return g_steal_pointer(&ip_config); + if (!l3cd) + return NULL; + + return nm_l3_config_data_seal(g_steal_pointer(&l3cd)); } -static NMActStageReturn -act_stage3_ip_config_start(NMDevice * device, - int addr_family, - gpointer * out_config, - NMDeviceStateReason *out_failure_reason) +static void +act_stage3_ip_config(NMDevice *device, int addr_family) { - gs_unref_object NMIPConfig *ip_config = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; - ip_config = _get_dev2_ip_config(NM_DEVICE_WIREGUARD(device), addr_family); - - nm_device_set_dev2_ip_config(device, addr_family, ip_config); - - return NM_DEVICE_CLASS(nm_device_wireguard_parent_class) - ->act_stage3_ip_config_start(device, addr_family, out_config, out_failure_reason); + l3cd = _get_dev2_ip_config(NM_DEVICE_WIREGUARD(device), addr_family); + nm_device_devip_set_state(device, addr_family, NM_DEVICE_IP_STATE_READY, l3cd); } static guint32 @@ -1819,7 +1815,7 @@ _device_cleanup(NMDeviceWireGuard *self) } static void -device_state_changed(NMDevice * device, +device_state_changed(NMDevice *device, NMDeviceState new_state, NMDeviceState old_state, NMDeviceStateReason reason) @@ -1833,12 +1829,12 @@ device_state_changed(NMDevice * device, /*****************************************************************************/ static gboolean -can_reapply_change(NMDevice * device, +can_reapply_change(NMDevice *device, const char *setting_name, - NMSetting * s_old, - NMSetting * s_new, + NMSetting *s_old, + NMSetting *s_new, GHashTable *diffs, - GError ** error) + GError **error) { if (nm_streq(setting_name, NM_SETTING_WIREGUARD_SETTING_NAME)) { /* Most, but not all WireGuard settings can be reapplied. Whitelist. @@ -1864,11 +1860,9 @@ can_reapply_change(NMDevice * device, static void reapply_connection(NMDevice *device, NMConnection *con_old, NMConnection *con_new) { - NMDeviceWireGuard * self = NM_DEVICE_WIREGUARD(device); - NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE(self); - gs_unref_object NMIPConfig *ip4_config = NULL; - gs_unref_object NMIPConfig *ip6_config = NULL; - NMDeviceState state = nm_device_get_state(device); + NMDeviceWireGuard *self = NM_DEVICE_WIREGUARD(device); + NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE(self); + NMDeviceState state = nm_device_get_state(device); NM_DEVICE_CLASS(nm_device_wireguard_parent_class)->reapply_connection(device, con_old, con_new); @@ -1878,11 +1872,14 @@ reapply_connection(NMDevice *device, NMConnection *con_old, NMConnection *con_ne } if (state >= NM_DEVICE_STATE_IP_CONFIG) { - ip4_config = _get_dev2_ip_config(self, AF_INET); - ip6_config = _get_dev2_ip_config(self, AF_INET6); + nm_auto_unref_l3cd const NML3ConfigData *l3cd_4 = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd_6 = NULL; + + l3cd_4 = _get_dev2_ip_config(self, AF_INET); + l3cd_6 = _get_dev2_ip_config(self, AF_INET6); - nm_device_set_dev2_ip_config(device, AF_INET, ip4_config); - nm_device_set_dev2_ip_config(device, AF_INET6, ip6_config); + nm_device_devip_set_state(device, AF_INET, NM_DEVICE_IP_STATE_READY, l3cd_4); + nm_device_devip_set_state(device, AF_INET6, NM_DEVICE_IP_STATE_READY, l3cd_6); } } @@ -1893,7 +1890,7 @@ update_connection(NMDevice *device, NMConnection *connection) { NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE(device); NMSettingWireGuard *s_wg = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_WIREGUARD); - const NMPObject * obj_wg; + const NMPObject *obj_wg; const NMPObjectLnkWireGuard *olnk_wg; guint i; @@ -1914,7 +1911,7 @@ update_connection(NMDevice *device, NMConnection *connection) for (i = 0; i < olnk_wg->peers_len; i++) { nm_auto_unref_wgpeer NMWireGuardPeer *peer = NULL; - const NMPWireGuardPeer * ppeer = &olnk_wg->peers[i]; + const NMPWireGuardPeer *ppeer = &olnk_wg->peers[i]; peer = nm_wireguard_peer_new(); @@ -1929,7 +1926,7 @@ update_connection(NMDevice *device, NMConnection *connection) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMDeviceWireGuard * self = NM_DEVICE_WIREGUARD(object); + NMDeviceWireGuard *self = NM_DEVICE_WIREGUARD(object); NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE(self); switch (prop_id) { @@ -1974,7 +1971,7 @@ dispose(GObject *object) static void finalize(GObject *object) { - NMDeviceWireGuard * self = NM_DEVICE_WIREGUARD(object); + NMDeviceWireGuard *self = NM_DEVICE_WIREGUARD(object); NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE(self); nm_explicit_bzero(priv->lnk_curr.private_key, sizeof(priv->lnk_curr.private_key)); @@ -2007,9 +2004,9 @@ static const NMDBusInterfaceInfoExtended interface_info_device_wireguard = { static void nm_device_wireguard_class_init(NMDeviceWireGuardClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->get_property = get_property; object_class->dispose = dispose; @@ -2025,7 +2022,7 @@ nm_device_wireguard_class_init(NMDeviceWireGuardClass *klass) device_class->create_and_realize = create_and_realize; device_class->act_stage2_config = act_stage2_config; device_class->act_stage2_config_also_for_external_or_assume = TRUE; - device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; + device_class->act_stage3_ip_config = act_stage3_ip_config; device_class->get_generic_capabilities = get_generic_capabilities; device_class->link_changed = link_changed; device_class->update_connection = update_connection; @@ -2069,11 +2066,11 @@ nm_device_wireguard_class_init(NMDeviceWireGuardClass *klass) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_WIREGUARD_DEVICE_FACTORY, NMWireGuardDeviceFactory)) static NMDevice * -create_device(NMDeviceFactory * factory, - const char * iface, +create_device(NMDeviceFactory *factory, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore) + NMConnection *connection, + gboolean *out_ignore) { return g_object_new(NM_TYPE_DEVICE_WIREGUARD, NM_DEVICE_IFACE, diff --git a/src/core/devices/nm-device-wpan.c b/src/core/devices/nm-device-wpan.c index 9bc43a85..f7b712ea 100644 --- a/src/core/devices/nm-device-wpan.c +++ b/src/core/devices/nm-device-wpan.c @@ -14,7 +14,6 @@ #include "nm-act-request.h" #include "nm-device-private.h" -#include "nm-ip4-config.h" #include "libnm-platform/nm-platform.h" #include "nm-device-factory.h" #include "nm-setting-wpan.h" @@ -39,11 +38,11 @@ G_DEFINE_TYPE(NMDeviceWpan, nm_device_wpan, NM_TYPE_DEVICE) /*****************************************************************************/ static gboolean -complete_connection(NMDevice * device, - NMConnection * connection, - const char * specific_object, +complete_connection(NMDevice *device, + NMConnection *connection, + const char *specific_object, NMConnection *const *existing_connections, - GError ** error) + GError **error) { NMSettingWpan *s_wpan; @@ -79,7 +78,7 @@ static gboolean check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error) { NMSettingWpan *s_wpan; - const char * mac, *hw_addr; + const char *mac, *hw_addr; if (!NM_DEVICE_CLASS(nm_device_wpan_parent_class) ->check_connection_compatible(device, connection, error)) @@ -104,17 +103,17 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError * static NMActStageReturn act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) { - NMDeviceWpan * self = NM_DEVICE_WPAN(device); - NMSettingWpan * s_wpan; - NMPlatform * platform; + NMDeviceWpan *self = NM_DEVICE_WPAN(device); + NMSettingWpan *s_wpan; + NMPlatform *platform; guint16 pan_id; guint16 short_address; gint16 page, channel; int ifindex; - const guint8 * hwaddr; + const guint8 *hwaddr; gsize hwaddr_len = 0; const NMPlatformLink *lowpan_plink; - NMDevice * lowpan_device = NULL; + NMDevice *lowpan_device = NULL; NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; platform = nm_device_get_platform(device); @@ -203,7 +202,7 @@ static const NMDBusInterfaceInfoExtended interface_info_device_wpan = { static void nm_device_wpan_class_init(NMDeviceWpanClass *klass) { - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS(&interface_info_device_wpan); @@ -225,11 +224,11 @@ nm_device_wpan_class_init(NMDeviceWpanClass *klass) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_WPAN_DEVICE_FACTORY, NMWpanDeviceFactory)) static NMDevice * -create_device(NMDeviceFactory * factory, - const char * iface, +create_device(NMDeviceFactory *factory, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore) + NMConnection *connection, + gboolean *out_ignore) { return g_object_new(NM_TYPE_DEVICE_WPAN, NM_DEVICE_IFACE, diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index ea1b9647..696c0df8 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -34,22 +34,23 @@ #include "nm-device-private.h" #include "nm-l3cfg.h" #include "nm-l3-config-data.h" +#include "nm-l3-ipv4ll.h" +#include "nm-l3-ipv6ll.h" #include "NetworkManagerUtils.h" #include "nm-manager.h" #include "libnm-platform/nm-platform.h" #include "libnm-platform/nm-platform-utils.h" #include "libnm-platform/nmp-object.h" -#include "libnm-platform/nmp-rules-manager.h" +#include "libnm-platform/nmp-route-manager.h" #include "ndisc/nm-ndisc.h" #include "ndisc/nm-lndp-ndisc.h" + #include "dhcp/nm-dhcp-manager.h" #include "dhcp/nm-dhcp-utils.h" #include "nm-act-request.h" -#include "nm-proxy-config.h" -#include "nm-ip4-config.h" -#include "nm-ip6-config.h" #include "nm-pacrunner-manager.h" #include "dnsmasq/nm-dnsmasq-manager.h" +#include "nm-ip-config.h" #include "nm-dhcp-config.h" #include "nm-rfkill-manager.h" #include "nm-firewall-utils.h" @@ -66,7 +67,6 @@ #include "nm-config.h" #include "c-list/src/c-list.h" #include "dns/nm-dns-manager.h" -#include "nm-acd-manager.h" #include "libnm-core-intern/nm-core-internal.h" #include "libnm-systemd-core/nm-sd.h" #include "nm-lldp-listener.h" @@ -86,19 +86,7 @@ #define DEFAULT_AUTOCONNECT TRUE -static guint32 -dhcp_grace_period_from_timeout(guint32 timeout) -{ -#define DHCP_GRACE_PERIOD_MULTIPLIER 2U - - nm_assert(timeout > 0); - nm_assert(timeout < G_MAXINT32); - - if (timeout < G_MAXUINT32 / DHCP_GRACE_PERIOD_MULTIPLIER) - return timeout * DHCP_GRACE_PERIOD_MULTIPLIER; - - return G_MAXUINT32; -} +#define GRACE_PERIOD_MULTIPLIER 2U #define CARRIER_WAIT_TIME_MS 6000 #define CARRIER_WAIT_TIME_AFTER_MTU_MS 10000 @@ -117,6 +105,13 @@ typedef enum { CLEANUP_TYPE_DECONFIGURE, } CleanupType; +typedef enum _nm_packed { + ADDR_METHOD_STATE_DISABLED, + ADDR_METHOD_STATE_PENDING, + ADDR_METHOD_STATE_GOOD, + ADDR_METHOD_STATE_FAILED, +} AddrMethodState; + typedef struct { CList lst_slave; NMDevice *slave; @@ -131,36 +126,72 @@ typedef struct { } DeleteOnDeactivateData; typedef struct { - NMDevice * device; - GCancellable * cancellable; + NMDevice *device; + GCancellable *cancellable; NMPlatformAsyncCallback callback; gpointer callback_data; guint num_vfs; NMOptionBool autoprobe; } SriovOp; -typedef void (*AcdCallback)(NMDevice *, NMIP4Config **, gboolean); - typedef enum { /* The various NML3ConfigData types that we track explicitly. Note that * their relative order matters: higher numbers in this enum means more - * important (and during merge overwrites other settings). */ + * important (and during merge overwrites other settings). This is passed + * as priority to nm_l3cfg_add_config(). */ + L3_CONFIG_DATA_TYPE_LL_4, + L3_CONFIG_DATA_TYPE_LL_6, + +#define L3_CONFIG_DATA_TYPE_LL_X(IS_IPv4) \ + ((IS_IPv4) ? L3_CONFIG_DATA_TYPE_LL_4 : L3_CONFIG_DATA_TYPE_LL_6) + L3_CONFIG_DATA_TYPE_AC_6, + L3_CONFIG_DATA_TYPE_PD_6, + L3_CONFIG_DATA_TYPE_DHCP_4, L3_CONFIG_DATA_TYPE_DHCP_6, - L3_CONFIG_DATA_TYPE_DEV_4, - L3_CONFIG_DATA_TYPE_DEV_6, - L3_CONFIG_DATA_TYPE_SETTING, + +#define L3_CONFIG_DATA_TYPE_DHCP_X(IS_IPv4) \ + ((IS_IPv4) ? L3_CONFIG_DATA_TYPE_DHCP_4 : L3_CONFIG_DATA_TYPE_DHCP_6) + + L3_CONFIG_DATA_TYPE_SHARED_4, + L3_CONFIG_DATA_TYPE_DEVIP_UNSPEC, + L3_CONFIG_DATA_TYPE_DEVIP_4, + L3_CONFIG_DATA_TYPE_DEVIP_6, + +#define L3_CONFIG_DATA_TYPE_DEVIP(addr_family) \ + ({ \ + L3ConfigDataType _t; \ + \ + switch (addr_family) { \ + case AF_INET: \ + _t = L3_CONFIG_DATA_TYPE_DEVIP_4; \ + break; \ + case AF_INET6: \ + _t = L3_CONFIG_DATA_TYPE_DEVIP_6; \ + break; \ + default: \ + nm_assert_not_reached(); \ + /* fall-through */ \ + case AF_UNSPEC: \ + _t = L3_CONFIG_DATA_TYPE_DEVIP_UNSPEC; \ + break; \ + } \ + \ + _t; \ + }) + + L3_CONFIG_DATA_TYPE_MANUALIP, + _L3_CONFIG_DATA_TYPE_NUM, _L3_CONFIG_DATA_TYPE_NONE, + _L3_CONFIG_DATA_TYPE_ACD_ONLY, } L3ConfigDataType; -typedef struct { - AcdCallback callback; - NMDevice * device; - NMIP4Config **configs; -} AcdData; +G_STATIC_ASSERT(NM_L3CFG_CONFIG_PRIORITY_IPV4LL == L3_CONFIG_DATA_TYPE_LL_4); +G_STATIC_ASSERT(NM_L3CFG_CONFIG_PRIORITY_IPV6LL == L3_CONFIG_DATA_TYPE_LL_6); +G_STATIC_ASSERT(NM_L3CFG_CONFIG_PRIORITY_VPN == L3_CONFIG_DATA_TYPE_DEVIP_6); typedef enum { HW_ADDR_TYPE_UNSET = 0, @@ -177,26 +208,81 @@ typedef enum { } FirewallState; typedef struct { - NMIPConfig *orig; /* the original configuration applied to the device */ - NMIPConfig *current; /* configuration after external changes. NULL means - * that the original configuration didn't change. */ -} AppliedConfig; + NMIPConfig *ip_config; +} L3IPData; + +typedef struct { + GSource *check_async_source; + GSource *req_timeout_source; + union { + const NMDeviceIPState state; + NMDeviceIPState state_; + }; + bool wait_for_carrier : 1; + bool wait_for_ports : 1; + bool is_disabled : 1; + bool is_ignore : 1; + bool do_reapply : 1; +} IPStateData; + +typedef struct { + NMDhcpClient *client; + NMDhcpConfig *config; + gulong notify_sigid; + NMDeviceIPState state; + union { + struct { + } v4; + struct { + guint needed_prefixes; + NMNDiscDHCPLevel mode; + } v6; + }; +} IPDhcpStateData; + +typedef struct { + NMDeviceIPState state; + NMDeviceStateReason failed_reason; +} IPDevStateData; + +typedef struct { + NMDeviceIPState state; + union { + struct { + NMDnsMasqManager *dnsmasq_manager; + NMNetnsSharedIPHandle *shared_ip_handle; + NMFirewallConfig *firewall_config; + gulong dnsmasq_state_id; + const NML3ConfigData *l3cd; + } v4; + struct { + } v6; + }; +} IPSharedStateData; typedef struct { - NMDhcpClient *client; - NMDhcpConfig *config; - gulong notify_sigid; - guint grace_id; - bool grace_pending : 1; - bool was_active : 1; -} DhcpData; + NMDeviceIPState state; + union { + struct { + NML3IPv4LL *ipv4ll; + NML3IPv4LLRegistration *ipv4ll_registation; + GSource *timeout_source; + } v4; + struct { + NML3IPv6LL *ipv6ll; + GSource *retry_source; + NML3IPv6LLState llstate; + struct in6_addr lladdr; + } v6; + }; +} IPLLStateData; struct _NMDeviceConnectivityHandle { CList concheck_lst; - NMDevice * self; + NMDevice *self; NMDeviceConnectivityCallback callback; gpointer user_data; - NMConnectivityCheckHandle * c_handle; + NMConnectivityCheckHandle *c_handle; guint64 seq; bool is_periodic : 1; bool is_periodic_bump : 1; @@ -209,8 +295,8 @@ typedef struct { NMEthtoolFeatureStates *features; NMOptionBool requested[_NM_ETHTOOL_ID_FEATURE_NUM]; NMEthtoolCoalesceState *coalesce; - NMEthtoolRingState * ring; - NMEthtoolPauseState * pause; + NMEthtoolRingState *ring; + NMEthtoolPauseState *pause; } EthtoolState; typedef enum { @@ -223,8 +309,8 @@ typedef struct { ResolverState state; GInetAddress *address; GCancellable *cancellable; - char * hostname; - NMDevice * device; + char *hostname; + NMDevice *device; guint timeout_id; /* Used when waiting for the address */ int addr_family; } HostnameResolver; @@ -234,14 +320,14 @@ typedef struct { enum { STATE_CHANGED, AUTOCONNECT_ALLOWED, - IP4_CONFIG_CHANGED, - IP6_CONFIG_CHANGED, + L3CD_CHANGED, IP6_PREFIX_DELEGATED, IP6_SUBNET_NEEDED, REMOVED, RECHECK_AUTO_ACTIVATE, RECHECK_ASSUME, DNS_LOOKUP_DONE, + PLATFORM_ADDRESS_CHANGED, LAST_SIGNAL, }; static guint signals[LAST_SIGNAL] = {0}; @@ -260,6 +346,9 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMDevice, PROP_IP4_ADDRESS, PROP_IP4_CONFIG, PROP_DHCP4_CONFIG, + +#define PROP_DHCPX_CONFIG(IS_IPv4) ((IS_IPv4) ? PROP_DHCP4_CONFIG : PROP_DHCP6_CONFIG) + PROP_IP6_CONFIG, PROP_DHCP6_CONFIG, PROP_STATE, @@ -294,8 +383,6 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMDevice, PROP_PORTS, ); typedef struct _NMDevicePrivate { - bool in_state_changed; - guint device_link_changed_id; guint device_ip_link_changed_id; @@ -309,22 +396,12 @@ typedef struct _NMDevicePrivate { NMDeviceStateReason reason; } queued_state; - union { - struct { - guint queued_ip_config_id_6; - guint queued_ip_config_id_4; - }; - guint queued_ip_config_id_x[2]; - }; - struct { const char **arr; guint len; guint alloc; } pending_actions; - GSList *dad6_failed_addrs; - NMDBusTrackObjPath parent_device; char *udi; @@ -332,23 +409,41 @@ typedef struct _NMDevicePrivate { union { const char *const iface; - char * iface_; + char *iface_; }; union { const char *const ip_iface; - char * ip_iface_; + char *ip_iface_; + }; + + union { + NML3Cfg *const l3cfg; + NML3Cfg *l3cfg_; + }; + + union { + struct { + L3IPData l3ipdata_6; + L3IPData l3ipdata_4; + }; + L3IPData l3ipdata_x[2]; }; + NML3CfgCommitTypeHandle *l3cfg_commit_type; + union { const int ifindex; int ifindex_; }; + union { const int ip_ifindex; int ip_ifindex_; }; - NMNetnsSharedIPHandle *shared_ip_handle; + union { + const NML3ConfigData *d; + } l3cds[_L3_CONFIG_DATA_TYPE_NUM]; int parent_ifindex; @@ -371,22 +466,21 @@ typedef struct _NMDevicePrivate { bool real : 1; - bool update_ip_config_completed_v4 : 1; - bool update_ip_config_completed_v6 : 1; - NMDeviceType type; - char * type_desc; + char *type_desc; NMLinkType link_type; NMDeviceCapabilities capabilities; - char * driver; - char * driver_version; - char * firmware_version; + char *driver; + char *driver_version; + char *firmware_version; RfKillType rfkill_type; bool firmware_missing : 1; bool nm_plugin_missing : 1; bool hw_addr_perm_fake : 1; /* whether the permanent HW address could not be read and is a fake */ + guint8 in_state_changed : 4; + NMUtilsStableType current_stable_id_type : 3; bool nm_owned : 1; /* whether the device is a device owned and created by NM */ @@ -397,10 +491,10 @@ typedef struct _NMDevicePrivate { guint64 udi_id; GHashTable *available_connections; - char * hw_addr; - char * hw_addr_perm; - char * hw_addr_initial; - char * physical_port_id; + char *hw_addr; + char *hw_addr_perm; + char *hw_addr_initial; + char *physical_port_id; guint dev_id; NMUnmanagedFlags unmanaged_mask; @@ -410,25 +504,12 @@ typedef struct _NMDevicePrivate { GCancellable *deactivating_cancellable; - NMActRequest * queued_act_request; + NMActRequest *queued_act_request; bool queued_act_request_is_waiting_for_carrier : 1; NMDBusTrackObjPath act_request; - union { - struct { - guint activation_source_id_6; - guint activation_source_id_4; /* for layer2 and IPv4. */ - }; - guint activation_source_id_x[2]; - }; - - union { - struct { - ActivationHandleFunc activation_source_func_6; - ActivationHandleFunc activation_source_func_4; /* for layer2 and IPv4. */ - }; - ActivationHandleFunc activation_source_func_x[2]; - }; + GSource *activation_idle_source; + ActivationHandleFunc activation_func; guint recheck_assume_id; @@ -452,7 +533,7 @@ typedef struct _NMDevicePrivate { gulong config_changed_id; gulong ifindex_changed_id; guint32 mtu; - guint32 ip6_mtu; + guint32 ip6_mtu; /* FIXME(l3cfg) */ guint32 mtu_initial; guint32 ip6_mtu_initial; NMDeviceMtuSource mtu_source; @@ -468,6 +549,14 @@ typedef struct _NMDevicePrivate { * in the future. This is used to extend the grace period in this particular case. */ gint64 carrier_wait_until_ms; + union { + struct { + NML3ConfigMergeFlags l3config_merge_flags_6; + NML3ConfigMergeFlags l3config_merge_flags_4; + }; + NML3ConfigMergeFlags l3config_merge_flags_x[2]; + }; + union { const NMDeviceSysIfaceState sys_iface_state; NMDeviceSysIfaceState sys_iface_state_; @@ -478,12 +567,6 @@ typedef struct _NMDevicePrivate { bool up : 1; /* IFF_UP */ - bool v4_commit_first_time : 1; - bool v6_commit_first_time : 1; - - bool default_route_metric_penalty_ip4_has : 1; - bool default_route_metric_penalty_ip6_has : 1; - bool v4_route_table_initialized : 1; bool v6_route_table_initialized : 1; @@ -496,165 +579,115 @@ typedef struct _NMDevicePrivate { bool is_enslaved : 1; - bool ipv6ll_handle : 1; /* TRUE if NM handles the device's IPv6LL address */ - bool ipv6ll_has : 1; - bool ndisc_started : 1; bool device_link_changed_down : 1; bool concheck_rp_filter_checked : 1; - NMDeviceStageState stage1_sriov_state : 3; - - bool ip_config_started : 1; bool tc_committed : 1; - char *current_stable_id; + NMDeviceStageState stage1_sriov_state : 3; - union { - struct { - GSource *ip_req_timeout_source_6; - GSource *ip_req_timeout_source_4; - }; - GSource *ip_req_timeout_source_x[2]; - }; + char *current_stable_id; - /* Proxy Configuration */ - NMProxyConfig * proxy_config; NMPacrunnerConfId *pacrunner_conf_id; - /* IP configuration info. Combined config from VPN, settings, and device */ + struct { + union { + const NMDeviceIPState state; + NMDeviceIPState state_; + }; + } ip_data; + union { struct { - NMIP6Config *ip_config_6; - NMIP4Config *ip_config_4; + IPStateData ip_data_6; + IPStateData ip_data_4; }; - NMIPConfig *ip_config_x[2]; + IPStateData ip_data_x[2]; }; - /* Config from DHCP, PPP, LLv4, etc */ - AppliedConfig dev_ip_config_4; + struct { + GSource *carrier_timeout; + union { + struct { + NMDeviceIPState state_6; + NMDeviceIPState state_4; + }; + NMDeviceIPState state_x[2]; + }; + bool carrier_timeout_expired; + } ipmanual_data; - /* config from the setting */ union { struct { - NMIP6Config *con_ip_config_6; - NMIP4Config *con_ip_config_4; + IPDhcpStateData ipdhcp_data_6; + IPDhcpStateData ipdhcp_data_4; }; - NMIPConfig *con_ip_config_x[2]; + IPDhcpStateData ipdhcp_data_x[2]; }; - /* Stuff added outside NM */ + struct { + NMNDisc *ndisc; + GSource *ndisc_grace_source; + gulong ndisc_changed_id; + gulong ndisc_timeout_id; + NMDeviceIPState state; + const NML3ConfigData *l3cd; + } ipac6_data; + union { struct { - NMIP6Config *ext_ip_config_6; - NMIP4Config *ext_ip_config_4; + IPLLStateData ipll_data_6; + IPLLStateData ipll_data_4; }; - NMIPConfig *ext_ip_config_x[2]; + IPLLStateData ipll_data_x[2]; }; - /* VPNs which use this device */ union { struct { - GSList *vpn_configs_6; - GSList *vpn_configs_4; + IPSharedStateData ipshared_data_6; + IPSharedStateData ipshared_data_4; }; - GSList *vpn_configs_x[2]; + IPSharedStateData ipshared_data_x[2]; }; - /* Extra device configuration, injected by the subclass of NMDevice. - * This is used for example by NMDeviceModem for WWAN configuration. */ union { struct { - AppliedConfig dev2_ip_config_6; - AppliedConfig dev2_ip_config_4; + IPDevStateData ipdev_data_6; + IPDevStateData ipdev_data_4; }; - AppliedConfig dev2_ip_config_x[2]; + IPDevStateData ipdev_data_x[2]; }; - /* DHCPv4 tracking */ - struct { - char *pac_url; - } dhcp4; + IPDevStateData ipdev_data_unspec; struct { - /* IP6 config from DHCP */ - AppliedConfig ip6_config; - /* Event ID of the current IP6 config from DHCP */ - char * event_id; - NMNDiscDHCPLevel mode; - guint needed_prefixes; - } dhcp6; + /* If we set the addrgenmode6, this records the previously set value. */ + guint8 previous_mode_val; - union { - struct { - DhcpData dhcp_data_6; - DhcpData dhcp_data_4; - }; - DhcpData dhcp_data_x[2]; - }; + /* whether @previous_mode_val is set. */ + bool previous_mode_has : 1; + } addrgenmode6_data; struct { NMLogDomain log_domain; guint timeout; guint watch; GPid pid; - char * binary; - char * address; + char *binary; + char *address; guint deadline; } gw_ping; - /* dnsmasq stuff for shared connections */ - NMDnsMasqManager *dnsmasq_manager; - gulong dnsmasq_state_id; - /* Firewall */ FirewallState fw_state : 4; - NMFirewalldManager * fw_mgr; + NMFirewalldManager *fw_mgr; NMFirewalldManagerCallId *fw_call; - /* IPv4LL stuff */ - sd_ipv4ll *ipv4ll; - guint ipv4ll_timeout; - guint rt6_temporary_not_available_id; - - /* IPv4 DAD stuff */ - struct { - GSList * dad_list; - NMAcdManager *announcing; - } acd; - - union { - struct { - const NMDeviceIPState ip_state_6; - const NMDeviceIPState ip_state_4; - }; - union { - const NMDeviceIPState ip_state_x[2]; - NMDeviceIPState ip_state_x_[2]; - }; - }; - - AppliedConfig ac_ip6_config; /* config from IPv6 autoconfiguration */ - NMIP6Config * ext_ip6_config_captured; /* Configuration captured from platform. */ - NMIP6Config * dad6_ip6_config; - struct in6_addr ipv6ll_addr; - - GHashTable *rt6_temporary_not_available; - - NMNDisc * ndisc; - gulong ndisc_changed_id; - gulong ndisc_timeout_id; - NMSettingIP6ConfigPrivacy ndisc_use_tempaddr; - - guint linklocal6_timeout_id; - guint8 linklocal6_dad_counter; - GHashTable *ip6_saved_properties; EthtoolState *ethtool_state; - gboolean needs_ip6_subnet; - /* master interface for bridge/bond/team slave */ NMDevice *master; gulong master_ready_id; @@ -666,7 +699,7 @@ typedef struct _NMDevicePrivate { NMMetered metered; NMSettings *settings; - NMManager * manager; + NMManager *manager; NMNetns *netns; @@ -710,9 +743,12 @@ typedef struct _NMDevicePrivate { bool mtu_force_set_done : 1; + bool needs_ip6_subnet : 1; + NMOptionBool promisc_reset; GVariant *ports_variant; /* Array of port devices D-Bus path */ + char *prop_ip_iface; /* IP interface D-Bus property */ } NMDevicePrivate; G_DEFINE_ABSTRACT_TYPE(NMDevice, nm_device, NM_TYPE_DBUS_OBJECT) @@ -724,58 +760,83 @@ G_DEFINE_ABSTRACT_TYPE(NMDevice, nm_device, NM_TYPE_DBUS_OBJECT) static const NMDBusInterfaceInfoExtended interface_info_device; static const GDBusSignalInfo signal_info_state_changed; -static void nm_device_set_proxy_config(NMDevice *self, const char *pac_url); +static void _dev_l3_cfg_commit(NMDevice *self, gboolean do_sync); -static gboolean update_ext_ip_config(NMDevice *self, int addr_family, gboolean intersect_configs); - -static gboolean nm_device_set_ip_config(NMDevice * self, - int addr_family, - NMIPConfig *config, - gboolean commit, - GPtrArray * ip4_dev_route_blacklist); - -static gboolean ip_config_merge_and_apply(NMDevice *self, int addr_family, gboolean commit); +static void _dev_l3_cfg_commit_type_reset(NMDevice *self); static gboolean nm_device_master_add_slave(NMDevice *self, NMDevice *slave, gboolean configure); static void nm_device_slave_notify_enslave(NMDevice *self, gboolean success); static void nm_device_slave_notify_release(NMDevice *self, NMDeviceStateReason reason); -static void addrconf6_start_with_link_ready(NMDevice *self); -static gboolean linklocal6_start(NMDevice *self); +static void _dev_ipll6_start(NMDevice *self); -static guint32 default_route_metric_penalty_get(NMDevice *self, int addr_family); +static void _dev_ipac6_start_continue(NMDevice *self); +static void _dev_ipac6_ndisc_set_router_config(NMDevice *self); -static guint _prop_get_ipv4_dad_timeout(NMDevice *self); +static guint32 _dev_default_route_metric_penalty_get(NMDevice *self, int addr_family); -static NMIP6Config *dad6_get_pending_addresses(NMDevice *self); +static guint32 _prop_get_ipv4_dad_timeout(NMDevice *self); static void _carrier_wait_check_queued_act_request(NMDevice *self); static gint64 _get_carrier_wait_ms(NMDevice *self); +static GBytes *_prop_get_ipv6_dhcp_duid(NMDevice *self, + NMConnection *connection, + GBytes *hwaddr, + gboolean *out_enforce); + static const char *_activation_func_to_string(ActivationHandleFunc func); static void _set_state_full(NMDevice *self, NMDeviceState state, NMDeviceStateReason reason, gboolean quitting); -static void queued_state_clear(NMDevice *device); -static gboolean queued_ip4_config_change(gpointer user_data); -static gboolean queued_ip6_config_change(gpointer user_data); -static void ip_check_ping_watch_cb(GPid pid, int status, gpointer user_data); -static gboolean ip_config_valid(NMDeviceState state); -static NMActStageReturn dhcp4_start(NMDevice *self); -static gboolean dhcp6_start(NMDevice *self, gboolean wait_for_ll); -static void nm_device_start_ip_check(NMDevice *self); -static void realize_start_setup(NMDevice * self, - const NMPlatformLink *plink, - gboolean assume_state_guess_assume, - const char * assume_state_connection_uuid, - gboolean set_nm_owned, - NMUnmanFlagOp unmanaged_user_explicit, - gboolean force_platform_init); -static void _set_mtu(NMDevice *self, guint32 mtu); -static void _commit_mtu(NMDevice *self, const NMIP4Config *config); -static void _cancel_activation(NMDevice *self); - -static void concheck_update_state(NMDevice * self, +static void queued_state_clear(NMDevice *device); +static void ip_check_ping_watch_cb(GPid pid, int status, gpointer user_data); +static void nm_device_start_ip_check(NMDevice *self); +static void realize_start_setup(NMDevice *self, + const NMPlatformLink *plink, + gboolean assume_state_guess_assume, + const char *assume_state_connection_uuid, + gboolean set_nm_owned, + NMUnmanFlagOp unmanaged_user_explicit, + gboolean force_platform_init); +static void _set_mtu(NMDevice *self, guint32 mtu); +static void _commit_mtu(NMDevice *self); +static void _cancel_activation(NMDevice *self); + +static void _dev_ipll4_notify_event(NMDevice *self); + +static void _dev_ip_state_check(NMDevice *self, int addr_family); + +static void _dev_ipmanual_check_ready(NMDevice *self); + +static void +_dev_ipdhcpx_cleanup(NMDevice *self, int addr_family, gboolean reset_dhcp_config, gboolean release); + +static void _dev_ip_state_check_async(NMDevice *self, int addr_family); + +static void _dev_ipdhcpx_set_state(NMDevice *self, int addr_family, NMDeviceIPState state); + +static void _dev_ipdhcpx_restart(NMDevice *self, int addr_family, gboolean release); + +static gboolean +_dev_ipac6_grace_period_start(NMDevice *self, guint32 timeout_sec, gboolean force_restart); + +static void _dev_ipac6_start(NMDevice *self); + +static void _dev_ipac6_set_state(NMDevice *self, NMDeviceIPState state); + +static void +_dev_unmanaged_check_external_down(NMDevice *self, gboolean only_if_unmanaged, gboolean now); + +static void _dev_ipshared4_start(NMDevice *self); +static void _dev_ipshared4_spawn_dnsmasq(NMDevice *self); + +static void _dev_ipshared6_start(NMDevice *self); + +static void +_cleanup_ip_pre(NMDevice *self, int addr_family, CleanupType cleanup_type, gboolean from_reapply); + +static void concheck_update_state(NMDevice *self, int addr_family, NMConnectivityState state, gboolean is_periodic); @@ -783,8 +844,80 @@ static void concheck_update_state(NMDevice * self, static void sriov_op_cb(GError *error, gpointer user_data); static void device_ifindex_changed_cb(NMManager *manager, NMDevice *device_changed, NMDevice *self); -static gboolean device_link_changed(NMDevice *self); -static void check_ip_state(NMDevice *self, gboolean may_fail, gboolean full_state_update); +static gboolean device_link_changed(gpointer user_data); +static gboolean _get_maybe_ipv6_disabled(NMDevice *self); + +/*****************************************************************************/ + +#define _NMLOG_addr_family(level, prefix, addr_family, fmt, ...) \ + G_STMT_START \ + { \ + const int _addr_family2 = (addr_family); \ + \ + _NMLOG(level, \ + (_addr_family2 == AF_UNSPEC ? LOGD_IP : LOGD_IPX(NM_IS_IPv4(_addr_family2))), \ + "" prefix "%s: " fmt, \ + nm_utils_addr_family_to_str(_addr_family2), \ + ##__VA_ARGS__); \ + } \ + G_STMT_END + +#define _NMLOG_ip(level, ...) _NMLOG_addr_family(level, "ip", __VA_ARGS__) +#define _LOGT_ip(...) _NMLOG_ip(LOGL_TRACE, __VA_ARGS__) +#define _LOGD_ip(...) _NMLOG_ip(LOGL_DEBUG, __VA_ARGS__) +#define _LOGI_ip(...) _NMLOG_ip(LOGL_INFO, __VA_ARGS__) +#define _LOGW_ip(...) _NMLOG_ip(LOGL_WARN, __VA_ARGS__) + +#define _NMLOG_ipll(level, ...) _NMLOG_addr_family(level, "ip:ll", __VA_ARGS__) +#define _LOGT_ipll(...) _NMLOG_ipll(LOGL_TRACE, __VA_ARGS__) +#define _LOGD_ipll(...) _NMLOG_ipll(LOGL_DEBUG, __VA_ARGS__) +#define _LOGI_ipll(...) _NMLOG_ipll(LOGL_INFO, __VA_ARGS__) +#define _LOGW_ipll(...) _NMLOG_ipll(LOGL_WARN, __VA_ARGS__) + +#define _NMLOG_ipdev(level, ...) _NMLOG_addr_family(level, "ip:dev", __VA_ARGS__) +#define _LOGT_ipdev(...) _NMLOG_ipdev(LOGL_TRACE, __VA_ARGS__) +#define _LOGD_ipdev(...) _NMLOG_ipdev(LOGL_DEBUG, __VA_ARGS__) +#define _LOGI_ipdev(...) _NMLOG_ipdev(LOGL_INFO, __VA_ARGS__) +#define _LOGW_ipdev(...) _NMLOG_ipdev(LOGL_WARN, __VA_ARGS__) + +#define _NMLOG_ipdhcp(level, ...) _NMLOG_addr_family(level, "ip:dhcp", __VA_ARGS__) +#define _LOGT_ipdhcp(...) _NMLOG_ipdhcp(LOGL_TRACE, __VA_ARGS__) +#define _LOGD_ipdhcp(...) _NMLOG_ipdhcp(LOGL_DEBUG, __VA_ARGS__) +#define _LOGI_ipdhcp(...) _NMLOG_ipdhcp(LOGL_INFO, __VA_ARGS__) +#define _LOGW_ipdhcp(...) _NMLOG_ipdhcp(LOGL_WARN, __VA_ARGS__) + +#define _NMLOG_ipshared(level, ...) _NMLOG_addr_family(level, "ip:shared", __VA_ARGS__) +#define _LOGT_ipshared(...) _NMLOG_ipshared(LOGL_TRACE, __VA_ARGS__) +#define _LOGD_ipshared(...) _NMLOG_ipshared(LOGL_DEBUG, __VA_ARGS__) +#define _LOGI_ipshared(...) _NMLOG_ipshared(LOGL_INFO, __VA_ARGS__) +#define _LOGW_ipshared(...) _NMLOG_ipshared(LOGL_WARN, __VA_ARGS__) + +#define _NMLOG_ipac6(level, ...) _NMLOG_addr_family(level, "ip:ac6", AF_UNSPEC, __VA_ARGS__) +#define _LOGT_ipac6(...) _NMLOG_ipac6(LOGL_TRACE, __VA_ARGS__) +#define _LOGD_ipac6(...) _NMLOG_ipac6(LOGL_DEBUG, __VA_ARGS__) +#define _LOGI_ipac6(...) _NMLOG_ipac6(LOGL_INFO, __VA_ARGS__) +#define _LOGW_ipac6(...) _NMLOG_ipac6(LOGL_WARN, __VA_ARGS__) + +#define _NMLOG_ipmanual(level, ...) _NMLOG_addr_family(level, "ip:manual", __VA_ARGS__) +#define _LOGT_ipmanual(...) _NMLOG_ipmanual(LOGL_TRACE, __VA_ARGS__) +#define _LOGD_ipmanual(...) _NMLOG_ipmanual(LOGL_DEBUG, __VA_ARGS__) +#define _LOGI_ipmanual(...) _NMLOG_ipmanual(LOGL_INFO, __VA_ARGS__) +#define _LOGW_ipmanual(...) _NMLOG_ipmanual(LOGL_WARN, __VA_ARGS__) + +/*****************************************************************************/ + +#define _CACHED_BOOL(cached_value, cmd) \ + ({ \ + NMTernary *const _cached_value = (cached_value); \ + \ + nm_assert(_cached_value); \ + nm_assert_is_ternary(*_cached_value); \ + \ + if (*_cached_value == NM_TERNARY_DEFAULT) \ + *_cached_value = !!(cmd); \ + \ + !!(*_cached_value); \ + }) /*****************************************************************************/ @@ -803,6 +936,38 @@ _hostname_resolver_free(HostnameResolver *resolver) /*****************************************************************************/ +/** + * Update the "ip_iface" property when something changes (device + * state, ifindex) and emit a notify signal if needed. Note that + * the property must be NULL for devices without an ifindex and + * when the device is not activated. This behavior is part of the + * API and should not be changed. + */ +static void +update_prop_ip_iface(NMDevice *self) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + const char *ip_iface = NULL; + gs_free char *to_free = NULL; + + if (nm_device_get_ip_ifindex(self) > 0 + && (priv->state == NM_DEVICE_STATE_UNMANAGED + || (priv->state >= NM_DEVICE_STATE_IP_CHECK + && priv->state <= NM_DEVICE_STATE_DEACTIVATING))) { + ip_iface = nm_utils_str_utf8safe_escape(nm_device_get_ip_iface(self), + NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL, + &to_free); + } + + if (!nm_streq0(priv->prop_ip_iface, ip_iface)) { + g_free(priv->prop_ip_iface); + priv->prop_ip_iface = to_free ? g_steal_pointer(&to_free) : g_strdup(ip_iface); + _notify(self, PROP_IP_IFACE); + } +} + +/*****************************************************************************/ + static NMSettingIP6ConfigPrivacy _ip6_privacy_clamp(NMSettingIP6ConfigPrivacy use_tempaddr) { @@ -819,8 +984,8 @@ _ip6_privacy_clamp(NMSettingIP6ConfigPrivacy use_tempaddr) /*****************************************************************************/ static const char * -_prop_get_connection_stable_id(NMDevice * self, - NMConnection * connection, +_prop_get_connection_stable_id(NMDevice *self, + NMConnection *connection, NMUtilsStableType *out_stable_type) { NMDevicePrivate *priv; @@ -839,13 +1004,13 @@ _prop_get_connection_stable_id(NMDevice * self, * Especially with ${RANDOM} stable-id we want to generate *one* configuration * for each activation. */ if (G_UNLIKELY(!priv->current_stable_id)) { - gs_free char * generated = NULL; + gs_free char *generated = NULL; NMUtilsStableType stable_type; NMSettingConnection *s_con; gboolean hwaddr_is_fake; - const char * hwaddr; - const char * stable_id; - const char * uuid; + const char *hwaddr; + const char *stable_id; + const char *uuid; s_con = nm_connection_get_setting_connection(connection); @@ -907,18 +1072,18 @@ _prop_get_connection_stable_id(NMDevice * self, } static GBytes * -_prop_get_ipv6_dhcp_duid(NMDevice * self, +_prop_get_ipv6_dhcp_duid(NMDevice *self, NMConnection *connection, - GBytes * hwaddr, - gboolean * out_enforce) + GBytes *hwaddr, + gboolean *out_enforce) { NMSettingIPConfig *s_ip6; - const char * duid; - const char * duid_error; - GBytes * duid_out; + const char *duid; + const char *duid_error; + GBytes *duid_out; gboolean duid_enforce = TRUE; - gs_free char * logstr1 = NULL; - const guint8 * hwaddr_bin; + gs_free char *logstr1 = NULL; + const guint8 *hwaddr_bin; gsize hwaddr_len; int arp_type; @@ -979,12 +1144,12 @@ _prop_get_ipv6_dhcp_duid(NMDevice * self, * * Implementations that are added later, should use a distinct salt instead, * like "stable-ll"/"stable-llt" with ARPHRD_INFINIBAND below. */ - const guint32 DEFAULT_SALT = 670531087u; - nm_auto_free_checksum GChecksum *sum = NULL; + const guint32 DEFAULT_SALT = 670531087u; + nm_auto_free_checksum GChecksum *sum = NULL; NMUtilsStableType stable_type; - const char * stable_id = NULL; + const char *stable_id = NULL; guint32 salted_header; - const guint8 * host_id; + const guint8 *host_id; gsize host_id_len; union { guint8 sha256[NM_UTILS_CHECKSUM_LENGTH_SHA256]; @@ -1157,7 +1322,7 @@ _prop_get_ipv6_ra_timeout(NMDevice *self) static NMSettingConnectionMdns _prop_get_connection_mdns(NMDevice *self) { - NMConnection * connection; + NMConnection *connection; NMSettingConnectionMdns mdns = NM_SETTING_CONNECTION_MDNS_DEFAULT; g_return_val_if_fail(NM_IS_DEVICE(self), NM_SETTING_CONNECTION_MDNS_DEFAULT); @@ -1179,7 +1344,7 @@ _prop_get_connection_mdns(NMDevice *self) static NMSettingConnectionLlmnr _prop_get_connection_llmnr(NMDevice *self) { - NMConnection * connection; + NMConnection *connection; NMSettingConnectionLlmnr llmnr = NM_SETTING_CONNECTION_LLMNR_DEFAULT; g_return_val_if_fail(NM_IS_DEVICE(self), NM_SETTING_CONNECTION_LLMNR_DEFAULT); @@ -1201,7 +1366,7 @@ _prop_get_connection_llmnr(NMDevice *self) static NMSettingConnectionDnsOverTls _prop_get_connection_dns_over_tls(NMDevice *self) { - NMConnection * connection; + NMConnection *connection; NMSettingConnectionDnsOverTls dns_over_tls = NM_SETTING_CONNECTION_DNS_OVER_TLS_DEFAULT; g_return_val_if_fail(NM_IS_DEVICE(self), NM_SETTING_CONNECTION_DNS_OVER_TLS_DEFAULT); @@ -1224,14 +1389,14 @@ _prop_get_connection_dns_over_tls(NMDevice *self) static guint32 _prop_get_ipvx_route_table(NMDevice *self, int addr_family) { - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - NMDeviceClass * klass; - NMConnection * connection; - NMSettingIPConfig * s_ip; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NMDeviceClass *klass; + NMConnection *connection; + NMSettingIPConfig *s_ip; guint32 route_table = 0; gboolean is_user_config = TRUE; NMSettingConnection *s_con; - NMSettingVrf * s_vrf; + NMSettingVrf *s_vrf; nm_assert_addr_family(addr_family); @@ -1311,8 +1476,8 @@ _prop_get_ipvx_route_table(NMDevice *self, int addr_family) static gboolean _prop_get_connection_lldp(NMDevice *self) { - NMConnection * connection; - NMSettingConnection * s_con; + NMConnection *connection; + NMSettingConnection *s_con; NMSettingConnectionLldp lldp = NM_SETTING_CONNECTION_LLDP_DEFAULT; connection = nm_device_get_applied_connection(self); @@ -1335,10 +1500,10 @@ _prop_get_connection_lldp(NMDevice *self) return lldp == NM_SETTING_CONNECTION_LLDP_ENABLE_RX; } -static guint +static guint32 _prop_get_ipv4_dad_timeout(NMDevice *self) { - NMConnection * connection; + NMConnection *connection; NMSettingIPConfig *s_ip4 = NULL; int timeout = -1; @@ -1347,6 +1512,9 @@ _prop_get_ipv4_dad_timeout(NMDevice *self) s_ip4 = nm_connection_get_setting_ip4_config(connection); if (s_ip4) timeout = nm_setting_ip_config_get_dad_timeout(s_ip4); + + nm_assert(timeout >= -1 && timeout <= NM_SETTING_IP_CONFIG_DAD_TIMEOUT_MAX); + if (timeout >= 0) return timeout; @@ -1362,9 +1530,9 @@ static guint32 _prop_get_ipvx_dhcp_timeout(NMDevice *self, int addr_family) { NMDeviceClass *klass; - NMConnection * connection; - int timeout_i; + NMConnection *connection; guint32 timeout; + int timeout_i; nm_assert(NM_IS_DEVICE(self)); nm_assert_addr_family(addr_family); @@ -1406,10 +1574,41 @@ out: return timeout; } +static guint32 +_prop_get_ipvx_dns_priority(NMDevice *self, int addr_family) +{ + NMConnection *connection; + NMSettingIPConfig *s_ip; + int prio = 0; + + connection = nm_device_get_applied_connection(self); + s_ip = nm_connection_get_setting_ip_config(connection, addr_family); + if (s_ip) + prio = nm_setting_ip_config_get_dns_priority(s_ip); + + if (prio == 0) { + prio = nm_config_data_get_connection_default_int64( + NM_CONFIG_GET_DATA, + NM_IS_IPv4(addr_family) ? NM_CON_DEFAULT("ipv4.dns-priority") + : NM_CON_DEFAULT("ipv6.dns-priority"), + self, + G_MININT32, + G_MAXINT32, + 0); + if (prio == 0) { + prio = nm_device_is_vpn(self) ? NM_DNS_PRIORITY_DEFAULT_VPN + : NM_DNS_PRIORITY_DEFAULT_NORMAL; + } + } + + nm_assert(prio != 0); + return prio; +} + static guint32 _prop_get_ipvx_required_timeout(NMDevice *self, int addr_family) { - NMConnection * connection; + NMConnection *connection; NMSettingIPConfig *s_ip; int timeout; @@ -1440,6 +1639,25 @@ _prop_get_ipvx_required_timeout(NMDevice *self, int addr_family) 0); } +static gboolean +_prop_get_ipvx_may_fail(NMDevice *self, int addr_family) +{ + NMConnection *connection; + NMSettingIPConfig *s_ip = NULL; + + connection = nm_device_get_applied_connection(self); + if (connection) + s_ip = nm_connection_get_setting_ip_config(connection, addr_family); + + return !s_ip || nm_setting_ip_config_get_may_fail(s_ip); +} + +static gboolean +_prop_get_ipvx_may_fail_cached(NMDevice *self, int addr_family, NMTernary *cache) +{ + return _CACHED_BOOL(cache, _prop_get_ipvx_may_fail(self, addr_family)); +} + /** * _prop_get_ipvx_dhcp_iaid: * @self: the #NMDevice @@ -1453,18 +1671,18 @@ _prop_get_ipvx_required_timeout(NMDevice *self, int addr_family) * Returns: a IAID value for this device and the given connection. */ static guint32 -_prop_get_ipvx_dhcp_iaid(NMDevice * self, +_prop_get_ipvx_dhcp_iaid(NMDevice *self, int addr_family, NMConnection *connection, gboolean log_silent, - gboolean * out_is_explicit) + gboolean *out_is_explicit) { const int IS_IPv4 = NM_IS_IPv4(addr_family); NMSettingIPConfig *s_ip; - const char * iaid_str; + const char *iaid_str; guint32 iaid; - const char * iface; - const char * fail_reason; + const char *iface; + const char *fail_reason; gboolean is_explicit = TRUE; s_ip = nm_connection_get_setting_ip_config(connection, addr_family); @@ -1528,9 +1746,9 @@ _prop_get_ipvx_dhcp_iaid(NMDevice * self, nm_auto_free_checksum GChecksum *sum = NULL; guint8 digest[NM_UTILS_CHECKSUM_LENGTH_SHA1]; NMUtilsStableType stable_type; - const char * stable_id; + const char *stable_id; guint32 salted_header; - const guint8 * host_id; + const guint8 *host_id; gsize host_id_len; stable_id = _prop_get_connection_stable_id(self, connection, &stable_type); @@ -1583,9 +1801,9 @@ out_good: static NMDhcpHostnameFlags _prop_get_ipvx_dhcp_hostname_flags(NMDevice *self, int addr_family) { - NMConnection * connection; - NMSettingIPConfig * s_ip; - NMDhcpHostnameFlags flags; + NMConnection *connection; + NMSettingIPConfig *s_ip; + NMDhcpHostnameFlags flags; gs_free_error GError *error = NULL; g_return_val_if_fail(NM_IS_DEVICE(self), NM_DHCP_HOSTNAME_FLAG_NONE); @@ -1660,15 +1878,15 @@ static GBytes * _prop_get_ipv4_dhcp_client_id(NMDevice *self, NMConnection *connection, GBytes *hwaddr) { NMSettingIPConfig *s_ip4; - const char * client_id; - guint8 * client_id_buf; - const char * fail_reason; + const char *client_id; + guint8 *client_id_buf; + const char *fail_reason; guint8 hwaddr_bin_buf[_NM_UTILS_HWADDR_LEN_MAX]; - const guint8 * hwaddr_bin; + const guint8 *hwaddr_bin; int arp_type; gsize hwaddr_len; - GBytes * result; - gs_free char * logstr1 = NULL; + GBytes *result; + gs_free char *logstr1 = NULL; s_ip4 = nm_connection_get_setting_ip4_config(connection); client_id = nm_setting_ip4_config_get_dhcp_client_id(NM_SETTING_IP4_CONFIG(s_ip4)); @@ -1739,7 +1957,7 @@ _prop_get_ipv4_dhcp_client_id(NMDevice *self, NMConnection *connection, GBytes * gs_unref_bytes GBytes *duid = NULL; gboolean iaid_is_explicit; guint32 iaid; - const guint8 * duid_arr; + const guint8 *duid_arr; gsize duid_len; iaid = _prop_get_ipvx_dhcp_iaid(self, AF_INET, connection, FALSE, &iaid_is_explicit); @@ -1764,9 +1982,9 @@ _prop_get_ipv4_dhcp_client_id(NMDevice *self, NMConnection *connection, GBytes * nm_auto_free_checksum GChecksum *sum = NULL; guint8 digest[NM_UTILS_CHECKSUM_LENGTH_SHA1]; NMUtilsStableType stable_type; - const char * stable_id; + const char *stable_id; guint32 salted_header; - const guint8 * host_id; + const guint8 *host_id; gsize host_id_len; stable_id = _prop_get_connection_stable_id(self, connection, &stable_type); @@ -1812,9 +2030,9 @@ static GBytes * _prop_get_ipv4_dhcp_vendor_class_identifier(NMDevice *self, NMSettingIP4Config *s_ip4) { gs_free char *to_free = NULL; - const char * conn_prop; - GBytes * bytes = NULL; - const char * bin; + const char *conn_prop; + GBytes *bytes = NULL; + const char *bin; gsize len; conn_prop = nm_setting_ip4_config_get_dhcp_vendor_class_identifier(s_ip4); @@ -1848,7 +2066,7 @@ static NMSettingIP6ConfigPrivacy _prop_get_ipv6_ip6_privacy(NMDevice *self) { NMSettingIP6ConfigPrivacy ip6_privacy; - NMConnection * connection; + NMConnection *connection; g_return_val_if_fail(self, NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN); @@ -1895,7 +2113,7 @@ _prop_get_ipv6_ip6_privacy(NMDevice *self) static const char * _prop_get_x_cloned_mac_address(NMDevice *self, NMConnection *connection, gboolean is_wifi) { - NMSetting * setting; + NMSetting *setting; const char *addr = NULL; setting = nm_connection_get_setting(connection, @@ -1941,7 +2159,7 @@ _prop_get_x_cloned_mac_address(NMDevice *self, NMConnection *connection, gboolea static const char * _prop_get_x_generate_mac_address_mask(NMDevice *self, NMConnection *connection, gboolean is_wifi) { - NMSetting * setting; + NMSetting *setting; const char *value; setting = nm_connection_get_setting(connection, @@ -1967,7 +2185,7 @@ _prop_get_x_generate_mac_address_mask(NMDevice *self, NMConnection *connection, static void _ethtool_features_reset(NMDevice *self, NMPlatform *platform, EthtoolState *ethtool_state) { - gs_free NMEthtoolFeatureStates *features; + gs_free NMEthtoolFeatureStates *features = NULL; features = g_steal_pointer(ðtool_state->features); @@ -1982,9 +2200,9 @@ _ethtool_features_reset(NMDevice *self, NMPlatform *platform, EthtoolState *etht } static void -_ethtool_features_set(NMDevice * self, - NMPlatform * platform, - EthtoolState * ethtool_state, +_ethtool_features_set(NMDevice *self, + NMPlatform *platform, + EthtoolState *ethtool_state, NMSettingEthtool *s_ethtool) { gs_free NMEthtoolFeatureStates *features = NULL; @@ -2033,18 +2251,18 @@ _ethtool_coalesce_reset(NMDevice *self, NMPlatform *platform, EthtoolState *etht } static void -_ethtool_coalesce_set(NMDevice * self, - NMPlatform * platform, - EthtoolState * ethtool_state, +_ethtool_coalesce_set(NMDevice *self, + NMPlatform *platform, + EthtoolState *ethtool_state, NMSettingEthtool *s_ethtool) { NMEthtoolCoalesceState coalesce_old; NMEthtoolCoalesceState coalesce_new; gboolean has_old = FALSE; - GHashTable * hash; + GHashTable *hash; GHashTableIter iter; - const char * name; - GVariant * variant; + const char *name; + GVariant *variant; nm_assert(NM_IS_DEVICE(self)); nm_assert(NM_IS_PLATFORM(platform)); @@ -2111,17 +2329,17 @@ _ethtool_ring_reset(NMDevice *self, NMPlatform *platform, EthtoolState *ethtool_ } static void -_ethtool_ring_set(NMDevice * self, - NMPlatform * platform, - EthtoolState * ethtool_state, +_ethtool_ring_set(NMDevice *self, + NMPlatform *platform, + EthtoolState *ethtool_state, NMSettingEthtool *s_ethtool) { NMEthtoolRingState ring_old; NMEthtoolRingState ring_new; - GHashTable * hash; + GHashTable *hash; GHashTableIter iter; - const char * name; - GVariant * variant; + const char *name; + GVariant *variant; gboolean has_old = FALSE; nm_assert(NM_IS_DEVICE(self)); @@ -2207,17 +2425,17 @@ _ethtool_pause_reset(NMDevice *self, NMPlatform *platform, EthtoolState *ethtool } static void -_ethtool_pause_set(NMDevice * self, - NMPlatform * platform, - EthtoolState * ethtool_state, +_ethtool_pause_set(NMDevice *self, + NMPlatform *platform, + EthtoolState *ethtool_state, NMSettingEthtool *s_ethtool) { NMEthtoolPauseState pause_old; NMEthtoolPauseState pause_new; - GHashTable * hash; + GHashTable *hash; GHashTableIter iter; - const char * name; - GVariant * variant; + const char *name; + GVariant *variant; gboolean has_old = FALSE; NMTernary pause_autoneg = NM_TERNARY_DEFAULT; NMTernary pause_rx = NM_TERNARY_DEFAULT; @@ -2297,8 +2515,8 @@ _ethtool_pause_set(NMDevice * self, static void _ethtool_state_reset(NMDevice *self) { - NMPlatform * platform = nm_device_get_platform(self); - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NMPlatform *platform = nm_device_get_platform(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); gs_free EthtoolState *ethtool_state = g_steal_pointer(&priv->ethtool_state); if (!ethtool_state) @@ -2317,12 +2535,12 @@ _ethtool_state_reset(NMDevice *self) static void _ethtool_state_set(NMDevice *self) { - int ifindex; - NMPlatform * platform; - NMConnection * connection; - NMSettingEthtool *s_ethtool; + int ifindex; + NMPlatform *platform; + NMConnection *connection; + NMSettingEthtool *s_ethtool; gs_free EthtoolState *ethtool_state = NULL; - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); ifindex = nm_device_get_ip_ifindex(self); if (ifindex <= 0) @@ -2416,27 +2634,6 @@ concheck_get_mgr(NMDevice *self) return priv->concheck_mgr; } -NMIP4Config * -nm_device_ip4_config_new(NMDevice *self) -{ - return nm_ip4_config_new(nm_device_get_multi_index(self), nm_device_get_ip_ifindex(self)); -} - -NMIP6Config * -nm_device_ip6_config_new(NMDevice *self) -{ - return nm_ip6_config_new(nm_device_get_multi_index(self), nm_device_get_ip_ifindex(self)); -} - -NMIPConfig * -nm_device_ip_config_new(NMDevice *self, int addr_family) -{ - nm_assert_addr_family(addr_family); - - return NM_IS_IPv4(addr_family) ? (gpointer) nm_device_ip4_config_new(self) - : (gpointer) nm_device_ip6_config_new(self); -} - NML3ConfigData * nm_device_create_l3_config_data(NMDevice *self, NMIPConfigSource source) { @@ -2451,128 +2648,59 @@ nm_device_create_l3_config_data(NMDevice *self, NMIPConfigSource source) return nm_l3_config_data_new(nm_device_get_multi_index(self), ifindex, source); } -static void -applied_config_clear(AppliedConfig *config) +const NML3ConfigData * +nm_device_create_l3_config_data_from_connection(NMDevice *self, NMConnection *connection) { - g_clear_object(&config->current); - g_clear_object(&config->orig); -} + NML3ConfigData *l3cd; + int ifindex; -static void -applied_config_init(AppliedConfig *config, gpointer ip_config) -{ - nm_assert(!ip_config || (!config->orig && !config->current) - || nm_ip_config_get_addr_family(ip_config) - == nm_ip_config_get_addr_family(config->orig ?: config->current)); - nm_assert(!ip_config || NM_IS_IP_CONFIG(ip_config)); + nm_assert(NM_IS_DEVICE(self)); + nm_assert(!connection || NM_IS_CONNECTION(connection)); - nm_g_object_ref(ip_config); - applied_config_clear(config); - config->orig = ip_config; -} + if (!connection) + return NULL; -static void -applied_config_init_new(AppliedConfig *config, NMDevice *self, int addr_family) -{ - gs_unref_object NMIPConfig *c = nm_device_ip_config_new(self, addr_family); + ifindex = nm_device_get_ip_ifindex(self); + if (ifindex <= 0) + g_return_val_if_reached(NULL); - applied_config_init(config, c); + l3cd = + nm_l3_config_data_new_from_connection(nm_device_get_multi_index(self), ifindex, connection); + nm_l3_config_data_set_mdns(l3cd, _prop_get_connection_mdns(self)); + nm_l3_config_data_set_llmnr(l3cd, _prop_get_connection_llmnr(self)); + nm_l3_config_data_set_dns_over_tls(l3cd, _prop_get_connection_dns_over_tls(self)); + nm_l3_config_data_set_ip6_privacy(l3cd, _prop_get_ipv6_ip6_privacy(self)); + return l3cd; } -static NMIPConfig * -applied_config_get_current(AppliedConfig *config) -{ - return config->current ?: config->orig; -} +/*****************************************************************************/ -static void -applied_config_add_address(AppliedConfig *config, const NMPlatformIPAddress *address) +NMDeviceSysIfaceState +nm_device_sys_iface_state_get(NMDevice *self) { - if (config->orig) - nm_ip_config_add_address(config->orig, address); - else - nm_assert(!config->current); + g_return_val_if_fail(NM_IS_DEVICE(self), NM_DEVICE_SYS_IFACE_STATE_EXTERNAL); - if (config->current) - nm_ip_config_add_address(config->current, address); + return NM_DEVICE_GET_PRIVATE(self)->sys_iface_state; } -static void -applied_config_add_nameserver(AppliedConfig *config, const NMIPAddr *ns) +gboolean +nm_device_sys_iface_state_is_external(NMDevice *self) { - if (config->orig) - nm_ip_config_add_nameserver(config->orig, ns); - else - nm_assert(!config->current); - - if (config->current) - nm_ip_config_add_nameserver(config->current, ns); + return NM_IN_SET(nm_device_sys_iface_state_get(self), NM_DEVICE_SYS_IFACE_STATE_EXTERNAL); } -static void -applied_config_add_search(AppliedConfig *config, const char *new) +gboolean +nm_device_sys_iface_state_is_external_or_assume(NMDevice *self) { - if (config->orig) - nm_ip_config_add_search(config->orig, new); - else - nm_assert(!config->current); - - if (config->current) - nm_ip_config_add_search(config->current, new); + return NM_IN_SET(nm_device_sys_iface_state_get(self), + NM_DEVICE_SYS_IFACE_STATE_EXTERNAL, + NM_DEVICE_SYS_IFACE_STATE_ASSUME); } -static void -applied_config_reset_searches(AppliedConfig *config) +void +nm_device_sys_iface_state_set(NMDevice *self, NMDeviceSysIfaceState sys_iface_state) { - if (config->orig) - nm_ip_config_reset_searches(config->orig); - else - nm_assert(!config->current); - - if (config->current) - nm_ip_config_reset_searches(config->current); -} - -static void -applied_config_reset_nameservers(AppliedConfig *config) -{ - if (config->orig) - nm_ip_config_reset_nameservers(config->orig); - else - nm_assert(!config->current); - - if (config->current) - nm_ip_config_reset_nameservers(config->current); -} - -/*****************************************************************************/ - -NMDeviceSysIfaceState -nm_device_sys_iface_state_get(NMDevice *self) -{ - g_return_val_if_fail(NM_IS_DEVICE(self), NM_DEVICE_SYS_IFACE_STATE_EXTERNAL); - - return NM_DEVICE_GET_PRIVATE(self)->sys_iface_state; -} - -gboolean -nm_device_sys_iface_state_is_external(NMDevice *self) -{ - return NM_IN_SET(nm_device_sys_iface_state_get(self), NM_DEVICE_SYS_IFACE_STATE_EXTERNAL); -} - -gboolean -nm_device_sys_iface_state_is_external_or_assume(NMDevice *self) -{ - return NM_IN_SET(nm_device_sys_iface_state_get(self), - NM_DEVICE_SYS_IFACE_STATE_EXTERNAL, - NM_DEVICE_SYS_IFACE_STATE_ASSUME); -} - -void -nm_device_sys_iface_state_set(NMDevice *self, NMDeviceSysIfaceState sys_iface_state) -{ - NMDevicePrivate *priv; + NMDevicePrivate *priv; g_return_if_fail(NM_IS_DEVICE(self)); g_return_if_fail(NM_IN_SET(sys_iface_state, @@ -2588,6 +2716,7 @@ nm_device_sys_iface_state_set(NMDevice *self, NMDeviceSysIfaceState sys_iface_st nm_device_sys_iface_state_to_string(priv->sys_iface_state), nm_device_sys_iface_state_to_string(sys_iface_state)); priv->sys_iface_state_ = sys_iface_state; + _dev_l3_cfg_commit_type_reset(self); } /* this function only sets a flag, no immediate actions are initiated. @@ -2598,7 +2727,7 @@ nm_device_sys_iface_state_set(NMDevice *self, NMDeviceSysIfaceState sys_iface_st } static void -_active_connection_set_state_flags_full(NMDevice * self, +_active_connection_set_state_flags_full(NMDevice *self, NMActivationStateFlags flags, NMActivationStateFlags mask) { @@ -2618,12 +2747,12 @@ _active_connection_set_state_flags(NMDevice *self, NMActivationStateFlags flags) /*****************************************************************************/ static gboolean -set_interface_flags_full(NMDevice * self, +set_interface_flags_full(NMDevice *self, NMDeviceInterfaceFlags mask, NMDeviceInterfaceFlags interface_flags, gboolean notify) { - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); NMDeviceInterfaceFlags f; nm_assert(!!mask); @@ -2642,7 +2771,7 @@ set_interface_flags_full(NMDevice * self, } static gboolean -set_interface_flags(NMDevice * self, +set_interface_flags(NMDevice *self, NMDeviceInterfaceFlags interface_flags, gboolean set, gboolean notify) @@ -2654,8 +2783,8 @@ set_interface_flags(NMDevice * self, } void -nm_device_assume_state_get(NMDevice * self, - gboolean * out_assume_state_guess_assume, +nm_device_assume_state_get(NMDevice *self, + gboolean *out_assume_state_guess_assume, const char **out_assume_state_connection_uuid) { NMDevicePrivate *priv; @@ -2668,7 +2797,7 @@ nm_device_assume_state_get(NMDevice * self, } static void -_assume_state_set(NMDevice * self, +_assume_state_set(NMDevice *self, gboolean assume_state_guess_assume, const char *assume_state_connection_uuid) { @@ -2700,33 +2829,6 @@ nm_device_assume_state_reset(NMDevice *self) /*****************************************************************************/ -static void -init_ip_config_dns_priority(NMDevice *self, NMIPConfig *config) -{ - const char *property; - int priority; - - property = (nm_ip_config_get_addr_family(config) == AF_INET) - ? NM_CON_DEFAULT("ipv4.dns-priority") - : NM_CON_DEFAULT("ipv6.dns-priority"); - - priority = nm_config_data_get_connection_default_int64(NM_CONFIG_GET_DATA, - property, - self, - G_MININT, - G_MAXINT, - 0); - - if (priority == 0) { - priority = - nm_device_is_vpn(self) ? NM_DNS_PRIORITY_DEFAULT_VPN : NM_DNS_PRIORITY_DEFAULT_NORMAL; - } - - nm_ip_config_set_dns_priority(config, priority); -} - -/*****************************************************************************/ - static char * nm_device_sysctl_ip_conf_get(NMDevice *self, int addr_family, const char *property) { @@ -2744,7 +2846,7 @@ nm_device_sysctl_ip_conf_get(NMDevice *self, int addr_family, const char *proper } static gint64 -nm_device_sysctl_ip_conf_get_int_checked(NMDevice * self, +nm_device_sysctl_ip_conf_get_int_checked(NMDevice *self, int addr_family, const char *property, guint base, @@ -2771,59 +2873,15 @@ nm_device_sysctl_ip_conf_get_int_checked(NMDevice * self, fallback); } -static void -set_ipv6_token(NMDevice *self, const NMUtilsIPv6IfaceId *iid, const char *token_str) -{ - NMPlatform * platform; - int ifindex; - const NMPlatformLink *link; - char buf[32]; - gint64 val; - - /* Setting the kernel token is not strictly necessary as the - * IPv6 address is generated in userspace. However it is - * convenient so that users can see the token with iproute - * ('ip token'). */ - platform = nm_device_get_platform(self); - ifindex = nm_device_get_ip_ifindex(self); - link = nm_platform_link_get(platform, ifindex); - - if (link && link->inet6_token.id == iid->id) { - _LOGT(LOGD_DEVICE | LOGD_IP6, "token %s already set", token_str); - return; - } - - /* The kernel allows setting a token only when 'accept_ra' - * is 1: temporarily flip it if necessary; unfortunately - * this will also generate an additional Router Solicitation - * from kernel. */ - val = nm_device_sysctl_ip_conf_get_int_checked(self, - AF_INET6, - "accept_ra", - 10, - G_MININT32, - G_MAXINT32, - 1); - if (val != 1) - nm_device_sysctl_ip_conf_set(self, AF_INET6, "accept_ra", "1"); - - nm_platform_link_set_ipv6_token(platform, ifindex, iid); - - if (val != 1) { - nm_sprintf_buf(buf, "%d", (int) val); - nm_device_sysctl_ip_conf_set(self, AF_INET6, "accept_ra", buf); - } -} - gboolean -nm_device_sysctl_ip_conf_set(NMDevice * self, +nm_device_sysctl_ip_conf_set(NMDevice *self, int addr_family, const char *property, const char *value) { - NMPlatform * platform = nm_device_get_platform(self); + NMPlatform *platform = nm_device_get_platform(self); gs_free char *value_to_free = NULL; - const char * ifname; + const char *ifname; nm_assert_addr_family(addr_family); @@ -2863,245 +2921,1316 @@ _add_capabilities(NMDevice *self, NMDeviceCapabilities capabilities) /*****************************************************************************/ +static void +_dev_ip_state_req_timeout_cancel(NMDevice *self, int addr_family) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + + if (addr_family == AF_UNSPEC) { + _dev_ip_state_req_timeout_cancel(self, AF_INET); + _dev_ip_state_req_timeout_cancel(self, AF_INET6); + return; + } + + if (nm_clear_g_source_inst(&priv->ip_data_x[NM_IS_IPv4(addr_family)].req_timeout_source)) + _LOGD_ip(addr_family, "required-timeout: cancelled"); +} + static gboolean -ip_required_timeout_x(NMDevice *self, int addr_family) +_dev_ip_state_req_timeout_cb_x(NMDevice *self, int addr_family) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - _LOGD(LOGD_CORE, - "required-timeout expired for IPv%c", - nm_utils_addr_family_to_char(addr_family)); - nm_clear_g_source_inst(&priv->ip_req_timeout_source_x[NM_IS_IPv4(addr_family)]); - check_ip_state(self, FALSE, TRUE); + _LOGD_ip(addr_family, "required-timeout: expired"); + nm_clear_g_source_inst(&priv->ip_data_x[NM_IS_IPv4(addr_family)].req_timeout_source); + _dev_ip_state_check(self, nm_utils_addr_family_other(addr_family)); return G_SOURCE_CONTINUE; } static gboolean -ip_required_timeout_4(gpointer data) +_dev_ip_state_req_timeout_cb_4(gpointer user_data) { - return ip_required_timeout_x(data, AF_INET); + return _dev_ip_state_req_timeout_cb_x(user_data, AF_INET); } static gboolean -ip_required_timeout_6(gpointer data) +_dev_ip_state_req_timeout_cb_6(gpointer user_data) { - return ip_required_timeout_x(data, AF_INET6); + return _dev_ip_state_req_timeout_cb_x(user_data, AF_INET6); } static void -_set_ip_state(NMDevice *self, int addr_family, NMDeviceIPState new_state) +_dev_ip_state_req_timeout_schedule(NMDevice *self, int addr_family) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); const int IS_IPv4 = NM_IS_IPv4(addr_family); - guint timeout_msec; - int v4; - - nm_assert_addr_family(addr_family); - - if (new_state == NM_DEVICE_IP_STATE_CONF && !priv->ip_config_started) { - /* Start the required-timeout timers when one of IPv4/IPv6 - * enters the CONF state. This means that if there is no carrier and - * ipv4.method=auto,ipv6.method=manual, the timeout for IPv4 will - * start as soon as connection is activated, even if DHCPv4 did not - * start yet. - */ - priv->ip_config_started = TRUE; - - for (v4 = 1; v4 >= 0; v4--) { - char buf[32]; + guint32 timeout_msec; + char buf[32]; - nm_assert(!priv->ip_req_timeout_source_x[v4]); - if ((timeout_msec = _prop_get_ipvx_required_timeout(self, v4 ? AF_INET : AF_INET6))) { - _LOGD(LOGD_CORE, - "required-timeout in %s msec for IPv%c", - timeout_msec == G_MAXINT32 ? "∞" : nm_sprintf_buf(buf, "%u", timeout_msec), - v4 ? '4' : '6'); + nm_assert(!priv->ip_data_x[IS_IPv4].req_timeout_source); - if (timeout_msec == G_MAXINT32) { - priv->ip_req_timeout_source_x[v4] = g_source_ref(nm_g_source_sentinel_get(0)); - } else { - priv->ip_req_timeout_source_x[v4] = - nm_g_timeout_add_source(timeout_msec, - v4 ? ip_required_timeout_4 : ip_required_timeout_6, - self); - } - } - } + timeout_msec = _prop_get_ipvx_required_timeout(self, addr_family); + if (timeout_msec == 0) { + _LOGD_ip(addr_family, "required-timeout: disabled"); + return; } - if (priv->ip_state_x[IS_IPv4] == new_state) - return; + _LOGD_ip(addr_family, + "required-timeout: started (%s msec)", + timeout_msec == G_MAXINT32 ? "∞" : nm_sprintf_buf(buf, "%u", timeout_msec)); - _LOGT(LOGD_DEVICE, - "ip%c-state: set to %d (%s)", - nm_utils_addr_family_to_char(addr_family), - (int) new_state, - nm_device_ip_state_to_string(new_state)); + if (timeout_msec == G_MAXINT32) { + priv->ip_data_x[IS_IPv4].req_timeout_source = g_source_ref(nm_g_source_sentinel_get(0)); + } else { + priv->ip_data_x[IS_IPv4].req_timeout_source = nm_g_timeout_add_source( + timeout_msec, + IS_IPv4 ? _dev_ip_state_req_timeout_cb_4 : _dev_ip_state_req_timeout_cb_6, + self); + } +} - priv->ip_state_x_[IS_IPv4] = new_state; +static gboolean +_dev_ip_state_set_state(NMDevice *self, + int addr_family, + NMDeviceIPState ip_state, + const char *reason) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + int IS_IPv4; - if (new_state == NM_DEVICE_IP_STATE_DONE) { - /* we only set the IPx_READY flag once we reach NM_DEVICE_IP_STATE_DONE state. We don't - * ever clear it, even if we later enter NM_DEVICE_IP_STATE_FAIL state. - * - * This is not documented/guaranteed behavior, but seems to make sense for now. */ - _active_connection_set_state_flags(self, - NM_IS_IPv4(addr_family) - ? NM_ACTIVATION_STATE_FLAG_IP4_READY - : NM_ACTIVATION_STATE_FLAG_IP6_READY); + if (addr_family == AF_UNSPEC) { + if (priv->ip_data.state == ip_state) + return FALSE; + _LOGD_ip(addr_family, + "set (combined) state %s (was %s, reason: %s)", + nm_device_ip_state_to_string(ip_state), + nm_device_ip_state_to_string(priv->ip_data.state), + reason); + priv->ip_data.state_ = ip_state; + return TRUE; } -} -/*****************************************************************************/ + IS_IPv4 = NM_IS_IPv4(addr_family); -const char * -nm_device_get_udi(NMDevice *self) -{ - g_return_val_if_fail(self != NULL, NULL); + if (priv->ip_data_x[IS_IPv4].state_ == ip_state) + return FALSE; - return NM_DEVICE_GET_PRIVATE(self)->udi; + _LOGD_ip(addr_family, + "set state %s (was %s, reason: %s)", + nm_device_ip_state_to_string(ip_state), + nm_device_ip_state_to_string(priv->ip_data_x[IS_IPv4].state), + reason); + priv->ip_data_x[IS_IPv4].state_ = ip_state; + return TRUE; } -const char * -nm_device_get_iface(NMDevice *self) +static void +_device_ip_state_accumulate(NMDeviceIPState state, + gboolean *out_is_started, + gboolean *out_is_pending, + gboolean *out_is_failed) { - g_return_val_if_fail(NM_IS_DEVICE(self), NULL); - - return NM_DEVICE_GET_PRIVATE(self)->iface; + switch (state) { + case NM_DEVICE_IP_STATE_NONE: + return; + case NM_DEVICE_IP_STATE_PENDING: + *out_is_started = TRUE; + *out_is_pending = TRUE; + return; + case NM_DEVICE_IP_STATE_READY: + *out_is_started = TRUE; + return; + case NM_DEVICE_IP_STATE_FAILED: + *out_is_started = TRUE; + *out_is_failed = TRUE; + return; + } + nm_assert_not_reached(); + return; } -static gboolean -_set_ifindex(NMDevice *self, int ifindex, gboolean is_ip_ifindex) +static void +_dev_ip_state_check(NMDevice *self, int addr_family) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - int * p_ifindex; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + const int IS_IPv4 = NM_IS_IPv4(addr_family); + gboolean s_is_started = FALSE; + gboolean s_is_failed = FALSE; + gboolean s_is_pending = FALSE; + gboolean v_bool; + NMDeviceIPState ip_state; + NMDeviceIPState ip_state_other; + NMDeviceIPState combinedip_state; + NMTernary may_fail = NM_TERNARY_DEFAULT; + NMTernary may_fail_other = NM_TERNARY_DEFAULT; + gboolean disabled_or_ignore = FALSE; + gboolean disabled_or_ignore_other = FALSE; + + if (priv->ip_data_x[IS_IPv4].is_disabled || priv->ip_data_x[IS_IPv4].is_ignore) + disabled_or_ignore = TRUE; + if (priv->ip_data_x[!IS_IPv4].is_disabled || priv->ip_data_x[!IS_IPv4].is_ignore) + disabled_or_ignore_other = TRUE; + + /* State handling in NMDevice: + * + * NMDevice manages a lot of state, that is for the various IP addressing methods, the state + * of the interface (controller/port), and a overall nm_device_get_state(). + * + * The idea is to compartmentalize these states into smaller units, and combine them as appropriate. + * + * For example, NMDhcpClient already provides an API that hides most of the complexity. But it still + * needs to expose some state, like whether we are still trying to get a lease (PENDING), whether there + * was a critical failure (FAILED) or we have a lease (READY). This state is grouped in NMDevice + * under priv->ipdhcp_data_x. Most important is priv->ipdhcp_data_x[].state, which distills all of this + * into 4 values of type NMDeviceIPState. This state is cached, so whenever something changes (e.g. + * an event from NMDhcpClient), we determine the new state and compare it with what is cached. If + * the cached state is as the new state, we are done. Otherwise, the change gets escalated (which + * means to call _dev_ip_state_check_async()). + * + * Then, the various sub-states escalate their changes to this function (_dev_ip_state_check). This + * function first takes the sub-states related to one IP address family, and combines them into + * priv->ip_data_x[] (and in particular priv->ip_data_x[].state). The same repeats. The current + * state is cached in priv->ip_data_x[].state, and _dev_ip_state_check() determines the new state. + * If there is no change, it ends here. Otherwise, it gets escalated. In this case, the escaplation + * happens in _dev_ip_state_check() below by combining the combined per-address-family into + * priv->ip_data. In particular this step needs to take into account settings like "may-fail" + * and "required-timeout". + * + * The escalation and compartmentalization priv->ip_data repeats. This time it escalates + * to the overall device state (nm_device_state_changed() and nm_device_get_state()), which then + * triggers larger state changes (e.g. the activation might fail). + */ - if (ifindex < 0) - ifindex = 0; + if (priv->l3cfg && nm_l3cfg_commit_on_idle_is_scheduled(priv->l3cfg)) { + /* we have an update on NML3Cfg scheduled. We first process that, before + * progressing the IP state. When that's done, we will be called again. */ + _dev_ip_state_check_async(self, addr_family); + return; + } - p_ifindex = is_ip_ifindex ? &priv->ip_ifindex_ : &priv->ifindex_; + if (priv->ip_data_x[IS_IPv4].state == NM_DEVICE_IP_STATE_NONE) { + ip_state = NM_DEVICE_IP_STATE_NONE; + goto got_ip_state; + } - if (*p_ifindex == ifindex) - return FALSE; + if (nm_device_sys_iface_state_is_external(self)) { + ip_state = NM_DEVICE_IP_STATE_READY; + goto got_ip_state; + } - *p_ifindex = ifindex; + if (priv->ip_data_x[IS_IPv4].state == NM_DEVICE_IP_STATE_PENDING + && (priv->state < NM_DEVICE_STATE_IP_CONFIG || priv->state > NM_DEVICE_STATE_ACTIVATED)) { + /* we can only leave pending state, if we are between (including) IP_CONFIG and ACTIVATED states. */ + ip_state = NM_DEVICE_IP_STATE_PENDING; + goto got_ip_state; + } - _LOGD(LOGD_DEVICE, "ifindex: set %sifindex %d", is_ip_ifindex ? "ip-" : "", ifindex); + if (priv->ip_data_x[IS_IPv4].state == NM_DEVICE_IP_STATE_PENDING + && nm_active_connection_get_master(NM_ACTIVE_CONNECTION(priv->act_request.obj)) + && !priv->is_enslaved) { + /* Don't progress into IP_CHECK or SECONDARIES if we're waiting for the + * master to enslave us. */ + ip_state = NM_DEVICE_IP_STATE_PENDING; + goto got_ip_state; + } - if (!is_ip_ifindex) - _notify(self, PROP_IFINDEX); + if (priv->ip_data_x[IS_IPv4].wait_for_carrier || priv->ip_data_x[IS_IPv4].wait_for_ports) { + ip_state = NM_DEVICE_IP_STATE_PENDING; + goto got_ip_state; + } - if (priv->manager) - nm_manager_emit_device_ifindex_changed(priv->manager, self); - return TRUE; -} + if (disabled_or_ignore) { + ip_state = NM_DEVICE_IP_STATE_READY; + goto got_ip_state; + } -/** - * nm_device_take_over_link: - * @self: the #NMDevice - * @ifindex: a ifindex - * @old_name: (transfer full): on return, the name of the old link, if - * the link was renamed - * @error: location to store error, or %NULL - * - * Given an existing link, move it under the control of a device. In - * particular, the link will be renamed to match the device name. If the - * link was renamed, the old name is returned in @old_name. - * - * Returns: %TRUE if the device took control of the link, %FALSE otherwise - */ -gboolean -nm_device_take_over_link(NMDevice *self, int ifindex, char **old_name, GError **error) -{ - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - const NMPlatformLink *plink; - NMPlatform * platform; + _device_ip_state_accumulate(priv->ipmanual_data.state_x[IS_IPv4], + &s_is_started, + &s_is_pending, + &s_is_failed); - nm_assert(ifindex > 0); - NM_SET_OUT(old_name, NULL); + _device_ip_state_accumulate(priv->ipll_data_x[IS_IPv4].state, + &s_is_started, + &s_is_pending, + &s_is_failed); - if (priv->ifindex > 0 && priv->ifindex != ifindex) { - nm_utils_error_set(error, - NM_UTILS_ERROR_UNKNOWN, - "the device already has ifindex %d", - priv->ifindex); - return FALSE; + if (!IS_IPv4) { + _device_ip_state_accumulate(priv->ipac6_data.state, + &s_is_started, + &s_is_pending, + &s_is_failed); + } + + v_bool = FALSE; + _device_ip_state_accumulate(priv->ipdhcp_data_x[IS_IPv4].state, + &s_is_started, + &s_is_pending, + &v_bool); + if (v_bool) { + if (!IS_IPv4 && priv->ipdhcp_data_6.v6.mode == NM_NDISC_DHCP_LEVEL_OTHERCONF) { + /* DHCPv6 is best-effort and not required. */ + } else + s_is_failed = TRUE; + } + + _device_ip_state_accumulate(priv->ipshared_data_x[IS_IPv4].state, + &s_is_started, + &s_is_pending, + &s_is_failed); + + _device_ip_state_accumulate(priv->ipdev_data_x[IS_IPv4].state, + &s_is_started, + &s_is_pending, + &s_is_failed); + + _device_ip_state_accumulate(priv->ipdev_data_unspec.state, + &s_is_started, + &s_is_pending, + &s_is_failed); + + if (s_is_failed) + ip_state = NM_DEVICE_IP_STATE_FAILED; + else if (s_is_pending) + ip_state = NM_DEVICE_IP_STATE_PENDING; + else if (s_is_started) + ip_state = NM_DEVICE_IP_STATE_READY; + else + ip_state = NM_DEVICE_IP_STATE_PENDING; + +got_ip_state: + +#define _state_str_a(state, name) \ + ({ \ + const NMDeviceIPState _state = (state); \ + char *_s = ""; \ + \ + if (_state != NM_DEVICE_IP_STATE_NONE) { \ + _s = nm_sprintf_bufa(NM_STRLEN(name) + 11, \ + " " name "=%s", \ + nm_device_ip_state_to_string(_state)); \ + } \ + _s; \ + }) + + nm_assert(!priv->ip_data_4.is_ignore); + + _LOGT_ip(addr_family, + "check-state: state %s => %s, is_failed=%d, is_pending=%d, is_started=%d, " + "may-fail-4=%d, may-fail-6=%d;" + "%s;%s%s%s%s%s%s;%s%s%s%s%s%s%s%s", + nm_device_ip_state_to_string(priv->ip_data_x[IS_IPv4].state), + nm_device_ip_state_to_string(ip_state), + s_is_failed, + s_is_pending, + s_is_started, + _prop_get_ipvx_may_fail_cached(self, AF_INET, IS_IPv4 ? &may_fail : &may_fail_other), + _prop_get_ipvx_may_fail_cached(self, AF_INET6, !IS_IPv4 ? &may_fail : &may_fail_other), + priv->ip_data_4.is_disabled ? " disabled4" : "", + _state_str_a(priv->ipmanual_data.state_4, "manualip4"), + _state_str_a(priv->ipdev_data_unspec.state, "dev"), + _state_str_a(priv->ipll_data_4.state, "ll4"), + _state_str_a(priv->ipdhcp_data_4.state, "dhcp4"), + _state_str_a(priv->ipdev_data_4.state, "dev4"), + _state_str_a(priv->ipshared_data_4.state, "shared4"), + priv->ip_data_6.is_disabled ? " disabled6" : "", + priv->ip_data_6.is_ignore ? " ignore6" : "", + _state_str_a(priv->ipmanual_data.state_6, "manualip6"), + _state_str_a(priv->ipll_data_6.state, "ll6"), + _state_str_a(priv->ipac6_data.state, "ac6"), + _state_str_a(priv->ipdhcp_data_6.state, "dhcp6"), + _state_str_a(priv->ipdev_data_6.state, "dev6"), + _state_str_a(priv->ipshared_data_6.state, "shared6")); + + if (priv->ip_data_x[IS_IPv4].state == ip_state) { + /* no change. We can stop here. However, we also cancel the pending check, if any, + * because we just determined that there is no change. */ + } else { + _dev_ip_state_set_state(self, addr_family, ip_state, "check-ip-state"); } - platform = nm_device_get_platform(self); - plink = nm_platform_link_get(platform, ifindex); - if (!plink) { - nm_utils_error_set(error, NM_UTILS_ERROR_UNKNOWN, "link %d not found", ifindex); - return FALSE; + if (ip_state == NM_DEVICE_IP_STATE_NONE) { + /* Nothing to do. This almost cannot happen, and there is probably nothing + * to do about this case. */ + goto out_done; } - if (!nm_streq(plink->name, nm_device_get_iface(self))) { - gboolean up; - gboolean success; - gs_free char *name = NULL; + ip_state_other = priv->ip_data_x[!IS_IPv4].state; - up = NM_FLAGS_HAS(plink->n_ifi_flags, IFF_UP); - name = g_strdup(plink->name); + if (ip_state == NM_DEVICE_IP_STATE_READY) { + /* we only set NM_ACTIVATION_STATE_FLAG_IP_READY_X() flag once we reach NM_DEVICE_IP_STATE_READY state. + * We don't ever clear it, even if we later enter NM_DEVICE_IP_STATE_FAILED state. + * + * This is not documented/guaranteed behavior, but seems to make sense for now. */ + _active_connection_set_state_flags(self, NM_ACTIVATION_STATE_FLAG_IP_READY_X(IS_IPv4)); + } + + if (ip_state == NM_DEVICE_IP_STATE_READY && ip_state_other == NM_DEVICE_IP_STATE_READY) + combinedip_state = NM_DEVICE_IP_STATE_READY; + else if (ip_state == NM_DEVICE_IP_STATE_READY && ip_state_other == NM_DEVICE_IP_STATE_PENDING + && disabled_or_ignore) { + /* This IP method is disabled/ignore, but the other family is still pending. + * Regardless of ipvx.may-fail, this means that we always require the other IP family + * to get ready too. */ + combinedip_state = NM_DEVICE_IP_STATE_PENDING; + } else if (ip_state == NM_DEVICE_IP_STATE_READY && ip_state_other == NM_DEVICE_IP_STATE_PENDING + && (priv->ip_data_x[!IS_IPv4].req_timeout_source + || !_prop_get_ipvx_may_fail_cached(self, + nm_utils_addr_family_other(addr_family), + &may_fail_other))) + combinedip_state = NM_DEVICE_IP_STATE_PENDING; + else if (ip_state == NM_DEVICE_IP_STATE_READY + && _prop_get_ipvx_may_fail_cached(self, + nm_utils_addr_family_other(addr_family), + &may_fail_other)) + combinedip_state = NM_DEVICE_IP_STATE_READY; + else if (ip_state == NM_DEVICE_IP_STATE_FAILED + && !_prop_get_ipvx_may_fail_cached(self, addr_family, &may_fail)) + combinedip_state = NM_DEVICE_IP_STATE_FAILED; + else if ((ip_state == NM_DEVICE_IP_STATE_FAILED + || (ip_state == NM_DEVICE_IP_STATE_READY && disabled_or_ignore)) + && (ip_state_other == NM_DEVICE_IP_STATE_FAILED + || (ip_state_other == NM_DEVICE_IP_STATE_READY && disabled_or_ignore_other))) { + /* If both IP states failed, or one failed and the other is disabled + * then it's a failure. may-fail does not mean that both families may + * fail, instead it means that at least one family must succeed. */ + if (nm_device_sys_iface_state_is_external_or_assume(self)) { + _dev_ip_state_set_state(self, AF_INET, NM_DEVICE_IP_STATE_READY, "assumed"); + _dev_ip_state_set_state(self, AF_INET6, NM_DEVICE_IP_STATE_READY, "assumed"); + combinedip_state = NM_DEVICE_IP_STATE_READY; + } else { + combinedip_state = NM_DEVICE_IP_STATE_FAILED; + } + } else { + if (priv->ip_data.state == NM_DEVICE_IP_STATE_NONE) + combinedip_state = NM_DEVICE_IP_STATE_PENDING; + else + combinedip_state = priv->ip_data.state; + } - /* Rename the link to the device ifname */ - if (up) - nm_platform_link_change_flags(platform, ifindex, IFF_UP, FALSE); - success = nm_platform_link_set_name(platform, ifindex, nm_device_get_iface(self)); - if (up) - nm_platform_link_change_flags(platform, ifindex, IFF_UP, TRUE); + _LOGT_ip(AF_UNSPEC, + "check-state: (combined) state %s => %s", + nm_device_ip_state_to_string(priv->ip_data.state), + nm_device_ip_state_to_string(combinedip_state)); - if (!success) { - nm_utils_error_set(error, NM_UTILS_ERROR_UNKNOWN, "failure renaming link %d", ifindex); - return FALSE; - } + if (!_dev_ip_state_set_state(self, AF_UNSPEC, combinedip_state, "check-ip-state")) + goto out_done; - NM_SET_OUT(old_name, g_steal_pointer(&name)); + switch (combinedip_state) { + case NM_DEVICE_IP_STATE_PENDING: + break; + case NM_DEVICE_IP_STATE_READY: + _dev_ip_state_req_timeout_cancel(self, AF_UNSPEC); + if (priv->state == NM_DEVICE_STATE_IP_CONFIG) { + nm_device_state_changed(self, NM_DEVICE_STATE_IP_CHECK, NM_DEVICE_STATE_REASON_NONE); + } + break; + case NM_DEVICE_IP_STATE_FAILED: + nm_device_state_changed(self, + NM_DEVICE_STATE_FAILED, + NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); + break; + case NM_DEVICE_IP_STATE_NONE: + default: + nm_assert_not_reached(); } - _set_ifindex(self, ifindex, FALSE); - - return TRUE; +out_done: + /* we just checked the state. We can cancel the pending async check. */ + nm_clear_g_source_inst(&priv->ip_data_x[IS_IPv4].check_async_source); } -int -nm_device_get_ifindex(NMDevice *self) +static gboolean +_dev_ip_state_check_async_cb(NMDevice *self, int addr_family) { - g_return_val_if_fail(NM_IS_DEVICE(self), 0); - - return NM_DEVICE_GET_PRIVATE(self)->ifindex; + _dev_ip_state_check(self, addr_family); + return G_SOURCE_CONTINUE; } -/** - * nm_device_is_software: - * @self: the #NMDevice - * - * Indicates if the device is a software-based virtual device without - * backing hardware, which can be added and removed programmatically. - * - * Returns: %TRUE if the device is a software-based device - */ -gboolean -nm_device_is_software(NMDevice *self) +static gboolean +_dev_ip_state_check_async_cb_4(gpointer user_data) { - return NM_FLAGS_HAS(NM_DEVICE_GET_PRIVATE(self)->capabilities, NM_DEVICE_CAP_IS_SOFTWARE); + return _dev_ip_state_check_async_cb(user_data, AF_INET); } -/** - * nm_device_is_real: - * @self: the #NMDevice - * - * Returns: %TRUE if the device exists, %FALSE if the device is a placeholder - */ -gboolean -nm_device_is_real(NMDevice *self) +static gboolean +_dev_ip_state_check_async_cb_6(gpointer user_data) { - g_return_val_if_fail(NM_IS_DEVICE(self), FALSE); - - return NM_DEVICE_GET_PRIVATE(self)->real; + return _dev_ip_state_check_async_cb(user_data, AF_INET6); } -const char * -nm_device_get_ip_iface(NMDevice *self) +static void +_dev_ip_state_check_async(NMDevice *self, int addr_family) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + int IS_IPv4; + + if (addr_family == AF_UNSPEC) { + _dev_ip_state_check_async(self, AF_INET); + _dev_ip_state_check_async(self, AF_INET6); + return; + } + + IS_IPv4 = NM_IS_IPv4(addr_family); + if (!priv->ip_data_x[IS_IPv4].check_async_source) { + priv->ip_data_x[IS_IPv4].check_async_source = nm_g_idle_add_source( + (IS_IPv4 ? _dev_ip_state_check_async_cb_4 : _dev_ip_state_check_async_cb_6), + self); + } +} + +static void +_dev_ip_state_cleanup(NMDevice *self, int addr_family, gboolean from_reapply) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + int IS_IPv4; + + if (addr_family == AF_UNSPEC) { + _dev_ip_state_set_state(self, + addr_family, + from_reapply ? NM_DEVICE_IP_STATE_PENDING : NM_DEVICE_IP_STATE_NONE, + "ip-state-clear"); + return; + } + + IS_IPv4 = NM_IS_IPv4(addr_family); + + nm_clear_g_source_inst(&priv->ip_data_x[IS_IPv4].check_async_source); + nm_clear_g_source_inst(&priv->ip_data_x[IS_IPv4].req_timeout_source); + _dev_ip_state_set_state(self, + addr_family, + from_reapply ? NM_DEVICE_IP_STATE_PENDING : NM_DEVICE_IP_STATE_NONE, + "ip-state-clear"); + priv->ip_data_x[IS_IPv4].wait_for_carrier = FALSE; + priv->ip_data_x[IS_IPv4].wait_for_ports = FALSE; + priv->ip_data_x[IS_IPv4].is_disabled = FALSE; + priv->ip_data_x[IS_IPv4].is_ignore = FALSE; + priv->ip_data_x[IS_IPv4].do_reapply = FALSE; +} + +/*****************************************************************************/ + +static gpointer +_dev_l3_config_data_tag_get(NMDevicePrivate *priv, L3ConfigDataType l3cd_type) +{ + nm_assert(_NM_INT_NOT_NEGATIVE(l3cd_type) && l3cd_type < G_N_ELEMENTS(priv->l3cds)); + + return &priv->l3cds[l3cd_type]; +} + +static L3ConfigDataType +_dev_l3_config_data_tag_to_type(NMDevice *self, gconstpointer tag) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + int d; + + /* In C it is undefined behavior to compare unrelated pointers. + * Work around that by using nm_ptr_to_uintptr(), which casts the pointers + * to integers. + * + * I guess, theoretically it's still a problem to assume that if tag pointers + * somewhere inside priv->l3cds, that the uintptr_t case would also yield + * a value in that range. In practice, I couldn't imaging this not not work + * reliably. */ + + if (nm_ptr_to_uintptr(tag) < nm_ptr_to_uintptr(&priv->l3cds[0]) + || nm_ptr_to_uintptr(tag) >= nm_ptr_to_uintptr(&priv->l3cds[G_N_ELEMENTS(priv->l3cds)])) + return _L3_CONFIG_DATA_TYPE_NONE; + + d = ((typeof(priv->l3cds[0]) *) tag) - (&priv->l3cds[0]); + + nm_assert(d >= 0); + nm_assert(d < _L3_CONFIG_DATA_TYPE_NUM); + nm_assert(tag == &priv->l3cds[d]); + nm_assert(tag == _dev_l3_config_data_tag_get(priv, d)); + return d; +} + +static L3ConfigDataType +_dev_l3_config_data_acd_addr_info_to_type(NMDevice *self, + const NML3AcdAddrInfo *addr_info, + guint i_track_infos) +{ + nm_assert(NM_IS_DEVICE(self)); + nm_assert(addr_info); + nm_assert(i_track_infos < addr_info->n_track_infos); + + return _dev_l3_config_data_tag_to_type(self, addr_info->track_infos[i_track_infos].tag); +} + +// FIXME(l3cfg): unused function?? +_nm_unused static const NML3AcdAddrTrackInfo * +_dev_l3_config_data_acd_addr_info_has_by_type(NMDevice *self, + const NML3AcdAddrInfo *addr_info, + L3ConfigDataType l3cd_type) +{ + guint i; + + nm_assert(NM_IS_DEVICE(self)); + nm_assert(addr_info); + nm_assert(_NM_INT_NOT_NEGATIVE(l3cd_type) && l3cd_type < _L3_CONFIG_DATA_TYPE_NUM); + + for (i = 0; i < addr_info->n_track_infos; i++) { + if (l3cd_type == _dev_l3_config_data_acd_addr_info_to_type(self, addr_info, i)) + return &addr_info->track_infos[i]; + } + return NULL; +} + +static void +_dev_l3_get_config_settings(NMDevice *self, + L3ConfigDataType type, + NML3ConfigMergeFlags *out_merge_flags, + NML3AcdDefendType *out_acd_defend_type, + guint32 *out_acd_timeout_msec) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NML3ConfigMergeFlags flags; + NMConnection *connection; + NMSettingIPConfig *s_ip; + + nm_assert(_NM_INT_NOT_NEGATIVE(type) && type < _L3_CONFIG_DATA_TYPE_NUM); + + if (G_UNLIKELY(!priv->l3config_merge_flags_has)) { + int IS_IPv4; + + connection = nm_device_get_applied_connection(self); + + for (IS_IPv4 = 0; IS_IPv4 < 2; IS_IPv4++) { + flags = NM_L3_CONFIG_MERGE_FLAGS_NONE; + + if (connection + && (s_ip = nm_connection_get_setting_ip_config(connection, + IS_IPv4 ? AF_INET : AF_INET6))) { + if (nm_setting_ip_config_get_ignore_auto_routes(s_ip)) + flags |= NM_L3_CONFIG_MERGE_FLAGS_NO_ROUTES; + + if (nm_setting_ip_config_get_ignore_auto_dns(s_ip)) + flags |= NM_L3_CONFIG_MERGE_FLAGS_NO_DNS; + + if (nm_setting_ip_config_get_never_default(s_ip) + || nm_setting_ip_config_get_gateway(s_ip)) { + /* if the connection has an explicit gateway, we also ignore + * the default routes from other sources. */ + flags |= NM_L3_CONFIG_MERGE_FLAGS_NO_DEFAULT_ROUTES; + } + } + + priv->l3config_merge_flags_x[IS_IPv4] = flags; + } + priv->l3config_merge_flags_has = TRUE; + } + + switch (type) { + case L3_CONFIG_DATA_TYPE_DEVIP_UNSPEC: + case L3_CONFIG_DATA_TYPE_MANUALIP: + case L3_CONFIG_DATA_TYPE_LL_4: + case L3_CONFIG_DATA_TYPE_LL_6: + case L3_CONFIG_DATA_TYPE_PD_6: + case L3_CONFIG_DATA_TYPE_SHARED_4: + case L3_CONFIG_DATA_TYPE_DEVIP_4: + case L3_CONFIG_DATA_TYPE_AC_6: + case L3_CONFIG_DATA_TYPE_DHCP_6: + case L3_CONFIG_DATA_TYPE_DEVIP_6: + *out_acd_timeout_msec = _prop_get_ipv4_dad_timeout(self); + goto after_acd_timeout; + + case L3_CONFIG_DATA_TYPE_DHCP_4: + /* For DHCP, we perform ACD separately, because we want to decline the + * lease in case of a conflict. */ + *out_acd_timeout_msec = 0; + goto after_acd_timeout; + + case _L3_CONFIG_DATA_TYPE_NUM: + case _L3_CONFIG_DATA_TYPE_NONE: + case _L3_CONFIG_DATA_TYPE_ACD_ONLY: + break; + } + *out_acd_timeout_msec = nm_assert_unreachable_val(0); + +after_acd_timeout: + switch (type) { + case L3_CONFIG_DATA_TYPE_LL_4: + *out_acd_defend_type = NM_L3_ACD_DEFEND_TYPE_ONCE; + goto after_acd_defend_type; + + case L3_CONFIG_DATA_TYPE_DEVIP_UNSPEC: + case L3_CONFIG_DATA_TYPE_MANUALIP: + case L3_CONFIG_DATA_TYPE_LL_6: + case L3_CONFIG_DATA_TYPE_PD_6: + case L3_CONFIG_DATA_TYPE_SHARED_4: + case L3_CONFIG_DATA_TYPE_DHCP_4: + case L3_CONFIG_DATA_TYPE_DEVIP_4: + case L3_CONFIG_DATA_TYPE_AC_6: + case L3_CONFIG_DATA_TYPE_DHCP_6: + case L3_CONFIG_DATA_TYPE_DEVIP_6: + *out_acd_defend_type = NM_L3_ACD_DEFEND_TYPE_ALWAYS; + goto after_acd_defend_type; + + case _L3_CONFIG_DATA_TYPE_NUM: + case _L3_CONFIG_DATA_TYPE_NONE: + case _L3_CONFIG_DATA_TYPE_ACD_ONLY: + break; + } + *out_acd_defend_type = nm_assert_unreachable_val(NM_L3_ACD_DEFEND_TYPE_ALWAYS); + +after_acd_defend_type: + switch (type) { + case L3_CONFIG_DATA_TYPE_DEVIP_UNSPEC: + case L3_CONFIG_DATA_TYPE_MANUALIP: + case L3_CONFIG_DATA_TYPE_LL_4: + case L3_CONFIG_DATA_TYPE_LL_6: + case L3_CONFIG_DATA_TYPE_PD_6: + case L3_CONFIG_DATA_TYPE_SHARED_4: + *out_merge_flags = NM_L3_CONFIG_MERGE_FLAGS_NONE; + goto after_merge_flags; + + case L3_CONFIG_DATA_TYPE_DHCP_4: + case L3_CONFIG_DATA_TYPE_DEVIP_4: + *out_merge_flags = priv->l3config_merge_flags_4; + goto after_merge_flags; + + case L3_CONFIG_DATA_TYPE_AC_6: + case L3_CONFIG_DATA_TYPE_DHCP_6: + case L3_CONFIG_DATA_TYPE_DEVIP_6: + *out_merge_flags = priv->l3config_merge_flags_6; + goto after_merge_flags; + + case _L3_CONFIG_DATA_TYPE_NUM: + case _L3_CONFIG_DATA_TYPE_NONE: + case _L3_CONFIG_DATA_TYPE_ACD_ONLY: + break; + } + *out_merge_flags = nm_assert_unreachable_val(NM_L3_CONFIG_MERGE_FLAGS_NONE); + +after_merge_flags: + return; +} + +static gboolean +_dev_l3_register_l3cds_add_config(NMDevice *self, + L3ConfigDataType l3cd_type, + NML3CfgConfigFlags flags) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NML3ConfigMergeFlags merge_flags; + NML3AcdDefendType acd_defend_type; + guint32 acd_timeout_msec; + + _dev_l3_get_config_settings(self, l3cd_type, &merge_flags, &acd_defend_type, &acd_timeout_msec); + return nm_l3cfg_add_config(priv->l3cfg, + _dev_l3_config_data_tag_get(priv, l3cd_type), + FALSE, + priv->l3cds[l3cd_type].d, + l3cd_type, + nm_device_get_route_table(self, AF_INET), + nm_device_get_route_table(self, AF_INET6), + nm_device_get_route_metric(self, AF_INET), + nm_device_get_route_metric(self, AF_INET6), + _dev_default_route_metric_penalty_get(self, AF_INET), + _dev_default_route_metric_penalty_get(self, AF_INET6), + _prop_get_ipvx_dns_priority(self, AF_INET), + _prop_get_ipvx_dns_priority(self, AF_INET6), + acd_defend_type, + acd_timeout_msec, + flags, + merge_flags); +} + +static gboolean +_dev_l3_register_l3cds_set_one_full(NMDevice *self, + L3ConfigDataType l3cd_type, + const NML3ConfigData *l3cd, + NML3CfgConfigFlags flags, + NMTernary commit_sync) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + nm_auto_unref_l3cd const NML3ConfigData *l3cd_old = NULL; + gboolean changed = FALSE; + + if (priv->l3cds[l3cd_type].d != l3cd) { + if (nm_l3_config_data_equal(priv->l3cds[l3cd_type].d, l3cd)) { + /* we would set to a different instance, but the same content! + * We keep the previous one and ignore the new @l3cd. + * + * Warning: this means, that after calling this function, + * priv->l3cds[l3cd_type].d still might point to a different + * (though semantically equal) l3cd instance. */ + } else { + l3cd_old = g_steal_pointer(&priv->l3cds[l3cd_type].d); + if (l3cd) + priv->l3cds[l3cd_type].d = nm_l3_config_data_ref_and_seal(l3cd); + } + } + + if (priv->l3cfg) { + if (priv->l3cds[l3cd_type].d) { + if (_dev_l3_register_l3cds_add_config(self, l3cd_type, flags)) + changed = TRUE; + } + + if (l3cd_old) { + if (nm_l3cfg_remove_config(priv->l3cfg, + _dev_l3_config_data_tag_get(priv, l3cd_type), + l3cd_old)) + changed = TRUE; + } + } + + if (changed && commit_sync != NM_TERNARY_DEFAULT) + _dev_l3_cfg_commit(self, !!commit_sync); + + return changed; +} + +static gboolean +_dev_l3_register_l3cds_set_one(NMDevice *self, + L3ConfigDataType l3cd_type, + const NML3ConfigData *l3cd, + NMTernary commit_sync) +{ + return _dev_l3_register_l3cds_set_one_full(self, + l3cd_type, + l3cd, + NM_L3CFG_CONFIG_FLAGS_NONE, + commit_sync); +} + +static void +_dev_l3_update_l3cds_ifindex(NMDevice *self) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + int ip_ifindex; + int i; + + ip_ifindex = nm_device_get_ip_ifindex(self); + if (ip_ifindex <= 0) + return; + + for (i = 0; i < (int) G_N_ELEMENTS(priv->l3cds); i++) { + if (priv->l3cds[i].d && nm_l3_config_data_get_ifindex(priv->l3cds[i].d) != ip_ifindex) { + nm_auto_unref_l3cd const NML3ConfigData *l3cd_old = NULL; + + l3cd_old = g_steal_pointer(&priv->l3cds[i].d); + + priv->l3cds[i].d = + nm_l3_config_data_seal(nm_l3_config_data_new_clone(l3cd_old, ip_ifindex)); + } + } +} + +static gboolean +_dev_l3_register_l3cds(NMDevice *self, + NML3Cfg *l3cfg, + gboolean do_add /* else remove */, + NMTernary do_commit) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + gboolean is_external; + gboolean changed; + int i; + + if (!l3cfg) + return FALSE; + + is_external = nm_device_sys_iface_state_is_external(self); + + changed = FALSE; + for (i = 0; i < (int) G_N_ELEMENTS(priv->l3cds); i++) { + if (!priv->l3cds[i].d) + continue; + if (!do_add) { + if (nm_l3cfg_remove_config(l3cfg, + _dev_l3_config_data_tag_get(priv, i), + priv->l3cds[i].d)) + changed = TRUE; + continue; + } + if (is_external) + continue; + if (_dev_l3_register_l3cds_add_config(self, i, NM_L3CFG_CONFIG_FLAGS_NONE)) + changed = TRUE; + } + + if (do_commit == NM_TERNARY_DEFAULT) + do_commit = changed; + if (do_commit) + _dev_l3_cfg_commit(self, TRUE); + + return changed; +} + +/*****************************************************************************/ + +void +nm_device_l3cfg_commit(NMDevice *self, NML3CfgCommitType commit_type, gboolean commit_sync) +{ + NMDevicePrivate *priv; + + g_return_if_fail(NM_IS_DEVICE(self)); + + priv = NM_DEVICE_GET_PRIVATE(self); + + if (!priv->l3cfg) + return; + + /* FIXME(l3cfg): commit_sync should go away and not be used. The reason is that + * a commit does *a lot* of things which are outside the control of the caller, + * which makes it unsuitable to call in most cases. */ + if (!commit_sync) { + nm_l3cfg_commit_on_idle_schedule(priv->l3cfg, commit_type); + return; + } + + nm_l3cfg_commit(priv->l3cfg, commit_type); +} + +static void +_dev_l3_cfg_commit(NMDevice *self, gboolean commit_sync) +{ + nm_device_l3cfg_commit(self, NM_L3_CFG_COMMIT_TYPE_AUTO, commit_sync); +} + +static void +update_external_connection(NMDevice *self) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NMSettingsConnection *settings_connection; + gs_unref_object NMConnection *connection_new = NULL; + NMConnection *connection_old; + gs_unref_object NMSetting *s_ip4_new = NULL; + gs_unref_object NMSetting *s_ip6_new = NULL; + NMSetting *s_ip4_old; + NMSetting *s_ip6_old; + + /* Update external connections with configuration from platform */ + + if (!nm_device_sys_iface_state_is_external(self)) + return; + + settings_connection = nm_device_get_settings_connection(self); + if (!settings_connection) + return; + + if (!NM_FLAGS_HAS(nm_settings_connection_get_flags(settings_connection), + NM_SETTINGS_CONNECTION_INT_FLAGS_EXTERNAL)) + return; + + if (nm_active_connection_get_activation_type(NM_ACTIVE_CONNECTION(priv->act_request.obj)) + != NM_ACTIVATION_TYPE_EXTERNAL) + return; + + connection_old = nm_settings_connection_get_connection(settings_connection); + s_ip4_old = nm_connection_get_setting(connection_old, NM_TYPE_SETTING_IP4_CONFIG); + s_ip6_old = nm_connection_get_setting(connection_old, NM_TYPE_SETTING_IP6_CONFIG); + + s_ip4_new = nm_utils_platform_capture_ip_setting(nm_device_get_platform(self), + AF_INET, + nm_device_get_ip_ifindex(self), + FALSE); + s_ip6_new = nm_utils_platform_capture_ip_setting(nm_device_get_platform(self), + AF_INET6, + nm_device_get_ip_ifindex(self), + _get_maybe_ipv6_disabled(self)); + + if (!s_ip4_old || !nm_setting_compare(s_ip4_new, s_ip4_old, NM_SETTING_COMPARE_FLAG_EXACT)) { + connection_new = nm_simple_connection_new_clone(connection_old); + nm_connection_add_setting(connection_new, g_steal_pointer(&s_ip4_new)); + } + + if (!s_ip6_old || !nm_setting_compare(s_ip6_new, s_ip6_old, NM_SETTING_COMPARE_FLAG_EXACT)) { + if (!connection_new) + connection_new = nm_simple_connection_new_clone(connection_old); + nm_connection_add_setting(connection_new, g_steal_pointer(&s_ip6_new)); + } + + if (connection_new) { + nm_settings_connection_update(settings_connection, + connection_new, + NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY, + NM_SETTINGS_CONNECTION_INT_FLAGS_NONE, + NM_SETTINGS_CONNECTION_INT_FLAGS_NONE, + NM_SETTINGS_CONNECTION_UPDATE_REASON_UPDATE_NON_SECRET, + "update-external", + NULL); + } +} + +static void +_dev_l3_cfg_notify_cb(NML3Cfg *l3cfg, const NML3ConfigNotifyData *notify_data, NMDevice *self) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + + nm_assert(l3cfg == priv->l3cfg); + + switch (notify_data->notify_type) { + case NM_L3_CONFIG_NOTIFY_TYPE_L3CD_CHANGED: + if (notify_data->l3cd_changed.commited) { + g_signal_emit(self, + signals[L3CD_CHANGED], + 0, + notify_data->l3cd_changed.l3cd_old, + notify_data->l3cd_changed.l3cd_new); + } + return; + case NM_L3_CONFIG_NOTIFY_TYPE_ACD_EVENT: + { + const NML3AcdAddrInfo *addr_info = ¬ify_data->acd_event.info; + + if (addr_info->state > NM_L3_ACD_ADDR_STATE_PROBING) + _dev_ipmanual_check_ready(self); + return; + } + case NM_L3_CONFIG_NOTIFY_TYPE_PRE_COMMIT: + { + const NML3ConfigData *l3cd; + + /* FIXME(l3cfg): MTU handling should be moved to l3cfg. */ + l3cd = nm_l3cfg_get_combined_l3cd(l3cfg, TRUE); + if (l3cd) + priv->ip6_mtu = nm_l3_config_data_get_ip6_mtu(l3cd); + _commit_mtu(self); + return; + } + case NM_L3_CONFIG_NOTIFY_TYPE_POST_COMMIT: + if (priv->ipshared_data_4.state == NM_DEVICE_IP_STATE_PENDING + && !priv->ipshared_data_4.v4.dnsmasq_manager && priv->ipshared_data_4.v4.l3cd) { + _dev_ipshared4_spawn_dnsmasq(self); + nm_clear_l3cd(&priv->ipshared_data_4.v4.l3cd); + } + _dev_ipmanual_check_ready(self); + return; + case NM_L3_CONFIG_NOTIFY_TYPE_IPV4LL_EVENT: + nm_assert(NM_IS_L3_IPV4LL(notify_data->ipv4ll_event.ipv4ll)); + if (priv->ipll_data_4.v4.ipv4ll == notify_data->ipv4ll_event.ipv4ll) + _dev_ipll4_notify_event(self); + return; + case NM_L3_CONFIG_NOTIFY_TYPE_PLATFORM_CHANGE: + return; + case NM_L3_CONFIG_NOTIFY_TYPE_ROUTES_TEMPORARY_NOT_AVAILABLE_EXPIRED: + /* we commit again. This way we try to configure the routes.*/ + _dev_l3_cfg_commit(self, FALSE); + return; + case NM_L3_CONFIG_NOTIFY_TYPE_PLATFORM_CHANGE_ON_IDLE: + if (NM_FLAGS_ANY(notify_data->platform_change_on_idle.obj_type_flags, + nmp_object_type_to_flags(NMP_OBJECT_TYPE_LINK) + | nmp_object_type_to_flags(NMP_OBJECT_TYPE_IP4_ADDRESS) + | nmp_object_type_to_flags(NMP_OBJECT_TYPE_IP6_ADDRESS))) + _dev_unmanaged_check_external_down(self, TRUE, TRUE); + + if (NM_FLAGS_ANY(notify_data->platform_change_on_idle.obj_type_flags, + nmp_object_type_to_flags(NMP_OBJECT_TYPE_IP4_ADDRESS) + | nmp_object_type_to_flags(NMP_OBJECT_TYPE_IP6_ADDRESS))) { + g_signal_emit(self, signals[PLATFORM_ADDRESS_CHANGED], 0); + } + + /* Check if AC6 addresses completed DAD */ + if (NM_FLAGS_ANY(notify_data->platform_change_on_idle.obj_type_flags, + nmp_object_type_to_flags(NMP_OBJECT_TYPE_IP6_ADDRESS)) + && priv->ipac6_data.state == NM_DEVICE_IP_STATE_PENDING && priv->ipac6_data.l3cd + && nm_l3cfg_check_ready(l3cfg, + priv->ipac6_data.l3cd, + AF_INET6, + NM_L3CFG_CHECK_READY_FLAGS_IP6_DAD_READY, + NULL)) { + nm_clear_l3cd(&priv->ipac6_data.l3cd); + _dev_ipac6_set_state(self, NM_DEVICE_IP_STATE_READY); + _dev_ip_state_check_async(self, AF_INET6); + } + + _dev_ipmanual_check_ready(self); + update_external_connection(self); + nm_device_queue_recheck_assume(self); + return; + + case _NM_L3_CONFIG_NOTIFY_TYPE_NUM: + break; + } + nm_assert_not_reached(); +} + +static void +_dev_l3_cfg_commit_type_reset(NMDevice *self) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NML3CfgCommitType commit_type; + + if (!priv->l3cfg) + return; + + switch (priv->sys_iface_state) { + case NM_DEVICE_SYS_IFACE_STATE_EXTERNAL: + case NM_DEVICE_SYS_IFACE_STATE_REMOVED: + commit_type = NM_L3_CFG_COMMIT_TYPE_NONE; + goto do_set; + case NM_DEVICE_SYS_IFACE_STATE_ASSUME: + commit_type = NM_L3_CFG_COMMIT_TYPE_ASSUME; + goto do_set; + case NM_DEVICE_SYS_IFACE_STATE_MANAGED: + commit_type = NM_L3_CFG_COMMIT_TYPE_UPDATE; + goto do_set; + } + nm_assert_not_reached(); + return; + +do_set: + priv->l3cfg_commit_type = + nm_l3cfg_commit_type_register(priv->l3cfg, commit_type, priv->l3cfg_commit_type, "device"); + if (commit_type == NM_L3_CFG_COMMIT_TYPE_NONE) + nm_l3cfg_commit_type_reset_update(priv->l3cfg); +} + +/*****************************************************************************/ + +const char * +nm_device_get_udi(NMDevice *self) +{ + g_return_val_if_fail(self != NULL, NULL); + + return NM_DEVICE_GET_PRIVATE(self)->udi; +} + +const char * +nm_device_get_iface(NMDevice *self) +{ + g_return_val_if_fail(NM_IS_DEVICE(self), NULL); + + return NM_DEVICE_GET_PRIVATE(self)->iface; +} + +static gboolean +_set_ifindex(NMDevice *self, int ifindex, gboolean is_ip_ifindex) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + gs_unref_object NML3Cfg *l3cfg_old = NULL; + NML3CfgCommitTypeHandle *l3cfg_commit_type_old = NULL; + gboolean l3_changed; + int ip_ifindex_new; + int *p_ifindex; + gboolean l3cfg_was_reset = FALSE; + + if (ifindex < 0) { + nm_assert_not_reached(); + ifindex = 0; + } + + p_ifindex = is_ip_ifindex ? &priv->ip_ifindex_ : &priv->ifindex_; + + if (*p_ifindex == ifindex) + return FALSE; + + *p_ifindex = ifindex; + + ip_ifindex_new = nm_device_get_ip_ifindex(self); + + if (priv->l3cfg) { + if (ip_ifindex_new <= 0 || ip_ifindex_new != nm_l3cfg_get_ifindex(priv->l3cfg)) { + const NML3ConfigData *l3cd_old; + + if (ip_ifindex_new <= 0) { + /* The ifindex was reset. Send a last L3CD_CHANGED + * signal with a NULL l3cd so that the old one can + * be removed from the DNS manager. + */ + l3cd_old = nm_l3cfg_get_combined_l3cd(priv->l3cfg, TRUE); + if (l3cd_old) + g_signal_emit(self, signals[L3CD_CHANGED], 0, l3cd_old, NULL); + } + + g_signal_handlers_disconnect_by_func(priv->l3cfg, + G_CALLBACK(_dev_l3_cfg_notify_cb), + self); + l3cfg_old = g_steal_pointer(&priv->l3cfg_); + l3cfg_commit_type_old = g_steal_pointer(&priv->l3cfg_commit_type); + l3cfg_was_reset = TRUE; + } + } + if (!priv->l3cfg && ip_ifindex_new > 0) { + priv->l3cfg_ = nm_netns_l3cfg_acquire(priv->netns, ip_ifindex_new); + + g_signal_connect(priv->l3cfg, + NM_L3CFG_SIGNAL_NOTIFY, + G_CALLBACK(_dev_l3_cfg_notify_cb), + self); + + _dev_l3_cfg_commit_type_reset(self); + l3cfg_was_reset = TRUE; + } + if (!priv->l3cfg) { + _cleanup_ip_pre(self, AF_INET, CLEANUP_TYPE_KEEP, FALSE); + _cleanup_ip_pre(self, AF_INET6, CLEANUP_TYPE_KEEP, FALSE); + } + + _LOGD(LOGD_DEVICE, + "ifindex: set %sifindex %d%s%s%s%s%s%s", + is_ip_ifindex ? "ip-" : "", + ifindex, + NM_PRINT_FMT_QUOTED(l3cfg_old && l3cfg_old != priv->l3cfg, + " (old-l3cfg: ", + nm_hash_obfuscated_ptr_str_a(l3cfg_old), + ")", + ""), + NM_PRINT_FMT_QUOTED(priv->l3cfg && l3cfg_old != priv->l3cfg, + " (l3cfg: ", + nm_hash_obfuscated_ptr_str_a(priv->l3cfg), + ")", + "")); + + if (priv->manager) + nm_manager_emit_device_ifindex_changed(priv->manager, self); + + if (!is_ip_ifindex) + _notify(self, PROP_IFINDEX); + + if (l3cfg_was_reset) { + gs_unref_object NMIPConfig *ipconf_old_4 = NULL; + gs_unref_object NMIPConfig *ipconf_old_6 = NULL; + + ipconf_old_4 = g_steal_pointer(&priv->l3ipdata_4.ip_config); + ipconf_old_6 = g_steal_pointer(&priv->l3ipdata_6.ip_config); + if (priv->l3cfg) { + priv->l3ipdata_4.ip_config = nm_l3cfg_ipconfig_acquire(priv->l3cfg, AF_INET); + priv->l3ipdata_6.ip_config = nm_l3cfg_ipconfig_acquire(priv->l3cfg, AF_INET6); + } + _notify(self, PROP_IP4_CONFIG); + _notify(self, PROP_IP6_CONFIG); + } + + if (l3cfg_old != priv->l3cfg) { + l3_changed = FALSE; + if (_dev_l3_register_l3cds(self, l3cfg_old, FALSE, FALSE)) + l3_changed = TRUE; + + /* Now it gets ugly. We changed the ip-ifindex, which determines the NML3Cfg instance. + * But all the NML3ConfigData we currently track are still for the old ifindex. We + * need to update them. + * + * This should be all handled entirely different, where an NMDevice is strictly + * associated with one ifindex (and not the ifindex/ip-ifindex split). Or it + * is not at all associated with an ifindex, but only a controlling device for + * a real NMDevice (that has the ifindex). */ + _dev_l3_update_l3cds_ifindex(self); + + if (_dev_l3_register_l3cds(self, priv->l3cfg, TRUE, FALSE)) + l3_changed = TRUE; + + if (l3_changed) + _dev_l3_cfg_commit(self, TRUE); + } + + if (l3cfg_commit_type_old) + nm_l3cfg_commit_type_unregister(l3cfg_old, l3cfg_commit_type_old); + + update_prop_ip_iface(self); + + return TRUE; +} + +/** + * nm_device_take_over_link: + * @self: the #NMDevice + * @ifindex: a ifindex + * @old_name: (transfer full): on return, the name of the old link, if + * the link was renamed + * @error: location to store error, or %NULL + * + * Given an existing link, move it under the control of a device. In + * particular, the link will be renamed to match the device name. If the + * link was renamed, the old name is returned in @old_name. + * + * Returns: %TRUE if the device took control of the link, %FALSE otherwise + */ +gboolean +nm_device_take_over_link(NMDevice *self, int ifindex, char **old_name, GError **error) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + const NMPlatformLink *plink; + NMPlatform *platform; + + nm_assert(ifindex > 0); + NM_SET_OUT(old_name, NULL); + + if (priv->ifindex > 0 && priv->ifindex != ifindex) { + nm_utils_error_set(error, + NM_UTILS_ERROR_UNKNOWN, + "the device already has ifindex %d", + priv->ifindex); + return FALSE; + } + + platform = nm_device_get_platform(self); + plink = nm_platform_link_get(platform, ifindex); + if (!plink) { + nm_utils_error_set(error, NM_UTILS_ERROR_UNKNOWN, "link %d not found", ifindex); + return FALSE; + } + + if (!nm_streq(plink->name, nm_device_get_iface(self))) { + gboolean up; + gboolean success; + gs_free char *name = NULL; + + up = NM_FLAGS_HAS(plink->n_ifi_flags, IFF_UP); + name = g_strdup(plink->name); + + /* Rename the link to the device ifname */ + if (up) + nm_platform_link_change_flags(platform, ifindex, IFF_UP, FALSE); + success = nm_platform_link_set_name(platform, ifindex, nm_device_get_iface(self)); + if (up) + nm_platform_link_change_flags(platform, ifindex, IFF_UP, TRUE); + + if (!success) { + nm_utils_error_set(error, NM_UTILS_ERROR_UNKNOWN, "failure renaming link %d", ifindex); + return FALSE; + } + + NM_SET_OUT(old_name, g_steal_pointer(&name)); + } + + _set_ifindex(self, ifindex, FALSE); + + return TRUE; +} + +int +nm_device_get_ifindex(NMDevice *self) +{ + g_return_val_if_fail(NM_IS_DEVICE(self), 0); + + return NM_DEVICE_GET_PRIVATE(self)->ifindex; +} + +/** + * nm_device_is_software: + * @self: the #NMDevice + * + * Indicates if the device is a software-based virtual device without + * backing hardware, which can be added and removed programmatically. + * + * Returns: %TRUE if the device is a software-based device + */ +gboolean +nm_device_is_software(NMDevice *self) +{ + return NM_FLAGS_HAS(NM_DEVICE_GET_PRIVATE(self)->capabilities, NM_DEVICE_CAP_IS_SOFTWARE); +} + +/** + * nm_device_is_real: + * @self: the #NMDevice + * + * Returns: %TRUE if the device exists, %FALSE if the device is a placeholder + */ +gboolean +nm_device_is_real(NMDevice *self) +{ + g_return_val_if_fail(NM_IS_DEVICE(self), FALSE); + + return NM_DEVICE_GET_PRIVATE(self)->real; +} + +const char * +nm_device_get_ip_iface(NMDevice *self) { NMDevicePrivate *priv; @@ -3140,7 +4269,7 @@ static void _set_ip_ifindex(NMDevice *self, int ifindex, const char *ifname) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - NMPlatform * platform; + NMPlatform *platform; gboolean eq_name; /* normalize arguments */ @@ -3159,13 +4288,12 @@ _set_ip_ifindex(NMDevice *self, int ifindex, const char *ifname) NM_PRINT_FMT_QUOTE_STRING(ifname), ifindex); - _set_ifindex(self, ifindex, TRUE); - if (!eq_name) { g_free(priv->ip_iface_); priv->ip_iface_ = g_strdup(ifname); - _notify(self, PROP_IP_IFACE); + update_prop_ip_iface(self); } + _set_ifindex(self, ifindex, TRUE); if (priv->ip_ifindex > 0) { platform = nm_device_get_platform(self); @@ -3265,10 +4393,10 @@ parent_changed_notify(NMDevice *self, static gboolean _parent_set_ifindex(NMDevice *self, int parent_ifindex, gboolean force_check) { - NMDevicePrivate *priv; - NMDevice * parent_device; - gboolean changed = FALSE; - int old_ifindex; + NMDevicePrivate *priv; + NMDevice *parent_device; + gboolean changed = FALSE; + int old_ifindex; gs_unref_object NMDevice *old_device = NULL; g_return_val_if_fail(NM_IS_DEVICE(self), FALSE); @@ -3359,7 +4487,7 @@ const char * nm_device_parent_find_for_connection(NMDevice *self, const char *current_setting_parent) { const char *new_parent; - NMDevice * parent_device; + NMDevice *parent_device; parent_device = nm_device_parent_get_device(self); if (!parent_device) @@ -3496,10 +4624,10 @@ _stats_set_refresh_rate(NMDevice *self, guint refresh_rate_ms) static gboolean get_ip_iface_identifier(NMDevice *self, NMUtilsIPv6IfaceId *out_iid) { - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - NMPlatform * platform = nm_device_get_platform(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NMPlatform *platform = nm_device_get_platform(self); const NMPlatformLink *pllink; - const guint8 * hwaddr; + const guint8 *hwaddr; guint8 pseudo_hwaddr[ETH_ALEN]; gsize hwaddr_len; int ifindex; @@ -3560,6 +4688,7 @@ get_ip_iface_identifier(NMDevice *self, NMUtilsIPv6IfaceId *out_iid) * @self: an #NMDevice * @iid: where to place the interface identifier * @ignore_token: force creation of a non-tokenized address + * @out_is_token: on return, whether the identifier is tokenized * * Return the interface's identifier for the EUI64 address generation mode. * It's either a manually set token or and identifier generated in a @@ -3571,19 +4700,26 @@ get_ip_iface_identifier(NMDevice *self, NMUtilsIPv6IfaceId *out_iid) * Returns: #TRUE if the @iid could be set */ static gboolean -nm_device_get_ip_iface_identifier(NMDevice *self, NMUtilsIPv6IfaceId *iid, gboolean ignore_token) +nm_device_get_ip_iface_identifier(NMDevice *self, + NMUtilsIPv6IfaceId *iid, + gboolean ignore_token, + gboolean *out_is_token) { NMSettingIP6Config *s_ip6; - const char * token = NULL; + const char *token = NULL; g_return_val_if_fail(NM_IS_DEVICE(self), FALSE); + NM_SET_OUT(out_is_token, FALSE); + if (!ignore_token) { s_ip6 = nm_device_get_applied_setting(self, NM_TYPE_SETTING_IP6_CONFIG); g_return_val_if_fail(s_ip6, FALSE); token = nm_setting_ip6_config_get_token(s_ip6); + if (token) + NM_SET_OUT(out_is_token, TRUE); } if (token) return nm_utils_ipv6_interface_identifier_get_from_token(iid, token); @@ -3729,29 +4865,16 @@ nm_device_get_route_metric_default(NMDeviceType device_type) return 11000; } -static gboolean -default_route_metric_penalty_detect(NMDevice *self, int addr_family) +static guint32 +_dev_default_route_metric_penalty_get(NMDevice *self, int addr_family) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); const int IS_IPv4 = NM_IS_IPv4(addr_family); - /* currently we don't differentiate between IPv4 and IPv6 when detecting - * connectivity. */ if (priv->concheck_x[IS_IPv4].state != NM_CONNECTIVITY_FULL && nm_connectivity_check_enabled(concheck_get_mgr(self))) - return TRUE; - - return FALSE; -} - -static guint32 -default_route_metric_penalty_get(NMDevice *self, int addr_family) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - - if (NM_IS_IPv4(addr_family) ? priv->default_route_metric_penalty_ip4_has - : priv->default_route_metric_penalty_ip6_has) return 20000; + return 0; } @@ -3760,8 +4883,8 @@ nm_device_get_route_metric(NMDevice *self, int addr_family) { gint64 route_metric; NMSettingIPConfig *s_ip; - NMConnection * connection; - const char * property; + NMConnection *connection; + const char *property; g_return_val_if_fail(NM_IS_DEVICE(self), G_MAXUINT32); g_return_val_if_fail(NM_IN_SET(addr_family, AF_INET, AF_INET6), G_MAXUINT32); @@ -3813,28 +4936,23 @@ nm_device_get_route_table(NMDevice *self, int addr_family) return route_table ?: (guint32) RT_TABLE_MAIN; } -static NMIPRouteTableSyncMode +/* FIXME(l3cfg): need to properly handle the route-table sync mode and + * use it during commit. */ +_nm_unused static NMIPRouteTableSyncMode _get_route_table_sync_mode_stateful(NMDevice *self, int addr_family) { - const int IS_IPv4 = NM_IS_IPv4(addr_family); - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - NMDedupMultiIter ipconf_iter; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); gboolean all_sync_now; gboolean all_sync_eff; all_sync_now = _prop_get_ipvx_route_table(self, addr_family) != 0u; if (!all_sync_now) { - const NMPlatformIPRoute *route; + const NML3ConfigData *l3cd = priv->l3cds[L3_CONFIG_DATA_TYPE_MANUALIP].d; /* If there's a local route switch to all-sync in order * to properly manage the local table */ - nm_ip_config_iter_ip_route_for_each (&ipconf_iter, priv->con_ip_config_x[IS_IPv4], &route) { - if (nm_platform_route_type_uncoerce(route->type_coerced) == RTN_LOCAL) { - all_sync_now = TRUE; - break; - } - } + all_sync_now = l3cd && nm_l3_config_data_has_routes_with_type_local(l3cd, addr_family); } if (all_sync_now) @@ -3866,18 +4984,20 @@ nm_device_get_best_default_route(NMDevice *self, int addr_family) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - switch (addr_family) { - case AF_INET: - return priv->ip_config_4 ? nm_ip4_config_best_default_route_get(priv->ip_config_4) : NULL; - case AF_INET6: - return priv->ip_config_6 ? nm_ip6_config_best_default_route_get(priv->ip_config_6) : NULL; - case AF_UNSPEC: - return (priv->ip_config_4 ? nm_ip4_config_best_default_route_get(priv->ip_config_4) : NULL) - ?: (priv->ip_config_6 ? nm_ip6_config_best_default_route_get(priv->ip_config_6) - : NULL); - default: - g_return_val_if_reached(NULL); - } + if (!priv->l3cfg) + return NULL; + + /* FIXME(l3cfg): this function returns the best default route that we + * *want* to configure. What is the meaning of that? Possibly the caller + * cares whether there *is* a default route configured, for which they + * should ask platform. + * + * Check callers why they call this. Quite possibly this whole notion of + * "has a default route" is wrong to being with, regardless whether we + * look at the desired or actual configuration. That is, because "has a default route" + * does not do justice to the complexity of routing (with policy routing, + * etc.). */ + return nm_l3cfg_get_best_default_route(priv->l3cfg, addr_family, TRUE); } const char * @@ -3982,7 +5102,7 @@ NMConnection * nm_device_get_settings_connection_get_connection(NMDevice *self) { NMSettingsConnection *sett_con; - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); if (!priv->act_request.obj) return NULL; @@ -4055,7 +5175,7 @@ typedef enum { CONCHECK_SCHEDULE_RETURNED_MAX, } ConcheckScheduleMode; -static NMDeviceConnectivityHandle *concheck_start(NMDevice * self, +static NMDeviceConnectivityHandle *concheck_start(NMDevice *self, int addr_family, NMDeviceConnectivityCallback callback, gpointer user_data, @@ -4361,7 +5481,7 @@ nm_device_check_connectivity_update_interval(NMDevice *self) } static void -concheck_update_state(NMDevice * self, +concheck_update_state(NMDevice *self, int addr_family, NMConnectivityState state, gboolean allow_periodic_bump) @@ -4432,22 +5552,16 @@ concheck_update_state(NMDevice * self, _notify(self, IS_IPv4 ? PROP_IP4_CONNECTIVITY : PROP_IP6_CONNECTIVITY); - if (priv->state == NM_DEVICE_STATE_ACTIVATED && !nm_device_sys_iface_state_is_external(self)) { - if (nm_device_get_best_default_route(self, AF_INET) - && !ip_config_merge_and_apply(self, AF_INET, TRUE)) - _LOGW(LOGD_IP4, "Failed to update IPv4 route metric"); - if (nm_device_get_best_default_route(self, AF_INET6) - && !ip_config_merge_and_apply(self, AF_INET6, TRUE)) - _LOGW(LOGD_IP6, "Failed to update IPv6 route metric"); - } + if (priv->state == NM_DEVICE_STATE_ACTIVATED && !nm_device_sys_iface_state_is_external(self)) + _dev_l3_register_l3cds(self, priv->l3cfg, TRUE, NM_TERNARY_DEFAULT); } static const char * nm_device_get_effective_ip_config_method(NMDevice *self, int addr_family) { NMDeviceClass *klass; - NMConnection * connection = nm_device_get_applied_connection(self); - const char * method; + NMConnection *connection = nm_device_get_applied_connection(self); + const char *method; const int IS_IPv4 = NM_IS_IPv4(addr_family); g_return_val_if_fail(NM_IS_CONNECTION(connection), "" /* bogus */); @@ -4494,16 +5608,16 @@ concheck_handle_complete(NMDeviceConnectivityHandle *handle, GError *error) } static void -concheck_cb(NMConnectivity * connectivity, +concheck_cb(NMConnectivity *connectivity, NMConnectivityCheckHandle *c_handle, NMConnectivityState state, gpointer user_data) { _nm_unused gs_unref_object NMDevice *self_keep_alive = NULL; - NMDevice * self; - NMDevicePrivate * priv; - NMDeviceConnectivityHandle * handle; - NMDeviceConnectivityHandle * other_handle; + NMDevice *self; + NMDevicePrivate *priv; + NMDeviceConnectivityHandle *handle; + NMDeviceConnectivityHandle *other_handle; gboolean handle_is_alive; gboolean allow_periodic_bump; gboolean any_periodic_before; @@ -4627,16 +5741,16 @@ check_handles: } static NMDeviceConnectivityHandle * -concheck_start(NMDevice * self, +concheck_start(NMDevice *self, int addr_family, NMDeviceConnectivityCallback callback, gpointer user_data, gboolean is_periodic) { static guint64 seq_counter = 0; - NMDevicePrivate * priv; + NMDevicePrivate *priv; NMDeviceConnectivityHandle *handle; - const char * ifname; + const char *ifname; g_return_val_if_fail(NM_IS_DEVICE(self), NULL); @@ -4692,7 +5806,7 @@ concheck_start(NMDevice * self, } NMDeviceConnectivityHandle * -nm_device_check_connectivity(NMDevice * self, +nm_device_check_connectivity(NMDevice *self, int addr_family, NMDeviceConnectivityCallback callback, gpointer user_data) @@ -4748,8 +5862,8 @@ static SlaveInfo * find_slave_info(NMDevice *self, NMDevice *slave) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - CList * iter; - SlaveInfo * info; + CList *iter; + SlaveInfo *info; c_list_for_each (iter, &priv->slaves) { info = c_list_entry(iter, SlaveInfo, lst_slave); @@ -4774,16 +5888,14 @@ find_slave_info(NMDevice *self, NMDevice *slave) static gboolean nm_device_master_enslave_slave(NMDevice *self, NMDevice *slave, NMConnection *connection) { - NMDevicePrivate *priv; - SlaveInfo * info; - gboolean success = FALSE; - gboolean configure; + SlaveInfo *info; + gboolean success = FALSE; + gboolean configure; g_return_val_if_fail(self != NULL, FALSE); g_return_val_if_fail(slave != NULL, FALSE); g_return_val_if_fail(NM_DEVICE_GET_CLASS(self)->enslave_slave != NULL, FALSE); - priv = NM_DEVICE_GET_PRIVATE(self); info = find_slave_info(self, slave); if (!info) return FALSE; @@ -4806,22 +5918,17 @@ nm_device_master_enslave_slave(NMDevice *self, NMDevice *slave, NMConnection *co */ nm_device_update_hw_address(self); + /* Since slave devices don't have their own IP configuration, + * set the MTU here. + */ + _commit_mtu(slave); + /* Restart IP configuration if we're waiting for slaves. Do this * after updating the hardware address as IP config may need the * new address. */ - if (success) { - if (priv->ip_state_4 == NM_DEVICE_IP_STATE_WAIT) - nm_device_activate_stage3_ip_start(self, AF_INET); - - if (priv->ip_state_6 == NM_DEVICE_IP_STATE_WAIT) - nm_device_activate_stage3_ip_start(self, AF_INET6); - } - - /* Since slave devices don't have their own IP configuration, - * set the MTU here. - */ - _commit_mtu(slave, NM_DEVICE_GET_PRIVATE(slave)->ip_config_4); + if (success) + nm_device_activate_schedule_stage3_ip_config(self, FALSE); return success; } @@ -4840,15 +5947,15 @@ nm_device_master_enslave_slave(NMDevice *self, NMDevice *slave, NMConnection *co * updates the state of @self and @slave to reflect its release. */ static void -nm_device_master_release_one_slave(NMDevice * self, - NMDevice * slave, +nm_device_master_release_one_slave(NMDevice *self, + NMDevice *slave, gboolean configure, gboolean force, NMDeviceStateReason reason) { - NMDevicePrivate *priv; - NMDevicePrivate *slave_priv; - SlaveInfo * info; + NMDevicePrivate *priv; + NMDevicePrivate *slave_priv; + SlaveInfo *info; gs_unref_object NMDevice *self_free = NULL; g_return_if_fail(NM_DEVICE(self)); @@ -4908,6 +6015,8 @@ nm_device_master_release_one_slave(NMDevice * self, NM_DEVICE_STATE_REASON_REMOVED); } +/*****************************************************************************/ + /** * can_unmanaged_external_down: * @self: the device @@ -4922,7 +6031,7 @@ can_unmanaged_external_down(NMDevice *self) } static NMUnmanFlagOp -is_unmanaged_external_down(NMDevice *self, gboolean consider_can) +_dev_unmanaged_is_external_down(NMDevice *self, gboolean consider_can) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); @@ -4939,7 +6048,7 @@ is_unmanaged_external_down(NMDevice *self, gboolean consider_can) } static void -set_unmanaged_external_down(NMDevice *self, gboolean only_if_unmanaged) +_dev_unmanaged_check_external_down(NMDevice *self, gboolean only_if_unmanaged, gboolean now) { NMUnmanFlagOp ext_flags; @@ -4951,7 +6060,7 @@ set_unmanaged_external_down(NMDevice *self, gboolean only_if_unmanaged) return; } - ext_flags = is_unmanaged_external_down(self, FALSE); + ext_flags = _dev_unmanaged_is_external_down(self, FALSE); if (ext_flags != NM_UNMAN_FLAG_OP_SET_UNMANAGED) { /* Ensure the assume check is queued before any queued state changes * from the transition to UNAVAILABLE. @@ -4959,10 +6068,17 @@ set_unmanaged_external_down(NMDevice *self, gboolean only_if_unmanaged) nm_device_queue_recheck_assume(self); } - nm_device_set_unmanaged_by_flags(self, - NM_UNMANAGED_EXTERNAL_DOWN, - ext_flags, - NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED); + if (now) { + nm_device_set_unmanaged_by_flags(self, + NM_UNMANAGED_EXTERNAL_DOWN, + ext_flags, + NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED); + } else { + nm_device_set_unmanaged_by_flags_queue(self, + NM_UNMANAGED_EXTERNAL_DOWN, + ext_flags, + NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED); + } } void @@ -4979,26 +6095,15 @@ nm_device_update_dynamic_ip_setup(NMDevice *self) g_hash_table_remove_all(priv->ip6_saved_properties); - if (priv->dhcp_data_4.client) { - if (!nm_device_dhcp4_renew(self, FALSE)) { - nm_device_state_changed(self, - NM_DEVICE_STATE_FAILED, - NM_DEVICE_STATE_REASON_DHCP_FAILED); - return; - } - } - if (priv->dhcp_data_6.client) { - if (!nm_device_dhcp6_renew(self, FALSE)) { - nm_device_state_changed(self, - NM_DEVICE_STATE_FAILED, - NM_DEVICE_STATE_REASON_DHCP_FAILED); - return; - } - } - if (priv->ndisc) { + if (priv->ipdhcp_data_4.state != NM_DEVICE_IP_STATE_NONE) + _dev_ipdhcpx_restart(self, AF_INET, FALSE); + if (priv->ipdhcp_data_6.state != NM_DEVICE_IP_STATE_NONE) + _dev_ipdhcpx_restart(self, AF_INET6, FALSE); + + if (priv->ipac6_data.ndisc) { /* FIXME: todo */ } - if (priv->dnsmasq_manager) { + if (priv->ipshared_data_4.v4.dnsmasq_manager) { /* FIXME: todo */ } } @@ -5033,10 +6138,8 @@ carrier_changed(NMDevice *self, gboolean carrier) nm_device_update_dynamic_ip_setup(self); /* If needed, also resume IP configuration that is * waiting for carrier. */ - if (nm_device_activate_ip4_state_in_wait(self)) - nm_device_activate_stage3_ip_start(self, AF_INET); - if (nm_device_activate_ip6_state_in_wait(self)) - nm_device_activate_stage3_ip_start(self, AF_INET6); + if (priv->state == NM_DEVICE_STATE_IP_CONFIG) + nm_device_activate_schedule_stage3_ip_config(self, FALSE); return; } /* fall-through and change state of device */ @@ -5082,7 +6185,7 @@ carrier_changed(NMDevice *self, gboolean carrier) static gboolean carrier_disconnected_action_cb(gpointer user_data) { - NMDevice * self = NM_DEVICE(user_data); + NMDevice *self = NM_DEVICE(user_data); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); _LOGD(LOGD_DEVICE, @@ -5134,10 +6237,6 @@ nm_device_set_carrier(NMDevice *self, gboolean carrier) nm_device_remove_pending_action(self, NM_PENDING_ACTION_CARRIER_WAIT, FALSE); _carrier_wait_check_queued_act_request(self); } - - /* Send ARP announcements if did not yet and have carrier. */ - if (priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE && !priv->acd.announcing) - nm_device_arp_announce(self); } else { if (priv->carrier_wait_id) nm_device_add_pending_action(self, NM_PENDING_ACTION_CARRIER_WAIT, FALSE); @@ -5188,10 +6287,10 @@ nm_device_set_carrier_from_platform(NMDevice *self) static void device_recheck_slave_status(NMDevice *self, const NMPlatformLink *plink) { - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - NMDevice * master; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NMDevice *master; nm_auto_nmpobj const NMPObject *plink_master_keep_alive = NULL; - const NMPlatformLink * plink_master; + const NMPlatformLink *plink_master; g_return_if_fail(plink); @@ -5268,89 +6367,10 @@ device_ifindex_changed_cb(NMManager *manager, NMDevice *device_changed, NMDevice priv->device_link_changed_id = g_idle_add((GSourceFunc) device_link_changed, self); } -static void -ndisc_set_router_config(NMNDisc *ndisc, NMDevice *self) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - gs_unref_array GArray *addresses = NULL; - gs_unref_array GArray *dns_servers = NULL; - gs_unref_array GArray * dns_domains = NULL; - guint len; - guint i; - const NMDedupMultiHeadEntry *head_entry; - NMDedupMultiIter ipconf_iter; - - if (nm_ndisc_get_node_type(ndisc) != NM_NDISC_NODE_TYPE_ROUTER) - return; - - head_entry = nm_ip6_config_lookup_addresses(priv->ip_config_6); - addresses = - g_array_sized_new(FALSE, TRUE, sizeof(NMNDiscAddress), head_entry ? head_entry->len : 0); - nm_dedup_multi_iter_for_each (&ipconf_iter, head_entry) { - const NMPlatformIP6Address *addr = NMP_OBJECT_CAST_IP6_ADDRESS(ipconf_iter.current->obj); - NMNDiscAddress * ndisc_addr; - guint32 lifetime; - guint32 preferred; - - if (IN6_IS_ADDR_UNSPECIFIED(&addr->address) || IN6_IS_ADDR_LINKLOCAL(&addr->address)) - continue; - - if (addr->n_ifa_flags & IFA_F_TENTATIVE || addr->n_ifa_flags & IFA_F_DADFAILED) - continue; - - if (addr->plen != 64) - continue; - - lifetime = nmp_utils_lifetime_get(addr->timestamp, - addr->lifetime, - addr->preferred, - NM_NDISC_EXPIRY_BASE_TIMESTAMP / 1000, - &preferred); - if (!lifetime) - continue; - - g_array_set_size(addresses, addresses->len + 1); - ndisc_addr = &g_array_index(addresses, NMNDiscAddress, addresses->len - 1); - ndisc_addr->address = addr->address; - ndisc_addr->expiry_msec = - _nm_ndisc_lifetime_to_expiry(NM_NDISC_EXPIRY_BASE_TIMESTAMP, lifetime); - ndisc_addr->expiry_preferred_msec = - _nm_ndisc_lifetime_to_expiry(NM_NDISC_EXPIRY_BASE_TIMESTAMP, preferred); - } - - len = nm_ip6_config_get_num_nameservers(priv->ip_config_6); - dns_servers = g_array_sized_new(FALSE, TRUE, sizeof(NMNDiscDNSServer), len); - g_array_set_size(dns_servers, len); - for (i = 0; i < len; i++) { - const struct in6_addr *nameserver = nm_ip6_config_get_nameserver(priv->ip_config_6, i); - NMNDiscDNSServer * ndisc_nameserver; - - ndisc_nameserver = &g_array_index(dns_servers, NMNDiscDNSServer, i); - ndisc_nameserver->address = *nameserver; - ndisc_nameserver->expiry_msec = - _nm_ndisc_lifetime_to_expiry(NM_NDISC_EXPIRY_BASE_TIMESTAMP, NM_NDISC_ROUTER_LIFETIME); - } - - len = nm_ip6_config_get_num_searches(priv->ip_config_6); - dns_domains = g_array_sized_new(FALSE, TRUE, sizeof(NMNDiscDNSDomain), len); - g_array_set_size(dns_domains, len); - for (i = 0; i < len; i++) { - const char * search = nm_ip6_config_get_search(priv->ip_config_6, i); - NMNDiscDNSDomain *ndisc_search; - - ndisc_search = &g_array_index(dns_domains, NMNDiscDNSDomain, i); - ndisc_search->domain = (char *) search; - ndisc_search->expiry_msec = - _nm_ndisc_lifetime_to_expiry(NM_NDISC_EXPIRY_BASE_TIMESTAMP, NM_NDISC_ROUTER_LIFETIME); - } - - nm_ndisc_set_config(ndisc, addresses, dns_servers, dns_domains); -} - static void device_update_interface_flags(NMDevice *self, const NMPlatformLink *plink) { - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); NMDeviceInterfaceFlags flags = NM_DEVICE_INTERFACE_FLAG_NONE; if (plink && NM_FLAGS_HAS(plink->n_ifi_flags, IFF_UP)) @@ -5378,14 +6398,15 @@ device_update_interface_flags(NMDevice *self, const NMPlatformLink *plink) } static gboolean -device_link_changed(NMDevice *self) +device_link_changed(gpointer user_data) { - NMDeviceClass * klass = NM_DEVICE_GET_CLASS(self); - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - gboolean ip_ifname_changed = FALSE; + NMDevice *self = user_data; + NMDeviceClass *klass = NM_DEVICE_GET_CLASS(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + gboolean ip_ifname_changed = FALSE; nm_auto_nmpobj const NMPObject *pllink_keep_alive = NULL; - const NMPlatformLink * pllink; - const char * str; + const NMPlatformLink *pllink; + const char *str; int ifindex; gboolean was_up; gboolean update_unmanaged_specs = FALSE; @@ -5446,14 +6467,15 @@ device_link_changed(NMDevice *self) /* If the device has no explicit ip_iface, then changing iface changes ip_iface too. */ ip_ifname_changed = !priv->ip_iface; - if (nm_device_get_unmanaged_flags(self, NM_UNMANAGED_PLATFORM_INIT)) - nm_device_set_unmanaged_by_user_settings(self); - else + if (!nm_device_get_unmanaged_flags(self, NM_UNMANAGED_PLATFORM_INIT)) { + /* Since the interface name changed, we need to re-evaluate the + * user settings specs. */ update_unmanaged_specs = TRUE; + } _notify(self, PROP_IFACE); if (ip_ifname_changed) - _notify(self, PROP_IP_IFACE); + update_prop_ip_iface(self); /* Re-match available connections against the new interface name */ nm_device_recheck_available_connections(self); @@ -5464,8 +6486,8 @@ device_link_changed(NMDevice *self) nm_device_emit_recheck_auto_activate(self); } - if (priv->ndisc && pllink->inet6_token.id) { - if (nm_ndisc_set_iid(priv->ndisc, pllink->inet6_token)) + if (priv->ipac6_data.ndisc && pllink->inet6_token.id) { + if (nm_ndisc_set_iid(priv->ipac6_data.ndisc, pllink->inet6_token, TRUE)) _LOGD(LOGD_DEVICE, "IPv6 tokenized identifier present on device %s", priv->iface); } @@ -5508,31 +6530,35 @@ device_link_changed(NMDevice *self) } } + /* The assume check should happen before the device transitions to + * UNAVAILABLE, because in UNAVAILABLE we already clean up the IP + * configuration. Therefore, this function should never trigger a + * sync state transition. + */ nm_device_queue_recheck_assume(self); - nm_device_set_unmanaged_by_flags(self, NM_UNMANAGED_PLATFORM_INIT, FALSE, reason); + nm_device_set_unmanaged_by_flags_queue(self, NM_UNMANAGED_PLATFORM_INIT, FALSE, reason); } - set_unmanaged_external_down(self, FALSE); + _dev_unmanaged_check_external_down(self, FALSE, FALSE); device_recheck_slave_status(self, pllink); if (priv->up && (!was_up || seen_down)) { /* the link was down and just came up. That happens for example, while changing MTU. - * We must restore IP configuration. */ - if (NM_IN_SET(priv->ip_state_4, NM_DEVICE_IP_STATE_CONF, NM_DEVICE_IP_STATE_DONE)) { - if (!ip_config_merge_and_apply(self, AF_INET, TRUE)) - _LOGW(LOGD_IP4, "failed applying IP4 config after link comes up again"); - } - - priv->linklocal6_dad_counter = 0; - if (NM_IN_SET(priv->ip_state_6, NM_DEVICE_IP_STATE_CONF, NM_DEVICE_IP_STATE_DONE)) { - if (!ip_config_merge_and_apply(self, AF_INET6, TRUE)) - _LOGW(LOGD_IP6, "failed applying IP6 config after link comes up again"); - } + * We must restore IP configuration. + * + * FIXME(l3cfg): when NML3Cfg notices that the device goes down and up, then + * it should automatically schedule a REAPPLY commit -- provided that the current + * commit-type is >= UPDATE. The idea is to move logic away from NMDevice + * so that it theoretically would also work for NMVpnConnection (although, + * NMVpnConnection should become like a regular device, akin to NMDevicePpp). + */ + if (!nm_device_sys_iface_state_is_external(self)) + nm_device_l3cfg_commit(self, NM_L3_CFG_COMMIT_TYPE_REAPPLY, FALSE); } if (update_unmanaged_specs) - nm_device_set_unmanaged_by_user_settings(self); + nm_device_set_unmanaged_by_user_settings(self, FALSE); if (got_hw_addr && !priv->up && nm_device_get_state(self) == NM_DEVICE_STATE_UNAVAILABLE) { /* @@ -5550,11 +6576,12 @@ device_link_changed(NMDevice *self) } static gboolean -device_ip_link_changed(NMDevice *self) +device_ip_link_changed(gpointer user_data) { - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); + NMDevice *self = user_data; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); const NMPlatformLink *pllink; - const char * ip_iface; + const char *ip_iface; priv->device_ip_link_changed_id = 0; @@ -5586,7 +6613,7 @@ device_ip_link_changed(NMDevice *self) ip_iface); g_free(priv->ip_iface_); priv->ip_iface_ = g_strdup(ip_iface); - _notify(self, PROP_IP_IFACE); + update_prop_ip_iface(self); nm_device_update_dynamic_ip_setup(self); } @@ -5595,15 +6622,15 @@ device_ip_link_changed(NMDevice *self) } static void -link_changed_cb(NMPlatform * platform, +link_changed_cb(NMPlatform *platform, int obj_type_i, int ifindex, NMPlatformLink *info, int change_type_i, - NMDevice * self) + NMDevice *self) { const NMPlatformSignalChangeType change_type = change_type_i; - NMDevicePrivate * priv; + NMDevicePrivate *priv; if (change_type != NM_PLATFORM_SIGNAL_CHANGED) return; @@ -5614,13 +6641,12 @@ link_changed_cb(NMPlatform * platform, if (!(info->n_ifi_flags & IFF_UP)) priv->device_link_changed_down = TRUE; if (!priv->device_link_changed_id) { - priv->device_link_changed_id = g_idle_add((GSourceFunc) device_link_changed, self); + priv->device_link_changed_id = g_idle_add(device_link_changed, self); _LOGD(LOGD_DEVICE, "queued link change for ifindex %d", ifindex); } } else if (ifindex == nm_device_get_ip_ifindex(self)) { if (!priv->device_ip_link_changed_id) { - priv->device_ip_link_changed_id = - g_idle_add((GSourceFunc) device_ip_link_changed, self); + priv->device_ip_link_changed_id = g_idle_add(device_ip_link_changed, self); _LOGD(LOGD_DEVICE, "queued link change for ip-ifindex %d", ifindex); } } @@ -5703,14 +6729,14 @@ link_type_compatible(NMDevice *self, NMLinkType link_type, gboolean *out_compati * Returns: %TRUE on success, %FALSE on error */ gboolean -nm_device_realize_start(NMDevice * self, +nm_device_realize_start(NMDevice *self, const NMPlatformLink *plink, gboolean assume_state_guess_assume, - const char * assume_state_connection_uuid, + const char *assume_state_connection_uuid, gboolean set_nm_owned, NMUnmanFlagOp unmanaged_user_explicit, - gboolean * out_compatible, - GError ** error) + gboolean *out_compatible, + GError **error) { nm_auto_nmpobj const NMPObject *plink_keep_alive = NULL; @@ -5757,14 +6783,14 @@ nm_device_realize_start(NMDevice * self, * Returns: %TRUE on success, %FALSE on error */ gboolean -nm_device_create_and_realize(NMDevice * self, +nm_device_create_and_realize(NMDevice *self, NMConnection *connection, - NMDevice * parent, - GError ** error) + NMDevice *parent, + GError **error) { nm_auto_nmpobj const NMPObject *plink_keep_alive = NULL; - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - const NMPlatformLink * plink; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + const NMPlatformLink *plink; gboolean nm_owned; /* Must be set before device is realized */ @@ -5812,7 +6838,7 @@ void nm_device_update_from_platform_link(NMDevice *self, const NMPlatformLink *plink) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - const char * str; + const char *str; gboolean ifindex_changed; guint32 mtu; @@ -5889,9 +6915,9 @@ sriov_op_start(NMDevice *self, SriovOp *op) static void sriov_op_cb(GError *error, gpointer user_data) { - SriovOp * op = user_data; + SriovOp *op = user_data; gs_unref_object NMDevice *self = op->device; - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); nm_assert(op == priv->sriov.pending); @@ -5941,7 +6967,7 @@ sriov_op_queue_op(NMDevice *self, SriovOp *op) } static void -sriov_op_queue(NMDevice * self, +sriov_op_queue(NMDevice *self, guint num_vfs, NMOptionBool autoprobe, NMPlatformAsyncCallback callback, @@ -6000,11 +7026,11 @@ device_init_static_sriov_num_vfs(NMDevice *self) } static void -config_changed(NMConfig * config, - NMConfigData * config_data, +config_changed(NMConfig *config, + NMConfigData *config_data, NMConfigChangeFlags changes, - NMConfigData * old_data, - NMDevice * self) + NMConfigData *old_data, + NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); @@ -6043,19 +7069,19 @@ realize_start_notify(NMDevice *self, const NMPlatformLink *pllink) * stuff). */ static void -realize_start_setup(NMDevice * self, +realize_start_setup(NMDevice *self, const NMPlatformLink *plink, gboolean assume_state_guess_assume, - const char * assume_state_connection_uuid, + const char *assume_state_connection_uuid, gboolean set_nm_owned, NMUnmanFlagOp unmanaged_user_explicit, gboolean force_platform_init) { - NMDevicePrivate * priv; - NMDeviceClass * klass; - NMPlatform * platform; + NMDevicePrivate *priv; + NMDeviceClass *klass; + NMPlatform *platform; NMDeviceCapabilities capabilities = 0; - NMConfig * config; + NMConfig *config; guint refresh_rate_ms; gboolean unmanaged; @@ -6072,8 +7098,6 @@ realize_start_setup(NMDevice * self, g_return_if_fail(nm_device_get_unmanaged_flags(self, NM_UNMANAGED_PLATFORM_INIT)); g_return_if_fail(priv->ip_ifindex <= 0); g_return_if_fail(priv->ip_iface == NULL); - g_return_if_fail(!priv->queued_ip_config_id_4); - g_return_if_fail(!priv->queued_ip_config_id_6); _LOGD(LOGD_DEVICE, "start setup of %s, kernel ifindex %d", @@ -6120,9 +7144,6 @@ realize_start_setup(NMDevice * self, if (priv->firmware_version) _notify(self, PROP_FIRMWARE_VERSION); - priv->ipv6ll_handle = (nm_platform_link_get_inet6_addr_gen_mode(platform, priv->ifindex) - == NM_IN6_ADDR_GEN_MODE_NONE); - if (nm_platform_link_supports_sriov(platform, priv->ifindex)) capabilities |= NM_DEVICE_CAP_SRIOV; } @@ -6180,7 +7201,7 @@ realize_start_setup(NMDevice * self, * or have IP addressing */ nm_device_set_unmanaged_flags(self, NM_UNMANAGED_EXTERNAL_DOWN, - is_unmanaged_external_down(self, TRUE)); + _dev_unmanaged_is_external_down(self, TRUE)); /* Unmanaged the loopback device with an explicit NM_UNMANAGED_BY_TYPE flag. * Later we might want to manage 'lo' too. Currently, that doesn't work because @@ -6219,9 +7240,6 @@ nm_device_realize_finish(NMDevice *self, const NMPlatformLink *plink) if (plink) device_recheck_slave_status(self, plink); - priv->update_ip_config_completed_v4 = FALSE; - priv->update_ip_config_completed_v6 = FALSE; - priv->real = TRUE; _notify(self, PROP_REAL); @@ -6242,7 +7260,7 @@ unrealize_notify(NMDevice *self) static gboolean available_connections_check_delete_unrealized_on_idle(gpointer user_data) { - NMDevice * self = user_data; + NMDevice *self = user_data; NMDevicePrivate *priv; g_return_val_if_fail(NM_IS_DEVICE(self), G_SOURCE_REMOVE); @@ -6317,9 +7335,6 @@ nm_device_unrealize(NMDevice *self, gboolean remove_resources, GError **error) } } - nm_clear_g_source(&priv->queued_ip_config_id_4); - nm_clear_g_source(&priv->queued_ip_config_id_6); - g_object_freeze_notify(G_OBJECT(self)); NM_DEVICE_GET_CLASS(self)->unrealize_notify(self); @@ -6328,7 +7343,7 @@ nm_device_unrealize(NMDevice *self, gboolean remove_resources, GError **error) _set_ifindex(self, 0, FALSE); _set_ifindex(self, 0, TRUE); if (nm_clear_g_free(&priv->ip_iface_)) - _notify(self, PROP_IP_IFACE); + update_prop_ip_iface(self); priv->master_ifindex = 0; @@ -6444,7 +7459,7 @@ NMConnection * nm_device_new_default_connection(NMDevice *self) { NMConnection *connection; - GError * error = NULL; + GError *error = NULL; if (!NM_DEVICE_GET_CLASS(self)->new_default_connection) return NULL; @@ -6463,11 +7478,11 @@ nm_device_new_default_connection(NMDevice *self) } static void -slave_state_changed(NMDevice * slave, +slave_state_changed(NMDevice *slave, NMDeviceState slave_new_state, NMDeviceState slave_old_state, NMDeviceStateReason reason, - NMDevice * self) + NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); gboolean release = FALSE; @@ -6524,7 +7539,7 @@ nm_device_master_add_slave(NMDevice *self, NMDevice *slave, gboolean configure) { NMDevicePrivate *priv; NMDevicePrivate *slave_priv; - SlaveInfo * info; + SlaveInfo *info; gboolean changed = FALSE; g_return_val_if_fail(NM_IS_DEVICE(self), FALSE); @@ -6594,9 +7609,9 @@ void nm_device_master_check_slave_physical_port(NMDevice *self, NMDevice *slave, NMLogDomain log_domain) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - const char * slave_physical_port_id, *existing_physical_port_id; - SlaveInfo * info; - CList * iter; + const char *slave_physical_port_id, *existing_physical_port_id; + SlaveInfo *info; + CList *iter; slave_physical_port_id = nm_device_get_physical_port_id(slave); if (!slave_physical_port_id) @@ -6627,9 +7642,9 @@ nm_device_master_check_slave_physical_port(NMDevice *self, NMDevice *slave, NMLo void nm_device_master_release_slaves(NMDevice *self) { - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); NMDeviceStateReason reason; - CList * iter, *safe; + CList *iter, *safe; /* Don't release the slaves if this connection doesn't belong to NM. */ if (nm_device_sys_iface_state_is_external(self)) @@ -6683,117 +7698,6 @@ nm_device_get_master(NMDevice *self) return NULL; } -static gboolean -get_ip_config_may_fail(NMDevice *self, int addr_family) -{ - NMConnection * connection; - NMSettingIPConfig *s_ip; - - connection = nm_device_get_applied_connection(self); - - s_ip = nm_connection_get_setting_ip_config(connection, addr_family); - - return !s_ip || nm_setting_ip_config_get_may_fail(s_ip); -} - -/* - * check_ip_state - * - * When @full_state_update is TRUE, transition the device from IP_CONFIG to the - * next state according to the outcome of IPv4 and IPv6 configuration. @may_fail - * indicates that we are called just after the initial configuration and thus - * IPv4/IPv6 are allowed to fail if the ipvx.may-fail properties say so, because - * the IP methods couldn't even be started. - * If @full_state_update is FALSE, just check if the connection should be failed - * due to the state of both ip families and the ipvx.may-fail settings. - */ -static void -check_ip_state(NMDevice *self, gboolean may_fail, gboolean full_state_update) -{ - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - gboolean ip4_disabled = FALSE, ip6_disabled = FALSE; - NMSettingIPConfig *s_ip4, *s_ip6; - NMDeviceState state; - int IS_IPv4; - - if (full_state_update && nm_device_get_state(self) != NM_DEVICE_STATE_IP_CONFIG) - return; - - /* Don't progress into IP_CHECK or SECONDARIES if we're waiting for the - * master to enslave us. */ - if (nm_active_connection_get_master(NM_ACTIVE_CONNECTION(priv->act_request.obj)) - && !priv->is_enslaved) - return; - - s_ip4 = nm_device_get_applied_setting(self, NM_TYPE_SETTING_IP4_CONFIG); - if (s_ip4 - && nm_streq0(nm_setting_ip_config_get_method(s_ip4), NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) - ip4_disabled = TRUE; - - s_ip6 = nm_device_get_applied_setting(self, NM_TYPE_SETTING_IP6_CONFIG); - if (s_ip6 - && NM_IN_STRSET(nm_setting_ip_config_get_method(s_ip6), - NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_METHOD_DISABLED)) - ip6_disabled = TRUE; - - if (priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE - && priv->ip_state_6 == NM_DEVICE_IP_STATE_DONE) { - /* Both method completed (or disabled), proceed with activation */ - nm_device_state_changed(self, NM_DEVICE_STATE_IP_CHECK, NM_DEVICE_STATE_REASON_NONE); - return; - } - - for (IS_IPv4 = 1; IS_IPv4 >= 0; IS_IPv4--) { - if (priv->ip_state_x[IS_IPv4] == NM_DEVICE_IP_STATE_CONF - && priv->ip_req_timeout_source_x[IS_IPv4]) { - return; - } - } - - if ((priv->ip_state_4 == NM_DEVICE_IP_STATE_FAIL - || (ip4_disabled && priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE)) - && (priv->ip_state_6 == NM_DEVICE_IP_STATE_FAIL - || (ip6_disabled && priv->ip_state_6 == NM_DEVICE_IP_STATE_DONE))) { - /* Either both methods failed, or only one failed and the other is - * disabled */ - if (nm_device_sys_iface_state_is_external_or_assume(self)) { - /* We have assumed configuration, but couldn't redo it. No problem, - * move to check state. */ - _set_ip_state(self, AF_INET, NM_DEVICE_IP_STATE_DONE); - _set_ip_state(self, AF_INET6, NM_DEVICE_IP_STATE_DONE); - state = NM_DEVICE_STATE_IP_CHECK; - } else if (may_fail && get_ip_config_may_fail(self, AF_INET) - && get_ip_config_may_fail(self, AF_INET6)) { - /* Couldn't start either IPv6 and IPv4 autoconfiguration, - * but both are allowed to fail. */ - state = NM_DEVICE_STATE_SECONDARIES; - } else { - /* Autoconfiguration attempted without success. */ - state = NM_DEVICE_STATE_FAILED; - } - - if (full_state_update || state == NM_DEVICE_STATE_FAILED) { - nm_device_state_changed(self, state, NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); - } - return; - } - - /* If a method is still pending but required, wait */ - if (priv->ip_state_4 != NM_DEVICE_IP_STATE_DONE && !get_ip_config_may_fail(self, AF_INET)) - return; - if (priv->ip_state_6 != NM_DEVICE_IP_STATE_DONE && !get_ip_config_may_fail(self, AF_INET6)) - return; - - /* If at least a method has completed, proceed with activation */ - if ((priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE && !ip4_disabled) - || (priv->ip_state_6 == NM_DEVICE_IP_STATE_DONE && !ip6_disabled)) { - if (full_state_update) - nm_device_state_changed(self, NM_DEVICE_STATE_IP_CHECK, NM_DEVICE_STATE_REASON_NONE); - return; - } -} - /** * nm_device_slave_notify_enslave: * @self: the slave device @@ -6806,7 +7710,7 @@ static void nm_device_slave_notify_enslave(NMDevice *self, gboolean success) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - NMConnection * connection = nm_device_get_applied_connection(self); + NMConnection *connection = nm_device_get_applied_connection(self); gboolean activating = (priv->state == NM_DEVICE_STATE_IP_CONFIG); g_return_if_fail(priv->master); @@ -6833,13 +7737,17 @@ nm_device_slave_notify_enslave(NMDevice *self, gboolean success) } } - if (activating) { - if (success) - check_ip_state(self, FALSE, TRUE); - else - nm_device_queue_state(self, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_UNKNOWN); - } else + if (!activating) { nm_device_queue_recheck_assume(self); + return; + } + + if (!success) { + nm_device_queue_state(self, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_UNKNOWN); + return; + } + + nm_device_activate_schedule_stage3_ip_config(self, FALSE); } /** @@ -6853,8 +7761,8 @@ static void nm_device_slave_notify_release(NMDevice *self, NMDeviceStateReason reason) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - NMConnection * connection = nm_device_get_applied_connection(self); - const char * master_status; + NMConnection *connection = nm_device_get_applied_connection(self); + const char *master_status; g_return_if_fail(priv->master); @@ -6913,6 +7821,9 @@ nm_device_removed(NMDevice *self, gboolean unconfigure_ip_config) g_return_if_fail(NM_IS_DEVICE(self)); + _dev_ipdhcpx_cleanup(self, AF_INET, TRUE, FALSE); + _dev_ipdhcpx_cleanup(self, AF_INET6, TRUE, FALSE); + priv = NM_DEVICE_GET_PRIVATE(self); if (priv->master) { /* this is called when something externally messes with the slave or during shut-down. @@ -6924,15 +7835,7 @@ nm_device_removed(NMDevice *self, gboolean unconfigure_ip_config) NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED); } - if (unconfigure_ip_config) { - nm_device_set_ip_config(self, AF_INET, NULL, FALSE, NULL); - nm_device_set_ip_config(self, AF_INET6, NULL, FALSE, NULL); - } else { - if (priv->dhcp_data_4.client) - nm_dhcp_client_stop(priv->dhcp_data_4.client, FALSE); - if (priv->dhcp_data_6.client) - nm_dhcp_client_stop(priv->dhcp_data_6.client, FALSE); - } + _dev_l3_register_l3cds(self, priv->l3cfg, FALSE, unconfigure_ip_config); } static gboolean @@ -7033,7 +7936,7 @@ nm_device_autoconnect_blocked_get(NMDevice *self, NMDeviceAutoconnectBlockedFlag } void -nm_device_autoconnect_blocked_set_full(NMDevice * self, +nm_device_autoconnect_blocked_set_full(NMDevice *self, NMDeviceAutoconnectBlockedFlags mask, NMDeviceAutoconnectBlockedFlags value) { @@ -7068,8 +7971,8 @@ nm_device_autoconnect_blocked_set_full(NMDevice * self, static gboolean autoconnect_allowed_accumulator(GSignalInvocationHint *ihint, - GValue * return_accu, - const GValue * handler_return, + GValue *return_accu, + const GValue *handler_return, gpointer data) { if (!g_value_get_boolean(handler_return)) @@ -7089,7 +7992,7 @@ gboolean nm_device_autoconnect_allowed(NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - NMDeviceClass * klass = NM_DEVICE_GET_CLASS(self); + NMDeviceClass *klass = NM_DEVICE_GET_CLASS(self); GValue instance = G_VALUE_INIT; GValue retval = G_VALUE_INIT; @@ -7190,22 +8093,36 @@ nm_device_can_auto_connect(NMDevice *self, NMSettingsConnection *sett_conn, char static gboolean device_has_config(NMDevice *self) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + const NMDedupMultiHeadEntry *head_entry; + const NMPlatformLink *pllink; + NMPLookup lookup; + + pllink = nm_l3cfg_get_pllink(priv->l3cfg, TRUE); + if (!pllink) + return FALSE; + + if (pllink->master > 0) { + /* Master-slave relationship is also a configuration */ + return TRUE; + } - /* Check for IP configuration. */ - if (priv->ip_config_4 && nm_ip4_config_get_num_addresses(priv->ip_config_4)) - return TRUE; - if (priv->ip_config_6 && nm_ip6_config_get_num_addresses(priv->ip_config_6)) + head_entry = nm_platform_lookup( + nm_device_get_platform(self), + nmp_lookup_init_object(&lookup, NMP_OBJECT_TYPE_IP4_ADDRESS, pllink->ifindex)); + if (head_entry) return TRUE; - /* The existence of a software device is good enough. */ - if (nm_device_is_software(self) && nm_device_is_real(self)) + head_entry = nm_platform_lookup( + nm_device_get_platform(self), + nmp_lookup_init_object(&lookup, NMP_OBJECT_TYPE_IP6_ADDRESS, pllink->ifindex)); + if (head_entry) return TRUE; - /* Master-slave relationship is also a configuration */ - if (!c_list_is_empty(&priv->slaves) - || nm_platform_link_get_master(nm_device_get_platform(self), priv->ifindex) > 0) + if (nm_device_is_software(self) && nm_device_is_real(self)) { + /* The existence of a software device is good enough. */ return TRUE; + } return FALSE; } @@ -7224,10 +8141,10 @@ device_has_config(NMDevice *self) * %FALSE on failure. */ gboolean -nm_device_master_update_slave_connection(NMDevice * self, - NMDevice * slave, +nm_device_master_update_slave_connection(NMDevice *self, + NMDevice *slave, NMConnection *connection, - GError ** error) + GError **error) { NMDeviceClass *klass; gboolean success; @@ -7293,19 +8210,19 @@ NMConnection * nm_device_generate_connection(NMDevice *self, NMDevice *master, gboolean *out_maybe_later, - GError ** error) + GError **error) { - NMDeviceClass * klass = NM_DEVICE_GET_CLASS(self); - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - const char * ifname = nm_device_get_iface(self); + NMDeviceClass *klass = NM_DEVICE_GET_CLASS(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + const char *ifname = nm_device_get_iface(self); gs_unref_object NMConnection *connection = NULL; - NMSetting * s_con; - NMSetting * s_ip4; - NMSetting * s_ip6; + NMSetting *s_con; + NMSetting *s_ip4; + NMSetting *s_ip6; char uuid[37]; - const char * ip4_method, *ip6_method; - GError * local = NULL; - const NMPlatformLink * pllink; + const char *ip4_method, *ip6_method; + GError *local = NULL; + const NMPlatformLink *pllink; NM_SET_OUT(out_maybe_later, FALSE); @@ -7363,10 +8280,16 @@ nm_device_generate_connection(NMDevice *self, } } else { /* Only regular and master devices get IP configuration; slaves do not */ - s_ip4 = nm_ip4_config_create_setting(priv->ip_config_4); + s_ip4 = nm_utils_platform_capture_ip_setting(nm_device_get_platform(self), + AF_INET, + nm_device_get_ip_ifindex(self), + FALSE); nm_connection_add_setting(connection, s_ip4); - s_ip6 = nm_ip6_config_create_setting(priv->ip_config_6, _get_maybe_ipv6_disabled(self)); + s_ip6 = nm_utils_platform_capture_ip_setting(nm_device_get_platform(self), + AF_INET6, + nm_device_get_ip_ifindex(self), + _get_maybe_ipv6_disabled(self)); nm_connection_add_setting(connection, s_ip6); nm_connection_add_setting(connection, nm_setting_proxy_new()); @@ -7449,11 +8372,11 @@ nm_device_generate_connection(NMDevice *self, * Returns: success or failure. */ gboolean -nm_device_complete_connection(NMDevice * self, - NMConnection * connection, - const char * specific_object, +nm_device_complete_connection(NMDevice *self, + NMConnection *connection, + const char *specific_object, NMConnection *const *existing_connections, - GError ** error) + GError **error) { NMDeviceClass *klass; @@ -7511,14 +8434,14 @@ nm_device_match_parent(NMDevice *self, const char *parent) } gboolean -nm_device_match_parent_hwaddr(NMDevice * device, +nm_device_match_parent_hwaddr(NMDevice *device, NMConnection *connection, gboolean fail_if_no_hwaddr) { NMSettingWired *s_wired; - NMDevice * parent_device; - const char * setting_mac; - const char * parent_mac; + NMDevice *parent_device; + const char *setting_mac; + const char *parent_mac; s_wired = nm_connection_get_setting_wired(connection); if (!s_wired) @@ -7539,13 +8462,13 @@ nm_device_match_parent_hwaddr(NMDevice * device, static gboolean check_connection_compatible(NMDevice *self, NMConnection *connection, GError **error) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - const char * device_iface = nm_device_get_iface(self); - gs_free_error GError *local = NULL; - gs_free char * conn_iface = NULL; - NMDeviceClass * klass; - NMSettingMatch * s_match; - const GSList * specs; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + const char *device_iface = nm_device_get_iface(self); + gs_free_error GError *local = NULL; + gs_free char *conn_iface = NULL; + NMDeviceClass *klass; + NMSettingMatch *s_match; + const GSList *specs; gboolean has_match = FALSE; klass = NM_DEVICE_GET_CLASS(self); @@ -7668,7 +8591,7 @@ gboolean nm_device_check_slave_connection_compatible(NMDevice *self, NMConnection *slave) { NMSettingConnection *s_con; - const char * connection_type, *slave_type; + const char *connection_type, *slave_type; g_return_val_if_fail(NM_IS_DEVICE(self), FALSE); g_return_val_if_fail(NM_IS_CONNECTION(slave), FALSE); @@ -7746,7 +8669,7 @@ nm_device_unmanage_on_quit(NMDevice *self) static gboolean nm_device_emit_recheck_assume(gpointer user_data) { - NMDevice * self = user_data; + NMDevice *self = user_data; NMDevicePrivate *priv; g_return_val_if_fail(NM_IS_DEVICE(self), G_SOURCE_REMOVE); @@ -7772,7 +8695,7 @@ nm_device_queue_recheck_assume(NMDevice *self) static gboolean recheck_available(gpointer user_data) { - NMDevice * self = NM_DEVICE(user_data); + NMDevice *self = NM_DEVICE(user_data); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); gboolean now_available; NMDeviceState state = nm_device_get_state(self); @@ -7810,7 +8733,7 @@ recheck_available(gpointer user_data) } void -nm_device_queue_recheck_available(NMDevice * self, +nm_device_queue_recheck_available(NMDevice *self, NMDeviceStateReason available_reason, NMDeviceStateReason unavailable_reason) { @@ -7832,27 +8755,13 @@ nm_device_emit_recheck_auto_activate(NMDevice *self) g_signal_emit(self, signals[RECHECK_AUTO_ACTIVATE], 0); } -static void -dnsmasq_state_changed_cb(NMDnsMasqManager *manager, guint32 status, gpointer user_data) -{ - NMDevice *self = NM_DEVICE(user_data); - - switch (status) { - case NM_DNSMASQ_STATUS_DEAD: - nm_device_ip_method_failed(self, AF_INET, NM_DEVICE_STATE_REASON_SHARED_START_FAILED); - break; - default: - break; - } -} - void -nm_device_auth_request(NMDevice * self, - GDBusMethodInvocation * context, - NMConnection * connection, - const char * permission, +nm_device_auth_request(NMDevice *self, + GDBusMethodInvocation *context, + NMConnection *connection, + const char *permission, gboolean allow_interaction, - GCancellable * cancellable, + GCancellable *cancellable, NMManagerDeviceAuthRequestFunc callback, gpointer user_data) { @@ -7870,156 +8779,120 @@ nm_device_auth_request(NMDevice * self, /*****************************************************************************/ static void -activation_source_clear(NMDevice *self, int addr_family) +activation_source_clear(NMDevice *self) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - const int IS_IPv4 = NM_IS_IPv4(addr_family); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - if (priv->activation_source_id_x[IS_IPv4] != 0) { + if (nm_clear_g_source_inst(&priv->activation_idle_source)) { _LOGD(LOGD_DEVICE, - "activation-stage: clear %s,v%c (id %u)", - _activation_func_to_string(priv->activation_source_func_x[IS_IPv4]), - nm_utils_addr_family_to_char(addr_family), - priv->activation_source_id_x[IS_IPv4]); - nm_clear_g_source(&priv->activation_source_id_x[IS_IPv4]); - priv->activation_source_func_x[IS_IPv4] = NULL; + "activation-stage: clear %s", + _activation_func_to_string(priv->activation_func)); + priv->activation_func = NULL; } } static gboolean -activation_source_handle_cb(NMDevice *self, int addr_family) +activation_source_handle_cb(gpointer user_data) { - NMDevicePrivate * priv; - const int IS_IPv4 = NM_IS_IPv4(addr_family); - ActivationHandleFunc activation_source_func; - guint activation_source_id; + NMDevice *self = user_data; + NMDevicePrivate *priv; + ActivationHandleFunc activation_func; g_return_val_if_fail(NM_IS_DEVICE(self), G_SOURCE_REMOVE); priv = NM_DEVICE_GET_PRIVATE(self); - activation_source_func = priv->activation_source_func_x[IS_IPv4]; - activation_source_id = priv->activation_source_id_x[IS_IPv4]; - - g_return_val_if_fail(activation_source_id != 0, G_SOURCE_REMOVE); - nm_assert(activation_source_func); + g_return_val_if_fail(priv->activation_idle_source, G_SOURCE_REMOVE); - priv->activation_source_func_x[IS_IPv4] = NULL; - priv->activation_source_id_x[IS_IPv4] = 0; + nm_assert(priv->activation_func); - _LOGD(LOGD_DEVICE, - "activation-stage: invoke %s,v%c (id %u)", - _activation_func_to_string(activation_source_func), - nm_utils_addr_family_to_char(addr_family), - activation_source_id); + activation_func = priv->activation_func; + priv->activation_func = NULL; - activation_source_func(self); - - _LOGT(LOGD_DEVICE, - "activation-stage: complete %s,v%c (id %u)", - _activation_func_to_string(activation_source_func), - nm_utils_addr_family_to_char(addr_family), - activation_source_id); + nm_clear_g_source_inst(&priv->activation_idle_source); - return G_SOURCE_REMOVE; -} + _LOGD(LOGD_DEVICE, "activation-stage: invoke %s", _activation_func_to_string(activation_func)); -static gboolean -activation_source_handle_cb_4(gpointer user_data) -{ - return activation_source_handle_cb(user_data, AF_INET); -} + activation_func(self); -static gboolean -activation_source_handle_cb_6(gpointer user_data) -{ - return activation_source_handle_cb(user_data, AF_INET6); + return G_SOURCE_CONTINUE; } static void -activation_source_schedule(NMDevice *self, ActivationHandleFunc func, int addr_family) +activation_source_schedule(NMDevice *self, ActivationHandleFunc func) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - const int IS_IPv4 = NM_IS_IPv4(addr_family); - guint new_id = 0; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - if (priv->activation_source_id_x[IS_IPv4] != 0 - && priv->activation_source_func_x[IS_IPv4] == func) { + if (priv->activation_idle_source && priv->activation_func == func) { /* Scheduling the same stage multiple times is fine. */ _LOGT(LOGD_DEVICE, - "activation-stage: already scheduled %s,v%c (id %u)", - _activation_func_to_string(func), - nm_utils_addr_family_to_char(addr_family), - priv->activation_source_id_x[IS_IPv4]); + "activation-stage: already scheduled %s", + _activation_func_to_string(func)); return; } - new_id = - g_idle_add(IS_IPv4 ? activation_source_handle_cb_4 : activation_source_handle_cb_6, self); - - if (priv->activation_source_id_x[IS_IPv4] != 0) { + if (priv->activation_idle_source) { _LOGD(LOGD_DEVICE, - "activation-stage: schedule %s,v%c which replaces %s,v%c (id %u -> %u)", + "activation-stage: schedule %s (which replaces %s)", _activation_func_to_string(func), - nm_utils_addr_family_to_char(addr_family), - _activation_func_to_string(priv->activation_source_func_x[IS_IPv4]), - nm_utils_addr_family_to_char(addr_family), - priv->activation_source_id_x[IS_IPv4], - new_id); - nm_clear_g_source(&priv->activation_source_id_x[IS_IPv4]); + _activation_func_to_string(priv->activation_func)); + nm_clear_g_source_inst(&priv->activation_idle_source); } else { - _LOGD(LOGD_DEVICE, - "activation-stage: schedule %s,v%c (id %u)", - _activation_func_to_string(func), - nm_utils_addr_family_to_char(addr_family), - new_id); + _LOGD(LOGD_DEVICE, "activation-stage: schedule %s", _activation_func_to_string(func)); } - priv->activation_source_func_x[IS_IPv4] = func; - priv->activation_source_id_x[IS_IPv4] = new_id; + priv->activation_idle_source = nm_g_idle_add_source(activation_source_handle_cb, self); + priv->activation_func = func; } static void -activation_source_invoke_sync(NMDevice *self, ActivationHandleFunc func, int addr_family) +activation_source_invoke_sync(NMDevice *self, ActivationHandleFunc func) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - const int IS_IPv4 = NM_IS_IPv4(addr_family); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - if (priv->activation_source_id_x[IS_IPv4] == 0) { + if (!priv->activation_idle_source) { _LOGD(LOGD_DEVICE, - "activation-stage: synchronously invoke %s,v%c", - _activation_func_to_string(func), - nm_utils_addr_family_to_char(addr_family)); - } else if (priv->activation_source_func_x[IS_IPv4] == func) { + "activation-stage: synchronously invoke %s", + _activation_func_to_string(func)); + } else if (priv->activation_func == func) { _LOGD(LOGD_DEVICE, - "activation-stage: synchronously invoke %s,v%c which was already scheduled (id %u)", - _activation_func_to_string(func), - nm_utils_addr_family_to_char(addr_family), - priv->activation_source_id_x[IS_IPv4]); + "activation-stage: synchronously invoke %s (which was already scheduled)", + _activation_func_to_string(func)); } else { _LOGD(LOGD_DEVICE, - "activation-stage: synchronously invoke %s,v%c which replaces %s,v%c (id %u)", + "activation-stage: synchronously invoke %s (which replaces %s)", _activation_func_to_string(func), - nm_utils_addr_family_to_char(addr_family), - _activation_func_to_string(priv->activation_source_func_x[IS_IPv4]), - nm_utils_addr_family_to_char(addr_family), - priv->activation_source_id_x[IS_IPv4]); + _activation_func_to_string(priv->activation_func)); } - nm_clear_g_source(&priv->activation_source_id_x[IS_IPv4]); - priv->activation_source_func_x[IS_IPv4] = NULL; + nm_clear_g_source_inst(&priv->activation_idle_source); + priv->activation_func = NULL; func(self); } +static void +activation_source_invoke_or_schedule(NMDevice *self, ActivationHandleFunc func, gboolean do_sync) +{ + nm_assert(NM_IS_DEVICE(self)); + nm_assert(NM_DEVICE_GET_PRIVATE(self)->act_request.obj); + nm_assert(func); + + if (do_sync) { + activation_source_invoke_sync(self, func); + return; + } + activation_source_schedule(self, func); +} + /*****************************************************************************/ static void master_ready(NMDevice *self, NMActiveConnection *active) { - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); NMActiveConnection *master_connection; - NMDevice * master; + NMDevice *master; /* Notify a master device that it has a new slave */ nm_assert(nm_active_connection_get_master_ready(active)); @@ -8057,10 +8930,10 @@ master_ready_cb(NMActiveConnection *active, GParamSpec *pspec, NMDevice *self) static NMPlatformVF * sriov_vf_config_to_platform(NMDevice *self, NMSriovVF *vf, GError **error) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); gs_free NMPlatformVF *plat_vf = NULL; - const guint * vlan_ids; - GVariant * variant; + const guint *vlan_ids; + GVariant *variant; guint i, num_vlans; gsize length; @@ -8131,8 +9004,8 @@ sriov_vf_config_to_platform(NMDevice *self, NMSriovVF *vf, GError **error) static void sriov_params_cb(GError *error, gpointer user_data) { - NMDevice * self; - NMDevicePrivate *priv; + NMDevice *self; + NMDevicePrivate *priv; nm_auto_freev NMPlatformVF **plat_vfs = NULL; nm_utils_user_data_unpack(user_data, &self, &plat_vfs); @@ -8174,20 +9047,26 @@ sriov_params_cb(GError *error, gpointer user_data) static void activate_stage1_device_prepare(NMDevice *self) { - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); NMActStageReturn ret = NM_ACT_STAGE_RETURN_SUCCESS; NMActiveConnection *active; NMActiveConnection *master; - NMDeviceClass * klass; + NMDeviceClass *klass; - priv->v4_route_table_initialized = FALSE; - priv->v6_route_table_initialized = FALSE; + nm_assert((priv->ip_data_4.state == NM_DEVICE_IP_STATE_NONE) + == (priv->ip_data_6.state == NM_DEVICE_IP_STATE_NONE)); + + if (priv->ip_data_4.state == NM_DEVICE_IP_STATE_NONE) { + _dev_ip_state_set_state(self, AF_INET, NM_DEVICE_IP_STATE_PENDING, "stage1"); + _dev_ip_state_set_state(self, AF_INET6, NM_DEVICE_IP_STATE_PENDING, "stage1"); - _set_ip_state(self, AF_INET, NM_DEVICE_IP_STATE_NONE); - _set_ip_state(self, AF_INET6, NM_DEVICE_IP_STATE_NONE); + /* Notify the new ActiveConnection along with the state change */ + nm_dbus_track_obj_path_set(&priv->act_request, priv->act_request.obj, TRUE); - /* Notify the new ActiveConnection along with the state change */ - nm_dbus_track_obj_path_set(&priv->act_request, priv->act_request.obj, TRUE); + priv->v4_route_table_initialized = FALSE; + priv->v6_route_table_initialized = FALSE; + priv->l3config_merge_flags_has = FALSE; + } nm_device_state_changed(self, NM_DEVICE_STATE_PREPARE, NM_DEVICE_STATE_REASON_NONE); @@ -8201,11 +9080,11 @@ activate_stage1_device_prepare(NMDevice *self) else if (priv->ifindex > 0 && nm_device_has_capability(self, NM_DEVICE_CAP_SRIOV) && (s_sriov = nm_device_get_applied_setting(self, NM_TYPE_SETTING_SRIOV))) { nm_auto_freev NMPlatformVF **plat_vfs = NULL; - gs_free_error GError *error = NULL; - NMSriovVF * vf; - NMTernary autoprobe; - guint num; - guint i; + gs_free_error GError *error = NULL; + NMSriovVF *vf; + NMTernary autoprobe; + guint num; + guint i; autoprobe = nm_setting_sriov_get_autoprobe_drivers(s_sriov); if (autoprobe == NM_TERNARY_DEFAULT) { @@ -8248,6 +9127,7 @@ activate_stage1_device_prepare(NMDevice *self) priv->stage1_sriov_state = NM_DEVICE_STAGE_STATE_PENDING; return; } + priv->stage1_sriov_state = NM_DEVICE_STAGE_STATE_COMPLETED; } @@ -8323,15 +9203,7 @@ activate_stage1_device_prepare(NMDevice *self) void nm_device_activate_schedule_stage1_device_prepare(NMDevice *self, gboolean do_sync) { - g_return_if_fail(NM_IS_DEVICE(self)); - g_return_if_fail(NM_DEVICE_GET_PRIVATE(self)->act_request.obj); - - if (!do_sync) { - activation_source_schedule(self, activate_stage1_device_prepare, AF_INET); - return; - } - - activation_source_invoke_sync(self, activate_stage1_device_prepare, AF_INET); + activation_source_invoke_or_schedule(self, activate_stage1_device_prepare, do_sync); } static NMActStageReturn @@ -8408,8 +9280,8 @@ static void _routing_rules_sync(NMDevice *self, NMTernary set_mode) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - NMPRulesManager *rules_manager = nm_netns_get_rules_manager(nm_device_get_netns(self)); - NMDeviceClass * klass = NM_DEVICE_GET_CLASS(self); + NMPRouteManager *route_manager = nm_netns_get_route_manager(nm_device_get_netns(self)); + NMDeviceClass *klass = NM_DEVICE_GET_CLASS(self); gboolean untrack_only_dirty = FALSE; gboolean keep_deleted_rules; gpointer user_tag_1; @@ -8420,15 +9292,12 @@ _routing_rules_sync(NMDevice *self, NMTernary set_mode) user_tag_2 = &priv->v6_route_table; if (set_mode == NM_TERNARY_TRUE) { - NMConnection * applied_connection; + NMConnection *applied_connection; NMSettingIPConfig *s_ip; guint i, num; int is_ipv4; untrack_only_dirty = TRUE; - nmp_rules_manager_set_dirty(rules_manager, user_tag_1); - if (klass->get_extra_rules) - nmp_rules_manager_set_dirty(rules_manager, user_tag_2); applied_connection = nm_device_get_applied_connection(self); @@ -8442,19 +9311,19 @@ _routing_rules_sync(NMDevice *self, NMTernary set_mode) num = nm_setting_ip_config_get_num_routing_rules(s_ip); for (i = 0; i < num; i++) { NMPlatformRoutingRule plrule; - NMIPRoutingRule * rule; + NMIPRoutingRule *rule; rule = nm_setting_ip_config_get_routing_rule(s_ip, i); nm_ip_routing_rule_to_platform(rule, &plrule); /* We track this rule, but we also make it explicitly not weakly-tracked - * (meaning to untrack NMP_RULES_MANAGER_EXTERN_WEAKLY_TRACKED_USER_TAG at + * (meaning to untrack NMP_ROUTE_MANAGER_EXTERN_WEAKLY_TRACKED_USER_TAG at * the same time). */ - nmp_rules_manager_track(rules_manager, - &plrule, - 10, - user_tag_1, - NMP_RULES_MANAGER_EXTERN_WEAKLY_TRACKED_USER_TAG); + nmp_route_manager_track_rule(route_manager, + &plrule, + 10, + user_tag_1, + NMP_ROUTE_MANAGER_EXTERN_WEAKLY_TRACKED_USER_TAG); } } @@ -8464,24 +9333,25 @@ _routing_rules_sync(NMDevice *self, NMTernary set_mode) extra_rules = klass->get_extra_rules(self); if (extra_rules) { for (i = 0; i < extra_rules->len; i++) { - nmp_rules_manager_track(rules_manager, - NMP_OBJECT_CAST_ROUTING_RULE(extra_rules->pdata[i]), - 10, - user_tag_2, - NMP_RULES_MANAGER_EXTERN_WEAKLY_TRACKED_USER_TAG); + nmp_route_manager_track_rule( + route_manager, + NMP_OBJECT_CAST_ROUTING_RULE(extra_rules->pdata[i]), + 10, + user_tag_2, + NMP_ROUTE_MANAGER_EXTERN_WEAKLY_TRACKED_USER_TAG); } } } } - nmp_rules_manager_untrack_all(rules_manager, user_tag_1, !untrack_only_dirty); + nmp_route_manager_untrack_all(route_manager, user_tag_1, !untrack_only_dirty, TRUE); if (klass->get_extra_rules) - nmp_rules_manager_untrack_all(rules_manager, user_tag_2, !untrack_only_dirty); + nmp_route_manager_untrack_all(route_manager, user_tag_2, !untrack_only_dirty, TRUE); keep_deleted_rules = FALSE; if (set_mode == NM_TERNARY_DEFAULT) { /* when exiting NM, we leave the device up and the rules configured. - * We just all nmp_rules_manager_sync() to forget about the synced rules, + * We just call nmp_route_manager_sync() to forget about the synced rules, * but we don't actually delete them. * * FIXME: that is a problem after restart of NetworkManager, because these @@ -8495,7 +9365,7 @@ _routing_rules_sync(NMDevice *self, NMTernary set_mode) * file and track them after restart again. */ keep_deleted_rules = TRUE; } - nmp_rules_manager_sync(rules_manager, keep_deleted_rules); + nmp_route_manager_sync(route_manager, NMP_OBJECT_TYPE_ROUTING_RULE, keep_deleted_rules); } static gboolean @@ -8503,8 +9373,8 @@ tc_commit(NMDevice *self) { gs_unref_ptrarray GPtrArray *qdiscs = NULL; gs_unref_ptrarray GPtrArray *tfilters = NULL; - NMSettingTCConfig * s_tc; - NMPlatform * platform; + NMSettingTCConfig *s_tc; + NMPlatform *platform; int ip_ifindex; s_tc = nm_device_get_applied_setting(self, NM_TYPE_SETTING_TC_CONFIG); @@ -8536,11 +9406,11 @@ static void activate_stage2_device_config(NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - NMDeviceClass * klass; + NMDeviceClass *klass; NMActStageReturn ret; - NMSettingWired * s_wired; + NMSettingWired *s_wired; gboolean no_firmware = FALSE; - CList * iter; + CList *iter; NMTernary accept_all_mac_addresses; nm_device_state_changed(self, NM_DEVICE_STATE_CONFIG, NM_DEVICE_STATE_REASON_NONE); @@ -8588,7 +9458,7 @@ activate_stage2_device_config(NMDevice *self) /* If we have slaves that aren't yet enslaved, do that now */ c_list_for_each (iter, &priv->slaves) { - SlaveInfo * info = c_list_entry(iter, SlaveInfo, lst_slave); + SlaveInfo *info = c_list_entry(iter, SlaveInfo, lst_slave); NMDeviceState slave_state = nm_device_get_state(info->slave); if (slave_state == NM_DEVICE_STATE_IP_CONFIG) @@ -8623,420 +9493,115 @@ activate_stage2_device_config(NMDevice *self) lldp_setup(self, NM_TERNARY_DEFAULT); - _commit_mtu(self, NULL); + _commit_mtu(self); - nm_device_activate_schedule_stage3_ip_config_start(self); + nm_device_activate_schedule_stage3_ip_config(self, TRUE); } void nm_device_activate_schedule_stage2_device_config(NMDevice *self, gboolean do_sync) { - g_return_if_fail(NM_IS_DEVICE(self)); - - if (!do_sync) { - activation_source_schedule(self, activate_stage2_device_config, AF_INET); - return; - } - - activation_source_invoke_sync(self, activate_stage2_device_config, AF_INET); -} - -void -nm_device_ip_method_failed(NMDevice *self, int addr_family, NMDeviceStateReason reason) -{ - g_return_if_fail(NM_IS_DEVICE(self)); - g_return_if_fail(NM_IN_SET(addr_family, AF_INET, AF_INET6)); - - _set_ip_state(self, addr_family, NM_DEVICE_IP_STATE_FAIL); - - if (get_ip_config_may_fail(self, addr_family)) - check_ip_state(self, FALSE, (nm_device_get_state(self) == NM_DEVICE_STATE_IP_CONFIG)); - else - nm_device_state_changed(self, NM_DEVICE_STATE_FAILED, reason); + activation_source_invoke_or_schedule(self, activate_stage2_device_config, do_sync); } /*****************************************************************************/ static void -acd_data_destroy(gpointer ptr) -{ - AcdData *data = ptr; - int i; - - for (i = 0; data->configs && data->configs[i]; i++) - g_object_unref(data->configs[i]); - g_free(data->configs); - g_slice_free(AcdData, data); -} - -static void -ipv4_manual_method_apply(NMDevice *self, NMIP4Config **configs, gboolean success) +_dev_ipllx_set_state(NMDevice *self, int addr_family, NMDeviceIPState state) { - NMConnection *connection; - const char * method; - - connection = nm_device_get_applied_connection(self); - nm_assert(connection); - method = nm_utils_get_ip_config_method(connection, AF_INET); - nm_assert(NM_IN_STRSET(method, - NM_SETTING_IP4_CONFIG_METHOD_MANUAL, - NM_SETTING_IP4_CONFIG_METHOD_AUTO)); - - if (!success) { - nm_device_ip_method_failed(self, AF_INET, NM_DEVICE_STATE_REASON_IP_ADDRESS_DUPLICATE); - return; - } - - if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) - nm_device_activate_schedule_ip_config_result(self, AF_INET, NULL); - else { - if (NM_DEVICE_GET_PRIVATE(self)->ip_state_4 != NM_DEVICE_IP_STATE_DONE) - ip_config_merge_and_apply(self, AF_INET, TRUE); - } -} - -static void -acd_manager_probe_terminated(NMAcdManager *acd_manager, gpointer user_data) -{ - AcdData * data = user_data; - NMDevice * self; - NMDevicePrivate * priv; - NMDedupMultiIter ipconf_iter; - const NMPlatformIP4Address *address; - gboolean result, success = TRUE; - int i; - - g_assert(data); - self = data->device; - priv = NM_DEVICE_GET_PRIVATE(self); - - for (i = 0; data->configs && data->configs[i]; i++) { - nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, data->configs[i], &address) { - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; - - result = nm_acd_manager_check_address(acd_manager, address->address); - success &= result; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + const int IS_IPv4 = NM_IS_IPv4(addr_family); - _NMLOG(result ? LOGL_DEBUG : LOGL_WARN, - LOGD_DEVICE, - "IPv4 DAD result: address %s is %s", - _nm_utils_inet4_ntop(address->address, sbuf), - result ? "unique" : "duplicate"); - } + if (priv->ipll_data_x[IS_IPv4].state != state) { + _LOGD_ipll(addr_family, + "set state %s (was %s)", + nm_device_ip_state_to_string(state), + nm_device_ip_state_to_string(priv->ipll_data_x[IS_IPv4].state)); + priv->ipll_data_x[IS_IPv4].state = state; } - - data->callback(self, data->configs, success); - - priv->acd.dad_list = g_slist_remove(priv->acd.dad_list, acd_manager); - nm_acd_manager_free(acd_manager); } -/** - * ipv4_dad_start: - * @self: device instance - * @configs: NULL-terminated array of IPv4 configurations - * @cb: callback function - * - * Start IPv4 DAD on device @self, check addresses in @configs and call @cb - * when the procedure ends. @cb will be called in any case, even if DAD can't - * be started. @configs will be unreferenced after @cb has been called. - */ static void -ipv4_dad_start(NMDevice *self, NMIP4Config **configs, AcdCallback cb) +_dev_ipllx_cleanup(NMDevice *self, int addr_family) { - static const NMAcdCallbacks acd_callbacks = { - .probe_terminated_callback = acd_manager_probe_terminated, - .user_data_destroy = acd_data_destroy, - }; - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - NMAcdManager * acd_manager; - const NMPlatformIP4Address *address; - NMDedupMultiIter ipconf_iter; - AcdData * data; - guint timeout; - gboolean addr_found; - int r; - const guint8 * hwaddr_arr; - size_t length; - guint i; - - g_return_if_fail(NM_IS_DEVICE(self)); - g_return_if_fail(configs); - g_return_if_fail(cb); - - for (i = 0, addr_found = FALSE; configs[i]; i++) { - if (nm_ip4_config_get_num_addresses(configs[i]) > 0) { - addr_found = TRUE; - break; - } - } - - timeout = _prop_get_ipv4_dad_timeout(self); - hwaddr_arr = nm_platform_link_get_address(nm_device_get_platform(self), - nm_device_get_ip_ifindex(self), - &length); - - if (!timeout || !hwaddr_arr || !addr_found || length != ETH_ALEN - || nm_device_sys_iface_state_is_external_or_assume(self)) { - /* DAD not needed, signal success */ - cb(self, configs, TRUE); - - for (i = 0; configs[i]; i++) - g_object_unref(configs[i]); - g_free(configs); - - return; - } - - data = g_slice_new0(AcdData); - data->configs = configs; - data->callback = cb; - data->device = self; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + const int IS_IPv4 = NM_IS_IPv4(addr_family); - acd_manager = nm_acd_manager_new(nm_device_get_ip_ifindex(self), - hwaddr_arr, - length, - &acd_callbacks, - data); - priv->acd.dad_list = g_slist_append(priv->acd.dad_list, acd_manager); + if (IS_IPv4) { + if (nm_clear_pointer(&priv->ipll_data_4.v4.ipv4ll, nm_l3_ipv4ll_unref)) + nm_clear_pointer(&priv->ipll_data_4.v4.ipv4ll_registation, + nm_l3_ipv4ll_register_remove); + else + nm_assert(!priv->ipll_data_4.v4.ipv4ll_registation); - for (i = 0; configs[i]; i++) { - nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, configs[i], &address) - nm_acd_manager_add_address(acd_manager, address->address); + nm_clear_g_source_inst(&priv->ipll_data_4.v4.timeout_source); + } else { + nm_clear_pointer(&priv->ipll_data_6.v6.ipv6ll, nm_l3_ipv6ll_destroy); + priv->ipll_data_6.v6.llstate = NM_L3_IPV6LL_STATE_NONE; + priv->ipll_data_6.v6.lladdr = nm_ip_addr_zero.addr6; + nm_clear_g_source_inst(&priv->ipll_data_6.v6.retry_source); } - r = nm_acd_manager_start_probe(acd_manager, timeout); - if (r < 0) { - _LOGW(LOGD_DEVICE, "acd probe failed"); + _dev_l3_register_l3cds_set_one(self, L3_CONFIG_DATA_TYPE_LL_X(IS_IPv4), NULL, FALSE); - /* DAD could not be started, signal success */ - cb(self, configs, TRUE); - - priv->acd.dad_list = g_slist_remove(priv->acd.dad_list, acd_manager); - nm_acd_manager_free(acd_manager); - } + _dev_ipllx_set_state(self, addr_family, NM_DEVICE_IP_STATE_NONE); } /*****************************************************************************/ -/* IPv4LL stuff */ - -static void -ipv4ll_cleanup(NMDevice *self) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - - if (priv->ipv4ll) { - sd_ipv4ll_set_callback(priv->ipv4ll, NULL, NULL); - sd_ipv4ll_stop(priv->ipv4ll); - priv->ipv4ll = sd_ipv4ll_unref(priv->ipv4ll); - } - - nm_clear_g_source(&priv->ipv4ll_timeout); -} - -static NMIP4Config * -ipv4ll_get_ip4_config(NMDevice *self, guint32 lla) -{ - NMIP4Config * config = NULL; - NMPlatformIP4Address address; - NMPlatformIP4Route route; - - config = nm_device_ip4_config_new(self); - g_assert(config); - - memset(&address, 0, sizeof(address)); - nm_platform_ip4_address_set_addr(&address, lla, 16); - address.addr_source = NM_IP_CONFIG_SOURCE_IP4LL; - nm_ip4_config_add_address(config, &address); - - /* Add a multicast route for link-local connections: destination= 224.0.0.0, netmask=240.0.0.0 */ - memset(&route, 0, sizeof(route)); - route.network = htonl(0xE0000000L); - route.plen = 4; - route.rt_source = NM_IP_CONFIG_SOURCE_IP4LL; - route.table_coerced = nm_platform_route_table_coerce(nm_device_get_route_table(self, AF_INET)); - route.metric = nm_device_get_route_metric(self, AF_INET); - nm_ip4_config_add_route(config, &route, NULL); - - return config; -} static void -nm_device_handle_ipv4ll_event(sd_ipv4ll *ll, int event, void *data) -{ - NMDevice * self = data; - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - struct in_addr address; - NMIP4Config * config; - int r; - - if (priv->act_request.obj == NULL) - return; - - nm_assert(nm_streq(nm_device_get_effective_ip_config_method(self, AF_INET), - NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)); - - switch (event) { - case SD_IPV4LL_EVENT_BIND: - r = sd_ipv4ll_get_address(ll, &address); - if (r < 0) { - _LOGE(LOGD_AUTOIP4, "invalid IPv4 link-local address received, error %d.", r); - nm_device_ip_method_failed(self, AF_INET, NM_DEVICE_STATE_REASON_AUTOIP_START_FAILED); - return; - } - - if (!nm_utils_ip4_address_is_link_local(address.s_addr)) { - _LOGE(LOGD_AUTOIP4, "invalid address %08x received (not link-local).", address.s_addr); - nm_device_ip_method_failed(self, AF_INET, NM_DEVICE_STATE_REASON_AUTOIP_ERROR); - return; - } - - config = ipv4ll_get_ip4_config(self, address.s_addr); - if (config == NULL) { - _LOGE(LOGD_AUTOIP4, "failed to get IPv4LL config"); - nm_device_ip_method_failed(self, AF_INET, NM_DEVICE_STATE_REASON_AUTOIP_FAILED); - return; - } - - if (priv->ip_state_4 == NM_DEVICE_IP_STATE_CONF) { - nm_clear_g_source(&priv->ipv4ll_timeout); - nm_device_activate_schedule_ip_config_result(self, AF_INET, NM_IP_CONFIG_CAST(config)); - } else if (priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE) { - applied_config_init(&priv->dev_ip_config_4, config); - if (!ip_config_merge_and_apply(self, AF_INET, TRUE)) { - _LOGE(LOGD_AUTOIP4, "failed to update IP4 config for autoip change."); - nm_device_ip_method_failed(self, AF_INET, NM_DEVICE_STATE_REASON_AUTOIP_FAILED); - } - } else - g_assert_not_reached(); - - g_object_unref(config); - break; - default: - _LOGW(LOGD_AUTOIP4, "IPv4LL address no longer valid after event %d.", event); - nm_device_ip_method_failed(self, AF_INET, NM_DEVICE_STATE_REASON_AUTOIP_FAILED); - } -} - -static gboolean -ipv4ll_timeout_cb(gpointer user_data) -{ - NMDevice * self = NM_DEVICE(user_data); - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - - if (priv->ipv4ll_timeout) { - _LOGI(LOGD_AUTOIP4, "IPv4LL configuration timed out."); - priv->ipv4ll_timeout = 0; - ipv4ll_cleanup(self); - - if (priv->ip_state_4 == NM_DEVICE_IP_STATE_CONF) - nm_device_activate_schedule_ip_config_timeout(self, AF_INET); - } - - return FALSE; -} - -static NMActStageReturn -ipv4ll_start(NMDevice *self) -{ - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - const struct ether_addr *addr; - int ifindex, r; - size_t addr_len; - - ipv4ll_cleanup(self); - - r = sd_ipv4ll_new(&priv->ipv4ll); - if (r < 0) { - _LOGE(LOGD_AUTOIP4, "IPv4LL: new() failed with error %d", r); - return NM_ACT_STAGE_RETURN_FAILURE; - } - - r = sd_ipv4ll_attach_event(priv->ipv4ll, NULL, 0); - if (r < 0) { - _LOGE(LOGD_AUTOIP4, "IPv4LL: attach_event() failed with error %d", r); - return NM_ACT_STAGE_RETURN_FAILURE; - } - - ifindex = nm_device_get_ip_ifindex(self); - addr = nm_platform_link_get_address(nm_device_get_platform(self), ifindex, &addr_len); - if (!addr || addr_len != ETH_ALEN) { - _LOGE(LOGD_AUTOIP4, "IPv4LL: can't retrieve hardware address"); - return NM_ACT_STAGE_RETURN_FAILURE; - } - - r = sd_ipv4ll_set_mac(priv->ipv4ll, addr); - if (r < 0) { - _LOGE(LOGD_AUTOIP4, "IPv4LL: set_mac() failed with error %d", r); - return NM_ACT_STAGE_RETURN_FAILURE; - } - - r = sd_ipv4ll_set_ifindex(priv->ipv4ll, ifindex); - if (r < 0) { - _LOGE(LOGD_AUTOIP4, "IPv4LL: set_ifindex() failed with error %d", r); - return NM_ACT_STAGE_RETURN_FAILURE; - } - - r = sd_ipv4ll_set_callback(priv->ipv4ll, nm_device_handle_ipv4ll_event, self); - if (r < 0) { - _LOGE(LOGD_AUTOIP4, "IPv4LL: set_callback() failed with error %d", r); - return NM_ACT_STAGE_RETURN_FAILURE; +_dev_ipll4_notify_event(NMDevice *self) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NML3IPv4LLState ipv4ll_state; + const NML3ConfigData *l3cd; + NMDeviceIPState state; + + nm_assert(NM_IS_L3_IPV4LL(priv->ipll_data_4.v4.ipv4ll)); + nm_assert(priv->ipll_data_4.state >= NM_DEVICE_IP_STATE_PENDING); + + ipv4ll_state = nm_l3_ipv4ll_get_state(priv->ipll_data_4.v4.ipv4ll); + + if (nm_l3_ipv4ll_state_is_good(ipv4ll_state)) { + l3cd = nm_l3_ipv4ll_get_l3cd(priv->ipll_data_4.v4.ipv4ll); + nm_assert(NM_IS_L3_CONFIG_DATA(l3cd)); + nm_assert(!nm_l3_ipv4ll_is_timed_out(priv->ipll_data_4.v4.ipv4ll)); + state = NM_DEVICE_IP_STATE_READY; + } else if (priv->ipll_data_4.v4.ipv4ll + && nm_l3_ipv4ll_is_timed_out(priv->ipll_data_4.v4.ipv4ll)) { + l3cd = NULL; + state = NM_DEVICE_IP_STATE_FAILED; + } else { + l3cd = NULL; + state = (priv->ipll_data_4.state == NM_DEVICE_IP_STATE_PENDING) ? NM_DEVICE_IP_STATE_PENDING + : NM_DEVICE_IP_STATE_FAILED; } - r = sd_ipv4ll_start(priv->ipv4ll); - if (r < 0) { - _LOGE(LOGD_AUTOIP4, "IPv4LL: start() failed with error %d", r); - return NM_ACT_STAGE_RETURN_FAILURE; - } + _dev_ipllx_set_state(self, AF_INET, state); - _LOGI(LOGD_DEVICE | LOGD_AUTOIP4, "IPv4LL: started"); + _dev_l3_register_l3cds_set_one(self, L3_CONFIG_DATA_TYPE_LL_4, l3cd, FALSE); - /* Start a timeout to bound the address attempt */ - priv->ipv4ll_timeout = g_timeout_add_seconds(20, ipv4ll_timeout_cb, self); - return NM_ACT_STAGE_RETURN_POSTPONE; + _dev_ip_state_check_async(self, AF_INET); } -/*****************************************************************************/ - static void -ensure_con_ip_config(NMDevice *self, int addr_family) +_dev_ipll4_start(NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - NMConnection * connection; - const int IS_IPv4 = NM_IS_IPv4(addr_family); - NMIPConfig * con_ip_config; - - if (priv->con_ip_config_x[IS_IPv4]) - return; + guint32 timeout_msec; - connection = nm_device_get_applied_connection(self); - if (!connection) + if (priv->ipll_data_4.state >= NM_DEVICE_IP_STATE_PENDING) return; - con_ip_config = nm_device_ip_config_new(self, addr_family); - - if (IS_IPv4) { - nm_ip4_config_merge_setting(NM_IP4_CONFIG(con_ip_config), - nm_connection_get_setting_ip4_config(connection), - _prop_get_connection_mdns(self), - _prop_get_connection_llmnr(self), - _prop_get_connection_dns_over_tls(self), - nm_device_get_route_table(self, addr_family), - nm_device_get_route_metric(self, addr_family)); - } else { - nm_ip6_config_merge_setting(NM_IP6_CONFIG(con_ip_config), - nm_connection_get_setting_ip6_config(connection), - nm_device_get_route_table(self, addr_family), - nm_device_get_route_metric(self, addr_family)); - } + _dev_ipllx_set_state(self, AF_INET, NM_DEVICE_IP_STATE_PENDING); - if (nm_device_sys_iface_state_is_external_or_assume(self)) { - /* For assumed connections ignore all addresses and routes. */ - nm_ip_config_reset_addresses(con_ip_config); - nm_ip_config_reset_routes(con_ip_config); - } + timeout_msec = _prop_get_ipv4_dad_timeout(self); + if (timeout_msec == 0) + timeout_msec = NM_ACD_TIMEOUT_RFC5227_MSEC; - priv->con_ip_config_x[IS_IPv4] = con_ip_config; + priv->ipll_data_4.v4.ipv4ll = nm_l3cfg_access_ipv4ll(priv->l3cfg); + priv->ipll_data_4.v4.ipv4ll_registation = + nm_l3_ipv4ll_register_new(priv->ipll_data_4.v4.ipv4ll, timeout_msec); } /*****************************************************************************/ @@ -9056,545 +9621,465 @@ _device_get_dhcp_anycast_address(NMDevice *self) return NULL; } -static void -dhcp4_cleanup(NMDevice *self, CleanupType cleanup_type, gboolean release) +/*****************************************************************************/ + +static IPDevStateData * +_dev_ipdev_data(NMDevice *self, int addr_family) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - priv->dhcp_data_4.was_active = FALSE; - nm_clear_g_source(&priv->dhcp_data_4.grace_id); - priv->dhcp_data_4.grace_pending = FALSE; - nm_clear_g_free(&priv->dhcp4.pac_url); - - if (priv->dhcp_data_4.client) { - /* Stop any ongoing DHCP transaction on this device */ - nm_clear_g_signal_handler(priv->dhcp_data_4.client, &priv->dhcp_data_4.notify_sigid); - - if (cleanup_type == CLEANUP_TYPE_DECONFIGURE || cleanup_type == CLEANUP_TYPE_REMOVED) - nm_dhcp_client_stop(priv->dhcp_data_4.client, release); - - g_clear_object(&priv->dhcp_data_4.client); - } - - if (priv->dhcp_data_4.config) { - nm_dbus_object_clear_and_unexport(&priv->dhcp_data_4.config); - _notify(self, PROP_DHCP4_CONFIG); + switch (addr_family) { + case AF_INET: + return &priv->ipdev_data_4; + case AF_INET6: + return &priv->ipdev_data_6; + default: + nm_assert_not_reached(); + /* fall-through */ + case AF_UNSPEC: + return &priv->ipdev_data_unspec; } } -static gboolean -ip_config_merge_and_apply(NMDevice *self, int addr_family, gboolean commit) +static void +_dev_ipdev_cleanup(NMDevice *self, int addr_family) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - gboolean success; - gs_unref_object NMIPConfig *composite = NULL; - NMIPConfig * config; - gs_unref_ptrarray GPtrArray *ip4_dev_route_blacklist = NULL; - NMConnection * connection; - gboolean ignore_auto_routes = FALSE; - gboolean ignore_auto_dns = FALSE; - gboolean ignore_default_routes = FALSE; - GSList * iter; - const char * ip6_addr_gen_token = NULL; - const int IS_IPv4 = NM_IS_IPv4(addr_family); + IPDevStateData *p; - if (nm_device_sys_iface_state_is_external(self)) - commit = FALSE; + p = _dev_ipdev_data(self, addr_family); + if (p->state != NM_DEVICE_IP_STATE_NONE) { + _LOGD_ipdev(addr_family, "reset state"); + p->state = NM_DEVICE_IP_STATE_NONE; + p->failed_reason = NM_DEVICE_STATE_REASON_NONE; + } - connection = nm_device_get_applied_connection(self); + _dev_l3_register_l3cds_set_one(self, L3_CONFIG_DATA_TYPE_DEVIP(addr_family), NULL, FALSE); +} - /* Apply ignore-auto-routes and ignore-auto-dns settings */ - if (connection) { - NMSettingIPConfig *s_ip; +NMDeviceIPState +nm_device_devip_get_state(NMDevice *self, int addr_family) +{ + g_return_val_if_fail(NM_IS_DEVICE(self), NM_DEVICE_IP_STATE_NONE); - s_ip = nm_connection_get_setting_ip_config(connection, addr_family); - if (s_ip) { - ignore_auto_routes = nm_setting_ip_config_get_ignore_auto_routes(s_ip); - ignore_auto_dns = nm_setting_ip_config_get_ignore_auto_dns(s_ip); + return _dev_ipdev_data(self, addr_family)->state; +} - /* if the connection has an explicit gateway, we also ignore - * the default routes from other sources. */ - ignore_default_routes = nm_setting_ip_config_get_never_default(s_ip) - || nm_setting_ip_config_get_gateway(s_ip); +void +nm_device_devip_set_state_full(NMDevice *self, + int addr_family, + NMDeviceIPState ip_state, + const NML3ConfigData *l3cd, + NMDeviceStateReason failed_reason) +{ + NMDevicePrivate *priv; + IPDevStateData *p; - if (!IS_IPv4) { - NMSettingIP6Config *s_ip6 = NM_SETTING_IP6_CONFIG(s_ip); + g_return_if_fail(NM_IS_DEVICE(self)); - if (nm_setting_ip6_config_get_addr_gen_mode(s_ip6) - == NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64) - ip6_addr_gen_token = nm_setting_ip6_config_get_token(s_ip6); - } - } - } + priv = NM_DEVICE_GET_PRIVATE(self); - composite = nm_device_ip_config_new(self, addr_family); + nm_assert_addr_family_or_unspec(addr_family); + nm_assert(NM_IN_SET(ip_state, + NM_DEVICE_IP_STATE_PENDING, + NM_DEVICE_IP_STATE_READY, + NM_DEVICE_IP_STATE_FAILED)); + nm_assert(!l3cd || NM_IS_L3_CONFIG_DATA(l3cd)); - if (!IS_IPv4) { - nm_ip6_config_set_privacy(NM_IP6_CONFIG(composite), - priv->ndisc ? priv->ndisc_use_tempaddr - : NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN); - } + nm_assert((ip_state != NM_DEVICE_IP_STATE_FAILED) + == (failed_reason == NM_DEVICE_STATE_REASON_NONE)); + nm_assert((ip_state != NM_DEVICE_IP_STATE_FAILED) || !l3cd); + + p = _dev_ipdev_data(self, addr_family); - init_ip_config_dns_priority(self, composite); + if (p->state == ip_state && p->failed_reason == failed_reason + && priv->l3cds[L3_CONFIG_DATA_TYPE_DEVIP(addr_family)].d == l3cd) + return; - if (commit) { - if (priv->queued_ip_config_id_x[IS_IPv4]) - update_ext_ip_config(self, addr_family, FALSE); - ensure_con_ip_config(self, addr_family); + if (ip_state == NM_DEVICE_IP_STATE_FAILED) { + _LOGD_ipdev(addr_family, + "set state=failed (reason %s)", + nm_device_state_reason_to_string_a(failed_reason)); + } else { + _LOGD_ipdev(addr_family, + "set state=%s%s", + nm_device_ip_state_to_string(ip_state), + l3cd ? " (has extra IP configuration)" : ""); } + p->state = ip_state; + p->failed_reason = failed_reason; + _dev_l3_register_l3cds_set_one(self, L3_CONFIG_DATA_TYPE_DEVIP(addr_family), l3cd, FALSE); + _dev_ip_state_check_async(self, addr_family); +} - if (!IS_IPv4) { - if (commit && priv->ipv6ll_has) { - const NMPlatformIP6Address ll_a = { - .address = priv->ipv6ll_addr, - .plen = 64, - .addr_source = NM_IP_CONFIG_SOURCE_IP6LL, - }; - const NMPlatformIP6Route ll_r = { - .network.s6_addr16[0] = htons(0xfe80u), - .plen = 64, - .metric = nm_device_get_route_metric(self, addr_family), - .rt_source = NM_IP_CONFIG_SOURCE_IP6LL, - }; +/*****************************************************************************/ - nm_assert(IN6_IS_ADDR_LINKLOCAL(&priv->ipv6ll_addr)); +static void +_dev_ipmanual_set_state(NMDevice *self, int addr_family, NMDeviceIPState state) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + int IS_IPv4; - nm_ip6_config_add_address(NM_IP6_CONFIG(composite), &ll_a); - nm_ip6_config_add_route(NM_IP6_CONFIG(composite), &ll_r, NULL); - } + if (addr_family == AF_UNSPEC) { + _dev_ipmanual_set_state(self, AF_INET, state); + _dev_ipmanual_set_state(self, AF_INET6, state); + return; } - if (commit) { - gboolean v; - - v = default_route_metric_penalty_detect(self, addr_family); - if (IS_IPv4) - priv->default_route_metric_penalty_ip4_has = v; - else - priv->default_route_metric_penalty_ip6_has = v; + IS_IPv4 = NM_IS_IPv4(addr_family); + if (priv->ipmanual_data.state_x[IS_IPv4] != state) { + _LOGD_ipmanual(addr_family, "set state %s", nm_device_ip_state_to_string(state)); + priv->ipmanual_data.state_x[IS_IPv4] = state; } +} - /* Merge all the IP configs into the composite config */ +static void +_dev_ipmanual_cleanup(NMDevice *self) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - if (IS_IPv4) { - config = applied_config_get_current(&priv->dev_ip_config_4); - if (config) { - nm_ip4_config_merge( - NM_IP4_CONFIG(composite), - NM_IP4_CONFIG(config), - (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) - | (ignore_default_routes ? NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES : 0) - | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0), - default_route_metric_penalty_get(self, addr_family)); - } + if (priv->ipmanual_data.state_4 == NM_DEVICE_IP_STATE_NONE + && priv->ipmanual_data.state_6 == NM_DEVICE_IP_STATE_NONE) { + nm_assert(!priv->l3cds[L3_CONFIG_DATA_TYPE_MANUALIP].d); + return; } - if (!IS_IPv4) { - config = applied_config_get_current(&priv->ac_ip6_config); - if (config) { - nm_ip6_config_merge( - NM_IP6_CONFIG(composite), - NM_IP6_CONFIG(config), - (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) - | (ignore_default_routes ? NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES : 0) - | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0), - default_route_metric_penalty_get(self, addr_family)); - } - } + _dev_ipmanual_set_state(self, AF_UNSPEC, NM_DEVICE_IP_STATE_NONE); + nm_clear_g_source_inst(&priv->ipmanual_data.carrier_timeout); + priv->ipmanual_data.carrier_timeout_expired = FALSE; - if (!IS_IPv4) { - config = applied_config_get_current(&priv->dhcp6.ip6_config); - if (config) { - nm_ip6_config_merge( - NM_IP6_CONFIG(composite), - NM_IP6_CONFIG(config), - (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) - | (ignore_default_routes ? NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES : 0) - | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0), - default_route_metric_penalty_get(self, addr_family)); - } - } + _dev_l3_register_l3cds_set_one(self, L3_CONFIG_DATA_TYPE_MANUALIP, NULL, FALSE); - for (iter = priv->vpn_configs_x[IS_IPv4]; iter; iter = iter->next) - nm_ip_config_merge(composite, iter->data, NM_IP_CONFIG_MERGE_DEFAULT, 0); + _dev_ip_state_check_async(self, AF_INET); + _dev_ip_state_check_async(self, AF_INET6); +} - if (priv->ext_ip_config_x[IS_IPv4]) - nm_ip_config_merge(composite, - priv->ext_ip_config_x[IS_IPv4], - NM_IP_CONFIG_MERGE_EXTERNAL, - 0); +static gboolean +_dev_ipmanual_carrier_timeout(NMDevice *self) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - /* Merge WWAN config *last* to ensure modem-given settings overwrite - * any external stuff set by pppd or other scripts. - */ - config = applied_config_get_current(&priv->dev2_ip_config_x[IS_IPv4]); - if (config) { - nm_ip_config_merge(composite, - config, - (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) - | (ignore_default_routes ? NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES : 0) - | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0), - default_route_metric_penalty_get(self, addr_family)); - } + priv->ipmanual_data.carrier_timeout_expired = TRUE; + nm_clear_g_source_inst(&priv->ipmanual_data.carrier_timeout); + _dev_ipmanual_check_ready(self); - if (!IS_IPv4) { - if (priv->rt6_temporary_not_available) { - const NMPObject *o; - GHashTableIter hiter; - - g_hash_table_iter_init(&hiter, priv->rt6_temporary_not_available); - while (g_hash_table_iter_next(&hiter, (gpointer *) &o, NULL)) { - nm_ip6_config_add_route(NM_IP6_CONFIG(composite), - NMP_OBJECT_CAST_IP6_ROUTE(o), - NULL); - } - } - } + return G_SOURCE_CONTINUE; +} - /* Merge user overrides into the composite config. For assumed connections, - * con_ip_config_x is empty. */ - if (priv->con_ip_config_x[IS_IPv4]) { - nm_ip_config_merge(composite, - priv->con_ip_config_x[IS_IPv4], - NM_IP_CONFIG_MERGE_DEFAULT, - default_route_metric_penalty_get(self, addr_family)); +static void +_dev_ipmanual_check_ready(NMDevice *self) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + const NMPlatformLink *plink; + gboolean has_carrier; + NML3CfgCheckReadyFlags flags; + gboolean ready; + gboolean acd_used = FALSE; + int IS_IPv4; + + if (priv->ipmanual_data.state_4 != NM_DEVICE_IP_STATE_PENDING + && priv->ipmanual_data.state_6 != NM_DEVICE_IP_STATE_PENDING) { + /* we only care about PENDING to get it READY. Currently not other + * conditions are implemented. That is, we cannot get to FAILED + * (maybe we should, if DAD fails) and we cannot get from anything + * once we are READY. */ + return; } - if (commit) { - gboolean is_vrf; - - is_vrf = priv->master && nm_device_get_device_type(priv->master) == NM_DEVICE_TYPE_VRF; + plink = nm_l3cfg_get_pllink(priv->l3cfg, TRUE); + has_carrier = plink && NM_FLAGS_HAS(plink->n_ifi_flags, IFF_LOWER_UP); - if (IS_IPv4) { - nm_ip4_config_add_dependent_routes(NM_IP4_CONFIG(composite), - nm_device_get_route_table(self, addr_family), - nm_device_get_route_metric(self, addr_family), - is_vrf, - &ip4_dev_route_blacklist); + if (has_carrier) { + nm_clear_g_source_inst(&priv->ipmanual_data.carrier_timeout); + } else { + if (priv->ipmanual_data.carrier_timeout_expired) { + /* go on */ + } else if (priv->ipmanual_data.carrier_timeout) { + /* wait a bit more until timer expires */ + return; } else { - nm_ip6_config_add_dependent_routes(NM_IP6_CONFIG(composite), - nm_device_get_route_table(self, addr_family), - nm_device_get_route_metric(self, addr_family), - is_vrf); + priv->ipmanual_data.carrier_timeout = + nm_g_timeout_add_source(2000, G_SOURCE_FUNC(_dev_ipmanual_carrier_timeout), self); + return; } } - if (IS_IPv4) { - if (commit) { - if (NM_DEVICE_GET_CLASS(self)->ip4_config_pre_commit) - NM_DEVICE_GET_CLASS(self)->ip4_config_pre_commit(self, NM_IP4_CONFIG(composite)); - } + flags = NM_L3CFG_CHECK_READY_FLAGS_NONE; + if (has_carrier) { + flags |= NM_L3CFG_CHECK_READY_FLAGS_IP4_ACD_READY; + flags |= NM_L3CFG_CHECK_READY_FLAGS_IP6_DAD_READY; } - if (!IS_IPv4) { - NMUtilsIPv6IfaceId iid; + for (IS_IPv4 = 0; IS_IPv4 < 2; IS_IPv4++) { + const int addr_family = IS_IPv4 ? AF_INET : AF_INET6; - if (commit && priv->ndisc_started && ip6_addr_gen_token - && nm_utils_ipv6_interface_identifier_get_from_token(&iid, ip6_addr_gen_token)) { - set_ipv6_token(self, &iid, ip6_addr_gen_token); + ready = nm_l3cfg_check_ready(priv->l3cfg, + priv->l3cds[L3_CONFIG_DATA_TYPE_MANUALIP].d, + addr_family, + flags, + &acd_used); + if (acd_used) { + _dev_ipmanual_set_state(self, addr_family, NM_DEVICE_IP_STATE_FAILED); + _dev_ip_state_check_async(self, AF_UNSPEC); + } else if (ready) { + _dev_ipmanual_set_state(self, addr_family, NM_DEVICE_IP_STATE_READY); + _dev_ip_state_check_async(self, AF_UNSPEC); } } - - success = - nm_device_set_ip_config(self, addr_family, composite, commit, ip4_dev_route_blacklist); - if (commit) { - if (IS_IPv4) - priv->v4_commit_first_time = FALSE; - else - priv->v6_commit_first_time = FALSE; - } - - return success; } -static gboolean -dhcp4_lease_change(NMDevice *self, NMIP4Config *config, gboolean bound) +static void +_dev_ipmanual_start(NMDevice *self) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - gs_free_error GError *error = NULL; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; - g_return_val_if_fail(config, FALSE); - - applied_config_init(&priv->dev_ip_config_4, config); + if (priv->ipmanual_data.state_4 != NM_DEVICE_IP_STATE_NONE + || priv->ipmanual_data.state_6 != NM_DEVICE_IP_STATE_NONE) + return; - if (!ip_config_merge_and_apply(self, AF_INET, TRUE)) { - _LOGW(LOGD_DHCP4, "failed to update IPv4 config for DHCP change."); - return FALSE; + if (nm_device_get_ip_ifindex(self) > 0) { + l3cd = + nm_device_create_l3_config_data_from_connection(self, + nm_device_get_applied_connection(self)); } - /* TODO: we should perform DAD again whenever we obtain a - * new lease after an expiry. But what should we do if - * a duplicate address is detected? Fail the connection; - * restart DHCP; continue without an address? */ - if (bound && !nm_dhcp_client_accept(priv->dhcp_data_4.client, &error)) { - _LOGW(LOGD_DHCP4, "error accepting lease: %s", error->message); - return FALSE; + if (!l3cd) { + _dev_ipmanual_cleanup(self); + return; } - nm_dispatcher_call_device(NM_DISPATCHER_ACTION_DHCP_CHANGE_4, self, NULL, NULL, NULL, NULL); + /* Initially we set the state to pending, because we (maybe) have to perform ACD first. */ + _dev_ipmanual_set_state(self, AF_UNSPEC, NM_DEVICE_IP_STATE_PENDING); - return TRUE; + _dev_l3_register_l3cds_set_one(self, L3_CONFIG_DATA_TYPE_MANUALIP, l3cd, FALSE); + + _dev_ip_state_check_async(self, AF_UNSPEC); } -static gboolean -dhcp_grace_period_expired(NMDevice *self, int addr_family) +/*****************************************************************************/ + +static void +_dev_ipdhcpx_set_state(NMDevice *self, int addr_family, NMDeviceIPState state) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); const int IS_IPv4 = NM_IS_IPv4(addr_family); - priv->dhcp_data_x[IS_IPv4].grace_id = 0; - priv->dhcp_data_x[IS_IPv4].grace_pending = FALSE; - - _LOGI(LOGD_DHCPX(IS_IPv4), - "DHCPv%c: grace period expired", - nm_utils_addr_family_to_char(addr_family)); - - nm_device_ip_method_failed(self, addr_family, NM_DEVICE_STATE_REASON_IP_CONFIG_EXPIRED); - /* If the device didn't fail, the DHCP client will continue */ - - return G_SOURCE_REMOVE; -} - -static gboolean -dhcp_grace_period_expired_4(gpointer user_data) -{ - return dhcp_grace_period_expired(user_data, AF_INET); -} - -static gboolean -dhcp_grace_period_expired_6(gpointer user_data) -{ - return dhcp_grace_period_expired(user_data, AF_INET6); + if (priv->ipdhcp_data_x[IS_IPv4].state != state) { + _LOGD_ipdhcp(addr_family, + "set state %s (was %s)", + nm_device_ip_state_to_string(state), + nm_device_ip_state_to_string(priv->ipdhcp_data_x[IS_IPv4].state)); + priv->ipdhcp_data_x[IS_IPv4].state = state; + } } -static gboolean -dhcp_grace_period_start(NMDevice *self, int addr_family) +static void +_dev_ipdhcpx_cleanup(NMDevice *self, int addr_family, gboolean full_cleanup, gboolean release) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); const int IS_IPv4 = NM_IS_IPv4(addr_family); - guint32 timeout; - /* In any other case (expired lease, assumed connection, etc.), - * wait for some time before failing the IP method. - */ - if (priv->dhcp_data_x[IS_IPv4].grace_pending) { - /* already pending. */ - return FALSE; + _dev_ipdhcpx_set_state(self, addr_family, NM_DEVICE_IP_STATE_NONE); + + if (full_cleanup && !IS_IPv4) { + priv->ipdhcp_data_6.v6.mode = NM_NDISC_DHCP_LEVEL_NONE; + priv->ipdhcp_data_6.v6.needed_prefixes = 0; } - /* Start a grace period equal to the DHCP timeout multiplied - * by a constant factor. */ - timeout = _prop_get_ipvx_dhcp_timeout(self, addr_family); - if (timeout == NM_DHCP_TIMEOUT_INFINITY) - _LOGI(LOGD_DHCPX(IS_IPv4), - "DHCPv%c: trying to acquire a new lease", - nm_utils_addr_family_to_char(addr_family)); - else { - timeout = dhcp_grace_period_from_timeout(timeout); - _LOGI(LOGD_DHCPX(IS_IPv4), - "DHCPv%c: trying to acquire a new lease within %u seconds", - nm_utils_addr_family_to_char(addr_family), - timeout); - nm_assert(!priv->dhcp_data_x[IS_IPv4].grace_id); - priv->dhcp_data_x[IS_IPv4].grace_id = g_timeout_add_seconds( - timeout, - IS_IPv4 ? dhcp_grace_period_expired_4 : dhcp_grace_period_expired_6, - self); + if (full_cleanup) + _dev_l3_register_l3cds_set_one(self, L3_CONFIG_DATA_TYPE_DHCP_X(IS_IPv4), NULL, FALSE); + + if (priv->ipdhcp_data_x[IS_IPv4].client) { + nm_clear_g_signal_handler(priv->ipdhcp_data_x[IS_IPv4].client, + &priv->ipdhcp_data_x[IS_IPv4].notify_sigid); + nm_dhcp_client_stop(priv->ipdhcp_data_x[IS_IPv4].client, release); + g_clear_object(&priv->ipdhcp_data_x[IS_IPv4].client); } - priv->dhcp_data_x[IS_IPv4].grace_pending = TRUE; + if (full_cleanup && priv->ipdhcp_data_x[IS_IPv4].config) { + gs_unref_object NMDhcpConfig *config = + g_steal_pointer(&priv->ipdhcp_data_x[IS_IPv4].config); - return TRUE; + _notify(self, PROP_DHCPX_CONFIG(IS_IPv4)); + nm_dbus_object_unexport_on_idle(g_steal_pointer(&config)); + } + + _dev_ip_state_check_async(self, addr_family); } + static void -dhcp4_fail(NMDevice *self, NMDhcpState dhcp_state) +_dev_ipdhcpx_handle_fail(NMDevice *self, int addr_family, const char *reason) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - - _LOGD(LOGD_DHCP4, - "DHCPv4 failed (ip_state %s, was_active %d)", - nm_device_ip_state_to_string(priv->ip_state_4), - priv->dhcp_data_4.was_active); - - /* The client is always left running after a failure. */ - - /* Nothing to do if we failed before... */ - if (priv->ip_state_4 == NM_DEVICE_IP_STATE_FAIL) - goto clear_config; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + const int IS_IPv4 = NM_IS_IPv4(addr_family); - /* ... and also if there are static addresses configured - * on the interface. - */ - if (priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE && priv->con_ip_config_4 - && nm_ip4_config_get_num_addresses(priv->con_ip_config_4) > 0) - goto clear_config; - - /* Fail the method when one of the following is true: - * 1) the DHCP client terminated: it does not make sense to start a grace - * period without a client running; - * 2) we failed to get an initial lease AND the client was - * not active before. - */ - if (dhcp_state == NM_DHCP_STATE_TERMINATED - || (!priv->dhcp_data_4.was_active && priv->ip_state_4 == NM_DEVICE_IP_STATE_CONF)) { - nm_device_activate_schedule_ip_config_timeout(self, AF_INET); + if (priv->ipdhcp_data_x[IS_IPv4].state == NM_DEVICE_IP_STATE_FAILED) return; - } - if (dhcp_grace_period_start(self, AF_INET)) - goto clear_config; + _LOGT_ipdhcp(addr_family, "DHCP failing: %s", reason ?: "unknown reason"); - return; + _dev_ipdhcpx_set_state(self, addr_family, NM_DEVICE_IP_STATE_FAILED); -clear_config: - /* The previous configuration is no longer valid */ - if (priv->dhcp_data_4.config) { - nm_dbus_object_clear_and_unexport(&priv->dhcp_data_4.config); - priv->dhcp_data_4.config = nm_dhcp_config_new(AF_INET); - _notify(self, PROP_DHCP4_CONFIG); - } -} + _dev_l3_register_l3cds_set_one(self, L3_CONFIG_DATA_TYPE_DHCP_X(IS_IPv4), NULL, FALSE); -static void -dhcp4_dad_cb(NMDevice *self, NMIP4Config **configs, gboolean success) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + if (priv->ipdhcp_data_x[IS_IPv4].config) + nm_dhcp_config_set_lease(priv->ipdhcp_data_x[IS_IPv4].config, NULL); - if (success) { - nm_device_activate_schedule_ip_config_result(self, AF_INET, NM_IP_CONFIG_CAST(configs[1])); - } else { - nm_dhcp_client_decline(priv->dhcp_data_4.client, "Address conflict detected", NULL); - nm_device_ip_method_failed(self, AF_INET, NM_DEVICE_STATE_REASON_IP_ADDRESS_DUPLICATE); - } + _dev_ip_state_check_async(self, addr_family); } static void -dhcp4_notify(NMDhcpClient *client, const NMDhcpClientNotifyData *notify_data, NMDevice *self) +_dev_ipdhcpx_notify(NMDhcpClient *client, const NMDhcpClientNotifyData *notify_data, NMDevice *self) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - NMIP4Config * manual; - NMIP4Config ** configs; - NMConnection * connection; - NMDhcpState state; - NMIP4Config * ip4_config; - GHashTable * options; - - nm_assert(nm_dhcp_client_get_addr_family(client) == AF_INET); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + const int addr_family = nm_dhcp_client_get_addr_family(client); + const int IS_IPv4 = NM_IS_IPv4(addr_family); + nm_assert(notify_data); - nm_assert(notify_data->notify_type == NM_DHCP_CLIENT_NOTIFY_TYPE_STATE_CHANGED); + nm_assert(priv->ipdhcp_data_x[IS_IPv4].state > NM_DEVICE_IP_STATE_NONE); + nm_assert(client && priv->ipdhcp_data_x[IS_IPv4].client == client); + + switch (notify_data->notify_type) { + case NM_DHCP_CLIENT_NOTIFY_TYPE_PREFIX_DELEGATED: + nm_assert(!IS_IPv4); + /* Just re-emit. The device just contributes the prefix to the + * pool in NMPolicy, which decides about subnet allocation + * on the shared devices. */ + g_signal_emit(self, signals[IP6_PREFIX_DELEGATED], 0, notify_data->prefix_delegated.prefix); + return; - state = notify_data->state_changed.dhcp_state; - ip4_config = NM_IP4_CONFIG(notify_data->state_changed.ip_config); - options = notify_data->state_changed.options; + case NM_DHCP_CLIENT_NOTIFY_TYPE_NO_LEASE_TIMEOUT: + /* Here we also fail if we had a lease and it expired. Maybe, + * ipv[46].dhcp-timeout should only cover the time until we get + * a lease for the first time. How it is here, it means that a + * connection can fail after being connected successfully for a + * longer time. */ + _dev_ipdhcpx_handle_fail(self, addr_family, "timeout getting lease"); + return; - nm_assert(!ip4_config || NM_IS_IP4_CONFIG(ip4_config)); + case NM_DHCP_CLIENT_NOTIFY_TYPE_IT_LOOKS_BAD: + /* Like NM_DHCP_CLIENT_NOTIFY_TYPE_NO_LEASE_TIMEOUT, this does not + * apply only if we never got a lease, but also after being fully + * connected. We can also fail then. */ + _dev_ipdhcpx_handle_fail(self, addr_family, notify_data->it_looks_bad.reason); + return; - _LOGD(LOGD_DHCP4, "new DHCPv4 client state %d", (int) state); + case NM_DHCP_CLIENT_NOTIFY_TYPE_LEASE_UPDATE: - switch (state) { - case NM_DHCP_STATE_BOUND: - case NM_DHCP_STATE_EXTENDED: - if (!ip4_config) { - _LOGW(LOGD_DHCP4, "failed to get IPv4 config in response to DHCP event."); - dhcp4_fail(self, state); - break; + if (!notify_data->lease_update.l3cd) { + _LOGT_ipdhcp(addr_family, "lease lost"); + goto lease_update_out; } - nm_clear_g_source(&priv->dhcp_data_4.grace_id); - priv->dhcp_data_4.grace_pending = FALSE; - - /* After some failures, we have been able to renew the lease: - * update the ip state - */ - if (priv->ip_state_4 == NM_DEVICE_IP_STATE_FAIL) - _set_ip_state(self, AF_INET, NM_DEVICE_IP_STATE_CONF); - - g_free(priv->dhcp4.pac_url); - priv->dhcp4.pac_url = g_strdup(g_hash_table_lookup(options, "wpad")); - nm_device_set_proxy_config(self, priv->dhcp4.pac_url); - - nm_dhcp_config_set_options(priv->dhcp_data_4.config, options); - _notify(self, PROP_DHCP4_CONFIG); - - if (priv->ip_state_4 == NM_DEVICE_IP_STATE_CONF) { - connection = nm_device_get_applied_connection(self); - g_assert(connection); - - manual = nm_device_ip4_config_new(self); - nm_ip4_config_merge_setting(manual, - nm_connection_get_setting_ip4_config(connection), - NM_SETTING_CONNECTION_MDNS_DEFAULT, - NM_SETTING_CONNECTION_LLMNR_DEFAULT, - NM_SETTING_CONNECTION_DNS_OVER_TLS_DEFAULT, - nm_device_get_route_table(self, AF_INET), - nm_device_get_route_metric(self, AF_INET)); - - configs = g_new0(NMIP4Config *, 3); - configs[0] = manual; - configs[1] = g_object_ref(ip4_config); - - ipv4_dad_start(self, configs, dhcp4_dad_cb); - } else if (priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE) { - if (dhcp4_lease_change(self, ip4_config, state == NM_DHCP_STATE_BOUND)) - nm_device_update_metered(self); - else - dhcp4_fail(self, state); + if (notify_data->lease_update.accepted) + _LOGT_ipdhcp(addr_family, "lease accepted"); + else + _LOGT_ipdhcp(addr_family, "lease update"); + + nm_dhcp_config_set_lease(priv->ipdhcp_data_x[IS_IPv4].config, + notify_data->lease_update.l3cd); + + /* Schedule a commit of the configuration. If the DHCP client + * needs to accept the lease, it will send later a LEASE_UPDATE + * notification with accepted=1 once the address appears in platform. + * Otherwise, this notification already has accepted=1. */ + _dev_l3_register_l3cds_set_one_full(self, + L3_CONFIG_DATA_TYPE_DHCP_X(IS_IPv4), + notify_data->lease_update.l3cd, + NM_L3CFG_CONFIG_FLAGS_FORCE_ONCE, + FALSE); + + if (notify_data->lease_update.accepted) { + if (priv->ipdhcp_data_x[IS_IPv4].state != NM_DEVICE_IP_STATE_READY) { + _dev_ipdhcpx_set_state(self, addr_family, NM_DEVICE_IP_STATE_READY); + nm_dispatcher_call_device(NM_DISPATCHER_ACTION_DHCP_CHANGE_X(IS_IPv4), + self, + NULL, + NULL, + NULL, + NULL); + _dev_ip_state_check_async(self, addr_family); + } } - break; - case NM_DHCP_STATE_TIMEOUT: - dhcp4_fail(self, state); - break; - case NM_DHCP_STATE_EXPIRE: - /* Ignore expiry before we even have a lease (NAK, old lease, etc) */ - if (priv->ip_state_4 == NM_DEVICE_IP_STATE_CONF) - break; - /* fall-through */ - case NM_DHCP_STATE_DONE: - case NM_DHCP_STATE_FAIL: - case NM_DHCP_STATE_TERMINATED: - dhcp4_fail(self, state); - break; - default: - break; + +lease_update_out: + nm_device_update_metered(self); + return; } + + nm_assert_not_reached(); } -static NMActStageReturn -dhcp4_start(NMDevice *self) +/*****************************************************************************/ + +static void +_dev_ipdhcpx_start(NMDevice *self, int addr_family) { - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - NMSettingIPConfig *s_ip4; - gs_unref_bytes GBytes *vendor_class_identifier = NULL; - gs_unref_bytes GBytes *hwaddr = NULL; - gs_unref_bytes GBytes *bcast_hwaddr = NULL; - gs_unref_bytes GBytes *client_id = NULL; - NMConnection * connection; - NMSettingConnection * s_con; - GError * error = NULL; - const NMPlatformLink * pllink; - const char *const * reject_servers; + const int IS_IPv4 = NM_IS_IPv4(addr_family); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip; + const NML3ConfigData *previous_lease; + gs_unref_bytes GBytes *hwaddr = NULL; + gboolean enforce_duid = FALSE; + gs_free_error GError *error = NULL; + const NMPlatformLink *pllink; + guint no_lease_timeout_sec; + int ifindex; + const char *str; gboolean request_broadcast; - const char * str; + const char *fail_reason; - connection = nm_device_get_applied_connection(self); - g_return_val_if_fail(connection, FALSE); + if (priv->ipdhcp_data_x[IS_IPv4].state == NM_DEVICE_IP_STATE_NONE) + _dev_ipdhcpx_set_state(self, addr_family, NM_DEVICE_IP_STATE_PENDING); + else if (priv->ipdhcp_data_x[IS_IPv4].state > NM_DEVICE_IP_STATE_PENDING) { + /* already succeeded or failed */ + return; + } else if (priv->ipdhcp_data_x[IS_IPv4].client) { + /* DHCP client already started */ + return; + } - s_ip4 = nm_connection_get_setting_ip4_config(connection); + if (nm_device_sys_iface_state_is_external(self)) { + fail_reason = nm_assert_unreachable_val("cannot run DHCP on external interface"); + goto out_fail; + } + + connection = nm_device_get_applied_connection(self); + if (!connection) { + fail_reason = nm_assert_unreachable_val("no applied connection for starting DHCP"); + goto out_fail; + } s_con = nm_connection_get_setting_connection(connection); + s_ip = nm_connection_get_setting_ip_config(connection, addr_family); nm_assert(s_con); + nm_assert(s_ip); - /* Clear old exported DHCP options */ - nm_dbus_object_clear_and_unexport(&priv->dhcp_data_4.config); - priv->dhcp_data_4.config = nm_dhcp_config_new(AF_INET); + ifindex = 0; + pllink = nm_l3cfg_get_pllink(priv->l3cfg, TRUE); + if (pllink) { + ifindex = pllink->ifindex; + nm_assert(ifindex > 0); + nm_assert(ifindex == nm_device_get_ip_ifindex(self)); + } + if (ifindex <= 0) { + fail_reason = "cannot start DHCP without interface"; + goto out_fail; + } - request_broadcast = FALSE; + hwaddr = nmp_link_address_get_as_bytes(&pllink->l_address); - pllink = nm_platform_link_get(nm_device_get_platform(self), nm_device_get_ip_ifindex(self)); - if (pllink) { - hwaddr = nmp_link_address_get_as_bytes(&pllink->l_address); - bcast_hwaddr = nmp_link_address_get_as_bytes(&pllink->l_broadcast); + if (!IS_IPv4) { + if (!hwaddr) { + fail_reason = "interface has no MAC address to start DHCPv6"; + goto out_fail; + } + } + request_broadcast = FALSE; + if (pllink) { str = nmp_object_link_udev_device_get_property_value(NMP_OBJECT_UP_CAST(pllink), "ID_NET_DHCP_BROADCAST"); if (str && _nm_utils_ascii_str_to_bool(str, FALSE)) { @@ -9606,103 +10091,211 @@ dhcp4_start(NMDevice *self) } } - client_id = _prop_get_ipv4_dhcp_client_id(self, connection, hwaddr); - vendor_class_identifier = - _prop_get_ipv4_dhcp_vendor_class_identifier(self, NM_SETTING_IP4_CONFIG(s_ip4)); - reject_servers = nm_setting_ip_config_get_dhcp_reject_servers(s_ip4, NULL); - - g_warn_if_fail(priv->dhcp_data_4.client == NULL); - priv->dhcp_data_4.client = nm_dhcp_manager_start_ip4( - nm_dhcp_manager_get(), - nm_netns_get_multi_idx(nm_device_get_netns(self)), - nm_device_get_ip_iface(self), - nm_device_get_ip_ifindex(self), - hwaddr, - bcast_hwaddr, - nm_connection_get_uuid(connection), - nm_device_get_route_table(self, AF_INET), - nm_device_get_route_metric(self, AF_INET), - request_broadcast ? NM_DHCP_CLIENT_FLAGS_REQUEST_BROADCAST : NM_DHCP_CLIENT_FLAGS_NONE, - 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_fqdn(NM_SETTING_IP4_CONFIG(s_ip4)), - _prop_get_ipvx_dhcp_hostname_flags(self, AF_INET), - _prop_get_connection_mud_url(self, s_con), - client_id, - _prop_get_ipvx_dhcp_timeout(self, AF_INET), - _device_get_dhcp_anycast_address(self), - NULL, - vendor_class_identifier, - reject_servers, - &error); - if (!priv->dhcp_data_4.client) { - _LOGW(LOGD_DHCP4, "failure to start DHCP: %s", error->message); - g_clear_error(&error); - return NM_ACT_STAGE_RETURN_FAILURE; - } - - priv->dhcp_data_4.notify_sigid = g_signal_connect(priv->dhcp_data_4.client, - NM_DHCP_CLIENT_NOTIFY, - G_CALLBACK(dhcp4_notify), - self); + if (!IS_IPv4 + && NM_IN_SET(priv->ipll_data_6.state, + NM_DEVICE_IP_STATE_NONE, + NM_DEVICE_IP_STATE_PENDING)) { + _dev_ipll6_start(self); + return; + } + + no_lease_timeout_sec = _prop_get_ipvx_dhcp_timeout(self, addr_family); + + if (IS_IPv4) { + NMDhcpClientConfig config; + gs_unref_bytes GBytes *bcast_hwaddr = NULL; + gs_unref_bytes GBytes *client_id = NULL; + gs_unref_bytes GBytes *vendor_class_identifier = NULL; + const char *const *reject_servers; + const char *hostname; + gboolean hostname_is_fqdn; + + client_id = _prop_get_ipv4_dhcp_client_id(self, connection, hwaddr); + vendor_class_identifier = + _prop_get_ipv4_dhcp_vendor_class_identifier(self, NM_SETTING_IP4_CONFIG(s_ip)); + reject_servers = nm_setting_ip_config_get_dhcp_reject_servers(s_ip, NULL); + + bcast_hwaddr = nmp_link_address_get_as_bytes(&pllink->l_broadcast); + + hostname = nm_setting_ip4_config_get_dhcp_fqdn(NM_SETTING_IP4_CONFIG(s_ip)); + if (hostname) { + hostname_is_fqdn = TRUE; + } else { + hostname_is_fqdn = FALSE; + hostname = nm_setting_ip_config_get_dhcp_hostname(s_ip); + } + + config = (NMDhcpClientConfig){ + .addr_family = AF_INET, + .l3cfg = nm_device_get_l3cfg(self), + .iface = nm_device_get_ip_iface(self), + .uuid = nm_connection_get_uuid(connection), + .hwaddr = hwaddr, + .bcast_hwaddr = bcast_hwaddr, + .send_hostname = nm_setting_ip_config_get_dhcp_send_hostname(s_ip), + .hostname = hostname, + .hostname_flags = _prop_get_ipvx_dhcp_hostname_flags(self, AF_INET), + .client_id = client_id, + .mud_url = _prop_get_connection_mud_url(self, s_con), + .timeout = no_lease_timeout_sec, + .anycast_address = _device_get_dhcp_anycast_address(self), + .vendor_class_identifier = vendor_class_identifier, + .use_fqdn = hostname_is_fqdn, + .reject_servers = reject_servers, + .v4.request_broadcast = request_broadcast, + }; + + priv->ipdhcp_data_4.client = + nm_dhcp_manager_start_client(nm_dhcp_manager_get(), &config, &error); + } else { + gs_unref_bytes GBytes *duid = NULL; + gboolean iaid_explicit; + guint32 iaid; + NMDhcpClientConfig config; + + iaid = _prop_get_ipvx_dhcp_iaid(self, AF_INET6, connection, FALSE, &iaid_explicit); + duid = _prop_get_ipv6_dhcp_duid(self, connection, hwaddr, &enforce_duid); + + config = (NMDhcpClientConfig){ + .addr_family = AF_INET6, + .l3cfg = nm_device_get_l3cfg(self), + .iface = nm_device_get_ip_iface(self), + .uuid = nm_connection_get_uuid(connection), + .send_hostname = nm_setting_ip_config_get_dhcp_send_hostname(s_ip), + .hostname = nm_setting_ip_config_get_dhcp_hostname(s_ip), + .hostname_flags = _prop_get_ipvx_dhcp_hostname_flags(self, AF_INET6), + .client_id = duid, + .mud_url = _prop_get_connection_mud_url(self, s_con), + .timeout = no_lease_timeout_sec, + .anycast_address = _device_get_dhcp_anycast_address(self), + .v6.enforce_duid = enforce_duid, + .v6.iaid = iaid, + .v6.iaid_explicit = iaid_explicit, + .v6.info_only = (priv->ipdhcp_data_6.v6.mode == NM_NDISC_DHCP_LEVEL_OTHERCONF), + .v6.needed_prefixes = priv->ipdhcp_data_6.v6.needed_prefixes, + }; + + priv->ipdhcp_data_6.client = + nm_dhcp_manager_start_client(nm_dhcp_manager_get(), &config, &error); + } + + if (!priv->ipdhcp_data_x[IS_IPv4].client) { + fail_reason = error->message; + goto out_fail; + } + + priv->ipdhcp_data_x[IS_IPv4].notify_sigid = + g_signal_connect(priv->ipdhcp_data_x[IS_IPv4].client, + NM_DHCP_CLIENT_NOTIFY, + G_CALLBACK(_dev_ipdhcpx_notify), + self); - if (nm_device_sys_iface_state_is_external_or_assume(self)) - priv->dhcp_data_4.was_active = TRUE; + /* FIXME(l3cfg:dhcp:previous-lease): take the NML3ConfigData from the previous lease (if any) + * and pass it on to NMDhcpClient. This is a fake lease that we use initially (until + * NMDhcpClient got a real lease). Note that NMDhcpClient needs to check whether the + * lease already expired. */ - /* DHCP devices will be notified by the DHCP manager when stuff happens */ - return NM_ACT_STAGE_RETURN_POSTPONE; + previous_lease = nm_dhcp_client_get_lease(priv->ipdhcp_data_x[IS_IPv4].client); + if (!priv->ipdhcp_data_x[IS_IPv4].config) { + priv->ipdhcp_data_x[IS_IPv4].config = nm_dhcp_config_new(addr_family, previous_lease); + _notify(self, PROP_DHCPX_CONFIG(IS_IPv4)); + } + if (previous_lease) { + nm_dhcp_config_set_lease(priv->ipdhcp_data_x[IS_IPv4].config, previous_lease); + _dev_l3_register_l3cds_set_one_full(self, + L3_CONFIG_DATA_TYPE_DHCP_X(IS_IPv4), + previous_lease, + NM_L3CFG_CONFIG_FLAGS_FORCE_ONCE, + FALSE); + } + + return; + +out_fail: + _dev_ipdhcpx_handle_fail(self, addr_family, fail_reason); } -gboolean -nm_device_dhcp4_renew(NMDevice *self, gboolean release) +static void +_dev_ipdhcpx_start_continue(NMDevice *self, int addr_family) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + const int IS_IPv4 = NM_IS_IPv4(addr_family); + + if (priv->ipdhcp_data_x[IS_IPv4].state != NM_DEVICE_IP_STATE_NONE) + _dev_ipdhcpx_start(self, addr_family); +} - g_return_val_if_fail(priv->dhcp_data_4.client != NULL, FALSE); +static void +_dev_ipdhcpx_restart(NMDevice *self, int addr_family, gboolean release) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + const int IS_IPv4 = NM_IS_IPv4(addr_family); - _LOGI(LOGD_DHCP4, "DHCPv4 lease renewal requested"); + if (priv->ipdhcp_data_x[IS_IPv4].state != NM_DEVICE_IP_STATE_NONE) { + _LOGI_ipdhcp(addr_family, "restarting%s", release ? " (release lease)" : ""); + _dev_ipdhcpx_cleanup(self, addr_family, FALSE, release); + } - /* Terminate old DHCP instance and release the old lease */ - dhcp4_cleanup(self, CLEANUP_TYPE_DECONFIGURE, release); + _dev_ipdhcpx_start(self, addr_family); +} - /* Start DHCP again on the interface */ - return dhcp4_start(self) != NM_ACT_STAGE_RETURN_FAILURE; +void +nm_device_ip_method_dhcp4_start(NMDevice *self) +{ + _dev_ipdhcpx_start(self, AF_INET); } -/*****************************************************************************/ +static void +_dev_ipdhcp6_set_dhcp_level(NMDevice *self, NMNDiscDHCPLevel dhcp_level) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + + nm_assert(NM_IN_SET(dhcp_level, + NM_NDISC_DHCP_LEVEL_NONE, + NM_NDISC_DHCP_LEVEL_OTHERCONF, + NM_NDISC_DHCP_LEVEL_MANAGED)); + + if (dhcp_level == NM_NDISC_DHCP_LEVEL_NONE && priv->ipdhcp_data_6.v6.needed_prefixes > 0) + dhcp_level = NM_NDISC_DHCP_LEVEL_OTHERCONF; + + if (priv->ipdhcp_data_6.v6.mode == dhcp_level) + return; + + _LOGD_ipdhcp(AF_INET6, "level: set to %s", nm_ndisc_dhcp_level_to_string(dhcp_level)); + + if (dhcp_level == NM_NDISC_DHCP_LEVEL_NONE) { + _dev_ipdhcpx_cleanup(self, AF_INET6, TRUE, TRUE); + return; + } + + priv->ipdhcp_data_6.v6.mode = dhcp_level; + _dev_ipdhcpx_restart(self, AF_INET6, TRUE); +} -static NMIP4Config * -shared4_new_config(NMDevice *self, NMConnection *connection) +/* + * Called on the requesting interface when a subnet can't be obtained + * from known prefixes for a newly active shared connection. + */ +void +nm_device_request_ip6_prefixes(NMDevice *self, guint needed_prefixes) { - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - NMIP4Config * config; - NMSettingIPConfig * s_ip4; - NMPlatformIP4Address address = { - .addr_source = NM_IP_CONFIG_SOURCE_SHARED, - }; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - g_return_val_if_fail(self, NULL); - g_return_val_if_fail(connection, NULL); + if (priv->ipdhcp_data_6.v6.needed_prefixes == needed_prefixes) + return; - s_ip4 = nm_connection_get_setting_ip4_config(connection); - if (s_ip4 && nm_setting_ip_config_get_num_addresses(s_ip4) > 0) { - /* Use the first user-supplied address */ - NMIPAddress *user = nm_setting_ip_config_get_address(s_ip4, 0); - in_addr_t a; + _LOGD(LOGD_IP6, "ipv6-pd: asking DHCPv6 for %u prefixes", needed_prefixes); - nm_ip_address_get_address_binary(user, &a); - nm_platform_ip4_address_set_addr(&address, a, nm_ip_address_get_prefix(user)); - nm_clear_pointer(&priv->shared_ip_handle, nm_netns_shared_ip_release); - } else { - if (!priv->shared_ip_handle) - priv->shared_ip_handle = nm_netns_shared_ip_reserve(nm_device_get_netns(self)); - nm_platform_ip4_address_set_addr(&address, priv->shared_ip_handle->addr, 24); - } + priv->ipdhcp_data_6.v6.needed_prefixes = needed_prefixes; - config = nm_device_ip4_config_new(self); - nm_ip4_config_add_address(config, &address); + if (priv->ipdhcp_data_6.v6.mode == NM_NDISC_DHCP_LEVEL_NONE) { + priv->ipdhcp_data_6.v6.mode = NM_NDISC_DHCP_LEVEL_OTHERCONF; + _LOGD_ipdhcp(AF_INET6, + "level: set to %s", + nm_ndisc_dhcp_level_to_string(NM_NDISC_DHCP_LEVEL_OTHERCONF)); + } - return config; + _dev_ipdhcpx_restart(self, AF_INET6, TRUE); } /*****************************************************************************/ @@ -9710,7 +10303,7 @@ shared4_new_config(NMDevice *self, NMConnection *connection) static gboolean connection_ip_method_requires_carrier(NMConnection *connection, int addr_family, - gboolean * out_ip_enabled) + gboolean *out_ip_enabled) { const char *method; @@ -9737,7 +10330,7 @@ connection_ip_method_requires_carrier(NMConnection *connection, static gboolean connection_requires_carrier(NMConnection *connection) { - NMSettingIPConfig * s_ip4, *s_ip6; + NMSettingIPConfig *s_ip4, *s_ip6; NMSettingConnection *s_con; gboolean ip4_carrier_wanted, ip6_carrier_wanted; gboolean ip4_used = FALSE, ip6_used = FALSE; @@ -9784,8 +10377,8 @@ static gboolean have_any_ready_slaves(NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - SlaveInfo * info; - CList * iter; + SlaveInfo *info; + CList *iter; /* Any enslaved slave is "ready" in the generic case as it's * at least >= NM_DEVCIE_STATE_IP_CONFIG and has had Layer 2 @@ -9800,392 +10393,6 @@ have_any_ready_slaves(NMDevice *self) } /*****************************************************************************/ -/* DHCPv6 stuff */ - -static void -dhcp6_cleanup(NMDevice *self, CleanupType cleanup_type, gboolean release) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - - priv->dhcp_data_6.was_active = FALSE; - priv->dhcp6.mode = NM_NDISC_DHCP_LEVEL_NONE; - applied_config_clear(&priv->dhcp6.ip6_config); - nm_clear_g_free(&priv->dhcp6.event_id); - nm_clear_g_source(&priv->dhcp_data_6.grace_id); - priv->dhcp_data_6.grace_pending = FALSE; - - if (priv->dhcp_data_6.client) { - nm_clear_g_signal_handler(priv->dhcp_data_6.client, &priv->dhcp_data_6.notify_sigid); - - if (cleanup_type == CLEANUP_TYPE_DECONFIGURE || cleanup_type == CLEANUP_TYPE_REMOVED) - nm_dhcp_client_stop(priv->dhcp_data_6.client, release); - - g_clear_object(&priv->dhcp_data_6.client); - } - - if (priv->dhcp_data_6.config) { - nm_dbus_object_clear_and_unexport(&priv->dhcp_data_6.config); - _notify(self, PROP_DHCP6_CONFIG); - } -} - -static gboolean -dhcp6_lease_change(NMDevice *self) -{ - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - NMSettingsConnection *settings_connection; - - if (!applied_config_get_current(&priv->dhcp6.ip6_config)) { - _LOGW(LOGD_DHCP6, "failed to get DHCPv6 config for rebind"); - return FALSE; - } - - g_assert(priv->dhcp_data_6.client); /* sanity check */ - - settings_connection = nm_device_get_settings_connection(self); - g_assert(settings_connection); - - /* Apply the updated config */ - if (!ip_config_merge_and_apply(self, AF_INET6, TRUE)) { - _LOGW(LOGD_DHCP6, "failed to update IPv6 config in response to DHCP event"); - return FALSE; - } - - nm_dispatcher_call_device(NM_DISPATCHER_ACTION_DHCP_CHANGE_6, self, NULL, NULL, NULL, NULL); - - return TRUE; -} - -static void -dhcp6_fail(NMDevice *self, NMDhcpState dhcp_state) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - gboolean is_dhcp_managed; - - _LOGD(LOGD_DHCP6, - "DHCPv6 failed (ip_state %s, was_active %d)", - nm_device_ip_state_to_string(priv->ip_state_6), - priv->dhcp_data_6.was_active); - - /* The client is always left running after a failure. */ - - /* Nothing to do if we failed before... */ - if (priv->ip_state_6 == NM_DEVICE_IP_STATE_FAIL) - goto clear_config; - - is_dhcp_managed = (priv->dhcp6.mode == NM_NDISC_DHCP_LEVEL_MANAGED); - - if (is_dhcp_managed) { - /* ... and also if there are static addresses configured - * on the interface. - */ - if (priv->ip_state_6 == NM_DEVICE_IP_STATE_DONE && priv->con_ip_config_6 - && nm_ip6_config_get_num_addresses(priv->con_ip_config_6)) - goto clear_config; - - /* Fail the method when one of the following is true: - * 1) the DHCP client terminated: it does not make sense to start a grace - * period without a client running; - * 2) we failed to get an initial lease AND the client was - * not active before. - */ - if (dhcp_state == NM_DHCP_STATE_TERMINATED - || (!priv->dhcp_data_6.was_active && priv->ip_state_6 == NM_DEVICE_IP_STATE_CONF)) { - nm_device_activate_schedule_ip_config_timeout(self, AF_INET6); - return; - } - - if (dhcp_grace_period_start(self, AF_INET6)) - goto clear_config; - } else { - /* not a hard failure; just live with the RA info */ - dhcp6_cleanup(self, CLEANUP_TYPE_DECONFIGURE, FALSE); - if (priv->ip_state_6 == NM_DEVICE_IP_STATE_CONF) - nm_device_activate_schedule_ip_config_result(self, AF_INET6, NULL); - } - return; - -clear_config: - /* The previous configuration is no longer valid */ - if (priv->dhcp_data_6.config) { - nm_dbus_object_clear_and_unexport(&priv->dhcp_data_6.config); - priv->dhcp_data_6.config = nm_dhcp_config_new(AF_INET6); - _notify(self, PROP_DHCP6_CONFIG); - } -} - -static void -dhcp6_notify(NMDhcpClient *client, const NMDhcpClientNotifyData *notify_data, NMDevice *self) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - gs_free char * event_id = NULL; - NMDhcpState state; - NMIP6Config * ip6_config; - GHashTable * options; - - nm_assert(nm_dhcp_client_get_addr_family(client) == AF_INET6); - nm_assert(notify_data); - - if (notify_data->notify_type == NM_DHCP_CLIENT_NOTIFY_TYPE_PREFIX_DELEGATED) { - /* Just re-emit. The device just contributes the prefix to the - * pool in NMPolicy, which decides about subnet allocation - * on the shared devices. */ - g_signal_emit(self, signals[IP6_PREFIX_DELEGATED], 0, notify_data->prefix_delegated.prefix); - return; - } - - nm_assert(notify_data->notify_type == NM_DHCP_CLIENT_NOTIFY_TYPE_STATE_CHANGED); - - state = notify_data->state_changed.dhcp_state; - ip6_config = NM_IP6_CONFIG(notify_data->state_changed.ip_config); - options = notify_data->state_changed.options; - - nm_assert(!ip6_config || NM_IS_IP6_CONFIG(ip6_config)); - - _LOGD(LOGD_DHCP6, "new DHCPv6 client state %d", (int) state); - - switch (state) { - case NM_DHCP_STATE_BOUND: - case NM_DHCP_STATE_EXTENDED: - nm_clear_g_source(&priv->dhcp_data_6.grace_id); - priv->dhcp_data_6.grace_pending = FALSE; - /* If the server sends multiple IPv6 addresses, we receive a state - * changed event for each of them. Use the event ID to merge IPv6 - * addresses from the same transaction into a single configuration. - */ - - event_id = nm_dhcp_utils_get_dhcp6_event_id(options); - - if (ip6_config && event_id && priv->dhcp6.event_id - && nm_streq(event_id, priv->dhcp6.event_id)) { - NMDedupMultiIter ipconf_iter; - const NMPlatformIP6Address *a; - - nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, ip6_config, &a) - applied_config_add_address(&priv->dhcp6.ip6_config, NM_PLATFORM_IP_ADDRESS_CAST(a)); - } else { - nm_clear_g_free(&priv->dhcp6.event_id); - if (ip6_config) { - applied_config_init(&priv->dhcp6.ip6_config, ip6_config); - priv->dhcp6.event_id = g_strdup(event_id); - nm_dhcp_config_set_options(priv->dhcp_data_6.config, options); - _notify(self, PROP_DHCP6_CONFIG); - } else - applied_config_clear(&priv->dhcp6.ip6_config); - } - - /* After long time we have been able to renew the lease: - * update the ip state - */ - if (priv->ip_state_6 == NM_DEVICE_IP_STATE_FAIL) - _set_ip_state(self, AF_INET6, NM_DEVICE_IP_STATE_CONF); - - if (priv->ip_state_6 == NM_DEVICE_IP_STATE_CONF) { - if (!applied_config_get_current(&priv->dhcp6.ip6_config)) { - nm_device_ip_method_failed(self, AF_INET6, NM_DEVICE_STATE_REASON_DHCP_FAILED); - break; - } - nm_device_activate_schedule_ip_config_result(self, AF_INET6, NULL); - } else if (priv->ip_state_6 == NM_DEVICE_IP_STATE_DONE) - if (!dhcp6_lease_change(self)) - dhcp6_fail(self, state); - break; - case NM_DHCP_STATE_TIMEOUT: - if (priv->dhcp6.mode == NM_NDISC_DHCP_LEVEL_MANAGED) - dhcp6_fail(self, state); - else { - /* not a hard failure; just live with the RA info */ - dhcp6_cleanup(self, CLEANUP_TYPE_DECONFIGURE, FALSE); - if (priv->ip_state_6 == NM_DEVICE_IP_STATE_CONF) - nm_device_activate_schedule_ip_config_result(self, AF_INET6, NULL); - } - break; - case NM_DHCP_STATE_EXPIRE: - /* Ignore expiry before we even have a lease (NAK, old lease, etc) */ - if (priv->ip_state_6 != NM_DEVICE_IP_STATE_CONF) - dhcp6_fail(self, state); - break; - case NM_DHCP_STATE_TERMINATED: - /* In IPv6 info-only mode, the client doesn't handle leases so it - * may exit right after getting a response from the server. That's - * normal. In that case we just ignore the exit. - */ - if (priv->dhcp6.mode == NM_NDISC_DHCP_LEVEL_OTHERCONF) - break; - /* fall-through */ - case NM_DHCP_STATE_DONE: - case NM_DHCP_STATE_FAIL: - dhcp6_fail(self, state); - break; - default: - break; - } -} - -/*****************************************************************************/ - -static gboolean -dhcp6_start_with_link_ready(NMDevice *self, NMConnection *connection) -{ - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - NMSettingIPConfig *s_ip6; - gs_unref_bytes GBytes *hwaddr = NULL; - gs_unref_bytes GBytes * duid = NULL; - gboolean enforce_duid = FALSE; - const NMPlatformLink * pllink; - GError * error = NULL; - guint32 iaid; - gboolean iaid_explicit; - NMSettingConnection * s_con; - const NMPlatformIP6Address *ll_addr = NULL; - int ip_ifindex; - - g_return_val_if_fail(connection, FALSE); - - s_ip6 = nm_connection_get_setting_ip6_config(connection); - nm_assert(s_ip6); - s_con = nm_connection_get_setting_connection(connection); - nm_assert(s_con); - - if (priv->ext_ip6_config_captured) { - ll_addr = nm_ip_config_find_first_address(NM_IP_CONFIG(priv->ext_ip6_config_captured), - NM_PLATFORM_MATCH_WITH_ADDRTYPE_LINKLOCAL - | NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL); - } - - if (!ll_addr) { - _LOGW(LOGD_DHCP6, "can't start DHCPv6: no link-local address"); - return FALSE; - } - - ip_ifindex = nm_device_get_ip_ifindex(self); - if (ip_ifindex <= 0) { - _LOGD(LOGD_DHCP6, "can't start DHCPv6: interface is gone"); - return FALSE; - } - - pllink = nm_platform_link_get(nm_device_get_platform(self), ip_ifindex); - if (pllink) - hwaddr = nmp_link_address_get_as_bytes(&pllink->l_address); - - iaid = _prop_get_ipvx_dhcp_iaid(self, AF_INET6, connection, TRUE, &iaid_explicit); - duid = _prop_get_ipv6_dhcp_duid(self, connection, hwaddr, &enforce_duid); - - priv->dhcp_data_6.client = nm_dhcp_manager_start_ip6( - nm_dhcp_manager_get(), - nm_device_get_multi_index(self), - nm_device_get_ip_iface(self), - ip_ifindex, - &ll_addr->address, - nm_connection_get_uuid(connection), - nm_device_get_route_table(self, AF_INET6), - nm_device_get_route_metric(self, AF_INET6), - (priv->dhcp6.mode == NM_NDISC_DHCP_LEVEL_OTHERCONF) ? NM_DHCP_CLIENT_FLAGS_INFO_ONLY - : NM_DHCP_CLIENT_FLAGS_NONE, - nm_setting_ip_config_get_dhcp_send_hostname(s_ip6), - nm_setting_ip_config_get_dhcp_hostname(s_ip6), - _prop_get_ipvx_dhcp_hostname_flags(self, AF_INET6), - _prop_get_connection_mud_url(self, s_con), - duid, - enforce_duid, - iaid, - iaid_explicit, - _prop_get_ipvx_dhcp_timeout(self, AF_INET6), - _device_get_dhcp_anycast_address(self), - nm_setting_ip6_config_get_ip6_privacy(NM_SETTING_IP6_CONFIG(s_ip6)), - priv->dhcp6.needed_prefixes, - &error); - if (!priv->dhcp_data_6.client) { - _LOGW(LOGD_DHCP6, "failure to start DHCPv6: %s", error->message); - g_clear_error(&error); - if (nm_device_sys_iface_state_is_external_or_assume(self)) - priv->dhcp_data_6.was_active = TRUE; - return FALSE; - } - - priv->dhcp_data_6.notify_sigid = g_signal_connect(priv->dhcp_data_6.client, - NM_DHCP_CLIENT_NOTIFY, - G_CALLBACK(dhcp6_notify), - self); - - if (nm_device_sys_iface_state_is_external_or_assume(self)) - priv->dhcp_data_6.was_active = TRUE; - - return TRUE; -} - -static gboolean -dhcp6_start(NMDevice *self, gboolean wait_for_ll) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - NMConnection * connection; - - nm_dbus_object_clear_and_unexport(&priv->dhcp_data_6.config); - priv->dhcp_data_6.config = nm_dhcp_config_new(AF_INET6); - - nm_assert(!applied_config_get_current(&priv->dhcp6.ip6_config)); - applied_config_clear(&priv->dhcp6.ip6_config); - nm_clear_g_free(&priv->dhcp6.event_id); - - connection = nm_device_get_applied_connection(self); - g_return_val_if_fail(connection, FALSE); - - if (wait_for_ll) { - /* ensure link local is ready... */ - if (!linklocal6_start(self)) { - /* wait for the LL address to show up */ - return TRUE; - } - /* already have the LL address; kick off DHCP */ - } - - if (!dhcp6_start_with_link_ready(self, connection)) - return FALSE; - - return TRUE; -} - -gboolean -nm_device_dhcp6_renew(NMDevice *self, gboolean release) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - NMNDiscDHCPLevel mode; - - g_return_val_if_fail(priv->dhcp_data_6.client != NULL, FALSE); - - _LOGI(LOGD_DHCP6, "DHCPv6 lease renewal requested"); - - /* Terminate old DHCP instance and release the old lease */ - mode = priv->dhcp6.mode; - dhcp6_cleanup(self, CLEANUP_TYPE_DECONFIGURE, release); - priv->dhcp6.mode = mode; - - /* Start DHCP again on the interface */ - return dhcp6_start(self, FALSE); -} - -/*****************************************************************************/ - -/* - * Called on the requesting interface when a subnet can't be obtained - * from known prefixes for a newly active shared connection. - */ -void -nm_device_request_ip6_prefixes(NMDevice *self, int needed_prefixes) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - - priv->dhcp6.needed_prefixes = needed_prefixes; - - if (priv->dhcp_data_6.client) { - _LOGD(LOGD_IP6, "ipv6-pd: asking DHCPv6 for %d prefixes", needed_prefixes); - nm_device_dhcp6_renew(self, FALSE); - } else { - priv->dhcp6.mode = NM_NDISC_DHCP_LEVEL_OTHERCONF; - _LOGD(LOGD_DEVICE | LOGD_DHCP6, "ipv6-pd: starting DHCPv6 to request a prefix"); - dhcp6_start(self, FALSE); - } -} gboolean nm_device_needs_ip6_subnet(NMDevice *self) @@ -10200,25 +10407,25 @@ nm_device_needs_ip6_subnet(NMDevice *self) void nm_device_use_ip6_subnet(NMDevice *self, const NMPlatformIP6Address *subnet) { - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - NMPlatformIP6Address address = *subnet; - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + char sbuf[sizeof(_nm_utils_to_string_buffer)]; + NMPlatformIP6Address address; - if (!applied_config_get_current(&priv->ac_ip6_config)) - applied_config_init_new(&priv->ac_ip6_config, self, AF_INET6); + l3cd = nm_device_create_l3_config_data(self, NM_IP_CONFIG_SOURCE_SHARED); /* Assign a ::1 address in the subnet for us. */ + address = *subnet; address.address.s6_addr32[3] |= htonl(1); - applied_config_add_address(&priv->ac_ip6_config, NM_PLATFORM_IP_ADDRESS_CAST(&address)); + + nm_l3_config_data_add_address_6(l3cd, &address); _LOGD(LOGD_IP6, - "ipv6-pd: using %s address (preferred for %u seconds)", - _nm_utils_inet6_ntop(&address.address, sbuf), - subnet->preferred); + "ipv6-pd: using %s", + nm_platform_ip6_address_to_string(&address, sbuf, sizeof(sbuf))); - /* This also updates the ndisc if there are actual changes. */ - if (!ip_config_merge_and_apply(self, AF_INET6, TRUE)) - _LOGW(LOGD_IP6, "ipv6-pd: failed applying IP6 config for connection sharing"); + _dev_l3_register_l3cds_set_one(self, L3_CONFIG_DATA_TYPE_PD_6, l3cd, FALSE); + _dev_l3_cfg_commit(self, TRUE); + _dev_ipac6_ndisc_set_router_config(self); } /* @@ -10228,217 +10435,231 @@ nm_device_use_ip6_subnet(NMDevice *self, const NMPlatformIP6Address *subnet) void nm_device_copy_ip6_dns_config(NMDevice *self, NMDevice *from_device) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - NMIP6Config * from_config = NULL; - guint i, len; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NMDevicePrivate *priv_src; + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + const NML3ConfigData *l3cd_src = NULL; - if (applied_config_get_current(&priv->ac_ip6_config)) { - applied_config_reset_nameservers(&priv->ac_ip6_config); - applied_config_reset_searches(&priv->ac_ip6_config); - } else - applied_config_init_new(&priv->ac_ip6_config, self, AF_INET6); + /* FIXME(l3cfg): this entire code an approach seems flawed. It's flawed, because the + * very next RA will reset the changes. */ - if (from_device) - from_config = nm_device_get_ip6_config(from_device); - if (!from_config) - return; + if (priv->l3cds[L3_CONFIG_DATA_TYPE_AC_6].d) { + l3cd = nm_l3_config_data_new_clone(priv->l3cds[L3_CONFIG_DATA_TYPE_AC_6].d, 0); + nm_l3_config_data_clear_nameservers(l3cd, AF_INET6); + nm_l3_config_data_clear_searches(l3cd, AF_INET6); + } else + l3cd = nm_device_create_l3_config_data(self, NM_IP_CONFIG_SOURCE_SHARED); - len = nm_ip6_config_get_num_nameservers(from_config); - for (i = 0; i < len; i++) { - applied_config_add_nameserver( - &priv->ac_ip6_config, - (const NMIPAddr *) nm_ip6_config_get_nameserver(from_config, i)); + if (from_device) { + priv_src = NM_DEVICE_GET_PRIVATE(from_device); + l3cd_src = priv_src->l3cds[L3_CONFIG_DATA_TYPE_AC_6].d; } + if (l3cd_src) { + const char *const *strvarr; + const struct in6_addr *const *addrs; + guint n; + guint i; + + addrs = nm_l3_config_data_get_nameservers(l3cd_src, AF_INET6, &n); + for (i = 0; i < n; i++) + nm_l3_config_data_add_nameserver(l3cd, AF_INET6, addrs[i]); - len = nm_ip6_config_get_num_searches(from_config); - for (i = 0; i < len; i++) { - applied_config_add_search(&priv->ac_ip6_config, nm_ip6_config_get_search(from_config, i)); + strvarr = nm_l3_config_data_get_searches(l3cd_src, AF_INET6, &n); + for (i = 0; i < n; i++) + nm_l3_config_data_add_search(l3cd, AF_INET6, strvarr[i]); } - if (!ip_config_merge_and_apply(self, AF_INET6, TRUE)) - _LOGW(LOGD_IP6, "ipv6-pd: failed applying DNS config for connection sharing"); + _dev_l3_register_l3cds_set_one(self, L3_CONFIG_DATA_TYPE_AC_6, l3cd, FALSE); + + _dev_l3_cfg_commit(self, TRUE); } /*****************************************************************************/ -static void -linklocal6_failed(NMDevice *self) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - - nm_clear_g_source(&priv->linklocal6_timeout_id); - nm_device_activate_schedule_ip_config_timeout(self, AF_INET6); -} - static gboolean -linklocal6_timeout_cb(gpointer user_data) +_dev_ipll6_state_retry_cb(gpointer user_data) { - NMDevice *self = user_data; + NMDevice *self = user_data; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - _LOGD(LOGD_DEVICE, "linklocal6: waiting for link-local addresses failed due to timeout"); - linklocal6_failed(self); - return G_SOURCE_REMOVE; + nm_clear_g_source_inst(&priv->ipll_data_6.v6.retry_source); + _dev_ipll6_start(self); + return G_SOURCE_CONTINUE; } static void -linklocal6_check_complete(NMDevice *self) +_dev_ipll6_set_llstate(NMDevice *self, NML3IPv6LLState llstate, const struct in6_addr *lladdr) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - NMConnection * connection; - const char * method; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + gboolean changed = FALSE; + NMDeviceIPState state; + NMDeviceIPState old_state; + + if (!lladdr) + lladdr = &nm_ip_addr_zero.addr6; + + if (priv->ipll_data_6.v6.llstate != llstate + || !IN6_ARE_ADDR_EQUAL(&priv->ipll_data_6.v6.lladdr, lladdr)) { + changed = TRUE; + priv->ipll_data_6.v6.llstate = llstate; + priv->ipll_data_6.v6.lladdr = *lladdr; + } + + nm_assert((priv->ipll_data_6.v6.ipv6ll + && NM_IN_SET(priv->ipll_data_6.v6.llstate, + NM_L3_IPV6LL_STATE_STARTING, + NM_L3_IPV6LL_STATE_DAD_IN_PROGRESS, + NM_L3_IPV6LL_STATE_READY, + NM_L3_IPV6LL_STATE_DAD_FAILED)) + || (!priv->ipll_data_6.v6.ipv6ll + && NM_IN_SET(priv->ipll_data_6.v6.llstate, + NM_L3_IPV6LL_STATE_NONE, + NM_L3_IPV6LL_STATE_DEFUNCT))); + + switch (priv->ipll_data_6.v6.llstate) { + case NM_L3_IPV6LL_STATE_NONE: + state = NM_DEVICE_IP_STATE_NONE; + break; + case NM_L3_IPV6LL_STATE_DEFUNCT: + case NM_L3_IPV6LL_STATE_DAD_FAILED: + state = NM_DEVICE_IP_STATE_FAILED; + break; + case NM_L3_IPV6LL_STATE_READY: + state = NM_DEVICE_IP_STATE_READY; + break; + case NM_L3_IPV6LL_STATE_STARTING: + case NM_L3_IPV6LL_STATE_DAD_IN_PROGRESS: + state = NM_DEVICE_IP_STATE_PENDING; + break; + default: + state = nm_assert_unreachable_val(NM_DEVICE_IP_STATE_FAILED); + break; + } - if (!priv->linklocal6_timeout_id) { - /* we are not waiting for linklocal to complete. Nothing to do. */ - return; + old_state = priv->ipll_data_6.state; + if (priv->ipll_data_6.state != state) { + priv->ipll_data_6.state = state; + changed = TRUE; } - if (!priv->ext_ip6_config_captured - || !nm_ip_config_find_first_address(NM_IP_CONFIG(priv->ext_ip6_config_captured), - NM_PLATFORM_MATCH_WITH_ADDRTYPE_LINKLOCAL - | NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL)) { - /* we don't have a non-tentative link local address yet. Wait longer. */ - return; + if (priv->ipll_data_6.v6.llstate != NM_L3_IPV6LL_STATE_DEFUNCT) + nm_clear_g_source_inst(&priv->ipll_data_6.v6.retry_source); + else if (!priv->ipll_data_6.v6.retry_source) { + /* we schedule a timer to try to recover from this... Possibly some higher layer + * will however fail the activation... */ + priv->ipll_data_6.v6.retry_source = + nm_g_timeout_add_source(10000, _dev_ipll6_state_retry_cb, self); } - nm_clear_g_source(&priv->linklocal6_timeout_id); + if (changed) { + char sbuf[NM_UTILS_INET_ADDRSTRLEN]; - connection = nm_device_get_applied_connection(self); - g_assert(connection); + _LOGT_ipll(AF_INET6, + "set state %s (was %s, llstate=%s, lladdr=%s)", + nm_device_ip_state_to_string(priv->ipll_data_6.state), + nm_device_ip_state_to_string(old_state), + nm_l3_ipv6ll_state_to_string(priv->ipll_data_6.v6.llstate), + nm_ip_addr_is_null(AF_INET6, &priv->ipll_data_6.v6.lladdr) + ? "(none)" + : _nm_utils_inet6_ntop(&priv->ipll_data_6.v6.lladdr, sbuf)); + } - method = nm_device_get_effective_ip_config_method(self, AF_INET6); + if (changed) + _dev_ip_state_check_async(self, AF_INET6); - _LOGD(LOGD_DEVICE, - "linklocal6: waiting for link-local addresses successful, continue with method %s", - method); - - if (NM_IN_STRSET(method, - NM_SETTING_IP6_CONFIG_METHOD_AUTO, - NM_SETTING_IP6_CONFIG_METHOD_SHARED)) - addrconf6_start_with_link_ready(self); - else if (nm_streq(method, NM_SETTING_IP6_CONFIG_METHOD_DHCP)) { - if (!dhcp6_start_with_link_ready(self, connection)) { - /* Time out IPv6 instead of failing the entire activation */ - nm_device_activate_schedule_ip_config_timeout(self, AF_INET6); - } - } else if (nm_streq(method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL)) - nm_device_activate_schedule_ip_config_result(self, AF_INET6, NULL); - else - g_return_if_fail(FALSE); + if (priv->ipll_data_6.v6.llstate == NM_L3_IPV6LL_STATE_READY) { + /* if we got an IPv6LL address, we might poke some other methods + * to progress... */ + _dev_ipac6_start_continue(self); + _dev_ipdhcpx_start_continue(self, AF_INET6); + } } static void -check_and_add_ipv6ll_addr(NMDevice *self) +_dev_ipll6_state_change_cb(NML3IPv6LL *ipv6ll, + NML3IPv6LLState llstate, + const struct in6_addr *lladdr, + gpointer user_data) { - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - struct in6_addr lladdr; - NMConnection * connection; - NMSettingIP6Config *s_ip6 = NULL; - GError * error = NULL; - const char * addr_type; - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + _dev_ipll6_set_llstate(user_data, llstate, lladdr); +} - if (!priv->ipv6ll_handle) - return; +static void +_dev_ipll6_start(NMDevice *self) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NMConnection *connection; + NMSettingIP6Config *s_ip6 = NULL; + gboolean assume; + const char *ifname; + NML3IPv6LLState llstate; + const struct in6_addr *lladdr; - if (priv->ext_ip6_config_captured - && nm_ip_config_find_first_address(NM_IP_CONFIG(priv->ext_ip6_config_captured), - NM_PLATFORM_MATCH_WITH_ADDRTYPE_LINKLOCAL - | NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL - | NM_PLATFORM_MATCH_WITH_ADDRSTATE_TENTATIVE)) { - /* Already have an LL address, nothing to do */ + if (priv->ipll_data_6.v6.ipv6ll) return; - } - priv->ipv6ll_has = FALSE; - memset(&priv->ipv6ll_addr, 0, sizeof(priv->ipv6ll_addr)); + if (!priv->l3cfg) { + _LOGD(LOGD_IP6, "linklocal6: no IP link for IPv6"); + goto out_fail; + } - memset(&lladdr, 0, sizeof(lladdr)); - lladdr.s6_addr16[0] = htons(0xfe80); + ifname = nm_device_get_ip_iface(self); + if (!ifname) { + _LOGD(LOGD_IP6, "linklocal6: no interface name for IPv6"); + goto out_fail; + } connection = nm_device_get_applied_connection(self); if (connection) s_ip6 = NM_SETTING_IP6_CONFIG(nm_connection_get_setting_ip6_config(connection)); + assume = nm_device_sys_iface_state_is_external_or_assume(self); + if (s_ip6 && nm_setting_ip6_config_get_addr_gen_mode(s_ip6) == NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY) { NMUtilsStableType stable_type; - const char * stable_id; + const char *stable_id; stable_id = _prop_get_connection_stable_id(self, connection, &stable_type); - if (!nm_utils_ipv6_addr_set_stable_privacy_may_fail(stable_type, - &lladdr, - nm_device_get_iface(self), - stable_id, - priv->linklocal6_dad_counter++, - &error)) { - _LOGW(LOGD_IP6, "linklocal6: failed to generate an address: %s", error->message); - g_clear_error(&error); - linklocal6_failed(self); - return; - } - addr_type = "stable-privacy"; + priv->ipll_data_6.v6.ipv6ll = + nm_l3_ipv6ll_new_stable_privacy(priv->l3cfg, + assume, + stable_type, + ifname, + stable_id, + nm_device_get_route_table(self, AF_INET6), + _dev_ipll6_state_change_cb, + self); } else { NMUtilsIPv6IfaceId iid; - if (priv->linklocal6_timeout_id) { - /* We already started and attempt to add a LL address. For the EUI-64 - * mode we can't pick a new one, we'll just fail. */ - _LOGW(LOGD_IP6, "linklocal6: DAD failed for an EUI-64 address"); - linklocal6_failed(self); - return; - } - - if (!nm_device_get_ip_iface_identifier(self, &iid, TRUE)) { + if (!nm_device_get_ip_iface_identifier(self, &iid, TRUE, NULL)) { _LOGW(LOGD_IP6, "linklocal6: failed to get interface identifier; IPv6 cannot continue"); - return; + goto out_fail; } - nm_utils_ipv6_addr_set_interface_identifier(&lladdr, &iid); - addr_type = "EUI-64"; - } - - _LOGD(LOGD_IP6, - "linklocal6: generated %s IPv6LL address %s", - addr_type, - _nm_utils_inet6_ntop(&lladdr, sbuf)); - priv->ipv6ll_has = TRUE; - priv->ipv6ll_addr = lladdr; - ip_config_merge_and_apply(self, AF_INET6, TRUE); -} -static gboolean -linklocal6_start(NMDevice *self) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - - nm_clear_g_source(&priv->linklocal6_timeout_id); - - if (priv->ext_ip6_config_captured - && nm_ip_config_find_first_address(NM_IP_CONFIG(priv->ext_ip6_config_captured), - NM_PLATFORM_MATCH_WITH_ADDRTYPE_LINKLOCAL - | NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL)) - return TRUE; - - _LOGD(LOGD_DEVICE, - "linklocal6: starting IPv6 with method '%s', but the device has no link-local addresses " - "configured. Wait.", - nm_device_get_effective_ip_config_method(self, AF_INET6)); + priv->ipll_data_6.v6.ipv6ll = + nm_l3_ipv6ll_new_token(priv->l3cfg, + assume, + &iid, + nm_device_get_route_table(self, AF_INET6), + _dev_ipll6_state_change_cb, + self); + } - check_and_add_ipv6ll_addr(self); + llstate = nm_l3_ipv6ll_get_state(priv->ipll_data_6.v6.ipv6ll, &lladdr); + _dev_ipll6_set_llstate(self, llstate, lladdr); + return; - /* Depending on the network and what the 'dad_transmits' and 'retrans_time_ms' - * sysctl values are, DAD for the IPv6LL address may take quite a while. - * FIXME: use dad/retrans sysctl values if they are higher than a minimum time. - * (rh #1101809) - */ - priv->linklocal6_timeout_id = g_timeout_add_seconds(15, linklocal6_timeout_cb, self); - return FALSE; +out_fail: + _dev_ipll6_set_llstate(self, NM_L3_IPV6LL_STATE_DEFUNCT, NULL); } /*****************************************************************************/ gint64 -nm_device_get_configured_mtu_from_connection_default(NMDevice * self, +nm_device_get_configured_mtu_from_connection_default(NMDevice *self, const char *property_name, guint32 max_mtu) { @@ -10451,13 +10672,13 @@ nm_device_get_configured_mtu_from_connection_default(NMDevice * self, } guint32 -nm_device_get_configured_mtu_from_connection(NMDevice * self, +nm_device_get_configured_mtu_from_connection(NMDevice *self, GType setting_type, NMDeviceMtuSource *out_source) { - const char * global_property_name; + const char *global_property_name; NMConnection *connection; - NMSetting * setting; + NMSetting *setting; gint64 mtu_default; guint32 mtu = 0; guint32 max_mtu = G_MAXUINT32; @@ -10512,17 +10733,17 @@ nm_device_get_configured_mtu_from_connection(NMDevice * self, } guint32 -nm_device_get_configured_mtu_for_wired(NMDevice * self, +nm_device_get_configured_mtu_for_wired(NMDevice *self, NMDeviceMtuSource *out_source, - gboolean * out_force) + gboolean *out_force) { return nm_device_get_configured_mtu_from_connection(self, NM_TYPE_SETTING_WIRED, out_source); } guint32 -nm_device_get_configured_mtu_wired_parent(NMDevice * self, +nm_device_get_configured_mtu_wired_parent(NMDevice *self, NMDeviceMtuSource *out_source, - gboolean * out_force) + gboolean *out_force) { guint32 mtu = 0; guint32 parent_mtu = 0; @@ -10595,13 +10816,16 @@ set_platform_mtu(NMDevice *self, guint32 mtu) } static void -_commit_mtu(NMDevice *self, const NMIP4Config *config) -{ - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - NMDeviceMtuSource source = NM_DEVICE_MTU_SOURCE_NONE; - guint32 ip6_mtu, ip6_mtu_orig; - guint32 mtu_desired, mtu_desired_orig; - guint32 mtu_plat; +_commit_mtu(NMDevice *self) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NMDeviceMtuSource source = NM_DEVICE_MTU_SOURCE_NONE; + const NML3ConfigData *l3cd; + guint32 ip6_mtu_orig; + guint32 ip6_mtu; + guint32 mtu_desired_orig; + guint32 mtu_desired; + guint32 mtu_plat; struct { gboolean initialized; guint32 value; @@ -10609,7 +10833,9 @@ _commit_mtu(NMDevice *self, const NMIP4Config *config) 0, }; int ifindex; - char sbuf[64], sbuf1[64], sbuf2[64]; + char sbuf[64]; + char sbuf1[64]; + char sbuf2[64]; gboolean success = TRUE; ifindex = nm_device_get_ip_ifindex(self); @@ -10623,8 +10849,11 @@ _commit_mtu(NMDevice *self, const NMIP4Config *config) return; } + l3cd = nm_l3cfg_get_combined_l3cd(priv->l3cfg, FALSE); + { - guint32 mtu = 0; + guint32 mtu = 0; + guint32 mtu2; gboolean force = FALSE; /* We take the MTU from various sources: (in order of increasing @@ -10651,9 +10880,9 @@ _commit_mtu(NMDevice *self, const NMIP4Config *config) if (NM_DEVICE_GET_CLASS(self)->get_configured_mtu) mtu = NM_DEVICE_GET_CLASS(self)->get_configured_mtu(self, &source, &force); - if (config && !force && source < NM_DEVICE_MTU_SOURCE_IP_CONFIG - && nm_ip4_config_get_mtu(config)) { - mtu = nm_ip4_config_get_mtu(config); + if (l3cd && !force && source < NM_DEVICE_MTU_SOURCE_IP_CONFIG + && (mtu2 = nm_l3_config_data_get_mtu(l3cd)) > 0) { + mtu = mtu2; source = NM_DEVICE_MTU_SOURCE_IP_CONFIG; } @@ -10842,251 +11071,212 @@ nm_device_commit_mtu(NMDevice *self) state = nm_device_get_state(self); if (state >= NM_DEVICE_STATE_CONFIG && state < NM_DEVICE_STATE_DEACTIVATING) { _LOGT(LOGD_DEVICE, "mtu: commit-mtu..."); - _commit_mtu(self, NM_DEVICE_GET_PRIVATE(self)->ip_config_4); + _commit_mtu(self); } else _LOGT(LOGD_DEVICE, "mtu: commit-mtu... skip due to state %s", nm_device_state_to_string(state)); } +/*****************************************************************************/ + static void -ndisc_config_changed(NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_int, NMDevice *self) +_dev_ipac6_ndisc_set_router_config(NMDevice *self) { - NMNDiscConfigMap changed = changed_int; - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - int ifindex; - guint i; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + const NML3ConfigData *l3cd; - g_return_if_fail(priv->act_request.obj); + if (!priv->ipac6_data.ndisc) + return; - ifindex = nm_device_get_ip_ifindex(self); + if (nm_ndisc_get_node_type(priv->ipac6_data.ndisc) != NM_NDISC_NODE_TYPE_ROUTER) + return; - if (ifindex <= 0 - || (applied_config_get_current(&priv->ac_ip6_config) - && ifindex - != nm_ip_config_get_ifindex(applied_config_get_current(&priv->ac_ip6_config)))) - applied_config_clear(&priv->ac_ip6_config); + /* FIXME(l3cfg): this doesn't seem right. What is the meaning of the l3cd at this + * point? Also, when do we need to reset the config (and call this function again?). */ + l3cd = nm_l3cfg_get_combined_l3cd(priv->l3cfg, FALSE); + if (l3cd) + nm_ndisc_set_config(priv->ipac6_data.ndisc, l3cd); +} - if (ifindex <= 0) - return; +static void +_dev_ipac6_set_state(NMDevice *self, NMDeviceIPState state) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - if (!applied_config_get_current(&priv->ac_ip6_config)) - applied_config_init_new(&priv->ac_ip6_config, self, AF_INET6); - - if (changed & NM_NDISC_CONFIG_ADDRESSES) { - guint32 ifa_flags; - - /* Check, whether kernel is 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. */ - ifa_flags = IFA_F_NOPREFIXROUTE; - if (NM_IN_SET(priv->ndisc_use_tempaddr, - NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR, - NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR)) - ifa_flags |= IFA_F_MANAGETEMPADDR; - - nm_ip6_config_reset_addresses_ndisc((NMIP6Config *) priv->ac_ip6_config.orig, - rdata->addresses, - rdata->addresses_n, - 64, - ifa_flags); - if (priv->ac_ip6_config.current) { - nm_ip6_config_reset_addresses_ndisc((NMIP6Config *) priv->ac_ip6_config.current, - rdata->addresses, - rdata->addresses_n, - 64, - ifa_flags); - } + if (priv->ipac6_data.state != state) { + _LOGD_ipac6("set state: %s (was %s)", + nm_device_ip_state_to_string(state), + nm_device_ip_state_to_string(priv->ipac6_data.state)); + priv->ipac6_data.state = state; } +} - if (NM_FLAGS_ANY(changed, NM_NDISC_CONFIG_ROUTES | NM_NDISC_CONFIG_GATEWAYS)) { - nm_ip6_config_reset_routes_ndisc((NMIP6Config *) priv->ac_ip6_config.orig, - rdata->gateways, - rdata->gateways_n, - rdata->routes, - rdata->routes_n, - nm_device_get_route_table(self, AF_INET6), - nm_device_get_route_metric(self, AF_INET6)); - if (priv->ac_ip6_config.current) { - nm_ip6_config_reset_routes_ndisc((NMIP6Config *) priv->ac_ip6_config.current, - rdata->gateways, - rdata->gateways_n, - rdata->routes, - rdata->routes_n, - nm_device_get_route_table(self, AF_INET6), - nm_device_get_route_metric(self, AF_INET6)); +static void +_dev_ipac6_ndisc_config_changed(NMNDisc *ndisc, + const NMNDiscData *rdata, + guint changed_i, + const NML3ConfigData *l3cd, + NMDevice *self) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + gboolean ready = TRUE; + NMDedupMultiIter iter; + const NMPObject *obj; + + _dev_ipac6_grace_period_start(self, 0, TRUE); + + _dev_l3_register_l3cds_set_one_full(self, + L3_CONFIG_DATA_TYPE_AC_6, + l3cd, + NM_L3CFG_CONFIG_FLAGS_FORCE_ONCE, + FALSE); + + nm_clear_l3cd(&priv->ipac6_data.l3cd); + + /* wait that addresses are committed to platform and + * become non-tentative before declaring AC6 is ready.*/ + nm_l3_config_data_iter_obj_for_each (&iter, l3cd, &obj, NMP_OBJECT_TYPE_IP6_ADDRESS) { + const NMPlatformIP6Address *addr = NMP_OBJECT_CAST_IP6_ADDRESS(obj); + const NMPlatformIP6Address *plat_addr; + + plat_addr = nm_platform_ip6_address_get(nm_device_get_platform(self), + nm_device_get_ip_ifindex(self), + &addr->address); + if (!plat_addr || (plat_addr->n_ifa_flags & IFA_F_TENTATIVE)) { + ready = FALSE; + break; } } - if (changed & NM_NDISC_CONFIG_DNS_SERVERS) { - /* Rebuild DNS server list from neighbor discovery cache. */ - applied_config_reset_nameservers(&priv->ac_ip6_config); - - for (i = 0; i < rdata->dns_servers_n; i++) - applied_config_add_nameserver(&priv->ac_ip6_config, - (const NMIPAddr *) &rdata->dns_servers[i].address); + if (ready) { + _dev_ipac6_set_state(self, NM_DEVICE_IP_STATE_READY); + } else { + priv->ipac6_data.l3cd = nm_l3_config_data_ref(l3cd); } - if (changed & NM_NDISC_CONFIG_DNS_DOMAINS) { - /* Rebuild domain list from neighbor discovery cache. */ - applied_config_reset_searches(&priv->ac_ip6_config); - - for (i = 0; i < rdata->dns_domains_n; i++) - applied_config_add_search(&priv->ac_ip6_config, rdata->dns_domains[i].domain); - } + _dev_ipdhcp6_set_dhcp_level(self, rdata->dhcp_level); - if (changed & NM_NDISC_CONFIG_DHCP_LEVEL) { - dhcp6_cleanup(self, CLEANUP_TYPE_DECONFIGURE, TRUE); + _dev_l3_cfg_commit(self, FALSE); - priv->dhcp6.mode = rdata->dhcp_level; - if (priv->dhcp6.mode != NM_NDISC_DHCP_LEVEL_NONE) { - _LOGD(LOGD_DEVICE | LOGD_DHCP6, - "Activation: Stage 3 of 5 (IP Configure Start) starting DHCPv6" - " as requested by IPv6 router..."); - if (!dhcp6_start(self, FALSE)) { - if (priv->dhcp6.mode == NM_NDISC_DHCP_LEVEL_MANAGED) { - nm_device_state_changed(self, - NM_DEVICE_STATE_FAILED, - NM_DEVICE_STATE_REASON_DHCP_START_FAILED); - return; - } - } - } - } + _dev_ip_state_check_async(self, AF_INET6); +} - if (changed & NM_NDISC_CONFIG_HOP_LIMIT) - nm_platform_sysctl_ip_conf_set_ipv6_hop_limit_safe(nm_device_get_platform(self), - nm_device_get_ip_iface(self), - rdata->hop_limit); +static void +_dev_ipac6_handle_timeout(NMDevice *self) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - if (changed & NM_NDISC_CONFIG_REACHABLE_TIME) { - nm_platform_sysctl_ip_neigh_set_ipv6_reachable_time(nm_device_get_platform(self), - nm_device_get_ip_iface(self), - rdata->reachable_time_ms); - } + _LOGD_ipac6("timeout for autoconf (IPv6 router advertisement) reached"); - if (changed & NM_NDISC_CONFIG_RETRANS_TIMER) { - nm_platform_sysctl_ip_neigh_set_ipv6_retrans_time(nm_device_get_platform(self), - nm_device_get_ip_iface(self), - rdata->retrans_timer_ms); - } + nm_clear_g_source_inst(&priv->ipac6_data.ndisc_grace_source); - if (changed & NM_NDISC_CONFIG_MTU) { - if (priv->ip6_mtu != rdata->mtu) { - _LOGD(LOGD_DEVICE, "mtu: set IPv6 MTU to %u", (guint) rdata->mtu); - priv->ip6_mtu = rdata->mtu; - } - } + _dev_ipac6_set_state(self, NM_DEVICE_IP_STATE_FAILED); - nm_device_activate_schedule_ip_config_result(self, AF_INET6, NULL); + _dev_ip_state_check_async(self, AF_INET6); } static void -ndisc_ra_timeout(NMNDisc *ndisc, NMDevice *self) +_dev_ipac6_ndisc_ra_timeout(NMNDisc *ndisc, NMDevice *self) +{ + _dev_ipac6_handle_timeout(self); +} + +static gboolean +_dev_ipac6_grace_period_expired(gpointer user_data) +{ + _dev_ipac6_handle_timeout(user_data); + return G_SOURCE_REMOVE; +} + +static gboolean +_dev_ipac6_grace_period_start(NMDevice *self, guint32 timeout_sec, gboolean force_restart) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + gboolean stopped; - /* We don't want to stop listening for router advertisements completely, - * but instead let device activation continue activating. If an RA - * shows up later, we'll use it as long as the device is not disconnected. + /* In any other case (expired lease, assumed connection, etc.), + * wait for some time before failing the IP method. */ - - _LOGD(LOGD_IP6, "timed out waiting for IPv6 router advertisement"); - if (priv->ip_state_6 == NM_DEVICE_IP_STATE_CONF) { - /* If RA is our only source of addressing information and we don't - * ever receive one, then time out IPv6. But if there is other - * IPv6 configuration, like manual IPv6 addresses or external IPv6 - * config, consider that sufficient for IPv6 success. - * - * FIXME: it doesn't seem correct to determine this based on which - * addresses we find inside priv->ip_config_6. - */ - if (priv->ip_config_6 - && nm_ip_config_find_first_address(NM_IP_CONFIG(priv->ip_config_6), - NM_PLATFORM_MATCH_WITH_ADDRTYPE_NORMAL - | NM_PLATFORM_MATCH_WITH_ADDRSTATE__ANY)) - nm_device_activate_schedule_ip_config_result(self, AF_INET6, NULL); - else - nm_device_activate_schedule_ip_config_timeout(self, AF_INET6); + if (!force_restart && priv->ipac6_data.ndisc_grace_source) { + /* already pending. */ + return FALSE; } -} -static void -addrconf6_start_with_link_ready(NMDevice *self) -{ - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - NMUtilsIPv6IfaceId iid; + /* Start a grace period equal to the RA timeout multiplied + * by a constant factor. */ - g_assert(priv->ndisc); + stopped = nm_clear_g_source_inst(&priv->ipac6_data.ndisc_grace_source); - if (nm_device_get_ip_iface_identifier(self, &iid, FALSE)) { - _LOGD(LOGD_IP6, "addrconf6: using the device EUI-64 identifier"); - nm_ndisc_set_iid(priv->ndisc, iid); - } else { - /* Don't abort the addrconf at this point -- if ndisc needs the iid - * it will notice this itself. */ - _LOGI(LOGD_IP6, "addrconf6: no interface identifier; IPv6 address creation may fail"); + if (timeout_sec == 0) { + if (stopped) + _LOGD_ipac6("grace period stopped"); + return FALSE; } - /* Apply any manual configuration before starting RA */ - if (!ip_config_merge_and_apply(self, AF_INET6, TRUE)) - _LOGW(LOGD_IP6, "failed to apply manual IPv6 configuration"); + nm_assert(timeout_sec <= G_MAXINT32); - if (nm_ndisc_get_node_type(priv->ndisc) == NM_NDISC_NODE_TYPE_ROUTER) { - nm_device_sysctl_ip_conf_set(self, AF_INET6, "forwarding", "1"); - nm_device_activate_schedule_ip_config_result(self, AF_INET6, NULL); - priv->needs_ip6_subnet = TRUE; - g_signal_emit(self, signals[IP6_SUBNET_NEEDED], 0); - } + if (timeout_sec >= G_MAXUINT / (GRACE_PERIOD_MULTIPLIER * 1000u)) + timeout_sec = NM_RA_TIMEOUT_INFINITY; - priv->ndisc_changed_id = g_signal_connect(priv->ndisc, - NM_NDISC_CONFIG_RECEIVED, - G_CALLBACK(ndisc_config_changed), - self); - priv->ndisc_timeout_id = g_signal_connect(priv->ndisc, - NM_NDISC_RA_TIMEOUT_SIGNAL, - G_CALLBACK(ndisc_ra_timeout), - self); + if (timeout_sec == NM_RA_TIMEOUT_INFINITY) { + _LOGD_ipac6("grace period starts with infinity timeout"); + priv->ipac6_data.ndisc_grace_source = g_source_ref(nm_g_source_sentinel_get(0)); + } else { + _LOGD_ipac6("grace period starts with %u seconds", timeout_sec); + priv->ipac6_data.ndisc_grace_source = + nm_g_timeout_add_source(timeout_sec * (GRACE_PERIOD_MULTIPLIER * 1000u), + _dev_ipac6_grace_period_expired, + self); + } - ndisc_set_router_config(priv->ndisc, self); - nm_ndisc_start(priv->ndisc); - priv->ndisc_started = TRUE; - return; + return TRUE; } -static gboolean -addrconf6_start(NMDevice *self, NMSettingIP6ConfigPrivacy use_tempaddr) +static void +_dev_ipac6_start(NMDevice *self) { - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - NMConnection * connection; - NMSettingIP6Config *s_ip6 = NULL; - GError * error = NULL; - NMUtilsStableType stable_type; - const char * stable_id; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NMConnection *connection; + NMSettingIP6Config *s_ip = NULL; NMNDiscNodeType node_type; + NMUtilsStableType stable_type; + const char *stable_id; int max_addresses; int router_solicitations; int router_solicitation_interval; guint32 ra_timeout; guint32 default_ra_timeout; + NMUtilsIPv6IfaceId iid; + gboolean is_token; + + if (priv->ipac6_data.state == NM_DEVICE_IP_STATE_NONE) { + if (!g_file_test("/proc/sys/net/ipv6", G_FILE_TEST_IS_DIR)) { + _LOGI_ipac6("addrconf6: kernel does not support IPv6"); + _dev_ipac6_set_state(self, NM_DEVICE_IP_STATE_FAILED); + _dev_ip_state_check_async(self, AF_INET6); + return; + } - if (!g_file_test("/proc/sys/net/ipv6", G_FILE_TEST_IS_DIR)) { - _LOGI(LOGD_IP6, "addrconf6: kernel does not support IPv6"); - return FALSE; + _dev_ipac6_set_state(self, NM_DEVICE_IP_STATE_PENDING); } - connection = nm_device_get_applied_connection(self); - g_assert(connection); + if (NM_IN_SET(priv->ipll_data_6.state, NM_DEVICE_IP_STATE_NONE, NM_DEVICE_IP_STATE_PENDING)) { + _dev_ipac6_grace_period_start(self, 30, TRUE); + _dev_ipll6_start(self); + return; + } - nm_assert(!applied_config_get_current(&priv->ac_ip6_config)); - applied_config_clear(&priv->ac_ip6_config); + if (priv->ipac6_data.ndisc) { + /* we already started. Nothing to do. */ + return; + } - nm_clear_pointer(&priv->rt6_temporary_not_available, g_hash_table_unref); - nm_clear_g_source(&priv->rt6_temporary_not_available_id); + connection = nm_device_get_applied_connection(self); + if (connection) + s_ip = NM_SETTING_IP6_CONFIG(nm_connection_get_setting_ip6_config(connection)); - s_ip6 = NM_SETTING_IP6_CONFIG(nm_connection_get_setting_ip6_config(connection)); - g_assert(s_ip6); + g_return_if_fail(s_ip); if (nm_streq(nm_device_get_effective_ip_config_method(self, AF_INET6), NM_SETTING_IP6_CONFIG_METHOD_SHARED)) @@ -11109,60 +11299,102 @@ addrconf6_start(NMDevice *self, NMSettingIP6ConfigPrivacy use_tempaddr) ra_timeout = default_ra_timeout; } - stable_id = _prop_get_connection_stable_id(self, connection, &stable_type); - priv->ndisc = nm_lndp_ndisc_new(nm_device_get_platform(self), - nm_device_get_ip_ifindex(self), - nm_device_get_ip_iface(self), - stable_type, - stable_id, - nm_setting_ip6_config_get_addr_gen_mode(s_ip6), - node_type, - max_addresses, - router_solicitations, - router_solicitation_interval, - ra_timeout, - &error); - if (!priv->ndisc) { - _LOGE(LOGD_IP6, "addrconf6: failed to start neighbor discovery: %s", error->message); - g_error_free(error); - return FALSE; + stable_id = _prop_get_connection_stable_id(self, connection, &stable_type); + + { + const NMNDiscConfig config = { + .l3cfg = nm_device_get_l3cfg(self), + .ifname = nm_device_get_ip_iface(self), + .stable_type = stable_type, + .network_id = stable_id, + .addr_gen_mode = nm_setting_ip6_config_get_addr_gen_mode(s_ip), + .node_type = node_type, + .max_addresses = max_addresses, + .router_solicitations = router_solicitations, + .router_solicitation_interval = router_solicitation_interval, + .ra_timeout = ra_timeout, + .ip6_privacy = _prop_get_ipv6_ip6_privacy(self), + }; + + priv->ipac6_data.ndisc = nm_lndp_ndisc_new(&config); + + priv->ipac6_data.ndisc_changed_id = + g_signal_connect(priv->ipac6_data.ndisc, + NM_NDISC_CONFIG_RECEIVED, + G_CALLBACK(_dev_ipac6_ndisc_config_changed), + self); + priv->ipac6_data.ndisc_timeout_id = + g_signal_connect(priv->ipac6_data.ndisc, + NM_NDISC_RA_TIMEOUT_SIGNAL, + G_CALLBACK(_dev_ipac6_ndisc_ra_timeout), + self); } - priv->ndisc_use_tempaddr = use_tempaddr; + if (nm_device_get_ip_iface_identifier(self, &iid, FALSE, &is_token)) { + _LOGD_ipac6("using the device EUI-64 identifier"); + nm_ndisc_set_iid(priv->ipac6_data.ndisc, iid, is_token); + } else { + /* Don't abort the addrconf at this point -- if ndisc needs the iid + * it will notice this itself. */ + _LOGD_ipac6("no interface identifier; IPv6 address creation may fail"); + } - /* ensure link local is ready... */ - if (!linklocal6_start(self)) { - /* wait for the LL address to show up */ - return TRUE; + if (nm_ndisc_get_node_type(priv->ipac6_data.ndisc) == NM_NDISC_NODE_TYPE_ROUTER) { + nm_device_sysctl_ip_conf_set(self, AF_INET6, "forwarding", "1"); + priv->needs_ip6_subnet = TRUE; + g_signal_emit(self, signals[IP6_SUBNET_NEEDED], 0); } - /* already have the LL address; kick off neighbor discovery */ - addrconf6_start_with_link_ready(self); - return TRUE; + _dev_ipac6_ndisc_set_router_config(self); + + if (node_type == NM_NDISC_NODE_TYPE_ROUTER) + _dev_ipac6_set_state(self, NM_DEVICE_IP_STATE_READY); + else + _dev_ipac6_grace_period_start(self, ra_timeout, TRUE); + + nm_ndisc_start(priv->ipac6_data.ndisc); +} + +void +nm_device_ip_method_autoconf6_start(NMDevice *self) +{ + _dev_ipac6_start(self); +} + +static void +_dev_ipac6_start_continue(NMDevice *self) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + + if (priv->ipac6_data.state != NM_DEVICE_IP_STATE_NONE) + _dev_ipac6_start(self); } static void -addrconf6_cleanup(NMDevice *self) +_dev_ipac6_cleanup(NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - priv->ndisc_started = FALSE; - nm_clear_g_signal_handler(priv->ndisc, &priv->ndisc_changed_id); - nm_clear_g_signal_handler(priv->ndisc, &priv->ndisc_timeout_id); + nm_clear_g_source_inst(&priv->ipac6_data.ndisc_grace_source); + nm_clear_l3cd(&priv->ipac6_data.l3cd); + + nm_clear_g_signal_handler(priv->ipac6_data.ndisc, &priv->ipac6_data.ndisc_changed_id); + nm_clear_g_signal_handler(priv->ipac6_data.ndisc, &priv->ipac6_data.ndisc_timeout_id); + + _dev_l3_register_l3cds_set_one(self, L3_CONFIG_DATA_TYPE_AC_6, NULL, FALSE); - applied_config_clear(&priv->ac_ip6_config); - nm_clear_pointer(&priv->rt6_temporary_not_available, g_hash_table_unref); - nm_clear_g_source(&priv->rt6_temporary_not_available_id); - if (priv->ndisc) { - nm_ndisc_stop(priv->ndisc); - g_clear_object(&priv->ndisc); + if (priv->ipac6_data.ndisc) { + nm_ndisc_stop(priv->ipac6_data.ndisc); + g_clear_object(&priv->ipac6_data.ndisc); } + + _dev_ipac6_set_state(self, NM_DEVICE_IP_STATE_NONE); } /*****************************************************************************/ static void -save_ip6_properties(NMDevice *self) +_dev_sysctl_save_ip6_properties(NMDevice *self) { static const char *const ip6_properties_to_save[] = { "accept_ra", @@ -11172,9 +11404,9 @@ save_ip6_properties(NMDevice *self) "use_tempaddr", }; NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - NMPlatform * platform = nm_device_get_platform(self); - const char * ifname; - char * value; + NMPlatform *platform = nm_device_get_platform(self); + const char *ifname; + char *value; int i; g_hash_table_remove_all(priv->ip6_saved_properties); @@ -11195,61 +11427,90 @@ save_ip6_properties(NMDevice *self) } static void -restore_ip6_properties(NMDevice *self) +_dev_sysctl_restore_ip6_properties(NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); GHashTableIter iter; - gpointer key, value; + gpointer key; + gpointer value; g_hash_table_iter_init(&iter, priv->ip6_saved_properties); - while (g_hash_table_iter_next(&iter, &key, &value)) { - /* Don't touch "disable_ipv6" if we're doing userland IPv6LL */ - if (priv->ipv6ll_handle && nm_streq(key, "disable_ipv6")) - continue; + while (g_hash_table_iter_next(&iter, &key, &value)) nm_device_sysctl_ip_conf_set(self, AF_INET6, key, value); - } } static void -set_disable_ipv6(NMDevice *self, const char *value) +_dev_sysctl_set_disable_ipv6(NMDevice *self, gboolean do_disable) { - /* We only touch disable_ipv6 when NM is not managing the IPv6LL address */ - if (!NM_DEVICE_GET_PRIVATE(self)->ipv6ll_handle) - nm_device_sysctl_ip_conf_set(self, AF_INET6, "disable_ipv6", value); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + + /* If we previously set addrgenmode=none, we are managing + * IPv6 in user space and we should not disable it. */ + if (do_disable && priv->addrgenmode6_data.previous_mode_has + && priv->addrgenmode6_data.previous_mode_val == NM_IN6_ADDR_GEN_MODE_NONE) + return; + + nm_device_sysctl_ip_conf_set(self, AF_INET6, "disable_ipv6", do_disable ? "1" : "0"); } +/*****************************************************************************/ + static void -set_nm_ipv6ll(NMDevice *self, gboolean enable) +_dev_addrgenmode6_set(NMDevice *self, guint8 addr_gen_mode) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - int ifindex = nm_device_get_ip_ifindex(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + int ifindex = nm_device_get_ip_ifindex(self); + const NMPlatformLink *plink; + int r; + int cur_addr_gen_mode; + char sbuf[100]; - priv->ipv6ll_handle = enable; - if (ifindex > 0) { - int r; + if (ifindex <= 0) + return; + + plink = nm_platform_link_get(nm_device_get_platform(self), ifindex); + if (!plink) + return; + + cur_addr_gen_mode = _nm_platform_link_get_inet6_addr_gen_mode(plink); + nm_assert(cur_addr_gen_mode >= 0 && cur_addr_gen_mode <= 255); + + if (!priv->addrgenmode6_data.previous_mode_has) { + priv->addrgenmode6_data.previous_mode_has = TRUE; + priv->addrgenmode6_data.previous_mode_val = cur_addr_gen_mode; + nm_assert(priv->addrgenmode6_data.previous_mode_val == cur_addr_gen_mode); + } + + _LOGD_ip(AF_INET6, + "addrgenmode6: set %s%s", + nm_platform_link_inet6_addrgenmode2str(addr_gen_mode, sbuf, sizeof(sbuf)), + (cur_addr_gen_mode == addr_gen_mode) ? " (already set)" : ""); - _LOGD(LOGD_IP6, "will %s userland IPv6LL", enable ? "enable" : "disable"); + if (cur_addr_gen_mode != addr_gen_mode) { r = nm_platform_link_set_inet6_addr_gen_mode(nm_device_get_platform(self), ifindex, - enable ? NM_IN6_ADDR_GEN_MODE_NONE - : NM_IN6_ADDR_GEN_MODE_EUI64); + addr_gen_mode); if (r < 0) { - _NMLOG(NM_IN_SET(r, -NME_PL_NOT_FOUND, -NME_PL_OPNOTSUPP) ? LOGL_DEBUG : LOGL_WARN, - LOGD_IP6, - "failed to %s userspace IPv6LL address handling (%s)", - enable ? "enable" : "disable", - nm_strerror(r)); + _NMLOG_ip(NM_IN_SET(r, -NME_PL_NOT_FOUND, -NME_PL_OPNOTSUPP) ? LOGL_DEBUG : LOGL_WARN, + AF_INET6, + "addrgenmode6: failed to set %s: (%s)", + nm_platform_link_inet6_addrgenmode2str(addr_gen_mode, sbuf, sizeof(sbuf)), + nm_strerror(r)); + } else { + priv->addrgenmode6_data.previous_mode_val = addr_gen_mode; } + } - if (enable) { - gs_free char *value = NULL; - - /* Bounce IPv6 to ensure the kernel stops IPv6LL address generation */ - value = nm_device_sysctl_ip_conf_get(self, AF_INET6, "disable_ipv6"); - if (nm_streq0(value, "0")) - nm_device_sysctl_ip_conf_set(self, AF_INET6, "disable_ipv6", "1"); + if (addr_gen_mode == NM_IN6_ADDR_GEN_MODE_NONE) { + gs_free char *value = NULL; - /* Ensure IPv6 is enabled */ + /* Bounce IPv6 to ensure the kernel stops IPv6LL address and temporary + * address generation */ + _LOGD_ip(AF_INET6, + "addrgenmode6: toggle disable_ipv6 sysctl after disabling addr-gen-mode"); + value = nm_device_sysctl_ip_conf_get(self, AF_INET6, "disable_ipv6"); + if (nm_streq0(value, "0")) { + nm_device_sysctl_ip_conf_set(self, AF_INET6, "disable_ipv6", "1"); nm_device_sysctl_ip_conf_set(self, AF_INET6, "disable_ipv6", "0"); } } @@ -11275,30 +11536,41 @@ ip_requires_slaves(NMDevice *self, int addr_family) NM_SETTING_IP6_CONFIG_METHOD_DHCP); } -static NMActStageReturn -act_stage3_ip_config_start(NMDevice * self, - int addr_family, - gpointer * out_config, - NMDeviceStateReason *out_failure_reason) +static const char * +get_ip_method_auto(NMDevice *self, int addr_family) +{ + return NM_IS_IPv4(addr_family) ? NM_SETTING_IP4_CONFIG_METHOD_AUTO + : NM_SETTING_IP6_CONFIG_METHOD_AUTO; +} + +static void +activate_stage3_ip_config_for_addr_family(NMDevice *self, int addr_family, const char *method) { const int IS_IPv4 = NM_IS_IPv4(addr_family); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - NMConnection * connection; - NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; - const char * method; + NMDeviceClass *klass = NM_DEVICE_GET_CLASS(self); + NMConnection *connection; + int ip_ifindex; - nm_assert_addr_family(addr_family); + if (nm_device_sys_iface_state_is_external(self)) + goto out; connection = nm_device_get_applied_connection(self); + g_return_if_fail(connection); - g_return_val_if_fail(connection, NM_ACT_STAGE_RETURN_FAILURE); + ip_ifindex = nm_device_get_ip_ifindex(self); if (connection_ip_method_requires_carrier(connection, addr_family, NULL) && nm_device_is_master(self) && !priv->carrier) { - _LOGI(LOGD_IP | LOGD_DEVICE, - "IPv%c config waiting until carrier is on", - nm_utils_addr_family_to_char(addr_family)); - return NM_ACT_STAGE_RETURN_IP_WAIT; + if (!priv->ip_data_x[IS_IPv4].wait_for_carrier) { + _LOGT_ip(addr_family, "waiting until carrier is on"); + priv->ip_data_x[IS_IPv4].wait_for_carrier = TRUE; + } + goto out; + } + if (priv->ip_data_x[IS_IPv4].wait_for_carrier) { + _LOGT_ip(addr_family, "waiting until carrier completed"); + priv->ip_data_x[IS_IPv4].wait_for_carrier = FALSE; } if (nm_device_is_master(self) && ip_requires_slaves(self, addr_family)) { @@ -11306,94 +11578,45 @@ act_stage3_ip_config_start(NMDevice * self, * a successful IP configuration attempt, then postpone IP addressing. */ if (!have_any_ready_slaves(self)) { - _LOGI(LOGD_DEVICE | LOGD_IP, - "IPv%c config waiting until slaves are ready", - nm_utils_addr_family_to_char(addr_family)); - return NM_ACT_STAGE_RETURN_IP_WAIT; + if (!priv->ip_data_x[IS_IPv4].wait_for_ports) { + _LOGT_ip(addr_family, "waiting for ports"); + priv->ip_data_x[IS_IPv4].wait_for_ports = TRUE; + } + goto out; } } + if (priv->ip_data_x[IS_IPv4].wait_for_ports) { + _LOGT_ip(addr_family, "waiting until ports completed"); + priv->ip_data_x[IS_IPv4].wait_for_ports = FALSE; + } - if (!IS_IPv4) - priv->dhcp6.mode = NM_NDISC_DHCP_LEVEL_NONE; - - method = nm_device_get_effective_ip_config_method(self, addr_family); - - _LOGD(LOGD_IP | LOGD_DEVICE, - "IPv%c config method is %s", - nm_utils_addr_family_to_char(addr_family), - method); + if (klass->ready_for_ip_config && !klass->ready_for_ip_config(self)) + goto out_devip; if (IS_IPv4) { - if (NM_IN_STRSET(method, - NM_SETTING_IP4_CONFIG_METHOD_AUTO, - NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) { - NMSettingIPConfig *s_ip4; - NMIP4Config ** configs, *config; - guint num_addresses; - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_return_val_if_fail(s_ip4, NM_ACT_STAGE_RETURN_FAILURE); - num_addresses = nm_setting_ip_config_get_num_addresses(s_ip4); - - if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) { - ret = dhcp4_start(self); - if (ret == NM_ACT_STAGE_RETURN_FAILURE) { - NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_DHCP_START_FAILED); - return ret; - } - } else { - g_return_val_if_fail(num_addresses != 0, NM_ACT_STAGE_RETURN_FAILURE); - ret = NM_ACT_STAGE_RETURN_POSTPONE; - } - - if (num_addresses) { - config = nm_device_ip4_config_new(self); - nm_ip4_config_merge_setting(config, - nm_connection_get_setting_ip4_config(connection), - NM_SETTING_CONNECTION_MDNS_DEFAULT, - NM_SETTING_CONNECTION_LLMNR_DEFAULT, - NM_SETTING_CONNECTION_DNS_OVER_TLS_DEFAULT, - nm_device_get_route_table(self, AF_INET), - nm_device_get_route_metric(self, AF_INET)); - configs = g_new0(NMIP4Config *, 2); - configs[0] = config; - ipv4_dad_start(self, configs, ipv4_manual_method_apply); - } - } else if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)) { - ret = ipv4ll_start(self); - if (ret == NM_ACT_STAGE_RETURN_FAILURE) - NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_AUTOIP_START_FAILED); - } else if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)) { - if (out_config) { - *out_config = shared4_new_config(self, connection); - if (*out_config) { - priv->dnsmasq_manager = nm_dnsmasq_manager_new(nm_device_get_ip_iface(self)); - ret = NM_ACT_STAGE_RETURN_SUCCESS; - } else { - NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); - ret = NM_ACT_STAGE_RETURN_FAILURE; - } - } else - g_return_val_if_reached(NM_ACT_STAGE_RETURN_FAILURE); - } else if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) - ret = NM_ACT_STAGE_RETURN_SUCCESS; - else - _LOGW(LOGD_IP4, "unhandled IPv4 config method '%s'; will fail", method); - - return ret; - } else { - NMSettingIP6ConfigPrivacy ip6_privacy = NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN; - const char * ip6_privacy_str = "0"; - NMPlatform * platform; - int ifindex; + if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) + _dev_ipdhcpx_start(self, AF_INET); + else if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)) + _dev_ipll4_start(self); + else if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)) + _dev_ipshared4_start(self); + else if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) + priv->ip_data_x[IS_IPv4].is_disabled = TRUE; + else if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) { + /* pass */ + } else + nm_assert_not_reached(); + } + if (!IS_IPv4) { if (nm_streq(method, NM_SETTING_IP6_CONFIG_METHOD_DISABLED)) { - nm_device_sysctl_ip_conf_set(self, AF_INET6, "disable_ipv6", "1"); - return NM_ACT_STAGE_RETURN_IP_DONE; - } - - if (nm_streq(method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) { - if (!nm_device_sys_iface_state_is_external(self)) { + if (!priv->ip_data_x[IS_IPv4].is_disabled) { + priv->ip_data_x[IS_IPv4].is_disabled = TRUE; + nm_device_sysctl_ip_conf_set(self, AF_INET6, "disable_ipv6", "1"); + } + } else if (nm_streq(method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) { + if (!priv->ip_data_x[IS_IPv4].is_ignore) { + priv->ip_data_x[IS_IPv4].is_ignore = TRUE; if (priv->master) { /* If a device only has an IPv6 link-local address, * we don't generate an assumed connection. Therefore, @@ -11403,174 +11626,56 @@ act_stage3_ip_config_start(NMDevice * self, * slave should not depend on the previous state. Flush * addresses and routes on activation. */ - ifindex = nm_device_get_ip_ifindex(self); - platform = nm_device_get_platform(self); - - if (ifindex > 0) { - gs_unref_object NMIP6Config *config = nm_device_ip6_config_new(self); - - nm_platform_ip_route_flush(platform, AF_INET6, ifindex); - nm_platform_ip_address_flush(platform, AF_INET6, ifindex); - nm_device_set_ip_config(self, AF_INET6, (NMIPConfig *) config, FALSE, NULL); + if (ip_ifindex > 0) { + nm_platform_ip_route_flush(nm_device_get_platform(self), + AF_INET6, + ip_ifindex); + nm_platform_ip_address_flush(nm_device_get_platform(self), + AF_INET6, + ip_ifindex); } } else { - gboolean ipv6ll_handle_old = priv->ipv6ll_handle; - /* When activating an IPv6 'ignore' connection we need to revert back * to kernel IPv6LL, but the kernel won't actually assign an address * to the interface until disable_ipv6 is bounced. */ - set_nm_ipv6ll(self, FALSE); - if (ipv6ll_handle_old) - nm_device_sysctl_ip_conf_set(self, AF_INET6, "disable_ipv6", "1"); - restore_ip6_properties(self); + _dev_addrgenmode6_set(self, NM_IN6_ADDR_GEN_MODE_EUI64); + _dev_sysctl_set_disable_ipv6(self, TRUE); + _dev_sysctl_restore_ip6_properties(self); } } - return NM_ACT_STAGE_RETURN_IP_DONE; - } - - /* Ensure the MTU makes sense. If it was below 1280 the kernel would not - * expose any ipv6 sysctls or allow presence of any addresses on the interface, - * including LL, which * would make it impossible to autoconfigure MTU to a - * correct value. */ - _commit_mtu(self, priv->ip_config_4); - - /* Any method past this point requires an IPv6LL address. Use NM-controlled - * IPv6LL if this is not an assumed connection, since assumed connections - * will already have IPv6 set up. - */ - if (!nm_device_sys_iface_state_is_external_or_assume(self)) - set_nm_ipv6ll(self, TRUE); - - /* Re-enable IPv6 on the interface */ - nm_device_sysctl_ip_conf_set(self, AF_INET6, "accept_ra", "0"); - set_disable_ipv6(self, "0"); - - /* Synchronize external IPv6 configuration with kernel, since - * linklocal6_start() uses the information there to determine if we can - * proceed with the selected method (SLAAC, DHCP, link-local). - */ - nm_platform_process_events(nm_device_get_platform(self)); - g_clear_object(&priv->ext_ip6_config_captured); - priv->ext_ip6_config_captured = - nm_ip6_config_capture(nm_device_get_multi_index(self), - nm_device_get_platform(self), - nm_device_get_ip_ifindex(self), - NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN); - - ip6_privacy = _prop_get_ipv6_ip6_privacy(self); - - if (NM_IN_STRSET(method, - NM_SETTING_IP6_CONFIG_METHOD_AUTO, - NM_SETTING_IP6_CONFIG_METHOD_SHARED)) { - if (!addrconf6_start(self, ip6_privacy)) { - /* IPv6 might be disabled; allow IPv4 to proceed */ - ret = NM_ACT_STAGE_RETURN_IP_FAIL; - } else - ret = NM_ACT_STAGE_RETURN_POSTPONE; - } else if (nm_streq(method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL)) { - ret = - linklocal6_start(self) ? NM_ACT_STAGE_RETURN_SUCCESS : NM_ACT_STAGE_RETURN_POSTPONE; - } else if (nm_streq(method, NM_SETTING_IP6_CONFIG_METHOD_DHCP)) { - priv->dhcp6.mode = NM_NDISC_DHCP_LEVEL_MANAGED; - if (!dhcp6_start(self, TRUE)) { - /* IPv6 might be disabled; allow IPv4 to proceed */ - ret = NM_ACT_STAGE_RETURN_IP_FAIL; + } else { + _dev_ipll6_start(self); + + if (NM_IN_STRSET(method, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) + _dev_ipac6_start(self); + else if (NM_IN_STRSET(method, NM_SETTING_IP6_CONFIG_METHOD_SHARED)) + _dev_ipshared6_start(self); + else if (nm_streq(method, NM_SETTING_IP6_CONFIG_METHOD_DHCP)) { + priv->ipdhcp_data_6.v6.mode = NM_NDISC_DHCP_LEVEL_MANAGED; + _dev_ipdhcpx_start(self, AF_INET6); } else - ret = NM_ACT_STAGE_RETURN_POSTPONE; - } else if (nm_streq(method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) - ret = NM_ACT_STAGE_RETURN_SUCCESS; - else - _LOGW(LOGD_IP6, "unhandled IPv6 config method '%s'; will fail", method); - - if (ret != NM_ACT_STAGE_RETURN_FAILURE - && !nm_device_sys_iface_state_is_external_or_assume(self)) { - switch (ip6_privacy) { - case NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN: - case NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED: - ip6_privacy_str = "0"; - break; - case NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR: - ip6_privacy_str = "1"; - break; - case NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR: - ip6_privacy_str = "2"; - break; - } - nm_device_sysctl_ip_conf_set(self, AF_INET6, "use_tempaddr", ip6_privacy_str); + nm_assert(NM_IN_STRSET(method, + NM_SETTING_IP6_CONFIG_METHOD_MANUAL, + NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL)); } - - return ret; - } -} - -gboolean -nm_device_activate_stage3_ip_start(NMDevice *self, int addr_family) -{ - const int IS_IPv4 = NM_IS_IPv4(addr_family); - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - NMActStageReturn ret; - NMDeviceStateReason failure_reason = NM_DEVICE_STATE_REASON_NONE; - gs_unref_object NMIPConfig *ip_config = NULL; - - g_assert(priv->ip_state_x[IS_IPv4] == NM_DEVICE_IP_STATE_WAIT); - - if (nm_device_sys_iface_state_is_external(self)) { - _set_ip_state(self, addr_family, NM_DEVICE_IP_STATE_DONE); - check_ip_state(self, FALSE, TRUE); - return TRUE; } - _set_ip_state(self, addr_family, NM_DEVICE_IP_STATE_CONF); - - ret = NM_DEVICE_GET_CLASS(self)->act_stage3_ip_config_start(self, - addr_family, - (gpointer *) &ip_config, - &failure_reason); - - switch (ret) { - case NM_ACT_STAGE_RETURN_SUCCESS: - if (!IS_IPv4) { - /* Here we get a static IPv6 config, like for Shared where it's - * autogenerated or from modems where it comes from ModemManager. - */ - if (!ip_config) - ip_config = nm_device_ip_config_new(self, addr_family); - nm_assert(!applied_config_get_current(&priv->ac_ip6_config)); - applied_config_init(&priv->ac_ip6_config, ip_config); - ip_config = NULL; - } - nm_device_activate_schedule_ip_config_result(self, addr_family, ip_config); - break; - case NM_ACT_STAGE_RETURN_IP_DONE: - _set_ip_state(self, addr_family, NM_DEVICE_IP_STATE_DONE); - check_ip_state(self, FALSE, TRUE); - break; - case NM_ACT_STAGE_RETURN_FAILURE: - nm_device_state_changed(self, NM_DEVICE_STATE_FAILED, failure_reason); - return FALSE; - case NM_ACT_STAGE_RETURN_IP_FAIL: - /* Activation not wanted */ - _set_ip_state(self, addr_family, NM_DEVICE_IP_STATE_FAIL); - break; - case NM_ACT_STAGE_RETURN_IP_WAIT: - /* Wait for something to try IP config again */ - _set_ip_state(self, addr_family, NM_DEVICE_IP_STATE_WAIT); - break; - default: - g_assert(ret == NM_ACT_STAGE_RETURN_POSTPONE); - } +out_devip: + if (klass->act_stage3_ip_config) + klass->act_stage3_ip_config(self, addr_family); - return TRUE; +out: + _dev_ip_state_check_async(self, addr_family); } static void -fw_change_zone_cb(NMFirewalldManager * firewalld_manager, +fw_change_zone_cb(NMFirewalldManager *firewalld_manager, NMFirewalldManagerCallId *call_id, - GError * error, + GError *error, gpointer user_data) { - NMDevice * self = user_data; + NMDevice *self = user_data; NMDevicePrivate *priv; g_return_if_fail(NM_IS_DEVICE(self)); @@ -11588,12 +11693,12 @@ fw_change_zone_cb(NMFirewalldManager * firewalld_manager, switch (priv->fw_state) { case FIREWALL_STATE_WAIT_STAGE_3: priv->fw_state = FIREWALL_STATE_INITIALIZED; - nm_device_activate_schedule_stage3_ip_config_start(self); + nm_device_activate_schedule_stage3_ip_config(self, TRUE); break; case FIREWALL_STATE_WAIT_IP_CONFIG: priv->fw_state = FIREWALL_STATE_INITIALIZED; - if (priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE - || priv->ip_state_6 == NM_DEVICE_IP_STATE_DONE) + if (priv->ip_data_4.state == NM_DEVICE_IP_STATE_READY + || priv->ip_data_6.state == NM_DEVICE_IP_STATE_READY) nm_device_start_ip_check(self); break; case FIREWALL_STATE_INITIALIZED: @@ -11606,10 +11711,10 @@ fw_change_zone_cb(NMFirewalldManager * firewalld_manager, static void fw_change_zone(NMDevice *self) { - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - NMConnection * applied_connection; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NMConnection *applied_connection; NMSettingConnection *s_con; - const char * zone; + const char *zone; nm_assert(priv->fw_state >= FIREWALL_STATE_INITIALIZED); @@ -11645,24 +11750,51 @@ fw_change_zone(NMDevice *self) self); } -/* - * activate_stage3_ip_config_start - * - * Begin automatic/manual IP configuration - * - */ static void -activate_stage3_ip_config_start(NMDevice *self) +activate_stage3_ip_config(NMDevice *self) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NMDeviceClass *klass = NM_DEVICE_GET_CLASS(self); int ifindex; + const char *ipv4_method; + const char *ipv6_method; + + /* stage3 is different from stage1+2. + * + * What is true in all cases is that when we start a stage, we call the corresponding + * nm_device_activate_schedule_stage*() function. But usually the stage cannot complete + * right away but needs to wait for some things to happen. So the activate_stage*() function + * returns, and will be later proceeded by calling *the same* stage again. That means, + * activate_stage*() must be re-entrant and be called repeatedly until we can proceed + * to the next stage. Only when the stage is completed, we schedule the next one. + * + * stage3 is different. It does IP configuration and as such (the stage handling itself) + * cannot fail. If a failure happens (for example for DHCP), we remember that (in priv->ipdhcp_data_x) + * and issue _dev_ip_state_check_async(). That one combines the DHCP state to determine the + * overall per-address-family state (priv->ip_data_x). Those states are then combined + * further into priv->combinedip_state, which then leads to nm_device_state_changed() + * (which for example can make the device fully ACTIVATED or FAILED). + * + * The difference between stage1+2 and stage3 is that IP configuration is running continuously + * while the device is active. As such the activate_stage3_ip_config() does not fail directly, + * unlike the other stages which can abort via NM_ACT_STAGE_RETURN_FAILURE. */ g_return_if_fail(priv->act_request.obj); ifindex = nm_device_get_ip_ifindex(self); + if (priv->ip_data_4.do_reapply) { + _LOGD_ip(AF_INET, "reapply..."); + _cleanup_ip_pre(self, AF_INET, CLEANUP_TYPE_DECONFIGURE, TRUE); + } + if (priv->ip_data_6.do_reapply) { + _LOGD_ip(AF_INET6, "reapply..."); + _cleanup_ip_pre(self, AF_INET6, CLEANUP_TYPE_DECONFIGURE, TRUE); + } + /* Add the interface to the specified firewall zone */ - if (priv->fw_state == FIREWALL_STATE_UNMANAGED) { + switch (priv->fw_state) { + case FIREWALL_STATE_UNMANAGED: if (nm_device_sys_iface_state_is_external(self)) { /* fake success */ priv->fw_state = FIREWALL_STATE_INITIALIZED; @@ -11672,143 +11804,182 @@ activate_stage3_ip_config_start(NMDevice *self) return; } /* no ifindex, nothing to do for now */ - } else if (priv->fw_state == FIREWALL_STATE_WAIT_STAGE_3) { + break; + case FIREWALL_STATE_WAIT_STAGE_3: /* a firewall call for stage3 is pending. Return and wait. */ return; + default: + nm_assert(NM_IN_SET((FirewallState) priv->fw_state, + FIREWALL_STATE_INITIALIZED, + FIREWALL_STATE_WAIT_IP_CONFIG)); + break; } + nm_assert(ifindex <= 0 || priv->fw_state == FIREWALL_STATE_INITIALIZED); + + if (priv->state < NM_DEVICE_STATE_IP_CONFIG) { + _dev_ip_state_req_timeout_schedule(self, AF_INET); + _dev_ip_state_req_timeout_schedule(self, AF_INET6); - nm_assert(ifindex <= 0 || priv->fw_state == FIREWALL_STATE_INITIALIZED); + _active_connection_set_state_flags(self, NM_ACTIVATION_STATE_FLAG_LAYER2_READY); - _set_ip_state(self, AF_INET, NM_DEVICE_IP_STATE_WAIT); - _set_ip_state(self, AF_INET6, NM_DEVICE_IP_STATE_WAIT); + nm_device_state_changed(self, NM_DEVICE_STATE_IP_CONFIG, NM_DEVICE_STATE_REASON_NONE); - _active_connection_set_state_flags(self, NM_ACTIVATION_STATE_FLAG_LAYER2_READY); + /* Device should be up before we can do anything with it */ + if (!nm_device_sys_iface_state_is_external(self) && ifindex > 0 + && !nm_platform_link_is_up(nm_device_get_platform(self), ifindex)) + _LOGW(LOGD_DEVICE, + "interface %s not up for IP configuration", + nm_device_get_ip_iface(self)); + } - nm_device_state_changed(self, NM_DEVICE_STATE_IP_CONFIG, NM_DEVICE_STATE_REASON_NONE); + ipv4_method = nm_device_get_effective_ip_config_method(self, AF_INET); + if (nm_streq(ipv4_method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) { + /* "auto" usually means DHCPv4 or autoconf6, but it doesn't have to be. Subclasses + * can overwrite it. For example, you cannot run DHCPv4 on PPP/WireGuard links. */ + ipv4_method = klass->get_ip_method_auto(self, AF_INET); + } - /* Device should be up before we can do anything with it */ - if (!nm_device_sys_iface_state_is_external(self) - && (ifindex = nm_device_get_ip_ifindex(self)) > 0 - && !nm_platform_link_is_up(nm_device_get_platform(self), ifindex)) - _LOGW(LOGD_DEVICE, - "interface %s not up for IP configuration", - nm_device_get_ip_iface(self)); + ipv6_method = nm_device_get_effective_ip_config_method(self, AF_INET6); + if (nm_streq(ipv6_method, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) { + ipv6_method = klass->get_ip_method_auto(self, AF_INET6); + } - if (nm_device_activate_ip4_state_in_wait(self) - && !nm_device_activate_stage3_ip_start(self, AF_INET)) - return; + if (!nm_device_sys_iface_state_is_external(self) + && (!klass->ready_for_ip_config || klass->ready_for_ip_config(self))) { + if (priv->ipmanual_data.state_6 == NM_DEVICE_IP_STATE_NONE + && !NM_IN_STRSET(ipv6_method, + NM_SETTING_IP6_CONFIG_METHOD_DISABLED, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) { + /* Ensure the MTU makes sense. If it was below 1280 the kernel would not + * expose any ipv6 sysctls or allow presence of any addresses on the interface, + * including LL, which * would make it impossible to autoconfigure MTU to a + * correct value. */ + _commit_mtu(self); + + /* Any method past this point requires an IPv6LL address. Use NM-controlled + * IPv6LL if this is not an assumed connection, since assumed connections + * will already have IPv6 set up. + */ + if (!nm_device_sys_iface_state_is_external_or_assume(self)) + _dev_addrgenmode6_set(self, NM_IN6_ADDR_GEN_MODE_NONE); - if (nm_device_activate_ip6_state_in_wait(self) - && !nm_device_activate_stage3_ip_start(self, AF_INET6)) - return; + /* Re-enable IPv6 on the interface */ + nm_device_sysctl_ip_conf_set(self, AF_INET6, "accept_ra", "0"); + _dev_sysctl_set_disable_ipv6(self, FALSE); + } - /* Proxy */ - nm_device_set_proxy_config(self, NULL); + _dev_ipmanual_start(self); + } - check_ip_state(self, TRUE, TRUE); + activate_stage3_ip_config_for_addr_family(self, AF_INET, ipv4_method); + activate_stage3_ip_config_for_addr_family(self, AF_INET6, ipv6_method); } -/* - * nm_device_activate_schedule_stage3_ip_config_start - * - * Schedule IP configuration start - */ void -nm_device_activate_schedule_stage3_ip_config_start(NMDevice *self) +nm_device_activate_schedule_stage3_ip_config(NMDevice *self, gboolean do_sync) { - NMDevicePrivate *priv; - - g_return_if_fail(NM_IS_DEVICE(self)); - - priv = NM_DEVICE_GET_PRIVATE(self); - - g_return_if_fail(priv->act_request.obj); - - activation_source_schedule(self, activate_stage3_ip_config_start, AF_INET); + activation_source_invoke_or_schedule(self, activate_stage3_ip_config, do_sync); } -static NMActStageReturn -act_stage4_ip_config_timeout(NMDevice * self, - int addr_family, - NMDeviceStateReason *out_failure_reason) +/*****************************************************************************/ + +static void +_dev_ipsharedx_set_state(NMDevice *self, int addr_family, NMDeviceIPState state) { - nm_assert_addr_family(addr_family); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + const int IS_IPv4 = NM_IS_IPv4(addr_family); - if (!get_ip_config_may_fail(self, addr_family)) { - NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); - return NM_ACT_STAGE_RETURN_FAILURE; + if (priv->ipshared_data_x[IS_IPv4].state != state) { + _LOGD_ipshared(addr_family, + "set state %s (was %s)", + nm_device_ip_state_to_string(state), + nm_device_ip_state_to_string(priv->ipshared_data_x[IS_IPv4].state)); + priv->ipshared_data_x[IS_IPv4].state = state; } - - return NM_ACT_STAGE_RETURN_SUCCESS; } static void -activate_stage4_ip_config_timeout_x(NMDevice *self, int addr_family) +_dev_ipsharedx_cleanup(NMDevice *self, int addr_family) { - NMDeviceStateReason failure_reason = NM_DEVICE_STATE_REASON_NONE; - NMActStageReturn ret; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + const int IS_IPv4 = NM_IS_IPv4(addr_family); - ret = - NM_DEVICE_GET_CLASS(self)->act_stage4_ip_config_timeout(self, addr_family, &failure_reason); + if (IS_IPv4) { + if (priv->ipshared_data_4.v4.dnsmasq_manager) { + nm_clear_g_signal_handler(priv->ipshared_data_4.v4.dnsmasq_manager, + &priv->ipshared_data_4.v4.dnsmasq_state_id); + nm_dnsmasq_manager_stop(priv->ipshared_data_4.v4.dnsmasq_manager); + g_clear_object(&priv->ipshared_data_4.v4.dnsmasq_manager); + } - if (ret == NM_ACT_STAGE_RETURN_POSTPONE) - return; + if (priv->ipshared_data_4.v4.firewall_config) { + nm_firewall_config_apply(priv->ipshared_data_4.v4.firewall_config, FALSE); + nm_clear_pointer(&priv->ipshared_data_4.v4.firewall_config, nm_firewall_config_free); + } - if (ret == NM_ACT_STAGE_RETURN_FAILURE) { - nm_device_state_changed(self, NM_DEVICE_STATE_FAILED, failure_reason); - return; + nm_clear_pointer(&priv->ipshared_data_4.v4.shared_ip_handle, nm_netns_shared_ip_release); + nm_clear_l3cd(&priv->ipshared_data_4.v4.l3cd); + + _dev_l3_register_l3cds_set_one(self, L3_CONFIG_DATA_TYPE_SHARED_4, NULL, FALSE); } - g_assert(ret == NM_ACT_STAGE_RETURN_SUCCESS); - _set_ip_state(self, addr_family, NM_DEVICE_IP_STATE_FAIL); - check_ip_state(self, FALSE, TRUE); + _dev_ipsharedx_set_state(self, addr_family, NM_DEVICE_IP_STATE_NONE); } -static void -activate_stage4_ip_config_timeout_4(NMDevice *self) -{ - activate_stage4_ip_config_timeout_x(self, AF_INET); -} +/*****************************************************************************/ -static void -activate_stage4_ip_config_timeout_6(NMDevice *self) +static const NML3ConfigData * +_dev_ipshared4_new_l3cd(NMDevice *self, NMConnection *connection, NMPlatformIP4Address *out_addr4) { - activate_stage4_ip_config_timeout_x(self, AF_INET6); -} + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + NMSettingIPConfig *s_ip4; + NMPlatformIP4Address address = { + .addr_source = NM_IP_CONFIG_SOURCE_SHARED, + }; -#define activate_stage4_ip_config_timeout_x_fcn(addr_family) \ - (NM_IS_IPv4(addr_family) ? activate_stage4_ip_config_timeout_4 \ - : activate_stage4_ip_config_timeout_6) + g_return_val_if_fail(self, NULL); + g_return_val_if_fail(connection, NULL); -void -nm_device_activate_schedule_ip_config_timeout(NMDevice *self, int addr_family) -{ - NMDevicePrivate *priv; + s_ip4 = nm_connection_get_setting_ip4_config(connection); + if (s_ip4 && nm_setting_ip_config_get_num_addresses(s_ip4) > 0) { + /* Use the first user-supplied address */ + NMIPAddress *user = nm_setting_ip_config_get_address(s_ip4, 0); + in_addr_t a; - g_return_if_fail(NM_IS_DEVICE(self)); + nm_ip_address_get_address_binary(user, &a); + nm_platform_ip4_address_set_addr(&address, a, nm_ip_address_get_prefix(user)); + nm_clear_pointer(&priv->ipshared_data_4.v4.shared_ip_handle, nm_netns_shared_ip_release); + } else { + if (!priv->ipshared_data_4.v4.shared_ip_handle) + priv->ipshared_data_4.v4.shared_ip_handle = + nm_netns_shared_ip_reserve(nm_device_get_netns(self)); + nm_platform_ip4_address_set_addr(&address, + priv->ipshared_data_4.v4.shared_ip_handle->addr, + 24); + } - priv = NM_DEVICE_GET_PRIVATE(self); + l3cd = nm_device_create_l3_config_data(self, NM_IP_CONFIG_SOURCE_SHARED); + nm_l3_config_data_add_address_4(l3cd, &address); - g_return_if_fail(priv->act_request.obj); + NM_SET_OUT(out_addr4, address); - activation_source_schedule(self, - activate_stage4_ip_config_timeout_x_fcn(addr_family), - addr_family); + return nm_l3_config_data_seal(g_steal_pointer(&l3cd)); } static gboolean -share_init(NMDevice *self, GError **error) -{ - const char *const modules[] = {"ip_tables", - "iptable_nat", - "nf_nat_ftp", - "nf_nat_irc", - "nf_nat_sip", - "nf_nat_tftp", - "nf_nat_pptp", - "nf_nat_h323"}; - guint i; - int errsv; +_dev_ipshared4_init(NMDevice *self) +{ + static const char *const modules[] = {"ip_tables", + "iptable_nat", + "nf_nat_ftp", + "nf_nat_irc", + "nf_nat_sip", + "nf_nat_tftp", + "nf_nat_pptp", + "nf_nat_h323"}; + int errsv; + guint i; if (nm_platform_sysctl_get_int32(nm_device_get_platform(self), NMP_SYSCTL_PATHID_ABSOLUTE("/proc/sys/net/ipv4/ip_forward"), @@ -11819,15 +11990,7 @@ share_init(NMDevice *self, GError **error) NMP_SYSCTL_PATHID_ABSOLUTE("/proc/sys/net/ipv4/ip_forward"), "1")) { errsv = errno; - _LOGD(LOGD_SHARING, - "share: error enabling IPv4 forwarding: (%d) %s", - errsv, - nm_strerror_native(errsv)); - g_set_error(error, - NM_UTILS_ERROR, - NM_UTILS_ERROR_UNKNOWN, - "cannot set ipv4/ip_forward: %s", - nm_strerror_native(errsv)); + _LOGW_ipshared(AF_INET, "error enabling IPv4 forwarding: %s", nm_strerror_native(errsv)); return FALSE; } @@ -11840,10 +12003,9 @@ share_init(NMDevice *self, GError **error) NMP_SYSCTL_PATHID_ABSOLUTE("/proc/sys/net/ipv4/ip_dynaddr"), "1")) { errsv = errno; - _LOGD(LOGD_SHARING, - "share: error enabling dynamic addresses: (%d) %s", - errsv, - nm_strerror_native(errsv)); + _LOGD_ipshared(AF_INET, + "share: error enabling dynamic addresses: %s", + nm_strerror_native(errsv)); } for (i = 0; i < G_N_ELEMENTS(modules); i++) @@ -11852,48 +12014,86 @@ share_init(NMDevice *self, GError **error) return TRUE; } -static gboolean -start_sharing(NMDevice *self, NMIP4Config *config, GError **error) +static void +_dev_ipshared4_dnsmasq_state_changed_cb(NMDnsMasqManager *manager, guint status, gpointer user_data) +{ + NMDevice *self = NM_DEVICE(user_data); + + if (status != NM_DNSMASQ_STATUS_DEAD) + return; + + _dev_ipsharedx_set_state(self, AF_INET, NM_DEVICE_IP_STATE_FAILED); + _dev_ip_state_check_async(self, AF_INET); +} + +static void +_dev_ipshared4_start(NMDevice *self) { - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - NMActRequest * req; - const NMPlatformIP4Address *ip4_addr = NULL; - const char * ip_iface; - GError * local = NULL; - NMConnection * conn; - NMSettingConnection * s_con; - gboolean announce_android_metered; - NMFirewallConfig * firewall_config; + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; + NMPlatformIP4Address ip4_addr; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + const char *ip_iface; + NMConnection *applied; + + if (priv->ipshared_data_4.state != NM_DEVICE_IP_STATE_NONE) + return; - g_return_val_if_fail(config, FALSE); + nm_assert(!priv->ipshared_data_4.v4.firewall_config); + nm_assert(!priv->ipshared_data_4.v4.dnsmasq_manager); + nm_assert(priv->ipshared_data_4.v4.dnsmasq_state_id == 0); ip_iface = nm_device_get_ip_iface(self); - if (!ip_iface) { - g_set_error(error, NM_UTILS_ERROR, NM_UTILS_ERROR_UNKNOWN, "device has no ip interface"); - return FALSE; - } + g_return_if_fail(ip_iface); - ip4_addr = nm_ip4_config_get_first_address(config); - if (!ip4_addr || !ip4_addr->address) { - g_set_error(error, - NM_UTILS_ERROR, - NM_UTILS_ERROR_UNKNOWN, - "could not determine IPv4 address"); - return FALSE; + applied = nm_device_get_applied_connection(self); + g_return_if_fail(applied); + + _dev_ipsharedx_set_state(self, AF_INET, NM_DEVICE_IP_STATE_PENDING); + + l3cd = _dev_ipshared4_new_l3cd(self, applied, &ip4_addr); + if (!l3cd) { + nm_assert_not_reached(); + goto out_fail; } - if (!share_init(self, error)) - return FALSE; + if (!_dev_ipshared4_init(self)) + goto out_fail; + + priv->ipshared_data_4.v4.firewall_config = + nm_firewall_config_new(ip_iface, ip4_addr.address, ip4_addr.plen); + nm_firewall_config_apply(priv->ipshared_data_4.v4.firewall_config, TRUE); + + priv->ipshared_data_4.v4.l3cd = nm_l3_config_data_ref(l3cd); + _dev_l3_register_l3cds_set_one(self, L3_CONFIG_DATA_TYPE_SHARED_4, l3cd, FALSE); + + /* Wait that the address gets committed before spawning dnsmasq */ + return; +out_fail: + _dev_ipsharedx_set_state(self, AF_INET, NM_DEVICE_IP_STATE_FAILED); + _dev_ip_state_check_async(self, AF_INET); +} - req = nm_device_get_act_request(self); - g_return_val_if_fail(req, FALSE); +static void +_dev_ipshared4_spawn_dnsmasq(NMDevice *self) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + const char *ip_iface; + gs_free_error GError *error = NULL; + NMSettingConnection *s_con; + gboolean announce_android_metered; + NMConnection *applied; - firewall_config = nm_firewall_config_new(ip_iface, ip4_addr->address, ip4_addr->plen); + nm_assert(priv->ipshared_data_4.v4.firewall_config); + nm_assert(priv->ipshared_data_4.v4.dnsmasq_state_id == 0); + nm_assert(!priv->ipshared_data_4.v4.dnsmasq_manager); + nm_assert(priv->ipshared_data_4.v4.l3cd); - nm_act_request_set_shared(req, firewall_config); + ip_iface = nm_device_get_ip_iface(self); + g_return_if_fail(ip_iface); - conn = nm_act_request_get_applied_connection(req); - s_con = nm_connection_get_setting_connection(conn); + applied = nm_device_get_applied_connection(self); + g_return_if_fail(applied); + s_con = nm_connection_get_setting_connection(applied); switch (nm_setting_connection_get_metered(s_con)) { case NM_METERED_YES: @@ -11915,353 +12115,54 @@ start_sharing(NMDevice *self, NMIP4Config *config, GError **error) break; } - if (!nm_dnsmasq_manager_start(priv->dnsmasq_manager, - config, + priv->ipshared_data_4.v4.dnsmasq_manager = nm_dnsmasq_manager_new(ip_iface); + if (!nm_dnsmasq_manager_start(priv->ipshared_data_4.v4.dnsmasq_manager, + priv->ipshared_data_4.v4.l3cd, announce_android_metered, - &local)) { - g_set_error(error, - NM_UTILS_ERROR, - NM_UTILS_ERROR_UNKNOWN, - "could not start dnsmasq due to %s", - local->message); - g_error_free(local); - nm_act_request_set_shared(req, NULL); - return FALSE; - } - - priv->dnsmasq_state_id = g_signal_connect(priv->dnsmasq_manager, - NM_DNS_MASQ_MANAGER_STATE_CHANGED, - G_CALLBACK(dnsmasq_state_changed_cb), - self); - return TRUE; -} - -static void -arp_cleanup(NMDevice *self) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - - nm_clear_pointer(&priv->acd.announcing, nm_acd_manager_free); -} - -void -nm_device_arp_announce(NMDevice *self) -{ - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - NMConnection * connection; - NMSettingIPConfig *s_ip4; - guint num, i; - const guint8 * hw_addr; - size_t hw_addr_len = 0; - - arp_cleanup(self); - - hw_addr = nm_platform_link_get_address(nm_device_get_platform(self), - nm_device_get_ip_ifindex(self), - &hw_addr_len); - - if (!hw_addr || hw_addr_len != ETH_ALEN) - return; - - /* We only care about manually-configured addresses; DHCP- and autoip-configured - * ones should already have been seen on the network at this point. - */ - connection = nm_device_get_applied_connection(self); - if (!connection) - return; - s_ip4 = nm_connection_get_setting_ip4_config(connection); - if (!s_ip4) - return; - num = nm_setting_ip_config_get_num_addresses(s_ip4); - if (num == 0) - return; - - priv->acd.announcing = - nm_acd_manager_new(nm_device_get_ip_ifindex(self), hw_addr, hw_addr_len, NULL, NULL); - - for (i = 0; i < num; i++) { - NMIPAddress *ip = nm_setting_ip_config_get_address(s_ip4, i); - in_addr_t addr; - - if (inet_pton(AF_INET, nm_ip_address_get_address(ip), &addr) == 1) - nm_acd_manager_add_address(priv->acd.announcing, addr); - else - g_warn_if_reached(); - } - - nm_acd_manager_announce_addresses(priv->acd.announcing); -} - -static void -activate_stage5_ip_config_result_x(NMDevice *self, int addr_family) -{ - const int IS_IPv4 = NM_IS_IPv4(addr_family); - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - NMActRequest * req; - const char * method; - int ip_ifindex; - int errsv; - - req = nm_device_get_act_request(self); - g_assert(req); - - nm_clear_g_source_inst(&priv->ip_req_timeout_source_x[IS_IPv4]); - - /* Interface must be IFF_UP before IP config can be applied */ - ip_ifindex = nm_device_get_ip_ifindex(self); - g_return_if_fail(ip_ifindex); - - if (!nm_platform_link_is_up(nm_device_get_platform(self), ip_ifindex) - && !nm_device_sys_iface_state_is_external(self)) { - nm_platform_link_change_flags(nm_device_get_platform(self), ip_ifindex, IFF_UP, TRUE); - if (!nm_platform_link_is_up(nm_device_get_platform(self), ip_ifindex)) - _LOGW(LOGD_DEVICE, - "interface %s not up for IP configuration", - nm_device_get_ip_iface(self)); - } - - if (!ip_config_merge_and_apply(self, addr_family, TRUE)) { - _LOGD(LOGD_DEVICE | LOGD_IPX(IS_IPv4), - "Activation: Stage 5 of 5 (IPv%c Commit) failed", - nm_utils_addr_family_to_char(addr_family)); - nm_device_ip_method_failed(self, addr_family, NM_DEVICE_STATE_REASON_CONFIG_FAILED); - return; - } - - if (!IS_IPv4) { - if (priv->dhcp6.mode != NM_NDISC_DHCP_LEVEL_NONE - && priv->ip_state_6 == NM_DEVICE_IP_STATE_CONF) { - if (applied_config_get_current(&priv->dhcp6.ip6_config)) { - /* If IPv6 wasn't the first IP to complete, and DHCP was used, - * then ensure dispatcher scripts get the DHCP lease information. - */ - nm_dispatcher_call_device(NM_DISPATCHER_ACTION_DHCP_CHANGE_6, - self, - NULL, - NULL, - NULL, - NULL); - } else { - /* still waiting for first dhcp6 lease. */ - return; - } - } - } - - /* Start IPv4 sharing/IPv6 forwarding if we need it */ - method = nm_device_get_effective_ip_config_method(self, addr_family); - if (IS_IPv4) { - if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)) { - gs_free_error GError *error = NULL; - - if (!start_sharing(self, priv->ip_config_4, &error)) { - _LOGW(LOGD_SHARING, - "Activation: Stage 5 of 5 (IPv4 Commit) start sharing failed: %s", - error->message); - nm_device_ip_method_failed(self, - AF_INET, - NM_DEVICE_STATE_REASON_SHARED_START_FAILED); - return; - } - } - } else { - if (nm_streq(method, NM_SETTING_IP6_CONFIG_METHOD_SHARED)) { - if (!nm_platform_sysctl_set( - nm_device_get_platform(self), - NMP_SYSCTL_PATHID_ABSOLUTE("/proc/sys/net/ipv6/conf/all/forwarding"), - "1")) { - errsv = errno; - _LOGE(LOGD_SHARING, - "share: error enabling IPv6 forwarding: (%d) %s", - errsv, - nm_strerror_native(errsv)); - nm_device_ip_method_failed(self, - AF_INET6, - NM_DEVICE_STATE_REASON_SHARED_START_FAILED); - return; - } - } - } - - if (IS_IPv4) { - if (priv->dhcp_data_4.client) { - gs_free_error GError *error = NULL; - - if (!nm_dhcp_client_accept(priv->dhcp_data_4.client, &error)) { - _LOGW(LOGD_DHCP4, - "Activation: Stage 5 of 5 (IPv4 Commit) error accepting lease: %s", - error->message); - nm_device_ip_method_failed(self, AF_INET, NM_DEVICE_STATE_REASON_DHCP_ERROR); - return; - } - } - - /* If IPv4 wasn't the first to complete, and DHCP was used, then ensure - * dispatcher scripts get the DHCP lease information. - */ - if (priv->dhcp_data_4.client && nm_device_activate_ip4_state_in_conf(self) - && (nm_device_get_state(self) > NM_DEVICE_STATE_IP_CONFIG)) { - nm_dispatcher_call_device(NM_DISPATCHER_ACTION_DHCP_CHANGE_4, - self, - NULL, - NULL, - NULL, - NULL); - } - } - - if (!IS_IPv4) { - /* Check if we have to wait for DAD */ - if (priv->ip_state_6 == NM_DEVICE_IP_STATE_CONF && !priv->dad6_ip6_config) { - if (!priv->carrier && priv->ignore_carrier && get_ip_config_may_fail(self, AF_INET6)) - _LOGI(LOGD_DEVICE | LOGD_IP6, - "IPv6 DAD: carrier missing and ignored, not delaying activation"); - else - priv->dad6_ip6_config = dad6_get_pending_addresses(self); - - if (priv->dad6_ip6_config) { - _LOGD(LOGD_DEVICE | LOGD_IP6, "IPv6 DAD: awaiting termination"); - } else { - _set_ip_state(self, AF_INET6, NM_DEVICE_IP_STATE_DONE); - check_ip_state(self, FALSE, TRUE); - } - } - } - - if (IS_IPv4 && priv->carrier) { - /* We send ARP announcements only when the link gets carrier, - * otherwise the announcements would be lost. Furthermore, for - * controllers having carrier implies that there is at least one - * port and therefore the MAC address is the correct one. - */ - nm_device_arp_announce(self); - } - - if (IS_IPv4) { - /* Enter the IP_CHECK state if this is the first method to complete */ - _set_ip_state(self, AF_INET, NM_DEVICE_IP_STATE_DONE); - check_ip_state(self, FALSE, TRUE); + &error)) { + _LOGW_ipshared(AF_INET, "could not start dnsmasq: %s", error->message); + goto out_fail; } -} - -static void -activate_stage5_ip_config_result_4(NMDevice *self) -{ - activate_stage5_ip_config_result_x(self, AF_INET); -} - -static void -activate_stage5_ip_config_result_6(NMDevice *self) -{ - activate_stage5_ip_config_result_x(self, AF_INET6); -} - -#define activate_stage5_ip_config_result_x_fcn(addr_family) \ - (NM_IS_IPv4(addr_family) ? activate_stage5_ip_config_result_4 \ - : activate_stage5_ip_config_result_6) - -void -nm_device_activate_schedule_ip_config_result(NMDevice *self, int addr_family, NMIPConfig *config) -{ - NMDevicePrivate *priv; - const int IS_IPv4 = NM_IS_IPv4(addr_family); - g_return_if_fail(NM_IS_DEVICE(self)); - g_return_if_fail(!config || (IS_IPv4 && nm_ip_config_get_addr_family(config) == AF_INET)); - - priv = NM_DEVICE_GET_PRIVATE(self); + priv->ipshared_data_4.v4.dnsmasq_state_id = + g_signal_connect(priv->ipshared_data_4.v4.dnsmasq_manager, + NM_DNS_MASQ_MANAGER_STATE_CHANGED, + G_CALLBACK(_dev_ipshared4_dnsmasq_state_changed_cb), + self); - if (IS_IPv4) { - applied_config_init(&priv->dev_ip_config_4, config); - } else { - /* If IP had previously failed, move it back to NM_DEVICE_IP_STATE_CONF since we - * clearly now have configuration. - */ - if (priv->ip_state_6 == NM_DEVICE_IP_STATE_FAIL) - _set_ip_state(self, AF_INET6, NM_DEVICE_IP_STATE_CONF); - } + _dev_ipsharedx_set_state(self, AF_INET, NM_DEVICE_IP_STATE_READY); + _dev_ip_state_check_async(self, AF_INET); + return; - activation_source_schedule(self, - activate_stage5_ip_config_result_x_fcn(addr_family), - addr_family); +out_fail: + _dev_ipsharedx_set_state(self, AF_INET, NM_DEVICE_IP_STATE_FAILED); + _dev_ip_state_check_async(self, AF_INET); } -NMDeviceIPState -nm_device_activate_get_ip_state(NMDevice *self, int addr_family) -{ - const int IS_IPv4 = NM_IS_IPv4(addr_family); - - g_return_val_if_fail(NM_IS_DEVICE(self), NM_DEVICE_IP_STATE_NONE); - g_return_val_if_fail(NM_IN_SET(addr_family, AF_INET, AF_INET6), NM_DEVICE_IP_STATE_NONE); - - return NM_DEVICE_GET_PRIVATE(self)->ip_state_x[IS_IPv4]; -} +/*****************************************************************************/ static void -dad6_add_pending_address(NMDevice * self, - NMPlatform * platform, - int ifindex, - const struct in6_addr *address, - NMIP6Config ** dad6_config) -{ - const NMPlatformIP6Address *pl_addr; - - pl_addr = nm_platform_ip6_address_get(platform, ifindex, address); - if (pl_addr && NM_FLAGS_HAS(pl_addr->n_ifa_flags, IFA_F_TENTATIVE) - && !NM_FLAGS_HAS(pl_addr->n_ifa_flags, IFA_F_DADFAILED) - && !NM_FLAGS_HAS(pl_addr->n_ifa_flags, IFA_F_OPTIMISTIC)) { - _LOGt(LOGD_DEVICE, - "IPv6 DAD: pending address %s", - nm_platform_ip6_address_to_string(pl_addr, NULL, 0)); - - if (!*dad6_config) - *dad6_config = nm_device_ip6_config_new(self); - - nm_ip6_config_add_address(*dad6_config, pl_addr); - } -} - -/* - * Returns a NMIP6Config containing NM-configured addresses which - * have the tentative flag, or NULL if none is present. - */ -static NMIP6Config * -dad6_get_pending_addresses(NMDevice *self) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - NMIP6Config * confs[] = {(NMIP6Config *) applied_config_get_current(&priv->ac_ip6_config), - (NMIP6Config *) applied_config_get_current(&priv->dhcp6.ip6_config), - priv->con_ip_config_6, - (NMIP6Config *) applied_config_get_current(&priv->dev2_ip_config_6)}; - const NMPlatformIP6Address *addr; - NMIP6Config * dad6_config = NULL; - NMDedupMultiIter ipconf_iter; - guint i; - int ifindex; - NMPlatform * platform; - - ifindex = nm_device_get_ip_ifindex(self); - g_return_val_if_fail(ifindex > 0, NULL); - - platform = nm_device_get_platform(self); +_dev_ipshared6_start(NMDevice *self) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - if (priv->ipv6ll_has) { - dad6_add_pending_address(self, platform, ifindex, &priv->ipv6ll_addr, &dad6_config); - } + _dev_ipac6_start(self); - /* We are interested only in addresses that we have explicitly configured, - * not in externally added ones. - */ - for (i = 0; i < G_N_ELEMENTS(confs); i++) { - if (!confs[i]) - continue; + if (priv->ipshared_data_6.state != NM_DEVICE_IP_STATE_NONE) + return; - nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, confs[i], &addr) { - dad6_add_pending_address(self, platform, ifindex, &addr->address, &dad6_config); - } + if (!nm_platform_sysctl_set( + nm_device_get_platform(self), + NMP_SYSCTL_PATHID_ABSOLUTE("/proc/sys/net/ipv6/conf/all/forwarding"), + "1")) { + _LOGW_ipshared(AF_INET6, "failure to enable ipv6 forwarding"); + _dev_ipsharedx_set_state(self, AF_INET6, NM_DEVICE_IP_STATE_FAILED); + _dev_ip_state_check_async(self, AF_INET6); + return; } - return dad6_config; + _dev_ipsharedx_set_state(self, AF_INET6, NM_DEVICE_IP_STATE_READY); + _dev_ip_state_check_async(self, AF_INET6); } /*****************************************************************************/ @@ -12302,21 +12203,6 @@ act_request_set(NMDevice *self, NMActRequest *act_request) } } -static void -dnsmasq_cleanup(NMDevice *self) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - - if (!priv->dnsmasq_manager) - return; - - nm_clear_g_signal_handler(priv->dnsmasq_manager, &priv->dnsmasq_state_id); - - nm_dnsmasq_manager_stop(priv->dnsmasq_manager); - g_object_unref(priv->dnsmasq_manager); - priv->dnsmasq_manager = NULL; -} - gboolean nm_device_is_nm_owned(NMDevice *self) { @@ -12333,10 +12219,10 @@ nm_device_is_nm_owned(NMDevice *self) static gboolean delete_on_deactivate_link_delete(gpointer user_data) { - DeleteOnDeactivateData *data = user_data; - nm_auto_unref_object NMDevice *self = data->device; - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - gs_free_error GError *error = NULL; + DeleteOnDeactivateData *data = user_data; + nm_auto_unref_object NMDevice *self = data->device; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + gs_free_error GError *error = NULL; _LOGD(LOGD_DEVICE, "delete_on_deactivate: cleanup and delete virtual link (id=%u)", @@ -12375,7 +12261,7 @@ delete_on_deactivate_unschedule(NMDevice *self) static void delete_on_deactivate_check_and_schedule(NMDevice *self) { - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); DeleteOnDeactivateData *data; if (!priv->nm_owned) @@ -12401,40 +12287,32 @@ delete_on_deactivate_check_and_schedule(NMDevice *self) } static void -_cleanup_ip_pre(NMDevice *self, int addr_family, CleanupType cleanup_type) +_cleanup_ip_pre(NMDevice *self, int addr_family, CleanupType cleanup_type, gboolean from_reapply) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - const int IS_IPv4 = NM_IS_IPv4(addr_family); + const int IS_IPv4 = NM_IS_IPv4(addr_family); - _set_ip_state(self, addr_family, NM_DEVICE_IP_STATE_NONE); + _dev_ipsharedx_cleanup(self, addr_family); - if (nm_clear_g_source(&priv->queued_ip_config_id_x[IS_IPv4])) { - _LOGD(LOGD_DEVICE, - "clearing queued IP%c config change", - nm_utils_addr_family_to_char(addr_family)); - } + _dev_ipdev_cleanup(self, AF_UNSPEC); + _dev_ipdev_cleanup(self, addr_family); - if (IS_IPv4) { - dhcp4_cleanup(self, cleanup_type, FALSE); - arp_cleanup(self); - dnsmasq_cleanup(self); - ipv4ll_cleanup(self); - g_slist_free_full(priv->acd.dad_list, (GDestroyNotify) nm_acd_manager_free); - priv->acd.dad_list = NULL; - } else { - g_slist_free_full(priv->dad6_failed_addrs, (GDestroyNotify) nmp_object_unref); - priv->dad6_failed_addrs = NULL; - g_clear_object(&priv->dad6_ip6_config); - dhcp6_cleanup(self, cleanup_type, FALSE); - nm_clear_g_source(&priv->linklocal6_timeout_id); - addrconf6_cleanup(self); - } + _dev_ipdhcpx_cleanup(self, addr_family, TRUE, FALSE); + + if (!IS_IPv4) + _dev_ipac6_cleanup(self); + + _dev_ipllx_cleanup(self, addr_family); + + _dev_ipmanual_cleanup(self); + + _dev_ip_state_cleanup(self, AF_UNSPEC, from_reapply); + _dev_ip_state_cleanup(self, addr_family, from_reapply); } gboolean -_nm_device_hash_check_invalid_keys(GHashTable * hash, - const char * setting_name, - GError ** error, +_nm_device_hash_check_invalid_keys(GHashTable *hash, + const char *setting_name, + GError **error, const char *const *whitelist) { guint found_whitelisted_keys = 0; @@ -12469,8 +12347,8 @@ _nm_device_hash_check_invalid_keys(GHashTable * hash, if (error) { GHashTableIter iter; - const char * k = NULL; - const char * first_invalid_key = NULL; + const char *k = NULL; + const char *first_invalid_key = NULL; g_hash_table_iter_init(&iter, hash); while (g_hash_table_iter_next(&iter, (gpointer *) &k, NULL)) { @@ -12499,128 +12377,6 @@ _nm_device_hash_check_invalid_keys(GHashTable * hash, return FALSE; } -void -nm_device_reactivate_ip_config(NMDevice * self, - int addr_family, - NMSettingIPConfig *s_ip_old, - NMSettingIPConfig *s_ip_new) -{ - const int IS_IPv4 = NM_IS_IPv4(addr_family); - NMDevicePrivate *priv; - const char * method_old; - const char * method_new; - - g_return_if_fail(NM_IS_DEVICE(self)); - - priv = NM_DEVICE_GET_PRIVATE(self); - - if (priv->ip_state_x[IS_IPv4] == NM_DEVICE_IP_STATE_NONE) - return; - - g_clear_object(&priv->con_ip_config_x[IS_IPv4]); - g_clear_object(&priv->ext_ip_config_x[IS_IPv4]); - if (IS_IPv4) { - g_clear_object(&priv->dev_ip_config_4.current); - } else { - g_clear_object(&priv->ac_ip6_config.current); - g_clear_object(&priv->dhcp6.ip6_config.current); - } - g_clear_object(&priv->dev2_ip_config_x[IS_IPv4].current); - - if (!IS_IPv4) { - if (priv->ipv6ll_handle && !IN6_IS_ADDR_UNSPECIFIED(&priv->ipv6ll_addr)) - priv->ipv6ll_has = TRUE; - } - - priv->con_ip_config_x[IS_IPv4] = nm_device_ip_config_new(self, addr_family); - - if (IS_IPv4) { - nm_ip4_config_merge_setting(priv->con_ip_config_4, - s_ip_new, - _prop_get_connection_mdns(self), - _prop_get_connection_llmnr(self), - _prop_get_connection_dns_over_tls(self), - nm_device_get_route_table(self, AF_INET), - nm_device_get_route_metric(self, AF_INET)); - } else { - nm_ip6_config_merge_setting(priv->con_ip_config_6, - s_ip_new, - nm_device_get_route_table(self, AF_INET6), - nm_device_get_route_metric(self, AF_INET6)); - } - - method_old = (s_ip_old ? nm_setting_ip_config_get_method(s_ip_old) : NULL) - ?: (IS_IPv4 ? NM_SETTING_IP4_CONFIG_METHOD_DISABLED - : NM_SETTING_IP6_CONFIG_METHOD_IGNORE); - method_new = (s_ip_new ? nm_setting_ip_config_get_method(s_ip_new) : NULL) - ?: (IS_IPv4 ? NM_SETTING_IP4_CONFIG_METHOD_DISABLED - : NM_SETTING_IP6_CONFIG_METHOD_IGNORE); - - if (!nm_streq0(method_old, method_new)) { - _cleanup_ip_pre(self, addr_family, CLEANUP_TYPE_DECONFIGURE); - _set_ip_state(self, addr_family, NM_DEVICE_IP_STATE_WAIT); - if (!nm_device_activate_stage3_ip_start(self, addr_family)) { - _LOGW(LOGD_IP4, - "Failed to apply IPv%c configuration", - nm_utils_addr_family_to_char(addr_family)); - } - return; - } - - if (s_ip_old && s_ip_new) { - gint64 metric_old, metric_new; - - /* For dynamic IP methods (DHCP, IPv4LL, WWAN) the route metric is - * set at activation/renewal time using the value from static - * configuration. To support runtime change we need to update the - * dynamic configuration in place and tell the DHCP client the new - * value to use for future renewals. - */ - metric_old = nm_setting_ip_config_get_route_metric(s_ip_old); - metric_new = nm_setting_ip_config_get_route_metric(s_ip_new); - - if (metric_old != metric_new) { - if (IS_IPv4) { - if (priv->dev_ip_config_4.orig) { - nm_ip4_config_update_routes_metric((NMIP4Config *) priv->dev_ip_config_4.orig, - nm_device_get_route_metric(self, AF_INET)); - } - if (priv->dev2_ip_config_4.orig) { - nm_ip4_config_update_routes_metric((NMIP4Config *) priv->dev2_ip_config_4.orig, - nm_device_get_route_metric(self, AF_INET)); - } - if (priv->dhcp_data_4.client) { - nm_dhcp_client_set_route_metric(priv->dhcp_data_4.client, - nm_device_get_route_metric(self, AF_INET)); - } - } else { - if (priv->ac_ip6_config.orig) { - nm_ip6_config_update_routes_metric((NMIP6Config *) priv->ac_ip6_config.orig, - nm_device_get_route_metric(self, AF_INET6)); - } - if (priv->dhcp6.ip6_config.orig) { - nm_ip6_config_update_routes_metric((NMIP6Config *) priv->dhcp6.ip6_config.orig, - nm_device_get_route_metric(self, AF_INET6)); - } - if (priv->dev2_ip_config_6.orig) { - nm_ip6_config_update_routes_metric((NMIP6Config *) priv->dev2_ip_config_6.orig, - nm_device_get_route_metric(self, AF_INET6)); - } - if (priv->dhcp_data_6.client) { - nm_dhcp_client_set_route_metric(priv->dhcp_data_6.client, - nm_device_get_route_metric(self, AF_INET6)); - } - } - } - } - - if (nm_device_get_ip_ifindex(self) > 0 && !ip_config_merge_and_apply(self, addr_family, TRUE)) { - _LOGW(LOGD_IPX(IS_IPv4), - "Failed to reapply IPv%c configuration", - nm_utils_addr_family_to_char(addr_family)); - } -} - static void _pacrunner_manager_add(NMDevice *self) { @@ -12629,10 +12385,8 @@ _pacrunner_manager_add(NMDevice *self) nm_pacrunner_manager_remove_clear(&priv->pacrunner_conf_id); priv->pacrunner_conf_id = nm_pacrunner_manager_add(nm_pacrunner_manager_get(), - priv->proxy_config, nm_device_get_ip_iface(self), - NULL, - NULL); + nm_device_get_l3cd(self, TRUE)); } static void @@ -12640,19 +12394,19 @@ reactivate_proxy_config(NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - if (!priv->pacrunner_conf_id) - return; - nm_device_set_proxy_config(self, priv->dhcp4.pac_url); - _pacrunner_manager_add(self); + if (priv->pacrunner_conf_id) + _pacrunner_manager_add(self); } +/*****************************************************************************/ + static gboolean -can_reapply_change(NMDevice * self, +can_reapply_change(NMDevice *self, const char *setting_name, - NMSetting * s_old, - NMSetting * s_new, + NMSetting *s_old, + NMSetting *s_new, GHashTable *diffs, - GError ** error) + GError **error) { if (nm_streq(setting_name, NM_SETTING_CONNECTION_SETTING_NAME)) { /* Whitelist allowed properties from "connection" setting which are @@ -12730,20 +12484,19 @@ reapply_connection(NMDevice *self, NMConnection *con_old, NMConnection *con_new) * Return: %FALSE if the new configuration can not be reapplied. */ static gboolean -check_and_reapply_connection(NMDevice * self, +check_and_reapply_connection(NMDevice *self, NMConnection *connection, guint64 version_id, - char ** audit_args, - GError ** error) -{ - NMDeviceClass * klass = NM_DEVICE_GET_CLASS(self); - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - NMConnection * applied = nm_device_get_applied_connection(self); - gs_unref_object NMConnection *applied_clone = NULL; - gs_unref_hashtable GHashTable *diffs = NULL; - NMConnection * con_old, *con_new; - NMSettingIPConfig * s_ip4_old, *s_ip4_new; - NMSettingIPConfig * s_ip6_old, *s_ip6_new; + char **audit_args, + GError **error) +{ + NMDeviceClass *klass = NM_DEVICE_GET_CLASS(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NMConnection *applied = nm_device_get_applied_connection(self); + gs_unref_object NMConnection *applied_clone = NULL; + gs_unref_hashtable GHashTable *diffs = NULL; + NMConnection *con_old; + NMConnection *con_new; GHashTableIter iter; if (priv->state < NM_DEVICE_STATE_PREPARE || priv->state > NM_DEVICE_STATE_ACTIVATED) { @@ -12771,7 +12524,7 @@ check_and_reapply_connection(NMDevice * self, * check for unsupported changes and reject to reapply *************************************************************************/ if (diffs) { - char * setting_name; + char *setting_name; GHashTable *setting_diff; g_hash_table_iter_init(&iter, diffs); @@ -12792,11 +12545,11 @@ check_and_reapply_connection(NMDevice * self, && version_id != nm_active_connection_version_id_get( (NMActiveConnection *) priv->act_request.obj)) { - g_set_error_literal( - error, - NM_DEVICE_ERROR, - NM_DEVICE_ERROR_VERSION_ID_MISMATCH, - "Reapply failed because device changed in the meantime and the version-id mismatches"); + g_set_error_literal(error, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_VERSION_ID_MISMATCH, + "Reapply failed because device changed in the meantime and the " + "version-id mismatches"); return FALSE; } @@ -12814,7 +12567,7 @@ check_and_reapply_connection(NMDevice * self, diffs ? "" : " (unmodified)"); if (diffs) { - NMConnection * connection_clean = connection; + NMConnection *connection_clean = connection; gs_unref_object NMConnection *connection_clean_free = NULL; { @@ -12859,11 +12612,9 @@ check_and_reapply_connection(NMDevice * self, } else con_old = con_new = applied; - priv->v4_commit_first_time = TRUE; - priv->v6_commit_first_time = TRUE; - priv->v4_route_table_initialized = FALSE; priv->v6_route_table_initialized = FALSE; + priv->l3config_merge_flags_has = FALSE; /************************************************************************** * Reapply changes @@ -12880,20 +12631,21 @@ check_and_reapply_connection(NMDevice * self, lldp_setup(self, NM_TERNARY_DEFAULT); if (priv->state >= NM_DEVICE_STATE_IP_CONFIG) { - s_ip4_old = nm_connection_get_setting_ip4_config(con_old); - s_ip4_new = nm_connection_get_setting_ip4_config(con_new); - s_ip6_old = nm_connection_get_setting_ip6_config(con_old); - s_ip6_new = nm_connection_get_setting_ip6_config(con_new); - /* Allow reapply of MTU */ priv->mtu_source = NM_DEVICE_MTU_SOURCE_NONE; - nm_device_reactivate_ip_config(self, AF_INET, s_ip4_old, s_ip4_new); - nm_device_reactivate_ip_config(self, AF_INET6, s_ip6_old, s_ip6_new); + if (nm_g_hash_table_lookup(diffs, NM_SETTING_IP4_CONFIG_SETTING_NAME)) + priv->ip_data_4.do_reapply = TRUE; + if (nm_g_hash_table_lookup(diffs, NM_SETTING_IP6_CONFIG_SETTING_NAME)) + priv->ip_data_6.do_reapply = TRUE; + + nm_device_activate_schedule_stage3_ip_config(self, FALSE); _routing_rules_sync(self, NM_TERNARY_TRUE); reactivate_proxy_config(self); + + nm_device_l3cfg_commit(self, NM_L3_CFG_COMMIT_TYPE_REAPPLY, FALSE); } if (priv->state >= NM_DEVICE_STATE_IP_CHECK) @@ -12919,17 +12671,17 @@ typedef struct { } ReapplyData; static void -reapply_cb(NMDevice * self, +reapply_cb(NMDevice *self, GDBusMethodInvocation *context, - NMAuthSubject * subject, - GError * error, + NMAuthSubject *subject, + GError *error, gpointer user_data) { - ReapplyData * reapply_data = user_data; - guint64 version_id = 0; - gs_unref_object NMConnection *connection = NULL; - GError * local = NULL; - gs_free char * audit_args = NULL; + ReapplyData *reapply_data = user_data; + guint64 version_id = 0; + gs_unref_object NMConnection *connection = NULL; + GError *local = NULL; + gs_free char *audit_args = NULL; if (reapply_data) { connection = reapply_data->connection; @@ -12972,20 +12724,20 @@ reapply_cb(NMDevice * self, } static void -impl_device_reapply(NMDBusObject * obj, +impl_device_reapply(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * dbus_connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) -{ - NMDevice * self = NM_DEVICE(obj); - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - NMSettingsConnection *settings_connection; - NMConnection * connection = NULL; - GError * error = NULL; - ReapplyData * reapply_data; + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *dbus_connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) +{ + NMDevice *self = NM_DEVICE(obj); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NMSettingsConnection *settings_connection; + NMConnection *connection = NULL; + GError *error = NULL; + ReapplyData *reapply_data; gs_unref_variant GVariant *settings = NULL; guint64 version_id; guint32 flags; @@ -13063,20 +12815,20 @@ impl_device_reapply(NMDBusObject * obj, /*****************************************************************************/ static void -impl_device_get_applied_connection(NMDBusObject * obj, +impl_device_get_applied_connection(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) -{ - NMDevice * self = NM_DEVICE(obj); - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) +{ + NMDevice *self = NM_DEVICE(obj); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); gs_free_error GError *error = NULL; - NMConnection * applied_connection; + NMConnection *applied_connection; guint32 flags; - GVariant * var_settings; + GVariant *var_settings; g_variant_get(parameters, "(u)", &flags); @@ -13123,105 +12875,15 @@ impl_device_get_applied_connection(NMDBusObject * obj, /*****************************************************************************/ -typedef struct { - gint64 timestamp_ms; - bool dirty; -} IP6RoutesTemporaryNotAvailableData; - -static gboolean -_rt6_temporary_not_available_timeout(gpointer user_data) -{ - NMDevice * self = NM_DEVICE(user_data); - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - - priv->rt6_temporary_not_available_id = 0; - nm_device_activate_schedule_ip_config_result(self, AF_INET6, NULL); - - return G_SOURCE_REMOVE; -} - -static gboolean -_rt6_temporary_not_available_set(NMDevice *self, GPtrArray *temporary_not_available) -{ - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - IP6RoutesTemporaryNotAvailableData *data; - GHashTableIter iter; - gint64 now_ms, oldest_ms; - const gint64 MAX_AGE_MS = 20000; - guint i; - gboolean success = TRUE; - - if (!temporary_not_available || !temporary_not_available->len) { - /* nothing outstanding. Clear tracking the routes. */ - nm_clear_pointer(&priv->rt6_temporary_not_available, g_hash_table_unref); - nm_clear_g_source(&priv->rt6_temporary_not_available_id); - return success; - } - - if (priv->rt6_temporary_not_available) { - g_hash_table_iter_init(&iter, priv->rt6_temporary_not_available); - while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &data)) - data->dirty = TRUE; - } else { - priv->rt6_temporary_not_available = - g_hash_table_new_full((GHashFunc) nmp_object_id_hash, - (GEqualFunc) nmp_object_id_equal, - (GDestroyNotify) nmp_object_unref, - nm_g_slice_free_fcn(IP6RoutesTemporaryNotAvailableData)); - } - - now_ms = nm_utils_get_monotonic_timestamp_msec(); - oldest_ms = now_ms; - - for (i = 0; i < temporary_not_available->len; i++) { - const NMPObject *o = temporary_not_available->pdata[i]; - - data = g_hash_table_lookup(priv->rt6_temporary_not_available, o); - if (data) { - if (!data->dirty) - continue; - data->dirty = FALSE; - nm_assert(data->timestamp_ms > 0 && data->timestamp_ms <= now_ms); - if (now_ms > data->timestamp_ms + MAX_AGE_MS) { - /* timeout. Could not add this address. */ - _LOGW(LOGD_DEVICE, - "failure to add IPv6 route: %s", - nmp_object_to_string(o, NMP_OBJECT_TO_STRING_PUBLIC, NULL, 0)); - success = FALSE; - } else - oldest_ms = MIN(data->timestamp_ms, oldest_ms); - continue; - } - - data = g_slice_new0(IP6RoutesTemporaryNotAvailableData); - data->timestamp_ms = now_ms; - g_hash_table_insert(priv->rt6_temporary_not_available, (gpointer) nmp_object_ref(o), data); - } - - g_hash_table_iter_init(&iter, priv->rt6_temporary_not_available); - while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &data)) { - if (data->dirty) - g_hash_table_iter_remove(&iter); - } - - nm_clear_g_source(&priv->rt6_temporary_not_available_id); - priv->rt6_temporary_not_available_id = - g_timeout_add(oldest_ms + MAX_AGE_MS - now_ms, _rt6_temporary_not_available_timeout, self); - - return success; -} - -/*****************************************************************************/ - static void -disconnect_cb(NMDevice * self, +disconnect_cb(NMDevice *self, GDBusMethodInvocation *context, - NMAuthSubject * subject, - GError * error, + NMAuthSubject *subject, + GError *error, gpointer user_data) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - GError * local = NULL; + GError *local = NULL; if (error) { g_dbus_method_invocation_return_gerror(context, error); @@ -13269,17 +12931,17 @@ _clear_queued_act_request(NMDevicePrivate *priv, NMActiveConnectionStateReason a } static void -impl_device_disconnect(NMDBusObject * obj, +impl_device_disconnect(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * dbus_connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *dbus_connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMDevice * self = NM_DEVICE(obj); + NMDevice *self = NM_DEVICE(obj); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - NMConnection * connection; + NMConnection *connection; if (!priv->act_request.obj) { g_dbus_method_invocation_return_error_literal(invocation, @@ -13303,10 +12965,10 @@ impl_device_disconnect(NMDBusObject * obj, } static void -delete_cb(NMDevice * self, +delete_cb(NMDevice *self, GDBusMethodInvocation *context, - NMAuthSubject * subject, - GError * error, + NMAuthSubject *subject, + GError *error, gpointer user_data) { GError *local = NULL; @@ -13331,13 +12993,13 @@ delete_cb(NMDevice * self, } static void -impl_device_delete(NMDBusObject * obj, +impl_device_delete(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { NMDevice *self = NM_DEVICE(obj); @@ -13428,7 +13090,7 @@ static gboolean _carrier_wait_check_act_request_must_queue(NMDevice *self, NMActRequest *req) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - NMConnection * connection; + NMConnection *connection; /* If we have carrier or if we are not waiting for it, the activation * request is not blocked waiting for carrier. */ @@ -13477,11 +13139,11 @@ _carrier_wait_check_act_request_must_queue(NMDevice *self, NMActRequest *req) } void -nm_device_disconnect_active_connection(NMActiveConnection * active, +nm_device_disconnect_active_connection(NMActiveConnection *active, NMDeviceStateReason device_reason, NMActiveConnectionStateReason active_reason) { - NMDevice * self; + NMDevice *self; NMDevicePrivate *priv; g_return_if_fail(NM_IS_ACTIVE_CONNECTION(active)); @@ -13530,386 +13192,106 @@ nm_device_queue_activation(NMDevice *self, NMActRequest *req) g_return_if_fail(NM_IS_DEVICE(self)); g_return_if_fail(NM_IS_ACT_REQUEST(req)); - nm_keep_alive_arm(nm_active_connection_get_keep_alive(NM_ACTIVE_CONNECTION(req))); - - if (nm_active_connection_get_state(NM_ACTIVE_CONNECTION(req)) - >= NM_ACTIVE_CONNECTION_STATE_DEACTIVATING) { - /* it's already deactivating. Nothing to do. */ - nm_assert( - NM_IN_SET(nm_active_connection_get_device(NM_ACTIVE_CONNECTION(req)), NULL, self)); - return; - } - - nm_assert(self == nm_active_connection_get_device(NM_ACTIVE_CONNECTION(req))); - - priv = NM_DEVICE_GET_PRIVATE(self); - - must_queue = _carrier_wait_check_act_request_must_queue(self, req); - - if (!priv->act_request.obj && !must_queue && nm_device_is_real(self)) { - _device_activate(self, req); - return; - } - - /* supersede any already-queued request */ - _clear_queued_act_request(priv, NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED); - priv->queued_act_request = g_object_ref(req); - priv->queued_act_request_is_waiting_for_carrier = must_queue; - - _LOGD(LOGD_DEVICE, - "queue activation request waiting for %s", - must_queue ? "carrier" : "currently active connection to disconnect"); - - /* Deactivate existing activation request first */ - if (priv->act_request.obj) { - _LOGI(LOGD_DEVICE, "disconnecting for new activation request."); - nm_device_state_changed(self, - NM_DEVICE_STATE_DEACTIVATING, - NM_DEVICE_STATE_REASON_NEW_ACTIVATION); - } -} - -/* - * nm_device_is_activating - * - * Return whether or not the device is currently activating itself. - * - */ -gboolean -nm_device_is_activating(NMDevice *self) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - NMDeviceState state; - - g_return_val_if_fail(NM_IS_DEVICE(self), FALSE); - - state = nm_device_get_state(self); - if (state >= NM_DEVICE_STATE_PREPARE && state <= NM_DEVICE_STATE_SECONDARIES) - return TRUE; - - /* There's a small race between the time when stage 1 is scheduled - * and when the device actually sets STATE_PREPARE when the activation - * handler is actually run. If there's an activation handler scheduled - * we're activating anyway. - */ - return priv->activation_source_id_4 != 0; -} - -NMProxyConfig * -nm_device_get_proxy_config(NMDevice *self) -{ - g_return_val_if_fail(NM_IS_DEVICE(self), NULL); - - return NM_DEVICE_GET_PRIVATE(self)->proxy_config; -} - -static void -nm_device_set_proxy_config(NMDevice *self, const char *pac_url) -{ - NMDevicePrivate *priv; - NMConnection * connection; - NMSettingProxy * s_proxy = NULL; - - g_return_if_fail(NM_IS_DEVICE(self)); - - priv = NM_DEVICE_GET_PRIVATE(self); - - g_clear_object(&priv->proxy_config); - priv->proxy_config = nm_proxy_config_new(); - - if (pac_url) { - nm_proxy_config_set_method(priv->proxy_config, NM_PROXY_CONFIG_METHOD_AUTO); - nm_proxy_config_set_pac_url(priv->proxy_config, pac_url); - _LOGD(LOGD_PROXY, "proxy: PAC url \"%s\"", pac_url); - } else - nm_proxy_config_set_method(priv->proxy_config, NM_PROXY_CONFIG_METHOD_NONE); - - connection = nm_device_get_applied_connection(self); - if (connection) - s_proxy = nm_connection_get_setting_proxy(connection); - - if (s_proxy) - nm_proxy_config_merge_setting(priv->proxy_config, s_proxy); -} - -/* IP Configuration stuff */ -NMDhcpConfig * -nm_device_get_dhcp_config(NMDevice *self, int addr_family) -{ - const int IS_IPv4 = NM_IS_IPv4(addr_family); - - g_return_val_if_fail(NM_IS_DEVICE(self), NULL); - - nm_assert_addr_family(addr_family); - - return NM_DEVICE_GET_PRIVATE(self)->dhcp_data_x[IS_IPv4].config; -} - -NMIP4Config * -nm_device_get_ip4_config(NMDevice *self) -{ - g_return_val_if_fail(NM_IS_DEVICE(self), NULL); - - return NM_DEVICE_GET_PRIVATE(self)->ip_config_4; -} - -static gboolean -nm_device_set_ip_config(NMDevice * self, - int addr_family, - NMIPConfig *new_config, - gboolean commit, - GPtrArray * ip4_dev_route_blacklist) -{ - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - const int IS_IPv4 = NM_IS_IPv4(addr_family); - NMIPConfig * old_config; - gboolean has_changes = FALSE; - gboolean success = TRUE; - NMSettingsConnection * settings_connection; - NMIPRouteTableSyncMode route_table_sync_mode; - - nm_assert_addr_family(addr_family); - nm_assert(!new_config || nm_ip_config_get_addr_family(new_config) == addr_family); - nm_assert(!new_config - || (new_config && ({ - int ip_ifindex = nm_device_get_ip_ifindex(self); - - (ip_ifindex > 0 && ip_ifindex == nm_ip_config_get_ifindex(new_config)); - }))); - nm_assert(IS_IPv4 || !ip4_dev_route_blacklist); - - if (commit && new_config) - route_table_sync_mode = _get_route_table_sync_mode_stateful(self, addr_family); - else - route_table_sync_mode = NM_IP_ROUTE_TABLE_SYNC_MODE_NONE; - - _LOGD(LOGD_IPX(IS_IPv4), - "ip%c-config: update (commit=%d, new-config=" NM_HASH_OBFUSCATE_PTR_FMT - ", route-table-sync-mode=%d)", - nm_utils_addr_family_to_char(addr_family), - commit, - NM_HASH_OBFUSCATE_PTR(new_config), - (int) route_table_sync_mode); - - /* Always commit to nm-platform to update lifetimes */ - if (commit && new_config) { - _commit_mtu(self, IS_IPv4 ? NM_IP4_CONFIG(new_config) : priv->ip_config_4); - - if (IS_IPv4) { - success = nm_ip4_config_commit(NM_IP4_CONFIG(new_config), - nm_device_get_platform(self), - route_table_sync_mode); - nm_platform_ip4_dev_route_blacklist_set(nm_device_get_platform(self), - nm_ip_config_get_ifindex(new_config), - ip4_dev_route_blacklist); - } else { - gs_unref_ptrarray GPtrArray *temporary_not_available = NULL; - - success = nm_ip6_config_commit(NM_IP6_CONFIG(new_config), - nm_device_get_platform(self), - route_table_sync_mode, - &temporary_not_available); - - if (!_rt6_temporary_not_available_set(self, temporary_not_available)) - success = FALSE; - } - } - - old_config = priv->ip_config_x[IS_IPv4]; - - if (new_config && old_config) { - /* has_changes is set only on relevant changes, because when the configuration changes, - * this causes a re-read and reset. This should only happen for relevant changes */ - nm_ip_config_replace(old_config, new_config, &has_changes); - if (has_changes) { - _LOGD(LOGD_IPX(IS_IPv4), - "ip%c-config: update IP Config instance (%s)", - nm_utils_addr_family_to_char(addr_family), - nm_dbus_object_get_path(NM_DBUS_OBJECT(old_config))); - } - } else if (new_config /*&& !old_config*/) { - has_changes = TRUE; - priv->ip_config_x[IS_IPv4] = g_object_ref(new_config); - if (!nm_dbus_object_is_exported(NM_DBUS_OBJECT(new_config))) - nm_dbus_object_export(NM_DBUS_OBJECT(new_config)); - - _LOGD(LOGD_IPX(IS_IPv4), - "ip%c-config: set IP Config instance (%s)", - nm_utils_addr_family_to_char(addr_family), - nm_dbus_object_get_path(NM_DBUS_OBJECT(new_config))); - } else if (old_config /*&& !new_config*/) { - has_changes = TRUE; - priv->ip_config_x[IS_IPv4] = NULL; - _LOGD(LOGD_IPX(IS_IPv4), - "ip%c-config: clear IP Config instance (%s)", - nm_utils_addr_family_to_char(addr_family), - nm_dbus_object_get_path(NM_DBUS_OBJECT(old_config))); - if (IS_IPv4) { - /* Device config is invalid if combined config is invalid */ - applied_config_clear(&priv->dev_ip_config_4); - } else - priv->needs_ip6_subnet = FALSE; - } - - if (has_changes) { - if (old_config != priv->ip_config_x[IS_IPv4]) - _notify(self, IS_IPv4 ? PROP_IP4_CONFIG : PROP_IP6_CONFIG); - - g_signal_emit(self, - signals[IS_IPv4 ? IP4_CONFIG_CHANGED : IP6_CONFIG_CHANGED], - 0, - priv->ip_config_x[IS_IPv4], - old_config); - - if (old_config != priv->ip_config_x[IS_IPv4]) - nm_dbus_object_clear_and_unexport(&old_config); - - if (nm_device_sys_iface_state_is_external(self) - && (settings_connection = nm_device_get_settings_connection(self)) - && NM_FLAGS_HAS(nm_settings_connection_get_flags(settings_connection), - NM_SETTINGS_CONNECTION_INT_FLAGS_EXTERNAL) - && nm_active_connection_get_activation_type(NM_ACTIVE_CONNECTION(priv->act_request.obj)) - == NM_ACTIVATION_TYPE_EXTERNAL) { - gs_unref_object NMConnection *new_connection = NULL; - - new_connection = nm_simple_connection_new_clone( - nm_settings_connection_get_connection(settings_connection)); - - nm_connection_add_setting( - new_connection, - IS_IPv4 ? nm_ip4_config_create_setting(priv->ip_config_4) - : nm_ip6_config_create_setting(priv->ip_config_6, - _get_maybe_ipv6_disabled(self))); - - nm_settings_connection_update(settings_connection, - new_connection, - NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY, - NM_SETTINGS_CONNECTION_INT_FLAGS_NONE, - NM_SETTINGS_CONNECTION_INT_FLAGS_NONE, - NM_SETTINGS_CONNECTION_UPDATE_REASON_UPDATE_NON_SECRET, - "update-external", - NULL); - } - - nm_device_queue_recheck_assume(self); + nm_keep_alive_arm(nm_active_connection_get_keep_alive(NM_ACTIVE_CONNECTION(req))); - if (!IS_IPv4) { - if (priv->ndisc) - ndisc_set_router_config(priv->ndisc, self); - } + if (nm_active_connection_get_state(NM_ACTIVE_CONNECTION(req)) + >= NM_ACTIVE_CONNECTION_STATE_DEACTIVATING) { + /* it's already deactivating. Nothing to do. */ + nm_assert( + NM_IN_SET(nm_active_connection_get_device(NM_ACTIVE_CONNECTION(req)), NULL, self)); + return; } - nm_assert(!old_config || old_config == priv->ip_config_x[IS_IPv4]); - - return success; -} + nm_assert(self == nm_active_connection_get_device(NM_ACTIVE_CONNECTION(req))); -static gboolean -_replace_vpn_config_in_list(GSList **plist, GObject *old, GObject *new) -{ - GSList *old_link; + priv = NM_DEVICE_GET_PRIVATE(self); - /* Below, assert that @new is not yet tracked, but still behave - * correctly in any case. Don't complain for missing @old since - * it could have been removed when the parent device became - * unmanaged. */ + must_queue = _carrier_wait_check_act_request_must_queue(self, req); - if (old && (old_link = g_slist_find(*plist, old))) { - if (old != new) { - if (new) - old_link->data = g_object_ref(new); - else - *plist = g_slist_delete_link(*plist, old_link); - g_object_unref(old); - } - return TRUE; + if (!priv->act_request.obj && !must_queue && nm_device_is_real(self)) { + _device_activate(self, req); + return; } - if (new) { - if (!g_slist_find(*plist, new)) - *plist = g_slist_append(*plist, g_object_ref(new)); - else - g_return_val_if_reached(TRUE); - return TRUE; - } + /* supersede any already-queued request */ + _clear_queued_act_request(priv, NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED); + priv->queued_act_request = g_object_ref(req); + priv->queued_act_request_is_waiting_for_carrier = must_queue; - return FALSE; + _LOGD(LOGD_DEVICE, + "queue activation request waiting for %s", + must_queue ? "carrier" : "currently active connection to disconnect"); + + /* Deactivate existing activation request first */ + if (priv->act_request.obj) { + _LOGI(LOGD_DEVICE, "disconnecting for new activation request."); + nm_device_state_changed(self, + NM_DEVICE_STATE_DEACTIVATING, + NM_DEVICE_STATE_REASON_NEW_ACTIVATION); + } } -void -nm_device_replace_vpn4_config(NMDevice *self, NMIP4Config *old, NMIP4Config *config) +/* + * nm_device_is_activating + * + * Return whether or not the device is currently activating itself. + * + */ +gboolean +nm_device_is_activating(NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NMDeviceState state; - nm_assert(!old || NM_IS_IP4_CONFIG(old)); - nm_assert(!config || NM_IS_IP4_CONFIG(config)); - nm_assert(!old || nm_ip4_config_get_ifindex(old) == nm_device_get_ip_ifindex(self)); - nm_assert(!config || nm_ip4_config_get_ifindex(config) == nm_device_get_ip_ifindex(self)); + g_return_val_if_fail(NM_IS_DEVICE(self), FALSE); - if (!_replace_vpn_config_in_list(&priv->vpn_configs_4, (GObject *) old, (GObject *) config)) - return; + state = nm_device_get_state(self); + if (state >= NM_DEVICE_STATE_PREPARE && state <= NM_DEVICE_STATE_SECONDARIES) + return TRUE; - /* NULL to use existing configs */ - if (!ip_config_merge_and_apply(self, AF_INET, TRUE)) - _LOGW(LOGD_IP4, "failed to set VPN routes for device"); + /* There's a small race between the time when stage 1 is scheduled + * and when the device actually sets STATE_PREPARE when the activation + * handler is actually run. If there's an activation handler scheduled + * we're activating anyway. + */ + return !!priv->activation_idle_source; } -void -nm_device_set_dev2_ip_config(NMDevice *self, int addr_family, NMIPConfig *config) +NMDhcpConfig * +nm_device_get_dhcp_config(NMDevice *self, int addr_family) { - NMDevicePrivate *priv; - const int IS_IPv4 = NM_IS_IPv4(addr_family); - - g_return_if_fail(NM_IS_DEVICE(self)); - g_return_if_fail(NM_IN_SET(addr_family, AF_INET, AF_INET6)); - g_return_if_fail(!config || nm_ip_config_get_addr_family(config) == addr_family); - - priv = NM_DEVICE_GET_PRIVATE(self); + g_return_val_if_fail(NM_IS_DEVICE(self), NULL); - applied_config_init(&priv->dev2_ip_config_x[IS_IPv4], config); - if (!ip_config_merge_and_apply(self, addr_family, TRUE)) { - _LOGW(LOGD_IP, - "failed to set extra device IPv%c configuration", - nm_utils_addr_family_to_char(addr_family)); - } + return NM_DEVICE_GET_PRIVATE(self)->ipdhcp_data_x[NM_IS_IPv4(addr_family)].config; } -void -nm_device_replace_vpn6_config(NMDevice *self, NMIP6Config *old, NMIP6Config *config) +NML3Cfg * +nm_device_get_l3cfg(NMDevice *self) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - NMDeviceState state; - - nm_assert(!old || NM_IS_IP6_CONFIG(old)); - nm_assert(!old || nm_ip6_config_get_ifindex(old) > 0); - nm_assert(!old || nm_device_get_ip_ifindex(self) == 0 - || nm_device_get_ip_ifindex(self) == nm_ip6_config_get_ifindex(old)); - nm_assert(!config || NM_IS_IP6_CONFIG(config)); - nm_assert(!config || nm_ip6_config_get_ifindex(config) > 0); - nm_assert(!config || nm_device_get_ip_ifindex(self) == nm_ip6_config_get_ifindex(config)); - - if (!_replace_vpn_config_in_list(&priv->vpn_configs_6, (GObject *) old, (GObject *) config)) - return; + g_return_val_if_fail(NM_IS_DEVICE(self), NULL); - state = nm_device_get_state(self); - if (state >= NM_DEVICE_STATE_IP_CONFIG && state <= NM_DEVICE_STATE_ACTIVATED) { - if (!ip_config_merge_and_apply(self, AF_INET6, TRUE)) - _LOGW(LOGD_IP6, "failed to set VPN routes for device"); - } + return NM_DEVICE_GET_PRIVATE(self)->l3cfg; } -NMIP6Config * -nm_device_get_ip6_config(NMDevice *self) +const NML3ConfigData * +nm_device_get_l3cd(NMDevice *self, gboolean get_commited) { + NMDevicePrivate *priv; + g_return_val_if_fail(NM_IS_DEVICE(self), NULL); - return NM_DEVICE_GET_PRIVATE(self)->ip_config_6; + priv = NM_DEVICE_GET_PRIVATE(self); + + if (!priv->l3cfg) + return NULL; + + return nm_l3cfg_get_combined_l3cd(priv->l3cfg, get_commited); } /*****************************************************************************/ static gboolean -dispatcher_cleanup(NMDevice *self) +_dispatcher_cleanup(NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); @@ -13923,9 +13305,9 @@ dispatcher_cleanup(NMDevice *self) } static void -dispatcher_complete_proceed_state(NMDispatcherCallId *call_id, gpointer user_data) +_dispatcher_complete_proceed_state(NMDispatcherCallId *call_id, gpointer user_data) { - NMDevice * self = NM_DEVICE(user_data); + NMDevice *self = NM_DEVICE(user_data); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); g_return_if_fail(call_id == priv->dispatcher.call_id); @@ -13943,7 +13325,7 @@ ip_check_pre_up(NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - if (dispatcher_cleanup(self)) + if (_dispatcher_cleanup(self)) nm_assert_not_reached(); priv->dispatcher.post_state = NM_DEVICE_STATE_SECONDARIES; @@ -13951,11 +13333,11 @@ ip_check_pre_up(NMDevice *self) if (!nm_dispatcher_call_device(NM_DISPATCHER_ACTION_PRE_UP, self, NULL, - dispatcher_complete_proceed_state, + _dispatcher_complete_proceed_state, self, &priv->dispatcher.call_id)) { /* Just proceed on errors */ - dispatcher_complete_proceed_state(0, self); + _dispatcher_complete_proceed_state(0, self); } } @@ -13985,10 +13367,10 @@ ip_check_gw_ping_cleanup(NMDevice *self) static gboolean spawn_ping(NMDevice *self) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - gs_free char * str_timeout = NULL; - gs_free char * tmp_str = NULL; - const char * args[] = {priv->gw_ping.binary, + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + gs_free char *str_timeout = NULL; + gs_free char *tmp_str = NULL; + const char *args[] = {priv->gw_ping.binary, "-I", nm_device_get_ip_iface(self), "-c", @@ -13997,7 +13379,7 @@ spawn_ping(NMDevice *self) NULL, priv->gw_ping.address, NULL}; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; gboolean ret; args[6] = str_timeout = g_strdup_printf("%u", priv->gw_ping.deadline); @@ -14026,7 +13408,7 @@ spawn_ping(NMDevice *self) static gboolean respawn_ping_cb(gpointer user_data) { - NMDevice * self = NM_DEVICE(user_data); + NMDevice *self = NM_DEVICE(user_data); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); priv->gw_ping.watch = 0; @@ -14044,7 +13426,7 @@ respawn_ping_cb(gpointer user_data) static void ip_check_ping_watch_cb(GPid pid, int status, gpointer user_data) { - NMDevice * self = NM_DEVICE(user_data); + NMDevice *self = NM_DEVICE(user_data); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); NMLogDomain log_domain = priv->gw_ping.log_domain; gboolean success = FALSE; @@ -14078,7 +13460,7 @@ ip_check_ping_watch_cb(GPid pid, int status, gpointer user_data) static gboolean ip_check_ping_timeout_cb(gpointer user_data) { - NMDevice * self = NM_DEVICE(user_data); + NMDevice *self = NM_DEVICE(user_data); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); priv->gw_ping.timeout = 0; @@ -14091,7 +13473,7 @@ ip_check_ping_timeout_cb(gpointer user_data) } static gboolean -start_ping(NMDevice * self, +start_ping(NMDevice *self, NMLogDomain log_domain, const char *binary, const char *address, @@ -14120,11 +13502,11 @@ start_ping(NMDevice * self, static void nm_device_start_ip_check(NMDevice *self) { - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - NMConnection * connection; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NMConnection *connection; NMSettingConnection *s_con; guint timeout = 0; - const char * ping_binary = NULL; + const char *ping_binary = NULL; char buf[NM_UTILS_INET_ADDRSTRLEN]; NMLogDomain log_domain = LOGD_IP4; @@ -14135,8 +13517,8 @@ nm_device_start_ip_check(NMDevice *self) g_return_if_fail(!priv->gw_ping.watch); g_return_if_fail(!priv->gw_ping.timeout); g_return_if_fail(!priv->gw_ping.pid); - g_return_if_fail(priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE - || priv->ip_state_6 == NM_DEVICE_IP_STATE_DONE); + g_return_if_fail(priv->ip_data_4.state == NM_DEVICE_IP_STATE_READY + || priv->ip_data_6.state == NM_DEVICE_IP_STATE_READY); connection = nm_device_get_applied_connection(self); g_assert(connection); @@ -14147,17 +13529,21 @@ nm_device_start_ip_check(NMDevice *self) buf[0] = '\0'; if (timeout) { - const NMPObject *gw; + const NMPObject *gw; + const NML3ConfigData *l3cd; - if (priv->ip_config_4 && priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE) { - gw = nm_ip4_config_best_default_route_get(priv->ip_config_4); + l3cd = priv->l3cfg ? nm_l3cfg_get_combined_l3cd(priv->l3cfg, TRUE) : NULL; + if (!l3cd) { + /* pass */ + } else if (priv->ip_data_4.state == NM_DEVICE_IP_STATE_READY) { + gw = nm_l3_config_data_get_best_default_route(l3cd, AF_INET); if (gw) { _nm_utils_inet4_ntop(NMP_OBJECT_CAST_IP4_ROUTE(gw)->gateway, buf); ping_binary = nm_utils_find_helper("ping", "/usr/bin/ping", NULL); log_domain = LOGD_IP4; } - } else if (priv->ip_config_6 && priv->ip_state_6 == NM_DEVICE_IP_STATE_DONE) { - gw = nm_ip6_config_best_default_route_get(priv->ip_config_6); + } else if (priv->ip_data_6.state == NM_DEVICE_IP_STATE_READY) { + gw = nm_l3_config_data_get_best_default_route(l3cd, AF_INET6); if (gw) { _nm_utils_inet6_ntop(&NMP_OBJECT_CAST_IP6_ROUTE(gw)->gateway, buf); ping_binary = nm_utils_find_helper("ping6", "/usr/bin/ping6", NULL); @@ -14179,7 +13565,7 @@ nm_device_start_ip_check(NMDevice *self) static gboolean carrier_wait_timeout(gpointer user_data) { - NMDevice * self = NM_DEVICE(user_data); + NMDevice *self = NM_DEVICE(user_data); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); priv->carrier_wait_id = 0; @@ -14216,7 +13602,7 @@ _get_carrier_wait_ms(NMDevice *self) gboolean nm_device_bring_up(NMDevice *self, gboolean block, gboolean *no_firmware) { - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); gboolean device_is_up = FALSE; NMDeviceCapabilities capabilities; int ifindex; @@ -14274,475 +13660,92 @@ nm_device_bring_up(NMDevice *self, gboolean block, gboolean *no_firmware) /* Devices that support carrier detect must be IFF_UP to report carrier * changes; so after setting the device IFF_UP we must suppress startup - * complete (via a pending action) until either the carrier turns on, or - * a timeout is reached. - */ - if (nm_device_has_capability(self, NM_DEVICE_CAP_CARRIER_DETECT)) { - gint64 now_ms, until_ms; - - /* we start a grace period of 5 seconds during which we will schedule - * a pending action whenever we have no carrier. - * - * If during that time carrier goes away, we declare the interface - * as not ready. */ - nm_clear_g_source(&priv->carrier_wait_id); - if (!priv->carrier) - nm_device_add_pending_action(self, NM_PENDING_ACTION_CARRIER_WAIT, FALSE); - - now_ms = nm_utils_get_monotonic_timestamp_msec(); - until_ms = NM_MAX(now_ms + _get_carrier_wait_ms(self), priv->carrier_wait_until_ms); - priv->carrier_wait_id = g_timeout_add(until_ms - now_ms, carrier_wait_timeout, self); - } - - /* Can only get HW address of some devices when they are up */ - nm_device_update_hw_address(self); - - /* when the link comes up, we must restore IP configuration if necessary. */ - if (priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE) { - if (!ip_config_merge_and_apply(self, AF_INET, TRUE)) - _LOGW(LOGD_IP4, "failed applying IP4 config after bringing link up"); - } - if (priv->ip_state_6 == NM_DEVICE_IP_STATE_DONE) { - if (!ip_config_merge_and_apply(self, AF_INET6, TRUE)) - _LOGW(LOGD_IP6, "failed applying IP6 config after bringing link up"); - } - - return TRUE; -} - -void -nm_device_take_down(NMDevice *self, gboolean block) -{ - int ifindex; - gboolean device_is_up; - - g_return_if_fail(NM_IS_DEVICE(self)); - - ifindex = nm_device_get_ip_ifindex(self); - _LOGD(LOGD_PLATFORM, "taking down device %d", ifindex); - if (ifindex <= 0) { - /* devices without ifindex are always up. */ - return; - } - - if (!nm_platform_link_change_flags(nm_device_get_platform(self), ifindex, IFF_UP, FALSE)) - return; - - device_is_up = nm_device_is_up(self); - if (block && device_is_up) { - gint64 wait_until = nm_utils_get_monotonic_timestamp_usec() + 10000 /* microseconds */; - - do { - g_usleep(200); - if (!nm_platform_link_refresh(nm_device_get_platform(self), ifindex)) - return; - device_is_up = nm_device_is_up(self); - } while (device_is_up && nm_utils_get_monotonic_timestamp_usec() < wait_until); - } - - if (device_is_up) { - if (block) - _LOGW(LOGD_PLATFORM, "device not down after timeout!"); - else - _LOGD(LOGD_PLATFORM, "device not down immediately"); - } -} - -void -nm_device_set_firmware_missing(NMDevice *self, gboolean new_missing) -{ - NMDevicePrivate *priv; - - g_return_if_fail(NM_IS_DEVICE(self)); - - priv = NM_DEVICE_GET_PRIVATE(self); - if (priv->firmware_missing != new_missing) { - priv->firmware_missing = new_missing; - _notify(self, PROP_FIRMWARE_MISSING); - } -} - -gboolean -nm_device_get_firmware_missing(NMDevice *self) -{ - return NM_DEVICE_GET_PRIVATE(self)->firmware_missing; -} - -static void -intersect_ext_config(NMDevice * self, - AppliedConfig *config, - gboolean intersect_addresses, - gboolean intersect_routes) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - NMIPConfig * ext; - guint32 penalty; - int family; - - if (!config->orig) - return; - - family = nm_ip_config_get_addr_family(config->orig); - penalty = default_route_metric_penalty_get(self, family); - ext = family == AF_INET ? (NMIPConfig *) priv->ext_ip_config_4 - : (NMIPConfig *) priv->ext_ip_config_6; - - if (config->current) { - nm_ip_config_intersect(config->current, - ext, - intersect_addresses, - intersect_routes, - penalty); - } else { - config->current = nm_ip_config_intersect_alloc(config->orig, - ext, - intersect_addresses, - intersect_routes, - penalty); - } -} - -static gboolean -update_ext_ip_config(NMDevice *self, int addr_family, gboolean intersect_configs) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - int ifindex; - GSList * iter; - gboolean is_up; - - nm_assert_addr_family(addr_family); - - ifindex = nm_device_get_ip_ifindex(self); - if (!ifindex) - return FALSE; - - is_up = nm_platform_link_is_up(nm_device_get_platform(self), ifindex); - - if (NM_IS_IPv4(addr_family)) { - g_clear_object(&priv->ext_ip_config_4); - priv->ext_ip_config_4 = nm_ip4_config_capture(nm_device_get_multi_index(self), - nm_device_get_platform(self), - ifindex); - if (priv->ext_ip_config_4) { - if (intersect_configs) { - /* This function was called upon external changes. Remove the configuration - * (addresses,routes) that is no longer present externally from the internal - * config. This way, we don't re-add addresses that were manually removed - * by the user. */ - if (priv->con_ip_config_4) { - nm_ip4_config_intersect(priv->con_ip_config_4, - priv->ext_ip_config_4, - TRUE, - is_up, - default_route_metric_penalty_get(self, AF_INET)); - } - - intersect_ext_config(self, &priv->dev_ip_config_4, TRUE, is_up); - intersect_ext_config(self, &priv->dev2_ip_config_4, TRUE, is_up); - - for (iter = priv->vpn_configs_4; iter; iter = iter->next) - nm_ip4_config_intersect(iter->data, priv->ext_ip_config_4, TRUE, is_up, 0); - } - - /* Remove parts from ext_ip_config_4 to only contain the information that - * was configured externally -- we already have the same configuration from - * internal origins. */ - if (priv->con_ip_config_4) { - nm_ip4_config_subtract(priv->ext_ip_config_4, - priv->con_ip_config_4, - default_route_metric_penalty_get(self, AF_INET)); - } - if (applied_config_get_current(&priv->dev_ip_config_4)) { - nm_ip_config_subtract((NMIPConfig *) priv->ext_ip_config_4, - applied_config_get_current(&priv->dev_ip_config_4), - default_route_metric_penalty_get(self, AF_INET)); - } - if (applied_config_get_current(&priv->dev2_ip_config_4)) { - nm_ip_config_subtract((NMIPConfig *) priv->ext_ip_config_4, - applied_config_get_current(&priv->dev2_ip_config_4), - default_route_metric_penalty_get(self, AF_INET)); - } - for (iter = priv->vpn_configs_4; iter; iter = iter->next) - nm_ip4_config_subtract(priv->ext_ip_config_4, iter->data, 0); - } - - } else { - nm_assert(!NM_IS_IPv4(addr_family)); - - g_clear_object(&priv->ext_ip_config_6); - g_clear_object(&priv->ext_ip6_config_captured); - priv->ext_ip6_config_captured = - nm_ip6_config_capture(nm_device_get_multi_index(self), - nm_device_get_platform(self), - ifindex, - NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN); - if (priv->ext_ip6_config_captured) { - priv->ext_ip_config_6 = nm_ip6_config_new_cloned(priv->ext_ip6_config_captured); - - if (intersect_configs) { - /* This function was called upon external changes. Remove the configuration - * (addresses,routes) that is no longer present externally from the internal - * config. This way, we don't re-add addresses that were manually removed - * by the user. */ - if (priv->con_ip_config_6) { - nm_ip6_config_intersect(priv->con_ip_config_6, - priv->ext_ip_config_6, - is_up, - is_up, - default_route_metric_penalty_get(self, AF_INET6)); - } - - intersect_ext_config(self, &priv->ac_ip6_config, is_up, is_up); - intersect_ext_config(self, &priv->dhcp6.ip6_config, is_up, is_up); - intersect_ext_config(self, &priv->dev2_ip_config_6, is_up, is_up); - - for (iter = priv->vpn_configs_6; iter; iter = iter->next) - nm_ip6_config_intersect(iter->data, priv->ext_ip_config_6, is_up, is_up, 0); - - if (is_up && priv->ipv6ll_has - && !nm_ip6_config_lookup_address(priv->ext_ip_config_6, &priv->ipv6ll_addr)) - priv->ipv6ll_has = FALSE; - } - - /* Remove parts from ext_ip_config_6 to only contain the information that - * was configured externally -- we already have the same configuration from - * internal origins. */ - if (priv->con_ip_config_6) { - nm_ip6_config_subtract(priv->ext_ip_config_6, - priv->con_ip_config_6, - default_route_metric_penalty_get(self, AF_INET6)); - } - if (applied_config_get_current(&priv->ac_ip6_config)) { - nm_ip_config_subtract((NMIPConfig *) priv->ext_ip_config_6, - applied_config_get_current(&priv->ac_ip6_config), - default_route_metric_penalty_get(self, AF_INET6)); - } - if (applied_config_get_current(&priv->dhcp6.ip6_config)) { - nm_ip_config_subtract((NMIPConfig *) priv->ext_ip_config_6, - applied_config_get_current(&priv->dhcp6.ip6_config), - default_route_metric_penalty_get(self, AF_INET6)); - } - if (applied_config_get_current(&priv->dev2_ip_config_6)) { - nm_ip_config_subtract((NMIPConfig *) priv->ext_ip_config_6, - applied_config_get_current(&priv->dev2_ip_config_6), - default_route_metric_penalty_get(self, AF_INET6)); - } - for (iter = priv->vpn_configs_6; iter; iter = iter->next) - nm_ip6_config_subtract(priv->ext_ip_config_6, iter->data, 0); - } - } - - return TRUE; -} - -static void -update_ip_config(NMDevice *self, int addr_family) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - - nm_assert_addr_family(addr_family); - - if (NM_IS_IPv4(addr_family)) - priv->update_ip_config_completed_v4 = TRUE; - else - priv->update_ip_config_completed_v6 = TRUE; - - if (update_ext_ip_config(self, addr_family, TRUE)) { - if (NM_IS_IPv4(addr_family)) { - if (priv->ext_ip_config_4) - ip_config_merge_and_apply(self, AF_INET, FALSE); - } else { - if (priv->ext_ip6_config_captured) - ip_config_merge_and_apply(self, AF_INET6, FALSE); - } - } -} - -void -nm_device_capture_initial_config(NMDevice *self) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - - if (!priv->update_ip_config_completed_v4) - update_ip_config(self, AF_INET); - if (!priv->update_ip_config_completed_v6) - update_ip_config(self, AF_INET6); -} - -static gboolean -queued_ip_config_change(NMDevice *self, int addr_family) -{ - NMDevicePrivate *priv; - const int IS_IPv4 = NM_IS_IPv4(addr_family); - - g_return_val_if_fail(NM_IS_DEVICE(self), G_SOURCE_REMOVE); - - priv = NM_DEVICE_GET_PRIVATE(self); - - /* Wait for any queued state changes */ - if (priv->queued_state.id) - return G_SOURCE_CONTINUE; - - /* If a commit is scheduled, this function would potentially interfere with - * it changing IP configurations before they are applied. Postpone the - * update in such case. + * complete (via a pending action) until either the carrier turns on, or + * a timeout is reached. */ - if (priv->activation_source_id_x[IS_IPv4] != 0 - && priv->activation_source_func_x[IS_IPv4] - == activate_stage5_ip_config_result_x_fcn(addr_family)) - return G_SOURCE_CONTINUE; - - priv->queued_ip_config_id_x[IS_IPv4] = 0; + if (nm_device_has_capability(self, NM_DEVICE_CAP_CARRIER_DETECT)) { + gint64 now_ms, until_ms; - update_ip_config(self, addr_family); + /* we start a grace period of 5 seconds during which we will schedule + * a pending action whenever we have no carrier. + * + * If during that time carrier goes away, we declare the interface + * as not ready. */ + nm_clear_g_source(&priv->carrier_wait_id); + if (!priv->carrier) + nm_device_add_pending_action(self, NM_PENDING_ACTION_CARRIER_WAIT, FALSE); - if (!IS_IPv4) { - /* Check whether we need to complete waiting for link-local. - * We are also called from an idle handler, so no problem doing state transitions - * now. */ - linklocal6_check_complete(self); + now_ms = nm_utils_get_monotonic_timestamp_msec(); + until_ms = NM_MAX(now_ms + _get_carrier_wait_ms(self), priv->carrier_wait_until_ms); + priv->carrier_wait_id = g_timeout_add(until_ms - now_ms, carrier_wait_timeout, self); } - if (!IS_IPv4) { - NMPlatform * platform; - GSList * dad6_failed_addrs, *iter; - const NMPlatformLink *pllink; - - dad6_failed_addrs = g_steal_pointer(&priv->dad6_failed_addrs); - - if (priv->state > NM_DEVICE_STATE_DISCONNECTED && priv->state < NM_DEVICE_STATE_DEACTIVATING - && priv->ifindex > 0 && !nm_device_sys_iface_state_is_external(self) - && (platform = nm_device_get_platform(self)) - && (pllink = nm_platform_link_get(platform, priv->ifindex)) - && (pllink->n_ifi_flags & IFF_UP)) { - gboolean need_ipv6ll = FALSE; - NMNDiscConfigMap ndisc_config_changed = NM_NDISC_CONFIG_NONE; + /* Can only get HW address of some devices when they are up */ + nm_device_update_hw_address(self); - /* Handle DAD failures */ - for (iter = dad6_failed_addrs; iter; iter = iter->next) { - const NMPObject * obj = iter->data; - const NMPlatformIP6Address *addr; + _dev_l3_cfg_commit(self, TRUE); - if (!nm_ndisc_dad_addr_is_fail_candidate(platform, obj)) - continue; + return TRUE; +} - addr = NMP_OBJECT_CAST_IP6_ADDRESS(obj); +void +nm_device_take_down(NMDevice *self, gboolean block) +{ + int ifindex; + gboolean device_is_up; - _LOGI(LOGD_IP6, - "ipv6: duplicate address check failed for the %s address", - nm_platform_ip6_address_to_string(addr, NULL, 0)); + g_return_if_fail(NM_IS_DEVICE(self)); - if (IN6_IS_ADDR_LINKLOCAL(&addr->address)) - need_ipv6ll = TRUE; - else if (priv->ndisc) - ndisc_config_changed |= nm_ndisc_dad_failed(priv->ndisc, &addr->address, FALSE); - } + ifindex = nm_device_get_ip_ifindex(self); + _LOGD(LOGD_PLATFORM, "taking down device %d", ifindex); + if (ifindex <= 0) { + /* devices without ifindex are always up. */ + return; + } - if (ndisc_config_changed != NM_NDISC_CONFIG_NONE) - nm_ndisc_emit_config_change(priv->ndisc, ndisc_config_changed); + if (!nm_platform_link_change_flags(nm_device_get_platform(self), ifindex, IFF_UP, FALSE)) + return; - /* If no IPv6 link-local address exists but other addresses do then we - * must add the LL address to remain conformant with RFC 3513 chapter 2.1 - * ("Addressing Model"): "All interfaces are required to have at least - * one link-local unicast address". - */ - if (priv->ip_config_6 && nm_ip6_config_get_num_addresses(priv->ip_config_6)) - need_ipv6ll = TRUE; - if (need_ipv6ll) - check_and_add_ipv6ll_addr(self); - } + device_is_up = nm_device_is_up(self); + if (block && device_is_up) { + gint64 wait_until = nm_utils_get_monotonic_timestamp_usec() + 10000 /* microseconds */; - g_slist_free_full(dad6_failed_addrs, (GDestroyNotify) nmp_object_unref); + do { + g_usleep(200); + if (!nm_platform_link_refresh(nm_device_get_platform(self), ifindex)) + return; + device_is_up = nm_device_is_up(self); + } while (device_is_up && nm_utils_get_monotonic_timestamp_usec() < wait_until); } - if (!IS_IPv4) { - /* Check if DAD is still pending */ - if (priv->ip_state_6 == NM_DEVICE_IP_STATE_CONF && priv->dad6_ip6_config - && priv->ext_ip6_config_captured - && !nm_ip6_config_has_any_dad_pending(priv->ext_ip6_config_captured, - priv->dad6_ip6_config)) { - _LOGD(LOGD_DEVICE | LOGD_IP6, "IPv6 DAD terminated"); - g_clear_object(&priv->dad6_ip6_config); - _set_ip_state(self, addr_family, NM_DEVICE_IP_STATE_DONE); - check_ip_state(self, FALSE, TRUE); - if (priv->rt6_temporary_not_available) - nm_device_activate_schedule_ip_config_result(self, AF_INET6, NULL); - } + if (device_is_up) { + if (block) + _LOGW(LOGD_PLATFORM, "device not down after timeout!"); + else + _LOGD(LOGD_PLATFORM, "device not down immediately"); } - - set_unmanaged_external_down(self, TRUE); - - return G_SOURCE_REMOVE; -} - -static gboolean -queued_ip4_config_change(gpointer user_data) -{ - return queued_ip_config_change(user_data, AF_INET); } -static gboolean -queued_ip6_config_change(gpointer user_data) +void +nm_device_set_firmware_missing(NMDevice *self, gboolean new_missing) { - return queued_ip_config_change(user_data, AF_INET6); -} - -static void -device_ipx_changed(NMPlatform * platform, - int obj_type_i, - int ifindex, - gconstpointer platform_object, - int change_type_i, - NMDevice * self) -{ - const NMPObjectType obj_type = obj_type_i; - const NMPlatformSignalChangeType change_type = change_type_i; - NMDevicePrivate * priv; - const NMPlatformIP6Address * addr; - - if (nm_device_get_ip_ifindex(self) != ifindex) - return; - - if (!nm_device_is_real(self)) - return; + NMDevicePrivate *priv; - if (nm_device_get_unmanaged_flags(self, NM_UNMANAGED_PLATFORM_INIT)) { - /* ignore all platform signals until the link is initialized in platform. */ - return; - } + g_return_if_fail(NM_IS_DEVICE(self)); priv = NM_DEVICE_GET_PRIVATE(self); - - switch (obj_type) { - case NMP_OBJECT_TYPE_IP4_ADDRESS: - case NMP_OBJECT_TYPE_IP4_ROUTE: - if (!priv->queued_ip_config_id_4) { - priv->queued_ip_config_id_4 = g_idle_add(queued_ip4_config_change, self); - _LOGD(LOGD_DEVICE, "queued IP4 config change"); - } - break; - case NMP_OBJECT_TYPE_IP6_ADDRESS: - addr = platform_object; - - if (priv->state > NM_DEVICE_STATE_DISCONNECTED && priv->state < NM_DEVICE_STATE_DEACTIVATING - && nm_ndisc_dad_addr_is_fail_candidate_event(change_type, addr)) { - priv->dad6_failed_addrs = - g_slist_prepend(priv->dad6_failed_addrs, - (gpointer) nmp_object_ref(NMP_OBJECT_UP_CAST(addr))); - } - - /* fall-through */ - case NMP_OBJECT_TYPE_IP6_ROUTE: - if (!priv->queued_ip_config_id_6) { - priv->queued_ip_config_id_6 = g_idle_add(queued_ip6_config_change, self); - _LOGD(LOGD_DEVICE, "queued IP6 config change"); - } - break; - default: - g_return_if_reached(); + if (priv->firmware_missing != new_missing) { + priv->firmware_missing = new_missing; + _notify(self, PROP_FIRMWARE_MISSING); } } +gboolean +nm_device_get_firmware_missing(NMDevice *self) +{ + return NM_DEVICE_GET_PRIVATE(self)->firmware_missing; +} + /*****************************************************************************/ NM_UTILS_FLAGS2STR_DEFINE(nm_unmanaged_flags2str, @@ -14956,7 +13959,7 @@ nm_device_get_unmanaged_flags(NMDevice *self, NMUnmanagedFlags flag) * Set the unmanaged flags of the device. **/ static void -_set_unmanaged_flags(NMDevice * self, +_set_unmanaged_flags(NMDevice *self, NMUnmanagedFlags flags, NMUnmanFlagOp set_op, gboolean allow_state_transition, @@ -14967,7 +13970,7 @@ _set_unmanaged_flags(NMDevice * self, gboolean was_managed, transition_state; NMUnmanagedFlags old_flags, old_mask; NMDeviceState new_state; - const char * operation = NULL; + const char *operation = NULL; char str1[512]; char str2[512]; gboolean do_notify_has_pending_actions = FALSE; @@ -14995,12 +13998,6 @@ _set_unmanaged_flags(NMDevice * self, nm_device_set_unmanaged_flags(self, NM_UNMANAGED_USER_SETTINGS, !!unmanaged); } - /* trigger an initial update of IP configuration. */ - nm_assert_se(!nm_clear_g_source(&priv->queued_ip_config_id_4)); - nm_assert_se(!nm_clear_g_source(&priv->queued_ip_config_id_6)); - priv->queued_ip_config_id_4 = g_idle_add(queued_ip4_config_change, self); - priv->queued_ip_config_id_6 = g_idle_add(queued_ip6_config_change, self); - if (priv->pending_actions.len == 0) { do_notify_has_pending_actions = TRUE; had_pending_actions = nm_device_has_pending_action(self); @@ -15099,7 +14096,7 @@ nm_device_set_unmanaged_flags(NMDevice *self, NMUnmanagedFlags flags, NMUnmanFla * Set the unmanaged flags of the device and possibly trigger a state change. **/ void -nm_device_set_unmanaged_by_flags(NMDevice * self, +nm_device_set_unmanaged_by_flags(NMDevice *self, NMUnmanagedFlags flags, NMUnmanFlagOp set_op, NMDeviceStateReason reason) @@ -15108,7 +14105,7 @@ nm_device_set_unmanaged_by_flags(NMDevice * self, } void -nm_device_set_unmanaged_by_flags_queue(NMDevice * self, +nm_device_set_unmanaged_by_flags_queue(NMDevice *self, NMUnmanagedFlags flags, NMUnmanFlagOp set_op, NMDeviceStateReason reason) @@ -15143,7 +14140,7 @@ nm_device_check_unrealized_device_managed(NMDevice *self) } void -nm_device_set_unmanaged_by_user_settings(NMDevice *self) +nm_device_set_unmanaged_by_user_settings(NMDevice *self, gboolean now) { gboolean unmanaged; @@ -15165,11 +14162,13 @@ nm_device_set_unmanaged_by_user_settings(NMDevice *self) self, nm_settings_get_unmanaged_specs(NM_DEVICE_GET_PRIVATE(self)->settings)); - nm_device_set_unmanaged_by_flags(self, - NM_UNMANAGED_USER_SETTINGS, - !!unmanaged, - unmanaged ? NM_DEVICE_STATE_REASON_NOW_UNMANAGED - : NM_DEVICE_STATE_REASON_NOW_MANAGED); + _set_unmanaged_flags(self, + NM_UNMANAGED_USER_SETTINGS, + !!unmanaged, + TRUE, + now, + unmanaged ? NM_DEVICE_STATE_REASON_NOW_UNMANAGED + : NM_DEVICE_STATE_REASON_NOW_MANAGED); } void @@ -15247,12 +14246,12 @@ nm_device_set_unmanaged_by_quitting(NMDevice *self) void nm_device_reapply_settings_immediately(NMDevice *self) { - NMConnection * applied_connection; + NMConnection *applied_connection; NMSettingsConnection *settings_connection; NMDeviceState state; - NMSettingConnection * s_con_settings; - NMSettingConnection * s_con_applied; - const char * zone; + NMSettingConnection *s_con_settings; + NMSettingConnection *s_con_applied; + const char *zone; NMMetered metered; guint64 version_id; @@ -15322,10 +14321,10 @@ void nm_device_update_metered(NMDevice *self) { #define NM_METERED_INVALID ((NMMetered) -1) - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); NMSettingConnection *setting; NMMetered conn_value, value = NM_METERED_INVALID; - NMConnection * connection = NULL; + NMConnection *connection = NULL; NMDeviceState state; g_return_if_fail(NM_IS_DEVICE(self)); @@ -15352,9 +14351,13 @@ nm_device_update_metered(NMDevice *self) /* Try to guess a value using the metered flag in IP configuration */ if (value == NM_METERED_INVALID) { - if (priv->ip_config_4 && priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE - && nm_ip4_config_get_metered(priv->ip_config_4)) - value = NM_METERED_GUESS_YES; + if (priv->l3cfg) { + const NML3ConfigData *l3cd; + + l3cd = nm_l3cfg_get_combined_l3cd(priv->l3cfg, TRUE); + if (l3cd && nm_l3_config_data_get_metered(l3cd) == NM_TERNARY_TRUE) + value = NM_METERED_GUESS_YES; + } } /* Otherwise, look at connection type. For Bluetooth, we look at the type of @@ -15400,14 +14403,14 @@ _device_check_dev_available_flags_from_con(NMDeviceCheckConAvailableFlags con_fl } static gboolean -_nm_device_check_connection_available(NMDevice * self, - NMConnection * connection, +_nm_device_check_connection_available(NMDevice *self, + NMConnection *connection, NMDeviceCheckConAvailableFlags flags, - const char * specific_object, - GError ** error) + const char *specific_object, + GError **error) { NMDeviceState state; - GError * local = NULL; + GError *local = NULL; /* an unrealized software device is always available, hardware devices never. */ if (!nm_device_is_real(self)) { @@ -15511,11 +14514,11 @@ _nm_device_check_connection_available(NMDevice * self, * Returns: %TRUE if @connection can be activated on @self */ gboolean -nm_device_check_connection_available(NMDevice * self, - NMConnection * connection, +nm_device_check_connection_available(NMDevice *self, + NMConnection *connection, NMDeviceCheckConAvailableFlags flags, - const char * specific_object, - GError ** error) + const char *specific_object, + GError **error) { gboolean available; @@ -15569,11 +14572,11 @@ available_connections_del(NMDevice *self, NMSettingsConnection *sett_conn) } static gboolean -check_connection_available(NMDevice * self, - NMConnection * connection, +check_connection_available(NMDevice *self, + NMConnection *connection, NMDeviceCheckConAvailableFlags flags, - const char * specific_object, - GError ** error) + const char *specific_object, + GError **error) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); @@ -15616,12 +14619,12 @@ check_connection_available(NMDevice * self, void nm_device_recheck_available_connections(NMDevice *self) { - NMDevicePrivate * priv; - NMSettingsConnection *const *connections; - gboolean changed = FALSE; - GHashTableIter h_iter; - NMSettingsConnection * sett_conn; - guint i; + NMDevicePrivate *priv; + NMSettingsConnection *const *connections; + gboolean changed = FALSE; + GHashTableIter h_iter; + NMSettingsConnection *sett_conn; + guint i; gs_unref_hashtable GHashTable *prune_list = NULL; g_return_if_fail(NM_IS_DEVICE(self)); @@ -15678,7 +14681,7 @@ nm_device_recheck_available_connections(NMDevice *self) NMSettingsConnection * nm_device_get_best_connection(NMDevice *self, const char *specific_object, GError **error) { - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); NMSettingsConnection *sett_conn = NULL; NMSettingsConnection *candidate; guint64 best_timestamp = 0; @@ -15748,7 +14751,7 @@ cp_connection_added(NMSettings *settings, NMSettingsConnection *sett_conn, gpoin } static void -cp_connection_updated(NMSettings * settings, +cp_connection_updated(NMSettings *settings, NMSettingsConnection *sett_conn, guint update_reason_u, gpointer user_data) @@ -15925,12 +14928,11 @@ _cancel_activation(NMDevice *self) priv->fw_state = FIREWALL_STATE_INITIALIZED; } - dispatcher_cleanup(self); + _dispatcher_cleanup(self); ip_check_gw_ping_cleanup(self); /* Break the activation chain */ - activation_source_clear(self, AF_INET); - activation_source_clear(self, AF_INET6); + activation_source_clear(self); } static void @@ -15960,17 +14962,13 @@ _cleanup_generic_pre(NMDevice *self, CleanupType cleanup_type) queued_state_clear(self); - nm_clear_pointer(&priv->shared_ip_handle, nm_netns_shared_ip_release); - for (i = 0; i < 2; i++) nm_clear_pointer(&priv->hostname_resolver_x[i], _hostname_resolver_free); - _cleanup_ip_pre(self, AF_INET, cleanup_type); - _cleanup_ip_pre(self, AF_INET6, cleanup_type); + _cleanup_ip_pre(self, AF_INET, cleanup_type, FALSE); + _cleanup_ip_pre(self, AF_INET6, cleanup_type, FALSE); - priv->ip_config_started = FALSE; - nm_clear_g_source_inst(&priv->ip_req_timeout_source_4); - nm_clear_g_source_inst(&priv->ip_req_timeout_source_6); + _dev_ip_state_req_timeout_cancel(self, AF_UNSPEC); } static void @@ -15978,54 +14976,16 @@ _cleanup_generic_post(NMDevice *self, CleanupType cleanup_type) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - priv->v4_commit_first_time = TRUE; - priv->v6_commit_first_time = TRUE; - priv->v4_route_table_initialized = FALSE; priv->v6_route_table_initialized = FALSE; + priv->l3config_merge_flags_has = FALSE; priv->v4_route_table_all_sync_before = FALSE; priv->v6_route_table_all_sync_before = FALSE; - priv->default_route_metric_penalty_ip4_has = FALSE; - priv->default_route_metric_penalty_ip6_has = FALSE; - - priv->linklocal6_dad_counter = 0; - priv->mtu_force_set_done = FALSE; - /* Clean up IP configs; this does not actually deconfigure the - * interface; the caller must flush routes and addresses explicitly. - */ - nm_device_set_ip_config(self, AF_INET, NULL, TRUE, NULL); - nm_device_set_ip_config(self, AF_INET6, NULL, TRUE, NULL); - g_clear_object(&priv->proxy_config); - g_clear_object(&priv->con_ip_config_4); - applied_config_clear(&priv->dev_ip_config_4); - applied_config_clear(&priv->dev2_ip_config_4); - g_clear_object(&priv->ext_ip_config_4); - g_clear_object(&priv->ip_config_4); - g_clear_object(&priv->con_ip_config_6); - applied_config_clear(&priv->ac_ip6_config); - g_clear_object(&priv->ext_ip_config_6); - g_clear_object(&priv->ext_ip6_config_captured); - applied_config_clear(&priv->dev2_ip_config_6); - g_clear_object(&priv->ip_config_6); - g_clear_object(&priv->dad6_ip6_config); - priv->ipv6ll_has = FALSE; - memset(&priv->ipv6ll_addr, 0, sizeof(priv->ipv6ll_addr)); - - nm_clear_pointer(&priv->rt6_temporary_not_available, g_hash_table_unref); - nm_clear_g_source(&priv->rt6_temporary_not_available_id); - - g_slist_free_full(priv->vpn_configs_4, g_object_unref); - priv->vpn_configs_4 = NULL; - g_slist_free_full(priv->vpn_configs_6, g_object_unref); - priv->vpn_configs_6 = NULL; - - /* We no longer accept the delegations. nm_device_set_ip_config(NULL) - * above disables them. */ - nm_assert(priv->needs_ip6_subnet == FALSE); + priv->needs_ip6_subnet = FALSE; if (priv->act_request.obj) { nm_active_connection_set_default(NM_ACTIVE_CONNECTION(priv->act_request.obj), @@ -16047,6 +15007,9 @@ _cleanup_generic_post(NMDevice *self, CleanupType cleanup_type) * or ATM device). */ _set_ip_ifindex(self, 0, NULL); + + nm_clear_g_source_inst(&priv->ip_data_4.check_async_source); + nm_clear_g_source_inst(&priv->ip_data_6.check_async_source); } /* @@ -16078,7 +15041,7 @@ nm_device_cleanup(NMDevice *self, NMDeviceStateReason reason, CleanupType cleanu /* Turn off kernel IPv6 */ if (cleanup_type == CLEANUP_TYPE_DECONFIGURE) { - set_disable_ipv6(self, "1"); + _dev_sysctl_set_disable_ipv6(self, TRUE); nm_device_sysctl_ip_conf_set(self, AF_INET6, "use_tempaddr", "0"); } @@ -16094,12 +15057,10 @@ nm_device_cleanup(NMDevice *self, NMDeviceStateReason reason, CleanupType cleanu /* Take out any entries in the routing table and any IP address the device had. */ if (ifindex > 0) { - NMPlatform * platform = nm_device_get_platform(self); - NMUtilsIPv6IfaceId iid = {}; + NMPlatform *platform = nm_device_get_platform(self); nm_platform_ip_route_flush(platform, AF_UNSPEC, ifindex); nm_platform_ip_address_flush(platform, AF_UNSPEC, ifindex); - set_ipv6_token(self, &iid, "::"); if (nm_device_get_applied_setting(self, NM_TYPE_SETTING_TC_CONFIG)) { nm_platform_tc_sync(platform, ifindex, NULL, NULL); @@ -16192,213 +15153,13 @@ deactivate_reset_hw_addr(NMDevice *self) nm_device_hw_addr_reset(self, "deactivate"); } -static char * -find_dhcp4_address(NMDevice *self) -{ - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - const NMPlatformIP4Address *a; - NMDedupMultiIter ipconf_iter; - - if (!priv->ip_config_4) - return NULL; - - nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, priv->ip_config_4, &a) { - if (a->addr_source == NM_IP_CONFIG_SOURCE_DHCP) - return nm_utils_inet4_ntop_dup(a->address); - } - return NULL; -} - -void -nm_device_spawn_iface_helper(NMDevice *self) -{ - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - gboolean configured = FALSE; - NMConnection * connection; - GError * error = NULL; - const char * method; - GPtrArray * argv; - gs_free char * dhcp4_address = NULL; - char * logging_backend; - NMUtilsStableType stable_type; - const char * stable_id; - - if (priv->state != NM_DEVICE_STATE_ACTIVATED) - return; - if (!nm_device_can_assume_connections(self)) - return; - - connection = nm_device_get_applied_connection(self); - - g_return_if_fail(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))); - - stable_id = _prop_get_connection_stable_id(self, connection, &stable_type); - if (stable_type != NM_UTILS_STABLE_TYPE_UUID) { - g_ptr_array_add(argv, g_strdup("--stable-id")); - g_ptr_array_add(argv, g_strdup_printf("%d %s", (int) stable_type, stable_id)); - } - - logging_backend = - nm_config_data_get_value(NM_CONFIG_GET_DATA_ORIG, - NM_CONFIG_KEYFILE_GROUP_LOGGING, - NM_CONFIG_KEYFILE_KEY_LOGGING_BACKEND, - NM_CONFIG_GET_VALUE_STRIP | NM_CONFIG_GET_VALUE_NO_EMPTY); - if (logging_backend) { - g_ptr_array_add(argv, g_strdup("--logging-backend")); - g_ptr_array_add(argv, logging_backend); - } - - g_ptr_array_add(argv, g_strdup("--log-level")); - g_ptr_array_add(argv, g_strdup(nm_logging_level_to_string())); - - g_ptr_array_add(argv, g_strdup("--log-domains")); - g_ptr_array_add(argv, g_strdup(nm_logging_domains_to_string())); - - dhcp4_address = find_dhcp4_address(self); - - method = nm_device_get_effective_ip_config_method(self, AF_INET); - if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) { - NMSettingIPConfig *s_ip4; - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - nm_assert(s_ip4); - - g_ptr_array_add(argv, g_strdup("--priority4")); - g_ptr_array_add(argv, g_strdup_printf("%u", nm_device_get_route_metric(self, AF_INET))); - - 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")); - - if (priv->dhcp_data_4.client) { - const char *hostname; - GBytes * client_id; - - client_id = nm_dhcp_client_get_client_id(priv->dhcp_data_4.client); - if (client_id) { - g_ptr_array_add(argv, g_strdup("--dhcp4-clientid")); - g_ptr_array_add(argv, - nm_utils_bin2hexstr_full(g_bytes_get_data(client_id, NULL), - g_bytes_get_size(client_id), - ':', - FALSE, - NULL)); - } - - hostname = nm_dhcp_client_get_hostname(priv->dhcp_data_4.client); - if (hostname) { - if (NM_FLAGS_HAS(nm_dhcp_client_get_client_flags(priv->dhcp_data_4.client), - NM_DHCP_CLIENT_FLAGS_USE_FQDN)) - g_ptr_array_add(argv, g_strdup("--dhcp4-fqdn")); - else - 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, AF_INET6); - if (nm_streq(method, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) { - NMSettingIPConfig *s_ip6; - 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("--priority6")); - g_ptr_array_add(argv, g_strdup_printf("%u", nm_device_get_route_metric(self, AF_INET6))); - - 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->ndisc_use_tempaddr)); - - if (nm_device_get_ip_iface_identifier(self, &iid, FALSE)) { - g_ptr_array_add(argv, g_strdup("--iid")); - g_ptr_array_add( - argv, - nm_utils_bin2hexstr_full(iid.id_u8, sizeof(NMUtilsIPv6IfaceId), ':', FALSE, NULL)); - } - - g_ptr_array_add(argv, g_strdup("--addr-gen-mode")); - g_ptr_array_add( - argv, - g_strdup_printf("%d", - nm_setting_ip6_config_get_addr_gen_mode(NM_SETTING_IP6_CONFIG(s_ip6)))); - - configured = TRUE; - } - - if (configured) { - GPid pid; - - 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 -ip_config_valid(NMDeviceState state) -{ - return (state == NM_DEVICE_STATE_UNMANAGED) - || (state >= NM_DEVICE_STATE_IP_CHECK && state <= NM_DEVICE_STATE_DEACTIVATING); -} - -static void -notify_ip_properties(NMDevice *self) -{ - _notify(self, PROP_IP_IFACE); - _notify(self, PROP_IP4_CONFIG); - _notify(self, PROP_DHCP4_CONFIG); - _notify(self, PROP_IP6_CONFIG); - _notify(self, PROP_DHCP6_CONFIG); -} - static void ip6_managed_setup(NMDevice *self) { - set_nm_ipv6ll(self, TRUE); - set_disable_ipv6(self, "1"); + _dev_addrgenmode6_set(self, NM_IN6_ADDR_GEN_MODE_NONE); + _dev_sysctl_set_disable_ipv6(self, FALSE); nm_device_sysctl_ip_conf_set(self, AF_INET6, "accept_ra", "0"); nm_device_sysctl_ip_conf_set(self, AF_INET6, "use_tempaddr", "0"); nm_device_sysctl_ip_conf_set(self, AF_INET6, "forwarding", "0"); @@ -16422,7 +15183,7 @@ deactivate_ready(NMDevice *self, NMDeviceStateReason reason) static void sriov_reset_on_deactivate_cb(GError *error, gpointer user_data) { - NMDevice * self; + NMDevice *self; NMDevicePrivate *priv; gpointer reason; @@ -16440,7 +15201,7 @@ sriov_reset_on_deactivate_cb(GError *error, gpointer user_data) static void sriov_reset_on_failure_cb(GError *error, gpointer user_data) { - NMDevice * self = user_data; + NMDevice *self = user_data; NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); nm_assert(priv->sriov_reset_pending > 0); @@ -16457,7 +15218,7 @@ sriov_reset_on_failure_cb(GError *error, gpointer user_data) static void deactivate_async_ready(NMDevice *self, GError *error, gpointer user_data) { - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); NMDeviceStateReason reason = GPOINTER_TO_UINT(user_data); if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { @@ -16478,8 +15239,8 @@ deactivate_async_ready(NMDevice *self, GError *error, gpointer user_data) static void deactivate_dispatcher_complete(NMDispatcherCallId *call_id, gpointer user_data) { - NMDevice * self = NM_DEVICE(user_data); - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); + NMDevice *self = NM_DEVICE(user_data); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); NMDeviceStateReason reason; g_return_if_fail(call_id == priv->dispatcher.call_id); @@ -16532,20 +15293,19 @@ deactivate_dispatcher_complete(NMDispatcherCallId *call_id, gpointer user_data) static void _set_state_full(NMDevice *self, NMDeviceState state, NMDeviceStateReason reason, gboolean quitting) { - NMDevicePrivate *priv; - NMDeviceState old_state; - gs_unref_object NMActRequest *req = NULL; + gs_unref_object NMActRequest *req = NULL; + NMDevicePrivate *priv; + NMDeviceState old_state; gboolean no_firmware = FALSE; - NMSettingsConnection * sett_conn; - NMSettingSriov * s_sriov; + NMSettingsConnection *sett_conn; + NMSettingSriov *s_sriov; gboolean concheck_now; g_return_if_fail(NM_IS_DEVICE(self)); priv = NM_DEVICE_GET_PRIVATE(self); - /* Track re-entry */ - g_warn_if_fail(priv->in_state_changed == FALSE); + g_return_if_fail(priv->in_state_changed == 0); old_state = priv->state; @@ -16582,14 +15342,14 @@ _set_state_full(NMDevice *self, NMDeviceState state, NMDeviceStateReason reason, * by the device not having any pending action anymore * we add one here that gets removed at the end of the function */ nm_device_add_pending_action(self, NM_PENDING_ACTION_IN_STATE_CHANGE, TRUE); - priv->in_state_changed = TRUE; + priv->in_state_changed++; priv->state = state; priv->state_reason = reason; queued_state_clear(self); - dispatcher_cleanup(self); + _dispatcher_cleanup(self); nm_clear_g_cancellable(&priv->deactivating_cancellable); @@ -16646,15 +15406,15 @@ _set_state_full(NMDevice *self, NMDeviceState state, NMDeviceStateReason reason, nm_device_cleanup(self, reason, CLEANUP_TYPE_DECONFIGURE); nm_device_take_down(self, TRUE); nm_device_hw_addr_reset(self, "unmanage"); - set_nm_ipv6ll(self, FALSE); - restore_ip6_properties(self); + _dev_addrgenmode6_set(self, NM_IN6_ADDR_GEN_MODE_EUI64); + _dev_sysctl_restore_ip6_properties(self); } } nm_device_sys_iface_state_set(self, NM_DEVICE_SYS_IFACE_STATE_EXTERNAL); break; case NM_DEVICE_STATE_UNAVAILABLE: if (old_state == NM_DEVICE_STATE_UNMANAGED) { - save_ip6_properties(self); + _dev_sysctl_save_ip6_properties(self); if (priv->sys_iface_state == NM_DEVICE_SYS_IFACE_STATE_MANAGED) ip6_managed_setup(self); device_init_static_sriov_num_vfs(self); @@ -16683,7 +15443,7 @@ _set_state_full(NMDevice *self, NMDeviceState state, NMDeviceStateReason reason, /* Ensure devices that previously assumed a connection now have * userspace IPv6LL enabled. */ - set_nm_ipv6ll(self, TRUE); + _dev_addrgenmode6_set(self, NM_IN6_ADDR_GEN_MODE_NONE); nm_device_cleanup(self, reason, CLEANUP_TYPE_DECONFIGURE); } else if (old_state < NM_DEVICE_STATE_DISCONNECTED) { @@ -16703,8 +15463,8 @@ _set_state_full(NMDevice *self, NMDeviceState state, NMDeviceStateReason reason, /* Clean up any half-done IP operations if the device's layer2 * finds out it needs authentication during IP config. */ - _cleanup_ip_pre(self, AF_INET, CLEANUP_TYPE_DECONFIGURE); - _cleanup_ip_pre(self, AF_INET6, CLEANUP_TYPE_DECONFIGURE); + _cleanup_ip_pre(self, AF_INET, CLEANUP_TYPE_DECONFIGURE, FALSE); + _cleanup_ip_pre(self, AF_INET6, CLEANUP_TYPE_DECONFIGURE, FALSE); } break; default: @@ -16796,9 +15556,7 @@ _set_state_full(NMDevice *self, NMDeviceState state, NMDeviceStateReason reason, _LOGI(LOGD_DEVICE, "Activation: successful, device activated."); nm_device_update_metered(self); nm_dispatcher_call_device(NM_DISPATCHER_ACTION_UP, self, req, NULL, NULL, NULL); - - if (priv->proxy_config) - _pacrunner_manager_add(self); + _pacrunner_manager_add(self); break; case NM_DEVICE_STATE_FAILED: /* Usually upon failure the activation chain is interrupted in @@ -16859,10 +15617,6 @@ _set_state_full(NMDevice *self, NMDeviceState state, NMDeviceStateReason reason, } else nm_device_start_ip_check(self); - /* IP-related properties are only valid when the device has IP configuration; - * now that it does, ensure their change notifications are emitted. - */ - notify_ip_properties(self); break; } case NM_DEVICE_STATE_SECONDARIES: @@ -16885,18 +15639,15 @@ _set_state_full(NMDevice *self, NMDeviceState state, NMDeviceStateReason reason, } } - /* IP-related properties are only valid when the device has IP configuration. - * If it no longer does, ensure their change notifications are emitted. - */ - if (ip_config_valid(old_state) && !ip_config_valid(state)) - notify_ip_properties(self); - concheck_now = NM_IN_SET(state, NM_DEVICE_STATE_ACTIVATED, NM_DEVICE_STATE_DISCONNECTED) || old_state >= NM_DEVICE_STATE_ACTIVATED; concheck_update_interval(self, AF_INET, concheck_now); concheck_update_interval(self, AF_INET6, concheck_now); - priv->in_state_changed = FALSE; + update_prop_ip_iface(self); + + priv->in_state_changed--; + nm_device_remove_pending_action(self, NM_PENDING_ACTION_IN_STATE_CHANGE, TRUE); if ((old_state > NM_DEVICE_STATE_UNMANAGED) != (state > NM_DEVICE_STATE_UNMANAGED)) @@ -16912,8 +15663,8 @@ nm_device_state_changed(NMDevice *self, NMDeviceState state, NMDeviceStateReason static gboolean queued_state_set(gpointer user_data) { - NMDevice * self = NM_DEVICE(user_data); - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); + NMDevice *self = NM_DEVICE(user_data); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); NMDeviceState new_state; NMDeviceStateReason new_reason; @@ -17048,7 +15799,7 @@ gboolean nm_device_update_hw_address(NMDevice *self) { NMDevicePrivate *priv; - const guint8 * hwaddr; + const guint8 *hwaddr; gsize hwaddrlen = 0; priv = NM_DEVICE_GET_PRIVATE(self); @@ -17123,11 +15874,11 @@ nm_device_update_initial_hw_address(NMDevice *self) void nm_device_update_permanent_hw_address(NMDevice *self, gboolean force_freeze) { - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); guint8 buf[_NM_UTILS_HWADDR_LEN_MAX]; gboolean success_read; int ifindex; - const NMPlatformLink * pllink; + const NMPlatformLink *pllink; const NMConfigDeviceStateData *dev_state; NMPLinkAddress cached_hw_addr_perm; @@ -17236,7 +15987,7 @@ _hw_addr_matches(NMDevice *self, const guint8 *addr, gsize addr_len) } static gboolean -_hw_addr_set(NMDevice * self, +_hw_addr_set(NMDevice *self, const char *const addr, const char *const operation, const char *const detail) @@ -17439,20 +16190,20 @@ nm_device_hw_addr_set(NMDevice *self, const char *addr, const char *detail, gboo * %TRUE otherwise */ static gboolean -_hw_addr_get_cloned(NMDevice * self, +_hw_addr_get_cloned(NMDevice *self, NMConnection *connection, gboolean is_wifi, - gboolean * preserve, - char ** hwaddr, - HwAddrType * hwaddr_type, - const char ** hwaddr_detail, - GError ** error) + gboolean *preserve, + char **hwaddr, + HwAddrType *hwaddr_type, + const char **hwaddr_detail, + GError **error) { NMDevicePrivate *priv; - gs_free char * hw_addr_generated = NULL; - const char * addr; - const char * addr_setting; - char * addr_out; + gs_free char *hw_addr_generated = NULL; + const char *addr; + const char *addr_setting; + char *addr_out; HwAddrType type_out; g_return_val_if_fail(NM_IS_DEVICE(self), FALSE); @@ -17520,7 +16271,7 @@ _hw_addr_get_cloned(NMDevice * self, type_out = HW_ADDR_TYPE_GENERATED; } else if (NM_IN_STRSET(addr, NM_CLONED_MAC_STABLE)) { NMUtilsStableType stable_type; - const char * stable_id; + const char *stable_id; if (priv->hw_addr_type == HW_ADDR_TYPE_GENERATED) { /* hm, we already use a generate MAC address. Most certainly, that is from the same @@ -17569,12 +16320,12 @@ out_no_action: } gboolean -nm_device_hw_addr_get_cloned(NMDevice * self, +nm_device_hw_addr_get_cloned(NMDevice *self, NMConnection *connection, gboolean is_wifi, - char ** hwaddr, - gboolean * preserve, - GError ** error) + char **hwaddr, + gboolean *preserve, + GError **error) { if (!_hw_addr_get_cloned(self, connection, is_wifi, preserve, hwaddr, NULL, NULL, error)) return FALSE; @@ -17585,12 +16336,12 @@ nm_device_hw_addr_get_cloned(NMDevice * self, gboolean nm_device_hw_addr_set_cloned(NMDevice *self, NMConnection *connection, gboolean is_wifi) { - NMDevicePrivate *priv; - gboolean preserve = FALSE; - gs_free char * hwaddr = NULL; - const char * detail = NULL; - HwAddrType type = HW_ADDR_TYPE_UNSET; - gs_free_error GError *error = NULL; + NMDevicePrivate *priv; + gboolean preserve = FALSE; + gs_free char *hwaddr = NULL; + const char *detail = NULL; + HwAddrType type = HW_ADDR_TYPE_UNSET; + gs_free_error GError *error = NULL; g_return_val_if_fail(NM_IS_DEVICE(self), FALSE); priv = NM_DEVICE_GET_PRIVATE(self); @@ -17622,7 +16373,7 @@ gboolean nm_device_hw_addr_reset(NMDevice *self, const char *detail) { NMDevicePrivate *priv; - const char * addr; + const char *addr; g_return_val_if_fail(NM_IS_DEVICE(self), FALSE); @@ -17711,9 +16462,9 @@ nm_device_spec_match_list(NMDevice *self, const GSList *specs) int nm_device_spec_match_list_full(NMDevice *self, const GSList *specs, int no_match_value) { - NMDeviceClass * klass; + NMDeviceClass *klass; NMMatchSpecMatchType m; - const char * hw_address = NULL; + const char *hw_address = NULL; gboolean is_fake; g_return_val_if_fail(NM_IS_DEVICE(self), FALSE); @@ -17748,7 +16499,7 @@ nm_device_spec_match_list_full(NMDevice *self, const GSList *specs, int no_match guint nm_device_get_supplicant_timeout(NMDevice *self) { - NMConnection * connection; + NMConnection *connection; NMSetting8021x *s_8021x; int timeout; #define SUPPLICANT_DEFAULT_TIMEOUT 25 @@ -17777,7 +16528,7 @@ nm_device_get_supplicant_timeout(NMDevice *self) gboolean nm_device_auth_retries_try_next(NMDevice *self) { - NMDevicePrivate * priv; + NMDevicePrivate *priv; NMSettingConnection *s_con; int auth_retries; @@ -17826,11 +16577,11 @@ nm_device_auth_retries_try_next(NMDevice *self) static void hostname_dns_lookup_callback(GObject *source, GAsyncResult *result, gpointer user_data) { - HostnameResolver *resolver; - NMDevice * self; - gs_free char * addr_str = NULL; - gs_free char * output = NULL; - gs_free_error GError *error = NULL; + HostnameResolver *resolver; + NMDevice *self; + gs_free char *addr_str = NULL; + gs_free char *output = NULL; + gs_free_error GError *error = NULL; output = nm_device_resolve_address_finish(result, &error); if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) @@ -17869,7 +16620,7 @@ static gboolean hostname_dns_address_timeout(gpointer user_data) { HostnameResolver *resolver = user_data; - NMDevice * self = resolver->device; + NMDevice *self = resolver->device; g_return_val_if_fail(NM_IS_DEVICE(self), G_SOURCE_REMOVE); @@ -17914,17 +16665,70 @@ nm_device_clear_dns_lookup_data(NMDevice *self) nm_clear_pointer(&priv->hostname_resolver_x[i], _hostname_resolver_free); } +static GInetAddress * +get_address_for_hostname_dns_lookup(NMDevice *self, int addr_family) +{ + const int IS_IPv4 = NM_IS_IPv4(addr_family); + NMPLookup lookup; + const NMDedupMultiHeadEntry *head_entry; + const NMDedupMultiEntry *iter; + const guint8 *addr6_ll = NULL; + const guint8 *addr6_nonll = NULL; + int ifindex; + + ifindex = nm_device_get_ip_ifindex(self); + if (ifindex <= 0) + return NULL; + + /* FIXME(l3cfg): now we lookup the address from platform. Should we instead look + * it up from NML3Cfg? That is, take an address that we want to configure as + * opposed to an address that is configured? */ + head_entry = nm_platform_lookup( + nm_device_get_platform(self), + nmp_lookup_init_object(&lookup, NMP_OBJECT_TYPE_IP_ADDRESS(IS_IPv4), ifindex)); + + if (head_entry) { + c_list_for_each_entry (iter, &head_entry->lst_entries_head, lst_entries) { + const NMPlatformIPAddress *addr = NMP_OBJECT_CAST_IP_ADDRESS(iter->obj); + + if (IS_IPv4) { + return g_inet_address_new_from_bytes(addr->address_ptr, G_SOCKET_FAMILY_IPV4); + } + + /* For IPv6 prefer, in order: + * - !link-local, !deprecated + * - !link-local, deprecated + * - link-local + */ + + if (!IN6_IS_ADDR_LINKLOCAL(addr->address_ptr)) { + if (!(addr->n_ifa_flags & IFA_F_DEPRECATED)) { + return g_inet_address_new_from_bytes(addr->address_ptr, G_SOCKET_FAMILY_IPV6); + } + addr6_nonll = addr->address_ptr; + continue; + } + + addr6_ll = addr->address_ptr; + } + + if (addr6_nonll || addr6_ll) + return g_inet_address_new_from_bytes(addr6_nonll ?: addr6_ll, G_SOCKET_FAMILY_IPV6); + } + + return NULL; +} + /* return value is valid only immediately */ const char * nm_device_get_hostname_from_dns_lookup(NMDevice *self, int addr_family, gboolean *out_wait) { - NMDevicePrivate * priv; - const int IS_IPv4 = NM_IS_IPv4(addr_family); - HostnameResolver *resolver; - NMIPConfig * ip_config; - const char * method; - gboolean address_changed = FALSE; - gs_unref_object GInetAddress *new_address = NULL; + const int IS_IPv4 = NM_IS_IPv4(addr_family); + NMDevicePrivate *priv; + HostnameResolver *resolver; + const char *method; + gboolean address_changed = FALSE; + gs_unref_object GInetAddress *new_address = NULL; g_return_val_if_fail(NM_IS_DEVICE(self), NULL); priv = NM_DEVICE_GET_PRIVATE(self); @@ -17966,41 +16770,7 @@ nm_device_get_hostname_from_dns_lookup(NMDevice *self, int addr_family, gboolean /* Determine the most suitable address of the interface * and whether it changed from the previous lookup */ - ip_config = priv->ip_config_x[IS_IPv4]; - if (ip_config) { - const NMPlatformIPAddress *addr = NULL; - - if (IS_IPv4) { - addr = nm_ip_config_get_first_address(ip_config); - } else { - /* For IPv6 prefer, in order: - * - !link-local, !deprecated - * - !link-local, deprecated - * - link-local - */ - addr = nm_ip_config_find_first_address(ip_config, - NM_PLATFORM_MATCH_WITH_ADDRTYPE_NORMAL - | NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL); - if (!addr) { - addr = nm_ip_config_find_first_address( - ip_config, - NM_PLATFORM_MATCH_WITH_ADDRTYPE_NORMAL - | NM_PLATFORM_MATCH_WITH_ADDRSTATE_DEPRECATED); - } - if (!addr) { - addr = nm_ip_config_find_first_address(ip_config, - NM_PLATFORM_MATCH_WITH_ADDRTYPE_LINKLOCAL - | NM_PLATFORM_MATCH_WITH_ADDRSTATE__ANY); - } - } - - if (addr) { - new_address = g_inet_address_new_from_bytes(addr->address_ptr, - IS_IPv4 ? G_SOCKET_FAMILY_IPV4 - : G_SOCKET_FAMILY_IPV6); - } - } - + new_address = get_address_for_hostname_dns_lookup(self, addr_family); if (new_address && resolver->address) { if (!g_inet_address_equal(new_address, resolver->address)) address_changed = TRUE; @@ -18072,11 +16842,7 @@ _activation_func_to_string(ActivationHandleFunc func) G_STMT_END FUNC_TO_STRING_CHECK_AND_RETURN(func, activate_stage1_device_prepare); FUNC_TO_STRING_CHECK_AND_RETURN(func, activate_stage2_device_config); - FUNC_TO_STRING_CHECK_AND_RETURN(func, activate_stage3_ip_config_start); - FUNC_TO_STRING_CHECK_AND_RETURN(func, activate_stage4_ip_config_timeout_4); - FUNC_TO_STRING_CHECK_AND_RETURN(func, activate_stage4_ip_config_timeout_6); - FUNC_TO_STRING_CHECK_AND_RETURN(func, activate_stage5_ip_config_result_4); - FUNC_TO_STRING_CHECK_AND_RETURN(func, activate_stage5_ip_config_result_6); + FUNC_TO_STRING_CHECK_AND_RETURN(func, activate_stage3_ip_config); g_return_val_if_reached("unknown"); } @@ -18084,7 +16850,7 @@ static GVariant * _device_get_ports_variant(NMDevice *device) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(device); - SlaveInfo * info; + SlaveInfo *info; GVariantBuilder builder; gboolean any = FALSE; @@ -18116,7 +16882,7 @@ _device_get_ports_variant(NMDevice *device) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMDevice * self = NM_DEVICE(object); + NMDevice *self = NM_DEVICE(object); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); switch (prop_id) { @@ -18139,13 +16905,7 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) nm_utils_str_utf8safe_escape_cp(priv->iface, NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL)); break; case PROP_IP_IFACE: - if (ip_config_valid(priv->state)) { - g_value_take_string( - value, - nm_utils_str_utf8safe_escape_cp(nm_device_get_ip_iface(self), - NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL)); - } else - g_value_set_string(value, NULL); + g_value_set_string(value, priv->prop_ip_iface); break; case PROP_IFINDEX: g_value_set_int(value, priv->ifindex); @@ -18180,24 +16940,16 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) g_value_set_uint(value, priv->mtu); break; case PROP_IP4_CONFIG: - nm_dbus_utils_g_value_set_object_path(value, - ip_config_valid(priv->state) ? priv->ip_config_4 - : NULL); + nm_dbus_utils_g_value_set_object_path(value, priv->l3ipdata_4.ip_config); break; case PROP_DHCP4_CONFIG: - nm_dbus_utils_g_value_set_object_path( - value, - ip_config_valid(priv->state) ? priv->dhcp_data_4.config : NULL); + nm_dbus_utils_g_value_set_object_path(value, priv->ipdhcp_data_4.config); break; case PROP_IP6_CONFIG: - nm_dbus_utils_g_value_set_object_path(value, - ip_config_valid(priv->state) ? priv->ip_config_6 - : NULL); + nm_dbus_utils_g_value_set_object_path(value, priv->l3ipdata_6.ip_config); break; case PROP_DHCP6_CONFIG: - nm_dbus_utils_g_value_set_object_path( - value, - ip_config_valid(priv->state) ? priv->dhcp_data_6.config : NULL); + nm_dbus_utils_g_value_set_object_path(value, priv->ipdhcp_data_6.config); break; case PROP_STATE: g_value_set_uint(value, priv->state); @@ -18307,7 +17059,7 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - NMDevice * self = (NMDevice *) object; + NMDevice *self = (NMDevice *) object; NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); switch (prop_id) { @@ -18404,6 +17156,8 @@ nm_device_init(NMDevice *self) c_list_init(&self->devices_lst); c_list_init(&priv->slaves); + priv->ipdhcp_data_6.v6.mode = NM_NDISC_DHCP_LEVEL_NONE; + priv->concheck_x[0].state = NM_CONNECTIVITY_UNKNOWN; priv->concheck_x[1].state = NM_CONNECTIVITY_UNKNOWN; @@ -18429,19 +17183,16 @@ nm_device_init(NMDevice *self) priv->ip6_saved_properties = g_hash_table_new_full(nm_str_hash, g_str_equal, NULL, g_free); priv->sys_iface_state_ = NM_DEVICE_SYS_IFACE_STATE_EXTERNAL; - priv->v4_commit_first_time = TRUE; - priv->v6_commit_first_time = TRUE; - priv->promisc_reset = NM_OPTION_BOOL_DEFAULT; } static GObject * constructor(GType type, guint n_construct_params, GObjectConstructParam *construct_params) { - GObject * object; - GObjectClass * klass; - NMDevice * self; - NMDevicePrivate * priv; + GObject *object; + GObjectClass *klass; + NMDevice *self; + NMDevicePrivate *priv; const NMPlatformLink *pllink; klass = G_OBJECT_CLASS(nm_device_parent_class); @@ -18481,31 +17232,14 @@ constructor(GType type, guint n_construct_params, GObjectConstructParam *constru static void constructed(GObject *object) { - NMDevice * self = NM_DEVICE(object); + NMDevice *self = NM_DEVICE(object); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); - NMPlatform * platform; + NMPlatform *platform; if (NM_DEVICE_GET_CLASS(self)->get_generic_capabilities) priv->capabilities |= NM_DEVICE_GET_CLASS(self)->get_generic_capabilities(self); - /* Watch for external IP config changes */ platform = nm_device_get_platform(self); - g_signal_connect(platform, - NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED, - G_CALLBACK(device_ipx_changed), - self); - g_signal_connect(platform, - NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED, - G_CALLBACK(device_ipx_changed), - self); - g_signal_connect(platform, - NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, - G_CALLBACK(device_ipx_changed), - self); - g_signal_connect(platform, - NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, - G_CALLBACK(device_ipx_changed), - self); g_signal_connect(platform, NM_PLATFORM_SIGNAL_LINK_CHANGED, G_CALLBACK(link_changed_cb), self); priv->manager = g_object_ref(NM_MANAGER_GET); @@ -18532,11 +17266,11 @@ constructed(GObject *object) static void dispose(GObject *object) { - NMDevice * self = NM_DEVICE(object); - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - NMPlatform * platform; + NMDevice *self = NM_DEVICE(object); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NMPlatform *platform; NMDeviceConnectivityHandle *con_handle; - gs_free_error GError *cancelled_error = NULL; + gs_free_error GError *cancelled_error = NULL; _LOGD(LOGD_DEVICE, "disposing"); @@ -18557,15 +17291,12 @@ dispose(GObject *object) _parent_set_ifindex(self, 0, FALSE); platform = nm_device_get_platform(self); - g_signal_handlers_disconnect_by_func(platform, G_CALLBACK(device_ipx_changed), self); g_signal_handlers_disconnect_by_func(platform, G_CALLBACK(link_changed_cb), self); - arp_cleanup(self); - nm_clear_g_signal_handler(nm_config_get(), &priv->config_changed_id); nm_clear_g_signal_handler(priv->manager, &priv->ifindex_changed_id); - dispatcher_cleanup(self); + _dispatcher_cleanup(self); nm_pacrunner_manager_remove_clear(&priv->pacrunner_conf_id); @@ -18574,7 +17305,7 @@ dispose(GObject *object) nm_assert(c_list_is_empty(&priv->slaves)); /* Let the kernel manage IPv6LL again */ - set_nm_ipv6ll(self, FALSE); + _dev_addrgenmode6_set(self, NM_IN6_ADDR_GEN_MODE_EUI64); _cleanup_generic_post(self, CLEANUP_TYPE_KEEP); @@ -18621,6 +17352,10 @@ dispose(GObject *object) priv->sriov.next = NULL; } + g_clear_object(&priv->l3cfg); + g_clear_object(&priv->l3ipdata_4.ip_config); + g_clear_object(&priv->l3ipdata_6.ip_config); + G_OBJECT_CLASS(nm_device_parent_class)->dispose(object); if (nm_clear_g_source(&priv->queued_state.id)) { @@ -18634,7 +17369,7 @@ dispose(GObject *object) static void finalize(GObject *object) { - NMDevice * self = NM_DEVICE(object); + NMDevice *self = NM_DEVICE(object); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); _LOGD(LOGD_DEVICE, "finalize(): %s", G_OBJECT_TYPE_NAME(self)); @@ -18643,7 +17378,6 @@ finalize(GObject *object) g_free(priv->hw_addr_perm); g_free(priv->hw_addr_initial); g_free(priv->pending_actions.arr); - g_slist_free_full(priv->dad6_failed_addrs, (GDestroyNotify) nmp_object_unref); nm_clear_g_free(&priv->physical_port_id); g_free(priv->udi); g_free(priv->path); @@ -18806,7 +17540,7 @@ static const NMDBusInterfaceInfoExtended interface_info_device_statistics = { static void nm_device_class_init(NMDeviceClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); g_type_class_add_private(object_class, sizeof(NMDevicePrivate)); @@ -18824,10 +17558,9 @@ nm_device_class_init(NMDeviceClass *klass) klass->link_changed = link_changed; - klass->is_available = is_available; - klass->act_stage2_config = act_stage2_config; - klass->act_stage3_ip_config_start = act_stage3_ip_config_start; - klass->act_stage4_ip_config_timeout = act_stage4_ip_config_timeout; + klass->is_available = is_available; + klass->act_stage2_config = act_stage2_config; + klass->get_ip_method_auto = get_ip_method_auto; klass->get_type_description = get_type_description; klass->can_auto_connect = can_auto_connect; @@ -19166,29 +17899,17 @@ nm_device_class_init(NMDeviceClass *klass) G_TYPE_BOOLEAN, 0); - signals[IP4_CONFIG_CHANGED] = g_signal_new(NM_DEVICE_IP4_CONFIG_CHANGED, - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, - NULL, - NULL, - G_TYPE_NONE, - 2, - G_TYPE_OBJECT, - G_TYPE_OBJECT); - - signals[IP6_CONFIG_CHANGED] = g_signal_new(NM_DEVICE_IP6_CONFIG_CHANGED, - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, - NULL, - NULL, - G_TYPE_NONE, - 2, - G_TYPE_OBJECT, - G_TYPE_OBJECT); + signals[L3CD_CHANGED] = g_signal_new(NM_DEVICE_L3CD_CHANGED, + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_FIRST, + 0, + NULL, + NULL, + NULL, + G_TYPE_NONE, + 2, + G_TYPE_POINTER, /* (const NML3ConfigData *l3cd_old) */ + G_TYPE_POINTER /* (const NML3ConfigData *l3cd_new) */); signals[IP6_PREFIX_DELEGATED] = g_signal_new(NM_DEVICE_IP6_PREFIX_DELEGATED, @@ -19251,6 +17972,16 @@ nm_device_class_init(NMDeviceClass *klass) NULL, G_TYPE_NONE, 0); + + signals[PLATFORM_ADDRESS_CHANGED] = g_signal_new(NM_DEVICE_PLATFORM_ADDRESS_CHANGED, + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_FIRST, + 0, + NULL, + NULL, + NULL, + G_TYPE_NONE, + 0); } /* Connection defaults from plugins */ diff --git a/src/core/devices/nm-device.h b/src/core/devices/nm-device.h index d967bcb2..cfcd4ade 100644 --- a/src/core/devices/nm-device.h +++ b/src/core/devices/nm-device.h @@ -9,13 +9,14 @@ #include -#include "nm-setting-connection.h" -#include "nm-dbus-object.h" -#include "nm-dbus-interface.h" -#include "nm-connection.h" -#include "nm-rfkill-manager.h" #include "NetworkManagerUtils.h" +#include "nm-connection.h" +#include "nm-dbus-interface.h" +#include "nm-dbus-object.h" #include "nm-device-utils.h" +#include "nm-l3cfg.h" +#include "nm-rfkill-manager.h" +#include "nm-setting-connection.h" /* Properties */ #define NM_DEVICE_UDI "udi" @@ -70,17 +71,17 @@ #define NM_DEVICE_HAS_PENDING_ACTION "has-pending-action" /* Internal only */ /* Internal signals */ -#define NM_DEVICE_DNS_LOOKUP_DONE "dns-lookup-done" -#define NM_DEVICE_IP4_CONFIG_CHANGED "ip4-config-changed" -#define NM_DEVICE_IP6_CONFIG_CHANGED "ip6-config-changed" -#define NM_DEVICE_IP6_PREFIX_DELEGATED "ip6-prefix-delegated" -#define NM_DEVICE_IP6_SUBNET_NEEDED "ip6-subnet-needed" -#define NM_DEVICE_REMOVED "removed" -#define NM_DEVICE_RECHECK_AUTO_ACTIVATE "recheck-auto-activate" -#define NM_DEVICE_RECHECK_ASSUME "recheck-assume" -#define NM_DEVICE_STATE_CHANGED "state-changed" -#define NM_DEVICE_LINK_INITIALIZED "link-initialized" -#define NM_DEVICE_AUTOCONNECT_ALLOWED "autoconnect-allowed" +#define NM_DEVICE_DNS_LOOKUP_DONE "dns-lookup-done" +#define NM_DEVICE_L3CD_CHANGED "l3cd-changed" +#define NM_DEVICE_IP6_PREFIX_DELEGATED "ip6-prefix-delegated" +#define NM_DEVICE_IP6_SUBNET_NEEDED "ip6-subnet-needed" +#define NM_DEVICE_REMOVED "removed" +#define NM_DEVICE_RECHECK_AUTO_ACTIVATE "recheck-auto-activate" +#define NM_DEVICE_RECHECK_ASSUME "recheck-assume" +#define NM_DEVICE_STATE_CHANGED "state-changed" +#define NM_DEVICE_LINK_INITIALIZED "link-initialized" +#define NM_DEVICE_AUTOCONNECT_ALLOWED "autoconnect-allowed" +#define NM_DEVICE_PLATFORM_ADDRESS_CHANGED "platform-address-changed" #define NM_DEVICE_STATISTICS_REFRESH_RATE_MS "refresh-rate-ms" #define NM_DEVICE_STATISTICS_TX_BYTES "tx-bytes" @@ -169,7 +170,7 @@ typedef struct _NMDeviceClass { NMDBusObjectClass parent; struct _NMDeviceClass *default_type_description_klass; - const char * default_type_description; + const char *default_type_description; const char *connection_type_supported; @@ -208,7 +209,7 @@ typedef struct _NMDeviceClass { bool can_reapply_change_ovs_external_ids : 1; - void (*state_changed)(NMDevice * device, + void (*state_changed)(NMDevice *device, NMDeviceState new_state, NMDeviceState old_state, NMDeviceStateReason reason); @@ -232,11 +233,11 @@ typedef struct _NMDeviceClass { * * Returns: %TRUE on success, %FALSE on error */ - gboolean (*create_and_realize)(NMDevice * self, - NMConnection * connection, - NMDevice * parent, + gboolean (*create_and_realize)(NMDevice *self, + NMConnection *connection, + NMDevice *parent, const NMPlatformLink **out_plink, - GError ** error); + GError **error); /** * realize_start_notify(): @@ -294,13 +295,13 @@ typedef struct _NMDeviceClass { * which emits NM_DEVICE_RECHECK_AUTO_ACTIVATE signal. */ gboolean (*get_autoconnect_allowed)(NMDevice *self); - gboolean (*can_auto_connect)(NMDevice * self, + gboolean (*can_auto_connect)(NMDevice *self, NMSettingsConnection *sett_conn, - char ** specific_object); + char **specific_object); - guint32 (*get_configured_mtu)(NMDevice * self, + guint32 (*get_configured_mtu)(NMDevice *self, NMDeviceMtuSource *out_source, - gboolean * out_force); + gboolean *out_force); /* allow the subclass to overwrite the routing table. This is mainly useful * to change from partial mode (route-table=0) to full-sync mode (route-table=254). */ @@ -315,9 +316,9 @@ typedef struct _NMDeviceClass { * only the devices type and characteristics. Does not use any live * network information like Wi-Fi scan lists etc. */ - gboolean (*check_connection_compatible)(NMDevice * self, + gboolean (*check_connection_compatible)(NMDevice *self, NMConnection *connection, - GError ** error); + GError **error); /* Checks whether the connection is likely available to be activated, * including any live network information like scan lists. The connection @@ -330,33 +331,28 @@ typedef struct _NMDeviceClass { * * Specifying @specific_object can only reduce the availability of a connection. */ - gboolean (*check_connection_available)(NMDevice * self, - NMConnection * connection, + gboolean (*check_connection_available)(NMDevice *self, + NMConnection *connection, NMDeviceCheckConAvailableFlags flags, - const char * specific_object, - GError ** error); + const char *specific_object, + GError **error); - gboolean (*complete_connection)(NMDevice * self, - NMConnection * connection, - const char * specific_object, + gboolean (*complete_connection)(NMDevice *self, + NMConnection *connection, + const char *specific_object, NMConnection *const *existing_connections, - GError ** error); + GError **error); NMActStageReturn (*act_stage1_prepare)(NMDevice *self, NMDeviceStateReason *out_failure_reason); NMActStageReturn (*act_stage2_config)(NMDevice *self, NMDeviceStateReason *out_failure_reason); - NMActStageReturn (*act_stage3_ip_config_start)(NMDevice * self, - int addr_family, - gpointer * out_config, - NMDeviceStateReason *out_failure_reason); - NMActStageReturn (*act_stage4_ip_config_timeout)(NMDevice * self, - int addr_family, - NMDeviceStateReason *out_failure_reason); + void (*act_stage3_ip_config)(NMDevice *self, int addr_family); + gboolean (*ready_for_ip_config)(NMDevice *self); - void (*ip4_config_pre_commit)(NMDevice *self, NMIP4Config *config); + const char *(*get_ip_method_auto)(NMDevice *self, int addr_family); /* Async deactivating (in the DEACTIVATING phase) */ - void (*deactivate_async)(NMDevice * self, - GCancellable * cancellable, + void (*deactivate_async)(NMDevice *self, + GCancellable *cancellable, NMDeviceDeactivateCallback callback, gpointer user_data); @@ -372,13 +368,13 @@ typedef struct _NMDeviceClass { /* Update the connection with currently configured L2 settings */ void (*update_connection)(NMDevice *device, NMConnection *connection); - gboolean (*master_update_slave_connection)(NMDevice * self, - NMDevice * slave, + gboolean (*master_update_slave_connection)(NMDevice *self, + NMDevice *slave, NMConnection *connection, - GError ** error); + GError **error); - gboolean (*enslave_slave)(NMDevice * self, - NMDevice * slave, + gboolean (*enslave_slave)(NMDevice *self, + NMDevice *slave, NMConnection *connection, gboolean configure); @@ -396,12 +392,12 @@ typedef struct _NMDeviceClass { gboolean (*unmanaged_on_quit)(NMDevice *self); - gboolean (*can_reapply_change)(NMDevice * self, + gboolean (*can_reapply_change)(NMDevice *self, const char *setting_name, - NMSetting * s_old, - NMSetting * s_new, + NMSetting *s_old, + NMSetting *s_new, GHashTable *diffs, - GError ** error); + GError **error); void (*reapply_connection)(NMDevice *self, NMConnection *con_old, NMConnection *con_new); @@ -420,8 +416,8 @@ typedef struct _NMDeviceClass { GType nm_device_get_type(void); struct _NMDedupMultiIndex *nm_device_get_multi_index(NMDevice *self); -NMNetns * nm_device_get_netns(NMDevice *self); -NMPlatform * nm_device_get_platform(NMDevice *self); +NMNetns *nm_device_get_netns(NMDevice *self); +NMPlatform *nm_device_get_platform(NMDevice *self); const char *nm_device_get_udi(NMDevice *dev); const char *nm_device_get_iface(NMDevice *dev); @@ -437,13 +433,13 @@ _nm_device_get_iface(NMDevice *device) int nm_device_get_ifindex(NMDevice *dev); gboolean nm_device_is_software(NMDevice *dev); gboolean nm_device_is_real(NMDevice *dev); -const char * nm_device_get_ip_iface(NMDevice *dev); -const char * nm_device_get_ip_iface_from_platform(NMDevice *dev); +const char *nm_device_get_ip_iface(NMDevice *dev); +const char *nm_device_get_ip_iface_from_platform(NMDevice *dev); int nm_device_get_ip_ifindex(const NMDevice *dev); -const char * nm_device_get_driver(NMDevice *dev); -const char * nm_device_get_driver_version(NMDevice *dev); -const char * nm_device_get_type_desc(NMDevice *dev); -const char * nm_device_get_type_description(NMDevice *dev); +const char *nm_device_get_driver(NMDevice *dev); +const char *nm_device_get_driver_version(NMDevice *dev); +const char *nm_device_get_type_desc(NMDevice *dev); +const char *nm_device_get_type_description(NMDevice *dev); NMDeviceType nm_device_get_device_type(NMDevice *dev); NMLinkType nm_device_get_link_type(NMDevice *dev); NMMetered nm_device_get_metered(NMDevice *dev); @@ -460,16 +456,13 @@ const char *nm_device_get_permanent_hw_address_full(NMDevice *self, gboolean *out_is_fake); const char *nm_device_get_initial_hw_address(NMDevice *dev); -NMProxyConfig *nm_device_get_proxy_config(NMDevice *dev); - NMDhcpConfig *nm_device_get_dhcp_config(NMDevice *dev, int addr_family); -NMIP4Config * nm_device_get_ip4_config(NMDevice *dev); -void nm_device_replace_vpn4_config(NMDevice *dev, NMIP4Config *old, NMIP4Config *config); -NMIP6Config *nm_device_get_ip6_config(NMDevice *dev); -void nm_device_replace_vpn6_config(NMDevice *dev, NMIP6Config *old, NMIP6Config *config); +NML3Cfg *nm_device_get_l3cfg(NMDevice *self); + +const NML3ConfigData *nm_device_get_l3cd(NMDevice *self, gboolean get_commited); -void nm_device_capture_initial_config(NMDevice *dev); +void nm_device_l3cfg_commit(NMDevice *self, NML3CfgCommitType commit_type, gboolean commit_sync); int nm_device_parent_get_ifindex(NMDevice *dev); NMDevice *nm_device_parent_get_device(NMDevice *dev); @@ -478,7 +471,7 @@ gboolean nm_device_parent_notify_changed(NMDevice *self, NMDevice *change_candidate, gboolean device_removed); -const char *nm_device_parent_find_for_connection(NMDevice * self, +const char *nm_device_parent_find_for_connection(NMDevice *self, const char *current_setting_parent); /* Master */ @@ -487,11 +480,11 @@ gboolean nm_device_is_master(NMDevice *dev); /* Slave */ NMDevice *nm_device_get_master(NMDevice *dev); -NMActRequest * nm_device_get_act_request(NMDevice *dev); -NMSettingsConnection * nm_device_get_settings_connection(NMDevice *dev); -NMConnection * nm_device_get_settings_connection_get_connection(NMDevice *self); -NMConnection * nm_device_get_applied_connection(NMDevice *dev); -gboolean nm_device_has_unmodified_applied_connection(NMDevice * self, +NMActRequest *nm_device_get_act_request(NMDevice *dev); +NMSettingsConnection *nm_device_get_settings_connection(NMDevice *dev); +NMConnection *nm_device_get_settings_connection_get_connection(NMDevice *self); +NMConnection *nm_device_get_applied_connection(NMDevice *dev); +gboolean nm_device_has_unmodified_applied_connection(NMDevice *self, NMSettingCompareFlags compare_flags); NMActivationStateFlags nm_device_get_activation_state_flags(NMDevice *self); @@ -507,21 +500,21 @@ gboolean nm_device_has_carrier(NMDevice *dev); NMConnection *nm_device_generate_connection(NMDevice *self, NMDevice *master, gboolean *out_maybe_later, - GError ** error); + GError **error); -gboolean nm_device_master_update_slave_connection(NMDevice * master, - NMDevice * slave, +gboolean nm_device_master_update_slave_connection(NMDevice *master, + NMDevice *slave, NMConnection *connection, - GError ** error); + GError **error); gboolean nm_device_can_auto_connect(NMDevice *self, NMSettingsConnection *sett_conn, char **specific_object); -gboolean nm_device_complete_connection(NMDevice * device, - NMConnection * connection, - const char * specific_object, +gboolean nm_device_complete_connection(NMDevice *device, + NMConnection *connection, + const char *specific_object, NMConnection *const *existing_connections, - GError ** error); + GError **error); gboolean nm_device_check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error); @@ -547,7 +540,7 @@ RfKillType nm_device_get_rfkill_type(NMDevice *device); /* IPv6 prefix delegation */ -void nm_device_request_ip6_prefixes(NMDevice *self, int needed_prefixes); +void nm_device_request_ip6_prefixes(NMDevice *self, guint needed_prefixes); gboolean nm_device_needs_ip6_subnet(NMDevice *self); @@ -620,15 +613,15 @@ gboolean nm_device_get_managed(NMDevice *device, gboolean for_user_reque NMUnmanagedFlags nm_device_get_unmanaged_mask(NMDevice *device, NMUnmanagedFlags flag); NMUnmanagedFlags nm_device_get_unmanaged_flags(NMDevice *device, NMUnmanagedFlags flag); void nm_device_set_unmanaged_flags(NMDevice *device, NMUnmanagedFlags flags, NMUnmanFlagOp set_op); -void nm_device_set_unmanaged_by_flags(NMDevice * device, +void nm_device_set_unmanaged_by_flags(NMDevice *device, NMUnmanagedFlags flags, NMUnmanFlagOp set_op, NMDeviceStateReason reason); -void nm_device_set_unmanaged_by_flags_queue(NMDevice * self, +void nm_device_set_unmanaged_by_flags_queue(NMDevice *self, NMUnmanagedFlags flags, NMUnmanFlagOp set_op, NMDeviceStateReason reason); -void nm_device_set_unmanaged_by_user_settings(NMDevice *self); +void nm_device_set_unmanaged_by_user_settings(NMDevice *self, gboolean now); void nm_device_set_unmanaged_by_user_udev(NMDevice *self); void nm_device_set_unmanaged_by_user_conf(NMDevice *self); void nm_device_set_unmanaged_by_quitting(NMDevice *device); @@ -641,26 +634,26 @@ gboolean nm_device_has_capability(NMDevice *self, NMDeviceCapabilities caps); /*****************************************************************************/ -void nm_device_assume_state_get(NMDevice * self, - gboolean * out_assume_state_guess_assume, +void nm_device_assume_state_get(NMDevice *self, + gboolean *out_assume_state_guess_assume, const char **out_assume_state_connection_uuid); void nm_device_assume_state_reset(NMDevice *self); /*****************************************************************************/ -gboolean nm_device_realize_start(NMDevice * device, +gboolean nm_device_realize_start(NMDevice *device, const NMPlatformLink *plink, gboolean assume_state_guess_assume, - const char * assume_state_connection_uuid, + const char *assume_state_connection_uuid, gboolean set_nm_owned, NMUnmanFlagOp unmanaged_user_explicit, - gboolean * out_compatible, - GError ** error); + gboolean *out_compatible, + GError **error); void nm_device_realize_finish(NMDevice *self, const NMPlatformLink *plink); -gboolean nm_device_create_and_realize(NMDevice * self, +gboolean nm_device_create_and_realize(NMDevice *self, NMConnection *connection, - NMDevice * parent, - GError ** error); + NMDevice *parent, + GError **error); gboolean nm_device_unrealize(NMDevice *device, gboolean remove_resources, GError **error); void nm_device_update_from_platform_link(NMDevice *self, const NMPlatformLink *plink); @@ -686,7 +679,7 @@ typedef enum { NMDeviceAutoconnectBlockedFlags nm_device_autoconnect_blocked_get(NMDevice *device, NMDeviceAutoconnectBlockedFlags mask); -void nm_device_autoconnect_blocked_set_full(NMDevice * device, +void nm_device_autoconnect_blocked_set_full(NMDevice *device, NMDeviceAutoconnectBlockedFlags mask, NMDeviceAutoconnectBlockedFlags values); @@ -717,7 +710,7 @@ void nm_device_queue_state(NMDevice *self, NMDeviceState state, NMDeviceStateRea gboolean nm_device_get_firmware_missing(NMDevice *self); -void nm_device_disconnect_active_connection(NMActiveConnection * active, +void nm_device_disconnect_active_connection(NMActiveConnection *active, NMDeviceStateReason device_reason, NMActiveConnectionStateReason active_reason); @@ -740,11 +733,11 @@ nm_device_has_pending_action(NMDevice *device) NMSettingsConnection * nm_device_get_best_connection(NMDevice *device, const char *specific_object, GError **error); -gboolean nm_device_check_connection_available(NMDevice * device, - NMConnection * connection, +gboolean nm_device_check_connection_available(NMDevice *device, + NMConnection *connection, NMDeviceCheckConAvailableFlags flags, - const char * specific_object, - GError ** error); + const char *specific_object, + GError **error); void nm_device_notify_availability_maybe_changed(NMDevice *self); @@ -754,17 +747,11 @@ NMConnection *nm_device_new_default_connection(NMDevice *self); const NMPObject *nm_device_get_best_default_route(NMDevice *self, int addr_family); -void nm_device_spawn_iface_helper(NMDevice *self); - gboolean nm_device_reapply(NMDevice *self, NMConnection *connection, GError **error); void nm_device_reapply_settings_immediately(NMDevice *self); void nm_device_update_firewall_zone(NMDevice *self); void nm_device_update_metered(NMDevice *self); -void nm_device_reactivate_ip_config(NMDevice * device, - int addr_family, - NMSettingIPConfig *s_ip_old, - NMSettingIPConfig *s_ip_new); gboolean nm_device_update_hw_address(NMDevice *self); void nm_device_update_initial_hw_address(NMDevice *self); @@ -774,24 +761,24 @@ guint nm_device_get_supplicant_timeout(NMDevice *self); gboolean nm_device_auth_retries_try_next(NMDevice *self); -gboolean nm_device_hw_addr_get_cloned(NMDevice * self, +gboolean nm_device_hw_addr_get_cloned(NMDevice *self, NMConnection *connection, gboolean is_wifi, - char ** hwaddr, - gboolean * preserve, - GError ** error); + char **hwaddr, + gboolean *preserve, + GError **error); typedef struct _NMDeviceConnectivityHandle NMDeviceConnectivityHandle; -typedef void (*NMDeviceConnectivityCallback)(NMDevice * self, +typedef void (*NMDeviceConnectivityCallback)(NMDevice *self, NMDeviceConnectivityHandle *handle, NMConnectivityState state, - GError * error, + GError *error, gpointer user_data); void nm_device_check_connectivity_update_interval(NMDevice *self); -NMDeviceConnectivityHandle *nm_device_check_connectivity(NMDevice * self, +NMDeviceConnectivityHandle *nm_device_check_connectivity(NMDevice *self, int addr_family, NMDeviceConnectivityCallback callback, gpointer user_data); @@ -806,16 +793,16 @@ typedef void (*NMBtVTableRegisterCallback)(GError *error, gpointer user_data); struct _NMBtVTableNetworkServer { gboolean (*is_available)(const NMBtVTableNetworkServer *vtable, - const char * addr, - NMDevice * device_accept_busy); + const char *addr, + NMDevice *device_accept_busy); gboolean (*register_bridge)(const NMBtVTableNetworkServer *vtable, - const char * addr, - NMDevice * device, - GCancellable * cancellable, + const char *addr, + NMDevice *device, + GCancellable *cancellable, NMBtVTableRegisterCallback callback, gpointer callback_user_data, - GError ** error); + GError **error); gboolean (*unregister_bridge)(const NMBtVTableNetworkServer *vtable, NMDevice *device); }; diff --git a/src/core/devices/nm-lldp-listener.c b/src/core/devices/nm-lldp-listener.c index 4e178491..137bf8fb 100644 --- a/src/core/devices/nm-lldp-listener.c +++ b/src/core/devices/nm-lldp-listener.c @@ -34,7 +34,7 @@ struct _NMLldpListener { sd_lldp_rx *lldp_handle; GHashTable *lldp_neighbors; - GVariant * variant; + GVariant *variant; NMLldpListenerNotify notify_callback; gpointer notify_user_data; @@ -49,10 +49,10 @@ struct _NMLldpListener { /*****************************************************************************/ typedef struct { - GVariant * variant; + GVariant *variant; sd_lldp_neighbor *neighbor_sd; - char * chassis_id; - char * port_id; + char *chassis_id; + char *port_id; guint8 chassis_id_type; guint8 port_id_type; } LldpNeighbor; @@ -112,12 +112,12 @@ lldp_neighbor_get_raw(LldpNeighbor *neigh, const guint8 **out_raw_data, gsize *o static gboolean lldp_neighbor_id_get(struct sd_lldp_neighbor *neighbor_sd, - guint8 * out_chassis_id_type, - const guint8 ** out_chassis_id, - gsize * out_chassis_id_len, - guint8 * out_port_id_type, - const guint8 ** out_port_id, - gsize * out_port_id_len) + guint8 *out_chassis_id_type, + const guint8 **out_chassis_id, + gsize *out_chassis_id_len, + guint8 *out_port_id_type, + const guint8 **out_port_id, + gsize *out_port_id_len) { int r; @@ -144,8 +144,8 @@ lldp_neighbor_id_hash(gconstpointer ptr) const LldpNeighbor *neigh = ptr; guint8 chassis_id_type; guint8 port_id_type; - const guint8 * chassis_id; - const guint8 * port_id; + const guint8 *chassis_id; + const guint8 *port_id; gsize chassis_id_len; gsize port_id_len; NMHashState h; @@ -270,9 +270,9 @@ parse_management_address_tlv(const uint8_t *data, gsize len) { GVariantBuilder builder; gsize addr_len; - const guint8 * v_object_id_arr; + const guint8 *v_object_id_arr; gsize v_object_id_len; - const guint8 * v_address_arr; + const guint8 *v_address_arr; gsize v_address_len; guint32 v_interface_number; guint32 v_interface_number_subtype; @@ -393,7 +393,7 @@ format_string(const guint8 *data, gsize len, gboolean allow_trim, char **out_to_ static char * format_string_cp(const guint8 *data, gsize len, gboolean allow_trim) { - char * s_free = NULL; + char *s_free = NULL; const char *s; s = format_string(data, len, allow_trim, &s_free); @@ -482,11 +482,11 @@ lldp_neighbor_to_variant(LldpNeighbor *neigh) { struct ether_addr destination_address; GVariantBuilder builder; - const char * str; - const guint8 * raw_data; + const char *str; + const guint8 *raw_data; gsize raw_len; uint16_t u16; - uint8_t * data8; + uint8_t *data8; gsize len; int r; @@ -537,19 +537,19 @@ lldp_neighbor_to_variant(LldpNeighbor *neigh) else { gboolean v_management_addresses_has = FALSE; GVariantBuilder v_management_addresses; - GVariant * v_ieee_802_1_pvid = NULL; - GVariant * v_ieee_802_1_ppvid = NULL; - GVariant * v_ieee_802_1_ppvid_flags = NULL; + GVariant *v_ieee_802_1_pvid = NULL; + GVariant *v_ieee_802_1_ppvid = NULL; + GVariant *v_ieee_802_1_ppvid_flags = NULL; GVariantBuilder v_ieee_802_1_ppvids; - GVariant * v_ieee_802_1_vid = NULL; - GVariant * v_ieee_802_1_vlan_name = NULL; + GVariant *v_ieee_802_1_vid = NULL; + GVariant *v_ieee_802_1_vlan_name = NULL; GVariantBuilder v_ieee_802_1_vlans; - GVariant * v_ieee_802_3_mac_phy_conf = NULL; - GVariant * v_ieee_802_3_power_via_mdi = NULL; - GVariant * v_ieee_802_3_max_frame_size = NULL; - GVariant * v_mud_url = NULL; + GVariant *v_ieee_802_3_mac_phy_conf = NULL; + GVariant *v_ieee_802_3_power_via_mdi = NULL; + GVariant *v_ieee_802_3_max_frame_size = NULL; + GVariant *v_mud_url = NULL; GVariantBuilder tmp_builder; - GVariant * tmp_variant; + GVariant *tmp_variant; do { guint8 oui[3]; @@ -636,7 +636,7 @@ lldp_neighbor_to_variant(LldpNeighbor *neigh) case SD_LLDP_OUI_802_1_SUBTYPE_VLAN_NAME: { gs_free char *name_to_free = NULL; - const char * name; + const char *name; guint32 vid; gsize l; @@ -716,7 +716,7 @@ lldp_neighbor_to_variant(LldpNeighbor *neigh) case SD_LLDP_OUI_IANA_SUBTYPE_MUD: if (!v_mud_url) { gs_free char *s_free = NULL; - const char * s; + const char *s; s = format_string(data8, len, TRUE, &s_free); if (s) @@ -778,8 +778,8 @@ GVariant * nmtst_lldp_parse_from_raw(const guint8 *raw_data, gsize raw_len) { nm_auto(sd_lldp_neighbor_unrefp) sd_lldp_neighbor *neighbor_sd = NULL; - nm_auto(lldp_neighbor_freep) LldpNeighbor * neigh = NULL; - GVariant * variant; + nm_auto(lldp_neighbor_freep) LldpNeighbor *neigh = NULL; + GVariant *variant; int r; g_assert(raw_data); @@ -846,7 +846,7 @@ static void process_lldp_neighbor(NMLldpListener *self, sd_lldp_neighbor *neighbor_sd, gboolean remove) { nm_auto(lldp_neighbor_freep) LldpNeighbor *neigh = NULL; - LldpNeighbor * neigh_old; + LldpNeighbor *neigh_old; nm_assert(self); nm_assert(self->lldp_handle); @@ -933,10 +933,10 @@ NMLldpListener * nm_lldp_listener_new(int ifindex, NMLldpListenerNotify notify_callback, gpointer notify_user_data, - GError ** error) + GError **error) { NMLldpListener *self = NULL; - sd_lldp_rx * lldp_handle; + sd_lldp_rx *lldp_handle; int r; g_return_val_if_fail(ifindex > 0, FALSE); diff --git a/src/core/devices/nm-lldp-listener.h b/src/core/devices/nm-lldp-listener.h index 762eb3d2..f2e9bcd2 100644 --- a/src/core/devices/nm-lldp-listener.h +++ b/src/core/devices/nm-lldp-listener.h @@ -13,7 +13,7 @@ typedef void (*NMLldpListenerNotify)(NMLldpListener *self, gpointer user_data); NMLldpListener *nm_lldp_listener_new(int ifindex, NMLldpListenerNotify notify_callback, gpointer notify_user_data, - GError ** error); + GError **error); void nm_lldp_listener_destroy(NMLldpListener *self); int nm_lldp_listener_get_ifindex(NMLldpListener *self); diff --git a/src/core/devices/ovs/nm-device-ovs-bridge.c b/src/core/devices/ovs/nm-device-ovs-bridge.c index 26a5ba00..683ada13 100644 --- a/src/core/devices/ovs/nm-device-ovs-bridge.c +++ b/src/core/devices/ovs/nm-device-ovs-bridge.c @@ -42,11 +42,11 @@ get_type_description(NMDevice *device) } static gboolean -create_and_realize(NMDevice * device, - NMConnection * connection, - NMDevice * parent, +create_and_realize(NMDevice *device, + NMConnection *connection, + NMDevice *parent, const NMPlatformLink **out_plink, - GError ** error) + GError **error) { /* The actual backing resources will be created on enslavement by the port * when it can identify the port and the bridge. */ @@ -66,13 +66,16 @@ get_generic_capabilities(NMDevice *device) return NM_DEVICE_CAP_IS_SOFTWARE; } -static NMActStageReturn -act_stage3_ip_config_start(NMDevice * device, - int addr_family, - gpointer * out_config, - NMDeviceStateReason *out_failure_reason) +static gboolean +ready_for_ip_config(NMDevice *device) +{ + return FALSE; +} + +static void +act_stage3_ip_config(NMDevice *device, int addr_family) { - return NM_ACT_STAGE_RETURN_IP_FAIL; + nm_device_devip_set_state(device, addr_family, NM_DEVICE_IP_STATE_READY, NULL); } static gboolean @@ -141,7 +144,7 @@ static void nm_device_ovs_bridge_class_init(NMDeviceOvsBridgeClass *klass) { NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS(&interface_info_device_ovs_bridge); @@ -154,7 +157,8 @@ nm_device_ovs_bridge_class_init(NMDeviceOvsBridgeClass *klass) device_class->create_and_realize = create_and_realize; device_class->unrealize = unrealize; device_class->get_generic_capabilities = get_generic_capabilities; - device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; + device_class->act_stage3_ip_config = act_stage3_ip_config; + device_class->ready_for_ip_config = ready_for_ip_config; device_class->enslave_slave = enslave_slave; device_class->release_slave = release_slave; device_class->can_reapply_change_ovs_external_ids = TRUE; diff --git a/src/core/devices/ovs/nm-device-ovs-interface.c b/src/core/devices/ovs/nm-device-ovs-interface.c index 46a612ac..74707d24 100644 --- a/src/core/devices/ovs/nm-device-ovs-interface.c +++ b/src/core/devices/ovs/nm-device-ovs-interface.c @@ -49,11 +49,11 @@ get_type_description(NMDevice *device) } static gboolean -create_and_realize(NMDevice * device, - NMConnection * connection, - NMDevice * parent, +create_and_realize(NMDevice *device, + NMConnection *connection, + NMDevice *parent, const NMPlatformLink **out_plink, - GError ** error) + GError **error) { /* The actual backing resources will be created once an interface is * added to a port of ours, since there can be neither an empty port nor @@ -71,7 +71,7 @@ get_generic_capabilities(NMDevice *device) static gboolean is_available(NMDevice *device, NMDeviceCheckDevAvailableFlags flags) { - NMDeviceOvsInterface * self = NM_DEVICE_OVS_INTERFACE(device); + NMDeviceOvsInterface *self = NM_DEVICE_OVS_INTERFACE(device); NMDeviceOvsInterfacePrivate *priv = NM_DEVICE_OVS_INTERFACE_GET_PRIVATE(self); return nm_ovsdb_is_ready(priv->ovsdb); @@ -80,7 +80,7 @@ is_available(NMDevice *device, NMDeviceCheckDevAvailableFlags flags) static gboolean can_auto_connect(NMDevice *device, NMSettingsConnection *sett_conn, char **specific_object) { - NMDeviceOvsInterface * self = NM_DEVICE_OVS_INTERFACE(device); + NMDeviceOvsInterface *self = NM_DEVICE_OVS_INTERFACE(device); NMDeviceOvsInterfacePrivate *priv = NM_DEVICE_OVS_INTERFACE_GET_PRIVATE(self); return nm_ovsdb_is_ready(priv->ovsdb); @@ -124,14 +124,19 @@ link_changed(NMDevice *device, const NMPlatformLink *pllink) if (!nm_device_hw_addr_set_cloned(device, nm_device_get_applied_connection(device), FALSE)) { - nm_device_state_changed(device, - NM_DEVICE_STATE_FAILED, - NM_DEVICE_STATE_REASON_CONFIG_FAILED); + nm_device_devip_set_failed(device, AF_INET, NM_DEVICE_STATE_REASON_CONFIG_FAILED); + nm_device_devip_set_failed(device, AF_INET6, NM_DEVICE_STATE_REASON_CONFIG_FAILED); return; } nm_device_bring_up(device, TRUE, NULL); - nm_device_activate_schedule_stage3_ip_config_start(device); + + nm_device_devip_set_state(device, AF_INET, NM_DEVICE_IP_STATE_PENDING, NULL); + nm_device_devip_set_state(device, AF_INET6, NM_DEVICE_IP_STATE_PENDING, NULL); + nm_device_activate_schedule_stage3_ip_config(device, FALSE); + return; } + + nm_device_activate_schedule_stage2_device_config(device, FALSE); } static gboolean @@ -149,7 +154,7 @@ _is_internal_interface(NMDevice *device) static void set_platform_mtu_cb(GError *error, gpointer user_data) { - NMDevice * device = user_data; + NMDevice *device = user_data; NMDeviceOvsInterface *self = NM_DEVICE_OVS_INTERFACE(device); if (error && !g_error_matches(error, NM_UTILS_ERROR, NM_UTILS_ERROR_CANCELLED_DISPOSING)) { @@ -165,7 +170,7 @@ set_platform_mtu_cb(GError *error, gpointer user_data) static gboolean set_platform_mtu(NMDevice *device, guint32 mtu) { - NMDeviceOvsInterface * self = NM_DEVICE_OVS_INTERFACE(device); + NMDeviceOvsInterface *self = NM_DEVICE_OVS_INTERFACE(device); NMDeviceOvsInterfacePrivate *priv = NM_DEVICE_OVS_INTERFACE_GET_PRIVATE(self); /* @@ -188,31 +193,43 @@ set_platform_mtu(NMDevice *device, guint32 mtu) return NM_DEVICE_CLASS(nm_device_ovs_interface_parent_class)->set_platform_mtu(device, mtu); } -static NMActStageReturn -act_stage3_ip_config_start(NMDevice * device, - int addr_family, - gpointer * out_config, - NMDeviceStateReason *out_failure_reason) +static gboolean +ready_for_ip_config(NMDevice *device) { - NMDeviceOvsInterface * self = NM_DEVICE_OVS_INTERFACE(device); - NMDeviceOvsInterfacePrivate *priv = NM_DEVICE_OVS_INTERFACE_GET_PRIVATE(device); + return nm_device_get_ip_ifindex(device) > 0; +} + +static void +act_stage3_ip_config(NMDevice *device, int addr_family) +{ + NMDeviceOvsInterface *self = NM_DEVICE_OVS_INTERFACE(device); + NMDeviceOvsInterfacePrivate *priv = NM_DEVICE_OVS_INTERFACE_GET_PRIVATE(self); - if (!_is_internal_interface(device)) - return NM_ACT_STAGE_RETURN_IP_FAIL; + if (!_is_internal_interface(device)) { + nm_device_devip_set_state(device, addr_family, NM_DEVICE_IP_STATE_READY, NULL); + return; + } + /* FIXME(l3cfg): we should create the IP ifindex before stage3 start. + * + * For now it's here because when the ovs-interface enters stage3, then it's added to the + * controller (ovs-port) and the entry is create in the ovsdb. Only after that the kernel + * link appears. + * + * This should change. */ if (nm_device_get_ip_ifindex(device) <= 0) { _LOGT(LOGD_DEVICE, "waiting for link to appear"); priv->waiting_for_interface = TRUE; - return NM_ACT_STAGE_RETURN_POSTPONE; + nm_device_devip_set_state(device, addr_family, NM_DEVICE_IP_STATE_PENDING, NULL); + return; } if (!nm_device_hw_addr_set_cloned(device, nm_device_get_applied_connection(device), FALSE)) { - *out_failure_reason = NM_DEVICE_STATE_REASON_CONFIG_FAILED; - return NM_ACT_STAGE_RETURN_FAILURE; + nm_device_devip_set_failed(device, addr_family, NM_DEVICE_STATE_REASON_CONFIG_FAILED); + return; } - return NM_DEVICE_CLASS(nm_device_ovs_interface_parent_class) - ->act_stage3_ip_config_start(device, addr_family, out_config, out_failure_reason); + nm_device_devip_set_state(device, addr_family, NM_DEVICE_IP_STATE_READY, NULL); } static gboolean @@ -224,15 +241,15 @@ can_unmanaged_external_down(NMDevice *self) static void deactivate(NMDevice *device) { - NMDeviceOvsInterface * self = NM_DEVICE_OVS_INTERFACE(device); + NMDeviceOvsInterface *self = NM_DEVICE_OVS_INTERFACE(device); NMDeviceOvsInterfacePrivate *priv = NM_DEVICE_OVS_INTERFACE_GET_PRIVATE(self); priv->waiting_for_interface = FALSE; } typedef struct { - NMDeviceOvsInterface * self; - GCancellable * cancellable; + NMDeviceOvsInterface *self; + GCancellable *cancellable; NMDeviceDeactivateCallback callback; gpointer callback_user_data; gulong link_changed_id; @@ -258,14 +275,14 @@ deactivate_invoke_cb(DeactivateData *data, GError *error) } static void -deactivate_link_changed_cb(NMPlatform * platform, +deactivate_link_changed_cb(NMPlatform *platform, int obj_type_i, int ifindex, NMPlatformLink *info, int change_type_i, DeactivateData *data) { - NMDeviceOvsInterface * self = data->self; + NMDeviceOvsInterface *self = data->self; const NMPlatformSignalChangeType change_type = change_type_i; if (change_type == NM_PLATFORM_SIGNAL_REMOVED @@ -280,7 +297,7 @@ deactivate_link_changed_cb(NMPlatform * platform, static gboolean deactivate_link_timeout(gpointer user_data) { - DeactivateData * data = user_data; + DeactivateData *data = user_data; NMDeviceOvsInterface *self = data->self; _LOGT(LOGD_DEVICE, "deactivate: timeout waiting link removal"); @@ -300,7 +317,7 @@ deactivate_cancelled_cb(GCancellable *cancellable, gpointer user_data) static void deactivate_cb_on_idle(gpointer user_data, GCancellable *cancellable) { - DeactivateData *data = user_data; + DeactivateData *data = user_data; gs_free_error GError *cancelled_error = NULL; g_cancellable_set_error_if_cancelled(data->cancellable, &cancelled_error); @@ -308,14 +325,14 @@ deactivate_cb_on_idle(gpointer user_data, GCancellable *cancellable) } static void -deactivate_async(NMDevice * device, - GCancellable * cancellable, +deactivate_async(NMDevice *device, + GCancellable *cancellable, NMDeviceDeactivateCallback callback, gpointer callback_user_data) { - NMDeviceOvsInterface * self = NM_DEVICE_OVS_INTERFACE(device); + NMDeviceOvsInterface *self = NM_DEVICE_OVS_INTERFACE(device); NMDeviceOvsInterfacePrivate *priv = NM_DEVICE_OVS_INTERFACE_GET_PRIVATE(self); - DeactivateData * data; + DeactivateData *data; _LOGT(LOGD_CORE, "deactivate: start async"); @@ -402,7 +419,7 @@ nm_device_ovs_interface_init(NMDeviceOvsInterface *self) static void dispose(GObject *object) { - NMDeviceOvsInterface * self = NM_DEVICE_OVS_INTERFACE(object); + NMDeviceOvsInterface *self = NM_DEVICE_OVS_INTERFACE(object); NMDeviceOvsInterfacePrivate *priv = NM_DEVICE_OVS_INTERFACE_GET_PRIVATE(self); if (priv->ovsdb) { @@ -420,9 +437,9 @@ static const NMDBusInterfaceInfoExtended interface_info_device_ovs_interface = { static void nm_device_ovs_interface_class_init(NMDeviceOvsInterfaceClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->dispose = dispose; @@ -443,7 +460,8 @@ nm_device_ovs_interface_class_init(NMDeviceOvsInterfaceClass *klass) device_class->is_available = is_available; device_class->check_connection_compatible = check_connection_compatible; device_class->link_changed = link_changed; - device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; + device_class->act_stage3_ip_config = act_stage3_ip_config; + device_class->ready_for_ip_config = ready_for_ip_config; device_class->can_unmanaged_external_down = can_unmanaged_external_down; device_class->set_platform_mtu = set_platform_mtu; device_class->get_configured_mtu = nm_device_get_configured_mtu_for_wired; diff --git a/src/core/devices/ovs/nm-device-ovs-port.c b/src/core/devices/ovs/nm-device-ovs-port.c index f11c5852..4419cfe9 100644 --- a/src/core/devices/ovs/nm-device-ovs-port.c +++ b/src/core/devices/ovs/nm-device-ovs-port.c @@ -41,11 +41,11 @@ get_type_description(NMDevice *device) } static gboolean -create_and_realize(NMDevice * device, - NMConnection * connection, - NMDevice * parent, +create_and_realize(NMDevice *device, + NMConnection *connection, + NMDevice *parent, const NMPlatformLink **out_plink, - GError ** error) + GError **error) { /* The port will be added to ovsdb when an interface is enslaved, * because there's no such thing like an empty port. */ @@ -59,13 +59,16 @@ get_generic_capabilities(NMDevice *device) return NM_DEVICE_CAP_IS_SOFTWARE; } -static NMActStageReturn -act_stage3_ip_config_start(NMDevice * device, - int addr_family, - gpointer * out_config, - NMDeviceStateReason *out_failure_reason) +static gboolean +ready_for_ip_config(NMDevice *device) +{ + return FALSE; +} + +static void +act_stage3_ip_config(NMDevice *device, int addr_family) { - return NM_ACT_STAGE_RETURN_IP_FAIL; + nm_device_devip_set_state(device, addr_family, NM_DEVICE_IP_STATE_READY, NULL); } static void @@ -87,10 +90,10 @@ add_iface_cb(GError *error, gpointer user_data) static gboolean enslave_slave(NMDevice *device, NMDevice *slave, NMConnection *connection, gboolean configure) { - NMDeviceOvsPort * self = NM_DEVICE_OVS_PORT(device); + NMDeviceOvsPort *self = NM_DEVICE_OVS_PORT(device); NMActiveConnection *ac_port = NULL; NMActiveConnection *ac_bridge = NULL; - NMDevice * bridge_device; + NMDevice *bridge_device; if (!configure) return TRUE; @@ -143,18 +146,23 @@ release_slave(NMDevice *device, NMDevice *slave, gboolean configure) { NMDeviceOvsPort *self = NM_DEVICE_OVS_PORT(device); + _LOGI(LOGD_DEVICE, "releasing ovs interface %s", nm_device_get_ip_iface(slave)); + + /* Even if the an interface's device has gone away (e.g. externally + * removed and thus we're called with configure=FALSE), we still need + * to make sure its OVSDB entry is gone. + */ + nm_ovsdb_del_interface(nm_ovsdb_get(), + nm_device_get_iface(slave), + del_iface_cb, + g_object_ref(slave)); + if (configure) { - _LOGI(LOGD_DEVICE, "releasing ovs interface %s", nm_device_get_ip_iface(slave)); - nm_ovsdb_del_interface(nm_ovsdb_get(), - nm_device_get_iface(slave), - del_iface_cb, - g_object_ref(slave)); /* Open VSwitch is going to delete this one. We must ignore what happens * next with the interface. */ if (NM_IS_DEVICE_OVS_INTERFACE(slave)) nm_device_update_from_platform_link(slave, NULL); - } else - _LOGI(LOGD_DEVICE, "ovs interface %s was released", nm_device_get_ip_iface(slave)); + } } /*****************************************************************************/ @@ -174,7 +182,7 @@ static void nm_device_ovs_port_class_init(NMDeviceOvsPortClass *klass) { NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS(&interface_info_device_ovs_port); @@ -186,7 +194,8 @@ nm_device_ovs_port_class_init(NMDeviceOvsPortClass *klass) device_class->get_type_description = get_type_description; device_class->create_and_realize = create_and_realize; device_class->get_generic_capabilities = get_generic_capabilities; - device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; + device_class->act_stage3_ip_config = act_stage3_ip_config; + device_class->ready_for_ip_config = ready_for_ip_config; device_class->enslave_slave = enslave_slave; device_class->release_slave = release_slave; device_class->can_reapply_change_ovs_external_ids = TRUE; diff --git a/src/core/devices/ovs/nm-ovs-factory.c b/src/core/devices/ovs/nm-ovs-factory.c index 6f5d8832..3ff0abf8 100644 --- a/src/core/devices/ovs/nm-ovs-factory.c +++ b/src/core/devices/ovs/nm-ovs-factory.c @@ -61,7 +61,7 @@ NM_DEVICE_FACTORY_DECLARE_TYPES( NM_SETTING_OVS_PORT_SETTING_NAME)) G_MODULE_EXPORT NMDeviceFactory * - nm_device_factory_create(GError **error) +nm_device_factory_create(GError **error) { nm_manager_set_capability(NM_MANAGER_GET, NM_CAPABILITY_OVS); return g_object_new(NM_TYPE_OVS_FACTORY, NULL); @@ -106,14 +106,14 @@ new_device_from_type(const char *name, NMDeviceType device_type) } static void -ovsdb_device_added(NMOvsdb * ovsdb, - const char * name, +ovsdb_device_added(NMOvsdb *ovsdb, + const char *name, guint device_type_i, - const char * subtype, + const char *subtype, NMDeviceFactory *self) { const NMDeviceType device_type = device_type_i; - NMDevice * device; + NMDevice *device; if (device_type == NM_DEVICE_TYPE_OVS_INTERFACE && !NM_IN_STRSET(subtype, "internal", "patch")) { @@ -133,14 +133,14 @@ ovsdb_device_added(NMOvsdb * ovsdb, } static void -ovsdb_device_removed(NMOvsdb * ovsdb, - const char * name, +ovsdb_device_removed(NMOvsdb *ovsdb, + const char *name, guint device_type_i, - const char * subtype, + const char *subtype, NMDeviceFactory *self) { const NMDeviceType device_type = device_type_i; - NMDevice * device = NULL; + NMDevice *device = NULL; NMDeviceState device_state; gboolean is_system_interface = FALSE; @@ -149,8 +149,8 @@ ovsdb_device_removed(NMOvsdb * ovsdb, return; if (device_type == NM_DEVICE_TYPE_OVS_INTERFACE && nm_streq0(subtype, "system")) { - NMDevice * d; - const CList * list; + NMDevice *d; + const CList *list; NMSettingOvsInterface *s_ovs_int; /* The device associated to an OVS system interface can be of @@ -165,15 +165,6 @@ ovsdb_device_removed(NMOvsdb * ovsdb, continue; if (!nm_streq0(nm_setting_ovs_interface_get_interface_type(s_ovs_int), "system")) continue; - /* Failing the system interface device is almost always the right - * thing to do when the ovsdb entry is removed. However, to avoid - * that a late device-removed signal tears down a different, - * newly-activated connection, let's also check that we have a master. - * Or in alternative, that the device is assumed/external: in such - * case it's always fine to fail the device. - */ - if (!nm_device_get_master(d) && !nm_device_sys_iface_state_is_external_or_assume(d)) - continue; device = d; } @@ -195,22 +186,23 @@ ovsdb_device_removed(NMOvsdb * ovsdb, } /* OVS system interfaces still exist even without the ovsdb entry */ - if (!is_system_interface && device_state == NM_DEVICE_STATE_UNMANAGED) { + if (!is_system_interface + && (device_state == NM_DEVICE_STATE_UNMANAGED + || device_state == NM_DEVICE_STATE_UNAVAILABLE)) nm_device_unrealize(device, TRUE, NULL); - } } static void -ovsdb_interface_failed(NMOvsdb * ovsdb, - const char * name, - const char * connection_uuid, - const char * error, +ovsdb_interface_failed(NMOvsdb *ovsdb, + const char *name, + const char *connection_uuid, + const char *error, NMDeviceFactory *self) { - NMDevice * device = NULL; - NMSettingsConnection * connection = NULL; - NMConnection * c; - const char * type; + NMDevice *device = NULL; + NMSettingsConnection *connection = NULL; + NMConnection *c; + const char *type; NMSettingOvsInterface *s_ovs_int; gboolean is_patch = FALSE; gboolean ignore; @@ -280,14 +272,14 @@ start(NMDeviceFactory *self) } static NMDevice * -create_device(NMDeviceFactory * self, - const char * iface, +create_device(NMDeviceFactory *self, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore) + NMConnection *connection, + gboolean *out_ignore) { NMDeviceType device_type = NM_DEVICE_TYPE_UNKNOWN; - const char * connection_type = NULL; + const char *connection_type = NULL; if (g_strcmp0(iface, "ovs-system") == 0) { *out_ignore = TRUE; diff --git a/src/core/devices/ovs/nm-ovsdb.c b/src/core/devices/ovs/nm-ovsdb.c index e5673347..7c45e0e4 100644 --- a/src/core/devices/ovs/nm-ovsdb.c +++ b/src/core/devices/ovs/nm-ovsdb.c @@ -30,34 +30,34 @@ #endif typedef struct { - char * port_uuid; - char * name; - char * connection_uuid; + char *port_uuid; + char *name; + char *connection_uuid; GPtrArray *interfaces; /* interface uuids */ - GArray * external_ids; + GArray *external_ids; } OpenvswitchPort; typedef struct { - char * bridge_uuid; - char * name; - char * connection_uuid; + char *bridge_uuid; + char *name; + char *connection_uuid; GPtrArray *ports; /* port uuids */ - GArray * external_ids; + GArray *external_ids; } OpenvswitchBridge; typedef struct { - char * interface_uuid; - char * name; - char * type; - char * connection_uuid; + char *interface_uuid; + char *name; + char *type; + char *connection_uuid; GArray *external_ids; } OpenvswitchInterface; /*****************************************************************************/ typedef void (*OvsdbMethodCallback)(NMOvsdb *self, - json_t * response, - GError * error, + json_t *response, + GError *error, gpointer user_data); typedef enum { @@ -77,27 +77,27 @@ typedef union { NMConnection *bridge; NMConnection *port; NMConnection *interface; - NMDevice * bridge_device; - NMDevice * interface_device; + NMDevice *bridge_device; + NMDevice *interface_device; } add_interface; struct { char *ifname; } del_interface; struct { - char * ifname; + char *ifname; guint32 mtu; } set_interface_mtu; struct { NMDeviceType device_type; - char * ifname; - char * connection_uuid; - GHashTable * exid_old; - GHashTable * exid_new; + char *ifname; + char *connection_uuid; + GHashTable *exid_old; + GHashTable *exid_new; } set_external_ids; } OvsdbMethodPayload; typedef struct { - NMOvsdb * self; + NMOvsdb *self; CList calls_lst; guint64 call_id; OvsdbCommand command; @@ -120,11 +120,11 @@ static guint signals[LAST_SIGNAL] = {0}; typedef struct { GSocketConnection *conn; - GCancellable * conn_cancellable; + GCancellable *conn_cancellable; char buf[4096]; /* Input buffer */ size_t bufp; /* Last decoded byte in the input buffer. */ - GString * input; /* JSON stream waiting for decoding. */ - GString * output; /* JSON stream to be sent. */ + GString *input; /* JSON stream waiting for decoding. */ + GString *output; /* JSON stream to be sent. */ guint64 call_id_counter; CList calls_lst_head; @@ -132,7 +132,7 @@ typedef struct { GHashTable *interfaces; /* interface uuid => OpenvswitchInterface */ GHashTable *ports; /* port uuid => OpenvswitchPort */ GHashTable *bridges; /* bridge uuid => OpenvswitchBridge */ - char * db_uuid; + char *db_uuid; guint num_failures; guint num_pending_deletions; bool ready : 1; @@ -328,25 +328,25 @@ _free_interface(OpenvswitchInterface *ovs_interface) /*****************************************************************************/ static void -_signal_emit_device_added(NMOvsdb * self, - const char * name, +_signal_emit_device_added(NMOvsdb *self, + const char *name, NMDeviceType device_type, - const char * device_subtype) + const char *device_subtype) { g_signal_emit(self, signals[DEVICE_ADDED], 0, name, (guint) device_type, device_subtype); } static void -_signal_emit_device_removed(NMOvsdb * self, - const char * name, +_signal_emit_device_removed(NMOvsdb *self, + const char *name, NMDeviceType device_type, - const char * device_subtype) + const char *device_subtype) { g_signal_emit(self, signals[DEVICE_REMOVED], 0, name, (guint) device_type, device_subtype); } static void -_signal_emit_interface_failed(NMOvsdb * self, +_signal_emit_interface_failed(NMOvsdb *self, const char *name, const char *connection_uuid, const char *error) @@ -363,14 +363,14 @@ _signal_emit_interface_failed(NMOvsdb * self, * there's no command pending completion. */ static void -ovsdb_call_method(NMOvsdb * self, +ovsdb_call_method(NMOvsdb *self, OvsdbMethodCallback callback, gpointer user_data, gboolean add_first, OvsdbCommand command, const OvsdbMethodPayload *payload) { - NMOvsdbPrivate * priv = NM_OVSDB_GET_PRIVATE(self); + NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); OvsdbMethodCall *call; /* Ensure we're not unsynchronized before we queue the method call. */ @@ -653,11 +653,11 @@ _set_port_interfaces(json_t *params, const char *ifname, json_t *new_interfaces) static json_t * _j_create_external_ids_array_new(NMConnection *connection) { - json_t * array; - const char *const * external_ids = NULL; + json_t *array; + const char *const *external_ids = NULL; guint n_external_ids = 0; guint i; - const char * uuid; + const char *uuid; NMSettingOvsExternalIDs *s_exid; nm_assert(NM_IS_CONNECTION(connection)); @@ -688,10 +688,10 @@ _j_create_external_ids_array_update(const char *connection_uuid, GHashTable *exid_new) { GHashTableIter iter; - json_t * mutations; - json_t * array; - const char * key; - const char * val; + json_t *mutations; + json_t *array; + const char *key; + const char *val; nm_assert(connection_uuid); @@ -741,21 +741,24 @@ _j_create_external_ids_array_update(const char *connection_uuid, /** * _insert_interface: * - * Returns an commands that adds new interface from a given connection. + * Returns a command that adds new interface from a given connection. */ static void -_insert_interface(json_t * params, +_insert_interface(json_t *params, NMConnection *interface, - NMDevice * interface_device, - const char * cloned_mac) + NMDevice *interface_device, + const char *cloned_mac) { - const char * type = NULL; + const char *type = NULL; NMSettingOvsInterface *s_ovs_iface; - NMSettingOvsDpdk * s_ovs_dpdk; - NMSettingOvsPatch * s_ovs_patch; - const char * dpdk_devargs; - json_t * options = json_array(); - json_t * row; + NMSettingOvsDpdk *s_ovs_dpdk; + const char *devargs; + guint32 n_rxq; + char sbuf[64]; + json_t *dpdk_array; + NMSettingOvsPatch *s_ovs_patch; + json_t *options = json_array(); + json_t *row; guint32 mtu = 0; s_ovs_iface = nm_connection_get_setting_ovs_interface(interface); @@ -778,11 +781,21 @@ _insert_interface(json_t * params, s_ovs_patch = nm_connection_get_setting_ovs_patch(interface); if (s_ovs_dpdk) { - dpdk_devargs = nm_setting_ovs_dpdk_get_devargs(s_ovs_dpdk); - if (dpdk_devargs) - json_array_append_new(options, json_pack("[[s, s]]", "dpdk-devargs", dpdk_devargs)); - else - json_array_append_new(options, json_array()); + devargs = nm_setting_ovs_dpdk_get_devargs(s_ovs_dpdk); + n_rxq = nm_setting_ovs_dpdk_get_n_rxq(s_ovs_dpdk); + + dpdk_array = json_array(); + + if (devargs) + json_array_append_new(dpdk_array, json_pack("[s,s]", "dpdk-devargs", devargs)); + + if (n_rxq != 0) { + json_array_append_new(dpdk_array, + json_pack("[s,s]", "n_rxq", nm_sprintf_buf(sbuf, "%u", n_rxq))); + } + + json_array_append_new(options, dpdk_array); + } else if (s_ovs_patch) { json_array_append_new( options, @@ -828,13 +841,13 @@ static void _insert_port(json_t *params, NMConnection *port, json_t *new_interfaces) { NMSettingOvsPort *s_ovs_port; - const char * vlan_mode = NULL; + const char *vlan_mode = NULL; guint tag = 0; - const char * lacp = NULL; - const char * bond_mode = NULL; + const char *lacp = NULL; + const char *bond_mode = NULL; guint bond_updelay = 0; guint bond_downdelay = 0; - json_t * row; + json_t *row; s_ovs_port = nm_connection_get_setting_ovs_port(port); @@ -885,19 +898,19 @@ _insert_port(json_t *params, NMConnection *port, json_t *new_interfaces) * Returns an commands that adds new bridge from a given connection. */ static void -_insert_bridge(json_t * params, +_insert_bridge(json_t *params, NMConnection *bridge, - NMDevice * bridge_device, - json_t * new_ports, - const char * cloned_mac) + NMDevice *bridge_device, + json_t *new_ports, + const char *cloned_mac) { NMSettingOvsBridge *s_ovs_bridge; - const char * fail_mode = NULL; + const char *fail_mode = NULL; gboolean mcast_snooping_enable = FALSE; gboolean rstp_enable = FALSE; gboolean stp_enable = FALSE; - const char * datapath_type = NULL; - json_t * row; + const char *datapath_type = NULL; + json_t *row; s_ovs_bridge = nm_connection_get_setting_ovs_bridge(bridge); @@ -977,24 +990,24 @@ _inc_next_cfg(const char *db_uuid) * a parent @port and @bridge if needed. */ static void -_add_interface(NMOvsdb * self, - json_t * params, +_add_interface(NMOvsdb *self, + json_t *params, NMConnection *bridge, NMConnection *port, NMConnection *interface, - NMDevice * bridge_device, - NMDevice * interface_device) + NMDevice *bridge_device, + NMDevice *interface_device) { - NMOvsdbPrivate * priv = NM_OVSDB_GET_PRIVATE(self); - GHashTableIter iter; - const char * port_uuid; - const char * interface_uuid; - const char * bridge_name; - const char * port_name; - const char * interface_name; - OpenvswitchBridge * ovs_bridge = NULL; - OpenvswitchPort * ovs_port = NULL; - OpenvswitchInterface *ovs_interface = NULL; + NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); + GHashTableIter iter; + const char *port_uuid; + const char *interface_uuid; + const char *bridge_name; + const char *port_name; + const char *interface_name; + OpenvswitchBridge *ovs_bridge = NULL; + OpenvswitchPort *ovs_port = NULL; + OpenvswitchInterface *ovs_interface = NULL; nm_auto_decref_json json_t *bridges = NULL; nm_auto_decref_json json_t *new_bridges = NULL; nm_auto_decref_json json_t *ports = NULL; @@ -1003,9 +1016,9 @@ _add_interface(NMOvsdb * self, nm_auto_decref_json json_t *new_interfaces = NULL; gboolean has_interface = FALSE; gboolean interface_is_local; - gs_free char * bridge_cloned_mac = NULL; - gs_free char * interface_cloned_mac = NULL; - GError * error = NULL; + gs_free char *bridge_cloned_mac = NULL; + gs_free char *interface_cloned_mac = NULL; + GError *error = NULL; int pi; int ii; @@ -1162,13 +1175,13 @@ _add_interface(NMOvsdb * self, static void _delete_interface(NMOvsdb *self, json_t *params, const char *ifname) { - NMOvsdbPrivate * priv = NM_OVSDB_GET_PRIVATE(self); - GHashTableIter iter; - char * port_uuid; - char * interface_uuid; - OpenvswitchBridge * ovs_bridge; - OpenvswitchPort * ovs_port; - OpenvswitchInterface *ovs_interface; + NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); + GHashTableIter iter; + char *port_uuid; + char *interface_uuid; + OpenvswitchBridge *ovs_bridge; + OpenvswitchPort *ovs_port; + OpenvswitchInterface *ovs_interface; nm_auto_decref_json json_t *bridges = NULL; nm_auto_decref_json json_t *new_bridges = NULL; gboolean bridges_changed; @@ -1272,9 +1285,9 @@ _delete_interface(NMOvsdb *self, json_t *params, const char *ifname) static void ovsdb_next_command(NMOvsdb *self) { - NMOvsdbPrivate * priv = NM_OVSDB_GET_PRIVATE(self); - OvsdbMethodCall * call; - char * cmd; + NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); + OvsdbMethodCall *call; + char *cmd; nm_auto_decref_json json_t *msg = NULL; if (!priv->conn) @@ -1420,9 +1433,9 @@ static void _uuids_to_array_inplace(GPtrArray *array, const json_t *items) { const char *key; - json_t * value; + json_t *value; size_t index = 0; - json_t * set_value; + json_t *set_value; size_t set_index; while (index < json_array_size(items)) { @@ -1475,8 +1488,8 @@ _external_ids_extract(json_t *external_ids, GArray **out_array, const char **out array = json_array_get(external_ids, 1); json_array_foreach (array, index, value) { - const char * key = json_string_value(json_array_get(value, 0)); - const char * val = json_string_value(json_array_get(value, 1)); + const char *key = json_string_value(json_array_get(value, 0)); + const char *val = json_string_value(json_array_get(value, 1)); NMUtilsNamedValue *v; if (!key || !val) @@ -1559,20 +1572,20 @@ static void ovsdb_got_update(NMOvsdb *self, json_t *msg) { NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); - json_t * ovs = NULL; - json_t * bridge = NULL; - json_t * port = NULL; - json_t * interface = NULL; - json_t * items; - json_t * external_ids; + json_t *ovs = NULL; + json_t *bridge = NULL; + json_t *port = NULL; + json_t *interface = NULL; + json_t *items; + json_t *external_ids; json_error_t json_error = { 0, }; - void * iter; + void *iter; const char *name; const char *key; const char *type; - json_t * value; + json_t *value; if (json_unpack_ex(msg, &json_error, @@ -1602,10 +1615,10 @@ ovsdb_got_update(NMOvsdb *self, json_t *msg) } json_object_foreach (interface, key, value) { - OpenvswitchInterface *ovs_interface; + OpenvswitchInterface *ovs_interface; gs_unref_array GArray *external_ids_arr = NULL; - const char * connection_uuid = NULL; - json_t * error = NULL; + const char *connection_uuid = NULL; + json_t *error = NULL; int r; r = json_unpack(value, @@ -1726,10 +1739,10 @@ ovsdb_got_update(NMOvsdb *self, json_t *msg) json_object_foreach (port, key, value) { gs_unref_ptrarray GPtrArray *interfaces = NULL; - OpenvswitchPort * ovs_port; - gs_unref_array GArray *external_ids_arr = NULL; - const char * connection_uuid = NULL; - int r; + OpenvswitchPort *ovs_port; + gs_unref_array GArray *external_ids_arr = NULL; + const char *connection_uuid = NULL; + int r; r = json_unpack(value, "{s:{s:s, s:o, s:o}}", @@ -1827,10 +1840,10 @@ ovsdb_got_update(NMOvsdb *self, json_t *msg) json_object_foreach (bridge, key, value) { gs_unref_ptrarray GPtrArray *ports = NULL; - OpenvswitchBridge * ovs_bridge; - gs_unref_array GArray *external_ids_arr = NULL; - const char * connection_uuid = NULL; - int r; + OpenvswitchBridge *ovs_bridge; + gs_unref_array GArray *external_ids_arr = NULL; + const char *connection_uuid = NULL; + int r; r = json_unpack(value, "{s:{s:s, s:o, s:o}}", @@ -1940,9 +1953,9 @@ ovsdb_got_update(NMOvsdb *self, json_t *msg) static void ovsdb_got_echo(NMOvsdb *self, json_int_t id, json_t *data) { - NMOvsdbPrivate * priv = NM_OVSDB_GET_PRIVATE(self); - nm_auto_decref_json json_t *msg = NULL; - char * reply; + NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); + nm_auto_decref_json json_t *msg = NULL; + char *reply; gboolean output_was_empty; output_was_empty = priv->output->len == 0; @@ -1969,12 +1982,12 @@ ovsdb_got_msg(NMOvsdb *self, json_t *msg) json_error_t json_error = { 0, }; - json_t * json_id = NULL; + json_t *json_id = NULL; json_int_t id = (json_int_t) -1; const char *method = NULL; - json_t * params = NULL; - json_t * result = NULL; - json_t * error = NULL; + json_t *params = NULL; + json_t *result = NULL; + json_t *error = NULL; if (json_unpack_ex(msg, &json_error, @@ -2020,9 +2033,9 @@ ovsdb_got_msg(NMOvsdb *self, json_t *msg) } if (id >= 0) { - OvsdbMethodCall *call; + OvsdbMethodCall *call; gs_free_error GError *local = NULL; - gs_free char * msg_as_str = NULL; + gs_free char *msg_as_str = NULL; /* This is a response to a method call. */ if (c_list_is_empty(&priv->calls_lst_head)) { @@ -2078,7 +2091,7 @@ ovsdb_got_msg(NMOvsdb *self, json_t *msg) static size_t _json_callback(void *buffer, size_t buflen, void *user_data) { - NMOvsdb * self = NM_OVSDB(user_data); + NMOvsdb *self = NM_OVSDB(user_data); NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); if (priv->bufp == priv->input->len) { @@ -2102,12 +2115,12 @@ _json_callback(void *buffer, size_t buflen, void *user_data) static void ovsdb_read_cb(GObject *source_object, GAsyncResult *res, gpointer user_data) { - NMOvsdb * self = NM_OVSDB(user_data); + NMOvsdb *self = NM_OVSDB(user_data); NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); - GInputStream * stream = G_INPUT_STREAM(source_object); - GError * error = NULL; + GInputStream *stream = G_INPUT_STREAM(source_object); + GError *error = NULL; gssize size; - json_t * msg; + json_t *msg; json_error_t json_error = { 0, }; @@ -2160,10 +2173,10 @@ ovsdb_read(NMOvsdb *self) static void ovsdb_write_cb(GObject *source_object, GAsyncResult *res, gpointer user_data) { - GOutputStream * stream = G_OUTPUT_STREAM(source_object); - NMOvsdb * self = NM_OVSDB(user_data); + GOutputStream *stream = G_OUTPUT_STREAM(source_object); + NMOvsdb *self = NM_OVSDB(user_data); NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); - GError * error = NULL; + GError *error = NULL; gssize size; size = g_output_stream_write_finish(stream, res, &error); @@ -2188,7 +2201,7 @@ static void ovsdb_write(NMOvsdb *self) { NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); - GOutputStream * stream; + GOutputStream *stream; if (!priv->output->len) return; @@ -2221,7 +2234,7 @@ ovsdb_write(NMOvsdb *self) static void ovsdb_disconnect(NMOvsdb *self, gboolean retry, gboolean is_disposing) { - NMOvsdbPrivate * priv = NM_OVSDB_GET_PRIVATE(self); + NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); OvsdbMethodCall *call; nm_assert(!retry || !is_disposing); @@ -2278,8 +2291,8 @@ _check_ready(NMOvsdb *self) static void _del_initial_iface_cb(GError *error, gpointer user_data) { - NMOvsdb * self; - gs_free char * ifname = NULL; + NMOvsdb *self; + gs_free char *ifname = NULL; NMOvsdbPrivate *priv; nm_utils_user_data_unpack(user_data, &self, &ifname); @@ -2305,9 +2318,9 @@ _del_initial_iface_cb(GError *error, gpointer user_data) static void ovsdb_cleanup_initial_interfaces(NMOvsdb *self) { - NMOvsdbPrivate * priv = NM_OVSDB_GET_PRIVATE(self); + NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); const OpenvswitchInterface *interface; - NMUtilsUserData * data; + NMUtilsUserData *data; GHashTableIter iter; if (priv->ready || priv->num_pending_deletions != 0) @@ -2352,9 +2365,9 @@ _monitor_bridges_cb(NMOvsdb *self, json_t *result, GError *error, gpointer user_ static void _ovsdb_connect_complete_with_fd(NMOvsdb *self, int fd_take) { - NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); + NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); gs_unref_object GSocket *socket = NULL; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; socket = g_socket_new_from_fd(nm_steal_fd(&fd_take), &error); if (!socket) { @@ -2374,7 +2387,7 @@ static void _ovsdb_connect_priv_helper_cb(int fd_take, GError *error, gpointer user_data) { nm_auto_close int fd = fd_take; - NMOvsdb * self; + NMOvsdb *self; if (nm_utils_error_is_cancelled(error)) return; @@ -2394,9 +2407,9 @@ _ovsdb_connect_priv_helper_cb(int fd_take, GError *error, gpointer user_data) static void _ovsdb_connect_idle(gpointer user_data, GCancellable *cancellable) { - NMOvsdb * self; - NMOvsdbPrivate * priv; - nm_auto_close int fd = -1; + NMOvsdb *self; + NMOvsdbPrivate *priv; + nm_auto_close int fd = -1; gs_free_error GError *error = NULL; if (g_cancellable_is_cancelled(cancellable)) @@ -2468,11 +2481,11 @@ typedef struct { static void _transact_cb(NMOvsdb *self, json_t *result, GError *error, gpointer user_data) { - OvsdbCall * call = user_data; + OvsdbCall *call = user_data; const char *err; const char *err_details; size_t index; - json_t * value; + json_t *value; if (error) goto out; @@ -2516,12 +2529,12 @@ nm_ovsdb_is_ready(NMOvsdb *self) } void -nm_ovsdb_add_interface(NMOvsdb * self, - NMConnection * bridge, - NMConnection * port, - NMConnection * interface, - NMDevice * bridge_device, - NMDevice * interface_device, +nm_ovsdb_add_interface(NMOvsdb *self, + NMConnection *bridge, + NMConnection *port, + NMConnection *interface, + NMDevice *bridge_device, + NMDevice *interface_device, NMOvsdbCallback callback, gpointer user_data) { @@ -2538,8 +2551,8 @@ nm_ovsdb_add_interface(NMOvsdb * self, } void -nm_ovsdb_del_interface(NMOvsdb * self, - const char * ifname, +nm_ovsdb_del_interface(NMOvsdb *self, + const char *ifname, NMOvsdbCallback callback, gpointer user_data) { @@ -2552,8 +2565,8 @@ nm_ovsdb_del_interface(NMOvsdb * self, } void -nm_ovsdb_set_interface_mtu(NMOvsdb * self, - const char * ifname, +nm_ovsdb_set_interface_mtu(NMOvsdb *self, + const char *ifname, guint32 mtu, NMOvsdbCallback callback, gpointer user_data) @@ -2567,10 +2580,10 @@ nm_ovsdb_set_interface_mtu(NMOvsdb * self, } void -nm_ovsdb_set_external_ids(NMOvsdb * self, +nm_ovsdb_set_external_ids(NMOvsdb *self, NMDeviceType device_type, - const char * ifname, - const char * connection_uuid, + const char *ifname, + const char *connection_uuid, NMSettingOvsExternalIDs *s_exid_old, NMSettingOvsExternalIDs *s_exid_new) { @@ -2618,7 +2631,7 @@ nm_ovsdb_init(NMOvsdb *self) static void dispose(GObject *object) { - NMOvsdb * self = NM_OVSDB(object); + NMOvsdb *self = NM_OVSDB(object); NMOvsdbPrivate *priv = NM_OVSDB_GET_PRIVATE(self); ovsdb_disconnect(self, FALSE, TRUE); diff --git a/src/core/devices/ovs/nm-ovsdb.h b/src/core/devices/ovs/nm-ovsdb.h index d0b4d19d..a50db45a 100644 --- a/src/core/devices/ovs/nm-ovsdb.h +++ b/src/core/devices/ovs/nm-ovsdb.h @@ -27,32 +27,32 @@ NMOvsdb *nm_ovsdb_get(void); GType nm_ovsdb_get_type(void); -void nm_ovsdb_add_interface(NMOvsdb * self, - NMConnection * bridge, - NMConnection * port, - NMConnection * interface, - NMDevice * bridge_device, - NMDevice * interface_device, +void nm_ovsdb_add_interface(NMOvsdb *self, + NMConnection *bridge, + NMConnection *port, + NMConnection *interface, + NMDevice *bridge_device, + NMDevice *interface_device, NMOvsdbCallback callback, gpointer user_data); -void nm_ovsdb_del_interface(NMOvsdb * self, - const char * ifname, +void nm_ovsdb_del_interface(NMOvsdb *self, + const char *ifname, NMOvsdbCallback callback, gpointer user_data); -void nm_ovsdb_set_interface_mtu(NMOvsdb * self, - const char * ifname, +void nm_ovsdb_set_interface_mtu(NMOvsdb *self, + const char *ifname, guint32 mtu, NMOvsdbCallback callback, gpointer user_data); struct _NMSettingOvsExternalIDs; -void nm_ovsdb_set_external_ids(NMOvsdb * self, +void nm_ovsdb_set_external_ids(NMOvsdb *self, NMDeviceType device_type, - const char * ifname, - const char * connection_uuid, + const char *ifname, + const char *connection_uuid, struct _NMSettingOvsExternalIDs *s_exid_old, struct _NMSettingOvsExternalIDs *s_exid_new); diff --git a/src/core/devices/team/nm-device-team.c b/src/core/devices/team/nm-device-team.c index 3398e467..16cd2e87 100644 --- a/src/core/devices/team/nm-device-team.c +++ b/src/core/devices/team/nm-device-team.c @@ -23,7 +23,6 @@ #include "libnm-core-aux-intern/nm-libnm-core-utils.h" #include "libnm-core-intern/nm-core-internal.h" #include "nm-dbus-manager.h" -#include "nm-ip4-config.h" #include "libnm-std-aux/nm-dbus-compat.h" #define _NMLOG_DEVICE_TYPE NMDeviceTeam @@ -34,15 +33,15 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMDeviceTeam, PROP_CONFIG, ); typedef struct { - struct teamdctl * tdc; - char * config; + struct teamdctl *tdc; + char *config; GPid teamd_pid; guint teamd_process_watch; guint teamd_timeout; guint teamd_read_timeout; guint teamd_dbus_watch; bool kill_in_progress : 1; - GFileMonitor * usock_monitor; + GFileMonitor *usock_monitor; NMDeviceStageState stage1_state : 3; } NMDeviceTeamPrivate; @@ -73,11 +72,11 @@ get_generic_capabilities(NMDevice *device) } static gboolean -complete_connection(NMDevice * device, - NMConnection * connection, - const char * specific_object, +complete_connection(NMDevice *device, + NMConnection *connection, + const char *specific_object, NMConnection *const *existing_connections, - GError ** error) + GError **error) { nm_utils_complete_generic(nm_device_get_platform(device), connection, @@ -97,7 +96,7 @@ complete_connection(NMDevice * device, static gboolean ensure_teamd_connection(NMDevice *device) { - NMDeviceTeam * self = NM_DEVICE_TEAM(device); + NMDeviceTeam *self = NM_DEVICE_TEAM(device); NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE(self); int err; @@ -126,7 +125,7 @@ static gboolean teamd_read_config(NMDeviceTeam *self) { NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE(self); - const char * config = NULL; + const char *config = NULL; int err; if (priv->tdc) { @@ -151,7 +150,7 @@ teamd_read_config(NMDeviceTeam *self) static gboolean teamd_read_timeout_cb(gpointer user_data) { - NMDeviceTeam * self = user_data; + NMDeviceTeam *self = user_data; NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE(self); priv->teamd_read_timeout = 0; @@ -162,10 +161,10 @@ teamd_read_timeout_cb(gpointer user_data) static void update_connection(NMDevice *device, NMConnection *connection) { - NMDeviceTeam * self = NM_DEVICE_TEAM(device); - NMSettingTeam * s_team = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_TEAM); + NMDeviceTeam *self = NM_DEVICE_TEAM(device); + NMSettingTeam *s_team = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_TEAM); NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE(self); - struct teamdctl * tdc = priv->tdc; + struct teamdctl *tdc = priv->tdc; /* Read the configuration only if not already set */ if (!priv->config && ensure_teamd_connection(device)) @@ -184,18 +183,18 @@ update_connection(NMDevice *device, NMConnection *connection) /*****************************************************************************/ static gboolean -master_update_slave_connection(NMDevice * self, - NMDevice * slave, +master_update_slave_connection(NMDevice *self, + NMDevice *slave, NMConnection *connection, - GError ** error) + GError **error) { NMSettingTeamPort *s_port; - char * port_config = NULL; + char *port_config = NULL; int err = 0; - struct teamdctl * tdc; - const char * team_port_config = NULL; - const char * iface = nm_device_get_iface(self); - const char * iface_slave = nm_device_get_iface(slave); + struct teamdctl *tdc; + const char *team_port_config = NULL; + const char *iface = nm_device_get_iface(self); + const char *iface_slave = nm_device_get_iface(slave); tdc = teamdctl_alloc(); if (!tdc) { @@ -260,7 +259,7 @@ static void teamd_kill_cb(pid_t pid, gboolean success, int child_status, void *user_data) { gs_unref_object NMDeviceTeam *self = user_data; - NMDeviceTeamPrivate * priv = NM_DEVICE_TEAM_GET_PRIVATE(self); + NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE(self); priv->kill_in_progress = FALSE; @@ -308,8 +307,8 @@ teamd_cleanup(NMDeviceTeam *self, gboolean free_tdc) static gboolean teamd_timeout_cb(gpointer user_data) { - NMDeviceTeam * self = NM_DEVICE_TEAM(user_data); - NMDevice * device = NM_DEVICE(self); + NMDeviceTeam *self = NM_DEVICE_TEAM(user_data); + NMDevice *device = NM_DEVICE(self); NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE(self); g_return_val_if_fail(priv->teamd_timeout, FALSE); @@ -343,7 +342,7 @@ static void teamd_ready(NMDeviceTeam *self) { NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE(self); - NMDevice * device = NM_DEVICE(self); + NMDevice *device = NM_DEVICE(self); gboolean success; if (priv->kill_in_progress) { @@ -382,7 +381,7 @@ teamd_ready(NMDeviceTeam *self) static void teamd_gone(NMDeviceTeam *self) { - NMDevice * device = NM_DEVICE(self); + NMDevice *device = NM_DEVICE(self); NMDeviceState state; teamd_cleanup(self, TRUE); @@ -400,11 +399,11 @@ teamd_gone(NMDeviceTeam *self) static void teamd_dbus_appeared(GDBusConnection *connection, - const char * name, - const char * name_owner, + const char *name, + const char *name_owner, gpointer user_data) { - NMDeviceTeam * self = NM_DEVICE_TEAM(user_data); + NMDeviceTeam *self = NM_DEVICE_TEAM(user_data); NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE(self); g_return_if_fail(priv->teamd_dbus_watch); @@ -452,7 +451,7 @@ teamd_dbus_appeared(GDBusConnection *connection, static void teamd_dbus_vanished(GDBusConnection *dbus_connection, const char *name, gpointer user_data) { - NMDeviceTeam * self = NM_DEVICE_TEAM(user_data); + NMDeviceTeam *self = NM_DEVICE_TEAM(user_data); NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE(self); g_return_if_fail(priv->teamd_dbus_watch); @@ -472,9 +471,9 @@ teamd_dbus_vanished(GDBusConnection *dbus_connection, const char *name, gpointer } static void -monitor_changed_cb(GFileMonitor * monitor, - GFile * file, - GFile * other_file, +monitor_changed_cb(GFileMonitor *monitor, + GFile *file, + GFile *other_file, GFileMonitorEvent event_type, gpointer user_data) { @@ -496,9 +495,9 @@ monitor_changed_cb(GFileMonitor * monitor, static void teamd_process_watch_cb(GPid pid, int status, gpointer user_data) { - NMDeviceTeam * self = NM_DEVICE_TEAM(user_data); + NMDeviceTeam *self = NM_DEVICE_TEAM(user_data); NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE(self); - NMDevice * device = NM_DEVICE(self); + NMDevice *device = NM_DEVICE(self); NMDeviceState state = nm_device_get_state(device); g_return_if_fail(priv->teamd_process_watch); @@ -546,8 +545,8 @@ static gboolean teamd_kill(NMDeviceTeam *self, const char *teamd_binary, GError **error) { gs_unref_ptrarray GPtrArray *argv = NULL; - gs_free char * tmp_str = NULL; - gs_free const char ** envp = NULL; + gs_free char *tmp_str = NULL; + gs_free const char **envp = NULL; if (!teamd_binary) { teamd_binary = nm_utils_find_helper("teamd", NULL, error); @@ -582,18 +581,18 @@ teamd_kill(NMDeviceTeam *self, const char *teamd_binary, GError **error) static gboolean teamd_start(NMDeviceTeam *self) { - NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE(self); - const char * iface = nm_device_get_ip_iface(NM_DEVICE(self)); - NMConnection * connection; - gs_unref_ptrarray GPtrArray *argv = NULL; - gs_free_error GError * error = NULL; - gs_free char * tmp_str = NULL; - const char * teamd_binary; - const char * config; - nm_auto_free const char *config_free = NULL; - NMSettingTeam * s_team; - gs_free char * cloned_mac = NULL; - gs_free const char ** envp = NULL; + NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE(self); + const char *iface = nm_device_get_ip_iface(NM_DEVICE(self)); + NMConnection *connection; + gs_unref_ptrarray GPtrArray *argv = NULL; + gs_free_error GError *error = NULL; + gs_free char *tmp_str = NULL; + const char *teamd_binary; + const char *config; + nm_auto_free const char *config_free = NULL; + NMSettingTeam *s_team; + gs_free char *cloned_mac = NULL; + gs_free const char **envp = NULL; connection = nm_device_get_applied_connection(NM_DEVICE(self)); @@ -640,7 +639,7 @@ teamd_start(NMDeviceTeam *self) } if (cloned_mac) { - json_t * json, *hwaddr; + json_t *json, *hwaddr; json_error_t jerror; /* Inject the hwaddr property into the JSON configuration. @@ -707,11 +706,11 @@ teamd_start(NMDeviceTeam *self) static NMActStageReturn act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) { - NMDeviceTeam * self = NM_DEVICE_TEAM(device); - NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE(self); + NMDeviceTeam *self = NM_DEVICE_TEAM(device); + NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE(self); gs_free_error GError *error = NULL; - NMSettingTeam * s_team; - const char * cfg; + NMSettingTeam *s_team; + const char *cfg; if (nm_device_sys_iface_state_is_external(device)) return NM_ACT_STAGE_RETURN_SUCCESS; @@ -774,7 +773,7 @@ act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) static void deactivate(NMDevice *device) { - NMDeviceTeam * self = NM_DEVICE_TEAM(device); + NMDeviceTeam *self = NM_DEVICE_TEAM(device); NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE(self); priv->stage1_state = NM_DEVICE_STAGE_STATE_INIT; @@ -794,11 +793,11 @@ deactivate(NMDevice *device) static gboolean enslave_slave(NMDevice *device, NMDevice *slave, NMConnection *connection, gboolean configure) { - NMDeviceTeam * self = NM_DEVICE_TEAM(device); + NMDeviceTeam *self = NM_DEVICE_TEAM(device); NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE(self); gboolean success = TRUE; - const char * slave_iface = nm_device_get_ip_iface(slave); - NMSettingTeamPort * s_team_port; + const char *slave_iface = nm_device_get_ip_iface(slave); + NMSettingTeamPort *s_team_port; nm_device_master_check_slave_physical_port(device, slave, LOGD_TEAM); @@ -852,10 +851,10 @@ enslave_slave(NMDevice *device, NMDevice *slave, NMConnection *connection, gbool static void release_slave(NMDevice *device, NMDevice *slave, gboolean configure) { - NMDeviceTeam * self = NM_DEVICE_TEAM(device); + NMDeviceTeam *self = NM_DEVICE_TEAM(device); NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE(self); gboolean do_release, success; - NMSettingTeamPort * s_port; + NMSettingTeamPort *s_port; int ifindex_slave; int ifindex; @@ -902,11 +901,11 @@ release_slave(NMDevice *device, NMDevice *slave, gboolean configure) } static gboolean -create_and_realize(NMDevice * device, - NMConnection * connection, - NMDevice * parent, +create_and_realize(NMDevice *device, + NMConnection *connection, + NMDevice *parent, const NMPlatformLink **out_plink, - GError ** error) + GError **error) { const char *iface = nm_device_get_iface(device); int r; @@ -954,11 +953,11 @@ nm_device_team_init(NMDeviceTeam *self) static void constructed(GObject *object) { - NMDevice * device = NM_DEVICE(object); - NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE(device); - gs_free char * tmp_str = NULL; - gs_unref_object GFile *file = NULL; - GError * error; + NMDevice *device = NM_DEVICE(object); + NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE(device); + gs_free char *tmp_str = NULL; + gs_unref_object GFile *file = NULL; + GError *error; G_OBJECT_CLASS(nm_device_team_parent_class)->constructed(object); @@ -1006,7 +1005,7 @@ nm_device_team_new(const char *iface) static void dispose(GObject *object) { - NMDeviceTeam * self = NM_DEVICE_TEAM(object); + NMDeviceTeam *self = NM_DEVICE_TEAM(object); NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE(self); if (priv->teamd_dbus_watch) { @@ -1040,9 +1039,9 @@ static const NMDBusInterfaceInfoExtended interface_info_device_team = { static void nm_device_team_class_init(NMDeviceTeamClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->constructed = constructed; object_class->dispose = dispose; diff --git a/src/core/devices/team/nm-team-factory.c b/src/core/devices/team/nm-team-factory.c index e2040d19..b446cbd0 100644 --- a/src/core/devices/team/nm-team-factory.c +++ b/src/core/devices/team/nm-team-factory.c @@ -43,7 +43,7 @@ NM_DEVICE_FACTORY_DECLARE_TYPES(NM_DEVICE_FACTORY_DECLARE_LINK_TYPES( NM_LINK_TYPE_TEAM) NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES(NM_SETTING_TEAM_SETTING_NAME)) G_MODULE_EXPORT NMDeviceFactory * - nm_device_factory_create(GError **error) +nm_device_factory_create(GError **error) { nm_manager_set_capability(NM_MANAGER_GET, NM_CAPABILITY_TEAM); return g_object_new(NM_TYPE_TEAM_FACTORY, NULL); @@ -52,11 +52,11 @@ G_MODULE_EXPORT NMDeviceFactory * /*****************************************************************************/ static NMDevice * -create_device(NMDeviceFactory * factory, - const char * iface, +create_device(NMDeviceFactory *factory, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore) + NMConnection *connection, + gboolean *out_ignore) { return nm_device_team_new(iface); } diff --git a/src/core/devices/tests/meson.build b/src/core/devices/tests/meson.build index 1bc88370..871c3206 100644 --- a/src/core/devices/tests/meson.build +++ b/src/core/devices/tests/meson.build @@ -1,7 +1,6 @@ # SPDX-License-Identifier: LGPL-2.1-or-later test_units = [ - 'test-acd', 'test-lldp', ] diff --git a/src/core/devices/tests/test-acd.c b/src/core/devices/tests/test-acd.c deleted file mode 100644 index b4b65165..00000000 --- a/src/core/devices/tests/test-acd.c +++ /dev/null @@ -1,259 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2015 Red Hat, Inc. - */ - -#include "src/core/nm-default-daemon.h" - -#include "n-acd/src/n-acd.h" - -#include - -#include "devices/nm-acd-manager.h" -#include "platform/tests/test-common.h" - -#define IFACE_VETH0 "nm-test-veth0" -#define IFACE_VETH1 "nm-test-veth1" - -#define ADDR1 0x01010101 -#define ADDR2 0x02020202 -#define ADDR3 0x03030303 -#define ADDR4 0x04040404 - -/*****************************************************************************/ - -static gboolean -_skip_acd_test_check(void) -{ - NAcd * acd; - NAcdConfig * config; - const guint8 hwaddr[ETH_ALEN] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06}; - int r; - static int skip = -1; - - if (skip == -1) { - r = n_acd_config_new(&config); - g_assert(r == 0); - - n_acd_config_set_ifindex(config, 1); - n_acd_config_set_transport(config, N_ACD_TRANSPORT_ETHERNET); - n_acd_config_set_mac(config, hwaddr, sizeof(hwaddr)); - - r = n_acd_new(&acd, config); - n_acd_config_free(config); - if (r == 0) - n_acd_unref(acd); - - skip = (r != 0); - } - return skip; -} - -#define _skip_acd_test() \ - ({ \ - gboolean _skip = _skip_acd_test_check(); \ - \ - if (_skip) \ - g_test_skip("Cannot create NAcd. Running under valgind?"); \ - _skip; \ - }) - -/*****************************************************************************/ - -typedef struct { - int ifindex0; - int ifindex1; - const guint8 *hwaddr0; - const guint8 *hwaddr1; - size_t hwaddr0_len; - size_t hwaddr1_len; -} test_fixture; - -static void -fixture_setup(test_fixture *fixture, gconstpointer user_data) -{ - /* create veth pair. */ - fixture->ifindex0 = - nmtstp_link_veth_add(NM_PLATFORM_GET, -1, IFACE_VETH0, IFACE_VETH1)->ifindex; - fixture->ifindex1 = - nmtstp_link_get_typed(NM_PLATFORM_GET, -1, IFACE_VETH1, NM_LINK_TYPE_VETH)->ifindex; - - g_assert(nm_platform_link_change_flags(NM_PLATFORM_GET, fixture->ifindex0, IFF_UP, TRUE) >= 0); - g_assert(nm_platform_link_change_flags(NM_PLATFORM_GET, fixture->ifindex1, IFF_UP, TRUE) >= 0); - - fixture->hwaddr0 = - nm_platform_link_get_address(NM_PLATFORM_GET, fixture->ifindex0, &fixture->hwaddr0_len); - fixture->hwaddr1 = - nm_platform_link_get_address(NM_PLATFORM_GET, fixture->ifindex1, &fixture->hwaddr1_len); -} - -typedef struct { - in_addr_t addresses[8]; - in_addr_t peer_addresses[8]; - gboolean expected_result[8]; -} TestInfo; - -static void -acd_manager_probe_terminated(NMAcdManager *acd_manager, gpointer user_data) -{ - g_main_loop_quit(user_data); -} - -static void -test_acd_common(test_fixture *fixture, TestInfo *info) -{ - nm_auto_free_acdmgr NMAcdManager *manager = NULL; - nm_auto_unref_gmainloop GMainLoop *loop = NULL; - int i; - const guint WAIT_TIME_OPTIMISTIC = 50; - guint wait_time; - static const NMAcdCallbacks callbacks = { - .probe_terminated_callback = acd_manager_probe_terminated, - .user_data_destroy = (GDestroyNotify) g_main_loop_unref, - }; - int r; - - if (_skip_acd_test()) - return; - - /* first, try with a short waittime. We hope that this is long enough - * to successfully complete the test. Only if that's not the case, we - * assume the computer is currently busy (high load) and we retry with - * a longer timeout. */ - wait_time = WAIT_TIME_OPTIMISTIC; -again: - - nm_clear_pointer(&loop, g_main_loop_unref); - loop = g_main_loop_new(NULL, FALSE); - - nm_clear_pointer(&manager, nm_acd_manager_free); - manager = nm_acd_manager_new(fixture->ifindex0, - fixture->hwaddr0, - fixture->hwaddr0_len, - &callbacks, - g_main_loop_ref(loop)); - g_assert(manager != NULL); - - for (i = 0; info->addresses[i]; i++) - g_assert(nm_acd_manager_add_address(manager, info->addresses[i])); - - for (i = 0; info->peer_addresses[i]; i++) { - nmtstp_ip4_address_add(NULL, - FALSE, - fixture->ifindex1, - info->peer_addresses[i], - 24, - 0, - 3600, - 1800, - 0, - NULL); - } - - r = nm_acd_manager_start_probe(manager, wait_time); - g_assert_cmpint(r, ==, 0); - - g_assert(nmtst_main_loop_run(loop, 2000)); - - for (i = 0; info->addresses[i]; i++) { - gboolean val; - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; - - val = nm_acd_manager_check_address(manager, info->addresses[i]); - if (val == info->expected_result[i]) - continue; - - if (wait_time == WAIT_TIME_OPTIMISTIC) { - /* probably we just had a glitch and the system took longer than - * expected. Re-verify with a large timeout this time. */ - wait_time = 1000; - goto again; - } - - g_error("expected check for address #%d (%s) to %s, but it didn't", - i, - _nm_utils_inet4_ntop(info->addresses[i], sbuf), - info->expected_result[i] ? "detect no duplicated" : "detect a duplicate"); - } -} - -static void -test_acd_probe_1(test_fixture *fixture, gconstpointer user_data) -{ - TestInfo info = {.addresses = {ADDR1, ADDR2, ADDR3}, - .peer_addresses = {ADDR4}, - .expected_result = {TRUE, TRUE, TRUE}}; - - test_acd_common(fixture, &info); -} - -static void -test_acd_probe_2(test_fixture *fixture, gconstpointer user_data) -{ - TestInfo info = {.addresses = {ADDR1, ADDR2, ADDR3, ADDR4}, - .peer_addresses = {ADDR3, ADDR2}, - .expected_result = {TRUE, FALSE, FALSE, TRUE}}; - - test_acd_common(fixture, &info); -} - -static void -test_acd_announce(test_fixture *fixture, gconstpointer user_data) -{ - nm_auto_free_acdmgr NMAcdManager *manager = NULL; - nm_auto_unref_gmainloop GMainLoop *loop = NULL; - int r; - - if (_skip_acd_test()) - return; - - manager = - nm_acd_manager_new(fixture->ifindex0, fixture->hwaddr0, fixture->hwaddr0_len, NULL, NULL); - g_assert(manager != NULL); - - g_assert(nm_acd_manager_add_address(manager, ADDR1)); - g_assert(nm_acd_manager_add_address(manager, ADDR2)); - - loop = g_main_loop_new(NULL, FALSE); - r = nm_acd_manager_announce_addresses(manager); - g_assert_cmpint(r, ==, 0); - g_assert(!nmtst_main_loop_run(loop, 200)); -} - -static void -fixture_teardown(test_fixture *fixture, gconstpointer user_data) -{ - nm_platform_link_delete(NM_PLATFORM_GET, fixture->ifindex0); - nm_platform_link_delete(NM_PLATFORM_GET, fixture->ifindex1); -} - -NMTstpSetupFunc const _nmtstp_setup_platform_func = nm_linux_platform_setup; - -void -_nmtstp_init_tests(int *argc, char ***argv) -{ - nmtst_init_with_logging(argc, argv, NULL, "ALL"); -} - -void -_nmtstp_setup_tests(void) -{ - g_test_add("/acd/probe/1", - test_fixture, - NULL, - fixture_setup, - test_acd_probe_1, - fixture_teardown); - g_test_add("/acd/probe/2", - test_fixture, - NULL, - fixture_setup, - test_acd_probe_2, - fixture_teardown); - g_test_add("/acd/announce", - test_fixture, - NULL, - fixture_setup, - test_acd_announce, - fixture_teardown); -} diff --git a/src/core/devices/tests/test-lldp.c b/src/core/devices/tests/test-lldp.c index c64c7c11..048410c1 100644 --- a/src/core/devices/tests/test-lldp.c +++ b/src/core/devices/tests/test-lldp.c @@ -22,15 +22,15 @@ /*****************************************************************************/ static GVariant * -get_lldp_neighbor(GVariant * neighbors, +get_lldp_neighbor(GVariant *neighbors, int chassis_id_type, const char *chassis_id, int port_id_type, const char *port_id) { GVariantIter iter; - GVariant * variant; - GVariant * result = NULL; + GVariant *variant; + GVariant *result = NULL; nmtst_assert_variant_is_of_type(neighbors, G_VARIANT_TYPE("aa{sv}")); @@ -81,15 +81,15 @@ typedef struct { typedef struct { gsize frame_len; const uint8_t *frame; - const char * as_variant; + const char *as_variant; } TestRecvFrame; #define TEST_RECV_FRAME_DEFINE(name, _as_variant, ...) \ static const guint8 _##name##_v[] = {__VA_ARGS__}; \ static const TestRecvFrame name = { \ - .as_variant = _as_variant, \ - .frame_len = sizeof(_##name##_v), \ - .frame = _##name##_v, \ + .as_variant = _as_variant, \ + .frame_len = sizeof(_##name##_v), \ + .frame = _##name##_v, \ } typedef struct { @@ -183,7 +183,7 @@ TEST_RECV_FRAME_DEFINE( static void _test_recv_data0_check_do(GMainLoop *loop, NMLldpListener *listener, const TestRecvFrame *frame) { - GVariant * neighbors, *attr; + GVariant *neighbors, *attr; gs_unref_variant GVariant *neighbor = NULL; neighbors = nm_lldp_listener_get_neighbors(listener); @@ -537,10 +537,10 @@ TEST_RECV_FRAME_DEFINE( static void _test_recv_data1_check(GMainLoop *loop, NMLldpListener *listener, TestRecvCallbackInfo *info) { - GVariant * neighbors, *attr, *child; + GVariant *neighbors, *attr, *child; gs_unref_variant GVariant *neighbor = NULL; guint v_uint = 0; - const char * v_str = NULL; + const char *v_str = NULL; neighbors = nm_lldp_listener_get_neighbors(listener); nmtst_assert_variant_is_of_type(neighbors, G_VARIANT_TYPE("aa{sv}")); @@ -868,12 +868,12 @@ lldp_neighbors_changed(NMLldpListener *lldp_listener, gpointer user_data) static void test_recv(TestRecvFixture *fixture, gconstpointer user_data) { - const TestRecvData * data = user_data; - NMLldpListener * listener; - GMainLoop * loop; + const TestRecvData *data = user_data; + NMLldpListener *listener; + GMainLoop *loop; TestRecvCallbackInfo info = {}; gsize i_frames; - GError * error = NULL; + GError *error = NULL; guint sd_id; if (fixture->ifindex == 0) { @@ -918,10 +918,10 @@ _test_recv_fixture_teardown(TestRecvFixture *fixture, gconstpointer user_data) static void test_parse_frames(gconstpointer test_data) { - const TestRecvFrame *frame = test_data; + const TestRecvFrame *frame = test_data; gs_unref_variant GVariant *v_neighbor = NULL; gs_unref_variant GVariant *attr = NULL; - gs_free char * as_variant = NULL; + gs_free char *as_variant = NULL; v_neighbor = nmtst_lldp_parse_from_raw(frame->frame, frame->frame_len); g_assert(v_neighbor); diff --git a/src/core/devices/wifi/meson.build b/src/core/devices/wifi/meson.build index 85553c53..715bc0c9 100644 --- a/src/core/devices/wifi/meson.build +++ b/src/core/devices/wifi/meson.build @@ -4,6 +4,7 @@ iwd_sources = files() if enable_iwd iwd_sources += files( 'nm-device-iwd.c', + 'nm-device-iwd-p2p.c', 'nm-iwd-manager.c', ) endif diff --git a/src/core/devices/wifi/nm-device-iwd-p2p.c b/src/core/devices/wifi/nm-device-iwd-p2p.c new file mode 100644 index 00000000..01774b12 --- /dev/null +++ b/src/core/devices/wifi/nm-device-iwd-p2p.c @@ -0,0 +1,1262 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021 Intel Corporation + */ + +#include "src/core/nm-default-daemon.h" + +#include "nm-device-iwd-p2p.h" + +#include "NetworkManagerUtils.h" +#include "devices/nm-device-private.h" +#include "nm-act-request.h" +#include "libnm-core-aux-intern/nm-libnm-core-utils.h" +#include "libnm-core-intern/nm-core-internal.h" +#include "libnm-std-aux/nm-dbus-compat.h" +#include "nm-setting-wifi-p2p.h" +#include "nm-utils.h" +#include "nm-wifi-p2p-peer.h" +#include "nm-iwd-manager.h" +#include "settings/nm-settings.h" + +#define _NMLOG_DEVICE_TYPE NMDeviceIwdP2P +#include "devices/nm-device-logging.h" + +/*****************************************************************************/ + +NM_GOBJECT_PROPERTIES_DEFINE(NMDeviceIwdP2P, PROP_PEERS, ); + +typedef struct { + GDBusObject *dbus_obj; + GDBusProxy *dbus_p2p_proxy; + GDBusProxy *dbus_peer_proxy; + CList peers_lst_head; + + GSource *find_peer_timeout_source; + GSource *peer_dump_source; + + GCancellable *find_cancellable; + GCancellable *connect_cancellable; + + bool enabled : 1; + + bool stage2_ready : 1; + + bool wfd_registered : 1; +} NMDeviceIwdP2PPrivate; + +struct _NMDeviceIwdP2P { + NMDevice parent; + NMDeviceIwdP2PPrivate _priv; +}; + +struct _NMDeviceIwdP2PClass { + NMDeviceClass parent; +}; + +G_DEFINE_TYPE(NMDeviceIwdP2P, nm_device_iwd_p2p, NM_TYPE_DEVICE) + +#define NM_DEVICE_IWD_P2P_GET_PRIVATE(self) \ + _NM_GET_PRIVATE(self, NMDeviceIwdP2P, NM_IS_DEVICE_IWD_P2P, NMDevice) + +/*****************************************************************************/ + +static const NMDBusInterfaceInfoExtended interface_info_device_wifi_p2p; +static const GDBusSignalInfo nm_signal_info_wifi_p2p_peer_added; +static const GDBusSignalInfo nm_signal_info_wifi_p2p_peer_removed; +static gboolean iwd_discovery_timeout_cb(gpointer user_data); + +/*****************************************************************************/ + +static void +_peer_dump(NMDeviceIwdP2P *self, + NMLogLevel log_level, + const NMWifiP2PPeer *peer, + const char *prefix, + gint32 now_s) +{ + char buf[1024]; + + _NMLOG(log_level, + LOGD_WIFI_SCAN, + "wifi-peer: %-7s %s", + prefix, + nm_wifi_p2p_peer_to_string(peer, buf, sizeof(buf), now_s)); +} + +static gboolean +peer_list_dump(gpointer user_data) +{ + NMDeviceIwdP2P *self = NM_DEVICE_IWD_P2P(user_data); + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + + nm_clear_g_source_inst(&priv->peer_dump_source); + + if (_LOGD_ENABLED(LOGD_WIFI_SCAN)) { + NMWifiP2PPeer *peer; + gint32 now_s = nm_utils_get_monotonic_timestamp_sec(); + + _LOGD(LOGD_WIFI_SCAN, "P2P Peers: [now:%u]", now_s); + c_list_for_each_entry (peer, &priv->peers_lst_head, peers_lst) + _peer_dump(self, LOGL_DEBUG, peer, "dump", now_s); + } + + return G_SOURCE_REMOVE; +} + +static void +schedule_peer_list_dump(NMDeviceIwdP2P *self) +{ + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + + if (!priv->peer_dump_source && _LOGD_ENABLED(LOGD_WIFI_SCAN)) { + priv->peer_dump_source = nm_g_timeout_add_seconds_source(1, peer_list_dump, self); + } +} + +/*****************************************************************************/ + +static gboolean +is_available(NMDevice *device, NMDeviceCheckDevAvailableFlags flags) +{ + NMDeviceIwdP2P *self = NM_DEVICE_IWD_P2P(device); + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + + return priv->enabled; +} + +static gboolean +check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error) +{ + NMSettingWifiP2P *s_wifi_p2p; + GBytes *wfd_ies; + NMSettingIPConfig *s_ip; + + if (!NM_DEVICE_CLASS(nm_device_iwd_p2p_parent_class) + ->check_connection_compatible(device, connection, error)) + return FALSE; + + s_wifi_p2p = + NM_SETTING_WIFI_P2P(nm_connection_get_setting(connection, NM_TYPE_SETTING_WIFI_P2P)); + + /* Any of the existing values other than DISABLED is ok */ + if (nm_setting_wifi_p2p_get_wps_method(s_wifi_p2p) + == NM_SETTING_WIRELESS_SECURITY_WPS_METHOD_DISABLED) { + nm_utils_error_set_literal(error, + NM_UTILS_ERROR_CONNECTION_AVAILABLE_INCOMPATIBLE, + "No WPS method enabled"); + return FALSE; + } + + wfd_ies = nm_setting_wifi_p2p_get_wfd_ies(s_wifi_p2p); + if (wfd_ies && !nm_wifi_utils_parse_wfd_ies(wfd_ies, NULL)) { + nm_utils_error_set_literal(error, + NM_UTILS_ERROR_CONNECTION_AVAILABLE_INCOMPATIBLE, + "Can't parse connection WFD IEs"); + return FALSE; + } + + s_ip = NM_SETTING_IP_CONFIG(nm_connection_get_setting_ip4_config(connection)); + if (s_ip + && !NM_IN_STRSET(nm_setting_ip_config_get_method(s_ip), + NULL, + NM_SETTING_IP4_CONFIG_METHOD_AUTO)) { + nm_utils_error_set_literal(error, + NM_UTILS_ERROR_CONNECTION_AVAILABLE_INCOMPATIBLE, + "P2P implies 'auto' IPv4 config method"); + return FALSE; + } + + return TRUE; +} + +static gboolean +check_connection_available(NMDevice *device, + NMConnection *connection, + NMDeviceCheckConAvailableFlags flags, + const char *specific_object, + GError **error) +{ + NMDeviceIwdP2P *self = NM_DEVICE_IWD_P2P(device); + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + NMSettingWifiP2P *s_wifi_p2p; + GBytes *wfd_ies; + NMWifiP2PPeer *peer; + + if (specific_object) { + peer = nm_wifi_p2p_peer_lookup_for_device(NM_DEVICE(self), specific_object); + if (!peer) { + g_set_error(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY, + "The P2P peer %s is unknown", + specific_object); + return FALSE; + } + + if (!nm_wifi_p2p_peer_check_compatible(peer, connection, FALSE)) { + nm_utils_error_set_literal(error, + NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY, + "Requested P2P peer is not compatible with profile"); + return FALSE; + } + } else { + peer = nm_wifi_p2p_peers_find_first_compatible(&priv->peers_lst_head, connection, FALSE); + if (!peer) { + nm_utils_error_set_literal(error, + NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY, + "No compatible P2P peer found"); + return FALSE; + } + } + + s_wifi_p2p = + NM_SETTING_WIFI_P2P(nm_connection_get_setting(connection, NM_TYPE_SETTING_WIFI_P2P)); + wfd_ies = nm_setting_wifi_p2p_get_wfd_ies(s_wifi_p2p); + if (wfd_ies) { + NMIwdWfdInfo wfd_info = {}; + + if (!nm_wifi_utils_parse_wfd_ies(wfd_ies, &wfd_info)) { + nm_utils_error_set_literal(error, + NM_UTILS_ERROR_CONNECTION_AVAILABLE_INCOMPATIBLE, + "Can't parse connection WFD IEs"); + return FALSE; + } + + if (!nm_iwd_manager_check_wfd_info_compatible(nm_iwd_manager_get(), &wfd_info)) { + nm_utils_error_set_literal(error, + NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY, + "An incompatible WFD connection is active"); + return FALSE; + } + } + + return TRUE; +} + +static gboolean +complete_connection(NMDevice *device, + NMConnection *connection, + const char *specific_object, + NMConnection *const *existing_connections, + GError **error) +{ + NMDeviceIwdP2P *self = NM_DEVICE_IWD_P2P(device); + gs_free char *setting_name = NULL; + NMSettingWifiP2P *s_wifi_p2p; + NMWifiP2PPeer *peer; + const char *setting_peer; + + s_wifi_p2p = + NM_SETTING_WIFI_P2P(nm_connection_get_setting(connection, NM_TYPE_SETTING_WIFI_P2P)); + + if (!specific_object) { + /* If not given a specific object, we need at minimum a peer address */ + if (!s_wifi_p2p) { + g_set_error(error, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_INVALID_CONNECTION, + "A '%s' setting is required if no Peer path was given", + NM_SETTING_WIFI_P2P_SETTING_NAME); + return FALSE; + } + + setting_peer = nm_setting_wifi_p2p_get_peer(s_wifi_p2p); + if (!setting_peer) { + g_set_error(error, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_INVALID_CONNECTION, + "A '%s' setting with a valid Peer is required if no Peer path was given", + NM_SETTING_WIFI_P2P_SETTING_NAME); + return FALSE; + } + } else { + peer = nm_wifi_p2p_peer_lookup_for_device(NM_DEVICE(self), specific_object); + if (!peer) { + g_set_error(error, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_SPECIFIC_OBJECT_NOT_FOUND, + "The P2P peer %s is unknown", + specific_object); + return FALSE; + } + + setting_peer = nm_wifi_p2p_peer_get_address(peer); + g_return_val_if_fail(setting_peer, FALSE); + } + + /* Add a Wi-Fi P2P setting if one doesn't exist yet */ + s_wifi_p2p = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_WIFI_P2P); + + g_object_set(G_OBJECT(s_wifi_p2p), NM_SETTING_WIFI_P2P_PEER, setting_peer, NULL); + + setting_name = g_strdup_printf("Wi-Fi P2P Peer %s", setting_peer); + nm_utils_complete_generic(nm_device_get_platform(device), + connection, + NM_SETTING_WIFI_P2P_SETTING_NAME, + existing_connections, + setting_name, + setting_name, + NULL, + NULL, + TRUE); + + return TRUE; +} + +static gboolean +get_enabled(NMDevice *device) +{ + return NM_DEVICE_IWD_P2P_GET_PRIVATE(device)->enabled; +} + +static void +set_enabled_cb(GObject *source, GAsyncResult *res, gpointer user_data) +{ + NMDeviceIwdP2P *self = user_data; + gs_unref_variant GVariant *variant = NULL; + gs_free_error GError *error = NULL; + + variant = g_dbus_proxy_call_finish(G_DBUS_PROXY(source), res, &error); + if (!variant) { + _LOGE(LOGD_DEVICE | LOGD_WIFI, ".Set failed: %s", error->message); + return; + } + _LOGD(LOGD_DEVICE | LOGD_WIFI, ".Set OK!"); +} + +static void +set_enabled(NMDevice *device, gboolean enabled) +{ + NMDeviceIwdP2P *self = NM_DEVICE_IWD_P2P(device); + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + + enabled = !!enabled; + + if (priv->enabled == enabled) + return; + + _LOGD(LOGD_WIFI, "device will be %s", enabled ? "enabled" : "disabled"); + + g_dbus_proxy_call( + priv->dbus_p2p_proxy, + DBUS_INTERFACE_PROPERTIES ".Set", + g_variant_new("(ssv)", NM_IWD_P2P_INTERFACE, "Enabled", g_variant_new("b", enabled)), + G_DBUS_CALL_FLAGS_NONE, + 2000, + NULL, + set_enabled_cb, + self); +} + +static void +p2p_properties_changed_cb(GDBusProxy *proxy, + GVariant *changed_properties, + GStrv invalidate_properties, + gpointer user_data) +{ + NMDeviceIwdP2P *self = user_data; + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + NMDevice *device = NM_DEVICE(self); + gboolean new_bool; + + if (g_variant_lookup(changed_properties, "Enabled", "b", &new_bool) + && new_bool != priv->enabled) { + priv->enabled = new_bool; + + _LOGD(LOGD_WIFI, "device now %s", priv->enabled ? "enabled" : "disabled"); + + if (priv->enabled) { + NMDeviceState state = nm_device_get_state(device); + + if (state != NM_DEVICE_STATE_UNAVAILABLE) + _LOGW(LOGD_CORE, "not in expected unavailable state!"); + + nm_device_queue_recheck_available(device, + NM_DEVICE_STATE_REASON_SUPPLICANT_AVAILABLE, + NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED); + } else { + nm_device_state_changed(device, + NM_DEVICE_STATE_UNAVAILABLE, + NM_DEVICE_STATE_REASON_NONE); + } + } +} + +static void +iwd_request_discovery_cb(GObject *source, GAsyncResult *res, gpointer user_data) +{ + NMDeviceIwdP2P *self = user_data; + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + gs_unref_variant GVariant *variant = NULL; + gs_free_error GError *error = NULL; + + variant = g_dbus_proxy_call_finish(G_DBUS_PROXY(source), res, &error); + if (!variant) { + NMDevice *device = NM_DEVICE(self); + + _LOGE(LOGD_DEVICE | LOGD_WIFI, + "%s(wifi-p2p) IWD p2p.Device.RequestDiscovery failed: %s", + nm_device_is_activating(device) ? "Activation: " : "", + error->message); + + if (nm_utils_error_is_cancelled(error) && !nm_device_is_activating(device)) + return; + + nm_clear_g_cancellable(&priv->find_cancellable); + nm_device_state_changed(device, + NM_DEVICE_STATE_FAILED, + NM_DEVICE_STATE_REASON_PEER_NOT_FOUND); + return; + } + + nm_clear_g_cancellable(&priv->find_cancellable); + _LOGI(LOGD_DEVICE | LOGD_WIFI, + "%s(wifi-p2p) Target peer discovery running", + nm_device_is_activating(NM_DEVICE(self)) ? "Activation: " : ""); +} + +static void +iwd_request_discovery(NMDeviceIwdP2P *self, unsigned timeout) +{ + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + bool requested = priv->find_peer_timeout_source != NULL; + + nm_clear_g_source_inst(&priv->find_peer_timeout_source); + priv->find_peer_timeout_source = + nm_g_timeout_add_seconds_source(timeout, iwd_discovery_timeout_cb, self); + + if (!requested) { + priv->find_cancellable = g_cancellable_new(); + + g_dbus_proxy_call(priv->dbus_p2p_proxy, + "RequestDiscovery", + NULL, + G_DBUS_CALL_FLAGS_NONE, + G_MAXINT, + priv->find_cancellable, + iwd_request_discovery_cb, + self); + } +} + +static void +iwd_release_discovery(NMDeviceIwdP2P *self) +{ + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + + nm_clear_g_source_inst(&priv->find_peer_timeout_source); + nm_clear_g_cancellable(&priv->find_cancellable); + + g_dbus_proxy_call(priv->dbus_p2p_proxy, + "ReleaseDiscovery", + NULL, + G_DBUS_CALL_FLAGS_NONE, + G_MAXINT, + NULL, + NULL, + self); +} + +/* + * Called when IWD has been unable to find the peer we want to connect to within the + * 10s time limit or when a D-bus Find() ends. + */ +static gboolean +iwd_discovery_timeout_cb(gpointer user_data) +{ + NMDeviceIwdP2P *self = NM_DEVICE_IWD_P2P(user_data); + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + NMDevice *device = NM_DEVICE(self); + + nm_clear_g_source_inst(&priv->find_peer_timeout_source); + + iwd_release_discovery(self); + + if (nm_device_is_activating(device)) { + _LOGW(LOGD_DEVICE | LOGD_WIFI, + "Activation: (wifi-p2p) Could not find peer, failing activation"); + nm_device_state_changed(device, + NM_DEVICE_STATE_FAILED, + NM_DEVICE_STATE_REASON_PEER_NOT_FOUND); + } else { + _LOGD(LOGD_DEVICE | LOGD_WIFI, "(wifi-p2p) Find timeout"); + } + + return G_SOURCE_REMOVE; +} + +static void +cleanup_connect_attempt(NMDeviceIwdP2P *self) +{ + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + + if (priv->find_peer_timeout_source) + iwd_release_discovery(self); + + if (priv->wfd_registered) { + nm_iwd_manager_unregister_wfd(nm_iwd_manager_get()); + priv->wfd_registered = FALSE; + } + + if (!priv->dbus_peer_proxy) + return; + + if (nm_device_is_activating(NM_DEVICE(self))) + nm_device_set_ip_iface(NM_DEVICE(self), NULL); + + priv->stage2_ready = FALSE; + g_signal_handlers_disconnect_by_data(priv->dbus_peer_proxy, self); + g_clear_object(&priv->dbus_peer_proxy); + nm_clear_g_cancellable(&priv->connect_cancellable); +} + +static void +peer_properties_changed_cb(GDBusProxy *proxy, + GVariant *changed_properties, + GStrv invalidate_properties, + gpointer user_data) +{ + NMDeviceIwdP2P *self = user_data; + NMDeviceState state = nm_device_get_state(NM_DEVICE(self)); + gboolean new_bool; + const char *new_str; + + if (g_variant_lookup(changed_properties, "Connected", "b", &new_bool) && !new_bool + && state >= NM_DEVICE_STATE_CONFIG && state <= NM_DEVICE_STATE_DEACTIVATING) { + cleanup_connect_attempt(self); + nm_device_state_changed(NM_DEVICE(self), + NM_DEVICE_STATE_DISCONNECTED, + NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT); + } + + if (g_variant_lookup(changed_properties, "ConnectedInterface", "&s", &new_str) + && state >= NM_DEVICE_STATE_CONFIG && state <= NM_DEVICE_STATE_IP_CONFIG) { + nm_device_set_ip_iface(NM_DEVICE(self), new_str); + } +} + +static NMActStageReturn +act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) +{ + NMDeviceIwdP2P *self = NM_DEVICE_IWD_P2P(device); + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + NMConnection *connection; + NMSettingWifiP2P *s_wifi_p2p; + NMWifiP2PPeer *peer; + GBytes *wfd_ies; + + if (!priv->enabled) { + NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED); + return NM_ACT_STAGE_RETURN_FAILURE; + } + + connection = nm_device_get_applied_connection(NM_DEVICE(self)); + g_return_val_if_fail(connection, NM_ACT_STAGE_RETURN_FAILURE); + + s_wifi_p2p = + NM_SETTING_WIFI_P2P(nm_connection_get_setting(connection, NM_TYPE_SETTING_WIFI_P2P)); + g_return_val_if_fail(s_wifi_p2p, NM_ACT_STAGE_RETURN_FAILURE); + + /* Set the WFD IEs before connecting and before peer discovery if that is needed, + * usually the WFD IEs need to actually be sent in the Probe frames before we can + * receive the peers' WFD IEs and decide whether the peer is compatible with the + * requested WFD parameters. In the current setup we only get the WFD IEs from + * the connection settings so during a normal find the client will not be getting + * any WFD information about the peers and has to decide to connect based on the + * name and device type (category + subcategory) -- assuming that the peers even + * bother to reply to probes without WFD IEs. We'll then need to redo the find + * here in PREPARE because IWD wants to see that the parameters in the peer's + * WFD IEs match those in our WFD IEs. The normal use case for IWD is that the + * WFD client registers its WFD parameters as soon as it starts and they remain + * registered during the find and then during the connect. */ + wfd_ies = nm_setting_wifi_p2p_get_wfd_ies(s_wifi_p2p); + if (wfd_ies) { + NMIwdWfdInfo wfd_info = {}; + + if (!nm_wifi_utils_parse_wfd_ies(wfd_ies, &wfd_info)) { + _LOGE(LOGD_DEVICE | LOGD_WIFI, "Activation: (wifi-p2p) Can't parse connection WFD IEs"); + NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_CONFIG_FAILED); + return NM_ACT_STAGE_RETURN_FAILURE; + } + + if (!nm_iwd_manager_check_wfd_info_compatible(nm_iwd_manager_get(), &wfd_info)) { + _LOGE(LOGD_DEVICE | LOGD_WIFI, + "Activation: (wifi-p2p) An incompatible WFD connection is active"); + NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_CONFIG_FAILED); + return NM_ACT_STAGE_RETURN_FAILURE; + } + + if (!nm_iwd_manager_register_wfd(nm_iwd_manager_get(), &wfd_info)) { + _LOGE(LOGD_DEVICE | LOGD_WIFI, "Activation: (wifi-p2p) Can't register WFD service"); + NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_CONFIG_FAILED); + return NM_ACT_STAGE_RETURN_FAILURE; + } + + priv->wfd_registered = TRUE; + } + + peer = nm_wifi_p2p_peers_find_first_compatible(&priv->peers_lst_head, connection, TRUE); + if (!peer) { + iwd_request_discovery(self, 10); + return NM_ACT_STAGE_RETURN_POSTPONE; + } else if (priv->find_peer_timeout_source) { + iwd_release_discovery(self); + } + + return NM_ACT_STAGE_RETURN_SUCCESS; +} + +static void +iwd_wsc_connect_cb(GObject *source, GAsyncResult *res, gpointer user_data) +{ + NMDeviceIwdP2P *self = user_data; + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + gs_unref_variant GVariant *variant = NULL; + gs_free_error GError *error = NULL; + NMDevice *device = NM_DEVICE(self); + + variant = g_dbus_proxy_call_finish(G_DBUS_PROXY(source), res, &error); + if (!variant) { + _LOGE(LOGD_DEVICE | LOGD_WIFI, + "Activation: (wifi-p2p) IWD SimpleConfiguration.PushButton/StartPin() failed: %s", + error->message); + + if (nm_utils_error_is_cancelled(error) && !nm_device_is_activating(device)) + return; + + nm_clear_g_cancellable(&priv->connect_cancellable); + nm_device_state_changed(device, + NM_DEVICE_STATE_FAILED, + NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED); + return; + } + + nm_clear_g_cancellable(&priv->connect_cancellable); + _LOGI(LOGD_DEVICE | LOGD_WIFI, "Activation: (wifi-p2p) IWD connection successful"); + + g_signal_connect(priv->dbus_peer_proxy, + "g-properties-changed", + G_CALLBACK(peer_properties_changed_cb), + self); + + priv->stage2_ready = TRUE; + + nm_device_activate_schedule_stage2_device_config(device, FALSE); +} + +static NMActStageReturn +act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) +{ + NMDeviceIwdP2P *self = NM_DEVICE_IWD_P2P(device); + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + NMConnection *connection; + NMSettingWifiP2P *s_wifi_p2p; + NMWifiP2PPeer *peer; + gs_unref_object GDBusProxy *peer_proxy = NULL; + gs_unref_object GDBusProxy *wsc_proxy = NULL; + + if (priv->stage2_ready) + return NM_ACT_STAGE_RETURN_SUCCESS; + + if (!priv->dbus_p2p_proxy) { + cleanup_connect_attempt(self); + NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED); + return NM_ACT_STAGE_RETURN_FAILURE; + } + + if (nm_clear_g_source_inst(&priv->find_peer_timeout_source)) + nm_assert_not_reached(); + + connection = nm_device_get_applied_connection(device); + g_return_val_if_fail(connection, NM_ACT_STAGE_RETURN_FAILURE); + nm_assert( + NM_IS_SETTING_WIFI_P2P(nm_connection_get_setting(connection, NM_TYPE_SETTING_WIFI_P2P))); + + /* The prepare stage ensures that the peer has been found */ + peer = nm_wifi_p2p_peers_find_first_compatible(&priv->peers_lst_head, connection, TRUE); + if (!peer) { + cleanup_connect_attempt(self); + NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_PEER_NOT_FOUND); + return NM_ACT_STAGE_RETURN_FAILURE; + } + + s_wifi_p2p = + NM_SETTING_WIFI_P2P(nm_connection_get_setting(connection, NM_TYPE_SETTING_WIFI_P2P)); + if (nm_setting_wifi_p2p_get_wps_method(s_wifi_p2p) + == NM_SETTING_WIRELESS_SECURITY_WPS_METHOD_PIN) { + /* TODO: check we have the pin secret, if so use StartPin(pin) otherwise request pin, + * move to NEED_AUTH and return postpone */ + cleanup_connect_attempt(self); + NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED); + return NM_ACT_STAGE_RETURN_FAILURE; + } + + peer_proxy = nm_iwd_manager_get_dbus_interface(nm_iwd_manager_get(), + nm_wifi_p2p_peer_get_supplicant_path(peer), + NM_IWD_P2P_PEER_INTERFACE); + wsc_proxy = nm_iwd_manager_get_dbus_interface(nm_iwd_manager_get(), + nm_wifi_p2p_peer_get_supplicant_path(peer), + NM_IWD_WSC_INTERFACE); + + if (!wsc_proxy || !peer_proxy) { + cleanup_connect_attempt(self); + NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_PEER_NOT_FOUND); + return NM_ACT_STAGE_RETURN_FAILURE; + } + + g_dbus_proxy_call(wsc_proxy, + "PushButton", + NULL, + G_DBUS_CALL_FLAGS_NONE, + G_MAXINT, + priv->connect_cancellable, + iwd_wsc_connect_cb, + self); + + priv->dbus_peer_proxy = g_steal_pointer(&peer_proxy); + return NM_ACT_STAGE_RETURN_POSTPONE; +} + +/*****************************************************************************/ + +static void +emit_signal_p2p_peer_add_remove(NMDeviceIwdP2P *device, + NMWifiP2PPeer *peer, + gboolean is_added /* or else is_removed */) +{ + nm_dbus_object_emit_signal(NM_DBUS_OBJECT(device), + &interface_info_device_wifi_p2p, + is_added ? &nm_signal_info_wifi_p2p_peer_added + : &nm_signal_info_wifi_p2p_peer_removed, + "(o)", + nm_dbus_object_get_path(NM_DBUS_OBJECT(peer))); +} + +static void +act_check_new_peer_compatible(NMDeviceIwdP2P *self, NMWifiP2PPeer *peer) +{ + NMDevice *device = NM_DEVICE(self); + NMConnection *connection; + + connection = nm_device_get_applied_connection(device); + nm_assert(NM_IS_CONNECTION(connection)); + + if (nm_wifi_p2p_peer_check_compatible(peer, connection, TRUE)) { + /* A peer for the connection was found, cancel the timeout and go to configure state. */ + iwd_release_discovery(self); + nm_device_activate_schedule_stage2_device_config(device, FALSE); + } +} + +static void +peer_add_remove(NMDeviceIwdP2P *self, + gboolean is_adding, /* or else removing */ + NMWifiP2PPeer *peer, + gboolean recheck_available_connections) +{ + NMDevice *device = NM_DEVICE(self); + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + + if (is_adding) { + g_object_ref(peer); + peer->wifi_device = device; + c_list_link_tail(&priv->peers_lst_head, &peer->peers_lst); + nm_dbus_object_export(NM_DBUS_OBJECT(peer)); + _peer_dump(self, LOGL_DEBUG, peer, "added", 0); + + emit_signal_p2p_peer_add_remove(self, peer, TRUE); + } else { + peer->wifi_device = NULL; + c_list_unlink(&peer->peers_lst); + _peer_dump(self, LOGL_DEBUG, peer, "removed", 0); + } + + _notify(self, PROP_PEERS); + + if (!is_adding) { + emit_signal_p2p_peer_add_remove(self, peer, FALSE); + nm_dbus_object_clear_and_unexport(&peer); + } + + if (is_adding) { + /* If we are in prepare state, then we are currently running a find + * to search for the requested peer. */ + if (priv->find_peer_timeout_source + && nm_device_get_state(device) == NM_DEVICE_STATE_PREPARE) + act_check_new_peer_compatible(self, peer); + + /* TODO: We may want to re-check auto-activation here */ + } +} + +static void +iwd_peer_interface_added_cb(GDBusObject *peer_obj, GDBusInterface *interface, gpointer user_data) +{ + NMDeviceIwdP2P *self = user_data; + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + const char *iface_name; + NMWifiP2PPeer *peer; + + g_return_if_fail(G_IS_DBUS_PROXY(interface)); + + iface_name = g_dbus_proxy_get_interface_name(G_DBUS_PROXY(interface)); + if (!nm_streq(iface_name, NM_IWD_P2P_WFD_INTERFACE)) + return; + + peer = nm_wifi_p2p_peers_find_by_supplicant_path(&priv->peers_lst_head, + g_dbus_object_get_object_path(peer_obj)); + if (!peer) + return; + + nm_wifi_p2p_peer_update_from_iwd_object(peer, peer_obj); + + /* If we are in prepare state, then we are currently running a find + * to search for the requested peer. */ + if (priv->find_peer_timeout_source) + act_check_new_peer_compatible(self, peer); +} + +static void +iwd_peer_interface_removed_cb(GDBusObject *peer_obj, GDBusInterface *interface, gpointer user_data) +{ + NMDeviceIwdP2P *self = user_data; + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + const char *iface_name; + NMWifiP2PPeer *peer; + + g_return_if_fail(G_IS_DBUS_PROXY(interface)); + + iface_name = g_dbus_proxy_get_interface_name(G_DBUS_PROXY(interface)); + if (!nm_streq(iface_name, NM_IWD_P2P_WFD_INTERFACE)) + return; + + peer = nm_wifi_p2p_peers_find_by_supplicant_path(&priv->peers_lst_head, + g_dbus_object_get_object_path(peer_obj)); + if (!peer) + return; + + nm_wifi_p2p_peer_set_wfd_ies(peer, NULL); +} + +void +nm_device_iwd_p2p_peer_add_remove(NMDeviceIwdP2P *self, GDBusObject *peer_obj, bool add) +{ + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + NMWifiP2PPeer *found_peer; + + found_peer = nm_wifi_p2p_peers_find_by_supplicant_path(&priv->peers_lst_head, + g_dbus_object_get_object_path(peer_obj)); + + if (found_peer && !add) { + if (priv->dbus_peer_proxy + && !nm_streq(g_dbus_object_get_object_path(peer_obj), + g_dbus_proxy_get_object_path(priv->dbus_peer_proxy))) { + cleanup_connect_attempt(self); + nm_device_state_changed(NM_DEVICE(self), + NM_DEVICE_STATE_DISCONNECTED, + NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT); + } + + peer_add_remove(self, FALSE, found_peer, TRUE); + g_signal_handlers_disconnect_by_data(peer_obj, self); + } + + if (!found_peer && add) { + gs_unref_object NMWifiP2PPeer *peer = nm_wifi_p2p_peer_new_from_iwd_object(peer_obj); + + if (!peer) { + _LOGD(LOGD_DEVICE | LOGD_WIFI, + "Can't interpret IWD Peer properties at %s", + g_dbus_object_get_object_path(peer_obj)); + return; + } + + peer_add_remove(self, TRUE, peer, TRUE); + + /* None of the D-Bus properties that we use on this interface emit PropertiesChanges + * signals, only the WFD properties do. We do listen to changes to "Connected" + * but only while we're connecting/connected to a given peer. + */ + g_signal_connect(peer_obj, + "interface-added", + G_CALLBACK(iwd_peer_interface_added_cb), + self); + g_signal_connect(peer_obj, + "interface-removed", + G_CALLBACK(iwd_peer_interface_removed_cb), + self); + + /* TODO: every now and then call p2p.Device.GetPeers() and update the signal strength + * values for all peers we got through ObjectManager events. + */ + } + + schedule_peer_list_dump(self); +} + +/*****************************************************************************/ + +static void +deactivate(NMDevice *device) +{ + NMDeviceIwdP2P *self = NM_DEVICE_IWD_P2P(device); + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + + if (priv->find_peer_timeout_source) + iwd_release_discovery(self); + + if (priv->dbus_peer_proxy) { + g_dbus_proxy_call(priv->dbus_peer_proxy, + "Disconnect", + NULL, + G_DBUS_CALL_FLAGS_NONE, + G_MAXINT, + NULL, + NULL, + self); + + cleanup_connect_attempt(self); + } +} + +static guint32 +get_configured_mtu(NMDevice *device, NMDeviceMtuSource *out_source, gboolean *out_force) +{ + *out_source = NM_DEVICE_MTU_SOURCE_NONE; + return 0; +} + +static gboolean +unmanaged_on_quit(NMDevice *self) +{ + return TRUE; +} + +static void +device_state_changed(NMDevice *device, + NMDeviceState new_state, + NMDeviceState old_state, + NMDeviceStateReason reason) +{ + NMDeviceIwdP2P *self = NM_DEVICE_IWD_P2P(device); + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + + switch (new_state) { + case NM_DEVICE_STATE_UNMANAGED: + break; + case NM_DEVICE_STATE_UNAVAILABLE: + if (priv->enabled) { + nm_device_queue_recheck_available(device, + NM_DEVICE_STATE_REASON_SUPPLICANT_AVAILABLE, + NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED); + } + break; + case NM_DEVICE_STATE_IP_CONFIG: + /* TODO: start periodic RSSI and bitrate updates? */ + break; + default: + break; + } +} + +static void +impl_device_iwd_p2p_start_find(NMDBusObject *obj, + const NMDBusInterfaceInfoExtended *interface_info, + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) +{ + NMDeviceIwdP2P *self = NM_DEVICE_IWD_P2P(obj); + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + gs_unref_variant GVariant *options = NULL; + const char *opts_key; + GVariant *opts_val; + GVariantIter iter; + gint32 timeout = 30; + + g_variant_get(parameters, "(@a{sv})", &options); + + g_variant_iter_init(&iter, options); + while (g_variant_iter_next(&iter, "{&sv}", &opts_key, &opts_val)) { + _nm_unused gs_unref_variant GVariant *opts_val_free = opts_val; + + if (nm_streq(opts_key, "timeout")) { + if (!g_variant_is_of_type(opts_val, G_VARIANT_TYPE_INT32)) { + g_dbus_method_invocation_return_error_literal( + invocation, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_INVALID_ARGUMENT, + "\"timeout\" must be an integer \"i\""); + return; + } + + timeout = g_variant_get_int32(opts_val); + if (timeout <= 0 || timeout > 600) { + g_dbus_method_invocation_return_error_literal( + invocation, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_NOT_ALLOWED, + "The timeout for a find operation needs to be in the range of 1-600s."); + return; + } + + continue; + } + + g_dbus_method_invocation_return_error(invocation, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_INVALID_ARGUMENT, + "Unsupported options key \"%s\"", + opts_key); + return; + } + + if (!priv->enabled || nm_device_is_activating(NM_DEVICE(self))) { + g_dbus_method_invocation_return_error_literal(invocation, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_NOT_ACTIVE, + "P2P device not enabled or busy."); + return; + } + + iwd_request_discovery(self, timeout); + g_dbus_method_invocation_return_value(invocation, NULL); +} + +static void +impl_device_iwd_p2p_stop_find(NMDBusObject *obj, + const NMDBusInterfaceInfoExtended *interface_info, + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) +{ + NMDeviceIwdP2P *self = NM_DEVICE_IWD_P2P(obj); + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + + if (!priv->find_peer_timeout_source || nm_device_is_activating(NM_DEVICE(self))) { + g_dbus_method_invocation_return_error_literal(invocation, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_NOT_ACTIVE, + "Find phase is not active."); + return; + } + + iwd_release_discovery(self); + g_dbus_method_invocation_return_value(invocation, NULL); +} + +/*****************************************************************************/ + +static bool +nm_device_iwd_p2p_set_dbus_obj(NMDeviceIwdP2P *self, GDBusObject *obj) +{ + NMDeviceIwdP2PPrivate *priv; + gs_unref_variant GVariant *enabled_value = NULL; + + g_return_val_if_fail(NM_IS_DEVICE_IWD_P2P(self), FALSE); + + priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + + if (priv->dbus_obj == obj) + goto done; + + if (priv->dbus_obj) { + cleanup_connect_attempt(self); + g_signal_handlers_disconnect_by_data(priv->dbus_p2p_proxy, self); + g_clear_object(&priv->dbus_p2p_proxy); + g_clear_object(&priv->dbus_obj); + priv->enabled = FALSE; + } + + if (!obj) + goto done; + + priv->dbus_p2p_proxy = G_DBUS_PROXY(g_dbus_object_get_interface(obj, NM_IWD_P2P_INTERFACE)); + if (!priv->dbus_p2p_proxy) + return FALSE; + + enabled_value = g_dbus_proxy_get_cached_property(priv->dbus_p2p_proxy, "Enabled"); + if (!enabled_value || !g_variant_is_of_type(enabled_value, G_VARIANT_TYPE_BOOLEAN)) + return FALSE; + + priv->dbus_obj = g_object_ref(obj); + + g_signal_connect(priv->dbus_p2p_proxy, + "g-properties-changed", + G_CALLBACK(p2p_properties_changed_cb), + self); + + priv->enabled = g_variant_get_boolean(enabled_value); + _LOGD(LOGD_WIFI, "iniital state is %s", priv->enabled ? "enabled" : "disabled"); + +done: + nm_device_queue_recheck_available(NM_DEVICE(self), + NM_DEVICE_STATE_REASON_SUPPLICANT_AVAILABLE, + NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED); + return TRUE; +} + +void +nm_device_iwd_p2p_remove(NMDeviceIwdP2P *self) +{ + g_signal_emit_by_name(self, NM_DEVICE_REMOVED); +} + +/*****************************************************************************/ + +static const char * +get_type_description(NMDevice *device) +{ + return "wifi-p2p"; +} + +/*****************************************************************************/ + +static const GDBusSignalInfo nm_signal_info_wifi_p2p_peer_added = NM_DEFINE_GDBUS_SIGNAL_INFO_INIT( + "PeerAdded", + .args = NM_DEFINE_GDBUS_ARG_INFOS(NM_DEFINE_GDBUS_ARG_INFO("peer", "o"), ), ); + +static const GDBusSignalInfo nm_signal_info_wifi_p2p_peer_removed = + NM_DEFINE_GDBUS_SIGNAL_INFO_INIT( + "PeerRemoved", + .args = NM_DEFINE_GDBUS_ARG_INFOS(NM_DEFINE_GDBUS_ARG_INFO("peer", "o"), ), ); + +static const NMDBusInterfaceInfoExtended interface_info_device_wifi_p2p = { + .parent = NM_DEFINE_GDBUS_INTERFACE_INFO_INIT( + NM_DBUS_INTERFACE_DEVICE_WIFI_P2P, + .methods = NM_DEFINE_GDBUS_METHOD_INFOS( + NM_DEFINE_DBUS_METHOD_INFO_EXTENDED( + NM_DEFINE_GDBUS_METHOD_INFO_INIT( + "StartFind", + .in_args = NM_DEFINE_GDBUS_ARG_INFOS( + NM_DEFINE_GDBUS_ARG_INFO("options", "a{sv}"), ), ), + .handle = impl_device_iwd_p2p_start_find, ), + NM_DEFINE_DBUS_METHOD_INFO_EXTENDED(NM_DEFINE_GDBUS_METHOD_INFO_INIT("StopFind", ), + .handle = impl_device_iwd_p2p_stop_find, ), ), + .signals = NM_DEFINE_GDBUS_SIGNAL_INFOS(&nm_signal_info_wifi_p2p_peer_added, + &nm_signal_info_wifi_p2p_peer_removed, ), + .properties = NM_DEFINE_GDBUS_PROPERTY_INFOS( + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("HwAddress", "s", NM_DEVICE_HW_ADDRESS), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Peers", + "ao", + NM_DEVICE_IWD_P2P_PEERS), ), ), +}; + +/*****************************************************************************/ + +static void +get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +{ + NMDeviceIwdP2P *self = NM_DEVICE_IWD_P2P(object); + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + const char **list; + + switch (prop_id) { + case PROP_PEERS: + list = nm_wifi_p2p_peers_get_paths(&priv->peers_lst_head); + g_value_take_boxed(value, nm_strv_make_deep_copied(list)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +/*****************************************************************************/ + +static void +nm_device_iwd_p2p_init(NMDeviceIwdP2P *self) +{ + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(self); + + c_list_init(&priv->peers_lst_head); +} + +NMDeviceIwdP2P * +nm_device_iwd_p2p_new(GDBusObject *dbus_obj) +{ + gs_unref_object NMDeviceIwdP2P *self = NULL; + + g_return_val_if_fail(!dbus_obj || G_IS_DBUS_OBJECT(dbus_obj), NULL); + + /* cfg80211 P2P-Device virtual interfaces don't map to netdev-type interfaces. + * Provide a false unique interface name only to avoid triggering assertions + * in NMManager and for that name to appear in debug messages. */ + self = g_object_new(NM_TYPE_DEVICE_IWD_P2P, + NM_DEVICE_IFACE, + g_dbus_object_get_object_path(dbus_obj), + NM_DEVICE_TYPE_DESC, + "802.11 Wi-Fi P2P", + NM_DEVICE_DEVICE_TYPE, + NM_DEVICE_TYPE_WIFI_P2P, + NM_DEVICE_LINK_TYPE, + NM_LINK_TYPE_WIFI, + NM_DEVICE_RFKILL_TYPE, + RFKILL_TYPE_WLAN, + NULL); + + if (!self || !nm_device_iwd_p2p_set_dbus_obj(self, dbus_obj)) + return NULL; + + return nm_steal_pointer(&self); +} + +static void +dispose(GObject *object) +{ + NMDeviceIwdP2P *self = NM_DEVICE_IWD_P2P(object); + NMDeviceIwdP2PPrivate *priv = NM_DEVICE_IWD_P2P_GET_PRIVATE(object); + + nm_clear_g_source_inst(&priv->peer_dump_source); + + nm_device_iwd_p2p_set_dbus_obj(self, NULL); + + G_OBJECT_CLASS(nm_device_iwd_p2p_parent_class)->dispose(object); +} + +static void +nm_device_iwd_p2p_class_init(NMDeviceIwdP2PClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS(klass); + NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); + + object_class->get_property = get_property; + object_class->dispose = dispose; + + dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS(&interface_info_device_wifi_p2p); + + device_class->connection_type_supported = NM_SETTING_WIFI_P2P_SETTING_NAME; + device_class->connection_type_check_compatible = NM_SETTING_WIFI_P2P_SETTING_NAME; + device_class->link_types = NM_DEVICE_DEFINE_LINK_TYPES(NM_LINK_TYPE_WIFI_P2P); + device_class->get_type_description = get_type_description; + + device_class->is_available = is_available; + device_class->check_connection_compatible = check_connection_compatible; + device_class->check_connection_available = check_connection_available; + device_class->complete_connection = complete_connection; + device_class->get_enabled = get_enabled; + device_class->set_enabled = set_enabled; + + device_class->act_stage1_prepare = act_stage1_prepare; + device_class->act_stage2_config = act_stage2_config; + device_class->get_configured_mtu = get_configured_mtu; + + device_class->deactivate = deactivate; + device_class->unmanaged_on_quit = unmanaged_on_quit; + + device_class->state_changed = device_state_changed; + + obj_properties[PROP_PEERS] = g_param_spec_boxed(NM_DEVICE_IWD_P2P_PEERS, + "", + "", + G_TYPE_STRV, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); +} diff --git a/src/core/devices/wifi/nm-device-iwd-p2p.h b/src/core/devices/wifi/nm-device-iwd-p2p.h new file mode 100644 index 00000000..9ce353c0 --- /dev/null +++ b/src/core/devices/wifi/nm-device-iwd-p2p.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021 Intel Corporation + */ + +#ifndef __NM_DEVICE_IWD_P2P_H__ +#define __NM_DEVICE_IWD_P2P_H__ + +#include "devices/nm-device.h" +#include "nm-device-wifi-p2p.h" + +#define NM_TYPE_DEVICE_IWD_P2P (nm_device_iwd_p2p_get_type()) +#define NM_DEVICE_IWD_P2P(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_DEVICE_IWD_P2P, NMDeviceIwdP2P)) +#define NM_DEVICE_IWD_P2P_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), NM_TYPE_DEVICE_IWD_P2P, NMDeviceIwdP2PClass)) +#define NM_IS_DEVICE_IWD_P2P(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NM_TYPE_DEVICE_IWD_P2P)) +#define NM_IS_DEVICE_IWD_P2P_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NM_TYPE_DEVICE_IWD_P2P)) +#define NM_DEVICE_IWD_P2P_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_DEVICE_IWD_P2P, NMDeviceIwdP2PClass)) + +#define NM_DEVICE_IWD_P2P_PEERS NM_DEVICE_WIFI_P2P_PEERS +#define NM_DEVICE_IWD_P2P_GROUPS NM_DEVICE_WIFI_P2P_GROUPS + +typedef struct _NMDeviceIwdP2P NMDeviceIwdP2P; +typedef struct _NMDeviceIwdP2PClass NMDeviceIwdP2PClass; + +GType nm_device_iwd_p2p_get_type(void); + +NMDeviceIwdP2P *nm_device_iwd_p2p_new(GDBusObject *object); + +void nm_device_iwd_p2p_remove(NMDeviceIwdP2P *p2p); + +void nm_device_iwd_p2p_peer_add_remove(NMDeviceIwdP2P *p2p, GDBusObject *peer_obj, bool add); + +#endif /* __NM_DEVICE_IWD_P2P_H__ */ diff --git a/src/core/devices/wifi/nm-device-iwd.c b/src/core/devices/wifi/nm-device-iwd.c index 27a3188b..7543d9da 100644 --- a/src/core/devices/wifi/nm-device-iwd.c +++ b/src/core/devices/wifi/nm-device-iwd.c @@ -48,14 +48,14 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMDeviceIwd, PROP_LAST_SCAN, ); typedef struct { - GDBusObject * dbus_obj; - GDBusProxy * dbus_device_proxy; - GDBusProxy * dbus_station_proxy; - GDBusProxy * dbus_ap_proxy; - GDBusProxy * dbus_adhoc_proxy; + GDBusObject *dbus_obj; + GDBusProxy *dbus_device_proxy; + GDBusProxy *dbus_station_proxy; + GDBusProxy *dbus_ap_proxy; + GDBusProxy *dbus_adhoc_proxy; CList aps_lst_head; - NMWifiAP * current_ap; - GCancellable * cancellable; + NMWifiAP *current_ap; + GCancellable *cancellable; _NMDeviceWifiCapabilities capabilities; NMActRequestGetSecretsCallId *wifi_secrets_id; guint periodic_scan_id; @@ -74,8 +74,8 @@ typedef struct { uint32_t ap_id; guint32 rate; NMEtherAddr current_ap_bssid; - GDBusMethodInvocation * pending_agent_request; - NMActiveConnection * assumed_ac; + GDBusMethodInvocation *pending_agent_request; + NMActiveConnection *assumed_ac; guint assumed_ac_timeout; } NMDeviceIwdPrivate; @@ -120,7 +120,7 @@ _ap_dump(NMDeviceIwd *self, NMLogLevel log_level, const NMWifiAP *ap, const char static void ap_add_remove(NMDeviceIwd *self, gboolean is_adding, /* or else is removing */ - NMWifiAP * ap, + NMWifiAP *ap, gboolean recheck_available_connections) { NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); @@ -156,7 +156,7 @@ static void set_current_ap(NMDeviceIwd *self, NMWifiAP *new_ap, gboolean recheck_available_connections) { NMDeviceIwdPrivate *priv; - NMWifiAP * old_ap; + NMWifiAP *old_ap; g_return_if_fail(NM_IS_DEVICE_IWD(self)); @@ -186,7 +186,7 @@ static void remove_all_aps(NMDeviceIwd *self) { NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); - NMWifiAP * ap, *ap_safe; + NMWifiAP *ap, *ap_safe; if (c_list_is_empty(&priv->aps_lst_head)) return; @@ -219,20 +219,20 @@ ap_security_flags_from_network_type(const char *type) static NMWifiAP * ap_from_network(NMDeviceIwd *self, - GDBusProxy * network, + GDBusProxy *network, NMRefString *bss_path, gint64 last_seen_msec, int16_t signal) { - NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); + NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); gs_unref_variant GVariant *name_value = NULL; gs_unref_variant GVariant *type_value = NULL; - const char * name; - const char * type; + const char *name; + const char *type; uint32_t ap_id; - gs_unref_bytes GBytes *ssid = NULL; - NMWifiAP * ap; - NMSupplicantBssInfo bss_info; + gs_unref_bytes GBytes *ssid = NULL; + NMWifiAP *ap; + NMSupplicantBssInfo bss_info; g_return_val_if_fail(network, NULL); @@ -284,14 +284,14 @@ ap_from_network(NMDeviceIwd *self, static void insert_ap_from_network(NMDeviceIwd *self, - GHashTable * aps, - const char * path, + GHashTable *aps, + const char *path, gint64 last_seen_msec, int16_t signal) { - gs_unref_object GDBusProxy *network_proxy = NULL; - nm_auto_ref_string NMRefString *bss_path = nm_ref_string_new(path); - NMWifiAP * ap; + gs_unref_object GDBusProxy *network_proxy = NULL; + nm_auto_ref_string NMRefString *bss_path = nm_ref_string_new(path); + NMWifiAP *ap; if (g_hash_table_lookup(aps, bss_path)) { _LOGD(LOGD_WIFI, "Duplicate network at %s", path); @@ -311,16 +311,16 @@ insert_ap_from_network(NMDeviceIwd *self, static void get_ordered_networks_cb(GObject *source, GAsyncResult *res, gpointer user_data) { - NMDeviceIwd * self = user_data; - NMDeviceIwdPrivate *priv; - gs_free_error GError *error = NULL; - gs_unref_variant GVariant *variant = NULL; - GVariantIter * networks; - const char * path; - int16_t signal; - NMWifiAP * ap, *ap_safe, *new_ap; - gboolean changed; - GHashTableIter ap_iter; + NMDeviceIwd *self = user_data; + NMDeviceIwdPrivate *priv; + gs_free_error GError *error = NULL; + gs_unref_variant GVariant *variant = NULL; + GVariantIter *networks; + const char *path; + int16_t signal; + NMWifiAP *ap, *ap_safe, *new_ap; + gboolean changed; + GHashTableIter ap_iter; gs_unref_hashtable GHashTable *new_aps = NULL; gint64 last_seen_msec; @@ -421,7 +421,7 @@ periodic_update(NMDeviceIwd *self) int percent; NMEtherAddr bssid; gboolean ap_changed = FALSE; - NMPlatform * platform; + NMPlatform *platform; ifindex = nm_device_get_ifindex(NM_DEVICE(self)); if (ifindex <= 0) @@ -528,8 +528,8 @@ cleanup_association_attempt(NMDeviceIwd *self, gboolean disconnect) } static void -reset_mode(NMDeviceIwd * self, - GCancellable * cancellable, +reset_mode(NMDeviceIwd *self, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -575,7 +575,7 @@ get_variant_state(GVariant *v) static void deactivate(NMDevice *device) { - NMDeviceIwd * self = NM_DEVICE_IWD(device); + NMDeviceIwd *self = NM_DEVICE_IWD(device); NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); if (!priv->dbus_obj) @@ -608,8 +608,8 @@ disconnect_cb(GObject *source, GAsyncResult *res, gpointer user_data) gs_unref_object NMDeviceIwd *self = NULL; NMDeviceDeactivateCallback callback; gpointer callback_user_data; - gs_unref_variant GVariant *variant = NULL; - gs_free_error GError *error = NULL; + gs_unref_variant GVariant *variant = NULL; + gs_free_error GError *error = NULL; nm_utils_user_data_unpack(user_data, &self, &callback, &callback_user_data); @@ -623,7 +623,7 @@ disconnect_cb_on_idle(gpointer user_data, GCancellable *cancellable) gs_unref_object NMDeviceIwd *self = NULL; NMDeviceDeactivateCallback callback; gpointer callback_user_data; - gs_free_error GError *cancelled_error = NULL; + gs_free_error GError *cancelled_error = NULL; nm_utils_user_data_unpack(user_data, &self, &callback, &callback_user_data); @@ -632,12 +632,12 @@ disconnect_cb_on_idle(gpointer user_data, GCancellable *cancellable) } static void -deactivate_async(NMDevice * device, - GCancellable * cancellable, +deactivate_async(NMDevice *device, + GCancellable *cancellable, NMDeviceDeactivateCallback callback, gpointer callback_user_data) { - NMDeviceIwd * self = NM_DEVICE_IWD(device); + NMDeviceIwd *self = NM_DEVICE_IWD(device); NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); gpointer user_data; @@ -676,7 +676,7 @@ static gboolean is_connection_known_network(NMConnection *connection) { NMIwdNetworkSecurity security; - gs_free char * ssid = NULL; + gs_free char *ssid = NULL; if (!nm_wifi_connection_get_iwd_ssid_and_security(connection, &ssid, &security)) return FALSE; @@ -688,7 +688,7 @@ static gboolean is_ap_known_network(NMWifiAP *ap) { gs_unref_object GDBusProxy *network_proxy = NULL; - gs_unref_variant GVariant *known_network = NULL; + gs_unref_variant GVariant *known_network = NULL; network_proxy = nm_iwd_manager_get_dbus_interface(nm_iwd_manager_get(), @@ -704,17 +704,17 @@ is_ap_known_network(NMWifiAP *ap) static gboolean check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error) { - NMDeviceIwd * self = NM_DEVICE_IWD(device); - NMDeviceIwdPrivate * priv = NM_DEVICE_IWD_GET_PRIVATE(self); - NMSettingWireless * s_wireless; - const char * mac; - const char *const * mac_blacklist; + NMDeviceIwd *self = NM_DEVICE_IWD(device); + NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); + NMSettingWireless *s_wireless; + const char *mac; + const char *const *mac_blacklist; int i; - const char * perm_hw_addr; - const char * mode; + const char *perm_hw_addr; + const char *mode; NMIwdNetworkSecurity security; - GBytes * ssid; - const guint8 * ssid_bytes; + GBytes *ssid; + const guint8 *ssid_bytes; gsize ssid_len; if (!NM_DEVICE_CLASS(nm_device_iwd_parent_class) @@ -860,17 +860,17 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError * } static gboolean -check_connection_available(NMDevice * device, - NMConnection * connection, +check_connection_available(NMDevice *device, + NMConnection *connection, NMDeviceCheckConAvailableFlags flags, - const char * specific_object, - GError ** error) -{ - NMDeviceIwd * self = NM_DEVICE_IWD(device); - NMDeviceIwdPrivate * priv = NM_DEVICE_IWD_GET_PRIVATE(self); - NMSettingWireless * s_wifi; - const char * mode; - NMWifiAP * ap = NULL; + const char *specific_object, + GError **error) +{ + NMDeviceIwd *self = NM_DEVICE_IWD(device); + NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); + NMSettingWireless *s_wifi; + const char *mode; + NMWifiAP *ap = NULL; NMIwdNetworkSecurity security; s_wifi = nm_connection_get_setting_wireless(connection); @@ -952,20 +952,20 @@ iwd_ssid_to_str(const GBytes *ssid) } static gboolean -complete_connection(NMDevice * device, - NMConnection * connection, - const char * specific_object, +complete_connection(NMDevice *device, + NMConnection *connection, + const char *specific_object, NMConnection *const *existing_connections, - GError ** error) + GError **error) { - NMDeviceIwd * self = NM_DEVICE_IWD(device); + NMDeviceIwd *self = NM_DEVICE_IWD(device); NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); - NMSettingWireless * s_wifi; - gs_free char * ssid_utf8 = NULL; - NMWifiAP * ap; - GBytes * ssid = NULL; + NMSettingWireless *s_wifi; + gs_free char *ssid_utf8 = NULL; + NMWifiAP *ap; + GBytes *ssid = NULL; gboolean hidden = FALSE; - const char * mode; + const char *mode; s_wifi = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_WIRELESS); @@ -1059,7 +1059,7 @@ complete_connection(NMDevice * device, static gboolean is_available(NMDevice *device, NMDeviceCheckDevAvailableFlags flags) { - NMDeviceIwd * self = NM_DEVICE_IWD(device); + NMDeviceIwd *self = NM_DEVICE_IWD(device); NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); NMDeviceState state = nm_device_get_state(device); @@ -1088,12 +1088,12 @@ get_autoconnect_allowed(NMDevice *device) static gboolean can_auto_connect(NMDevice *device, NMSettingsConnection *sett_conn, char **specific_object) { - NMDeviceIwd * self = NM_DEVICE_IWD(device); + NMDeviceIwd *self = NM_DEVICE_IWD(device); NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); - NMConnection * connection; - NMSettingWireless * s_wifi; - NMWifiAP * ap; - const char * mode; + NMConnection *connection; + NMSettingWireless *s_wifi; + NMWifiAP *ap; + const char *mode; guint64 timestamp = 0; nm_assert(!specific_object || !*specific_object); @@ -1141,10 +1141,10 @@ _nm_device_iwd_get_aps(NMDeviceIwd *self) static void scan_cb(GObject *source, GAsyncResult *res, gpointer user_data) { - NMDeviceIwd * self = user_data; - NMDeviceIwdPrivate *priv; + NMDeviceIwd *self = user_data; + NMDeviceIwdPrivate *priv; gs_unref_variant GVariant *variant = NULL; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; variant = g_dbus_proxy_call_finish(G_DBUS_PROXY(source), res, &error); if (!variant && nm_utils_error_is_cancelled(error)) @@ -1165,14 +1165,14 @@ scan_cb(GObject *source, GAsyncResult *res, gpointer user_data) } static void -dbus_request_scan_cb(NMDevice * device, +dbus_request_scan_cb(NMDevice *device, GDBusMethodInvocation *context, - NMAuthSubject * subject, - GError * error, + NMAuthSubject *subject, + GError *error, gpointer user_data) { - NMDeviceIwd * self = NM_DEVICE_IWD(device); - NMDeviceIwdPrivate *priv; + NMDeviceIwd *self = NM_DEVICE_IWD(device); + NMDeviceIwdPrivate *priv; gs_unref_variant GVariant *scan_options = user_data; if (error) { @@ -1229,7 +1229,7 @@ void _nm_device_iwd_request_scan(NMDeviceIwd *self, GVariant *options, GDBusMethodInvocation *invocation) { NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); - NMDevice * device = NM_DEVICE(self); + NMDevice *device = NM_DEVICE(self); if (!priv->can_scan) { g_dbus_method_invocation_return_error_literal(invocation, @@ -1283,7 +1283,7 @@ static const char * get_agent_request_network_path(GDBusMethodInvocation *invocation) { const char *method_name = g_dbus_method_invocation_get_method_name(invocation); - GVariant * params = g_dbus_method_invocation_get_parameters(invocation); + GVariant *params = g_dbus_method_invocation_get_parameters(invocation); const char *network_path = NULL; if (nm_streq(method_name, "RequestPassphrase")) @@ -1308,17 +1308,17 @@ get_agent_request_network_path(GDBusMethodInvocation *invocation) * Return TRUE in either case, return FALSE if an error is detected. */ static gboolean -try_reply_agent_request(NMDeviceIwd * self, - NMConnection * connection, +try_reply_agent_request(NMDeviceIwd *self, + NMConnection *connection, GDBusMethodInvocation *invocation, gboolean allow_existing, - const char ** setting_name, - const char ** setting_key, - gboolean * replied) + const char **setting_name, + const char **setting_key, + gboolean *replied) { - const char * method_name = g_dbus_method_invocation_get_method_name(invocation); + const char *method_name = g_dbus_method_invocation_get_method_name(invocation); NMSettingWirelessSecurity *s_wireless_sec; - NMSetting8021x * s_8021x; + NMSetting8021x *s_8021x; s_wireless_sec = nm_connection_get_setting_wireless_security(connection); s_8021x = nm_connection_get_setting_802_1x(connection); @@ -1418,7 +1418,7 @@ try_reply_agent_request(NMDeviceIwd * self, static gboolean assumed_ac_timeout_cb(gpointer user_data) { - NMDeviceIwd * self = user_data; + NMDeviceIwd *self = user_data; NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); nm_assert(priv->assumed_ac); @@ -1434,30 +1434,30 @@ assumed_ac_timeout_cb(gpointer user_data) return G_SOURCE_REMOVE; } -static void wifi_secrets_get_one(NMDeviceIwd * self, - const char * setting_name, +static void wifi_secrets_get_one(NMDeviceIwd *self, + const char *setting_name, NMSecretAgentGetSecretsFlags flags, - const char * setting_key, - GDBusMethodInvocation * invocation); + const char *setting_key, + GDBusMethodInvocation *invocation); static void -wifi_secrets_cb(NMActRequest * req, +wifi_secrets_cb(NMActRequest *req, NMActRequestGetSecretsCallId *call_id, - NMSettingsConnection * s_connection, - GError * error, + NMSettingsConnection *s_connection, + GError *error, gpointer user_data) { - NMDeviceIwd * self; - NMDeviceIwdPrivate * priv; - NMDevice * device; - GDBusMethodInvocation * invocation; - const char * setting_name; - const char * setting_key; + NMDeviceIwd *self; + NMDeviceIwdPrivate *priv; + NMDevice *device; + GDBusMethodInvocation *invocation; + const char *setting_name; + const char *setting_key; gboolean replied; NMSecretAgentGetSecretsFlags get_secret_flags = NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION; NMIwdNetworkSecurity security; - NMConnection * connection; + NMConnection *connection; nm_utils_user_data_unpack(user_data, &self, &invocation); @@ -1550,14 +1550,14 @@ secrets_error: } static void -wifi_secrets_get_one(NMDeviceIwd * self, - const char * setting_name, +wifi_secrets_get_one(NMDeviceIwd *self, + const char *setting_name, NMSecretAgentGetSecretsFlags flags, - const char * setting_key, - GDBusMethodInvocation * invocation) + const char *setting_key, + GDBusMethodInvocation *invocation) { NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); - NMActRequest * req; + NMActRequest *req; wifi_secrets_cancel(self); @@ -1576,16 +1576,16 @@ wifi_secrets_get_one(NMDeviceIwd * self, static void network_connect_cb(GObject *source, GAsyncResult *res, gpointer user_data) { - NMDeviceIwd * self = user_data; - NMDevice * device = NM_DEVICE(self); - NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); + NMDeviceIwd *self = user_data; + NMDevice *device = NM_DEVICE(self); + NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); gs_unref_variant GVariant *variant = NULL; - gs_free_error GError *error = NULL; - NMConnection * connection; - gs_free char * ssid = NULL; - NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED; - GVariant * value; - gboolean disconnect; + gs_free_error GError *error = NULL; + NMConnection *connection; + gs_free char *ssid = NULL; + NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED; + GVariant *value; + gboolean disconnect; disconnect = !priv->iwd_autoconnect || nm_device_autoconnect_blocked_get(device, NM_DEVICE_AUTOCONNECT_BLOCKED_ALL); @@ -1642,7 +1642,7 @@ network_connect_cb(GObject *source, GAsyncResult *res, gpointer user_data) _LOGI(LOGD_DEVICE | LOGD_WIFI, "Activation: (wifi) Stage 2 of 5 (Device Configure) successful. Connected to '%s'.", ssid); - nm_device_activate_schedule_stage3_ip_config_start(device); + nm_device_activate_schedule_stage3_ip_config(device, FALSE); return; @@ -1667,10 +1667,10 @@ failed: static void act_failed_cb(GObject *source, GAsyncResult *res, gpointer user_data) { - NMDeviceIwd * self = user_data; - NMDevice * device = NM_DEVICE(self); + NMDeviceIwd *self = user_data; + NMDevice *device = NM_DEVICE(self); gs_unref_variant GVariant *variant = NULL; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; variant = g_dbus_proxy_call_finish(G_DBUS_PROXY(source), res, &error); if (!variant && nm_utils_error_is_cancelled(error)) @@ -1689,12 +1689,12 @@ act_failed_cb(GObject *source, GAsyncResult *res, gpointer user_data) static void act_start_cb(GObject *source, GAsyncResult *res, gpointer user_data) { - NMDeviceIwd * self = user_data; - NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); - NMDevice * device = NM_DEVICE(self); + NMDeviceIwd *self = user_data; + NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); + NMDevice *device = NM_DEVICE(self); gs_unref_variant GVariant *variant = NULL; - gs_free_error GError *error = NULL; - gs_free char * ssid = NULL; + gs_free_error GError *error = NULL; + gs_free char *ssid = NULL; variant = g_dbus_proxy_call_finish(G_DBUS_PROXY(source), res, &error); if (!variant) { @@ -1721,7 +1721,7 @@ act_start_cb(GObject *source, GAsyncResult *res, gpointer user_data) _LOGI(LOGD_DEVICE | LOGD_WIFI, "Activation: (wifi) Stage 2 of 5 (Device Configure) successful. Started '%s'.", ssid); - nm_device_activate_schedule_stage3_ip_config_start(device); + nm_device_activate_schedule_stage3_ip_config(device, FALSE); return; @@ -1736,12 +1736,12 @@ error: static void act_check_interface(NMDeviceIwd *self) { - NMDeviceIwdPrivate * priv = NM_DEVICE_IWD_GET_PRIVATE(self); - NMDevice * device = NM_DEVICE(self); - NMSettingWireless * s_wireless; - GDBusProxy * proxy = NULL; - gs_free char * ssid = NULL; - const char * mode; + NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); + NMDevice *device = NM_DEVICE(self); + NMSettingWireless *s_wireless; + GDBusProxy *proxy = NULL; + gs_free char *ssid = NULL; + const char *mode; NMIwdNetworkSecurity security; if (!priv->act_mode_switch) @@ -1780,7 +1780,7 @@ act_check_interface(NMDeviceIwd *self) self); } else if (security == NM_IWD_NETWORK_SECURITY_PSK) { NMSettingWirelessSecurity *s_wireless_sec; - const char * psk; + const char *psk; s_wireless_sec = (NMSettingWirelessSecurity *) nm_device_get_applied_setting( device, @@ -1813,11 +1813,11 @@ failed: static void act_set_mode_cb(GObject *source, GAsyncResult *res, gpointer user_data) { - NMDeviceIwd * self = user_data; - NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); - NMDevice * device = NM_DEVICE(self); + NMDeviceIwd *self = user_data; + NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); + NMDevice *device = NM_DEVICE(self); gs_unref_variant GVariant *variant = NULL; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; variant = g_dbus_proxy_call_finish(G_DBUS_PROXY(source), res, &error); if (!variant) { @@ -1848,10 +1848,10 @@ static void act_set_mode(NMDeviceIwd *self) { NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); - NMDevice * device = NM_DEVICE(self); - const char * iwd_mode; - const char * mode; - NMSettingWireless * s_wireless; + NMDevice *device = NM_DEVICE(self); + const char *iwd_mode; + const char *mode; + NMSettingWireless *s_wireless; s_wireless = (NMSettingWireless *) nm_device_get_applied_setting(device, NM_TYPE_SETTING_WIRELESS); @@ -1880,15 +1880,15 @@ act_set_mode(NMDeviceIwd *self) } static void -act_psk_cb(NMActRequest * req, +act_psk_cb(NMActRequest *req, NMActRequestGetSecretsCallId *call_id, - NMSettingsConnection * s_connection, - GError * error, + NMSettingsConnection *s_connection, + GError *error, gpointer user_data) { - NMDeviceIwd * self = user_data; + NMDeviceIwd *self = user_data; NMDeviceIwdPrivate *priv; - NMDevice * device; + NMDevice *device; if (nm_utils_error_is_cancelled(error)) return; @@ -1944,7 +1944,7 @@ static NMWifiAP * find_ap_by_supplicant_path(NMDeviceIwd *self, const NMRefString *path) { NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); - NMWifiAP * tmp; + NMWifiAP *tmp; c_list_for_each_entry (tmp, &priv->aps_lst_head, aps_lst) if (nm_wifi_ap_get_supplicant_path(tmp) == path) @@ -1956,7 +1956,7 @@ find_ap_by_supplicant_path(NMDeviceIwd *self, const NMRefString *path) static void assumed_connection_state_changed(NMActiveConnection *active, GParamSpec *pspec, NMDeviceIwd *self) { - NMSettingsConnection * sett_conn = nm_active_connection_get_settings_connection(active); + NMSettingsConnection *sett_conn = nm_active_connection_get_settings_connection(active); NMActiveConnectionState state = nm_active_connection_get_state(active); /* Delete the temporary connection created for an external IWD connection @@ -1983,10 +1983,10 @@ assumed_connection_state_changed(NMActiveConnection *active, GParamSpec *pspec, static void assumed_connection_state_changed_before_managed(NMActiveConnection *active, - GParamSpec * pspec, - NMDeviceIwd * self) + GParamSpec *pspec, + NMDeviceIwd *self) { - NMDeviceIwdPrivate * priv = NM_DEVICE_IWD_GET_PRIVATE(self); + NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); NMActiveConnectionState state = nm_active_connection_get_state(active); gboolean disconnect; @@ -2020,11 +2020,11 @@ assumed_connection_state_changed_before_managed(NMActiveConnection *active, static void assume_connection(NMDeviceIwd *self, NMWifiAP *ap) { - NMDeviceIwdPrivate * priv = NM_DEVICE_IWD_GET_PRIVATE(self); - NMSettingsConnection *sett_conn; + NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); + NMSettingsConnection *sett_conn; gs_unref_object NMAuthSubject *subject = NULL; - NMActiveConnection * ac; - gs_free_error GError *error = NULL; + NMActiveConnection *ac; + gs_free_error GError *error = NULL; /* We can use the .update_connection / nm_device_emit_recheck_assume * API but we can also pass an assumed/external activation type @@ -2104,7 +2104,7 @@ static void assumed_connection_progress_to_ip_config(NMDeviceIwd *self, gboolean was_postponed) { NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); - NMDevice * device = NM_DEVICE(self); + NMDevice *device = NM_DEVICE(self); NMDeviceState dev_state = nm_device_get_state(device); wifi_secrets_cancel(self); @@ -2127,17 +2127,17 @@ assumed_connection_progress_to_ip_config(NMDeviceIwd *self, gboolean was_postpon * that stage2 is done. */ if (was_postponed) - nm_device_activate_schedule_stage3_ip_config_start(NM_DEVICE(self)); + nm_device_activate_schedule_stage3_ip_config(NM_DEVICE(self), FALSE); } static void initial_check_assume(NMDeviceIwd *self) { - NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); - const char * network_path_str; + NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); + const char *network_path_str; nm_auto_ref_string NMRefString *network_path = NULL; - NMWifiAP * ap = NULL; - gs_unref_variant GVariant *state_value = + NMWifiAP *ap = NULL; + gs_unref_variant GVariant *state_value = g_dbus_proxy_get_cached_property(priv->dbus_station_proxy, "State"); gs_unref_variant GVariant *cn_value = g_dbus_proxy_get_cached_property(priv->dbus_station_proxy, "ConnectedNetwork"); @@ -2174,15 +2174,15 @@ initial_check_assume(NMDeviceIwd *self) static NMActStageReturn act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) { - NMDeviceIwd * self = NM_DEVICE_IWD(device); - NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); - NMWifiAP * ap = NULL; + NMDeviceIwd *self = NM_DEVICE_IWD(device); + NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); + NMWifiAP *ap = NULL; gs_unref_object NMWifiAP *ap_fake = NULL; - NMActRequest * req; - NMConnection * connection; - NMSettingWireless * s_wireless; - const char * mode; - const char * ap_path; + NMActRequest *req; + NMConnection *connection; + NMSettingWireless *s_wireless; + const char *mode; + const char *ap_path; req = nm_device_get_act_request(device); g_return_val_if_fail(req, NM_ACT_STAGE_RETURN_FAILURE); @@ -2246,12 +2246,12 @@ add_new: static NMActStageReturn act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) { - NMDeviceIwd * self = NM_DEVICE_IWD(device); + NMDeviceIwd *self = NM_DEVICE_IWD(device); NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); - NMActRequest * req; - NMConnection * connection; - NMSettingWireless * s_wireless; - const char * mode; + NMActRequest *req; + NMConnection *connection; + NMSettingWireless *s_wireless; + const char *mode; req = nm_device_get_act_request(device); connection = nm_act_request_get_applied_connection(req); @@ -2262,8 +2262,8 @@ act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) if (NM_IN_STRSET(mode, NULL, NM_SETTING_WIRELESS_MODE_INFRA)) { gs_unref_object GDBusProxy *network_proxy = NULL; - NMWifiAP * ap = priv->current_ap; - NMSettingWirelessSecurity * s_wireless_sec; + NMWifiAP *ap = priv->current_ap; + NMSettingWirelessSecurity *s_wireless_sec; if (!ap) { NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED); @@ -2432,7 +2432,7 @@ get_configured_mtu(NMDevice *device, NMDeviceMtuSource *out_source, gboolean *ou static gboolean periodic_scan_timeout_cb(gpointer user_data) { - NMDeviceIwd * self = user_data; + NMDeviceIwd *self = user_data; NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); priv->periodic_scan_id = 0; @@ -2503,15 +2503,15 @@ set_can_scan(NMDeviceIwd *self, gboolean can_scan) } static void -device_state_changed(NMDevice * device, +device_state_changed(NMDevice *device, NMDeviceState new_state, NMDeviceState old_state, NMDeviceStateReason reason) { - NMDeviceIwd * self = NM_DEVICE_IWD(device); + NMDeviceIwd *self = NM_DEVICE_IWD(device); NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); - NMSettingWireless * s_wireless; - const char * mode; + NMSettingWireless *s_wireless; + const char *mode; switch (new_state) { case NM_DEVICE_STATE_UNMANAGED: @@ -2559,7 +2559,7 @@ get_enabled(NMDevice *device) static void set_enabled(NMDevice *device, gboolean enabled) { - NMDeviceIwd * self = NM_DEVICE_IWD(device); + NMDeviceIwd *self = NM_DEVICE_IWD(device); NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); NMDeviceState state; @@ -2596,12 +2596,12 @@ set_enabled(NMDevice *device, gboolean enabled) } static gboolean -can_reapply_change(NMDevice * device, +can_reapply_change(NMDevice *device, const char *setting_name, - NMSetting * s_old, - NMSetting * s_new, + NMSetting *s_old, + NMSetting *s_new, GHashTable *diffs, - GError ** error) + GError **error) { NMDeviceClass *device_class; @@ -2624,9 +2624,9 @@ can_reapply_change(NMDevice * device, static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMDeviceIwd * self = NM_DEVICE_IWD(object); + NMDeviceIwd *self = NM_DEVICE_IWD(object); NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); - const char ** list; + const char **list; switch (prop_id) { case PROP_MODE: @@ -2673,18 +2673,18 @@ static void state_changed(NMDeviceIwd *self, const char *new_state) { NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); - NMDevice * device = NM_DEVICE(self); + NMDevice *device = NM_DEVICE(self); NMDeviceState dev_state = nm_device_get_state(device); gboolean nm_connection = priv->current_ap || priv->assumed_ac; gboolean iwd_connection = FALSE; - NMWifiAP * ap = NULL; + NMWifiAP *ap = NULL; gboolean can_connect = priv->nm_autoconnect; _LOGI(LOGD_DEVICE | LOGD_WIFI, "new IWD device state is %s", new_state); if (NM_IN_STRSET(new_state, "connecting", "connected", "roaming")) { - gs_unref_variant GVariant *value = NULL; - const char * network_path_str; + gs_unref_variant GVariant *value = NULL; + const char *network_path_str; nm_auto_ref_string NMRefString *network_path = NULL; value = g_dbus_proxy_get_cached_property(priv->dbus_station_proxy, "ConnectedNetwork"); @@ -2855,12 +2855,12 @@ scanning_changed(NMDeviceIwd *self, gboolean new_scanning) static void station_properties_changed(GDBusProxy *proxy, - GVariant * changed_properties, + GVariant *changed_properties, GStrv invalidate_properties, gpointer user_data) { NMDeviceIwd *self = user_data; - const char * new_str; + const char *new_str; gboolean new_bool; if (g_variant_lookup(changed_properties, "State", "&s", &new_str)) @@ -2872,7 +2872,7 @@ station_properties_changed(GDBusProxy *proxy, static void ap_adhoc_properties_changed(GDBusProxy *proxy, - GVariant * changed_properties, + GVariant *changed_properties, GStrv invalidate_properties, gpointer user_data) { @@ -2889,7 +2889,7 @@ static void powered_changed(NMDeviceIwd *self, gboolean new_powered) { NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); - GDBusInterface * interface; + GDBusInterface *interface; nm_device_queue_recheck_available(NM_DEVICE(self), NM_DEVICE_STATE_REASON_SUPPLICANT_AVAILABLE, @@ -3004,7 +3004,7 @@ powered_changed(NMDeviceIwd *self, gboolean new_powered) static void device_properties_changed(GDBusProxy *proxy, - GVariant * changed_properties, + GVariant *changed_properties, GStrv invalidate_properties, gpointer user_data) { @@ -3016,11 +3016,11 @@ device_properties_changed(GDBusProxy *proxy, } static void -config_changed(NMConfig * config, - NMConfigData * config_data, +config_changed(NMConfig *config, + NMConfigData *config_data, NMConfigChangeFlags changes, - NMConfigData * old_data, - NMDeviceIwd * self) + NMConfigData *old_data, + NMDeviceIwd *self) { NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); gboolean old_iwd_ac = priv->iwd_autoconnect; @@ -3048,12 +3048,12 @@ config_changed(NMConfig * config, void nm_device_iwd_set_dbus_object(NMDeviceIwd *self, GDBusObject *object) { - NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); - GDBusInterface * interface; - gs_unref_variant GVariant *value = NULL; + NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); + GDBusInterface *interface; + gs_unref_variant GVariant *value = NULL; gs_unref_object GDBusProxy *adapter_proxy = NULL; - GVariantIter * iter; - const char * mode; + GVariantIter *iter; + const char *mode; gboolean powered; _NMDeviceWifiCapabilities capabilities; @@ -3159,18 +3159,18 @@ error: gboolean nm_device_iwd_agent_query(NMDeviceIwd *self, GDBusMethodInvocation *invocation) { - NMDevice * device = NM_DEVICE(self); - NMDeviceIwdPrivate * priv = NM_DEVICE_IWD_GET_PRIVATE(self); + NMDevice *device = NM_DEVICE(self); + NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); NMDeviceState state = nm_device_get_state(device); - const char * setting_name; - const char * setting_key; + const char *setting_name; + const char *setting_key; gboolean replied; - NMWifiAP * ap; + NMWifiAP *ap; gboolean allow_existing = FALSE; NMSecretAgentGetSecretsFlags get_secret_flags = NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION; - NMIwdNetworkSecurity security; - NMConnection * connection; + NMIwdNetworkSecurity security; + NMConnection *connection; nm_auto_ref_string NMRefString *network_path = NULL; if (!invocation) { @@ -3324,9 +3324,9 @@ nm_device_iwd_agent_query(NMDeviceIwd *self, GDBusMethodInvocation *invocation) void nm_device_iwd_network_add_remove(NMDeviceIwd *self, GDBusProxy *network, bool add) { - NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); - NMWifiAP * ap = NULL; - bool recheck; + NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); + NMWifiAP *ap = NULL; + bool recheck; nm_auto_ref_string NMRefString *bss_path = NULL; bss_path = nm_ref_string_new(g_dbus_proxy_get_object_path(network)); @@ -3371,7 +3371,7 @@ nm_device_iwd_network_add_remove(NMDeviceIwd *self, GDBusProxy *network, bool ad static void autoconnect_changed(NMDevice *device, GParamSpec *pspec, NMDeviceIwd *self) { - NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); + NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); gs_unref_variant GVariant *value = NULL; /* Note IWD normally remains in "disconnected" during a secret request @@ -3434,7 +3434,7 @@ nm_device_iwd_new(const char *iface) static void dispose(GObject *object) { - NMDeviceIwd * self = NM_DEVICE_IWD(object); + NMDeviceIwd *self = NM_DEVICE_IWD(object); NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self); nm_clear_g_cancellable(&priv->cancellable); @@ -3450,9 +3450,9 @@ dispose(GObject *object) static void nm_device_iwd_class_init(NMDeviceIwdClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->get_property = get_property; object_class->dispose = dispose; diff --git a/src/core/devices/wifi/nm-device-iwd.h b/src/core/devices/wifi/nm-device-iwd.h index ce94c9ea..bb136bf6 100644 --- a/src/core/devices/wifi/nm-device-iwd.h +++ b/src/core/devices/wifi/nm-device-iwd.h @@ -40,8 +40,8 @@ gboolean nm_device_iwd_agent_query(NMDeviceIwd *device, GDBusMethodInvocation *i const CList *_nm_device_iwd_get_aps(NMDeviceIwd *self); -void _nm_device_iwd_request_scan(NMDeviceIwd * self, - GVariant * options, +void _nm_device_iwd_request_scan(NMDeviceIwd *self, + GVariant *options, GDBusMethodInvocation *invocation); void nm_device_iwd_network_add_remove(NMDeviceIwd *device, GDBusProxy *network, bool add); diff --git a/src/core/devices/wifi/nm-device-olpc-mesh.c b/src/core/devices/wifi/nm-device-olpc-mesh.c index d829f9ae..fd851ebc 100644 --- a/src/core/devices/wifi/nm-device-olpc-mesh.c +++ b/src/core/devices/wifi/nm-device-olpc-mesh.c @@ -39,7 +39,7 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMDeviceOlpcMesh, PROP_COMPANION, PROP_ACTIVE_CHANNEL, ); typedef struct { - NMDevice * companion; + NMDevice *companion; NMManager *manager; bool stage1_waiting : 1; } NMDeviceOlpcMeshPrivate; @@ -63,7 +63,7 @@ G_DEFINE_TYPE(NMDeviceOlpcMesh, nm_device_olpc_mesh, NM_TYPE_DEVICE) static gboolean get_autoconnect_allowed(NMDevice *device) { - NMDeviceOlpcMesh * self = NM_DEVICE_OLPC_MESH(device); + NMDeviceOlpcMesh *self = NM_DEVICE_OLPC_MESH(device); NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE(self); /* We can't even connect if we don't have a companion yet. */ @@ -81,11 +81,11 @@ get_autoconnect_allowed(NMDevice *device) #define DEFAULT_SSID "olpc-mesh" static gboolean -complete_connection(NMDevice * device, - NMConnection * connection, - const char * specific_object, +complete_connection(NMDevice *device, + NMConnection *connection, + const char *specific_object, NMConnection *const *existing_connections, - GError ** error) + GError **error) { NMSettingOlpcMesh *s_mesh; @@ -133,7 +133,7 @@ get_dhcp_anycast_address(NMDevice *device) static NMActStageReturn act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) { - NMDeviceOlpcMesh * self = NM_DEVICE_OLPC_MESH(device); + NMDeviceOlpcMesh *self = NM_DEVICE_OLPC_MESH(device); NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE(self); /* disconnect companion device, if it is connected */ @@ -183,9 +183,9 @@ _mesh_set_channel(NMDeviceOlpcMesh *self, guint32 channel) static NMActStageReturn act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) { - NMDeviceOlpcMesh * self = NM_DEVICE_OLPC_MESH(device); + NMDeviceOlpcMesh *self = NM_DEVICE_OLPC_MESH(device); NMSettingOlpcMesh *s_mesh; - GBytes * ssid; + GBytes *ssid; gboolean success; s_mesh = nm_device_get_applied_setting(device, NM_TYPE_SETTING_OLPC_MESH); @@ -243,7 +243,7 @@ companion_cleanup(NMDeviceOlpcMesh *self) static void companion_notify_cb(NMDeviceWifi *companion, GParamSpec *pspec, gpointer user_data) { - NMDeviceOlpcMesh * self = NM_DEVICE_OLPC_MESH(user_data); + NMDeviceOlpcMesh *self = NM_DEVICE_OLPC_MESH(user_data); NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE(self); nm_assert(NM_IS_DEVICE_WIFI(companion)); @@ -260,7 +260,7 @@ companion_notify_cb(NMDeviceWifi *companion, GParamSpec *pspec, gpointer user_da /* disconnect from mesh if someone starts using the companion */ static void -companion_state_changed_cb(NMDeviceWifi * companion, +companion_state_changed_cb(NMDeviceWifi *companion, NMDeviceState state, NMDeviceState old_state, NMDeviceStateReason reason, @@ -299,7 +299,7 @@ static gboolean check_companion(NMDeviceOlpcMesh *self, NMDevice *other) { NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE(self); - const char * my_addr, *their_addr; + const char *my_addr, *their_addr; if (!NM_IS_DEVICE_WIFI(other)) return FALSE; @@ -337,7 +337,7 @@ check_companion(NMDeviceOlpcMesh *self, NMDevice *other) static void device_added_cb(NMManager *manager, NMDevice *other, gpointer user_data) { - NMDeviceOlpcMesh * self = NM_DEVICE_OLPC_MESH(user_data); + NMDeviceOlpcMesh *self = NM_DEVICE_OLPC_MESH(user_data); NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE(self); if (!priv->companion && check_companion(self, other)) { @@ -363,8 +363,8 @@ static void find_companion(NMDeviceOlpcMesh *self) { NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE(self); - const CList * tmp_lst; - NMDevice * candidate; + const CList *tmp_lst; + NMDevice *candidate; if (priv->companion) return; @@ -386,12 +386,12 @@ find_companion(NMDeviceOlpcMesh *self) } static void -state_changed(NMDevice * device, +state_changed(NMDevice *device, NMDeviceState new_state, NMDeviceState old_state, NMDeviceStateReason reason) { - NMDeviceOlpcMesh * self = NM_DEVICE_OLPC_MESH(device); + NMDeviceOlpcMesh *self = NM_DEVICE_OLPC_MESH(device); NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE(self); if (new_state == NM_DEVICE_STATE_UNAVAILABLE) @@ -422,8 +422,8 @@ get_dhcp_timeout_for_device(NMDevice *device, int addr_family) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMDeviceOlpcMesh * self = NM_DEVICE_OLPC_MESH(object); - NMDevice * device = NM_DEVICE(self); + NMDeviceOlpcMesh *self = NM_DEVICE_OLPC_MESH(object); + NMDevice *device = NM_DEVICE(self); NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE(self); switch (prop_id) { @@ -450,7 +450,7 @@ nm_device_olpc_mesh_init(NMDeviceOlpcMesh *self) static void constructed(GObject *object) { - NMDeviceOlpcMesh * self = NM_DEVICE_OLPC_MESH(object); + NMDeviceOlpcMesh *self = NM_DEVICE_OLPC_MESH(object); NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE(self); G_OBJECT_CLASS(nm_device_olpc_mesh_parent_class)->constructed(object); @@ -479,7 +479,7 @@ nm_device_olpc_mesh_new(const char *iface) static void dispose(GObject *object) { - NMDeviceOlpcMesh * self = NM_DEVICE_OLPC_MESH(object); + NMDeviceOlpcMesh *self = NM_DEVICE_OLPC_MESH(object); NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE(self); companion_cleanup(self); @@ -510,9 +510,9 @@ static const NMDBusInterfaceInfoExtended interface_info_device_olpc_mesh = { static void nm_device_olpc_mesh_class_init(NMDeviceOlpcMeshClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->constructed = constructed; object_class->get_property = get_property; diff --git a/src/core/devices/wifi/nm-device-wifi-p2p.c b/src/core/devices/wifi/nm-device-wifi-p2p.c index 67202a67..dfbf8978 100644 --- a/src/core/devices/wifi/nm-device-wifi-p2p.c +++ b/src/core/devices/wifi/nm-device-wifi-p2p.c @@ -14,18 +14,18 @@ #include "NetworkManagerUtils.h" #include "devices/nm-device-private.h" -#include "nm-act-request.h" #include "libnm-core-aux-intern/nm-libnm-core-utils.h" #include "libnm-core-intern/nm-core-internal.h" #include "libnm-glib-aux/nm-ref-string.h" -#include "nm-ip4-config.h" +#include "libnm-platform/nm-platform.h" +#include "libnm-platform/nmp-object.h" +#include "nm-act-request.h" +#include "nm-l3-config-data.h" #include "nm-manager.h" #include "nm-manager.h" #include "nm-setting-wifi-p2p.h" #include "nm-utils.h" #include "nm-wifi-p2p-peer.h" -#include "libnm-platform/nm-platform.h" -#include "libnm-platform/nmp-object.h" #include "settings/nm-settings.h" #define _NMLOG_DEVICE_TYPE NMDeviceWifiP2P @@ -82,10 +82,10 @@ static void supplicant_interfaces_release(NMDeviceWifiP2P *self, gboolean set_is /*****************************************************************************/ static void -_peer_dump(NMDeviceWifiP2P * self, +_peer_dump(NMDeviceWifiP2P *self, NMLogLevel log_level, const NMWifiP2PPeer *peer, - const char * prefix, + const char *prefix, gint32 now_s) { char buf[1024]; @@ -100,7 +100,7 @@ _peer_dump(NMDeviceWifiP2P * self, static gboolean peer_list_dump(gpointer user_data) { - NMDeviceWifiP2P * self = NM_DEVICE_WIFI_P2P(user_data); + NMDeviceWifiP2P *self = NM_DEVICE_WIFI_P2P(user_data); NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(self); priv->peer_dump_id = 0; @@ -153,10 +153,10 @@ static gboolean check_connection_peer_joined(NMDeviceWifiP2P *device) { NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(device); - NMConnection * conn = nm_device_get_applied_connection(NM_DEVICE(device)); - NMWifiP2PPeer * peer; - const char * group; - const char *const * groups; + NMConnection *conn = nm_device_get_applied_connection(NM_DEVICE(device)); + NMWifiP2PPeer *peer; + const char *group; + const char *const *groups; if (!conn || !priv->group_iface) return FALSE; @@ -168,7 +168,7 @@ check_connection_peer_joined(NMDeviceWifiP2P *device) return FALSE; /* NOTE: We currently only support connections to a specific peer */ - peer = nm_wifi_p2p_peers_find_first_compatible(&priv->peers_lst_head, conn); + peer = nm_wifi_p2p_peers_find_first_compatible(&priv->peers_lst_head, conn, FALSE); if (!peer) return FALSE; @@ -182,8 +182,8 @@ check_connection_peer_joined(NMDeviceWifiP2P *device) static gboolean disconnect_on_connection_peer_missing_cb(gpointer user_data) { - NMDevice * device = NM_DEVICE(user_data); - NMDeviceWifiP2P * self = NM_DEVICE_WIFI_P2P(device); + NMDevice *device = NM_DEVICE(user_data); + NMDeviceWifiP2P *self = NM_DEVICE_WIFI_P2P(device); NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(self); _LOGW(LOGD_WIFI, "Peer requested in connection is missing for too long, failing connection."); @@ -222,8 +222,8 @@ update_disconnect_on_connection_peer_missing(NMDeviceWifiP2P *self) static gboolean is_available(NMDevice *device, NMDeviceCheckDevAvailableFlags flags) { - NMDeviceWifiP2P * self = NM_DEVICE_WIFI_P2P(device); - NMDeviceWifiP2PPrivate * priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(self); + NMDeviceWifiP2P *self = NM_DEVICE_WIFI_P2P(device); + NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(self); NMSupplicantInterfaceState supplicant_state; if (!priv->mgmt_iface) @@ -251,17 +251,17 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError * } static gboolean -complete_connection(NMDevice * device, - NMConnection * connection, - const char * specific_object, +complete_connection(NMDevice *device, + NMConnection *connection, + const char *specific_object, NMConnection *const *existing_connections, - GError ** error) + GError **error) { - NMDeviceWifiP2P * self = NM_DEVICE_WIFI_P2P(device); - gs_free char * setting_name = NULL; + NMDeviceWifiP2P *self = NM_DEVICE_WIFI_P2P(device); + gs_free char *setting_name = NULL; NMSettingWifiP2P *s_wifi_p2p; - NMWifiP2PPeer * peer; - const char * setting_peer; + NMWifiP2PPeer *peer; + const char *setting_peer; s_wifi_p2p = NM_SETTING_WIFI_P2P(nm_connection_get_setting(connection, NM_TYPE_SETTING_WIFI_P2P)); @@ -329,8 +329,8 @@ complete_connection(NMDevice * device, static gboolean supplicant_find_timeout_cb(gpointer user_data) { - NMDevice * device = NM_DEVICE(user_data); - NMDeviceWifiP2P * self = NM_DEVICE_WIFI_P2P(user_data); + NMDevice *device = NM_DEVICE(user_data); + NMDeviceWifiP2P *self = NM_DEVICE_WIFI_P2P(user_data); NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(self); priv->find_peer_timeout_id = 0; @@ -351,11 +351,11 @@ supplicant_find_timeout_cb(gpointer user_data) static NMActStageReturn act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) { - NMDeviceWifiP2P * self = NM_DEVICE_WIFI_P2P(device); + NMDeviceWifiP2P *self = NM_DEVICE_WIFI_P2P(device); NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(self); - NMConnection * connection; - NMSettingWifiP2P * s_wifi_p2p; - NMWifiP2PPeer * peer; + NMConnection *connection; + NMSettingWifiP2P *s_wifi_p2p; + NMWifiP2PPeer *peer; if (!priv->mgmt_iface) { NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED); @@ -369,7 +369,7 @@ act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) NM_SETTING_WIFI_P2P(nm_connection_get_setting(connection, NM_TYPE_SETTING_WIFI_P2P)); g_return_val_if_fail(s_wifi_p2p, NM_ACT_STAGE_RETURN_FAILURE); - peer = nm_wifi_p2p_peers_find_first_compatible(&priv->peers_lst_head, connection); + peer = nm_wifi_p2p_peers_find_first_compatible(&priv->peers_lst_head, connection, FALSE); if (!peer) { /* Set up a timeout on the find attempt and run a find for the same period of time */ if (priv->find_peer_timeout_id == 0) { @@ -393,8 +393,8 @@ act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) static gboolean supplicant_connection_timeout_cb(gpointer user_data) { - NMDevice * device = NM_DEVICE(user_data); - NMDeviceWifiP2P * self = NM_DEVICE_WIFI_P2P(user_data); + NMDevice *device = NM_DEVICE(user_data); + NMDeviceWifiP2P *self = NM_DEVICE_WIFI_P2P(user_data); NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(self); priv->sup_timeout_id = 0; @@ -415,12 +415,12 @@ supplicant_connection_timeout_cb(gpointer user_data) static NMActStageReturn act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) { - NMDeviceWifiP2P * self = NM_DEVICE_WIFI_P2P(device); + NMDeviceWifiP2P *self = NM_DEVICE_WIFI_P2P(device); NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(self); - NMConnection * connection; - NMSettingWifiP2P * s_wifi_p2p; - NMWifiP2PPeer * peer; - GBytes * wfd_ies; + NMConnection *connection; + NMSettingWifiP2P *s_wifi_p2p; + NMWifiP2PPeer *peer; + GBytes *wfd_ies; if (nm_clear_g_source(&priv->find_peer_timeout_id)) nm_assert_not_reached(); @@ -436,7 +436,7 @@ act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) NM_IS_SETTING_WIFI_P2P(nm_connection_get_setting(connection, NM_TYPE_SETTING_WIFI_P2P))); /* The prepare stage ensures that the peer has been found */ - peer = nm_wifi_p2p_peers_find_first_compatible(&priv->peers_lst_head, connection); + peer = nm_wifi_p2p_peers_find_first_compatible(&priv->peers_lst_head, connection, FALSE); if (!peer) { NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_PEER_NOT_FOUND); return NM_ACT_STAGE_RETURN_FAILURE; @@ -469,7 +469,7 @@ act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) static void emit_signal_p2p_peer_add_remove(NMDeviceWifiP2P *device, - NMWifiP2PPeer * peer, + NMWifiP2PPeer *peer, gboolean is_added /* or else is_removed */) { nm_dbus_object_emit_signal(NM_DBUS_OBJECT(device), @@ -483,10 +483,10 @@ emit_signal_p2p_peer_add_remove(NMDeviceWifiP2P *device, static void peer_add_remove(NMDeviceWifiP2P *self, gboolean is_adding, /* or else removing */ - NMWifiP2PPeer * peer, + NMWifiP2PPeer *peer, gboolean recheck_available_connections) { - NMDevice * device = NM_DEVICE(self); + NMDevice *device = NM_DEVICE(self); NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(self); if (is_adding) { @@ -521,7 +521,8 @@ peer_add_remove(NMDeviceWifiP2P *self, connection = nm_device_get_applied_connection(device); nm_assert(NM_IS_CONNECTION(connection)); - peer = nm_wifi_p2p_peers_find_first_compatible(&priv->peers_lst_head, connection); + peer = + nm_wifi_p2p_peers_find_first_compatible(&priv->peers_lst_head, connection, FALSE); if (peer) { /* A peer for the connection was found, cancel the timeout and go to configure state. */ nm_clear_g_source(&priv->find_peer_timeout_id); @@ -539,7 +540,7 @@ static void remove_all_peers(NMDeviceWifiP2P *self) { NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(self); - NMWifiP2PPeer * peer; + NMWifiP2PPeer *peer; if (c_list_is_empty(&priv->peers_lst_head)) return; @@ -552,46 +553,44 @@ remove_all_peers(NMDeviceWifiP2P *self) /*****************************************************************************/ -static NMActStageReturn -act_stage3_ip_config_start(NMDevice * device, - int addr_family, - gpointer * out_config, - NMDeviceStateReason *out_failure_reason) +static void +act_stage3_ip_config(NMDevice *device, int addr_family) { - NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(device); + NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(device); + const int IS_IPv4 = NM_IS_IPv4(addr_family); gboolean indicate_addressing_running; - NMConnection * connection; - const char * method; + NMConnection *connection; + const char *method; connection = nm_device_get_applied_connection(device); method = nm_utils_get_ip_config_method(connection, addr_family); /* We may have an address assigned by the group owner */ - if (NM_IN_STRSET(method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) && priv->group_iface + if (IS_IPv4 && NM_IN_STRSET(method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) && priv->group_iface && !nm_supplicant_interface_get_p2p_group_owner(priv->group_iface)) { in_addr_t addr; guint8 plen; if (nm_supplicant_interface_get_p2p_assigned_addr(priv->group_iface, &addr, &plen)) { - NMPlatformIP4Address address = { - .addr_source = NM_IP_CONFIG_SOURCE_DHCP, + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + NMPlatformIP4Address address = { + .addr_source = NM_IP_CONFIG_SOURCE_DHCP, }; - gs_unref_object NMIP4Config *ip4_config = NULL; nm_platform_ip4_address_set_addr(&address, addr, plen); - ip4_config = nm_device_ip4_config_new(device); - nm_ip4_config_add_address(ip4_config, &address); + l3cd = nm_device_create_l3_config_data(device, NM_IP_CONFIG_SOURCE_DHCP); + nm_l3_config_data_add_address_4(l3cd, &address); - nm_device_set_dev2_ip_config(device, AF_INET, NM_IP_CONFIG(ip4_config)); + nm_device_devip_set_state(device, AF_INET, NM_DEVICE_IP_STATE_READY, l3cd); /* This just disables the addressing indicator. */ method = NM_SETTING_IP4_CONFIG_METHOD_DISABLED; } } - if (addr_family == AF_INET) + if (IS_IPv4) indicate_addressing_running = NM_IN_STRSET(method, NM_SETTING_IP4_CONFIG_METHOD_AUTO); else { indicate_addressing_running = NM_IN_STRSET(method, @@ -603,15 +602,12 @@ act_stage3_ip_config_start(NMDevice * device, nm_platform_wifi_indicate_addressing_running(nm_device_get_platform(device), nm_device_get_ip_ifindex(device), TRUE); - - return NM_DEVICE_CLASS(nm_device_wifi_p2p_parent_class) - ->act_stage3_ip_config_start(device, addr_family, out_config, out_failure_reason); } static void deactivate(NMDevice *device) { - NMDeviceWifiP2P * self = NM_DEVICE_WIFI_P2P(device); + NMDeviceWifiP2P *self = NM_DEVICE_WIFI_P2P(device); int ifindex = nm_device_get_ip_ifindex(device); NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(self); @@ -642,7 +638,7 @@ get_configured_mtu(NMDevice *device, NMDeviceMtuSource *out_source, gboolean *ou static const char * get_auto_ip_config_method(NMDevice *device, int addr_family) { - NMDeviceWifiP2P * self = NM_DEVICE_WIFI_P2P(device); + NMDeviceWifiP2P *self = NM_DEVICE_WIFI_P2P(device); NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(self); if (addr_family == AF_INET && priv->group_iface @@ -675,8 +671,8 @@ supplicant_iface_state_cb(NMSupplicantInterface *iface, int disconnect_reason, gpointer user_data) { - NMDeviceWifiP2P * self = NM_DEVICE_WIFI_P2P(user_data); - NMDevice * device = NM_DEVICE(self); + NMDeviceWifiP2P *self = NM_DEVICE_WIFI_P2P(user_data); + NMDevice *device = NM_DEVICE(self); NMSupplicantInterfaceState new_state = new_state_i; NMSupplicantInterfaceState old_state = old_state_i; @@ -704,12 +700,12 @@ supplicant_iface_state_cb(NMSupplicantInterface *iface, static void supplicant_iface_peer_changed_cb(NMSupplicantInterface *iface, - NMSupplicantPeerInfo * peer_info, + NMSupplicantPeerInfo *peer_info, gboolean is_present, - NMDeviceWifiP2P * self) + NMDeviceWifiP2P *self) { NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(self); - NMWifiP2PPeer * found_peer; + NMWifiP2PPeer *found_peer; found_peer = nm_wifi_p2p_peers_find_by_supplicant_path(&priv->peers_lst_head, peer_info->peer_path->str); @@ -757,7 +753,7 @@ check_group_iface_ready(NMDeviceWifiP2P *self) nm_clear_g_source(&priv->sup_timeout_id); update_disconnect_on_connection_peer_missing(self); - nm_device_activate_schedule_stage3_ip_config_start(NM_DEVICE(self)); + nm_device_activate_schedule_stage3_ip_config(NM_DEVICE(self), FALSE); } static void @@ -786,7 +782,7 @@ supplicant_group_iface_state_cb(NMSupplicantInterface *iface, int disconnect_reason, gpointer user_data) { - NMDeviceWifiP2P * self = NM_DEVICE_WIFI_P2P(user_data); + NMDeviceWifiP2P *self = NM_DEVICE_WIFI_P2P(user_data); NMSupplicantInterfaceState new_state = new_state_i; NMSupplicantInterfaceState old_state = old_state_i; @@ -812,8 +808,8 @@ supplicant_group_iface_state_cb(NMSupplicantInterface *iface, static void supplicant_group_iface_group_finished_cb(NMSupplicantInterface *iface, - const char * iface_path, - void * user_data) + const char *iface_path, + void *user_data) { NMDeviceWifiP2P *self = NM_DEVICE_WIFI_P2P(user_data); @@ -826,8 +822,8 @@ supplicant_group_iface_group_finished_cb(NMSupplicantInterface *iface, static void supplicant_iface_group_joined_updated_cb(NMSupplicantInterface *iface, - GParamSpec * pspec, - void * user_data) + GParamSpec *pspec, + void *user_data) { NMDeviceWifiP2P *self = NM_DEVICE_WIFI_P2P(user_data); @@ -837,9 +833,9 @@ supplicant_iface_group_joined_updated_cb(NMSupplicantInterface *iface, static void supplicant_iface_group_started_cb(NMSupplicantInterface *iface, NMSupplicantInterface *group_iface, - NMDeviceWifiP2P * self) + NMDeviceWifiP2P *self) { - NMDeviceWifiP2PPrivate * priv; + NMDeviceWifiP2PPrivate *priv; NMSupplicantInterfaceState state; g_return_if_fail(self); @@ -923,12 +919,12 @@ supplicant_interfaces_release(NMDeviceWifiP2P *self, gboolean set_is_waiting) } static void -device_state_changed(NMDevice * device, +device_state_changed(NMDevice *device, NMDeviceState new_state, NMDeviceState old_state, NMDeviceStateReason reason) { - NMDeviceWifiP2P * self = NM_DEVICE_WIFI_P2P(device); + NMDeviceWifiP2P *self = NM_DEVICE_WIFI_P2P(device); NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(self); update_disconnect_on_connection_peer_missing(self); @@ -984,19 +980,19 @@ device_state_changed(NMDevice * device, } static void -impl_device_wifi_p2p_start_find(NMDBusObject * obj, +impl_device_wifi_p2p_start_find(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMDeviceWifiP2P * self = NM_DEVICE_WIFI_P2P(obj); - NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(self); + NMDeviceWifiP2P *self = NM_DEVICE_WIFI_P2P(obj); + NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(self); gs_unref_variant GVariant *options = NULL; - const char * opts_key; - GVariant * opts_val; + const char *opts_key; + GVariant *opts_val; GVariantIter iter; gint32 timeout = 30; @@ -1052,15 +1048,15 @@ impl_device_wifi_p2p_start_find(NMDBusObject * obj, } static void -impl_device_wifi_p2p_stop_find(NMDBusObject * obj, +impl_device_wifi_p2p_stop_find(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMDeviceWifiP2P * self = NM_DEVICE_WIFI_P2P(obj); + NMDeviceWifiP2P *self = NM_DEVICE_WIFI_P2P(obj); NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(self); if (!priv->mgmt_iface) { @@ -1184,9 +1180,9 @@ static const NMDBusInterfaceInfoExtended interface_info_device_wifi_p2p = { static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMDeviceWifiP2P * self = NM_DEVICE_WIFI_P2P(object); + NMDeviceWifiP2P *self = NM_DEVICE_WIFI_P2P(object); NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(self); - const char ** list; + const char **list; switch (prop_id) { case PROP_PEERS: @@ -1241,7 +1237,7 @@ nm_device_wifi_p2p_new(const char *iface) static void dispose(GObject *object) { - NMDeviceWifiP2P * self = NM_DEVICE_WIFI_P2P(object); + NMDeviceWifiP2P *self = NM_DEVICE_WIFI_P2P(object); NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(object); g_clear_object(&priv->sup_mgr); @@ -1254,7 +1250,7 @@ dispose(GObject *object) static void finalize(GObject *object) { - NMDeviceWifiP2P * peer = NM_DEVICE_WIFI_P2P(object); + NMDeviceWifiP2P *peer = NM_DEVICE_WIFI_P2P(object); NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(peer); nm_assert(c_list_is_empty(&priv->peers_lst_head)); @@ -1265,9 +1261,9 @@ finalize(GObject *object) static void nm_device_wifi_p2p_class_init(NMDeviceWifiP2PClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->constructed = constructed; object_class->get_property = get_property; @@ -1286,11 +1282,11 @@ nm_device_wifi_p2p_class_init(NMDeviceWifiP2PClass *klass) device_class->check_connection_compatible = check_connection_compatible; device_class->complete_connection = complete_connection; - device_class->act_stage1_prepare = act_stage1_prepare; - device_class->act_stage2_config = act_stage2_config; - device_class->get_configured_mtu = get_configured_mtu; - device_class->get_auto_ip_config_method = get_auto_ip_config_method; - device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; + device_class->act_stage1_prepare = act_stage1_prepare; + device_class->act_stage2_config = act_stage2_config; + device_class->get_configured_mtu = get_configured_mtu; + device_class->get_auto_ip_config_method = get_auto_ip_config_method; + device_class->act_stage3_ip_config = act_stage3_ip_config; device_class->deactivate = deactivate; device_class->unmanaged_on_quit = unmanaged_on_quit; diff --git a/src/core/devices/wifi/nm-device-wifi.c b/src/core/devices/wifi/nm-device-wifi.c index 82896c77..010cee08 100644 --- a/src/core/devices/wifi/nm-device-wifi.c +++ b/src/core/devices/wifi/nm-device-wifi.c @@ -32,7 +32,6 @@ #include "nm-setting-wireless-security.h" #include "nm-setting-8021x.h" #include "nm-setting-ip4-config.h" -#include "nm-ip4-config.h" #include "nm-setting-ip6-config.h" #include "libnm-platform/nm-platform.h" #include "nm-auth-utils.h" @@ -95,9 +94,9 @@ typedef struct { NMActRequestGetSecretsCallId *wifi_secrets_id; - NMSupplicantManager * sup_mgr; + NMSupplicantManager *sup_mgr; NMSupplMgrCreateIfaceHandle *sup_create_handle; - NMSupplicantInterface * sup_iface; + NMSupplicantInterface *sup_iface; gint64 scan_last_complete_msec; gint64 scan_periodic_next_msec; @@ -136,6 +135,8 @@ typedef struct { bool ssid_found : 1; bool hidden_probe_scan_warn : 1; + bool addressing_running_indicated : 1; + } NMDeviceWifiPrivate; struct _NMDeviceWifi { @@ -160,7 +161,7 @@ static void supplicant_iface_state_down(NMDeviceWifi *self); static void cleanup_association_attempt(NMDeviceWifi *self, gboolean disconnect); -static void supplicant_iface_state(NMDeviceWifi * self, +static void supplicant_iface_state(NMDeviceWifi *self, NMSupplicantInterfaceState new_state, NMSupplicantInterfaceState old_state, int disconnect_reason, @@ -173,27 +174,27 @@ static void supplicant_iface_state_cb(NMSupplicantInterface *iface, gpointer user_data); static void supplicant_iface_bss_changed_cb(NMSupplicantInterface *iface, - NMSupplicantBssInfo * bss_info, + NMSupplicantBssInfo *bss_info, gboolean is_present, - NMDeviceWifi * self); + NMDeviceWifi *self); static void supplicant_iface_wps_credentials_cb(NMSupplicantInterface *iface, - GVariant * credentials, - NMDeviceWifi * self); + GVariant *credentials, + NMDeviceWifi *self); static void supplicant_iface_notify_current_bss(NMSupplicantInterface *iface, - GParamSpec * pspec, - NMDeviceWifi * self); + GParamSpec *pspec, + NMDeviceWifi *self); static void supplicant_iface_notify_p2p_available(NMSupplicantInterface *iface, - GParamSpec * pspec, - NMDeviceWifi * self); + GParamSpec *pspec, + NMDeviceWifi *self); static void periodic_update(NMDeviceWifi *self); static void ap_add_remove(NMDeviceWifi *self, gboolean is_adding, - NMWifiAP * ap, + NMWifiAP *ap, gboolean recheck_available_connections); static void _hw_addr_set_scanning(NMDeviceWifi *self, gboolean do_reset); @@ -290,7 +291,7 @@ static GPtrArray * _scan_request_ssids_fetch(NMDeviceWifiPrivate *priv, gint64 now_msec) { ScanRequestSsidData *srs_data; - GPtrArray * ssids; + GPtrArray *ssids; guint len; _scan_request_ssids_remove_all(priv, now_msec, G_MAXUINT); @@ -331,7 +332,7 @@ _scan_request_ssids_track(NMDeviceWifiPrivate *priv, const GPtrArray *ssids) c_list_splice(&old_lst_head, &priv->scan_request_ssids_lst_head); for (i = 0; i < ssids->len; i++) { - GBytes * ssid = ssids->pdata[i]; + GBytes *ssid = ssids->pdata[i]; ScanRequestSsidData *d; G_STATIC_ASSERT_EXPR(G_STRUCT_OFFSET(ScanRequestSsidData, ssid) == 0); @@ -364,7 +365,7 @@ nm_device_wifi_scanning_prohibited_track(NMDeviceWifi *self, gboolean temporarily_prohibited) { NMDeviceWifiPrivate *priv; - NMCListElem * elem; + NMCListElem *elem; g_return_if_fail(NM_IS_DEVICE_WIFI(self)); nm_assert(tag); @@ -394,10 +395,26 @@ nm_device_wifi_scanning_prohibited_track(NMDeviceWifi *self, /*****************************************************************************/ static void -_ap_dump(NMDeviceWifi * self, +_indicate_addressing_running_reset(NMDeviceWifi *self) +{ + NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); + + if (!priv->addressing_running_indicated) + return; + + priv->addressing_running_indicated = FALSE; + nm_platform_wifi_indicate_addressing_running(nm_device_get_platform(NM_DEVICE(self)), + nm_device_get_ifindex(NM_DEVICE(self)), + FALSE); +} + +/*****************************************************************************/ + +static void +_ap_dump(NMDeviceWifi *self, NMLogLevel log_level, const NMWifiAP *ap, - const char * prefix, + const char *prefix, gint64 now_msec) { char buf[1024]; @@ -530,8 +547,8 @@ _scan_notify_allowed(NMDeviceWifi *self, NMTernary do_kickoff) static void supplicant_iface_notify_scanning_cb(NMSupplicantInterface *iface, - GParamSpec * pspec, - NMDeviceWifi * self) + GParamSpec *pspec, + NMDeviceWifi *self) { _scan_notify_is_scanning(self); } @@ -549,13 +566,13 @@ unmanaged_on_quit(NMDevice *self) } static void -supplicant_interface_acquire_cb(NMSupplicantManager * supplicant_manager, +supplicant_interface_acquire_cb(NMSupplicantManager *supplicant_manager, NMSupplMgrCreateIfaceHandle *handle, - NMSupplicantInterface * iface, - GError * error, + NMSupplicantInterface *iface, + GError *error, gpointer user_data) { - NMDeviceWifi * self = user_data; + NMDeviceWifi *self = user_data; NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); if (nm_utils_error_is_cancelled(error)) @@ -694,7 +711,7 @@ static void set_current_ap(NMDeviceWifi *self, NMWifiAP *new_ap, gboolean recheck_available_connections) { NMDeviceWifiPrivate *priv; - NMWifiAP * old_ap; + NMWifiAP *old_ap; g_return_if_fail(NM_IS_DEVICE_WIFI(self)); @@ -790,7 +807,7 @@ periodic_update_cb(gpointer user_data) static void ap_add_remove(NMDeviceWifi *self, gboolean is_adding, /* or else removing */ - NMWifiAP * ap, + NMWifiAP *ap, gboolean recheck_available_connections) { NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); @@ -831,7 +848,7 @@ static void remove_all_aps(NMDeviceWifi *self) { NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); - NMWifiAP * ap; + NMWifiAP *ap; if (c_list_is_empty(&priv->aps_lst_head)) return; @@ -847,7 +864,7 @@ remove_all_aps(NMDeviceWifi *self) static gboolean wake_on_wlan_restore(NMDeviceWifi *self) { - NMDeviceWifiPrivate * priv = NM_DEVICE_WIFI_GET_PRIVATE(self); + NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); _NMSettingWirelessWakeOnWLan w; w = priv->wowlan_restore; @@ -879,7 +896,7 @@ disconnect_cb_on_idle(gpointer user_data, GCancellable *cancellable) gs_unref_object NMDeviceWifi *self = NULL; NMDeviceDeactivateCallback callback; gpointer callback_user_data; - gs_free_error GError *cancelled_error = NULL; + gs_free_error GError *cancelled_error = NULL; nm_utils_user_data_unpack(user_data, &self, &callback, &callback_user_data); @@ -888,12 +905,12 @@ disconnect_cb_on_idle(gpointer user_data, GCancellable *cancellable) } static void -deactivate_async(NMDevice * device, - GCancellable * cancellable, +deactivate_async(NMDevice *device, + GCancellable *cancellable, NMDeviceDeactivateCallback callback, gpointer callback_user_data) { - NMDeviceWifi * self = NM_DEVICE_WIFI(device); + NMDeviceWifi *self = NM_DEVICE_WIFI(device); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); gpointer user_data; @@ -917,7 +934,7 @@ deactivate_async(NMDevice * device, static void deactivate(NMDevice *device) { - NMDeviceWifi * self = NM_DEVICE_WIFI(device); + NMDeviceWifi *self = NM_DEVICE_WIFI(device); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); int ifindex = nm_device_get_ifindex(device); @@ -932,8 +949,7 @@ deactivate(NMDevice *device) if (!wake_on_wlan_restore(self)) _LOGW(LOGD_DEVICE | LOGD_WIFI, "Cannot unconfigure WoWLAN."); - /* Clear any critical protocol notification in the Wi-Fi stack */ - nm_platform_wifi_indicate_addressing_running(nm_device_get_platform(device), ifindex, FALSE); + _indicate_addressing_running_reset(self); /* Ensure we're in infrastructure mode after deactivation; some devices * (usually older ones) don't scan well in adhoc mode. @@ -962,14 +978,14 @@ deactivate_reset_hw_addr(NMDevice *device) static gboolean check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error) { - NMDeviceWifi * self = NM_DEVICE_WIFI(device); + NMDeviceWifi *self = NM_DEVICE_WIFI(device); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); - NMSettingWireless * s_wireless; - const char * mac; - const char *const * mac_blacklist; + NMSettingWireless *s_wireless; + const char *mac; + const char *const *mac_blacklist; int i; - const char * mode; - const char * perm_hw_addr; + const char *mode; + const char *perm_hw_addr; if (!NM_DEVICE_CLASS(nm_device_wifi_parent_class) ->check_connection_compatible(device, connection, error)) @@ -1062,16 +1078,16 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError * } static gboolean -check_connection_available(NMDevice * device, - NMConnection * connection, +check_connection_available(NMDevice *device, + NMConnection *connection, NMDeviceCheckConAvailableFlags flags, - const char * specific_object, - GError ** error) + const char *specific_object, + GError **error) { - NMDeviceWifi * self = NM_DEVICE_WIFI(device); + NMDeviceWifi *self = NM_DEVICE_WIFI(device); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); - NMSettingWireless * s_wifi; - const char * mode; + NMSettingWireless *s_wifi; + const char *mode; s_wifi = nm_connection_get_setting_wireless(connection); g_return_val_if_fail(s_wifi, FALSE); @@ -1130,21 +1146,21 @@ check_connection_available(NMDevice * device, } static gboolean -complete_connection(NMDevice * device, - NMConnection * connection, - const char * specific_object, +complete_connection(NMDevice *device, + NMConnection *connection, + const char *specific_object, NMConnection *const *existing_connections, - GError ** error) + GError **error) { - NMDeviceWifi * self = NM_DEVICE_WIFI(device); + NMDeviceWifi *self = NM_DEVICE_WIFI(device); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); - NMSettingWireless * s_wifi; - gs_free char * ssid_utf8 = NULL; - NMWifiAP * ap; - GBytes * ssid = NULL; - GBytes * setting_ssid = NULL; + NMSettingWireless *s_wifi; + gs_free char *ssid_utf8 = NULL; + NMWifiAP *ap; + GBytes *ssid = NULL; + GBytes *setting_ssid = NULL; gboolean hidden = FALSE; - const char * mode; + const char *mode; s_wifi = nm_connection_get_setting_wireless(connection); @@ -1265,8 +1281,8 @@ complete_connection(NMDevice * device, static gboolean is_available(NMDevice *device, NMDeviceCheckDevAvailableFlags flags) { - NMDeviceWifi * self = NM_DEVICE_WIFI(device); - NMDeviceWifiPrivate * priv = NM_DEVICE_WIFI_GET_PRIVATE(self); + NMDeviceWifi *self = NM_DEVICE_WIFI(device); + NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); NMSupplicantInterfaceState supplicant_state; if (!priv->enabled) @@ -1292,12 +1308,12 @@ get_autoconnect_allowed(NMDevice *device) static gboolean can_auto_connect(NMDevice *device, NMSettingsConnection *sett_conn, char **specific_object) { - NMDeviceWifi * self = NM_DEVICE_WIFI(device); + NMDeviceWifi *self = NM_DEVICE_WIFI(device); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); - NMConnection * connection; - NMSettingWireless * s_wifi; - NMWifiAP * ap; - const char * method6, *mode; + NMConnection *connection; + NMSettingWireless *s_wifi; + NMWifiAP *ap; + const char *method6, *mode; gboolean auto4, auto6; nm_assert(!specific_object || !*specific_object); @@ -1345,7 +1361,7 @@ _nm_device_wifi_get_aps(NMDeviceWifi *self) static void _hw_addr_set_scanning(NMDeviceWifi *self, gboolean do_reset) { - NMDevice * device = (NMDevice *) self; + NMDevice *device = (NMDevice *) self; NMDeviceWifiPrivate *priv; guint32 now; gboolean randomize; @@ -1381,7 +1397,7 @@ _hw_addr_set_scanning(NMDeviceWifi *self, gboolean do_reset) if (now >= priv->hw_addr_scan_expire) { gs_free char *hw_addr_scan = NULL; - const char * generate_mac_address_mask; + const char *generate_mac_address_mask; /* the random MAC address for scanning expires after a while. * @@ -1428,7 +1444,7 @@ ssids_options_to_ptrarray(GVariant *value, GError **error) for (i = 0; i < num_ssids; i++) { gs_unref_variant GVariant *v = NULL; gsize len; - const guint8 * bytes; + const guint8 *bytes; v = g_variant_get_child_value(value, i); bytes = g_variant_get_fixed_array(v, &len, sizeof(guint8)); @@ -1455,14 +1471,14 @@ nmtst_ssids_options_to_ptrarray(GVariant *value, GError **error) } static void -dbus_request_scan_cb(NMDevice * device, +dbus_request_scan_cb(NMDevice *device, GDBusMethodInvocation *context, - NMAuthSubject * subject, - GError * error, + NMAuthSubject *subject, + GError *error, gpointer user_data) { - NMDeviceWifi * self = NM_DEVICE_WIFI(device); - NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); + NMDeviceWifi *self = NM_DEVICE_WIFI(device); + NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); gs_unref_ptrarray GPtrArray *ssids = user_data; if (error) { @@ -1477,13 +1493,13 @@ dbus_request_scan_cb(NMDevice * device, } void -_nm_device_wifi_request_scan(NMDeviceWifi * self, - GVariant * options, +_nm_device_wifi_request_scan(NMDeviceWifi *self, + GVariant *options, GDBusMethodInvocation *invocation) { - NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); - NMDevice * device = NM_DEVICE(self); - gs_unref_ptrarray GPtrArray *ssids = NULL; + NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); + NMDevice *device = NM_DEVICE(self); + gs_unref_ptrarray GPtrArray *ssids = NULL; if (options) { gs_unref_variant GVariant *val = g_variant_lookup_value(options, "ssids", NULL); @@ -1529,7 +1545,7 @@ _nm_device_wifi_request_scan(NMDeviceWifi * self, static gboolean hidden_filter_func(NMSettings *settings, NMSettingsConnection *set_con, gpointer user_data) { - NMConnection * connection = nm_settings_connection_get_connection(set_con); + NMConnection *connection = nm_settings_connection_get_connection(set_con); NMSettingWireless *s_wifi; if (!nm_connection_is_type(connection, NM_SETTING_WIRELESS_SETTING_NAME)) @@ -1545,12 +1561,12 @@ hidden_filter_func(NMSettings *settings, NMSettingsConnection *set_con, gpointer static GPtrArray * _scan_request_ssids_build_hidden(NMDeviceWifi *self, gint64 now_msec, - gboolean * out_has_hidden_profiles) + gboolean *out_has_hidden_profiles) { NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); - guint max_scan_ssids = nm_supplicant_interface_get_max_scan_ssids(priv->sup_iface); + guint max_scan_ssids = nm_supplicant_interface_get_max_scan_ssids(priv->sup_iface); gs_free NMSettingsConnection **connections = NULL; - gs_unref_ptrarray GPtrArray *ssids = NULL; + gs_unref_ptrarray GPtrArray *ssids = NULL; gs_unref_hashtable GHashTable *unique_ssids = NULL; guint connections_len; guint n_hidden; @@ -1608,7 +1624,7 @@ _scan_request_ssids_build_hidden(NMDeviceWifi *self, n_hidden = 0; for (i = 0; i < connections_len; i++) { NMSettingWireless *s_wifi; - GBytes * ssid; + GBytes *ssid; if (ssids->len >= max_scan_ssids) break; @@ -1637,7 +1653,7 @@ _scan_request_ssids_build_hidden(NMDeviceWifi *self, static gboolean _scan_request_delay_cb(gpointer user_data) { - NMDeviceWifi * self = user_data; + NMDeviceWifi *self = user_data; NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); nm_clear_g_source_inst(&priv->scan_request_delay_source); @@ -1650,10 +1666,10 @@ _scan_request_delay_cb(gpointer user_data) static void _scan_supplicant_request_scan_cb(NMSupplicantInterface *supp_iface, - GCancellable * cancellable, + GCancellable *cancellable, gpointer user_data) { - NMDeviceWifi * self; + NMDeviceWifi *self; NMDeviceWifiPrivate *priv; if (g_cancellable_is_cancelled(cancellable)) @@ -1680,7 +1696,7 @@ _scan_supplicant_request_scan_cb(NMSupplicantInterface *supp_iface, static gboolean _scan_kickoff_timeout_cb(gpointer user_data) { - NMDeviceWifi * self = user_data; + NMDeviceWifi *self = user_data; NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); priv->scan_kickoff_timeout_id = 0; @@ -1691,7 +1707,7 @@ _scan_kickoff_timeout_cb(gpointer user_data) static void _scan_kickoff(NMDeviceWifi *self) { - NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); + NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); gs_unref_ptrarray GPtrArray *ssids = NULL; gboolean is_explict = FALSE; NMDeviceState device_state; @@ -1866,7 +1882,7 @@ _scan_kickoff(NMDeviceWifi *self) static gboolean ap_list_dump(gpointer user_data) { - NMDeviceWifi * self = NM_DEVICE_WIFI(user_data); + NMDeviceWifi *self = NM_DEVICE_WIFI(user_data); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); priv->ap_dump_id = 0; @@ -1904,7 +1920,7 @@ schedule_ap_list_dump(NMDeviceWifi *self) static void try_fill_ssid_for_hidden_ap(NMDeviceWifi *self, NMWifiAP *ap) { - const char * bssid; + const char *bssid; NMSettingsConnection *const *connections; guint i; @@ -1918,7 +1934,7 @@ try_fill_ssid_for_hidden_ap(NMDeviceWifi *self, NMWifiAP *ap) connections = nm_settings_get_connections(nm_device_get_settings((NMDevice *) self), NULL); for (i = 0; connections[i]; i++) { NMSettingsConnection *sett_conn = connections[i]; - NMSettingWireless * s_wifi; + NMSettingWireless *s_wifi; if (!nm_settings_connection_has_seen_bssid(sett_conn, bssid)) continue; @@ -1934,13 +1950,13 @@ try_fill_ssid_for_hidden_ap(NMDeviceWifi *self, NMWifiAP *ap) static void supplicant_iface_bss_changed_cb(NMSupplicantInterface *iface, - NMSupplicantBssInfo * bss_info, + NMSupplicantBssInfo *bss_info, gboolean is_present, - NMDeviceWifi * self) + NMDeviceWifi *self) { NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); - NMWifiAP * found_ap; - GBytes * ssid; + NMWifiAP *found_ap; + GBytes *ssid; found_ap = g_hash_table_lookup(priv->aps_idx_by_supplicant_path, bss_info->bss_path); @@ -2033,14 +2049,14 @@ cleanup_supplicant_failures(NMDeviceWifi *self) } static void -wifi_secrets_cb(NMActRequest * req, +wifi_secrets_cb(NMActRequest *req, NMActRequestGetSecretsCallId *call_id, - NMSettingsConnection * connection, - GError * error, + NMSettingsConnection *connection, + GError *error, gpointer user_data) { - NMDevice * device = user_data; - NMDeviceWifi * self = user_data; + NMDevice *device = user_data; + NMDeviceWifi *self = user_data; NMDeviceWifiPrivate *priv; g_return_if_fail(NM_IS_DEVICE_WIFI(self)); @@ -2107,15 +2123,15 @@ wifi_secrets_cancel(NMDeviceWifi *self) static void supplicant_iface_wps_credentials_cb(NMSupplicantInterface *iface, - GVariant * credentials, - NMDeviceWifi * self) + GVariant *credentials, + NMDeviceWifi *self) { - NMActRequest * req; + NMActRequest *req; gs_unref_variant GVariant *val_key = NULL; gs_unref_variant GVariant *secrets = NULL; - gs_free_error GError *error = NULL; - const char * array; - gsize psk_len = 0; + gs_free_error GError *error = NULL; + const char *array; + gsize psk_len = 0; if (nm_device_get_state(NM_DEVICE(self)) != NM_DEVICE_STATE_NEED_AUTH) { _LOGI(LOGD_DEVICE | LOGD_WIFI, "WPS: The connection can't be updated with credentials"); @@ -2168,7 +2184,7 @@ supplicant_iface_wps_credentials_cb(NMSupplicantInterface *iface, static gboolean wps_timeout_cb(gpointer user_data) { - NMDeviceWifi * self = NM_DEVICE_WIFI(user_data); + NMDeviceWifi *self = NM_DEVICE_WIFI(user_data); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); priv->wps_timeout_id = 0; @@ -2183,12 +2199,12 @@ wps_timeout_cb(gpointer user_data) } static void -wifi_secrets_get_secrets(NMDeviceWifi * self, - const char * setting_name, +wifi_secrets_get_secrets(NMDeviceWifi *self, + const char *setting_name, NMSecretAgentGetSecretsFlags flags) { NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); - NMActRequest * req; + NMActRequest *req; wifi_secrets_cancel(self); @@ -2209,8 +2225,8 @@ wifi_secrets_get_secrets(NMDeviceWifi * self, static gboolean link_timeout_cb(gpointer user_data) { - NMDevice * device = NM_DEVICE(user_data); - NMDeviceWifi * self = NM_DEVICE_WIFI(device); + NMDevice *device = NM_DEVICE(user_data); + NMDeviceWifi *self = NM_DEVICE_WIFI(device); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); _LOGW(LOGD_WIFI, "link timed out."); @@ -2234,14 +2250,14 @@ link_timeout_cb(gpointer user_data) } static gboolean -need_new_8021x_secrets(NMDeviceWifi * self, +need_new_8021x_secrets(NMDeviceWifi *self, NMSupplicantInterfaceState old_state, - const char ** setting_name) + const char **setting_name) { - NMSetting8021x * s_8021x; + NMSetting8021x *s_8021x; NMSettingWirelessSecurity *s_wsec; NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE; - NMConnection * connection; + NMConnection *connection; g_return_val_if_fail(setting_name, FALSE); @@ -2289,14 +2305,14 @@ need_new_8021x_secrets(NMDeviceWifi * self, } static gboolean -need_new_wpa_psk(NMDeviceWifi * self, +need_new_wpa_psk(NMDeviceWifi *self, NMSupplicantInterfaceState old_state, int disconnect_reason, - const char ** setting_name) + const char **setting_name) { NMSettingWirelessSecurity *s_wsec; - NMConnection * connection; - const char * key_mgmt = NULL; + NMConnection *connection; + const char *key_mgmt = NULL; g_return_val_if_fail(setting_name, FALSE); @@ -2331,14 +2347,14 @@ need_new_wpa_psk(NMDeviceWifi * self, } static gboolean -handle_8021x_or_psk_auth_fail(NMDeviceWifi * self, +handle_8021x_or_psk_auth_fail(NMDeviceWifi *self, NMSupplicantInterfaceState new_state, NMSupplicantInterfaceState old_state, int disconnect_reason) { - NMDevice * device = NM_DEVICE(self); + NMDevice *device = NM_DEVICE(self); NMActRequest *req; - const char * setting_name = NULL; + const char *setting_name = NULL; gboolean handled = FALSE; g_return_val_if_fail(new_state == NM_SUPPLICANT_INTERFACE_STATE_DISCONNECTED, FALSE); @@ -2370,8 +2386,8 @@ handle_8021x_or_psk_auth_fail(NMDeviceWifi * self, static gboolean reacquire_interface_cb(gpointer user_data) { - NMDevice * device = NM_DEVICE(user_data); - NMDeviceWifi * self = NM_DEVICE_WIFI(device); + NMDevice *device = NM_DEVICE(user_data); + NMDeviceWifi *self = NM_DEVICE_WIFI(device); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); priv->reacquire_iface_id = 0; @@ -2389,7 +2405,7 @@ static void supplicant_iface_state_down(NMDeviceWifi *self) { NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); - NMDevice * device = NM_DEVICE(self); + NMDevice *device = NM_DEVICE(self); nm_device_queue_recheck_available(device, NM_DEVICE_STATE_REASON_SUPPLICANT_AVAILABLE, @@ -2409,14 +2425,14 @@ supplicant_iface_state_down(NMDeviceWifi *self) } static void -supplicant_iface_state(NMDeviceWifi * self, +supplicant_iface_state(NMDeviceWifi *self, NMSupplicantInterfaceState new_state, NMSupplicantInterfaceState old_state, int disconnect_reason, gboolean is_real_signal) { NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); - NMDevice * device = NM_DEVICE(self); + NMDevice *device = NM_DEVICE(self); NMDeviceState devstate; gboolean scanning; gboolean scan_changed; @@ -2463,8 +2479,8 @@ supplicant_iface_state(NMDeviceWifi * self, */ if (devstate == NM_DEVICE_STATE_CONFIG) { NMSettingWireless *s_wifi; - GBytes * ssid; - gs_free char * ssid_str = NULL; + GBytes *ssid; + gs_free char *ssid_str = NULL; s_wifi = nm_device_get_applied_setting(NM_DEVICE(self), NM_TYPE_SETTING_WIRELESS); @@ -2478,7 +2494,7 @@ supplicant_iface_state(NMDeviceWifi * self, priv->mode == _NM_802_11_MODE_AP ? "Started Wi-Fi Hotspot" : "Connected to wireless network", (ssid_str = _nm_utils_ssid_to_string_gbytes(ssid))); - nm_device_activate_schedule_stage3_ip_config_start(device); + nm_device_activate_schedule_stage3_ip_config(device, FALSE); } else if (devstate == NM_DEVICE_STATE_ACTIVATED) periodic_update(self); break; @@ -2540,7 +2556,7 @@ static void supplicant_iface_assoc_cb(NMSupplicantInterface *iface, GError *error, gpointer user_data) { NMDeviceWifi *self = NM_DEVICE_WIFI(user_data); - NMDevice * device = NM_DEVICE(self); + NMDevice *device = NM_DEVICE(self); if (error && !nm_utils_error_is_cancelled_or_disposing(error) && nm_device_is_activating(device)) { @@ -2553,23 +2569,23 @@ supplicant_iface_assoc_cb(NMSupplicantInterface *iface, GError *error, gpointer static void supplicant_iface_notify_current_bss(NMSupplicantInterface *iface, - GParamSpec * pspec, - NMDeviceWifi * self) + GParamSpec *pspec, + NMDeviceWifi *self) { NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); - NMRefString * current_bss; - NMWifiAP * new_ap = NULL; - NMActRequest * req; + NMRefString *current_bss; + NMWifiAP *new_ap = NULL; + NMActRequest *req; current_bss = nm_supplicant_interface_get_current_bss(iface); if (current_bss) new_ap = g_hash_table_lookup(priv->aps_idx_by_supplicant_path, current_bss); if (new_ap != priv->current_ap) { - const char * new_bssid = NULL; - GBytes * new_ssid = NULL; - const char * old_bssid = NULL; - GBytes * old_ssid = NULL; + const char *new_bssid = NULL; + GBytes *new_ssid = NULL; + const char *old_bssid = NULL; + GBytes *old_ssid = NULL; gs_free char *new_ssid_s = NULL; gs_free char *old_ssid_s = NULL; @@ -2666,8 +2682,8 @@ recheck_p2p_availability(NMDeviceWifi *self) static void supplicant_iface_notify_p2p_available(NMSupplicantInterface *iface, - GParamSpec * pspec, - NMDeviceWifi * self) + GParamSpec *pspec, + NMDeviceWifi *self) { if (nm_supplicant_interface_get_state(iface) > NM_SUPPLICANT_INTERFACE_STATE_STARTING) recheck_p2p_availability(self); @@ -2676,14 +2692,14 @@ supplicant_iface_notify_p2p_available(NMSupplicantInterface *iface, static gboolean handle_auth_or_fail(NMDeviceWifi *self, NMActRequest *req, gboolean new_secrets) { - NMDeviceWifiPrivate * priv = NM_DEVICE_WIFI_GET_PRIVATE(self); - const char * setting_name; - NMConnection * applied_connection; - NMSettingWirelessSecurity * s_wsec; - const char * bssid = NULL; + NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); + const char *setting_name; + NMConnection *applied_connection; + NMSettingWirelessSecurity *s_wsec; + const char *bssid = NULL; NM80211ApFlags ap_flags; NMSettingWirelessSecurityWpsMethod wps_method; - const char * type; + const char *type; NMSecretAgentGetSecretsFlags get_secret_flags = NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION; @@ -2761,11 +2777,11 @@ handle_auth_or_fail(NMDeviceWifi *self, NMActRequest *req, gboolean new_secrets) static gboolean supplicant_connection_timeout_cb(gpointer user_data) { - NMDevice * device = NM_DEVICE(user_data); - NMDeviceWifi * self = NM_DEVICE_WIFI(user_data); + NMDevice *device = NM_DEVICE(user_data); + NMDeviceWifi *self = NM_DEVICE_WIFI(user_data); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); - NMActRequest * req; - NMConnection * connection; + NMActRequest *req; + NMConnection *connection; cleanup_association_attempt(self, TRUE); @@ -2841,12 +2857,12 @@ static NMSupplicantConfig * build_supplicant_config(NMDeviceWifi *self, NMConnection *connection, guint32 fixed_freq, - GError ** error) + GError **error) { - NMDeviceWifiPrivate * priv = NM_DEVICE_WIFI_GET_PRIVATE(self); - NMSupplicantConfig * config = NULL; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity * s_wireless_sec; + NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); + NMSupplicantConfig *config = NULL; + NMSettingWireless *s_wireless; + NMSettingWirelessSecurity *s_wireless_sec; NMSettingWirelessSecurityPmf pmf; NMSettingWirelessSecurityFils fils; NMTernary ap_isolation; @@ -2889,7 +2905,7 @@ build_supplicant_config(NMDeviceWifi *self, s_wireless_sec = nm_connection_get_setting_wireless_security(connection); if (s_wireless_sec) { NMSetting8021x *s_8021x; - const char * con_uuid = nm_connection_get_uuid(connection); + const char *con_uuid = nm_connection_get_uuid(connection); guint32 mtu = nm_platform_link_get_mtu(nm_device_get_platform(NM_DEVICE(self)), nm_device_get_ifindex(NM_DEVICE(self))); @@ -2950,10 +2966,10 @@ error: static gboolean wake_on_wlan_enable(NMDeviceWifi *self) { - NMDeviceWifiPrivate * priv = NM_DEVICE_WIFI_GET_PRIVATE(self); + NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); NMSettingWirelessWakeOnWLan wowl; _NMSettingWirelessWakeOnWLan wowl2; - NMSettingWireless * s_wireless; + NMSettingWireless *s_wireless; s_wireless = nm_device_get_applied_setting(NM_DEVICE(self), NM_TYPE_SETTING_WIRELESS); if (s_wireless) { @@ -3004,15 +3020,15 @@ found: static NMActStageReturn act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) { - NMDeviceWifi * self = NM_DEVICE_WIFI(device); - NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); - NMWifiAP * ap = NULL; + NMDeviceWifi *self = NM_DEVICE_WIFI(device); + NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); + NMWifiAP *ap = NULL; gs_unref_object NMWifiAP *ap_fake = NULL; - NMActRequest * req; - NMConnection * connection; - NMSettingWireless * s_wireless; - const char * mode; - const char * ap_path; + NMActRequest *req; + NMConnection *connection; + NMSettingWireless *s_wireless; + const char *mode; + const char *ap_path; req = nm_device_get_act_request(NM_DEVICE(self)); g_return_val_if_fail(req, NM_ACT_STAGE_RETURN_FAILURE); @@ -3087,8 +3103,8 @@ act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) static void ensure_hotspot_frequency(NMDeviceWifi *self, NMSettingWireless *s_wifi, NMWifiAP *ap) { - NMDevice * device = NM_DEVICE(self); - const char * band = nm_setting_wireless_get_band(s_wifi); + NMDevice *device = NM_DEVICE(self); + const char *band = nm_setting_wireless_get_band(s_wifi); const guint32 a_freqs[] = {5180, 5200, 5220, 5745, 5765, 5785, 5805, 0}; const guint32 bg_freqs[] = {2412, 2437, 2462, 2472, 0}; guint32 freq = 0; @@ -3117,8 +3133,8 @@ ensure_hotspot_frequency(NMDeviceWifi *self, NMSettingWireless *s_wifi, NMWifiAP static void set_powersave(NMDevice *device) { - NMDeviceWifi * self = NM_DEVICE_WIFI(device); - NMSettingWireless * s_wireless; + NMDeviceWifi *self = NM_DEVICE_WIFI(device); + NMSettingWireless *s_wireless; NMSettingWirelessPowersave val; s_wireless = nm_device_get_applied_setting(device, NM_TYPE_SETTING_WIRELESS); @@ -3148,20 +3164,20 @@ set_powersave(NMDevice *device) static NMActStageReturn act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) { - NMDeviceWifi * self = NM_DEVICE_WIFI(device); - NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); + NMDeviceWifi *self = NM_DEVICE_WIFI(device); + NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); gs_unref_object NMSupplicantConfig *config = NULL; _NM80211Mode ap_mode; - NMActRequest * req; - NMWifiAP * ap; - NMConnection * connection; - const char * setting_name; - NMSettingWireless * s_wireless; - GError * error = NULL; + NMActRequest *req; + NMWifiAP *ap; + NMConnection *connection; + const char *setting_name; + NMSettingWireless *s_wireless; + GError *error = NULL; guint timeout; - NMActRequest * request; - NMActiveConnection * master_ac; - NMDevice * master; + NMActRequest *request; + NMActiveConnection *master_ac; + NMDevice *master; nm_clear_g_source(&priv->sup_timeout_id); nm_clear_g_source(&priv->link_timeout_id); @@ -3263,20 +3279,24 @@ out_fail: return NM_ACT_STAGE_RETURN_FAILURE; } -static NMActStageReturn -act_stage3_ip_config_start(NMDevice * device, - int addr_family, - gpointer * out_config, - NMDeviceStateReason *out_failure_reason) +static void +act_stage3_ip_config(NMDevice *device, int addr_family) { - gboolean indicate_addressing_running; - NMConnection *connection; - const char * method; + NMDeviceWifi *self = NM_DEVICE_WIFI(device); + NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); + const char *method; + gboolean indicate_addressing_running; + + if (priv->addressing_running_indicated) + return; - connection = nm_device_get_applied_connection(device); + /* we always set the flag, even if we don't indicate it below. The reason + * is that we always want to *clear* the flag after we are done (as we don't + * know whether it isn't already set on the interface). */ + priv->addressing_running_indicated = TRUE; - method = nm_utils_get_ip_config_method(connection, addr_family); - if (addr_family == AF_INET) + method = nm_utils_get_ip_config_method(nm_device_get_applied_connection(device), addr_family); + if (NM_IS_IPv4(addr_family)) indicate_addressing_running = NM_IN_STRSET(method, NM_SETTING_IP4_CONFIG_METHOD_AUTO); else { indicate_addressing_running = NM_IN_STRSET(method, @@ -3284,13 +3304,11 @@ act_stage3_ip_config_start(NMDevice * device, NM_SETTING_IP6_CONFIG_METHOD_DHCP); } - if (indicate_addressing_running) + if (indicate_addressing_running) { nm_platform_wifi_indicate_addressing_running(nm_device_get_platform(device), nm_device_get_ip_ifindex(device), TRUE); - - return NM_DEVICE_CLASS(nm_device_wifi_parent_class) - ->act_stage3_ip_config_start(device, addr_family, out_config, out_failure_reason); + } } static guint32 @@ -3301,90 +3319,18 @@ get_configured_mtu(NMDevice *device, NMDeviceMtuSource *out_source, gboolean *ou out_source); } -static gboolean -is_static_wep(NMConnection *connection) -{ - NMSettingWirelessSecurity *s_wsec; - const char * str; - - g_return_val_if_fail(connection != NULL, FALSE); - - s_wsec = nm_connection_get_setting_wireless_security(connection); - if (!s_wsec) - return FALSE; - - str = nm_setting_wireless_security_get_key_mgmt(s_wsec); - if (g_strcmp0(str, "none") != 0) - return FALSE; - - str = nm_setting_wireless_security_get_auth_alg(s_wsec); - if (g_strcmp0(str, "leap") == 0) - return FALSE; - - return TRUE; -} - -static NMActStageReturn -act_stage4_ip_config_timeout(NMDevice * device, - int addr_family, - NMDeviceStateReason *out_failure_reason) -{ - NMDeviceWifi * self = NM_DEVICE_WIFI(device); - NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); - NMConnection * connection; - NMSettingIPConfig * s_ip; - gboolean may_fail; - - connection = nm_device_get_applied_connection(device); - s_ip = nm_connection_get_setting_ip_config(connection, addr_family); - may_fail = nm_setting_ip_config_get_may_fail(s_ip); - - if (priv->mode == _NM_802_11_MODE_AP) - goto call_parent; - - if (may_fail || !is_static_wep(connection)) { - /* Not static WEP or failure allowed; let superclass handle it */ - goto call_parent; - } - - /* If IP configuration times out and it's a static WEP connection, that - * usually means the WEP key is wrong. WEP's Open System auth mode has - * no provision for figuring out if the WEP key is wrong, so you just have - * to wait for DHCP to fail to figure it out. For all other Wi-Fi security - * types (open, WPA, 802.1x, etc) if the secrets/certs were wrong the - * connection would have failed before IP configuration. - * - * Activation failed, we must have bad encryption key */ - _LOGW(LOGD_DEVICE | LOGD_WIFI, - "Activation: (wifi) could not get IP configuration for connection '%s'.", - nm_connection_get_id(connection)); - - if (!handle_auth_or_fail(self, NULL, TRUE)) { - NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_NO_SECRETS); - return NM_ACT_STAGE_RETURN_FAILURE; - } - - _LOGI(LOGD_DEVICE | LOGD_WIFI, "Activation: (wifi) asking for new secrets"); - return NM_ACT_STAGE_RETURN_POSTPONE; - -call_parent: - return NM_DEVICE_CLASS(nm_device_wifi_parent_class) - ->act_stage4_ip_config_timeout(device, addr_family, out_failure_reason); -} - static void activation_success_handler(NMDevice *device) { - NMDeviceWifi * self = NM_DEVICE_WIFI(device); + NMDeviceWifi *self = NM_DEVICE_WIFI(device); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); int ifindex = nm_device_get_ifindex(device); - NMActRequest * req; + NMActRequest *req; req = nm_device_get_act_request(device); g_assert(req); - /* Clear any critical protocol notification in the wifi stack */ - nm_platform_wifi_indicate_addressing_running(nm_device_get_platform(device), ifindex, FALSE); + _indicate_addressing_running_reset(self); /* There should always be a current AP, either a fake one because we haven't * seen a scan result for the activated AP yet, or a real one from the @@ -3439,12 +3385,12 @@ activation_success_handler(NMDevice *device) } static void -device_state_changed(NMDevice * device, +device_state_changed(NMDevice *device, NMDeviceState new_state, NMDeviceState old_state, NMDeviceStateReason reason) { - NMDeviceWifi * self = NM_DEVICE_WIFI(device); + NMDeviceWifi *self = NM_DEVICE_WIFI(device); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); gboolean clear_aps = FALSE; @@ -3484,19 +3430,13 @@ device_state_changed(NMDevice * device, nm_supplicant_interface_disconnect(priv->sup_iface); break; case NM_DEVICE_STATE_IP_CHECK: - /* Clear any critical protocol notification in the wifi stack */ - nm_platform_wifi_indicate_addressing_running(nm_device_get_platform(device), - nm_device_get_ifindex(device), - FALSE); + _indicate_addressing_running_reset(self); break; case NM_DEVICE_STATE_ACTIVATED: activation_success_handler(device); break; case NM_DEVICE_STATE_FAILED: - /* Clear any critical protocol notification in the wifi stack */ - nm_platform_wifi_indicate_addressing_running(nm_device_get_platform(device), - nm_device_get_ifindex(device), - FALSE); + _indicate_addressing_running_reset(self); break; case NM_DEVICE_STATE_DISCONNECTED: break; @@ -3519,7 +3459,7 @@ get_enabled(NMDevice *device) static void set_enabled(NMDevice *device, gboolean enabled) { - NMDeviceWifi * self = NM_DEVICE_WIFI(device); + NMDeviceWifi *self = NM_DEVICE_WIFI(device); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); NMDeviceState state; @@ -3573,19 +3513,19 @@ set_enabled(NMDevice *device, gboolean enabled) static gboolean get_guessed_metered(NMDevice *device) { - NMDeviceWifi * self = NM_DEVICE_WIFI(device); + NMDeviceWifi *self = NM_DEVICE_WIFI(device); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); return priv->current_ap && nm_wifi_ap_get_metered(priv->current_ap); } static gboolean -can_reapply_change(NMDevice * device, +can_reapply_change(NMDevice *device, const char *setting_name, - NMSetting * s_old, - NMSetting * s_new, + NMSetting *s_old, + NMSetting *s_new, GHashTable *diffs, - GError ** error) + GError **error) { NMDeviceClass *device_class; @@ -3623,9 +3563,9 @@ reapply_connection(NMDevice *device, NMConnection *con_old, NMConnection *con_ne static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMDeviceWifi * self = NM_DEVICE_WIFI(object); + NMDeviceWifi *self = NM_DEVICE_WIFI(object); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); - const char ** list; + const char **list; switch (prop_id) { case PROP_MODE: @@ -3664,7 +3604,7 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - NMDeviceWifi * device = NM_DEVICE_WIFI(object); + NMDeviceWifi *device = NM_DEVICE_WIFI(object); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(device); switch (prop_id) { @@ -3699,7 +3639,7 @@ nm_device_wifi_init(NMDeviceWifi *self) static void constructed(GObject *object) { - NMDeviceWifi * self = NM_DEVICE_WIFI(object); + NMDeviceWifi *self = NM_DEVICE_WIFI(object); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); G_OBJECT_CLASS(nm_device_wifi_parent_class)->constructed(object); @@ -3733,7 +3673,7 @@ nm_device_wifi_new(const char *iface, _NMDeviceWifiCapabilities capabilities) static void dispose(GObject *object) { - NMDeviceWifi * self = NM_DEVICE_WIFI(object); + NMDeviceWifi *self = NM_DEVICE_WIFI(object); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); nm_assert(c_list_is_empty(&priv->scanning_prohibited_lst_head)); @@ -3762,7 +3702,7 @@ dispose(GObject *object) static void finalize(GObject *object) { - NMDeviceWifi * self = NM_DEVICE_WIFI(object); + NMDeviceWifi *self = NM_DEVICE_WIFI(object); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); nm_assert(c_list_is_empty(&priv->aps_lst_head)); @@ -3776,9 +3716,9 @@ finalize(GObject *object) static void nm_device_wifi_class_init(NMDeviceWifiClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->constructed = constructed; object_class->get_property = get_property; @@ -3803,17 +3743,16 @@ nm_device_wifi_class_init(NMDeviceWifiClass *klass) device_class->get_guessed_metered = get_guessed_metered; device_class->set_enabled = set_enabled; - device_class->act_stage1_prepare = act_stage1_prepare; - device_class->act_stage2_config = act_stage2_config; - device_class->get_configured_mtu = get_configured_mtu; - device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; - device_class->act_stage4_ip_config_timeout = act_stage4_ip_config_timeout; - device_class->deactivate_async = deactivate_async; - device_class->deactivate = deactivate; - device_class->deactivate_reset_hw_addr = deactivate_reset_hw_addr; - device_class->unmanaged_on_quit = unmanaged_on_quit; - device_class->can_reapply_change = can_reapply_change; - device_class->reapply_connection = reapply_connection; + device_class->act_stage1_prepare = act_stage1_prepare; + device_class->act_stage2_config = act_stage2_config; + device_class->get_configured_mtu = get_configured_mtu; + device_class->act_stage3_ip_config = act_stage3_ip_config; + device_class->deactivate_async = deactivate_async; + device_class->deactivate = deactivate; + device_class->deactivate_reset_hw_addr = deactivate_reset_hw_addr; + device_class->unmanaged_on_quit = unmanaged_on_quit; + device_class->can_reapply_change = can_reapply_change; + device_class->reapply_connection = reapply_connection; device_class->state_changed = device_state_changed; diff --git a/src/core/devices/wifi/nm-device-wifi.h b/src/core/devices/wifi/nm-device-wifi.h index c7ff1a14..3a85192e 100644 --- a/src/core/devices/wifi/nm-device-wifi.h +++ b/src/core/devices/wifi/nm-device-wifi.h @@ -37,8 +37,8 @@ NMDevice *nm_device_wifi_new(const char *iface, _NMDeviceWifiCapabilities capabi const CList *_nm_device_wifi_get_aps(NMDeviceWifi *self); -void _nm_device_wifi_request_scan(NMDeviceWifi * self, - GVariant * options, +void _nm_device_wifi_request_scan(NMDeviceWifi *self, + GVariant *options, GDBusMethodInvocation *invocation); GPtrArray *nmtst_ssids_options_to_ptrarray(GVariant *value, GError **error); diff --git a/src/core/devices/wifi/nm-iwd-manager.c b/src/core/devices/wifi/nm-iwd-manager.c index 56386c57..5563ebf8 100644 --- a/src/core/devices/wifi/nm-iwd-manager.c +++ b/src/core/devices/wifi/nm-iwd-manager.c @@ -15,6 +15,7 @@ #include "libnm-core-intern/nm-core-internal.h" #include "nm-manager.h" #include "nm-device-iwd.h" +#include "nm-device-iwd-p2p.h" #include "nm-wifi-utils.h" #include "libnm-glib-aux/nm-uuid.h" #include "libnm-glib-aux/nm-random-utils.h" @@ -25,30 +26,42 @@ /*****************************************************************************/ +enum { + P2P_DEVICE_ADDED, + + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL]; + typedef struct { - const char * name; + const char *name; NMIwdNetworkSecurity security; char buf[0]; } KnownNetworkId; typedef struct { - GDBusProxy * known_network; + GDBusProxy *known_network; NMSettingsConnection *mirror_connection; const KnownNetworkId *id; } KnownNetworkData; typedef struct { - NMManager * manager; - NMSettings * settings; - GCancellable * cancellable; + NMManager *manager; + NMSettings *settings; + GCancellable *cancellable; gboolean running; GDBusObjectManager *object_manager; guint agent_id; - char * agent_path; - GHashTable * known_networks; - NMDeviceIwd * last_agent_call_device; - char * last_state_dir; - char * warned_state_dir; + char *agent_path; + GHashTable *known_networks; + NMDeviceIwd *last_agent_call_device; + char *last_state_dir; + char *warned_state_dir; + bool netconfig_enabled; + GHashTable *p2p_devices; + NMIwdWfdInfo wfd_info; + guint wfd_use_count; } NMIwdManagerPrivate; struct _NMIwdManager { @@ -98,7 +111,7 @@ G_DEFINE_TYPE(NMIwdManager, nm_iwd_manager, G_TYPE_OBJECT) /*****************************************************************************/ static void mirror_connection_take_and_delete(NMSettingsConnection *sett_conn, - KnownNetworkData * data); + KnownNetworkData *data); /*****************************************************************************/ @@ -146,10 +159,10 @@ get_property_bool(GDBusProxy *proxy, const char *property, gboolean default_val) static NMDeviceIwd * get_device_from_network(NMIwdManager *self, GDBusProxy *network) { - NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); - const char * ifname; - const char * device_path; - NMDevice * device; + NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); + const char *ifname; + const char *device_path; + NMDevice *device; gs_unref_object GDBusInterface *device_obj = NULL; /* Try not to rely on the path of the Device being a prefix of the @@ -182,21 +195,21 @@ get_device_from_network(NMIwdManager *self, GDBusProxy *network) } static void -agent_dbus_method_cb(GDBusConnection * connection, - const char * sender, - const char * object_path, - const char * interface_name, - const char * method_name, - GVariant * parameters, +agent_dbus_method_cb(GDBusConnection *connection, + const char *sender, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data) { - NMIwdManager * self = user_data; - NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); - const char * network_path; - NMDeviceIwd * device; - gs_free char * name_owner = NULL; - gs_unref_object GDBusInterface *network = NULL; + NMIwdManager *self = user_data; + NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); + const char *network_path; + NMDeviceIwd *device; + gs_free char *name_owner = NULL; + gs_unref_object GDBusInterface *network = NULL; /* Be paranoid and check the sender address */ name_owner = g_dbus_object_manager_client_get_name_owner( @@ -315,7 +328,7 @@ static void register_agent(NMIwdManager *self) { NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); - GDBusInterface * agent_manager; + GDBusInterface *agent_manager; agent_manager = g_dbus_object_manager_get_interface(priv->object_manager, "/net/connman/iwd", /* IWD 1.0+ */ @@ -388,9 +401,9 @@ static void set_device_dbus_object(NMIwdManager *self, GDBusProxy *proxy, GDBusObject *object) { NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); - const char * ifname; + const char *ifname; int ifindex; - NMDevice * device; + NMDevice *device; int errsv; ifname = get_property_string_or_null(proxy, "Name"); @@ -419,11 +432,71 @@ set_device_dbus_object(NMIwdManager *self, GDBusProxy *proxy, GDBusObject *objec nm_device_iwd_set_dbus_object(NM_DEVICE_IWD(device), object); } +static void +add_p2p_device(NMIwdManager *self, GDBusProxy *proxy, GDBusObject *object) +{ + NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); + const char *path = g_dbus_object_get_object_path(object); + NMDeviceIwdP2P *p2p; + gs_unref_object GDBusInterface *wiphy = NULL; + const char *phy_name; + + if (g_hash_table_contains(priv->p2p_devices, path)) + return; + + wiphy = g_dbus_object_get_interface(object, NM_IWD_WIPHY_INTERFACE); + if (!wiphy) + return; + + phy_name = get_property_string_or_null(G_DBUS_PROXY(wiphy), "Name"); + if (!phy_name) { + _LOGE("Name not cached for phy at %s", path); + return; + } + + p2p = nm_device_iwd_p2p_new(object); + if (!p2p) { + _LOGE("Can't create NMDeviceIwdP2P for phy at %s", path); + return; + } + + g_hash_table_insert(priv->p2p_devices, g_strdup(path), p2p); + g_signal_emit(self, signals[P2P_DEVICE_ADDED], 0, p2p, phy_name); + + /* There should be no peer objects before the device object appeared so don't + * try to look for them and notify the new device. */ +} + +static void +remove_p2p_device(NMIwdManager *self, GDBusProxy *proxy, GDBusObject *object) +{ + NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); + const char *path = g_dbus_object_get_object_path(object); + NMDeviceIwdP2P *p2p = g_hash_table_lookup(priv->p2p_devices, path); + + if (!p2p) + return; + + g_hash_table_remove(priv->p2p_devices, path); +} + +static NMDeviceIwdP2P * +get_p2p_device_from_peer(NMIwdManager *self, GDBusProxy *proxy) +{ + NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); + const char *device_path = get_property_string_or_null(proxy, "Device"); + + if (!device_path) + return NULL; + + return g_hash_table_lookup(priv->p2p_devices, device_path); +} + static void known_network_update_cb(GObject *source, GAsyncResult *res, gpointer user_data) { gs_unref_variant GVariant *variant = NULL; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; variant = g_dbus_proxy_call_finish(G_DBUS_PROXY(source), res, &error); if (!variant) { @@ -436,13 +509,13 @@ known_network_update_cb(GObject *source, GAsyncResult *res, gpointer user_data) } static gboolean -iwd_config_write(GKeyFile * config, - const char * filepath, +iwd_config_write(GKeyFile *config, + const char *filepath, const struct timespec *mtime, - GError ** error) + GError **error) { gsize length; - gs_free char * data = g_key_file_to_data(config, &length, NULL); + gs_free char *data = g_key_file_to_data(config, &length, NULL); struct timespec times[2] = {{.tv_nsec = UTIME_OMIT}, *mtime}; /* Atomically write or replace the file with the right permission bits @@ -458,7 +531,7 @@ static const char * get_config_path(NMIwdManager *self) { NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); - const char * path; + const char *path; path = nm_config_data_get_iwd_config_path(NM_CONFIG_GET_DATA); if (path && path[0] == '\0') { @@ -489,26 +562,26 @@ get_config_path(NMIwdManager *self) } static void -sett_conn_changed(NMSettingsConnection * sett_conn, +sett_conn_changed(NMSettingsConnection *sett_conn, guint update_reason, const KnownNetworkData *data) { - NMSettingsConnectionIntFlags flags; - NMConnection * conn = nm_settings_connection_get_connection(sett_conn); - NMSettingConnection * s_conn = nm_connection_get_setting_connection(conn); - NMSettingWireless * s_wifi = nm_connection_get_setting_wireless(conn); + NMSettingsConnectionIntFlags flags; + NMConnection *conn = nm_settings_connection_get_connection(sett_conn); + NMSettingConnection *s_conn = nm_connection_get_setting_connection(conn); + NMSettingWireless *s_wifi = nm_connection_get_setting_wireless(conn); nm_auto_unref_keyfile GKeyFile *iwd_config = NULL; - const char * iwd_dir; - gs_free char * filename = NULL; - gs_free char * full_path = NULL; - gs_free_error GError *error = NULL; - NMIwdNetworkSecurity security; - GBytes * ssid; - const guint8 * ssid_data; - gsize ssid_len; - gboolean removed; - GStatBuf statbuf; - gboolean have_mtime; + const char *iwd_dir; + gs_free char *filename = NULL; + gs_free char *full_path = NULL; + gs_free_error GError *error = NULL; + NMIwdNetworkSecurity security; + GBytes *ssid; + const guint8 *ssid_data; + gsize ssid_len; + gboolean removed; + GStatBuf statbuf; + gboolean have_mtime; nm_assert(sett_conn == data->mirror_connection); @@ -660,24 +733,24 @@ sett_conn_changed(NMSettingsConnection * sett_conn, * from the user. */ static NMSettingsConnection * -mirror_connection(NMIwdManager * self, +mirror_connection(NMIwdManager *self, const KnownNetworkId *id, gboolean create_new, - GDBusProxy * known_network) + GDBusProxy *known_network) { - NMIwdManagerPrivate * priv = NM_IWD_MANAGER_GET_PRIVATE(self); - NMSettingsConnection *const *iter; + NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); + NMSettingsConnection *const *iter; gs_unref_object NMConnection *connection = NULL; - NMSettingsConnection * settings_connection = NULL; + NMSettingsConnection *settings_connection = NULL; char uuid[37]; - NMSetting * setting; - gs_free_error GError *error = NULL; - gs_unref_bytes GBytes *new_ssid = NULL; - gsize ssid_len = strlen(id->name); - gboolean autoconnectable = TRUE; - gboolean hidden = FALSE; - gboolean exact_match = TRUE; - const char * key_mgmt = NULL; + NMSetting *setting; + gs_free_error GError *error = NULL; + gs_unref_bytes GBytes *new_ssid = NULL; + gsize ssid_len = strlen(id->name); + gboolean autoconnectable = TRUE; + gboolean hidden = FALSE; + gboolean exact_match = TRUE; + const char *key_mgmt = NULL; if (known_network) { autoconnectable = get_property_bool(known_network, "AutoConnect", TRUE); @@ -686,10 +759,10 @@ mirror_connection(NMIwdManager * self, for (iter = nm_settings_get_connections(priv->settings, NULL); *iter; iter++) { NMSettingsConnection *sett_conn = *iter; - NMConnection * conn = nm_settings_connection_get_connection(sett_conn); + NMConnection *conn = nm_settings_connection_get_connection(sett_conn); NMIwdNetworkSecurity security; - NMSettingWireless * s_wifi; - const guint8 * ssid_bytes; + NMSettingWireless *s_wifi; + const guint8 *ssid_bytes; gsize ssid_len2; if (!nm_wifi_connection_get_iwd_ssid_and_security(conn, NULL, &security)) @@ -770,7 +843,7 @@ mirror_connection(NMIwdManager * self, if (NM_FLAGS_HAS(flags, NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED)) { NMConnection *tmp_conn = nm_settings_connection_get_connection(settings_connection); NMSettingConnection *s_conn = nm_connection_get_setting_connection(tmp_conn); - NMSettingWireless * s_wifi = nm_connection_get_setting_wireless(tmp_conn); + NMSettingWireless *s_wifi = nm_connection_get_setting_wireless(tmp_conn); g_object_set(G_OBJECT(s_conn), NM_SETTING_CONNECTION_AUTOCONNECT, @@ -912,14 +985,14 @@ mirror_connection_take_and_delete(NMSettingsConnection *sett_conn, KnownNetworkD static void interface_added(GDBusObjectManager *object_manager, - GDBusObject * object, - GDBusInterface * interface, + GDBusObject *object, + GDBusInterface *interface, gpointer user_data) { - NMIwdManager * self = user_data; + NMIwdManager *self = user_data; NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); - GDBusProxy * proxy; - const char * iface_name; + GDBusProxy *proxy; + const char *iface_name; if (!priv->running) return; @@ -935,11 +1008,11 @@ interface_added(GDBusObjectManager *object_manager, } if (nm_streq(iface_name, NM_IWD_KNOWN_NETWORK_INTERFACE)) { - KnownNetworkId * id; - KnownNetworkId * orig_id; - KnownNetworkData * data; + KnownNetworkId *id; + KnownNetworkId *orig_id; + KnownNetworkData *data; NMIwdNetworkSecurity security; - const char * type_str, *name; + const char *type_str, *name; NMSettingsConnection *sett_conn = NULL; type_str = get_property_string_or_null(proxy, "Type"); @@ -998,18 +1071,34 @@ interface_added(GDBusObjectManager *object_manager, return; } + + if (nm_streq(iface_name, NM_IWD_P2P_INTERFACE)) { + add_p2p_device(self, proxy, object); + return; + } + + if (nm_streq(iface_name, NM_IWD_P2P_PEER_INTERFACE)) { + NMDeviceIwdP2P *p2p = get_p2p_device_from_peer(self, proxy); + + /* This is more conveniently done with a direct call than a signal because + * this way we only notify the interested NMDeviceIwdP2P. */ + if (p2p) + nm_device_iwd_p2p_peer_add_remove(p2p, object, TRUE); + + return; + } } static void interface_removed(GDBusObjectManager *object_manager, - GDBusObject * object, - GDBusInterface * interface, + GDBusObject *object, + GDBusInterface *interface, gpointer user_data) { - NMIwdManager * self = user_data; + NMIwdManager *self = user_data; NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); - GDBusProxy * proxy; - const char * iface_name; + GDBusProxy *proxy; + const char *iface_name; g_return_if_fail(G_IS_DBUS_PROXY(interface)); @@ -1023,7 +1112,7 @@ interface_removed(GDBusObjectManager *object_manager, if (nm_streq(iface_name, NM_IWD_KNOWN_NETWORK_INTERFACE)) { KnownNetworkId id; - const char * type_str; + const char *type_str; type_str = get_property_string_or_null(proxy, "Type"); id.name = get_property_string_or_null(proxy, "Name"); @@ -1051,6 +1140,20 @@ interface_removed(GDBusObjectManager *object_manager, return; } + + if (nm_streq(iface_name, NM_IWD_P2P_INTERFACE)) { + remove_p2p_device(self, proxy, object); + return; + } + + if (nm_streq(iface_name, NM_IWD_P2P_PEER_INTERFACE)) { + NMDeviceIwdP2P *p2p = get_p2p_device_from_peer(self, proxy); + + if (p2p) + nm_device_iwd_p2p_peer_add_remove(p2p, object, FALSE); + + return; + } } static void @@ -1088,19 +1191,19 @@ object_removed(GDBusObjectManager *object_manager, GDBusObject *object, gpointer static void connection_removed(NMSettings *settings, NMSettingsConnection *sett_conn, gpointer user_data) { - NMIwdManager * self = user_data; - NMIwdManagerPrivate * priv = NM_IWD_MANAGER_GET_PRIVATE(self); - NMConnection * conn = nm_settings_connection_get_connection(sett_conn); - NMSettingWireless * s_wireless; - KnownNetworkData * data; + NMIwdManager *self = user_data; + NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); + NMConnection *conn = nm_settings_connection_get_connection(sett_conn); + NMSettingWireless *s_wireless; + KnownNetworkData *data; KnownNetworkId id; char ssid_buf[33]; - const guint8 * ssid_bytes; + const guint8 *ssid_bytes; gsize ssid_len; NMSettingsConnection *new_mirror_conn; - const char * iwd_dir; - gs_free char * filename = NULL; - gs_free char * full_path = NULL; + const char *iwd_dir; + gs_free char *filename = NULL; + gs_free char *full_path = NULL; if (!nm_wifi_connection_get_iwd_ssid_and_security(conn, NULL, &id.security)) return; @@ -1170,13 +1273,13 @@ try_delete_file: static void connection_added(NMSettings *settings, NMSettingsConnection *sett_conn, gpointer user_data) { - NMIwdManager * self = user_data; - NMConnection * conn = nm_settings_connection_get_connection(sett_conn); - NMSettingConnection *s_conn = nm_connection_get_setting_connection(conn); - const char * iwd_dir; - gs_free char * filename = NULL; - gs_free char * full_path = NULL; - gs_free_error GError *error = NULL; + NMIwdManager *self = user_data; + NMConnection *conn = nm_settings_connection_get_connection(sett_conn); + NMSettingConnection *s_conn = nm_connection_get_setting_connection(conn); + const char *iwd_dir; + gs_free char *filename = NULL; + gs_free char *full_path = NULL; + gs_free_error GError *error = NULL; nm_auto_unref_keyfile GKeyFile *iwd_config = NULL; NMSettingsConnectionIntFlags flags; @@ -1259,7 +1362,7 @@ release_object_manager(NMIwdManager *self) g_signal_handlers_disconnect_by_data(priv->object_manager, self); if (priv->agent_id) { - GDBusConnection * agent_connection; + GDBusConnection *agent_connection; GDBusObjectManagerClient *omc = G_DBUS_OBJECT_MANAGER_CLIENT(priv->object_manager); agent_connection = g_dbus_object_manager_client_get_connection(omc); @@ -1281,9 +1384,9 @@ static void prepare_object_manager(NMIwdManager *self); static void name_owner_changed(GObject *object, GParamSpec *pspec, gpointer user_data) { - NMIwdManager * self = user_data; + NMIwdManager *self = user_data; NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); - GDBusObjectManager * object_manager = G_DBUS_OBJECT_MANAGER(object); + GDBusObjectManager *object_manager = G_DBUS_OBJECT_MANAGER(object); nm_assert(object_manager == priv->object_manager); @@ -1292,7 +1395,7 @@ name_owner_changed(GObject *object, GParamSpec *pspec, gpointer user_data) prepare_object_manager(self); } else { const CList *tmp_lst; - NMDevice * device; + NMDevice *device; if (!priv->running) return; @@ -1310,9 +1413,9 @@ name_owner_changed(GObject *object, GParamSpec *pspec, gpointer user_data) static void device_added(NMManager *manager, NMDevice *device, gpointer user_data) { - NMIwdManager * self = user_data; + NMIwdManager *self = user_data; NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); - GList * objects, *iter; + GList *objects, *iter; if (!NM_IS_DEVICE_IWD(device)) return; @@ -1331,7 +1434,7 @@ device_added(NMManager *manager, NMDevice *device, gpointer user_data) objects = g_dbus_object_manager_get_objects(priv->object_manager); for (iter = objects; iter; iter = iter->next) { - GDBusObject * object = G_DBUS_OBJECT(iter->data); + GDBusObject *object = G_DBUS_OBJECT(iter->data); gs_unref_object GDBusInterface *interface = NULL; interface = g_dbus_object_get_interface(object, NM_IWD_NETWORK_INTERFACE); @@ -1343,9 +1446,9 @@ device_added(NMManager *manager, NMDevice *device, gpointer user_data) } for (iter = objects; iter; iter = iter->next) { - GDBusObject * object = G_DBUS_OBJECT(iter->data); + GDBusObject *object = G_DBUS_OBJECT(iter->data); gs_unref_object GDBusInterface *interface = NULL; - const char * obj_ifname; + const char *obj_ifname; interface = g_dbus_object_get_interface(object, NM_IWD_DEVICE_INTERFACE); obj_ifname = get_property_string_or_null((GDBusProxy *) interface, "Name"); @@ -1363,7 +1466,7 @@ device_added(NMManager *manager, NMDevice *device, gpointer user_data) static void device_removed(NMManager *manager, NMDevice *device, gpointer user_data) { - NMIwdManager * self = user_data; + NMIwdManager *self = user_data; NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); if (!NM_IS_DEVICE_IWD(device)) @@ -1431,13 +1534,13 @@ object_compare_interfaces(gconstpointer a, gconstpointer b) static void get_daemon_info_cb(GObject *source, GAsyncResult *res, gpointer user_data) { - NMIwdManager * self = user_data; - NMIwdManagerPrivate *priv; + NMIwdManager *self = user_data; + NMIwdManagerPrivate *priv; gs_unref_variant GVariant *properties = NULL; - gs_free_error GError *error = NULL; - GVariantIter * properties_iter; - const char * key; - GVariant * value; + gs_free_error GError *error = NULL; + GVariantIter *properties_iter; + const char *key; + GVariant *value; properties = g_dbus_proxy_call_finish(G_DBUS_PROXY(source), res, &error); if (!properties) { @@ -1469,6 +1572,15 @@ get_daemon_info_cb(GObject *source, GAsyncResult *res, gpointer user_data) nm_clear_g_free(&priv->last_state_dir); priv->last_state_dir = g_variant_dup_string(value, NULL); + } else if (nm_streq(key, "NetworkConfigurationEnabled")) { + if (!g_variant_is_of_type(value, G_VARIANT_TYPE_BOOLEAN)) { + _LOGE("Daemon.GetInfo property %s is typed '%s' instead of 'b'", + key, + g_variant_get_type_string(value)); + goto next; + } + + priv->netconfig_enabled = g_variant_get_boolean(value); } next: @@ -1481,11 +1593,11 @@ next: static void got_object_manager(GObject *object, GAsyncResult *result, gpointer user_data) { - NMIwdManager * self = user_data; + NMIwdManager *self = user_data; NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); - GError * error = NULL; - GDBusObjectManager * object_manager; - GDBusConnection * connection; + GError *error = NULL; + GDBusObjectManager *object_manager; + GDBusConnection *connection; object_manager = g_dbus_object_manager_client_new_for_bus_finish(result, &error); if (object_manager == NULL) { @@ -1515,7 +1627,7 @@ got_object_manager(GObject *object, GAsyncResult *result, gpointer user_data) } if (_om_has_name_owner(object_manager)) { - GList * objects, *iter; + GList *objects, *iter; gs_unref_object GDBusInterface *daemon = NULL; priv->running = true; @@ -1543,6 +1655,8 @@ got_object_manager(GObject *object, GAsyncResult *result, gpointer user_data) if (priv->agent_id) register_agent(self); + priv->netconfig_enabled = false; /* Assume false until GetInfo() results come in */ + daemon = g_dbus_object_manager_get_interface(object_manager, "/net/connman/iwd", /* IWD 1.15+ */ NM_IWD_DAEMON_INTERFACE); @@ -1587,11 +1701,11 @@ nm_iwd_manager_is_known_network(NMIwdManager *self, const char *name, NMIwdNetwo NMSettingsConnection * nm_iwd_manager_get_ap_mirror_connection(NMIwdManager *self, NMWifiAP *ap) { - NMIwdManagerPrivate * priv = NM_IWD_MANAGER_GET_PRIVATE(self); - KnownNetworkData * data; + NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); + KnownNetworkData *data; char name_buf[33]; KnownNetworkId kn_id = {name_buf, NM_IWD_NETWORK_SECURITY_OPEN}; - const guint8 * ssid_bytes; + const guint8 *ssid_bytes; gsize ssid_len; NM80211ApFlags flags = nm_wifi_ap_get_flags(ap); NM80211ApSecurityFlags sec_flags = nm_wifi_ap_get_wpa_flags(ap) | nm_wifi_ap_get_rsn_flags(ap); @@ -1629,7 +1743,7 @@ GDBusProxy * nm_iwd_manager_get_dbus_interface(NMIwdManager *self, const char *path, const char *name) { NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); - GDBusInterface * interface; + GDBusInterface *interface; if (!priv->object_manager) return NULL; @@ -1639,6 +1753,121 @@ nm_iwd_manager_get_dbus_interface(NMIwdManager *self, const char *path, const ch return interface ? G_DBUS_PROXY(interface) : NULL; } +gboolean +nm_iwd_manager_get_netconfig_enabled(NMIwdManager *self) +{ + NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); + + return priv->netconfig_enabled; +} + +/* IWD's net.connman.iwd.p2p.ServiceManager.RegisterDisplayService() is global so + * two local Wi-Fi P2P devices can't be connected to (or even scanning for) WFD + * peers using different WFD IE contents, e.g. one as a sink and one as a source. + * If one device is connected to a peer without a WFD service, another can try + * to establish a WFD connection to a peer since this won't disturb the first + * connection. Similarly if one device is connected to a peer with WFD, another + * can make a connection to a non-WFD peer (if that exists...) because a non-WFD + * peer will simply ignore the WFD IEs, but it cannot connect to or search for a + * peer that's WFD capable without passing our own WFD IEs, i.e. if the new + * NMSettingsConnection has no WFD IEs and we're already in a WFD connection on + * another device, we can't activate that new connection. We expose methods + * for the NMDeviceIwdP2P's to register/unregister the service and one to check + * if there's already an incompatible connection active. + */ +gboolean +nm_iwd_manager_check_wfd_info_compatible(NMIwdManager *self, const NMIwdWfdInfo *wfd_info) +{ + NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); + + if (priv->wfd_use_count == 0) + return TRUE; + + return nm_wifi_utils_wfd_info_eq(&priv->wfd_info, wfd_info); +} + +gboolean +nm_iwd_manager_register_wfd(NMIwdManager *self, const NMIwdWfdInfo *wfd_info) +{ + NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); + gs_unref_object GDBusInterface *service_manager = NULL; + GVariantBuilder builder; + + nm_assert(nm_iwd_manager_check_wfd_info_compatible(self, wfd_info)); + + if (!priv->object_manager) + return FALSE; + + service_manager = g_dbus_object_manager_get_interface(priv->object_manager, + "/net/connman/iwd", + NM_IWD_P2P_SERVICE_MANAGER_INTERFACE); + if (!service_manager) { + _LOGE("IWD P2P service manager not found"); + return FALSE; + } + + g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT); + g_variant_builder_add(&builder, "{sv}", "Source", g_variant_new_boolean(wfd_info->source)); + g_variant_builder_add(&builder, "{sv}", "Sink", g_variant_new_boolean(wfd_info->sink)); + + if (wfd_info->source) + g_variant_builder_add(&builder, "{sv}", "Port", g_variant_new_uint16(wfd_info->port)); + + if (wfd_info->sink && wfd_info->has_audio) + g_variant_builder_add(&builder, "{sv}", "HasAudio", g_variant_new_boolean(TRUE)); + + if (wfd_info->has_uibc) + g_variant_builder_add(&builder, "{sv}", "HasUIBC", g_variant_new_boolean(TRUE)); + + if (wfd_info->has_cp) + g_variant_builder_add(&builder, + "{sv}", + "HasContentProtection", + g_variant_new_boolean(TRUE)); + + g_dbus_proxy_call(G_DBUS_PROXY(service_manager), + "RegisterDisplayService", + g_variant_new("(a{sv})", &builder), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + NULL, + NULL); + + memcpy(&priv->wfd_info, wfd_info, sizeof(priv->wfd_info)); + priv->wfd_use_count++; + return TRUE; +} + +void +nm_iwd_manager_unregister_wfd(NMIwdManager *self) +{ + NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); + gs_unref_object GDBusInterface *service_manager = NULL; + + nm_assert(priv->wfd_use_count > 0); + + priv->wfd_use_count--; + + if (!priv->object_manager) + return; + + service_manager = g_dbus_object_manager_get_interface(priv->object_manager, + "/net/connman/iwd", + NM_IWD_P2P_SERVICE_MANAGER_INTERFACE); + if (!service_manager) + return; + + g_dbus_proxy_call(G_DBUS_PROXY(service_manager), + "UnregisterDisplayService", + g_variant_new("()"), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + NULL, + NULL); +} + /*****************************************************************************/ NM_DEFINE_SINGLETON_GETTER(NMIwdManager, nm_iwd_manager_get, NM_TYPE_IWD_MANAGER); @@ -1685,13 +1914,15 @@ nm_iwd_manager_init(NMIwdManager *self) g_free, (GDestroyNotify) known_network_data_free); + priv->p2p_devices = g_hash_table_new_full(nm_str_hash, g_str_equal, g_free, g_object_unref); + prepare_object_manager(self); } static void dispose(GObject *object) { - NMIwdManager * self = (NMIwdManager *) object; + NMIwdManager *self = (NMIwdManager *) object; NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self); release_object_manager(self); @@ -1718,6 +1949,8 @@ dispose(GObject *object) nm_clear_g_free(&priv->last_state_dir); nm_clear_g_free(&priv->warned_state_dir); + g_hash_table_unref(nm_steal_pointer(&priv->p2p_devices)); + G_OBJECT_CLASS(nm_iwd_manager_parent_class)->dispose(object); } @@ -1727,4 +1960,16 @@ nm_iwd_manager_class_init(NMIwdManagerClass *klass) GObjectClass *object_class = G_OBJECT_CLASS(klass); object_class->dispose = dispose; + + signals[P2P_DEVICE_ADDED] = g_signal_new(NM_IWD_MANAGER_P2P_DEVICE_ADDED, + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_LAST, + 0, + NULL, + NULL, + NULL, + G_TYPE_NONE, + 2, + NM_TYPE_DEVICE, + G_TYPE_STRING); } diff --git a/src/core/devices/wifi/nm-iwd-manager.h b/src/core/devices/wifi/nm-iwd-manager.h index e794e661..02cd6bba 100644 --- a/src/core/devices/wifi/nm-iwd-manager.h +++ b/src/core/devices/wifi/nm-iwd-manager.h @@ -13,18 +13,22 @@ #define NM_IWD_BUS_TYPE G_BUS_TYPE_SYSTEM #define NM_IWD_SERVICE "net.connman.iwd" -#define NM_IWD_DAEMON_INTERFACE "net.connman.iwd.Daemon" -#define NM_IWD_AGENT_MANAGER_INTERFACE "net.connman.iwd.AgentManager" -#define NM_IWD_WIPHY_INTERFACE "net.connman.iwd.Adapter" -#define NM_IWD_DEVICE_INTERFACE "net.connman.iwd.Device" -#define NM_IWD_NETWORK_INTERFACE "net.connman.iwd.Network" -#define NM_IWD_AGENT_INTERFACE "net.connman.iwd.Agent" -#define NM_IWD_WSC_INTERFACE "net.connman.iwd.WiFiSimpleConfiguration" -#define NM_IWD_KNOWN_NETWORK_INTERFACE "net.connman.iwd.KnownNetwork" -#define NM_IWD_SIGNAL_AGENT_INTERFACE "net.connman.iwd.SignalLevelAgent" -#define NM_IWD_AP_INTERFACE "net.connman.iwd.AccessPoint" -#define NM_IWD_ADHOC_INTERFACE "net.connman.iwd.AdHoc" -#define NM_IWD_STATION_INTERFACE "net.connman.iwd.Station" +#define NM_IWD_DAEMON_INTERFACE "net.connman.iwd.Daemon" +#define NM_IWD_AGENT_MANAGER_INTERFACE "net.connman.iwd.AgentManager" +#define NM_IWD_WIPHY_INTERFACE "net.connman.iwd.Adapter" +#define NM_IWD_DEVICE_INTERFACE "net.connman.iwd.Device" +#define NM_IWD_NETWORK_INTERFACE "net.connman.iwd.Network" +#define NM_IWD_AGENT_INTERFACE "net.connman.iwd.Agent" +#define NM_IWD_WSC_INTERFACE "net.connman.iwd.SimpleConfiguration" +#define NM_IWD_KNOWN_NETWORK_INTERFACE "net.connman.iwd.KnownNetwork" +#define NM_IWD_SIGNAL_AGENT_INTERFACE "net.connman.iwd.SignalLevelAgent" +#define NM_IWD_AP_INTERFACE "net.connman.iwd.AccessPoint" +#define NM_IWD_ADHOC_INTERFACE "net.connman.iwd.AdHoc" +#define NM_IWD_STATION_INTERFACE "net.connman.iwd.Station" +#define NM_IWD_P2P_INTERFACE "net.connman.iwd.p2p.Device" +#define NM_IWD_P2P_PEER_INTERFACE "net.connman.iwd.p2p.Peer" +#define NM_IWD_P2P_SERVICE_MANAGER_INTERFACE "net.connman.iwd.p2p.ServiceManager" +#define NM_IWD_P2P_WFD_INTERFACE "net.connman.iwd.p2p.Display" #define NM_TYPE_IWD_MANAGER (nm_iwd_manager_get_type()) #define NM_IWD_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_IWD_MANAGER, NMIwdManager)) @@ -35,6 +39,8 @@ #define NM_IWD_MANAGER_GET_CLASS(obj) \ (G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_IWD_MANAGER, NMIwdManagerClass)) +#define NM_IWD_MANAGER_P2P_DEVICE_ADDED "p2p-device-added" + typedef struct _NMIwdManager NMIwdManager; typedef struct _NMIwdManagerClass NMIwdManagerClass; @@ -42,8 +48,8 @@ GType nm_iwd_manager_get_type(void); NMIwdManager *nm_iwd_manager_get(void); -gboolean nm_iwd_manager_is_known_network(NMIwdManager * self, - const char * name, +gboolean nm_iwd_manager_is_known_network(NMIwdManager *self, + const char *name, NMIwdNetworkSecurity security); NMSettingsConnection *nm_iwd_manager_get_ap_mirror_connection(NMIwdManager *self, NMWifiAP *ap); @@ -51,4 +57,10 @@ NMSettingsConnection *nm_iwd_manager_get_ap_mirror_connection(NMIwdManager *self GDBusProxy * nm_iwd_manager_get_dbus_interface(NMIwdManager *self, const char *path, const char *name); +gboolean nm_iwd_manager_get_netconfig_enabled(NMIwdManager *self); + +gboolean nm_iwd_manager_check_wfd_info_compatible(NMIwdManager *self, const NMIwdWfdInfo *wfd_info); +gboolean nm_iwd_manager_register_wfd(NMIwdManager *self, const NMIwdWfdInfo *wfd_info); +void nm_iwd_manager_unregister_wfd(NMIwdManager *self); + #endif /* __NETWORKMANAGER_IWD_MANAGER_H__ */ diff --git a/src/core/devices/wifi/nm-wifi-ap.c b/src/core/devices/wifi/nm-wifi-ap.c index 72a60885..ac0b748a 100644 --- a/src/core/devices/wifi/nm-wifi-ap.c +++ b/src/core/devices/wifi/nm-wifi-ap.c @@ -41,8 +41,8 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMWifiAP, struct _NMWifiAPPrivate { /* Scanned or cached values */ - GBytes * ssid; - char * address; + GBytes *ssid; + char *address; _NM80211Mode mode; guint8 strength; guint32 freq; /* Frequency in MHz; ie 2412 (== 2.412 GHz) */ @@ -430,7 +430,7 @@ has_proto(NMSettingWirelessSecurity *sec, const char *proto) static void add_pair_ciphers(NMWifiAP *ap, NMSettingWirelessSecurity *sec) { - NMWifiAPPrivate * priv = NM_WIFI_AP_GET_PRIVATE(ap); + NMWifiAPPrivate *priv = NM_WIFI_AP_GET_PRIVATE(ap); guint32 num = nm_setting_wireless_security_get_num_pairwise(sec); NM80211ApSecurityFlags flags = NM_802_11_AP_SEC_NONE; guint32 i; @@ -458,7 +458,7 @@ add_pair_ciphers(NMWifiAP *ap, NMSettingWirelessSecurity *sec) static void add_group_ciphers(NMWifiAP *ap, NMSettingWirelessSecurity *sec) { - NMWifiAPPrivate * priv = NM_WIFI_AP_GET_PRIVATE(ap); + NMWifiAPPrivate *priv = NM_WIFI_AP_GET_PRIVATE(ap); guint32 num = nm_setting_wireless_security_get_num_groups(sec); NM80211ApSecurityFlags flags = NM_802_11_AP_SEC_NONE; guint32 i; @@ -491,10 +491,10 @@ const char * nm_wifi_ap_to_string(const NMWifiAP *self, char *str_buf, gulong buf_len, gint64 now_msec) { const NMWifiAPPrivate *priv; - const char * supplicant_id = "-"; - const char * export_path; + const char *supplicant_id = "-"; + const char *export_path; guint32 chan; - gs_free char * ssid_to_free = NULL; + gs_free char *ssid_to_free = NULL; char str_buf_ts[100]; g_return_val_if_fail(NM_IS_WIFI_AP(self), NULL); @@ -558,13 +558,13 @@ freq_to_band(guint32 freq) gboolean nm_wifi_ap_check_compatible(NMWifiAP *self, NMConnection *connection) { - NMWifiAPPrivate * priv; - NMSettingWireless * s_wireless; + NMWifiAPPrivate *priv; + NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wireless_sec; - GBytes * ssid; - const char * mode; - const char * band; - const char * bssid; + GBytes *ssid; + const char *mode; + const char *band; + const char *bssid; guint32 channel; g_return_val_if_fail(NM_IS_WIFI_AP(self), FALSE); @@ -629,10 +629,10 @@ nm_wifi_ap_check_compatible(NMWifiAP *self, NMConnection *connection) } gboolean -nm_wifi_ap_complete_connection(NMWifiAP * self, +nm_wifi_ap_complete_connection(NMWifiAP *self, NMConnection *connection, gboolean lock_bssid, - GError ** error) + GError **error) { NMWifiAPPrivate *priv = NM_WIFI_AP_GET_PRIVATE(self); @@ -655,7 +655,7 @@ nm_wifi_ap_complete_connection(NMWifiAP * self, static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMWifiAP * self = NM_WIFI_AP(object); + NMWifiAP *self = NM_WIFI_AP(object); NMWifiAPPrivate *priv = NM_WIFI_AP_GET_PRIVATE(self); switch (prop_id) { @@ -734,11 +734,11 @@ nm_wifi_ap_new_from_properties(const NMSupplicantBssInfo *bss_info) NMWifiAP * nm_wifi_ap_new_fake_from_connection(NMConnection *connection) { - NMWifiAP * ap; - NMWifiAPPrivate * priv; - NMSettingWireless * s_wireless; + NMWifiAP *ap; + NMWifiAPPrivate *priv; + NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wireless_sec; - const char * mode, *band, *key_mgmt; + const char *mode, *band, *key_mgmt; guint32 channel; NM80211ApSecurityFlags flags; gboolean psk = FALSE, eap = FALSE, adhoc = FALSE; @@ -845,7 +845,7 @@ error: static void finalize(GObject *object) { - NMWifiAP * self = NM_WIFI_AP(object); + NMWifiAP *self = NM_WIFI_AP(object); NMWifiAPPrivate *priv = NM_WIFI_AP_GET_PRIVATE(self); nm_assert(!self->wifi_device); @@ -890,7 +890,7 @@ nm_wifi_ap_class_init(NMWifiAPClass *ap_class) | NM_802_11_AP_SEC_KEY_MGMT_SAE | NM_802_11_AP_SEC_KEY_MGMT_OWE \ | NM_802_11_AP_SEC_KEY_MGMT_OWE_TM | NM_802_11_AP_SEC_KEY_MGMT_EAP_SUITE_B_192) - GObjectClass * object_class = G_OBJECT_CLASS(ap_class); + GObjectClass *object_class = G_OBJECT_CLASS(ap_class); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(ap_class); g_type_class_add_private(object_class, sizeof(NMWifiAPPrivate)); @@ -987,10 +987,10 @@ nm_wifi_ap_class_init(NMWifiAPClass *ap_class) const char ** nm_wifi_aps_get_paths(const CList *aps_lst_head, gboolean include_without_ssid) { - NMWifiAP * ap; + NMWifiAP *ap; gsize i, n; const char **list; - const char * path; + const char *path; n = c_list_length(aps_lst_head); list = g_new(const char *, n + 1); diff --git a/src/core/devices/wifi/nm-wifi-ap.h b/src/core/devices/wifi/nm-wifi-ap.h index bffd28a8..c0422900 100644 --- a/src/core/devices/wifi/nm-wifi-ap.h +++ b/src/core/devices/wifi/nm-wifi-ap.h @@ -32,9 +32,9 @@ typedef struct { NMDBusObject parent; - NMDevice * wifi_device; + NMDevice *wifi_device; CList aps_lst; - NMRefString * _supplicant_path; + NMRefString *_supplicant_path; struct _NMWifiAPPrivate *_priv; } NMWifiAP; @@ -47,15 +47,15 @@ GType nm_wifi_ap_get_type(void); NMWifiAP *nm_wifi_ap_new_from_properties(const struct _NMSupplicantBssInfo *bss_info); NMWifiAP *nm_wifi_ap_new_fake_from_connection(NMConnection *connection); -gboolean nm_wifi_ap_update_from_properties(NMWifiAP * ap, +gboolean nm_wifi_ap_update_from_properties(NMWifiAP *ap, const struct _NMSupplicantBssInfo *bss_info); gboolean nm_wifi_ap_check_compatible(NMWifiAP *self, NMConnection *connection); -gboolean nm_wifi_ap_complete_connection(NMWifiAP * self, +gboolean nm_wifi_ap_complete_connection(NMWifiAP *self, NMConnection *connection, gboolean lock_bssid, - GError ** error); + GError **error); static inline NMRefString * nm_wifi_ap_get_supplicant_path(NMWifiAP *ap) @@ -65,9 +65,9 @@ nm_wifi_ap_get_supplicant_path(NMWifiAP *ap) return ap->_supplicant_path; } -GBytes * nm_wifi_ap_get_ssid(const NMWifiAP *ap); +GBytes *nm_wifi_ap_get_ssid(const NMWifiAP *ap); gboolean nm_wifi_ap_set_ssid(NMWifiAP *ap, GBytes *ssid); -const char * nm_wifi_ap_get_address(const NMWifiAP *ap); +const char *nm_wifi_ap_get_address(const NMWifiAP *ap); gboolean nm_wifi_ap_set_address(NMWifiAP *ap, const char *addr); gboolean nm_wifi_ap_set_address_bin(NMWifiAP *ap, const NMEtherAddr *addr); _NM80211Mode nm_wifi_ap_get_mode(NMWifiAP *ap); diff --git a/src/core/devices/wifi/nm-wifi-common.c b/src/core/devices/wifi/nm-wifi-common.c index d029ce7f..681d9cb5 100644 --- a/src/core/devices/wifi/nm-wifi-common.c +++ b/src/core/devices/wifi/nm-wifi-common.c @@ -56,17 +56,17 @@ _dispatch_request_scan(NMDevice *device, GVariant *options, GDBusMethodInvocatio } static void -impl_device_wifi_get_access_points(NMDBusObject * obj, +impl_device_wifi_get_access_points(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { gs_free const char **list = NULL; - GVariant * v; - const CList * all_aps; + GVariant *v; + const CList *all_aps; /* NOTE: this handler is called both for NMDevicwWifi and NMDeviceIwd. */ @@ -77,17 +77,17 @@ impl_device_wifi_get_access_points(NMDBusObject * obj, } static void -impl_device_wifi_get_all_access_points(NMDBusObject * obj, +impl_device_wifi_get_all_access_points(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { gs_free const char **list = NULL; - GVariant * v; - const CList * all_aps; + GVariant *v; + const CList *all_aps; /* NOTE: this handler is called both for NMDevicwWifi and NMDeviceIwd. */ @@ -98,13 +98,13 @@ impl_device_wifi_get_all_access_points(NMDBusObject * obj, } static void -impl_device_wifi_request_scan(NMDBusObject * obj, +impl_device_wifi_request_scan(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { gs_unref_variant GVariant *options = NULL; diff --git a/src/core/devices/wifi/nm-wifi-factory.c b/src/core/devices/wifi/nm-wifi-factory.c index d2269c74..5e354c6b 100644 --- a/src/core/devices/wifi/nm-wifi-factory.c +++ b/src/core/devices/wifi/nm-wifi-factory.c @@ -14,6 +14,8 @@ #include "nm-device-wifi-p2p.h" #include "nm-device-olpc-mesh.h" #include "nm-device-iwd.h" +#include "nm-device-iwd-p2p.h" +#include "nm-iwd-manager.h" #include "settings/nm-settings-connection.h" #include "libnm-platform/nm-platform.h" #include "nm-config.h" @@ -50,7 +52,7 @@ NM_DEVICE_FACTORY_DECLARE_TYPES( NM_SETTING_OLPC_MESH_SETTING_NAME)) G_MODULE_EXPORT NMDeviceFactory * - nm_device_factory_create(GError **error) +nm_device_factory_create(GError **error) { return g_object_new(NM_TYPE_WIFI_FACTORY, NULL); } @@ -67,15 +69,29 @@ p2p_device_created(NMDeviceWifi *device, NMDeviceWifiP2P *p2p_device, NMDeviceFa g_signal_emit_by_name(self, NM_DEVICE_FACTORY_DEVICE_ADDED, p2p_device); } +#if WITH_IWD +static void +iwd_p2p_device_added(NMIwdManager *iwd, + NMDeviceIwdP2P *p2p_device, + const char *phy_name, + NMDeviceFactory *self) +{ + nm_log_info(LOGD_PLATFORM | LOGD_WIFI, "Wi-Fi P2P device added on %s", phy_name); + + g_signal_emit_by_name(self, NM_DEVICE_FACTORY_DEVICE_ADDED, p2p_device); +} +#endif + static NMDevice * -create_device(NMDeviceFactory * factory, - const char * iface, +create_device(NMDeviceFactory *factory, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore) + NMConnection *connection, + gboolean *out_ignore) { gs_free char *backend_free = NULL; - const char * backend; + const char *backend; + _NM80211Mode mode; g_return_val_if_fail(iface != NULL, NULL); g_return_val_if_fail(plink != NULL, NULL); @@ -85,6 +101,20 @@ create_device(NMDeviceFactory * factory, if (plink->type != NM_LINK_TYPE_WIFI) return nm_device_olpc_mesh_new(iface); + /* Ignore monitor-mode and other unhandled interface types. + * FIXME: keep TYPE_MONITOR devices in UNAVAILABLE state and manage + * them if/when they change to a handled type. + */ + mode = nm_platform_wifi_get_mode(NM_PLATFORM_GET, plink->ifindex); + if (!NM_IN_SET(mode, + _NM_802_11_MODE_INFRA, + _NM_802_11_MODE_ADHOC, + _NM_802_11_MODE_AP, + _NM_802_11_MODE_MESH)) { + *out_ignore = TRUE; + return NULL; + } + backend = nm_config_data_get_device_config_by_pllink(NM_CONFIG_GET_DATA, NM_CONFIG_KEYFILE_KEY_DEVICE_WIFI_BACKEND, plink, @@ -92,15 +122,17 @@ create_device(NMDeviceFactory * factory, NULL); backend = nm_strstrip_avoid_copy_a(300, backend, &backend_free); + if (!backend) + backend = "" NM_CONFIG_DEFAULT_WIFI_BACKEND; + nm_log_dbg(LOGD_PLATFORM | LOGD_WIFI, "(%s) config: backend is %s%s%s%s", iface, NM_PRINT_FMT_QUOTE_STRING(backend), WITH_IWD ? " (iwd support enabled)" : ""); - if (!backend || !g_ascii_strcasecmp(backend, "wpa_supplicant")) { - NMDevice * device; + if (!g_ascii_strcasecmp(backend, "wpa_supplicant")) { + NMDevice *device; _NMDeviceWifiCapabilities capabilities; - _NM80211Mode mode; if (!nm_platform_wifi_get_capabilities(NM_PLATFORM_GET, plink->ifindex, &capabilities)) { nm_log_warn(LOGD_PLATFORM | LOGD_WIFI, @@ -110,16 +142,6 @@ create_device(NMDeviceFactory * factory, return NULL; } - /* Ignore monitor-mode and other unhandled interface types. - * FIXME: keep TYPE_MONITOR devices in UNAVAILABLE state and manage - * them if/when they change to a handled type. - */ - mode = nm_platform_wifi_get_mode(NM_PLATFORM_GET, plink->ifindex); - if (mode == _NM_802_11_MODE_UNKNOWN) { - *out_ignore = TRUE; - return NULL; - } - device = nm_device_wifi_new(iface, capabilities); g_signal_connect_object(device, @@ -131,8 +153,23 @@ create_device(NMDeviceFactory * factory, return device; } #if WITH_IWD - else if (!g_ascii_strcasecmp(backend, "iwd")) + else if (!g_ascii_strcasecmp(backend, "iwd")) { + NMIwdManager *iwd = nm_iwd_manager_get(); + + if (!g_signal_handler_find(iwd, + G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, + 0, + 0, + NULL, + G_CALLBACK(iwd_p2p_device_added), + factory)) + g_signal_connect(iwd, + NM_IWD_MANAGER_P2P_DEVICE_ADDED, + G_CALLBACK(iwd_p2p_device_added), + factory); + return nm_device_iwd_new(iface); + } #endif nm_log_warn(LOGD_PLATFORM | LOGD_WIFI, diff --git a/src/core/devices/wifi/nm-wifi-p2p-peer.c b/src/core/devices/wifi/nm-wifi-p2p-peer.c index ac13952d..0a174270 100644 --- a/src/core/devices/wifi/nm-wifi-p2p-peer.c +++ b/src/core/devices/wifi/nm-wifi-p2p-peer.c @@ -18,6 +18,7 @@ #include "nm-setting-wireless.h" #include "nm-utils.h" #include "nm-wifi-utils.h" +#include "nm-iwd-manager.h" #include "libnm-platform/nm-platform.h" #include "supplicant/nm-supplicant-types.h" @@ -77,8 +78,8 @@ const char ** nm_wifi_p2p_peers_get_paths(const CList *peers_lst_head) { NMWifiP2PPeer *peer; - const char ** list; - const char * path; + const char **list; + const char *path; gsize i, n; n = c_list_length(peers_lst_head); @@ -100,14 +101,16 @@ nm_wifi_p2p_peers_get_paths(const CList *peers_lst_head) } NMWifiP2PPeer * -nm_wifi_p2p_peers_find_first_compatible(const CList *peers_lst_head, NMConnection *connection) +nm_wifi_p2p_peers_find_first_compatible(const CList *peers_lst_head, + NMConnection *connection, + gboolean check_wfd) { NMWifiP2PPeer *peer; g_return_val_if_fail(connection, NULL); c_list_for_each_entry (peer, peers_lst_head, peers_lst) { - if (nm_wifi_p2p_peer_check_compatible(peer, connection)) + if (nm_wifi_p2p_peer_check_compatible(peer, connection, check_wfd)) return peer; } return NULL; @@ -261,7 +264,7 @@ nm_wifi_p2p_peer_get_wfd_ies(const NMWifiP2PPeer *peer) gboolean nm_wifi_p2p_peer_set_wfd_ies(NMWifiP2PPeer *peer, GBytes *wfd_ies) { - NMWifiP2PPeerPrivate *priv; + NMWifiP2PPeerPrivate *priv; gs_unref_bytes GBytes *wfd_ies_old = NULL; g_return_val_if_fail(NM_IS_WIFI_P2P_PEER(peer), FALSE); @@ -419,12 +422,96 @@ nm_wifi_p2p_peer_update_from_properties(NMWifiP2PPeer *peer, const NMSupplicantP return changed; } +gboolean +nm_wifi_p2p_peer_update_from_iwd_object(NMWifiP2PPeer *peer, GDBusObject *obj) +{ + NMWifiP2PPeerPrivate *priv; + gboolean changed = FALSE; + nm_auto_ref_string NMRefString *peer_path = NULL; + gs_unref_object GDBusProxy *peer_proxy = NULL; + gs_unref_object GDBusProxy *wfd_proxy = NULL; + GVariant *value; + gs_unref_bytes GBytes *wfd_ies = NULL; + + g_return_val_if_fail(NM_IS_WIFI_P2P_PEER(peer), FALSE); + + peer_proxy = G_DBUS_PROXY(g_dbus_object_get_interface(obj, NM_IWD_P2P_PEER_INTERFACE)); + wfd_proxy = G_DBUS_PROXY(g_dbus_object_get_interface(obj, NM_IWD_P2P_WFD_INTERFACE)); + g_return_val_if_fail(peer_proxy, FALSE); + + peer_path = nm_ref_string_new(g_dbus_object_get_object_path(obj)); + priv = NM_WIFI_P2P_PEER_GET_PRIVATE(peer); + nm_assert(!priv->supplicant_path || priv->supplicant_path == peer_path); + + g_object_freeze_notify(G_OBJECT(peer)); + + if (!priv->supplicant_path) { + priv->supplicant_path = g_steal_pointer(&peer_path); + changed = TRUE; + } + + value = g_dbus_proxy_get_cached_property(peer_proxy, "Name"); + if (value && g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) + changed |= nm_wifi_p2p_peer_set_name(peer, g_variant_get_string(value, NULL)); + else + changed |= nm_wifi_p2p_peer_set_name(peer, ""); + nm_g_variant_unref(value); + + value = g_dbus_proxy_get_cached_property(peer_proxy, "Address"); + if (value && g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) + changed |= nm_wifi_p2p_peer_set_address(peer, g_variant_get_string(value, NULL)); + nm_g_variant_unref(value); + + if (wfd_proxy) { + NMIwdWfdInfo wfd = {}; + + value = g_dbus_proxy_get_cached_property(wfd_proxy, "Source"); + wfd.source = value && g_variant_is_of_type(value, G_VARIANT_TYPE_BOOLEAN) + && g_variant_get_boolean(value); + nm_g_variant_unref(value); + + value = g_dbus_proxy_get_cached_property(wfd_proxy, "Sink"); + wfd.sink = value && g_variant_is_of_type(value, G_VARIANT_TYPE_BOOLEAN) + && g_variant_get_boolean(value); + nm_g_variant_unref(value); + + value = g_dbus_proxy_get_cached_property(wfd_proxy, "Port"); + wfd.port = (value && g_variant_is_of_type(value, G_VARIANT_TYPE_UINT16)) + ? g_variant_get_uint16(value) + : 0; + nm_g_variant_unref(value); + + value = g_dbus_proxy_get_cached_property(wfd_proxy, "HasAudio"); + wfd.has_audio = value && g_variant_is_of_type(value, G_VARIANT_TYPE_BOOLEAN) + && g_variant_get_boolean(value); + nm_g_variant_unref(value); + + value = g_dbus_proxy_get_cached_property(wfd_proxy, "HasUIBC"); + wfd.has_uibc = value && g_variant_is_of_type(value, G_VARIANT_TYPE_BOOLEAN) + && g_variant_get_boolean(value); + nm_g_variant_unref(value); + + value = g_dbus_proxy_get_cached_property(wfd_proxy, "HasContentProtection"); + wfd.has_cp = value && g_variant_is_of_type(value, G_VARIANT_TYPE_BOOLEAN) + && g_variant_get_boolean(value); + nm_g_variant_unref(value); + + wfd_ies = nm_wifi_utils_build_wfd_ies(&wfd); + } + + changed |= nm_wifi_p2p_peer_set_wfd_ies(peer, wfd_ies); + + g_object_thaw_notify(G_OBJECT(peer)); + + return changed; +} + const char * nm_wifi_p2p_peer_to_string(const NMWifiP2PPeer *self, char *str_buf, gsize buf_len, gint32 now_s) { const NMWifiP2PPeerPrivate *priv; - const char * supplicant_id = "-"; - const char * export_path; + const char *supplicant_id = "-"; + const char *export_path; g_return_val_if_fail(NM_IS_WIFI_P2P_PEER(self), NULL); @@ -458,11 +545,11 @@ nm_wifi_p2p_peer_to_string(const NMWifiP2PPeer *self, char *str_buf, gsize buf_l } gboolean -nm_wifi_p2p_peer_check_compatible(NMWifiP2PPeer *self, NMConnection *connection) +nm_wifi_p2p_peer_check_compatible(NMWifiP2PPeer *self, NMConnection *connection, gboolean check_wfd) { NMWifiP2PPeerPrivate *priv; - NMSettingWifiP2P * s_wifi_p2p; - const char * hwaddr; + NMSettingWifiP2P *s_wifi_p2p; + const char *hwaddr; g_return_val_if_fail(NM_IS_WIFI_P2P_PEER(self), FALSE); g_return_val_if_fail(NM_IS_CONNECTION(connection), FALSE); @@ -478,6 +565,10 @@ nm_wifi_p2p_peer_check_compatible(NMWifiP2PPeer *self, NMConnection *connection) if (hwaddr && (!priv->address || !nm_utils_hwaddr_matches(hwaddr, -1, priv->address, -1))) return FALSE; + if (check_wfd && nm_setting_wifi_p2p_get_wfd_ies(s_wifi_p2p) + && !nm_wifi_p2p_peer_get_wfd_ies(self)) + return FALSE; + return TRUE; } @@ -486,7 +577,7 @@ nm_wifi_p2p_peer_check_compatible(NMWifiP2PPeer *self, NMConnection *connection) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMWifiP2PPeer * self = NM_WIFI_P2P_PEER(object); + NMWifiP2PPeer *self = NM_WIFI_P2P_PEER(object); NMWifiP2PPeerPrivate *priv = NM_WIFI_P2P_PEER_GET_PRIVATE(self); switch (prop_id) { @@ -559,10 +650,21 @@ nm_wifi_p2p_peer_new_from_properties(const NMSupplicantPeerInfo *peer_info) return peer; } +NMWifiP2PPeer * +nm_wifi_p2p_peer_new_from_iwd_object(GDBusObject *obj) +{ + NMWifiP2PPeer *peer; + + /* TODO: Set the flags here */ + peer = g_object_new(NM_TYPE_WIFI_P2P_PEER, NULL); + nm_wifi_p2p_peer_update_from_iwd_object(peer, obj); + return peer; +} + static void finalize(GObject *object) { - NMWifiP2PPeer * self = NM_WIFI_P2P_PEER(object); + NMWifiP2PPeer *self = NM_WIFI_P2P_PEER(object); NMWifiP2PPeerPrivate *priv = NM_WIFI_P2P_PEER_GET_PRIVATE(self); nm_assert(!self->wifi_device); @@ -613,7 +715,7 @@ static const NMDBusInterfaceInfoExtended interface_info_p2p_peer = { static void nm_wifi_p2p_peer_class_init(NMWifiP2PPeerClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); g_type_class_add_private(object_class, sizeof(NMWifiP2PPeerPrivate)); diff --git a/src/core/devices/wifi/nm-wifi-p2p-peer.h b/src/core/devices/wifi/nm-wifi-p2p-peer.h index ee4bfb53..5124d1de 100644 --- a/src/core/devices/wifi/nm-wifi-p2p-peer.h +++ b/src/core/devices/wifi/nm-wifi-p2p-peer.h @@ -33,7 +33,7 @@ typedef struct { NMDBusObject parent; - NMDevice * wifi_device; + NMDevice *wifi_device; CList peers_lst; struct _NMWifiP2PPeerPrivate *_priv; } NMWifiP2PPeer; @@ -45,11 +45,15 @@ struct _NMSupplicantPeerInfo; GType nm_wifi_p2p_peer_get_type(void); NMWifiP2PPeer *nm_wifi_p2p_peer_new_from_properties(const struct _NMSupplicantPeerInfo *peer_info); +NMWifiP2PPeer *nm_wifi_p2p_peer_new_from_iwd_object(GDBusObject *obj); -gboolean nm_wifi_p2p_peer_update_from_properties(NMWifiP2PPeer * peer, +gboolean nm_wifi_p2p_peer_update_from_properties(NMWifiP2PPeer *peer, const struct _NMSupplicantPeerInfo *peer_info); +gboolean nm_wifi_p2p_peer_update_from_iwd_object(NMWifiP2PPeer *peer, GDBusObject *obj); -gboolean nm_wifi_p2p_peer_check_compatible(NMWifiP2PPeer *self, NMConnection *connection); +gboolean nm_wifi_p2p_peer_check_compatible(NMWifiP2PPeer *self, + NMConnection *connection, + gboolean check_wfd); const char *nm_wifi_p2p_peer_get_supplicant_path(NMWifiP2PPeer *peer); @@ -64,12 +68,12 @@ gboolean nm_wifi_p2p_peer_set_model_number(NMWifiP2PPeer *peer, const char *n const char *nm_wifi_p2p_peer_get_serial(const NMWifiP2PPeer *peer); gboolean nm_wifi_p2p_peer_set_serial(NMWifiP2PPeer *peer, const char *serial); -GBytes * nm_wifi_p2p_peer_get_wfd_ies(const NMWifiP2PPeer *peer); +GBytes *nm_wifi_p2p_peer_get_wfd_ies(const NMWifiP2PPeer *peer); gboolean nm_wifi_p2p_peer_set_wfd_ies(NMWifiP2PPeer *peer, GBytes *bytes); const char *const *nm_wifi_p2p_peer_get_groups(const NMWifiP2PPeer *peer); -const char * nm_wifi_p2p_peer_get_address(const NMWifiP2PPeer *peer); +const char *nm_wifi_p2p_peer_get_address(const NMWifiP2PPeer *peer); gboolean nm_wifi_p2p_peer_set_address(NMWifiP2PPeer *peer, const char *addr); gint8 nm_wifi_p2p_peer_get_strength(NMWifiP2PPeer *peer); gboolean nm_wifi_p2p_peer_set_strength(NMWifiP2PPeer *peer, gint8 strength); @@ -80,11 +84,12 @@ nm_wifi_p2p_peer_to_string(const NMWifiP2PPeer *self, char *str_buf, gsize buf_l const char **nm_wifi_p2p_peers_get_paths(const CList *peers_lst_head); -NMWifiP2PPeer *nm_wifi_p2p_peers_find_first_compatible(const CList * peers_lst_head, - NMConnection *connection); +NMWifiP2PPeer *nm_wifi_p2p_peers_find_first_compatible(const CList *peers_lst_head, + NMConnection *connection, + gboolean check_wfd); NMWifiP2PPeer *nm_wifi_p2p_peers_find_by_supplicant_path(const CList *peers_lst_head, - const char * path); + const char *path); NMWifiP2PPeer *nm_wifi_p2p_peer_lookup_for_device(NMDevice *device, const char *exported_path); diff --git a/src/core/devices/wifi/nm-wifi-utils.c b/src/core/devices/wifi/nm-wifi-utils.c index 4939e786..1a8204b0 100644 --- a/src/core/devices/wifi/nm-wifi-utils.c +++ b/src/core/devices/wifi/nm-wifi-utils.c @@ -41,9 +41,9 @@ verify_no_wep(NMSettingWirelessSecurity *s_wsec, const char *tag, GError **error static gboolean verify_leap(NMSettingWirelessSecurity *s_wsec, - NMSetting8021x * s_8021x, + NMSetting8021x *s_8021x, gboolean adhoc, - GError ** error) + GError **error) { const char *key_mgmt, *auth_alg, *leap_username; @@ -224,9 +224,9 @@ verify_no_wpa(NMSettingWirelessSecurity *s_wsec, const char *tag, GError **error static gboolean verify_dynamic_wep(NMSettingWirelessSecurity *s_wsec, - NMSetting8021x * s_8021x, + NMSetting8021x *s_8021x, gboolean adhoc, - GError ** error) + GError **error) { const char *key_mgmt, *auth_alg, *leap_username; @@ -303,11 +303,11 @@ verify_dynamic_wep(NMSettingWirelessSecurity *s_wsec, static gboolean verify_wpa_psk(NMSettingWirelessSecurity *s_wsec, - NMSetting8021x * s_8021x, + NMSetting8021x *s_8021x, gboolean adhoc, guint32 wpa_flags, guint32 rsn_flags, - GError ** error) + GError **error) { const char *key_mgmt, *auth_alg; @@ -400,10 +400,10 @@ verify_wpa_psk(NMSettingWirelessSecurity *s_wsec, static gboolean verify_wpa_eap(NMSettingWirelessSecurity *s_wsec, - NMSetting8021x * s_8021x, + NMSetting8021x *s_8021x, guint32 wpa_flags, guint32 rsn_flags, - GError ** error) + GError **error) { const char *key_mgmt, *auth_alg; gboolean is_wpa_eap = FALSE; @@ -465,9 +465,9 @@ verify_wpa_eap(NMSettingWirelessSecurity *s_wsec, static gboolean verify_adhoc(NMSettingWirelessSecurity *s_wsec, - NMSetting8021x * s_8021x, + NMSetting8021x *s_8021x, gboolean adhoc, - GError ** error) + GError **error) { const char *key_mgmt = NULL, *leap_username = NULL, *auth_alg = NULL; @@ -529,8 +529,8 @@ verify_adhoc(NMSettingWirelessSecurity *s_wsec, } gboolean -nm_wifi_utils_complete_connection(GBytes * ap_ssid, - const char * bssid, +nm_wifi_utils_complete_connection(GBytes *ap_ssid, + const char *bssid, _NM80211Mode ap_mode, guint32 ap_freq, guint32 ap_flags, @@ -538,13 +538,13 @@ nm_wifi_utils_complete_connection(GBytes * ap_ssid, guint32 ap_rsn_flags, NMConnection *connection, gboolean lock_bssid, - GError ** error) + GError **error) { - NMSettingWireless * s_wifi; + NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; - NMSetting8021x * s_8021x; - GBytes * ssid; - const char * mode, *key_mgmt, *auth_alg, *leap_username; + NMSetting8021x *s_8021x; + GBytes *ssid; + const char *mode, *key_mgmt, *auth_alg, *leap_username; gboolean adhoc = FALSE; gboolean mesh = FALSE; @@ -892,20 +892,20 @@ nm_wifi_utils_is_manf_default_ssid(GBytes *ssid) /* To be used for connections where the SSID has been validated before */ gboolean -nm_wifi_connection_get_iwd_ssid_and_security(NMConnection * connection, - char ** ssid, +nm_wifi_connection_get_iwd_ssid_and_security(NMConnection *connection, + char **ssid, NMIwdNetworkSecurity *security) { - NMSettingWireless * s_wireless; + NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wireless_sec; - const char * key_mgmt = NULL; + const char *key_mgmt = NULL; s_wireless = nm_connection_get_setting_wireless(connection); if (!s_wireless) return FALSE; if (ssid) { - GBytes * bytes = nm_setting_wireless_get_ssid(s_wireless); + GBytes *bytes = nm_setting_wireless_get_ssid(s_wireless); gsize ssid_len; const char *ssid_str = (const char *) g_bytes_get_data(bytes, &ssid_len); @@ -947,7 +947,7 @@ nm_wifi_connection_get_iwd_ssid_and_security(NMConnection * connection, * @ssid_len can be -1 instead of actual SSID length. */ char * -nm_wifi_utils_get_iwd_config_filename(const char * ssid, +nm_wifi_utils_get_iwd_config_filename(const char *ssid, gssize ssid_len, NMIwdNetworkSecurity security) { @@ -995,10 +995,10 @@ static gboolean psk_setting_to_iwd_config(GKeyFile *file, NMSettingWirelessSecurity *s_wsec, GError **error) { NMSettingSecretFlags psk_flags = nm_setting_wireless_security_get_psk_flags(s_wsec); - const char * psk = nm_setting_wireless_security_get_psk(s_wsec); + const char *psk = nm_setting_wireless_security_get_psk(s_wsec); gsize psk_len; guint8 buffer[32]; - const char * key_mgmt = nm_setting_wireless_security_get_key_mgmt(s_wsec); + const char *key_mgmt = nm_setting_wireless_security_get_key_mgmt(s_wsec); if (!psk || NM_FLAGS_ANY(psk_flags, SECRETS_DONT_STORE_FLAGS)) { if (NM_FLAGS_ANY(psk_flags, SECRETS_DONT_STORE_FLAGS)) { @@ -1029,11 +1029,11 @@ psk_setting_to_iwd_config(GKeyFile *file, NMSettingWirelessSecurity *s_wsec, GEr } static gboolean -eap_certs_to_iwd_config(GKeyFile * file, +eap_certs_to_iwd_config(GKeyFile *file, NMSetting8021x *s_8021x, bool phase2, - char * iwd_prefix, - GError ** error) + char *iwd_prefix, + GError **error) { NMSetting8021xCKScheme ca_cert_scheme = phase2 ? nm_setting_802_1x_get_phase2_ca_cert_scheme(s_8021x) @@ -1043,13 +1043,13 @@ eap_certs_to_iwd_config(GKeyFile * file, : nm_setting_802_1x_get_client_cert_scheme(s_8021x); NMSetting8021xCKScheme key_scheme; NMSettingSecretFlags key_password_flags; - const char * ca_path = phase2 ? nm_setting_802_1x_get_phase2_ca_path(s_8021x) + const char *ca_path = phase2 ? nm_setting_802_1x_get_phase2_ca_path(s_8021x) : nm_setting_802_1x_get_ca_path(s_8021x); - const char * cert_path; - const char * key_path = NULL; - const char * key_password; - const char * domain_suffix_match; - const char * domain_match; + const char *cert_path; + const char *key_path = NULL; + const char *key_password; + const char *domain_suffix_match; + const char *domain_match; char setting_buf[128]; /* TODO: should check that all certificates and the key are RSA */ @@ -1220,7 +1220,7 @@ private_key_done: : nm_setting_802_1x_get_domain_match(s_8021x); if (domain_suffix_match || domain_match) { - GString * s = g_string_sized_new(128); + GString *s = g_string_sized_new(128); const char *ptr; const char *end; @@ -1287,13 +1287,13 @@ eap_optional_identity_to_iwd_config(GKeyFile *file, const char *iwd_prefix, cons } static gboolean -eap_optional_password_to_iwd_config(GKeyFile * file, - const char * iwd_prefix, +eap_optional_password_to_iwd_config(GKeyFile *file, + const char *iwd_prefix, NMSetting8021x *s_8021x, - GError ** error) + GError **error) { char setting_buf[128]; - const char * password = nm_setting_802_1x_get_password(s_8021x); + const char *password = nm_setting_802_1x_get_password(s_8021x); NMSettingSecretFlags flags = nm_setting_802_1x_get_password_flags(s_8021x); if (!password && nm_setting_802_1x_get_password_raw(s_8021x)) { @@ -1347,12 +1347,12 @@ eap_phase1_identity_to_iwd_config(GKeyFile *file, const char *iwd_prefix, NMSett } static gboolean -eap_method_config_to_iwd_config(GKeyFile * file, +eap_method_config_to_iwd_config(GKeyFile *file, NMSetting8021x *s_8021x, gboolean phase2, - const char * method, - const char * iwd_prefix, - GError ** error) + const char *method, + const char *iwd_prefix, + GError **error) { char prefix_buf[128]; @@ -1677,18 +1677,18 @@ ip6_config_to_iwd_config(GKeyFile *file, NMSettingIPConfig *s_ip, GError **error GKeyFile * nm_wifi_utils_connection_to_iwd_config(NMConnection *connection, - char ** out_filename, - GError ** error) + char **out_filename, + GError **error) { - NMSettingConnection * s_conn = nm_connection_get_setting_connection(connection); - NMSettingWireless * s_wifi = nm_connection_get_setting_wireless(connection); - GBytes * ssid; - const guint8 * ssid_data; - gsize ssid_len; - NMIwdNetworkSecurity security; - const char * cloned_mac_addr; - gs_free char * comment = NULL; - nm_auto_unref_keyfile GKeyFile *file = NULL; + NMSettingConnection *s_conn = nm_connection_get_setting_connection(connection); + NMSettingWireless *s_wifi = nm_connection_get_setting_wireless(connection); + GBytes *ssid; + const guint8 *ssid_data; + gsize ssid_len; + NMIwdNetworkSecurity security; + const char *cloned_mac_addr; + gs_free char *comment = NULL; + nm_auto_unref_keyfile GKeyFile *file = NULL; if (!s_conn || !s_wifi || !nm_streq(nm_setting_connection_get_connection_type(s_conn), @@ -1800,3 +1800,151 @@ nm_wifi_utils_connection_to_iwd_config(NMConnection *connection, return g_steal_pointer(&file); } + +/* Wi-Fi Display Technical Specification v2.1.0 Table 27 */ +enum wfd_subelem_type { + WFD_SUBELEM_WFD_DEVICE_INFORMATION = 0, + WFD_SUBELEM_ASSOCIATED_BSSID = 1, + WFD_SUBELEM_COUPLED_SINK_INFORMATION = 6, + WFD_SUBELEM_EXTENDED_CAPABILITY = 7, + WFD_SUBELEM_LOCAL_IP_ADDRESS = 8, + WFD_SUBELEM_SESION_INFORMATION = 9, + WFD_SUBELEM_ALTERNATIVE_MAC_ADDRESS = 10, + WFD_SUBELEM_R2_DEVICE_INFORMATION = 11, +}; + +bool +nm_wifi_utils_parse_wfd_ies(GBytes *ies, NMIwdWfdInfo *out_wfd) +{ + size_t len; + const uint8_t *data = g_bytes_get_data(ies, &len); + const uint8_t *dev_info = NULL; + uint16_t dev_info_len = 0; + uint16_t dev_info_flags; + const uint8_t *ext_capability = NULL; + uint16_t ext_capability_len = 0; + + /* The single WFD IEs array provided by the client is supposed to be sent to + * the peer in the different frame types that may include the WFD IE: Probe + * Request/Response, Beacon, (Re)Association Request/Response, GO + * Negotiation Request/Response/Confirm and Provision Discovery + * Request/Response. + * + * It's going to be a subset of the elements allowed in all those frames. + * Validate that it contains at least a valid WFD Device Information (with + * the Session Available bit true) and that the sequence of subelements is + * valid. + */ + while (len) { + uint8_t subelem_id; + uint16_t subelem_len; + + /* Does the subelement header fit */ + if (len < 3) + return FALSE; + + subelem_id = data[0]; + subelem_len = (data[1] << 8) | data[2]; + data += 3; + len -= 3; + + if (subelem_len > len) + return FALSE; + + if (subelem_id == WFD_SUBELEM_WFD_DEVICE_INFORMATION) { + /* Is there a duplicate WFD Device Information */ + if (dev_info) + return FALSE; + + dev_info = data; + dev_info_len = subelem_len; + } + + if (subelem_id == WFD_SUBELEM_EXTENDED_CAPABILITY) { + /* Is there a duplicate WFD Extended Capability */ + if (ext_capability) + return FALSE; + + ext_capability = data; + ext_capability_len = subelem_len; + } + + data += subelem_len; + len -= subelem_len; + } + + if (!dev_info || dev_info_len != 6) + return FALSE; + + dev_info_flags = (dev_info[0] << 8) | dev_info[1]; + + /* Secondary sink not supported */ + if ((dev_info_flags & 3) == 2) + return FALSE; + + /* Must be available for WFD Session */ + if (((dev_info_flags >> 4) & 3) != 1) + return FALSE; + + /* TDLS persistent group re-invocation not supported */ + if ((dev_info_flags >> 13) & 1) + return FALSE; + + /* All other flags indicate support but not a requirement for something + * so not preserving them in the IEs IWD eventually sends doesn't break + * basic functionality. + */ + + if (ext_capability && ext_capability_len != 2) + return FALSE; + + if (!out_wfd) + return TRUE; + + out_wfd->source = NM_IN_SET(dev_info_flags & 3, 0, 3); + out_wfd->sink = NM_IN_SET(dev_info_flags & 3, 1, 3); + out_wfd->port = (dev_info[2] << 8) | dev_info[3]; + out_wfd->has_audio = + out_wfd->sink ? ((dev_info_flags >> 10) & 1) == 0 : (((dev_info_flags >> 11) & 1) == 1); + out_wfd->has_uibc = ext_capability && (ext_capability[1] & 1) == 1; + out_wfd->has_cp = ((dev_info_flags >> 8) & 1) == 1; + return TRUE; +} + +GBytes * +nm_wifi_utils_build_wfd_ies(const NMIwdWfdInfo *wfd) +{ + uint8_t data[64]; + uint8_t *ptr = data; + + *ptr++ = WFD_SUBELEM_WFD_DEVICE_INFORMATION; + *ptr++ = 0; /* WFD Subelement length */ + *ptr++ = 6; + *ptr++ = 0; /* WFD Device Information bitmap: */ + *ptr++ = (wfd->source ? (wfd->sink ? 3 : 0) : 1) | 0x10 | /* WFD Session Available */ + (wfd->has_cp ? 0x100 : 0) | (wfd->has_audio ? 0 : 0x400); + *ptr++ = wfd->port >> 8; + *ptr++ = wfd->port & 255; + *ptr++ = 0; /* WFD Device Maximum throughput */ + *ptr++ = 10; + + if (wfd->has_uibc) { + *ptr++ = WFD_SUBELEM_EXTENDED_CAPABILITY; + *ptr++ = 0; /* WFD Subelement length */ + *ptr++ = 2; + *ptr++ = 0x00; /* WFD Extended Capability Bitmap: */ + *ptr++ = 0x10; /* UIBC Support */ + } + + return g_bytes_new(data, ptr - data); +} + +bool +nm_wifi_utils_wfd_info_eq(const NMIwdWfdInfo *a, const NMIwdWfdInfo *b) +{ + if (!a || !b) + return a == b; + + return a->source == b->source && a->sink == b->sink && a->port == b->port + && a->has_audio == b->has_audio && a->has_uibc == b->has_uibc && a->has_cp == b->has_cp; +} diff --git a/src/core/devices/wifi/nm-wifi-utils.h b/src/core/devices/wifi/nm-wifi-utils.h index 2664c03e..1d46a900 100644 --- a/src/core/devices/wifi/nm-wifi-utils.h +++ b/src/core/devices/wifi/nm-wifi-utils.h @@ -20,8 +20,17 @@ typedef enum { NM_IWD_NETWORK_SECURITY_8021X, } NMIwdNetworkSecurity; -gboolean nm_wifi_utils_complete_connection(GBytes * ssid, - const char * bssid, +typedef struct { + bool source; + bool sink; + uint16_t port; + bool has_audio; + bool has_uibc; + bool has_cp; +} NMIwdWfdInfo; + +gboolean nm_wifi_utils_complete_connection(GBytes *ssid, + const char *bssid, _NM80211Mode mode, guint32 ap_freq, guint32 flags, @@ -29,18 +38,22 @@ gboolean nm_wifi_utils_complete_connection(GBytes * ssid, guint32 rsn_flags, NMConnection *connection, gboolean lock_bssid, - GError ** error); + GError **error); gboolean nm_wifi_utils_is_manf_default_ssid(GBytes *ssid); -gboolean nm_wifi_connection_get_iwd_ssid_and_security(NMConnection * connection, - char ** ssid, +gboolean nm_wifi_connection_get_iwd_ssid_and_security(NMConnection *connection, + char **ssid, NMIwdNetworkSecurity *security); -char * nm_wifi_utils_get_iwd_config_filename(const char * ssid, +char *nm_wifi_utils_get_iwd_config_filename(const char *ssid, gssize ssid_len, NMIwdNetworkSecurity security); GKeyFile * nm_wifi_utils_connection_to_iwd_config(NMConnection *conn, char **out_filename, GError **error); +bool nm_wifi_utils_parse_wfd_ies(GBytes *ies, NMIwdWfdInfo *out_wfd); +GBytes *nm_wifi_utils_build_wfd_ies(const NMIwdWfdInfo *wfd); +bool nm_wifi_utils_wfd_info_eq(const NMIwdWfdInfo *a, const NMIwdWfdInfo *b); + #endif /* __NM_WIFI_UTILS_H__ */ diff --git a/src/core/devices/wifi/tests/test-devices-wifi.c b/src/core/devices/wifi/tests/test-devices-wifi.c index 5d1167cf..69d365e3 100644 --- a/src/core/devices/wifi/tests/test-devices-wifi.c +++ b/src/core/devices/wifi/tests/test-devices-wifi.c @@ -47,18 +47,18 @@ } static gboolean -complete_connection(const char * ssid, - const char * bssid, +complete_connection(const char *ssid, + const char *bssid, _NM80211Mode mode, guint32 flags, guint32 wpa_flags, guint32 rsn_flags, gboolean lock_bssid, NMConnection *src, - GError ** error) + GError **error) { gs_unref_bytes GBytes *ssid_b = NULL; - NMSettingWireless * s_wifi; + NMSettingWireless *s_wifi; /* Add a wifi setting if one doesn't exist */ s_wifi = nm_connection_get_setting_wireless(src); @@ -91,8 +91,8 @@ static void set_items(NMSetting *setting, const KeyData *items) { const KeyData *item; - GParamSpec * pspec; - GBytes * tmp; + GParamSpec *pspec; + GBytes *tmp; for (item = items; item && item->key; item++) { g_assert(item->key); @@ -199,9 +199,9 @@ fill_8021x(NMConnection *connection, const KeyData items[]) static NMConnection * create_basic(const char *ssid, const char *bssid, _NM80211Mode mode) { - NMConnection * connection; + NMConnection *connection; NMSettingWireless *s_wifi = NULL; - GBytes * tmp; + GBytes *tmp; connection = nm_simple_connection_new(); @@ -233,10 +233,10 @@ static void test_lock_bssid(void) { NMConnection *src, *expected; - const char * bssid = "01:02:03:04:05:06"; - const char * ssid = "blahblah"; + const char *bssid = "01:02:03:04:05:06"; + const char *ssid = "blahblah"; gboolean success; - GError * error = NULL; + GError *error = NULL; src = nm_simple_connection_new(); success = complete_connection(ssid, @@ -261,10 +261,10 @@ static void test_open_ap_empty_connection(void) { NMConnection *src, *expected; - const char * bssid = "01:02:03:04:05:06"; - const char * ssid = "blahblah"; + const char *bssid = "01:02:03:04:05:06"; + const char *ssid = "blahblah"; gboolean success; - GError * error = NULL; + GError *error = NULL; /* Test that an empty source connection is correctly filled with the * SSID and Infra modes of the given AP details. @@ -293,11 +293,11 @@ static void test_open_ap_leap_connection_1(gconstpointer add_wifi) { NMConnection *src; - const char * bssid = "01:02:03:04:05:06"; + const char *bssid = "01:02:03:04:05:06"; const KeyData src_wsec[] = {{NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, "Bill Smith", 0}, {NULL}}; gboolean success; - GError * error = NULL; + GError *error = NULL; /* Test that a basic connection filled with a LEAP username is * rejected when completion is attempted with an open AP. LEAP requires @@ -330,10 +330,10 @@ static void test_open_ap_leap_connection_2(void) { NMConnection *src; - const char * bssid = "01:02:03:04:05:06"; + const char *bssid = "01:02:03:04:05:06"; const KeyData src_wsec[] = {{NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", 0}, {NULL}}; gboolean success; - GError * error = NULL; + GError *error = NULL; /* Test that a basic connection specifying IEEE8021x security (ie, Dynamic * WEP or LEAP) is rejected when completion is attempted with an open AP. @@ -364,14 +364,14 @@ static void test_open_ap_wep_connection(gconstpointer add_wifi) { NMConnection *src; - const char * bssid = "01:02:03:04:05:06"; + const char *bssid = "01:02:03:04:05:06"; const KeyData src_wsec[] = { {NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, "11111111111111111111111111", 0}, {NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, NULL, 0}, {NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "open", 0}, {NULL}}; gboolean success; - GError * error = NULL; + GError *error = NULL; /* Test that a static WEP connection is rejected when completion is * attempted with an open AP. @@ -399,8 +399,8 @@ test_open_ap_wep_connection(gconstpointer add_wifi) /*****************************************************************************/ static void -test_ap_wpa_psk_connection_base(const char * key_mgmt, - const char * auth_alg, +test_ap_wpa_psk_connection_base(const char *key_mgmt, + const char *auth_alg, guint32 flags, guint32 wpa_flags, guint32 rsn_flags, @@ -409,8 +409,8 @@ test_ap_wpa_psk_connection_base(const char * key_mgmt, NMConnection *expected) { NMConnection *src; - const char * ssid = "blahblah"; - const char * bssid = "01:02:03:04:05:06"; + const char *ssid = "blahblah"; + const char *bssid = "01:02:03:04:05:06"; const KeyData exp_wifi[] = {{NM_SETTING_WIRELESS_SSID, ssid, 0}, {NM_SETTING_WIRELESS_MODE, "infrastructure", 0}, {NULL}}; @@ -419,7 +419,7 @@ test_ap_wpa_psk_connection_base(const char * key_mgmt, {NM_SETTING_WIRELESS_SECURITY_PSK, "asdfasdfasdfasdfasdfafs", 0}, {NULL}}; gboolean success; - GError * error = NULL; + GError *error = NULL; src = nm_simple_connection_new(); if (add_wifi) @@ -538,13 +538,13 @@ test_ap_wpa_eap_connection_base(const char *key_mgmt, guint error_code) { NMConnection *src; - const char * bssid = "01:02:03:04:05:06"; + const char *bssid = "01:02:03:04:05:06"; const KeyData src_empty[] = {{NULL}}; const KeyData src_wsec[] = {{NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, key_mgmt, 0}, {NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, auth_alg, 0}, {NULL}}; gboolean success; - GError * error = NULL; + GError *error = NULL; src = nm_simple_connection_new(); if (add_wifi) @@ -738,11 +738,11 @@ static void test_priv_ap_empty_connection(void) { NMConnection *src, *expected; - const char * bssid = "01:02:03:04:05:06"; - const char * ssid = "blahblah"; + const char *bssid = "01:02:03:04:05:06"; + const char *ssid = "blahblah"; const KeyData exp_wsec[] = {{NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", 0}, {NULL}}; gboolean success; - GError * error = NULL; + GError *error = NULL; /* Test that an empty connection is completed to a valid Static WEP * connection when completed with an AP with the Privacy bit set. @@ -774,9 +774,9 @@ static void test_priv_ap_leap_connection_1(gconstpointer add_wifi) { NMConnection *src, *expected; - const char * ssid = "blahblah"; - const char * bssid = "01:02:03:04:05:06"; - const char * leap_username = "Bill Smith"; + const char *ssid = "blahblah"; + const char *bssid = "01:02:03:04:05:06"; + const char *leap_username = "Bill Smith"; const KeyData src_wsec[] = {{NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", 0}, {NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, leap_username, 0}, {NULL}}; @@ -785,7 +785,7 @@ test_priv_ap_leap_connection_1(gconstpointer add_wifi) {NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, leap_username, 0}, {NULL}}; gboolean success; - GError * error = NULL; + GError *error = NULL; /* Test that an minimal LEAP connection specifying only key management and * the LEAP username is completed to a full LEAP connection when completed @@ -823,12 +823,12 @@ static void test_priv_ap_leap_connection_2(void) { NMConnection *src; - const char * bssid = "01:02:03:04:05:06"; + const char *bssid = "01:02:03:04:05:06"; const KeyData src_wsec[] = {{NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", 0}, {NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "leap", 0}, {NULL}}; gboolean success; - GError * error = NULL; + GError *error = NULL; /* Test that an minimal LEAP connection specifying only key management and * the LEAP auth alg is completed to a full LEAP connection when completed @@ -859,8 +859,8 @@ static void test_priv_ap_dynamic_wep_1(void) { NMConnection *src, *expected; - const char * ssid = "blahblah"; - const char * bssid = "01:02:03:04:05:06"; + const char *ssid = "blahblah"; + const char *bssid = "01:02:03:04:05:06"; const KeyData src_wsec[] = {{NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", 0}, {NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "open", 0}, {NULL}}; @@ -872,7 +872,7 @@ test_priv_ap_dynamic_wep_1(void) {NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "open", 0}, {NULL}}; gboolean success; - GError * error = NULL; + GError *error = NULL; /* Test that an minimal Dynamic WEP connection specifying key management, * the auth algorithm, and valid 802.1x setting is completed to a valid @@ -909,8 +909,8 @@ static void test_priv_ap_dynamic_wep_2(void) { NMConnection *src, *expected; - const char * ssid = "blahblah"; - const char * bssid = "01:02:03:04:05:06"; + const char *ssid = "blahblah"; + const char *bssid = "01:02:03:04:05:06"; const KeyData src_wsec[] = {{NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "open", 0}, {NULL}}; const KeyData both_8021x[] = {{NM_SETTING_802_1X_EAP, "peap", 0}, {NM_SETTING_802_1X_IDENTITY, "Bill Smith", 0}, @@ -920,7 +920,7 @@ test_priv_ap_dynamic_wep_2(void) {NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "open", 0}, {NULL}}; gboolean success; - GError * error = NULL; + GError *error = NULL; /* Test that an minimal Dynamic WEP connection specifying only the auth * algorithm and a valid 802.1x setting is completed to a valid Dynamic @@ -957,14 +957,14 @@ static void test_priv_ap_dynamic_wep_3(void) { NMConnection *src; - const char * bssid = "01:02:03:04:05:06"; + const char *bssid = "01:02:03:04:05:06"; const KeyData src_wsec[] = {{NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "shared", 0}, {NULL}}; const KeyData src_8021x[] = {{NM_SETTING_802_1X_EAP, "peap", 0}, {NM_SETTING_802_1X_IDENTITY, "Bill Smith", 0}, {NM_SETTING_802_1X_PHASE2_AUTH, "mschapv2", 0}, {NULL}}; gboolean success; - GError * error = NULL; + GError *error = NULL; /* Ensure that a basic connection specifying 'shared' auth and an 802.1x * setting is rejected, as 802.1x is incompatible with 'shared' auth. @@ -1086,13 +1086,13 @@ test_wpa_ap_empty_connection(gconstpointer data) { guint idx = GPOINTER_TO_UINT(data); NMConnection *src, *expected; - const char * bssid = "01:02:03:04:05:06"; - const char * ssid = "blahblah"; + const char *bssid = "01:02:03:04:05:06"; + const char *ssid = "blahblah"; const KeyData exp_wsec[] = {{NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk", 0}, {NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "open", 0}, {NULL}}; gboolean success; - GError * error = NULL; + GError *error = NULL; /* Test that a basic WPA-PSK connection specifying just key management and * the auth algorithm is completed successfully when given an AP with WPA @@ -1126,14 +1126,14 @@ test_wpa_ap_leap_connection_1(gconstpointer data) { guint idx = GPOINTER_TO_UINT(data); NMConnection *src; - const char * ssid = "blahblah"; - const char * bssid = "01:02:03:04:05:06"; - const char * leap_username = "Bill Smith"; + const char *ssid = "blahblah"; + const char *bssid = "01:02:03:04:05:06"; + const char *leap_username = "Bill Smith"; const KeyData src_wsec[] = {{NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", 0}, {NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, leap_username, 0}, {NULL}}; gboolean success; - GError * error = NULL; + GError *error = NULL; /* Test that completion of a LEAP connection with a WPA-enabled AP is * rejected since WPA APs (usually) do not support LEAP. @@ -1164,12 +1164,12 @@ test_wpa_ap_leap_connection_2(gconstpointer data) { guint idx = GPOINTER_TO_UINT(data); NMConnection *src; - const char * bssid = "01:02:03:04:05:06"; + const char *bssid = "01:02:03:04:05:06"; const KeyData src_wsec[] = {{NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", 0}, {NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "leap", 0}, {NULL}}; gboolean success; - GError * error = NULL; + GError *error = NULL; /* Test that completion of a LEAP connection with a WPA-enabled AP is * rejected since WPA APs (usually) do not support LEAP. @@ -1200,10 +1200,10 @@ test_wpa_ap_dynamic_wep_connection(gconstpointer data) { guint idx = GPOINTER_TO_UINT(data); NMConnection *src; - const char * bssid = "01:02:03:04:05:06"; + const char *bssid = "01:02:03:04:05:06"; const KeyData src_wsec[] = {{NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", 0}, {NULL}}; gboolean success; - GError * error = NULL; + GError *error = NULL; /* Test that completion of a Dynamic WEP connection with a WPA-enabled AP is * rejected since WPA APs (usually) do not support Dynamic WEP. @@ -1409,12 +1409,12 @@ test_strength_all(void) static void do_test_ssids_options_to_ptrarray(const char *const *ssids) { - GVariantBuilder builder; - gs_unref_variant GVariant *variant = NULL; + GVariantBuilder builder; + gs_unref_variant GVariant *variant = NULL; gs_unref_ptrarray GPtrArray *ssids_arr = NULL; - gs_free_error GError *error = NULL; - gsize len; - gsize i; + gs_free_error GError *error = NULL; + gsize len; + gsize i; g_assert(ssids); @@ -1443,7 +1443,7 @@ do_test_ssids_options_to_ptrarray(const char *const *ssids) g_assert_cmpint(len, ==, ssids_arr->len); for (i = 0; i < len; i++) { const char *ssid = ssids[i]; - GBytes * bytes = ssids_arr->pdata[i]; + GBytes *bytes = ssids_arr->pdata[i]; g_assert(nm_g_bytes_equal_mem(bytes, ssid, strlen(ssid))); } diff --git a/src/core/devices/wwan/libnm-wwan.ver b/src/core/devices/wwan/libnm-wwan.ver index c368a590..640df36d 100644 --- a/src/core/devices/wwan/libnm-wwan.ver +++ b/src/core/devices/wwan/libnm-wwan.ver @@ -14,7 +14,6 @@ global: nm_modem_get_control_port; nm_modem_get_device_id; nm_modem_get_driver; - nm_modem_get_iid; nm_modem_get_ip_ifindex; nm_modem_get_operator_code; nm_modem_get_path; @@ -22,7 +21,6 @@ global: nm_modem_get_state; nm_modem_get_type; nm_modem_get_uid; - nm_modem_ip4_pre_commit; nm_modem_is_claimed; nm_modem_manager_get; nm_modem_manager_get_modems; @@ -32,8 +30,7 @@ global: nm_modem_manager_name_owner_unref; nm_modem_owns_port; nm_modem_set_mm_enabled; - nm_modem_stage3_ip4_config_start; - nm_modem_stage3_ip6_config_start; + nm_modem_stage3_ip_config_start; nm_modem_state_to_string; nm_modem_unclaim; local: diff --git a/src/core/devices/wwan/nm-device-modem.c b/src/core/devices/wwan/nm-device-modem.c index 1b285469..ef802a44 100644 --- a/src/core/devices/wwan/nm-device-modem.c +++ b/src/core/devices/wwan/nm-device-modem.c @@ -8,7 +8,7 @@ #include "nm-device-modem.h" #include "nm-modem.h" -#include "nm-ip4-config.h" +#include "nm-l3-config-data.h" #include "devices/nm-device-private.h" #include "nm-rfkill-manager.h" #include "settings/nm-settings-connection.h" @@ -30,14 +30,16 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMDeviceModem, PROP_APN, ); typedef struct { - NMModem * modem; + NMModem *modem; NMDeviceModemCapabilities caps; NMDeviceModemCapabilities current_caps; - char * device_id; - char * operator_code; - char * apn; + NMUtilsIPv6IfaceId iid; + char *device_id; + char *operator_code; + char *apn; bool rf_enabled : 1; NMDeviceStageState stage1_state : 3; + NMDeviceStageState stage2_state : 3; } NMDeviceModemPrivate; struct _NMDeviceModem { @@ -59,52 +61,18 @@ G_DEFINE_TYPE(NMDeviceModem, nm_device_modem, NM_TYPE_DEVICE) static void ppp_failed(NMModem *modem, guint i_reason, gpointer user_data) { - NMDevice * device = NM_DEVICE(user_data); - NMDeviceModem * self = NM_DEVICE_MODEM(user_data); + NMDevice *device = NM_DEVICE(user_data); NMDeviceStateReason reason = i_reason; - switch (nm_device_get_state(device)) { - case NM_DEVICE_STATE_PREPARE: - case NM_DEVICE_STATE_CONFIG: - case NM_DEVICE_STATE_NEED_AUTH: - nm_device_state_changed(device, NM_DEVICE_STATE_FAILED, reason); - break; - case NM_DEVICE_STATE_IP_CONFIG: - case NM_DEVICE_STATE_IP_CHECK: - case NM_DEVICE_STATE_SECONDARIES: - case NM_DEVICE_STATE_ACTIVATED: - if (nm_device_activate_ip4_state_in_conf(device)) - nm_device_activate_schedule_ip_config_timeout(device, AF_INET); - else if (nm_device_activate_ip6_state_in_conf(device)) - nm_device_activate_schedule_ip_config_timeout(device, AF_INET6); - else if (nm_device_activate_ip4_state_done(device)) { - nm_device_ip_method_failed(device, - AF_INET, - NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); - } else if (nm_device_activate_ip6_state_done(device)) { - nm_device_ip_method_failed(device, - AF_INET6, - NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); - } else { - _LOGW(LOGD_MB, - "PPP failure in unexpected state %u", - (guint) nm_device_get_state(device)); - nm_device_state_changed(device, - NM_DEVICE_STATE_FAILED, - NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); - } - break; - default: - break; - } + nm_device_state_changed(device, NM_DEVICE_STATE_FAILED, reason); } static void modem_prepare_result(NMModem *modem, gboolean success, guint i_reason, gpointer user_data) { - NMDeviceModem * self = NM_DEVICE_MODEM(user_data); + NMDeviceModem *self = NM_DEVICE_MODEM(user_data); NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE(self); - NMDevice * device = NM_DEVICE(self); + NMDevice *device = NM_DEVICE(self); NMDeviceStateReason reason = i_reason; if (nm_device_get_state(device) != NM_DEVICE_STATE_PREPARE @@ -173,7 +141,7 @@ modem_auth_requested(NMModem *modem, gpointer user_data) static void modem_auth_result(NMModem *modem, GError *error, gpointer user_data) { - NMDevice * device = NM_DEVICE(user_data); + NMDevice *device = NM_DEVICE(user_data); NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE(device); g_return_if_fail(nm_device_get_state(device) == NM_DEVICE_STATE_NEED_AUTH); @@ -188,102 +156,50 @@ modem_auth_result(NMModem *modem, GError *error, gpointer user_data) } static void -modem_ip4_config_result(NMModem *modem, NMIP4Config *config, GError *error, gpointer user_data) -{ - NMDeviceModem *self = NM_DEVICE_MODEM(user_data); - NMDevice * device = NM_DEVICE(self); - - if (!nm_device_activate_ip4_state_in_conf(device)) { - _LOGD(LOGD_MB | LOGD_IP4, - "retrieving IPv4 configuration while no longer in state IPv4 conf"); +modem_new_config(NMModem *modem, + int addr_family, + const NML3ConfigData *l3cd, + gboolean do_auto, + const NMUtilsIPv6IfaceId *iid, + int failure_reason_i, + GError *error, + gpointer user_data) +{ + const int IS_IPv4 = NM_IS_IPv4(addr_family); + NMDeviceModem *self = NM_DEVICE_MODEM(user_data); + NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE(self); + NMDevice *device = NM_DEVICE(self); + + if (nm_device_devip_get_state(device, addr_family) != NM_DEVICE_IP_STATE_PENDING) { + _LOGD(LOGD_MB, "retrieving IP configuration while no longer in pending state"); return; } if (error) { - _LOGW(LOGD_MB | LOGD_IP4, "retrieving IPv4 configuration failed: %s", error->message); - nm_device_ip_method_failed(device, AF_INET, NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); - return; - } - - nm_device_set_dev2_ip_config(device, AF_INET, NM_IP_CONFIG_CAST(config)); - nm_device_activate_schedule_ip_config_result(device, AF_INET, NULL); -} - -static void -modem_ip6_config_result(NMModem * modem, - NMIP6Config *config, - gboolean do_slaac, - GError * error, - gpointer user_data) -{ - NMDeviceModem * self = NM_DEVICE_MODEM(user_data); - NMDevice * device = NM_DEVICE(self); - NMActStageReturn ret; - NMDeviceStateReason failure_reason = NM_DEVICE_STATE_REASON_NONE; - gs_unref_object NMIP6Config *ignored = NULL; - gboolean got_config = !!config; - - if (!nm_device_activate_ip6_state_in_conf(device)) { - _LOGD(LOGD_MB | LOGD_IP6, - "retrieving IPv6 configuration while no longer in state IPv6 conf"); + _LOGW(LOGD_MB, "retrieving IP configuration failed: %s", error->message); + nm_device_devip_set_failed(device, addr_family, failure_reason_i); return; } - if (error) { - _LOGW(LOGD_MB | LOGD_IP6, "retrieving IPv6 configuration failed: %s", error->message); - nm_device_ip_method_failed(device, AF_INET6, NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); - return; - } + if (!IS_IPv4) + priv->iid = iid ? *iid : ((NMUtilsIPv6IfaceId) NM_UTILS_IPV6_IFACE_ID_INIT); - /* Re-enable IPv6 on the interface */ - nm_device_sysctl_ip_conf_set(device, AF_INET6, "disable_ipv6", "0"); - - if (config) - nm_device_set_dev2_ip_config(device, AF_INET6, NM_IP_CONFIG_CAST(config)); - - if (do_slaac == FALSE) { - if (got_config) - nm_device_activate_schedule_ip_config_result(device, AF_INET6, NULL); - else { - _LOGW(LOGD_MB | LOGD_IP6, - "retrieving IPv6 configuration failed: SLAAC not requested and no addresses"); - nm_device_ip_method_failed(device, - AF_INET6, - NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); - } - return; + if (do_auto) { + if (IS_IPv4) + nm_device_ip_method_dhcp4_start(device); + else + nm_device_ip_method_autoconf6_start(device); } - /* Start SLAAC now that we have a link-local address from the modem */ - ret = - NM_DEVICE_CLASS(nm_device_modem_parent_class) - ->act_stage3_ip_config_start(device, AF_INET6, (gpointer *) &ignored, &failure_reason); - - nm_assert(ignored == NULL); - - switch (ret) { - case NM_ACT_STAGE_RETURN_FAILURE: - nm_device_ip_method_failed(device, AF_INET6, failure_reason); - break; - case NM_ACT_STAGE_RETURN_IP_FAIL: - /* all done */ - nm_device_activate_schedule_ip_config_result(device, AF_INET6, NULL); - break; - case NM_ACT_STAGE_RETURN_POSTPONE: - /* let SLAAC run */ - break; - default: - /* Should never get here since we've assured that the IPv6 method - * will either be "auto" or "ignored" when starting IPv6 configuration. - */ - nm_assert_not_reached(); - } + nm_device_devip_set_state(device, addr_family, NM_DEVICE_IP_STATE_READY, l3cd); } static void ip_ifindex_changed_cb(NMModem *modem, GParamSpec *pspec, gpointer user_data) { - NMDevice *device = NM_DEVICE(user_data); + NMDevice *device = NM_DEVICE(user_data); + NMDeviceModem *self = NM_DEVICE_MODEM(device); + NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE(self); if (!nm_device_is_activating(device)) return; @@ -300,14 +216,19 @@ ip_ifindex_changed_cb(NMModem *modem, GParamSpec *pspec, gpointer user_data) * RA handling code to run before NM is ready. */ nm_device_sysctl_ip_conf_set(device, AF_INET6, "disable_ipv6", "1"); + + if (priv->stage2_state == NM_DEVICE_STAGE_STATE_PENDING) { + priv->stage2_state = NM_DEVICE_STAGE_STATE_COMPLETED; + nm_device_activate_schedule_stage2_device_config(device, FALSE); + } } static void operator_code_changed_cb(NMModem *modem, GParamSpec *pspec, gpointer user_data) { - NMDeviceModem * self = NM_DEVICE_MODEM(user_data); + NMDeviceModem *self = NM_DEVICE_MODEM(user_data); NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE(self); - const char * operator_code = nm_modem_get_operator_code(modem); + const char *operator_code = nm_modem_get_operator_code(modem); if (g_strcmp0(priv->operator_code, operator_code) != 0) { g_free(priv->operator_code); @@ -319,9 +240,9 @@ operator_code_changed_cb(NMModem *modem, GParamSpec *pspec, gpointer user_data) static void apn_changed_cb(NMModem *modem, GParamSpec *pspec, gpointer user_data) { - NMDeviceModem * self = NM_DEVICE_MODEM(user_data); + NMDeviceModem *self = NM_DEVICE_MODEM(user_data); NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE(self); - const char * apn = nm_modem_get_apn(modem); + const char *apn = nm_modem_get_apn(modem); if (g_strcmp0(priv->apn, apn) != 0) { g_free(priv->apn); @@ -341,7 +262,7 @@ modem_state_cb(NMModem *modem, int new_state_i, int old_state_i, gpointer user_d { NMModemState new_state = new_state_i; NMModemState old_state = old_state_i; - NMDevice * device = NM_DEVICE(user_data); + NMDevice *device = NM_DEVICE(user_data); NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE(device); NMDeviceState dev_state = nm_device_get_state(device); @@ -413,12 +334,12 @@ owns_iface(NMDevice *device, const char *iface) /*****************************************************************************/ static void -device_state_changed(NMDevice * device, +device_state_changed(NMDevice *device, NMDeviceState new_state, NMDeviceState old_state, NMDeviceStateReason reason) { - NMDeviceModem * self = NM_DEVICE_MODEM(device); + NMDeviceModem *self = NM_DEVICE_MODEM(device); NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE(self); g_return_if_fail(priv->modem); @@ -480,13 +401,13 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError * } static gboolean -check_connection_available(NMDevice * device, - NMConnection * connection, +check_connection_available(NMDevice *device, + NMConnection *connection, NMDeviceCheckConAvailableFlags flags, - const char * specific_object, - GError ** error) + const char *specific_object, + GError **error) { - NMDeviceModem * self = NM_DEVICE_MODEM(device); + NMDeviceModem *self = NM_DEVICE_MODEM(device); NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE(self); NMModemState state; @@ -525,11 +446,11 @@ check_connection_available(NMDevice * device, } static gboolean -complete_connection(NMDevice * device, - NMConnection * connection, - const char * specific_object, +complete_connection(NMDevice *device, + NMConnection *connection, + const char *specific_object, NMConnection *const *existing_connections, - GError ** error) + GError **error) { NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE(device); @@ -547,6 +468,7 @@ deactivate(NMDevice *device) nm_modem_deactivate(priv->modem, device); priv->stage1_state = NM_DEVICE_STAGE_STATE_INIT; + priv->stage2_state = NM_DEVICE_STAGE_STATE_INIT; } /*****************************************************************************/ @@ -554,7 +476,7 @@ deactivate(NMDevice *device) static void modem_deactivate_async_cb(NMModem *modem, GError *error, gpointer user_data) { - gs_unref_object NMDevice * self = NULL; + gs_unref_object NMDevice *self = NULL; NMDeviceDeactivateCallback callback; gpointer callback_user_data; @@ -563,8 +485,8 @@ modem_deactivate_async_cb(NMModem *modem, GError *error, gpointer user_data) } static void -deactivate_async(NMDevice * self, - GCancellable * cancellable, +deactivate_async(NMDevice *self, + GCancellable *cancellable, NMDeviceDeactivateCallback callback, gpointer user_data) { @@ -584,7 +506,7 @@ static NMActStageReturn act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) { NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE(device); - NMActRequest * req; + NMActRequest *req; req = nm_device_get_act_request(device); g_return_val_if_fail(req, NM_ACT_STAGE_RETURN_FAILURE); @@ -606,51 +528,44 @@ act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) static NMActStageReturn act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) { - nm_modem_act_stage2_config(NM_DEVICE_MODEM_GET_PRIVATE(device)->modem); - return NM_ACT_STAGE_RETURN_SUCCESS; -} - -static NMActStageReturn -act_stage3_ip_config_start(NMDevice * device, - int addr_family, - gpointer * out_config, - NMDeviceStateReason *out_failure_reason) -{ - NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE(device); - gboolean autoip4 = FALSE; - NMActStageReturn ret; - - if (!NM_IS_IPv4(addr_family)) - return nm_modem_stage3_ip6_config_start(priv->modem, device, out_failure_reason); - - ret = nm_modem_stage3_ip4_config_start(priv->modem, device, &autoip4, out_failure_reason); + NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE(device); - if (ret != NM_ACT_STAGE_RETURN_SUCCESS || !autoip4) - return ret; + if (priv->stage2_state == NM_DEVICE_STAGE_STATE_INIT) { + priv->stage2_state = NM_DEVICE_STAGE_STATE_PENDING; + return nm_modem_act_stage2_config(NM_DEVICE_MODEM_GET_PRIVATE(device)->modem, + device, + out_failure_reason); + } + if (priv->stage2_state == NM_DEVICE_STAGE_STATE_PENDING) + return NM_ACT_STAGE_RETURN_POSTPONE; - return NM_DEVICE_CLASS(nm_device_modem_parent_class) - ->act_stage3_ip_config_start(device, addr_family, out_config, out_failure_reason); + nm_assert(priv->stage2_state == NM_DEVICE_STAGE_STATE_COMPLETED); + return NM_ACT_STAGE_RETURN_SUCCESS; } static void -ip4_config_pre_commit(NMDevice *device, NMIP4Config *config) +act_stage3_ip_config(NMDevice *device, int addr_family) { - nm_modem_ip4_pre_commit(NM_DEVICE_MODEM_GET_PRIVATE(device)->modem, device, config); + NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE(device); + + if (nm_modem_stage3_ip_config_start(priv->modem, addr_family, device)) + nm_device_devip_set_state(device, addr_family, NM_DEVICE_IP_STATE_PENDING, NULL); } static gboolean get_ip_iface_identifier(NMDevice *device, NMUtilsIPv6IfaceId *out_iid) { - NMDeviceModem * self = NM_DEVICE_MODEM(device); + NMDeviceModem *self = NM_DEVICE_MODEM(device); NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE(self); - gboolean success; g_return_val_if_fail(priv->modem, FALSE); - success = nm_modem_get_iid(priv->modem, out_iid); - if (!success) - success = - NM_DEVICE_CLASS(nm_device_modem_parent_class)->get_ip_iface_identifier(device, out_iid); - return success; + + if (priv->iid.id != 0) { + *out_iid = priv->iid; + return TRUE; + } + + return NM_DEVICE_CLASS(nm_device_modem_parent_class)->get_ip_iface_identifier(device, out_iid); } /*****************************************************************************/ @@ -667,7 +582,7 @@ get_enabled(NMDevice *device) static void set_enabled(NMDevice *device, gboolean enabled) { - NMDeviceModem * self = NM_DEVICE_MODEM(device); + NMDeviceModem *self = NM_DEVICE_MODEM(device); NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE(self); /* Called only by the Manager in response to rfkill switch changes or @@ -688,7 +603,7 @@ set_enabled(NMDevice *device, gboolean enabled) static gboolean is_available(NMDevice *device, NMDeviceCheckDevAvailableFlags flags) { - NMDeviceModem * self = NM_DEVICE_MODEM(device); + NMDeviceModem *self = NM_DEVICE_MODEM(device); NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE(self); NMModemState modem_state; @@ -703,6 +618,16 @@ is_available(NMDevice *device, NMDeviceCheckDevAvailableFlags flags) return TRUE; } +static gboolean +ready_for_ip_config(NMDevice *device) +{ + /* Tell NMDevice to only run device-specific IP + * configuration (devip) and skip other methods + * (manual, dhcp, etc). + */ + return FALSE; +} + /*****************************************************************************/ static void @@ -716,8 +641,7 @@ set_modem(NMDeviceModem *self, NMModem *modem) g_signal_connect(modem, NM_MODEM_PPP_FAILED, G_CALLBACK(ppp_failed), self); g_signal_connect(modem, NM_MODEM_PREPARE_RESULT, G_CALLBACK(modem_prepare_result), self); - g_signal_connect(modem, NM_MODEM_IP4_CONFIG_RESULT, G_CALLBACK(modem_ip4_config_result), self); - g_signal_connect(modem, NM_MODEM_IP6_CONFIG_RESULT, G_CALLBACK(modem_ip6_config_result), self); + g_signal_connect(modem, NM_MODEM_NEW_CONFIG, G_CALLBACK(modem_new_config), self); g_signal_connect(modem, NM_MODEM_AUTH_REQUESTED, G_CALLBACK(modem_auth_requested), self); g_signal_connect(modem, NM_MODEM_AUTH_RESULT, G_CALLBACK(modem_auth_result), self); g_signal_connect(modem, NM_MODEM_STATE_CHANGED, G_CALLBACK(modem_state_cb), self); @@ -838,9 +762,9 @@ nm_device_modem_new(NMModem *modem) NM_DEVICE_MODEM_MODEM, modem, NM_DEVICE_MODEM_CAPABILITIES, - caps, + (guint) ((guint32) caps), NM_DEVICE_MODEM_CURRENT_CAPABILITIES, - current_caps, + (guint) ((guint32) current_caps), NM_DEVICE_MODEM_DEVICE_ID, nm_modem_get_device_id(modem), NULL); @@ -885,9 +809,9 @@ static const NMDBusInterfaceInfoExtended interface_info_device_modem = { static void nm_device_modem_class_init(NMDeviceModemClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMDeviceClass * device_class = NM_DEVICE_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->dispose = dispose; object_class->get_property = get_property; @@ -904,8 +828,7 @@ nm_device_modem_class_init(NMDeviceModemClass *klass) device_class->deactivate = deactivate; device_class->act_stage1_prepare = act_stage1_prepare; device_class->act_stage2_config = act_stage2_config; - device_class->act_stage3_ip_config_start = act_stage3_ip_config_start; - device_class->ip4_config_pre_commit = ip4_config_pre_commit; + device_class->act_stage3_ip_config = act_stage3_ip_config; device_class->get_enabled = get_enabled; device_class->set_enabled = set_enabled; device_class->owns_iface = owns_iface; @@ -913,6 +836,7 @@ nm_device_modem_class_init(NMDeviceModemClass *klass) device_class->get_ip_iface_identifier = get_ip_iface_identifier; device_class->get_configured_mtu = nm_modem_get_configured_mtu; device_class->get_dhcp_timeout_for_device = get_dhcp_timeout_for_device; + device_class->ready_for_ip_config = ready_for_ip_config; device_class->state_changed = device_state_changed; diff --git a/src/core/devices/wwan/nm-modem-broadband.c b/src/core/devices/wwan/nm-modem-broadband.c index a5139f08..f5336d37 100644 --- a/src/core/devices/wwan/nm-modem-broadband.c +++ b/src/core/devices/wwan/nm-modem-broadband.c @@ -16,29 +16,20 @@ #include "NetworkManagerUtils.h" #include "devices/nm-device-private.h" #include "libnm-platform/nm-platform.h" -#include "nm-ip4-config.h" -#include "nm-ip6-config.h" +#include "nm-l3-config-data.h" #define NM_MODEM_BROADBAND_MODEM "modem" -static gboolean -MODEM_CAPS_3GPP(MMModemCapability caps) -{ - G_GNUC_BEGIN_IGNORE_DEPRECATIONS - /* MM_MODEM_CAPABILITY_LTE_ADVANCED is marked as deprecated since ModemManager 1.14.0. - * - * The flag probably was never used, it certainly isn't used since 1.14.0. - * - * Still, just to be sure, there is no harm in checking it here. Suppress the - * warning, it should have no bad effect. - */ - return NM_FLAGS_ANY(caps, - (MM_MODEM_CAPABILITY_GSM_UMTS | MM_MODEM_CAPABILITY_LTE - | MM_MODEM_CAPABILITY_LTE_ADVANCED)); - G_GNUC_END_IGNORE_DEPRECATIONS -} +#if !MM_CHECK_VERSION(1, 14, 0) +#define MM_MODEM_CAPABILITY_5GNR ((MMModemCapability) (1 << 6)) +#endif + +#define MODEM_CAPS_3GPP(caps) \ + NM_FLAGS_ANY( \ + caps, \ + (MM_MODEM_CAPABILITY_GSM_UMTS | MM_MODEM_CAPABILITY_LTE | MM_MODEM_CAPABILITY_5GNR)) -#define MODEM_CAPS_3GPP2(caps) (caps & (MM_MODEM_CAPABILITY_CDMA_EVDO)) +#define MODEM_CAPS_3GPP2(caps) NM_FLAGS_ANY((caps), MM_MODEM_CAPABILITY_CDMA_EVDO) /* Maximum time to keep the DBus call waiting for a connection result. * This value is greater than the default timeout in ModemManager (180s since @@ -62,13 +53,13 @@ typedef struct { ConnectStep step; MMModemCapability caps; - NMConnection * connection; - GCancellable * cancellable; + NMConnection *connection; + GCancellable *cancellable; MMSimpleConnectProperties *connect_properties; - GArray * ip_types; + GArray *ip_types; guint ip_types_i; guint ip_type_tries; - GError * first_error; + GError *first_error; } ConnectContext; /*****************************************************************************/ @@ -79,21 +70,18 @@ typedef struct { /* The modem object from dbus */ MMObject *modem_object; /* Per-interface objects */ - MMModem * modem_iface; - MMModem3gpp * modem_3gpp_iface; + MMModem *modem_iface; + MMModem3gpp *modem_3gpp_iface; MMModemSimple *simple_iface; - MMSim * sim_iface; + MMSim *sim_iface; /* Connection setup */ ConnectContext *ctx; - MMBearer * bearer; + MMBearer *bearer; MMBearerIpConfig *ipv4_config; MMBearerIpConfig *ipv6_config; - guint idle_id_ip4; - guint idle_id_ip6; - guint32 pin_tries; } NMModemBroadbandPrivate; @@ -123,7 +111,7 @@ G_DEFINE_TYPE(NMModemBroadband, nm_modem_broadband, NM_TYPE_MODEM) if (nm_logging_enabled(_level, (_NMLOG_DOMAIN))) { \ NMModemBroadband *const __self = (self); \ char __prefix_name[128]; \ - const char * __uid; \ + const char *__uid; \ \ _nm_log(_level, \ (_NMLOG_DOMAIN), \ @@ -199,24 +187,28 @@ translate_mm_error(NMModemBroadband *self, GError *error) /*****************************************************************************/ static void -get_capabilities(NMModem * _self, +get_capabilities(NMModem *_self, NMDeviceModemCapabilities *modem_caps, NMDeviceModemCapabilities *current_caps) { - NMModemBroadband * self = NM_MODEM_BROADBAND(_self); - MMModemCapability all_supported = MM_MODEM_CAPABILITY_NONE; - MMModemCapability *supported; - guint n_supported; + NMModemBroadband *self = NM_MODEM_BROADBAND(_self); + MMModemCapability all_supported = MM_MODEM_CAPABILITY_NONE; + gs_free MMModemCapability *supported = NULL; + guint n_supported; + guint i; + + G_STATIC_ASSERT(MM_MODEM_CAPABILITY_POTS == (guint64) NM_DEVICE_MODEM_CAPABILITY_POTS); + G_STATIC_ASSERT(MM_MODEM_CAPABILITY_CDMA_EVDO + == (guint64) NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO); + G_STATIC_ASSERT(MM_MODEM_CAPABILITY_GSM_UMTS == (guint64) NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS); + G_STATIC_ASSERT(MM_MODEM_CAPABILITY_LTE == (guint64) NM_DEVICE_MODEM_CAPABILITY_LTE); + G_STATIC_ASSERT(MM_MODEM_CAPABILITY_5GNR == (guint64) NM_DEVICE_MODEM_CAPABILITY_5GNR); /* For now, we don't care about the capability combinations, just merge all * combinations in a single mask */ if (mm_modem_get_supported_capabilities(self->_priv.modem_iface, &supported, &n_supported)) { - guint i; - for (i = 0; i < n_supported; i++) all_supported |= supported[i]; - - g_free(supported); } *modem_caps = (NMDeviceModemCapabilities) all_supported; @@ -227,7 +219,7 @@ get_capabilities(NMModem * _self, static gboolean owns_port(NMModem *_self, const char *iface) { - NMModemBroadband * self = NM_MODEM_BROADBAND(_self); + NMModemBroadband *self = NM_MODEM_BROADBAND(_self); const MMModemPortInfo *ports = NULL; guint n_ports = 0, i; @@ -278,7 +270,7 @@ create_cdma_connect_properties(NMConnection *connection) #if !MM_CHECK_VERSION(1, 9, 1) { NMSettingCdma *setting; - const char * str; + const char *str; setting = nm_connection_get_setting_cdma(connection); str = nm_setting_cdma_get_number(setting); @@ -292,14 +284,14 @@ create_cdma_connect_properties(NMConnection *connection) static MMSimpleConnectProperties * create_gsm_connect_properties(NMConnection *connection, - const char * apn, - const char * username, - const char * password) + const char *apn, + const char *username, + const char *password) { - NMSettingGsm * setting; - NMSettingPpp * s_ppp; + NMSettingGsm *setting; + NMSettingPpp *s_ppp; MMSimpleConnectProperties *properties; - const char * str; + const char *str; setting = nm_connection_get_setting_gsm(connection); @@ -369,11 +361,11 @@ static void connect_context_step(NMModemBroadband *self); static void connect_ready(MMModemSimple *simple_iface, GAsyncResult *res, NMModemBroadband *self) { - ConnectContext *ctx; - GError * error = NULL; - NMModemIPMethod ip4_method = NM_MODEM_IP_METHOD_UNKNOWN; - NMModemIPMethod ip6_method = NM_MODEM_IP_METHOD_UNKNOWN; - gs_unref_object MMBearer *bearer = NULL; + ConnectContext *ctx; + GError *error = NULL; + NMModemIPMethod ip4_method = NM_MODEM_IP_METHOD_UNKNOWN; + NMModemIPMethod ip6_method = NM_MODEM_IP_METHOD_UNKNOWN; + gs_unref_object MMBearer *bearer = NULL; bearer = mm_modem_simple_connect_finish(simple_iface, res, &error); @@ -480,18 +472,18 @@ send_pin_ready(MMSim *sim, GAsyncResult *result, NMModemBroadband *self) } static void -find_gsm_apn_cb(const char * apn, - const char * username, - const char * password, - const char * gateway, - const char * auth_method, +find_gsm_apn_cb(const char *apn, + const char *username, + const char *password, + const char *gateway, + const char *auth_method, const GSList *dns, - GError * error, + GError *error, gpointer user_data) { - NMModemBroadband * self = user_data; + NMModemBroadband *self = user_data; NMModemBroadbandPrivate *priv = NM_MODEM_BROADBAND_GET_PRIVATE(self); - ConnectContext * ctx = priv->ctx; + ConnectContext *ctx = priv->ctx; if (error) { _LOGW("failed to connect '%s': APN not found: %s", @@ -514,14 +506,14 @@ static gboolean try_create_connect_properties(NMModemBroadband *self) { NMModemBroadbandPrivate *priv = NM_MODEM_BROADBAND_GET_PRIVATE(self); - ConnectContext * ctx = priv->ctx; + ConnectContext *ctx = priv->ctx; if (MODEM_CAPS_3GPP(ctx->caps)) { NMSettingGsm *s_gsm = nm_connection_get_setting_gsm(ctx->connection); if (!s_gsm || nm_setting_gsm_get_auto_config(s_gsm)) { gs_unref_object MMModem3gpp *modem_3gpp = NULL; - const char * network_id = NULL; + const char *network_id = NULL; s_gsm = nm_connection_get_setting_gsm(ctx->connection); if (s_gsm) @@ -590,7 +582,7 @@ connect_context_step(NMModemBroadband *self) if (MODEM_CAPS_3GPP(ctx->caps) && mm_modem_get_unlock_required(self->_priv.modem_iface) == MM_MODEM_LOCK_SIM_PIN) { NMSettingGsm *s_gsm = nm_connection_get_setting_gsm(ctx->connection); - const char * pin = nm_setting_gsm_get_pin(s_gsm); + const char *pin = nm_setting_gsm_get_pin(s_gsm); /* If we have a PIN already, send it. If we don't, get it. */ if (pin) { @@ -698,8 +690,8 @@ connect_context_step(NMModemBroadband *self) } static NMActStageReturn -modem_act_stage1_prepare(NMModem * _self, - NMConnection * connection, +modem_act_stage1_prepare(NMModem *_self, + NMConnection *connection, NMDeviceStateReason *out_failure_reason) { NMModemBroadband *self = NM_MODEM_BROADBAND(_self); @@ -772,15 +764,15 @@ check_connection_compatible_with_modem(NMModem *_self, NMConnection *connection, /*****************************************************************************/ static gboolean -complete_connection(NMModem * modem, - const char * iface, - NMConnection * connection, +complete_connection(NMModem *modem, + const char *iface, + NMConnection *connection, NMConnection *const *existing_connections, - GError ** error) + GError **error) { NMModemBroadband *self = NM_MODEM_BROADBAND(modem); MMModemCapability modem_caps; - NMSettingPpp * s_ppp; + NMSettingPpp *s_ppp; modem_caps = mm_modem_get_current_capabilities(self->_priv.modem_iface); @@ -860,7 +852,7 @@ complete_connection(NMModem * modem, static gboolean get_user_pass(NMModem *modem, NMConnection *connection, const char **user, const char **pass) { - NMSettingGsm * s_gsm; + NMSettingGsm *s_gsm; NMSettingCdma *s_cdma; s_gsm = nm_connection_get_setting_gsm(connection); @@ -958,259 +950,257 @@ set_mm_enabled(NMModem *_self, gboolean enabled) } /*****************************************************************************/ -/* IPv4 method static */ -static gboolean -static_stage3_ip4_done(NMModemBroadband *self) +static void +stage3_ip_config_start(NMModem *modem, int addr_family, NMModemIPMethod ip_method) { - GError * error = NULL; - gs_unref_object NMIP4Config *config = NULL; - const char * data_port; - const char * address_string; - const char * gw_string; - guint32 address_network; - guint32 gw = 0; - NMPlatformIP4Address address; - const char ** dns; - guint i; - guint32 ip4_route_table, ip4_route_metric; - NMPlatformIP4Route * r; - guint32 mtu_n; - - g_return_val_if_fail(self->_priv.ipv4_config, FALSE); - g_return_val_if_fail(self->_priv.bearer, FALSE); - - self->_priv.idle_id_ip4 = 0; - - _LOGI("IPv4 static configuration:"); - - /* Fully fail if invalid IP address retrieved */ - address_string = mm_bearer_ip_config_get_address(self->_priv.ipv4_config); - if (!address_string - || !nm_utils_parse_inaddr_bin(AF_INET, address_string, NULL, &address_network)) { - error = - g_error_new(NM_DEVICE_ERROR, + const int IS_IPv4 = NM_IS_IPv4(addr_family); + NMModemBroadband *self = NM_MODEM_BROADBAND(modem); + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + char sbuf[sizeof(_nm_utils_to_string_buffer)]; + gs_free_error GError *error = NULL; + const char *data_port; + const char *address_string; + const char **dns; + guint i; + gboolean do_auto = FALSE; + int ifindex; + NMUtilsIPv6IfaceId iid_data; + const NMUtilsIPv6IfaceId *iid = NULL; + + if (IS_IPv4) { + g_return_if_fail(self->_priv.ipv4_config); + g_return_if_fail(self->_priv.bearer); + + if (ip_method == NM_MODEM_IP_METHOD_AUTO) { + do_auto = TRUE; + goto out; + } + } else { + g_return_if_fail(self->_priv.ipv6_config); + } + + if (IS_IPv4) { + guint32 address_network; + guint32 gw = 0; + NMPlatformIP4Address address; + NMPlatformIP4Route route; + guint32 mtu_n; + const char *gw_string; + + _LOGI("IPv4 static configuration:"); + + /* Fully fail if invalid IP address retrieved */ + address_string = mm_bearer_ip_config_get_address(self->_priv.ipv4_config); + if (!address_string + || !nm_utils_parse_inaddr_bin(AF_INET, address_string, NULL, &address_network)) { + g_set_error(&error, + NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION, "(%s) retrieving IP4 configuration failed: invalid address given %s%s%s", nm_modem_get_uid(NM_MODEM(self)), NM_PRINT_FMT_QUOTE_STRING(address_string)); - goto out; - } + goto out; + } - /* Missing gateway not a hard failure */ - gw_string = mm_bearer_ip_config_get_gateway(self->_priv.ipv4_config); - if (gw_string && !nm_utils_parse_inaddr_bin(AF_INET, gw_string, NULL, &gw)) { - error = - g_error_new(NM_DEVICE_ERROR, + /* Missing gateway not a hard failure */ + gw_string = mm_bearer_ip_config_get_gateway(self->_priv.ipv4_config); + if (gw_string && !nm_utils_parse_inaddr_bin(AF_INET, gw_string, NULL, &gw)) { + g_set_error(&error, + NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION, "(%s) retrieving IP4 configuration failed: invalid gateway address \"%s\"", nm_modem_get_uid(NM_MODEM(self)), gw_string); - goto out; - } - - data_port = mm_bearer_get_interface(self->_priv.bearer); - g_return_val_if_fail(data_port, FALSE); - config = nm_ip4_config_new(nm_platform_get_multi_idx(NM_PLATFORM_GET), - nm_platform_link_get_ifindex(NM_PLATFORM_GET, data_port)); - - memset(&address, 0, sizeof(address)); - address.address = address_network; - address.peer_address = address_network; - address.plen = mm_bearer_ip_config_get_prefix(self->_priv.ipv4_config); - address.addr_source = NM_IP_CONFIG_SOURCE_WWAN; - if (address.plen <= 32) - nm_ip4_config_add_address(config, &address); - - _LOGI(" address %s/%d", address_string, address.plen); - - nm_modem_get_route_parameters(NM_MODEM(self), &ip4_route_table, &ip4_route_metric, NULL, NULL); - r = &(NMPlatformIP4Route){ - .rt_source = NM_IP_CONFIG_SOURCE_WWAN, - .gateway = gw, - .table_coerced = nm_platform_route_table_coerce(ip4_route_table), - .metric = ip4_route_metric, - }; - nm_ip4_config_add_route(config, r, NULL); - _LOGI(" gateway %s", gw_string); - - /* DNS servers */ - dns = mm_bearer_ip_config_get_dns(self->_priv.ipv4_config); - for (i = 0; dns && dns[i]; i++) { - if (nm_utils_parse_inaddr_bin(AF_INET, dns[i], NULL, &address_network) - && address_network > 0) { - nm_ip4_config_add_nameserver(config, address_network); - _LOGI(" DNS %s", dns[i]); + goto out; } - } -#if MM_CHECK_VERSION(1, 4, 0) - mtu_n = mm_bearer_ip_config_get_mtu(self->_priv.ipv4_config); - if (mtu_n) { - nm_ip4_config_set_mtu(config, mtu_n, NM_IP_CONFIG_SOURCE_WWAN); - _LOGI(" MTU %u", mtu_n); - } -#endif - -out: - g_signal_emit_by_name(self, NM_MODEM_IP4_CONFIG_RESULT, config, error); - g_clear_error(&error); - return FALSE; -} + data_port = mm_bearer_get_interface(self->_priv.bearer); + g_return_if_fail(data_port); -static NMActStageReturn -static_stage3_ip4_config_start(NMModem * modem, - NMActRequest * req, - NMDeviceStateReason *out_failure_reason) -{ - NMModemBroadband * self = NM_MODEM_BROADBAND(modem); - NMModemBroadbandPrivate *priv = NM_MODEM_BROADBAND_GET_PRIVATE(self); + ifindex = nm_platform_link_get_ifindex(NM_PLATFORM_GET, data_port); + if (ifindex <= 0) { + g_set_error(&error, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_INVALID_CONNECTION, + "(%s) data port %s not found", + nm_modem_get_uid(NM_MODEM(self)), + data_port); + goto out; + } - /* We schedule it in an idle just to follow the same logic as in the - * generic modem implementation. */ - nm_clear_g_source(&priv->idle_id_ip4); - priv->idle_id_ip4 = g_idle_add((GSourceFunc) static_stage3_ip4_done, self); + l3cd = nm_l3_config_data_new(nm_platform_get_multi_idx(NM_PLATFORM_GET), + ifindex, + NM_IP_CONFIG_SOURCE_WWAN); + + address = (NMPlatformIP4Address){ + .address = address_network, + .peer_address = address_network, + .plen = mm_bearer_ip_config_get_prefix(self->_priv.ipv4_config), + .addr_source = NM_IP_CONFIG_SOURCE_WWAN, + }; + if (address.plen <= 32) + nm_l3_config_data_add_address_4(l3cd, &address); + + _LOGI(" address %s", nm_platform_ip4_address_to_string(&address, sbuf, sizeof(sbuf))); + + route = (NMPlatformIP4Route){ + .rt_source = NM_IP_CONFIG_SOURCE_WWAN, + .gateway = gw, + .table_any = TRUE, + .table_coerced = 0, + .metric_any = TRUE, + .metric = 0, + }; + nm_l3_config_data_add_route_4(l3cd, &route); + _LOGI(" gateway %s", gw_string); + + dns = mm_bearer_ip_config_get_dns(self->_priv.ipv4_config); + for (i = 0; dns && dns[i]; i++) { + if (nm_utils_parse_inaddr_bin(AF_INET, dns[i], NULL, &address_network) + && address_network > 0) { + nm_l3_config_data_add_nameserver(l3cd, AF_INET, &address_network); + _LOGI(" DNS %s", dns[i]); + } + } - return NM_ACT_STAGE_RETURN_POSTPONE; -} +#if MM_CHECK_VERSION(1, 4, 0) + mtu_n = mm_bearer_ip_config_get_mtu(self->_priv.ipv4_config); + if (mtu_n) { + nm_l3_config_data_set_mtu(l3cd, mtu_n); + _LOGI(" MTU %u", mtu_n); + } +#endif + } else { + NMPlatformIP6Address address; + + address_string = mm_bearer_ip_config_get_address(self->_priv.ipv6_config); + if (!address_string) { + /* DHCP/SLAAC is allowed to skip addresses; other methods require it */ + if (ip_method != NM_MODEM_IP_METHOD_AUTO) { + g_set_error(&error, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_INVALID_CONNECTION, + "(%s) retrieving IPv6 configuration failed: no address given", + nm_modem_get_uid(NM_MODEM(self))); + } + goto out; + } -/*****************************************************************************/ -/* IPv6 method static */ + address = (NMPlatformIP6Address){}; -static gboolean -stage3_ip6_done(NMModemBroadband *self) -{ - GError * error = NULL; - NMIP6Config * config = NULL; - const char * data_port; - const char * address_string; - NMPlatformIP6Address address; - NMModemIPMethod ip_method; - const char ** dns; - guint i; - - g_return_val_if_fail(self->_priv.ipv6_config, FALSE); - - self->_priv.idle_id_ip6 = 0; - memset(&address, 0, sizeof(address)); - - ip_method = get_bearer_ip_method(self->_priv.ipv6_config); - - address_string = mm_bearer_ip_config_get_address(self->_priv.ipv6_config); - if (!address_string) { - /* DHCP/SLAAC is allowed to skip addresses; other methods require it */ - if (ip_method != NM_MODEM_IP_METHOD_AUTO) { - error = g_error_new(NM_DEVICE_ERROR, - NM_DEVICE_ERROR_INVALID_CONNECTION, - "(%s) retrieving IPv6 configuration failed: no address given", - nm_modem_get_uid(NM_MODEM(self))); + if (!inet_pton(AF_INET6, address_string, &address.address)) { + g_set_error(&error, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_INVALID_CONNECTION, + "(%s) retrieving IPv6 configuration failed: invalid address given '%s'", + nm_modem_get_uid(NM_MODEM(self)), + address_string); + goto out; } - goto out; - } - /* Fail if invalid IP address retrieved */ - if (!inet_pton(AF_INET6, address_string, (void *) &(address.address))) { - error = g_error_new(NM_DEVICE_ERROR, - NM_DEVICE_ERROR_INVALID_CONNECTION, - "(%s) retrieving IPv6 configuration failed: invalid address given '%s'", - nm_modem_get_uid(NM_MODEM(self)), - address_string); - goto out; - } + data_port = mm_bearer_get_interface(self->_priv.bearer); + g_return_if_fail(data_port); - _LOGI("IPv6 base configuration:"); + ifindex = nm_platform_link_get_ifindex(NM_PLATFORM_GET, data_port); + if (ifindex <= 0) { + g_set_error(&error, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_INVALID_CONNECTION, + "(%s) data port %s not found", + nm_modem_get_uid(NM_MODEM(self)), + data_port); + goto out; + } - data_port = mm_bearer_get_interface(self->_priv.bearer); - g_return_val_if_fail(data_port, FALSE); + _LOGI("IPv6 base configuration:"); - config = nm_ip6_config_new(nm_platform_get_multi_idx(NM_PLATFORM_GET), - nm_platform_link_get_ifindex(NM_PLATFORM_GET, data_port)); + l3cd = nm_l3_config_data_new(nm_platform_get_multi_idx(NM_PLATFORM_GET), + ifindex, + NM_IP_CONFIG_SOURCE_WWAN); - address.plen = mm_bearer_ip_config_get_prefix(self->_priv.ipv6_config); - if (address.plen <= 128) - nm_ip6_config_add_address(config, &address); + do_auto = TRUE; - _LOGI(" address %s/%d", address_string, address.plen); + address.plen = mm_bearer_ip_config_get_prefix(self->_priv.ipv6_config); + if (address.plen <= 128) { + if (IN6_IS_ADDR_LINKLOCAL(&address.address)) { + iid_data.id = ((guint64 *) (&address.address.s6_addr))[1]; + iid = &iid_data; + } else + do_auto = FALSE; + nm_l3_config_data_add_address_6(l3cd, &address); + } - address_string = mm_bearer_ip_config_get_gateway(self->_priv.ipv6_config); - if (address_string) { - guint32 ip6_route_table, ip6_route_metric; + _LOGI(" address %s (slaac %s)", + nm_platform_ip6_address_to_string(&address, sbuf, sizeof(sbuf)), + do_auto ? "enabled" : "disabled"); - if (inet_pton(AF_INET6, address_string, &address.address) != 1) { - error = - g_error_new(NM_DEVICE_ERROR, + address_string = mm_bearer_ip_config_get_gateway(self->_priv.ipv6_config); + if (address_string) { + if (inet_pton(AF_INET6, address_string, &address.address) != 1) { + g_set_error(&error, + NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION, "(%s) retrieving IPv6 configuration failed: invalid gateway given '%s'", nm_modem_get_uid(NM_MODEM(self)), address_string); - goto out; - } + goto out; + } - nm_modem_get_route_parameters(NM_MODEM(self), - NULL, - NULL, - &ip6_route_table, - &ip6_route_metric); - { - const NMPlatformIP6Route r = { - .rt_source = NM_IP_CONFIG_SOURCE_WWAN, - .gateway = address.address, - .table_coerced = nm_platform_route_table_coerce(ip6_route_table), - .metric = ip6_route_metric, - }; - - _LOGI(" gateway %s", address_string); - nm_ip6_config_add_route(config, &r, NULL); + { + const NMPlatformIP6Route r = { + .rt_source = NM_IP_CONFIG_SOURCE_WWAN, + .gateway = address.address, + .table_any = TRUE, + .table_coerced = 0, + .metric_any = TRUE, + .metric = 0, + }; + + _LOGI(" gateway %s", address_string); + nm_l3_config_data_add_route_6(l3cd, &r); + } + } else if (ip_method == NM_MODEM_IP_METHOD_STATIC) { + /* Gateway required for the 'static' method */ + g_set_error(&error, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_INVALID_CONNECTION, + "(%s) retrieving IPv6 configuration failed: missing gateway", + nm_modem_get_uid(NM_MODEM(self))); + goto out; } - } else if (ip_method == NM_MODEM_IP_METHOD_STATIC) { - /* Gateway required for the 'static' method */ - error = g_error_new(NM_DEVICE_ERROR, - NM_DEVICE_ERROR_INVALID_CONNECTION, - "(%s) retrieving IPv6 configuration failed: missing gateway", - nm_modem_get_uid(NM_MODEM(self))); - goto out; - } - /* DNS servers */ - dns = mm_bearer_ip_config_get_dns(self->_priv.ipv6_config); - for (i = 0; dns && dns[i]; i++) { - struct in6_addr addr; + dns = mm_bearer_ip_config_get_dns(self->_priv.ipv6_config); + for (i = 0; dns && dns[i]; i++) { + struct in6_addr addr; - if (inet_pton(AF_INET6, dns[i], &addr)) { - nm_ip6_config_add_nameserver(config, &addr); - _LOGI(" DNS %s", dns[i]); + if (inet_pton(AF_INET6, dns[i], &addr)) { + nm_l3_config_data_add_nameserver(l3cd, AF_INET6, &addr); + _LOGI(" DNS %s", dns[i]); + } } } out: - nm_modem_emit_ip6_config_result(NM_MODEM(self), config, error); - g_clear_object(&config); - g_clear_error(&error); - return FALSE; -} - -static NMActStageReturn -stage3_ip6_config_request(NMModem *modem, NMDeviceStateReason *out_failure_reason) -{ - NMModemBroadband * self = NM_MODEM_BROADBAND(modem); - NMModemBroadbandPrivate *priv = NM_MODEM_BROADBAND_GET_PRIVATE(self); - - /* We schedule it in an idle just to follow the same logic as in the - * generic modem implementation. */ - nm_clear_g_source(&priv->idle_id_ip6); - priv->idle_id_ip6 = g_idle_add((GSourceFunc) stage3_ip6_done, self); + if (error) { + nm_modem_emit_signal_new_config_failure(modem, + addr_family, + NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE, + error); + return; + } - return NM_ACT_STAGE_RETURN_POSTPONE; + nm_modem_emit_signal_new_config_success(modem, addr_family, l3cd, do_auto, iid); } /*****************************************************************************/ /* Disconnect */ typedef struct { - NMModemBroadband * self; + NMModemBroadband *self; _NMModemDisconnectCallback callback; gpointer callback_user_data; - GCancellable * cancellable; + GCancellable *cancellable; gboolean warn; } DisconnectContext; @@ -1227,7 +1217,7 @@ disconnect_context_complete(DisconnectContext *ctx, GError *error) static void disconnect_context_complete_on_idle(gpointer user_data, GCancellable *cancellable) { - DisconnectContext *ctx = user_data; + DisconnectContext *ctx = user_data; gs_free_error GError *cancelled_error = NULL; g_cancellable_set_error_if_cancelled(cancellable, &cancelled_error); @@ -1237,9 +1227,9 @@ disconnect_context_complete_on_idle(gpointer user_data, GCancellable *cancellabl static void simple_disconnect_ready(GObject *source_object, GAsyncResult *res, gpointer user_data) { - MMModemSimple * modem_iface = MM_MODEM_SIMPLE(source_object); - DisconnectContext *ctx = user_data; - gs_free_error GError *error = NULL; + MMModemSimple *modem_iface = MM_MODEM_SIMPLE(source_object); + DisconnectContext *ctx = user_data; + gs_free_error GError *error = NULL; if (!mm_modem_simple_disconnect_finish(modem_iface, res, &error)) { if (ctx->warn && !g_error_matches(error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN)) { @@ -1253,13 +1243,13 @@ simple_disconnect_ready(GObject *source_object, GAsyncResult *res, gpointer user } static void -disconnect(NMModem * modem, +disconnect(NMModem *modem, gboolean warn, - GCancellable * cancellable, + GCancellable *cancellable, _NMModemDisconnectCallback callback, gpointer user_data) { - NMModemBroadband * self = NM_MODEM_BROADBAND(modem); + NMModemBroadband *self = NM_MODEM_BROADBAND(modem); DisconnectContext *ctx; connect_context_clear(self); @@ -1336,11 +1326,11 @@ mm_state_to_nm(MMModemState mm_state) } static void -modem_state_changed(MMModem * modem, +modem_state_changed(MMModem *modem, MMModemState old_state, MMModemState new_state, MMModemStateChangeReason reason, - NMModemBroadband * self) + NMModemBroadband *self) { /* After the SIM is unlocked MM1 will move the device to INITIALIZING which * is an unavailable state. That makes state handling confusing here, so @@ -1378,7 +1368,7 @@ static void get_sim_ready(MMModem *modem, GAsyncResult *res, NMModemBroadband *self) { GError *error = NULL; - MMSim * new_sim; + MMSim *new_sim; new_sim = mm_modem_get_sim_finish(modem, res, &error); if (new_sim != self->_priv.sim_iface) { @@ -1512,12 +1502,12 @@ nm_modem_broadband_init(NMModemBroadband *self) NMModem * nm_modem_broadband_new(GObject *object, GError **error) { - MMObject * modem_object; - MMModem * modem_iface; - MMModem3gpp * modem_3gpp_iface; + MMObject *modem_object; + MMModem *modem_iface; + MMModem3gpp *modem_3gpp_iface; const char *const *drivers; - const char * operator_code = NULL; - gs_free char * driver = NULL; + const char *operator_code = NULL; + gs_free char *driver = NULL; g_return_val_if_fail(MM_IS_OBJECT(object), NULL); modem_object = MM_OBJECT(object); @@ -1561,30 +1551,27 @@ nm_modem_broadband_new(GObject *object, GError **error) static void dispose(GObject *object) { - NMModemBroadband * self = NM_MODEM_BROADBAND(object); + NMModemBroadband *self = NM_MODEM_BROADBAND(object); NMModemBroadbandPrivate *priv = NM_MODEM_BROADBAND_GET_PRIVATE(self); - nm_clear_g_source(&priv->idle_id_ip4); - nm_clear_g_source(&priv->idle_id_ip6); - connect_context_clear(self); - g_clear_object(&self->_priv.ipv4_config); - g_clear_object(&self->_priv.ipv6_config); - g_clear_object(&self->_priv.bearer); + g_clear_object(&priv->ipv4_config); + g_clear_object(&priv->ipv6_config); + g_clear_object(&priv->bearer); - if (self->_priv.modem_iface) { - g_signal_handlers_disconnect_by_data(self->_priv.modem_iface, self); - g_clear_object(&self->_priv.modem_iface); + if (priv->modem_iface) { + g_signal_handlers_disconnect_by_data(priv->modem_iface, self); + g_clear_object(&priv->modem_iface); } - if (self->_priv.modem_3gpp_iface) { - g_signal_handlers_disconnect_by_data(self->_priv.modem_3gpp_iface, self); - g_clear_object(&self->_priv.modem_3gpp_iface); + if (priv->modem_3gpp_iface) { + g_signal_handlers_disconnect_by_data(priv->modem_3gpp_iface, self); + g_clear_object(&priv->modem_3gpp_iface); } - g_clear_object(&self->_priv.simple_iface); - g_clear_object(&self->_priv.sim_iface); - g_clear_object(&self->_priv.modem_object); + g_clear_object(&priv->simple_iface); + g_clear_object(&priv->sim_iface); + g_clear_object(&priv->modem_object); G_OBJECT_CLASS(nm_modem_broadband_parent_class)->dispose(object); } @@ -1600,8 +1587,7 @@ nm_modem_broadband_class_init(NMModemBroadbandClass *klass) object_class->set_property = set_property; modem_class->get_capabilities = get_capabilities; - modem_class->static_stage3_ip4_config_start = static_stage3_ip4_config_start; - modem_class->stage3_ip6_config_request = stage3_ip6_config_request; + modem_class->stage3_ip_config_start = stage3_ip_config_start; modem_class->disconnect = disconnect; modem_class->deactivate_cleanup = deactivate_cleanup; modem_class->set_mm_enabled = set_mm_enabled; diff --git a/src/core/devices/wwan/nm-modem-manager.c b/src/core/devices/wwan/nm-modem-manager.c index 8d087d13..4a89f38e 100644 --- a/src/core/devices/wwan/nm-modem-manager.c +++ b/src/core/devices/wwan/nm-modem-manager.c @@ -45,7 +45,7 @@ typedef struct { GCancellable *main_cancellable; struct { - MMManager * manager; + MMManager *manager; GCancellable *poke_cancellable; gulong handle_name_owner_changed_id; gulong handle_object_added_id; @@ -61,15 +61,15 @@ typedef struct { LOG_AVAILABLE_NO, } log_available : 3; - GDBusProxy * proxy; + GDBusProxy *proxy; GCancellable *proxy_cancellable; guint proxy_ref_count; - char * proxy_name_owner; + char *proxy_name_owner; } modm; #if WITH_OFONO struct { - GDBusProxy * proxy; + GDBusProxy *proxy; GCancellable *cancellable; } ofono; #endif @@ -111,7 +111,7 @@ static void handle_new_modem(NMModemManager *self, NMModem *modem) { NMModemManagerPrivate *priv = NM_MODEM_MANAGER_GET_PRIVATE(self); - const char * path; + const char *path; path = nm_modem_get_path(modem); if (g_hash_table_lookup(priv->modems, path)) { @@ -163,10 +163,10 @@ static void modm_handle_object_added(MMManager *modem_manager, MMObject *modem_object, NMModemManager *self) { NMModemManagerPrivate *priv = NM_MODEM_MANAGER_GET_PRIVATE(self); - const char * path; - MMModem * modem_iface; - NMModem * modem; - GError * error = NULL; + const char *path; + MMModem *modem_iface; + NMModem *modem; + GError *error = NULL; /* Ensure we don't have the same modem already */ path = mm_object_get_path(modem_object); @@ -201,8 +201,8 @@ static void modm_handle_object_removed(MMManager *manager, MMObject *modem_object, NMModemManager *self) { NMModemManagerPrivate *priv = NM_MODEM_MANAGER_GET_PRIVATE(self); - NMModem * modem; - const char * path; + NMModem *modem; + const char *path; path = mm_object_get_path(modem_object); modem = (NMModem *) g_hash_table_lookup(priv->modems, path); @@ -217,7 +217,7 @@ static void modm_manager_available(NMModemManager *self) { NMModemManagerPrivate *priv = NM_MODEM_MANAGER_GET_PRIVATE(self); - GList * modems, *l; + GList *modems, *l; if (priv->modm.log_available != LOG_AVAILABLE_YES) { _LOGI("ModemManager %savailable", priv->modm.log_available ? "now " : ""); @@ -235,7 +235,7 @@ static void modm_handle_name_owner_changed(MMManager *modem_manager, GParamSpec *pspec, NMModemManager *self) { NMModemManagerPrivate *priv = NM_MODEM_MANAGER_GET_PRIVATE(self); - char * name_owner; + char *name_owner; /* Quit poking, if any */ nm_clear_g_source(&priv->modm.relaunch_id); @@ -273,9 +273,9 @@ modm_handle_name_owner_changed(MMManager *modem_manager, GParamSpec *pspec, NMMo static void modm_manager_poke_cb(GObject *connection, GAsyncResult *res, gpointer user_data) { - NMModemManager * self; - NMModemManagerPrivate *priv; - gs_free_error GError *error = NULL; + NMModemManager *self; + NMModemManagerPrivate *priv; + gs_free_error GError *error = NULL; gs_unref_variant GVariant *result = NULL; result = g_dbus_connection_call_finish(G_DBUS_CONNECTION(connection), res, &error); @@ -327,7 +327,7 @@ static void modm_manager_check_name_owner(NMModemManager *self) { NMModemManagerPrivate *priv = NM_MODEM_MANAGER_GET_PRIVATE(self); - gs_free char * name_owner = NULL; + gs_free char *name_owner = NULL; name_owner = g_dbus_object_manager_client_get_name_owner( G_DBUS_OBJECT_MANAGER_CLIENT(priv->modm.manager)); @@ -344,10 +344,10 @@ modm_manager_check_name_owner(NMModemManager *self) static void modm_manager_new_cb(GObject *source, GAsyncResult *res, gpointer user_data) { - NMModemManager * self; + NMModemManager *self; NMModemManagerPrivate *priv; - gs_free_error GError *error = NULL; - MMManager * modem_manager; + gs_free_error GError *error = NULL; + MMManager *modem_manager; modem_manager = mm_manager_new_finish(res, &error); if (!modem_manager && g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) @@ -445,7 +445,7 @@ static void modm_proxy_name_owner_reset(NMModemManager *self) { NMModemManagerPrivate *priv = NM_MODEM_MANAGER_GET_PRIVATE(self); - char * name = NULL; + char *name = NULL; if (priv->modm.proxy) name = g_dbus_proxy_get_name_owner(priv->modm.proxy); @@ -469,10 +469,10 @@ modm_proxy_name_owner_changed_cb(GObject *object, GParamSpec *pspec, gpointer us static void modm_proxy_new_cb(GObject *source_object, GAsyncResult *result, gpointer user_data) { - NMModemManager * self; + NMModemManager *self; NMModemManagerPrivate *priv; - GDBusProxy * proxy; - gs_free_error GError *error = NULL; + GDBusProxy *proxy; + gs_free_error GError *error = NULL; proxy = g_dbus_proxy_new_for_bus_finish(result, &error); if (!proxy && g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) @@ -567,7 +567,7 @@ static void ofono_create_modem(NMModemManager *self, const char *path) { NMModemManagerPrivate *priv = NM_MODEM_MANAGER_GET_PRIVATE(self); - NMModem * modem = NULL; + NMModem *modem = NULL; /* Ensure duplicate modems aren't created. Because we're not using the * ObjectManager interface there's a race during oFono startup where we @@ -585,15 +585,15 @@ ofono_create_modem(NMModemManager *self, const char *path) static void ofono_signal_cb(GDBusProxy *proxy, - char * sender_name, - char * signal_name, - GVariant * parameters, + char *sender_name, + char *signal_name, + GVariant *parameters, gpointer user_data) { - NMModemManager * self = NM_MODEM_MANAGER(user_data); + NMModemManager *self = NM_MODEM_MANAGER(user_data); NMModemManagerPrivate *priv = NM_MODEM_MANAGER_GET_PRIVATE(self); - char * object_path; - NMModem * modem; + char *object_path; + NMModem *modem; if (g_strcmp0(signal_name, "ModemAdded") == 0) { g_variant_get(parameters, "(oa{sv})", &object_path, NULL); @@ -619,12 +619,12 @@ ofono_signal_cb(GDBusProxy *proxy, static void ofono_enumerate_devices_done(GObject *proxy, GAsyncResult *res, gpointer user_data) { - NMModemManager * self; + NMModemManager *self; NMModemManagerPrivate *priv; - gs_free_error GError *error = NULL; - GVariant * results; - GVariantIter * iter; - const char * path; + gs_free_error GError *error = NULL; + GVariant *results; + GVariantIter *iter; + const char *path; results = g_dbus_proxy_call_finish(G_DBUS_PROXY(proxy), res, &error); if (!results && g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) @@ -651,7 +651,7 @@ static void ofono_check_name_owner(NMModemManager *self, gboolean first_invocation) { NMModemManagerPrivate *priv = NM_MODEM_MANAGER_GET_PRIVATE(self); - gs_free char * name_owner = NULL; + gs_free char *name_owner = NULL; name_owner = g_dbus_proxy_get_name_owner(G_DBUS_PROXY(priv->ofono.proxy)); if (name_owner) { @@ -670,7 +670,7 @@ ofono_check_name_owner(NMModemManager *self, gboolean first_invocation) self); } else { GHashTableIter iter; - NMModem * modem; + NMModem *modem; _LOGI("oFono is %savailable", first_invocation ? "not " : "no longer "); @@ -694,10 +694,10 @@ ofono_name_owner_changed(GDBusProxy *ofono_proxy, GParamSpec *pspec, NMModemMana static void ofono_proxy_new_cb(GObject *source_object, GAsyncResult *res, gpointer user_data) { - NMModemManager * self; + NMModemManager *self; NMModemManagerPrivate *priv; - gs_free_error GError *error = NULL; - GDBusProxy * proxy; + gs_free_error GError *error = NULL; + GDBusProxy *proxy; proxy = g_dbus_proxy_new_finish(res, &error); if (!proxy && g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) @@ -752,10 +752,10 @@ ofono_init_proxy(NMModemManager *self) static void bus_get_ready(GObject *source, GAsyncResult *res, gpointer user_data) { - NMModemManager * self; + NMModemManager *self; NMModemManagerPrivate *priv; - gs_free_error GError *error = NULL; - GDBusConnection * connection; + gs_free_error GError *error = NULL; + GDBusConnection *connection; connection = g_bus_get_finish(res, &error); if (!connection && g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) @@ -782,7 +782,7 @@ bus_get_ready(GObject *source, GAsyncResult *res, gpointer user_data) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMModemManager * self = NM_MODEM_MANAGER(object); + NMModemManager *self = NM_MODEM_MANAGER(object); NMModemManagerPrivate *priv = NM_MODEM_MANAGER_GET_PRIVATE(self); switch (prop_id) { @@ -812,7 +812,7 @@ nm_modem_manager_init(NMModemManager *self) static void dispose(GObject *object) { - NMModemManager * self = NM_MODEM_MANAGER(object); + NMModemManager *self = NM_MODEM_MANAGER(object); NMModemManagerPrivate *priv = NM_MODEM_MANAGER_GET_PRIVATE(self); nm_clear_g_cancellable(&priv->main_cancellable); diff --git a/src/core/devices/wwan/nm-modem-ofono.c b/src/core/devices/wwan/nm-modem-ofono.c index 78ad7b68..cac90d32 100644 --- a/src/core/devices/wwan/nm-modem-ofono.c +++ b/src/core/devices/wwan/nm-modem-ofono.c @@ -11,7 +11,7 @@ #include "devices/nm-device-private.h" #include "nm-modem.h" #include "libnm-platform/nm-platform.h" -#include "nm-ip4-config.h" +#include "nm-l3-config-data.h" #define VARIANT_IS_OF_TYPE_BOOLEAN(v) \ ((v) != NULL && (g_variant_is_of_type((v), G_VARIANT_TYPE_BOOLEAN))) @@ -47,7 +47,7 @@ typedef struct { gboolean modem_online; gboolean gprs_attached; - NMIP4Config *ip4_config; + NML3ConfigData *l3cd_4; } NMModemOfonoPrivate; struct _NMModemOfono { @@ -75,7 +75,7 @@ G_DEFINE_TYPE(NMModemOfono, nm_modem_ofono, NM_TYPE_MODEM) if (nm_logging_enabled(_level, (_NMLOG_DOMAIN))) { \ NMModemOfono *const __self = (self); \ char __prefix_name[128]; \ - const char * __uid; \ + const char *__uid; \ \ _nm_log(_level, \ (_NMLOG_DOMAIN), \ @@ -97,7 +97,7 @@ G_DEFINE_TYPE(NMModemOfono, nm_modem_ofono, NM_TYPE_MODEM) /*****************************************************************************/ static void -get_capabilities(NMModem * _self, +get_capabilities(NMModem *_self, NMDeviceModemCapabilities *modem_caps, NMDeviceModemCapabilities *current_caps) { @@ -112,7 +112,7 @@ update_modem_state(NMModemOfono *self) NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE(self); NMModemState state = nm_modem_get_state(NM_MODEM(self)); NMModemState new_state = NM_MODEM_STATE_DISABLED; - const char * reason = NULL; + const char *reason = NULL; _LOGI("'Attached': %s 'Online': %s 'IMSI': %s", priv->gprs_attached ? "true" : "false", @@ -137,10 +137,10 @@ update_modem_state(NMModemOfono *self) /* Disconnect */ typedef struct { - NMModemOfono * self; + NMModemOfono *self; _NMModemDisconnectCallback callback; gpointer callback_user_data; - GCancellable * cancellable; + GCancellable *cancellable; gboolean warn; } DisconnectContext; @@ -157,7 +157,7 @@ disconnect_context_complete(DisconnectContext *ctx, GError *error) static void disconnect_context_complete_on_idle(gpointer user_data, GCancellable *cancellable) { - DisconnectContext *ctx = user_data; + DisconnectContext *ctx = user_data; gs_free_error GError *error = NULL; if (!g_cancellable_set_error_if_cancelled(cancellable, &error)) { @@ -172,10 +172,10 @@ disconnect_context_complete_on_idle(gpointer user_data, GCancellable *cancellabl static void disconnect_done(GObject *source, GAsyncResult *result, gpointer user_data) { - DisconnectContext *ctx = user_data; - NMModemOfono * self = ctx->self; - gs_free_error GError *error = NULL; - gs_unref_variant GVariant *v = NULL; + DisconnectContext *ctx = user_data; + NMModemOfono *self = ctx->self; + gs_free_error GError *error = NULL; + gs_unref_variant GVariant *v = NULL; v = g_dbus_proxy_call_finish(G_DBUS_PROXY(source), result, &error); if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { @@ -193,15 +193,15 @@ disconnect_done(GObject *source, GAsyncResult *result, gpointer user_data) } static void -disconnect(NMModem * modem, +disconnect(NMModem *modem, gboolean warn, - GCancellable * cancellable, + GCancellable *cancellable, _NMModemDisconnectCallback callback, gpointer user_data) { - NMModemOfono * self = NM_MODEM_OFONO(modem); + NMModemOfono *self = NM_MODEM_OFONO(modem); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE(self); - DisconnectContext * ctx; + DisconnectContext *ctx; NMModemState state = nm_modem_get_state(NM_MODEM(self)); _LOGD("warn: %s modem_state: %s", warn ? "TRUE" : "FALSE", nm_modem_state_to_string(state)); @@ -235,12 +235,12 @@ disconnect(NMModem * modem, static void deactivate_cleanup(NMModem *modem, NMDevice *device, gboolean stop_ppp_manager) { - NMModemOfono * self = NM_MODEM_OFONO(modem); + NMModemOfono *self = NM_MODEM_OFONO(modem); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE(self); /* TODO: cancel SimpleConnect() if any */ - g_clear_object(&priv->ip4_config); + nm_clear_l3cd(&priv->l3cd_4); NM_MODEM_CLASS(nm_modem_ofono_parent_class) ->deactivate_cleanup(modem, device, stop_ppp_manager); @@ -249,9 +249,9 @@ deactivate_cleanup(NMModem *modem, NMDevice *device, gboolean stop_ppp_manager) static gboolean check_connection_compatible_with_modem(NMModem *modem, NMConnection *connection, GError **error) { - NMModemOfono * self = NM_MODEM_OFONO(modem); + NMModemOfono *self = NM_MODEM_OFONO(modem); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE(self); - const char * id; + const char *id; if (!_nm_connection_check_main_setting(connection, NM_SETTING_GSM_SETTING_NAME, NULL)) { nm_utils_error_set(error, @@ -290,7 +290,7 @@ check_connection_compatible_with_modem(NMModem *modem, NMConnection *connection, static void handle_sim_property(GDBusProxy *proxy, const char *property, GVariant *v, gpointer user_data) { - NMModemOfono * self = NM_MODEM_OFONO(user_data); + NMModemOfono *self = NM_MODEM_OFONO(user_data); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE(self); if (g_strcmp0(property, "SubscriberIdentity") == 0 && VARIANT_IS_OF_TYPE_STRING(v)) { @@ -324,14 +324,14 @@ sim_property_changed(GDBusProxy *proxy, const char *property, GVariant *v, gpoin static void sim_get_properties_done(GObject *source, GAsyncResult *result, gpointer user_data) { - NMModemOfono * self; - NMModemOfonoPrivate *priv; - gs_free_error GError *error = NULL; + NMModemOfono *self; + NMModemOfonoPrivate *priv; + gs_free_error GError *error = NULL; gs_unref_variant GVariant *v_properties = NULL; gs_unref_variant GVariant *v_dict = NULL; gs_unref_variant GVariant *v = NULL; GVariantIter i; - const char * property; + const char *property; v_properties = _nm_dbus_proxy_call_finish(G_DBUS_PROXY(source), result, G_VARIANT_TYPE("(a{sv})"), &error); @@ -377,10 +377,10 @@ sim_get_properties_done(GObject *source, GAsyncResult *result, gpointer user_dat static void _sim_proxy_new_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - NMModemOfono * self; - NMModemOfonoPrivate *priv; + NMModemOfono *self; + NMModemOfonoPrivate *priv; gs_free_error GError *error = NULL; - GDBusProxy * proxy; + GDBusProxy *proxy; proxy = g_dbus_proxy_new_for_bus_finish(result, &error); if (!proxy && g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) @@ -451,7 +451,7 @@ handle_sim_iface(NMModemOfono *self, gboolean found) static void handle_connman_property(GDBusProxy *proxy, const char *property, GVariant *v, gpointer user_data) { - NMModemOfono * self = NM_MODEM_OFONO(user_data); + NMModemOfono *self = NM_MODEM_OFONO(user_data); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE(self); if (g_strcmp0(property, "Attached") == 0 && VARIANT_IS_OF_TYPE_BOOLEAN(v)) { @@ -483,14 +483,14 @@ connman_property_changed(GDBusProxy *proxy, const char *property, GVariant *v, g static void connman_get_properties_done(GObject *source, GAsyncResult *result, gpointer user_data) { - NMModemOfono * self; - NMModemOfonoPrivate *priv; - gs_free_error GError *error = NULL; + NMModemOfono *self; + NMModemOfonoPrivate *priv; + gs_free_error GError *error = NULL; gs_unref_variant GVariant *v_properties = NULL; gs_unref_variant GVariant *v_dict = NULL; gs_unref_variant GVariant *v = NULL; GVariantIter i; - const char * property; + const char *property; v_properties = _nm_dbus_proxy_call_finish(G_DBUS_PROXY(source), result, G_VARIANT_TYPE("(a{sv})"), &error); @@ -528,10 +528,10 @@ connman_get_properties_done(GObject *source, GAsyncResult *result, gpointer user static void _connman_proxy_new_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - NMModemOfono * self; - NMModemOfonoPrivate *priv; + NMModemOfono *self; + NMModemOfonoPrivate *priv; gs_free_error GError *error = NULL; - GDBusProxy * proxy; + GDBusProxy *proxy; proxy = g_dbus_proxy_new_for_bus_finish(result, &error); if (!proxy && g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) @@ -606,7 +606,7 @@ handle_connman_iface(NMModemOfono *self, gboolean found) static void handle_modem_property(GDBusProxy *proxy, const char *property, GVariant *v, gpointer user_data) { - NMModemOfono * self = NM_MODEM_OFONO(user_data); + NMModemOfono *self = NM_MODEM_OFONO(user_data); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE(self); if ((g_strcmp0(property, "Online") == 0) && VARIANT_IS_OF_TYPE_BOOLEAN(v)) { @@ -655,14 +655,14 @@ modem_property_changed(GDBusProxy *proxy, const char *property, GVariant *v, gpo static void modem_get_properties_done(GObject *source, GAsyncResult *result, gpointer user_data) { - NMModemOfono * self; - NMModemOfonoPrivate *priv; - gs_free_error GError *error = NULL; + NMModemOfono *self; + NMModemOfonoPrivate *priv; + gs_free_error GError *error = NULL; gs_unref_variant GVariant *v_properties = NULL; gs_unref_variant GVariant *v_dict = NULL; - GVariant * v; + GVariant *v; GVariantIter i; - const char * property; + const char *property; v_properties = _nm_dbus_proxy_call_finish(G_DBUS_PROXY(source), result, G_VARIANT_TYPE("(a{sv})"), &error); @@ -704,10 +704,10 @@ modem_get_properties_done(GObject *source, GAsyncResult *result, gpointer user_d static void stage1_prepare_done(GObject *source, GAsyncResult *result, gpointer user_data) { - NMModemOfono * self; - NMModemOfonoPrivate *priv; - gs_free_error GError *error = NULL; - gs_unref_variant GVariant *v = NULL; + NMModemOfono *self; + NMModemOfonoPrivate *priv; + gs_free_error GError *error = NULL; + gs_unref_variant GVariant *v = NULL; v = g_dbus_proxy_call_finish(G_DBUS_PROXY(source), result, &error); if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) @@ -732,17 +732,17 @@ stage1_prepare_done(GObject *source, GAsyncResult *result, gpointer user_data) static void handle_settings(GVariant *v_dict, gpointer user_data) { - NMModemOfono * self = NM_MODEM_OFONO(user_data); + NMModemOfono *self = NM_MODEM_OFONO(user_data); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE(self); - NMPlatformIP4Address addr; + char sbuf[sizeof(_nm_utils_to_string_buffer)]; + NMPlatformIP4Address address; gboolean ret = FALSE; - const char * interface; - const char * s; - const char ** array, **iter; + const char *interface; + const char *s; + const char **array; guint32 address_network, gateway_network; - guint32 ip4_route_table, ip4_route_metric; int ifindex; - GError * error = NULL; + GError *error = NULL; //_LOGD("PropertyChanged: %s", property); @@ -773,12 +773,14 @@ handle_settings(GVariant *v_dict, gpointer user_data) } ifindex = nm_modem_get_ip_ifindex(NM_MODEM(self)); - nm_assert(ifindex > 0); + g_return_if_fail(ifindex > 0); - /* TODO: verify handling of ip4_config; check other places it's used... */ - g_clear_object(&priv->ip4_config); + /* TODO: verify handling of l3cd_4; check other places it's used... */ + nm_clear_l3cd(&priv->l3cd_4); - priv->ip4_config = nm_ip4_config_new(nm_platform_get_multi_idx(NM_PLATFORM_GET), ifindex); + priv->l3cd_4 = nm_l3_config_data_new(nm_platform_get_multi_idx(NM_PLATFORM_GET), + ifindex, + NM_IP_CONFIG_SOURCE_WWAN); if (!g_variant_lookup(v_dict, "Address", "&s", &s)) { _LOGW("Settings 'Address' missing"); @@ -788,10 +790,12 @@ handle_settings(GVariant *v_dict, gpointer user_data) _LOGW("can't convert 'Address' %s to addr", s ?: ""); goto out; } - memset(&addr, 0, sizeof(addr)); - addr.ifindex = ifindex; - addr.address = address_network; - addr.addr_source = NM_IP_CONFIG_SOURCE_WWAN; + + address = (NMPlatformIP4Address){ + .ifindex = ifindex, + .address = address_network, + .addr_source = NM_IP_CONFIG_SOURCE_WWAN, + }; if (!g_variant_lookup(v_dict, "Netmask", "&s", &s)) { _LOGW("Settings 'Netmask' missing"); @@ -801,10 +805,10 @@ handle_settings(GVariant *v_dict, gpointer user_data) _LOGW("invalid 'Netmask': %s", s ?: ""); goto out; } - addr.plen = nm_utils_ip4_netmask_to_prefix(address_network); + address.plen = nm_utils_ip4_netmask_to_prefix(address_network); - _LOGI("Address: %s", nm_platform_ip4_address_to_string(&addr, NULL, 0)); - nm_ip4_config_add_address(priv->ip4_config, &addr); + _LOGI("Address: %s", nm_platform_ip4_address_to_string(&address, sbuf, sizeof(sbuf))); + nm_l3_config_data_add_address_4(priv->l3cd_4, &address); if (!g_variant_lookup(v_dict, "Gateway", "&s", &s) || !s) { _LOGW("Settings 'Gateway' missing"); @@ -814,17 +818,18 @@ handle_settings(GVariant *v_dict, gpointer user_data) _LOGW("invalid 'Gateway': %s", s); goto out; } - nm_modem_get_route_parameters(NM_MODEM(self), &ip4_route_table, &ip4_route_metric, NULL, NULL); { const NMPlatformIP4Route r = { .rt_source = NM_IP_CONFIG_SOURCE_WWAN, .gateway = gateway_network, - .table_coerced = nm_platform_route_table_coerce(ip4_route_table), - .metric = ip4_route_metric, + .table_any = TRUE, + .table_coerced = 0, + .metric_any = TRUE, + .metric = 0, }; _LOGI("Gateway: %s", s); - nm_ip4_config_add_route(priv->ip4_config, &r, NULL); + nm_l3_config_data_add_route_4(priv->l3cd_4, &r); } if (!g_variant_lookup(v_dict, "DomainNameServers", "^a&s", &array)) { @@ -832,52 +837,48 @@ handle_settings(GVariant *v_dict, gpointer user_data) goto out; } if (array) { - for (iter = array; *iter; iter++) { - if (nm_utils_parse_inaddr_bin(AF_INET, *iter, NULL, &address_network) - && address_network) { - _LOGI("DNS: %s", *iter); - nm_ip4_config_add_nameserver(priv->ip4_config, address_network); - } else { - _LOGW("invalid NameServer: %s", *iter); + gboolean any_good = FALSE; + + for (; array[0]; array++) { + if (!nm_utils_parse_inaddr_bin(AF_INET, *array, NULL, &address_network) + || !address_network) { + _LOGW("invalid NameServer: %s", *array); + continue; } + any_good = TRUE; + _LOGI("DNS: %s", *array); + nm_l3_config_data_add_nameserver(priv->l3cd_4, AF_INET, &address_network); } - - if (iter == array) { + if (!any_good) { _LOGW("Settings: 'DomainNameServers': none specified"); - g_free(array); goto out; } - g_free(array); } if (g_variant_lookup(v_dict, "MessageProxy", "&s", &s)) { _LOGI("MessageProxy: %s", s); if (s && nm_utils_parse_inaddr_bin(AF_INET, s, NULL, &address_network)) { - nm_modem_get_route_parameters(NM_MODEM(self), - &ip4_route_table, - &ip4_route_metric, - NULL, - NULL); - - { - const NMPlatformIP4Route mms_route = { - .network = address_network, - .plen = 32, - .gateway = gateway_network, - .table_coerced = nm_platform_route_table_coerce(ip4_route_table), - .metric = ip4_route_metric, - }; - - nm_ip4_config_add_route(priv->ip4_config, &mms_route, NULL); - } - } else { + const NMPlatformIP4Route mms_route = { + .network = address_network, + .plen = 32, + .gateway = gateway_network, + .table_any = TRUE, + .table_coerced = 0, + .metric_any = TRUE, + .metric = 0, + }; + + nm_l3_config_data_add_route_4(priv->l3cd_4, &mms_route); + } else _LOGW("invalid MessageProxy: %s", s); - } } ret = TRUE; out: + if (priv->l3cd_4) + nm_l3_config_data_seal(priv->l3cd_4); + if (nm_modem_get_state(NM_MODEM(self)) != NM_MODEM_STATE_CONNECTED) { _LOGI("emitting PREPARE_RESULT: %s", ret ? "TRUE" : "FALSE"); nm_modem_emit_prepare_result(NM_MODEM(self), @@ -893,7 +894,7 @@ out: static void context_property_changed(GDBusProxy *proxy, const char *property, GVariant *v, gpointer user_data) { - NMModemOfono * self = NM_MODEM_OFONO(user_data); + NMModemOfono *self = NM_MODEM_OFONO(user_data); gs_unref_variant GVariant *v_dict = NULL; _LOGD("PropertyChanged: %s", property); @@ -912,38 +913,43 @@ context_property_changed(GDBusProxy *proxy, const char *property, GVariant *v, g handle_settings(v_dict, user_data); } -static NMActStageReturn -static_stage3_ip4_config_start(NMModem * modem, - NMActRequest * req, - NMDeviceStateReason *out_failure_reason) +static void +stage3_ip_config_start(NMModem *modem, int addr_family, NMModemIPMethod ip_method) { - NMModemOfono * self = NM_MODEM_OFONO(modem); - NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE(self); - GError * error = NULL; + NMModemOfono *self = NM_MODEM_OFONO(modem); + NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE(self); + gs_free_error GError *error = NULL; - if (!priv->ip4_config) { - _LOGD("IP4 config not ready(?)"); - return NM_ACT_STAGE_RETURN_FAILURE; + _LOGD("IP4 config is done; setting modem_state -> CONNECTED"); + + if (!NM_IS_IPv4(addr_family) || ip_method == NM_MODEM_IP_METHOD_AUTO) { + nm_modem_emit_signal_new_config_success(modem, addr_family, NULL, TRUE, NULL); + goto out; } - _LOGD("IP4 config is done; setting modem_state -> CONNECTED"); - g_signal_emit_by_name(self, NM_MODEM_IP4_CONFIG_RESULT, priv->ip4_config, error); + if (!priv->l3cd_4) { + nm_utils_error_set(&error, NM_UTILS_ERROR_UNKNOWN, "IP config not received"); + nm_modem_emit_signal_new_config_failure(modem, + addr_family, + NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE, + error); + goto out; + } - /* Signal listener takes ownership of the IP4Config */ - priv->ip4_config = NULL; + nm_modem_emit_signal_new_config_success(modem, addr_family, priv->l3cd_4, FALSE, NULL); +out: nm_modem_set_state(NM_MODEM(self), NM_MODEM_STATE_CONNECTED, nm_modem_state_to_string(NM_MODEM_STATE_CONNECTED)); - return NM_ACT_STAGE_RETURN_POSTPONE; } static void context_properties_cb(GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) { - NMModemOfono * self; - NMModemOfonoPrivate *priv; - gs_free_error GError *error = NULL; + NMModemOfono *self; + NMModemOfonoPrivate *priv; + gs_free_error GError *error = NULL; gs_unref_variant GVariant *properties = NULL; gs_unref_variant GVariant *settings = NULL; gs_unref_variant GVariant *v_dict = NULL; @@ -1007,10 +1013,10 @@ error: static void context_proxy_new_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - NMModemOfono * self; - NMModemOfonoPrivate *priv; + NMModemOfono *self; + NMModemOfonoPrivate *priv; gs_free_error GError *error = NULL; - GDBusProxy * proxy; + GDBusProxy *proxy; proxy = g_dbus_proxy_new_for_bus_finish(result, &error); if (!proxy || g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) @@ -1040,7 +1046,7 @@ context_proxy_new_cb(GObject *source, GAsyncResult *result, gpointer user_data) * clear it so that we can gate getting the IP config from oFono * on whether or not we have already received them */ - g_clear_object(&priv->ip4_config); + nm_clear_l3cd(&priv->l3cd_4); /* We need to directly query ConnectionContextinteface to get the current * property values */ @@ -1081,8 +1087,8 @@ static GHashTable * create_connect_properties(NMConnection *connection) { NMSettingGsm *setting; - GHashTable * properties; - const char * str; + GHashTable *properties; + const char *str; setting = nm_connection_get_setting_gsm(connection); properties = g_hash_table_new(nm_str_hash, g_str_equal); @@ -1103,14 +1109,14 @@ create_connect_properties(NMConnection *connection) } static NMActStageReturn -modem_act_stage1_prepare(NMModem * modem, - NMConnection * connection, +modem_act_stage1_prepare(NMModem *modem, + NMConnection *connection, NMDeviceStateReason *out_failure_reason) { - NMModemOfono * self = NM_MODEM_OFONO(modem); + NMModemOfono *self = NM_MODEM_OFONO(modem); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE(self); - const char * context_id; - char ** id = NULL; + const char *context_id; + char **id = NULL; context_id = nm_connection_get_id(connection); id = g_strsplit(context_id, "/", 0); @@ -1149,10 +1155,10 @@ modem_act_stage1_prepare(NMModem * modem, static void modem_proxy_new_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - NMModemOfono * self; - NMModemOfonoPrivate *priv; + NMModemOfono *self; + NMModemOfonoPrivate *priv; gs_free_error GError *error = NULL; - GDBusProxy * proxy; + GDBusProxy *proxy; proxy = g_dbus_proxy_new_for_bus_finish(result, &error); if (!proxy && g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) @@ -1194,7 +1200,7 @@ nm_modem_ofono_init(NMModemOfono *self) static void constructed(GObject *object) { - NMModemOfono * self = NM_MODEM_OFONO(object); + NMModemOfono *self = NM_MODEM_OFONO(object); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE(self); priv->modem_proxy_cancellable = g_cancellable_new(); @@ -1245,7 +1251,7 @@ nm_modem_ofono_new(const char *path) static void dispose(GObject *object) { - NMModemOfono * self = NM_MODEM_OFONO(object); + NMModemOfono *self = NM_MODEM_OFONO(object); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE(self); nm_clear_g_cancellable(&priv->modem_proxy_cancellable); @@ -1258,7 +1264,7 @@ dispose(GObject *object) priv->connect_properties = NULL; } - g_clear_object(&priv->ip4_config); + nm_clear_l3cd(&priv->l3cd_4); if (priv->modem_proxy) { g_signal_handlers_disconnect_by_data(priv->modem_proxy, self); @@ -1300,6 +1306,6 @@ nm_modem_ofono_class_init(NMModemOfonoClass *klass) modem_class->deactivate_cleanup = deactivate_cleanup; modem_class->check_connection_compatible_with_modem = check_connection_compatible_with_modem; - modem_class->modem_act_stage1_prepare = modem_act_stage1_prepare; - modem_class->static_stage3_ip4_config_start = static_stage3_ip4_config_start; + modem_class->modem_act_stage1_prepare = modem_act_stage1_prepare; + modem_class->stage3_ip_config_start = stage3_ip_config_start; } diff --git a/src/core/devices/wwan/nm-modem.c b/src/core/devices/wwan/nm-modem.c index ccea69db..a5ee8ce8 100644 --- a/src/core/devices/wwan/nm-modem.c +++ b/src/core/devices/wwan/nm-modem.c @@ -13,16 +13,16 @@ #include #include -#include "libnm-core-intern/nm-core-internal.h" -#include "libnm-platform/nm-platform.h" -#include "nm-setting-connection.h" #include "NetworkManagerUtils.h" #include "devices/nm-device-private.h" -#include "nm-netns.h" +#include "libnm-core-intern/nm-core-internal.h" +#include "libnm-platform/nm-platform.h" #include "nm-act-request.h" -#include "nm-ip4-config.h" -#include "nm-ip6-config.h" +#include "nm-l3-config-data.h" +#include "nm-netns.h" +#include "nm-setting-connection.h" #include "ppp/nm-ppp-manager-call.h" +#include "ppp/nm-ppp-mgr.h" #include "ppp/nm-ppp-status.h" /*****************************************************************************/ @@ -45,8 +45,7 @@ enum { PPP_STATS, PPP_FAILED, PREPARE_RESULT, - IP4_CONFIG_RESULT, - IP6_CONFIG_RESULT, + NEW_CONFIG, AUTH_REQUESTED, AUTH_RESULT, REMOVED, @@ -56,6 +55,11 @@ enum { static guint signals[LAST_SIGNAL] = {0}; +typedef struct { + GSource *stage3_on_idle_source; + bool stage3_started : 1; +} IPData; + typedef struct _NMModemPrivate { char *uid; char *path; @@ -63,41 +67,38 @@ typedef struct _NMModemPrivate { char *control_port; char *data_port; - /* TODO: ip_iface is solely used for nm_modem_owns_port(). - * We should rework the code that it's not necessary */ - char *ip_iface; - - int ip_ifindex; - NMModemIPMethod ip4_method; - NMModemIPMethod ip6_method; - NMUtilsIPv6IfaceId iid; - NMModemState state; - NMModemState prev_state; /* revert to this state if enable/disable fails */ - char * device_id; - char * sim_id; - NMModemIPType ip_types; - char * sim_operator_id; - char * operator_code; - char * apn; + int ip_ifindex; + NMModemIPMethod ip4_method; + NMModemIPMethod ip6_method; + NMModemState state; + NMModemState prev_state; /* revert to this state if enable/disable fails */ + char *device_id; + char *sim_id; + NMModemIPType ip_types; + char *sim_operator_id; + char *operator_code; + char *apn; NMPPPManager *ppp_manager; + NMPppMgr *ppp_mgr; - NMActRequest * act_request; + NMActRequest *act_req; + NMDevice *device; guint32 secrets_tries; NMActRequestGetSecretsCallId *secrets_id; guint mm_ip_timeout; - guint32 ip4_route_table; - guint32 ip4_route_metric; - guint32 ip6_route_table; - guint32 ip6_route_metric; + bool claimed : 1; - /* PPP stats */ - guint32 in_bytes; - guint32 out_bytes; + union { + struct { + IPData ip_data_6; + IPData ip_data_4; + }; + IPData ip_data_x[2]; + }; - bool claimed : 1; } NMModemPrivate; G_DEFINE_TYPE(NMModem, nm_modem, G_TYPE_OBJECT) @@ -149,7 +150,7 @@ _nmlog_prefix(char *prefix, NMModem *self) /*****************************************************************************/ -static void _set_ip_ifindex(NMModem *self, int ifindex, const char *ifname); +static void _set_ip_ifindex(NMModem *self, int ifindex); /*****************************************************************************/ /* State/enabled/connected */ @@ -180,6 +181,91 @@ nm_modem_state_to_string(NMModemState state) /*****************************************************************************/ +static NMPlatform * +_get_platform(NMModem *self) +{ + NMModemPrivate *priv = NM_MODEM_GET_PRIVATE(self); + + if (!priv->device) + return NULL; + + return nm_device_get_platform(priv->device); +} + +/*****************************************************************************/ + +void +nm_modem_emit_signal_new_config(NMModem *self, + int addr_family, + const NML3ConfigData *l3cd, + gboolean do_auto, + const NMUtilsIPv6IfaceId *iid, + NMDeviceStateReason failure_reason, + GError *error) +{ + nm_assert(NM_IS_MODEM(self)); + nm_assert_addr_family(addr_family); + nm_assert(!l3cd || NM_IS_L3_CONFIG_DATA(l3cd)); + nm_assert(!do_auto || addr_family == AF_INET6); + nm_assert(!iid || addr_family == AF_INET6); + nm_assert(!error || (!l3cd && !do_auto && !iid)); + + if (error) { + _LOGD("signal: new-config: IPv%c, failed '%s', %s", + nm_utils_addr_family_to_char(addr_family), + nm_device_state_reason_to_string_a(failure_reason), + error->message); + } else { + gs_free char *str_to_free = NULL; + + _LOGD( + "signal: new-config: IPv%c%s%s%s%s", + nm_utils_addr_family_to_char(addr_family), + l3cd ? ", has-l3cd" : "", + do_auto ? ", do-auto" : "", + NM_PRINT_FMT_QUOTED2(iid, + ", iid=", + nm_utils_bin2hexstr_a(iid, sizeof(*iid), ':', FALSE, &str_to_free), + "")); + } + + g_signal_emit(self, + signals[NEW_CONFIG], + 0, + addr_family, + nm_l3_config_data_seal(l3cd), + do_auto, + iid, + (int) failure_reason, + error); +} + +void +nm_modem_emit_signal_new_config_success(NMModem *self, + int addr_family, + const NML3ConfigData *l3cd, + gboolean do_auto, + const NMUtilsIPv6IfaceId *iid) +{ + nm_modem_emit_signal_new_config(self, + addr_family, + l3cd, + do_auto, + iid, + NM_DEVICE_STATE_REASON_NONE, + NULL); +} + +void +nm_modem_emit_signal_new_config_failure(NMModem *self, + int addr_family, + NMDeviceStateReason failure_reason, + GError *error) +{ + nm_assert(error); + nm_modem_emit_signal_new_config(self, addr_family, NULL, FALSE, NULL, failure_reason, error); +} + gboolean nm_modem_is_claimed(NMModem *self) { @@ -240,10 +326,10 @@ nm_modem_set_state(NMModem *self, NMModemState new_state, const char *reason) priv->prev_state = NM_MODEM_STATE_UNKNOWN; if (new_state != old_state) { - _LOGI("modem state changed, '%s' --> '%s' (reason: %s)", + _LOGD("signal: modem state changed, '%s' --> '%s' (reason: %s%s%s)", nm_modem_state_to_string(old_state), nm_modem_state_to_string(new_state), - reason ?: "none"); + NM_PRINT_FMT_QUOTE_STRING(reason)); priv->state = new_state; _notify(self, PROP_STATE); @@ -285,7 +371,7 @@ nm_modem_set_mm_enabled(NMModem *self, gboolean enabled) /* Try to unlock the modem if it's being enabled */ if (enabled) - g_signal_emit(self, signals[AUTH_REQUESTED], 0); + nm_modem_emit_auth_requested(self); return; } @@ -303,14 +389,25 @@ nm_modem_set_mm_enabled(NMModem *self, gboolean enabled) void nm_modem_emit_removed(NMModem *self) { + _LOGD("signal: removed"); g_signal_emit(self, signals[REMOVED], 0); } +void +nm_modem_emit_auth_requested(NMModem *self) +{ + _LOGD("signal: auth-requested"); + g_signal_emit(self, signals[AUTH_REQUESTED], 0); +} + void nm_modem_emit_prepare_result(NMModem *self, gboolean success, NMDeviceStateReason reason) { nm_assert(NM_IS_MODEM(self)); + _LOGD("signal: prepare-result: %s (%s)", + success ? "success" : "failure", + nm_device_state_reason_to_string_a(reason)); g_signal_emit(self, signals[PREPARE_RESULT], 0, success, (guint) reason); } @@ -319,6 +416,7 @@ nm_modem_emit_ppp_failed(NMModem *self, NMDeviceStateReason reason) { nm_assert(NM_IS_MODEM(self)); + _LOGD("signal: ppp-failed (%s)", nm_device_state_reason_to_string_a(reason)); g_signal_emit(self, signals[PPP_FAILED], 0, (guint) reason); } @@ -363,16 +461,16 @@ build_single_ip_type_array(NMModemIPType type) GArray * nm_modem_get_connection_ip_type(NMModem *self, NMConnection *connection, GError **error) { - NMModemPrivate * priv = NM_MODEM_GET_PRIVATE(self); + NMModemPrivate *priv = NM_MODEM_GET_PRIVATE(self); NMSettingIPConfig *s_ip4, *s_ip6; - const char * method; + 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_ip_config_get_method(s_ip4); - if (g_strcmp0(method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0) + if (nm_streq0(method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) ip4 = FALSE; ip4_may_fail = nm_setting_ip_config_get_may_fail(s_ip4); } @@ -413,7 +511,7 @@ nm_modem_get_connection_ip_type(NMModem *self, NMConnection *connection, GError if (ip4 && ip6) { NMModemIPType type; - GArray * out; + GArray *out; out = g_array_sized_new(FALSE, FALSE, sizeof(NMModemIPType), 3); @@ -487,83 +585,101 @@ nm_modem_get_apn(NMModem *self) } /*****************************************************************************/ -/* IP method PPP */ static void -ppp_state_changed(NMPPPManager *ppp_manager, NMPPPStatus status, gpointer user_data) +_ppp_mgr_cleanup(NMModem *self) { - switch (status) { - case NM_PPP_STATUS_DISCONNECT: - nm_modem_emit_ppp_failed(user_data, NM_DEVICE_STATE_REASON_PPP_DISCONNECT); - break; - case NM_PPP_STATUS_DEAD: - nm_modem_emit_ppp_failed(user_data, NM_DEVICE_STATE_REASON_PPP_FAILED); - break; - default: - break; - } + NMModemPrivate *priv = NM_MODEM_GET_PRIVATE(self); + + nm_clear_pointer(&priv->ppp_mgr, nm_ppp_mgr_destroy); } static void -ppp_ifindex_set(NMPPPManager *ppp_manager, int ifindex, const char *iface, gpointer user_data) +_ppp_maybe_emit_new_config(NMModem *self, int addr_family) { - NMModem *self = NM_MODEM(user_data); + NMModemPrivate *priv = NM_MODEM_GET_PRIVATE(self); + const int IS_IPv4 = NM_IS_IPv4(addr_family); + const NMPppMgrIPData *ip_data; + gboolean do_auto; - nm_assert(ifindex >= 0); - nm_assert(NM_MODEM_GET_PRIVATE(self)->ppp_manager == ppp_manager); + ip_data = nm_ppp_mgr_get_ip_data(priv->ppp_mgr, addr_family); - if (ifindex <= 0 && iface) { - /* this might happen, if the ifname was already deleted - * and we failed to resolve ifindex. - * - * Forget about the name. */ - iface = NULL; + if (!ip_data->ip_received) + return; + + if (IS_IPv4) + do_auto = FALSE; + else { + do_auto = !ip_data->l3cd + || (!nm_l3_config_data_get_first_obj(ip_data->l3cd, + NMP_OBJECT_TYPE_IP6_ADDRESS, + nmp_object_ip6_address_is_not_link_local)); } - _set_ip_ifindex(self, ifindex, iface); -} -static void -ppp_ip4_config(NMPPPManager *ppp_manager, NMIP4Config *config, gpointer user_data) -{ - NMModem *self = NM_MODEM(user_data); + nm_assert(!IS_IPv4 || !ip_data->ipv6_iid); - g_signal_emit(self, signals[IP4_CONFIG_RESULT], 0, config, NULL); + nm_modem_emit_signal_new_config_success(self, + addr_family, + ip_data->l3cd, + do_auto, + ip_data->ipv6_iid); } static void -ppp_ip6_config(NMPPPManager * ppp_manager, - const NMUtilsIPv6IfaceId *iid, - NMIP6Config * config, - gpointer user_data) +_ppp_mgr_callback(NMPppMgr *ppp_mgr, const NMPppMgrCallbackData *callback_data, gpointer user_data) { - NMModem *self = NM_MODEM(user_data); + NMModem *self = NM_MODEM(user_data); + NMModemPrivate *priv = NM_MODEM_GET_PRIVATE(self); + int IS_IPv4; - NM_MODEM_GET_PRIVATE(self)->iid = *iid; + switch (callback_data->callback_type) { + case NM_PPP_MGR_CALLBACK_TYPE_STATE_CHANGED: - nm_modem_emit_ip6_config_result(self, config, NULL); -} + if (callback_data->data.state >= _NM_PPP_MGR_STATE_FAILED_START) { + nm_modem_emit_ppp_failed(self, callback_data->data.reason); + return; + } -static void -ppp_stats(NMPPPManager *ppp_manager, guint i_in_bytes, guint i_out_bytes, gpointer user_data) -{ - NMModem * self = NM_MODEM(user_data); - NMModemPrivate *priv = NM_MODEM_GET_PRIVATE(self); - guint32 in_bytes = i_in_bytes; - guint32 out_bytes = i_out_bytes; + if (callback_data->data.state >= NM_PPP_MGR_STATE_HAVE_IFINDEX) + _set_ip_ifindex(self, callback_data->data.ifindex); + + if (callback_data->data.state >= NM_PPP_MGR_STATE_HAVE_IP_CONFIG) { + for (IS_IPv4 = 1; IS_IPv4 >= 0; IS_IPv4--) { + if (!priv->ip_data_x[IS_IPv4].stage3_started) { + /* stage3 didn't yet start. We don't emit the IP signal yet. + * We will emit it together with stage3. */ + continue; + } + if (priv->ip_data_x[IS_IPv4].stage3_on_idle_source) { + /* We scheduled already a handler. Let it handle the new configuration. */ + continue; + } + if (callback_data->data.ip_changed_x[IS_IPv4]) + _ppp_maybe_emit_new_config(self, IS_IPv4 ? AF_INET : AF_INET6); + } + } + return; - if (priv->in_bytes != in_bytes || priv->out_bytes != out_bytes) { - priv->in_bytes = in_bytes; - priv->out_bytes = out_bytes; - g_signal_emit(self, signals[PPP_STATS], 0, (guint) in_bytes, (guint) out_bytes); + case NM_PPP_MGR_CALLBACK_TYPE_STATS_CHANGED: + g_signal_emit(self, + signals[PPP_STATS], + 0, + (guint) callback_data->data.stats_data->in_bytes, + (guint) callback_data->data.stats_data->out_bytes); + return; } + + nm_assert_not_reached(); } +/*****************************************************************************/ + static gboolean port_speed_is_zero(const char *port) { struct termios options; nm_auto_close int fd = -1; - gs_free char * path = NULL; + gs_free char *path = NULL; nm_assert(port); @@ -585,291 +701,116 @@ port_speed_is_zero(const char *port) return cfgetospeed(&options) == B0; } -static NMActStageReturn -ppp_stage3_ip_config_start(NMModem * self, - NMActRequest * req, - NMDeviceStateReason *out_failure_reason) -{ - NMModemPrivate *priv = NM_MODEM_GET_PRIVATE(self); - const char * ppp_name = NULL; - GError * error = NULL; - guint ip_timeout = 30; - guint baud_override = 0; - - g_return_val_if_fail(NM_IS_MODEM(self), NM_ACT_STAGE_RETURN_FAILURE); - g_return_val_if_fail(NM_IS_ACT_REQUEST(req), NM_ACT_STAGE_RETURN_FAILURE); - - /* If we're already running PPP don't restart it; for example, if both - * IPv4 and IPv6 are requested, IPv4 gets started first, but we use the - * same pppd for both v4 and v6. - */ - if (priv->ppp_manager) - return NM_ACT_STAGE_RETURN_POSTPONE; - - if (NM_MODEM_GET_CLASS(self)->get_user_pass) { - NMConnection *connection = nm_act_request_get_applied_connection(req); - - g_assert(connection); - if (!NM_MODEM_GET_CLASS(self)->get_user_pass(self, connection, &ppp_name, NULL)) - return NM_ACT_STAGE_RETURN_FAILURE; - } - - if (!priv->data_port) { - _LOGE("error starting PPP (no data port)"); - NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_PPP_START_FAILED); - return NM_ACT_STAGE_RETURN_FAILURE; - } - - /* Check if ModemManager requested a specific IP timeout to be used. If 0 reported, - * use the default one (30s) */ - if (priv->mm_ip_timeout > 0) { - _LOGI("using modem-specified IP timeout: %u seconds", priv->mm_ip_timeout); - ip_timeout = priv->mm_ip_timeout; - } - - /* Some tty drivers and modems ignore port speed, but pppd requires the - * port speed to be > 0 or it exits. If the port speed is 0 pass an - * explicit speed to pppd to prevent the exit. - * https://bugzilla.redhat.com/show_bug.cgi?id=1281731 - */ - if (port_speed_is_zero(priv->data_port)) - baud_override = 57600; - - priv->ppp_manager = nm_ppp_manager_create(priv->data_port, &error); - - if (priv->ppp_manager) { - nm_ppp_manager_set_route_parameters(priv->ppp_manager, - priv->ip4_route_table, - priv->ip4_route_metric, - priv->ip6_route_table, - priv->ip6_route_metric); - } - - if (!priv->ppp_manager - || !nm_ppp_manager_start(priv->ppp_manager, - req, - ppp_name, - ip_timeout, - baud_override, - &error)) { - _LOGE("error starting PPP: %s", error->message); - g_error_free(error); - g_clear_object(&priv->ppp_manager); - NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_PPP_START_FAILED); - return NM_ACT_STAGE_RETURN_FAILURE; - } - - g_signal_connect(priv->ppp_manager, - NM_PPP_MANAGER_SIGNAL_STATE_CHANGED, - G_CALLBACK(ppp_state_changed), - self); - g_signal_connect(priv->ppp_manager, - NM_PPP_MANAGER_SIGNAL_IFINDEX_SET, - G_CALLBACK(ppp_ifindex_set), - self); - g_signal_connect(priv->ppp_manager, - NM_PPP_MANAGER_SIGNAL_IP4_CONFIG, - G_CALLBACK(ppp_ip4_config), - self); - g_signal_connect(priv->ppp_manager, - NM_PPP_MANAGER_SIGNAL_IP6_CONFIG, - G_CALLBACK(ppp_ip6_config), - self); - g_signal_connect(priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_STATS, G_CALLBACK(ppp_stats), self); - - return NM_ACT_STAGE_RETURN_POSTPONE; -} - /*****************************************************************************/ -NMActStageReturn -nm_modem_stage3_ip4_config_start(NMModem * self, - NMDevice * device, - gboolean * out_autoip4, - NMDeviceStateReason *out_failure_reason) +static gboolean +_stage3_ip_config_start_on_idle(NMModem *self, int addr_family) { - NMModemPrivate * priv; - NMActRequest * req; - NMConnection * connection; - const char * method; - NMActStageReturn ret; - - _LOGD("ip4_config_start"); + const int IS_IPv4 = NM_IS_IPv4(addr_family); + NMModemPrivate *priv = NM_MODEM_GET_PRIVATE(self); + NMModemIPMethod ip_method; + NMConnection *connection; + const char *method; + gs_free_error GError *error = NULL; + NMDeviceStateReason failure_reason; - g_return_val_if_fail(NM_IS_MODEM(self), NM_ACT_STAGE_RETURN_FAILURE); - g_return_val_if_fail(NM_IS_DEVICE(device), NM_ACT_STAGE_RETURN_FAILURE); - nm_assert(out_autoip4 && !*out_autoip4); - - req = nm_device_get_act_request(device); - g_return_val_if_fail(req, NM_ACT_STAGE_RETURN_FAILURE); - - connection = nm_act_request_get_applied_connection(req); - g_return_val_if_fail(connection, NM_ACT_STAGE_RETURN_FAILURE); + nm_clear_g_source_inst(&priv->ip_data_x[IS_IPv4].stage3_on_idle_source); - nm_modem_set_route_parameters_from_device(self, device); + connection = nm_act_request_get_applied_connection(priv->act_req); + g_return_val_if_fail(connection, G_SOURCE_CONTINUE); - method = nm_utils_get_ip_config_method(connection, AF_INET); + method = nm_utils_get_ip_config_method(connection, addr_family); - /* Only Disabled and Auto methods make sense for WWAN */ - if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) - return NM_ACT_STAGE_RETURN_SUCCESS; + if (IS_IPv4 ? NM_IN_STRSET(method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) + : NM_IN_STRSET(method, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP6_CONFIG_METHOD_DISABLED)) { + nm_modem_emit_signal_new_config_success(self, addr_family, NULL, FALSE, NULL); + return G_SOURCE_CONTINUE; + } - if (!nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) { - _LOGE("unhandled WWAN IPv4 method '%s'; will fail", method); - NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_IP_METHOD_UNSUPPORTED); - return NM_ACT_STAGE_RETURN_FAILURE; + if (!nm_streq(method, + IS_IPv4 ? NM_SETTING_IP4_CONFIG_METHOD_AUTO + : NM_SETTING_IP6_CONFIG_METHOD_AUTO)) { + failure_reason = NM_DEVICE_STATE_REASON_IP_METHOD_UNSUPPORTED; + nm_utils_error_set(&error, NM_UTILS_ERROR_UNKNOWN, "ip method unsupported by modem"); + goto out_failure; } - priv = NM_MODEM_GET_PRIVATE(self); - switch (priv->ip4_method) { + ip_method = IS_IPv4 ? priv->ip4_method : priv->ip6_method; + + switch (ip_method) { case NM_MODEM_IP_METHOD_PPP: - ret = ppp_stage3_ip_config_start(self, req, out_failure_reason); - break; + _ppp_maybe_emit_new_config(self, addr_family); + return G_SOURCE_CONTINUE; case NM_MODEM_IP_METHOD_STATIC: - _LOGD("MODEM_IP_METHOD_STATIC"); - ret = - NM_MODEM_GET_CLASS(self)->static_stage3_ip4_config_start(self, req, out_failure_reason); - break; case NM_MODEM_IP_METHOD_AUTO: - _LOGD("MODEM_IP_METHOD_AUTO"); - *out_autoip4 = TRUE; - ret = NM_ACT_STAGE_RETURN_SUCCESS; - break; + NM_MODEM_GET_CLASS(self)->stage3_ip_config_start(self, addr_family, ip_method); + return G_SOURCE_CONTINUE; default: - _LOGI("IPv4 configuration disabled"); - ret = NM_ACT_STAGE_RETURN_IP_FAIL; - break; + failure_reason = NM_DEVICE_STATE_REASON_IP_METHOD_UNSUPPORTED; + nm_utils_error_set(&error, NM_UTILS_ERROR_UNKNOWN, "modem IP method unsupported"); + goto out_failure; } - return ret; -} - -void -nm_modem_ip4_pre_commit(NMModem *modem, NMDevice *device, NMIP4Config *config) -{ - NMModemPrivate *priv = NM_MODEM_GET_PRIVATE(modem); + nm_assert_not_reached(); - /* If the modem has an ethernet-type data interface (ie, not PPP and thus - * not point-to-point) and IP config has a /32 prefix, then we assume that - * ARP will be pointless and we turn it off. - */ - if (priv->ip4_method == NM_MODEM_IP_METHOD_STATIC - || priv->ip4_method == NM_MODEM_IP_METHOD_AUTO) { - const NMPlatformIP4Address *address = nm_ip4_config_get_first_address(config); - - g_assert(address); - if (address->plen == 32) - nm_platform_link_change_flags(nm_device_get_platform(device), - nm_device_get_ip_ifindex(device), - IFF_NOARP, - TRUE); - } +out_failure: + nm_modem_emit_signal_new_config_failure(self, addr_family, failure_reason, error); + return G_SOURCE_CONTINUE; } -/*****************************************************************************/ - -void -nm_modem_emit_ip6_config_result(NMModem *self, NMIP6Config *config, GError *error) +static gboolean +_stage3_ip_config_start_on_idle_4(gpointer user_data) { - NMModemPrivate * priv = NM_MODEM_GET_PRIVATE(self); - NMDedupMultiIter ipconf_iter; - const NMPlatformIP6Address *addr; - gboolean do_slaac = TRUE; - - if (error) { - g_signal_emit(self, signals[IP6_CONFIG_RESULT], 0, NULL, FALSE, error); - return; - } - - if (config) { - /* If the IPv6 configuration only included a Link-Local address, then - * we have to run SLAAC to get the full IPv6 configuration. - */ - nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, config, &addr) { - if (IN6_IS_ADDR_LINKLOCAL(&addr->address)) { - if (!priv->iid.id) - priv->iid.id = ((guint64 *) (&addr->address.s6_addr))[1]; - } else - do_slaac = FALSE; - } - } - g_assert(config || do_slaac); - - g_signal_emit(self, signals[IP6_CONFIG_RESULT], 0, config, do_slaac, NULL); + return _stage3_ip_config_start_on_idle(user_data, AF_INET); } -static NMActStageReturn -stage3_ip6_config_request(NMModem *self, NMDeviceStateReason *out_failure_reason) +static gboolean +_stage3_ip_config_start_on_idle_6(gpointer user_data) { - NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); - return NM_ACT_STAGE_RETURN_FAILURE; + return _stage3_ip_config_start_on_idle(user_data, AF_INET6); } -NMActStageReturn -nm_modem_stage3_ip6_config_start(NMModem * self, - NMDevice * device, - NMDeviceStateReason *out_failure_reason) +gboolean +nm_modem_stage3_ip_config_start(NMModem *self, int addr_family, NMDevice *device) { - NMModemPrivate * priv; - NMActRequest * req; - NMActStageReturn ret; - NMConnection * connection; - const char * method; - - g_return_val_if_fail(NM_IS_MODEM(self), NM_ACT_STAGE_RETURN_FAILURE); - - req = nm_device_get_act_request(device); - g_return_val_if_fail(req, NM_ACT_STAGE_RETURN_FAILURE); - - connection = nm_act_request_get_applied_connection(req); - g_return_val_if_fail(connection, NM_ACT_STAGE_RETURN_FAILURE); + const int IS_IPv4 = NM_IS_IPv4(addr_family); + NMModemPrivate *priv; - nm_modem_set_route_parameters_from_device(self, device); + g_return_val_if_fail(NM_IS_MODEM(self), FALSE); + g_return_val_if_fail(NM_IS_DEVICE(device), FALSE); - method = nm_utils_get_ip_config_method(connection, AF_INET6); + priv = NM_MODEM_GET_PRIVATE(self); - /* Only Ignore, Disabled and Auto methods make sense for WWAN */ - if (NM_IN_STRSET(method, - NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_METHOD_DISABLED)) - return NM_ACT_STAGE_RETURN_IP_DONE; + g_return_val_if_fail(priv->device == device, FALSE); - if (!nm_streq(method, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) { - _LOGW("unhandled WWAN IPv6 method '%s'; will fail", method); - NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); - return NM_ACT_STAGE_RETURN_FAILURE; + if (priv->ip_data_x[IS_IPv4].stage3_started) { + /* we already started. Nothing to do. */ + return FALSE; } - priv = NM_MODEM_GET_PRIVATE(self); - switch (priv->ip6_method) { - case NM_MODEM_IP_METHOD_PPP: - ret = ppp_stage3_ip_config_start(self, req, out_failure_reason); - break; - case NM_MODEM_IP_METHOD_STATIC: - case NM_MODEM_IP_METHOD_AUTO: - /* Both static and DHCP/Auto retrieve a base IP config from the modem - * which in the static case is the full config, and the DHCP/Auto case - * is just the IPv6LL address to use for SLAAC. - */ - ret = NM_MODEM_GET_CLASS(self)->stage3_ip6_config_request(self, out_failure_reason); - break; - default: - _LOGI("IPv6 configuration disabled"); - ret = NM_ACT_STAGE_RETURN_IP_FAIL; - break; - } + nm_assert(!priv->ppp_mgr + || nm_ppp_mgr_get_state(priv->ppp_mgr) >= NM_PPP_MGR_STATE_HAVE_IFINDEX); + + priv->ip_data_x[IS_IPv4].stage3_started = TRUE; - return ret; + priv->ip_data_x[IS_IPv4].stage3_on_idle_source = nm_g_idle_add_source( + IS_IPv4 ? _stage3_ip_config_start_on_idle_4 : _stage3_ip_config_start_on_idle_6, + self); + return TRUE; } +/*****************************************************************************/ + guint32 nm_modem_get_configured_mtu(NMDevice *self, NMDeviceMtuSource *out_source, gboolean *out_force) { NMConnection *connection; - NMSetting * setting; + NMSetting *setting; gint64 mtu_default; guint mtu = 0; - const char * property_name; + const char *property_name; nm_assert(NM_IS_DEVICE(self)); nm_assert(out_source); @@ -910,17 +851,17 @@ cancel_get_secrets(NMModem *self) NMModemPrivate *priv = NM_MODEM_GET_PRIVATE(self); if (priv->secrets_id) - nm_act_request_cancel_secrets(priv->act_request, priv->secrets_id); + nm_act_request_cancel_secrets(priv->act_req, priv->secrets_id); } static void -modem_secrets_cb(NMActRequest * req, +modem_secrets_cb(NMActRequest *req, NMActRequestGetSecretsCallId *call_id, - NMSettingsConnection * connection, - GError * error, + NMSettingsConnection *connection, + GError *error, gpointer user_data) { - NMModem * self = NM_MODEM(user_data); + NMModem *self = NM_MODEM(user_data); NMModemPrivate *priv = NM_MODEM_GET_PRIVATE(self); g_return_if_fail(call_id == priv->secrets_id); @@ -934,23 +875,25 @@ modem_secrets_cb(NMActRequest * req, if (error) _LOGW("modem-secrets: %s", error->message); + _LOGD("signal: auth-result: %s%s", + NM_PRINT_FMT_QUOTED2(error, "failed: ", error->message, "success")); g_signal_emit(self, signals[AUTH_RESULT], 0, error); } void -nm_modem_get_secrets(NMModem * self, +nm_modem_get_secrets(NMModem *self, const char *setting_name, gboolean request_new, const char *hint) { - NMModemPrivate * priv = NM_MODEM_GET_PRIVATE(self); + NMModemPrivate *priv = NM_MODEM_GET_PRIVATE(self); NMSecretAgentGetSecretsFlags flags = NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION; cancel_get_secrets(self); if (request_new) flags |= NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW; - priv->secrets_id = nm_act_request_get_secrets(priv->act_request, + priv->secrets_id = nm_act_request_get_secrets(priv->act_req, FALSE, setting_name, flags, @@ -958,14 +901,14 @@ nm_modem_get_secrets(NMModem * self, modem_secrets_cb, self); g_return_if_fail(priv->secrets_id); - g_signal_emit(self, signals[AUTH_REQUESTED], 0); + nm_modem_emit_auth_requested(self); } /*****************************************************************************/ static NMActStageReturn -modem_act_stage1_prepare(NMModem * modem, - NMConnection * connection, +modem_act_stage1_prepare(NMModem *modem, + NMConnection *connection, NMDeviceStateReason *out_failure_reason) { NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_UNKNOWN); @@ -973,25 +916,28 @@ modem_act_stage1_prepare(NMModem * modem, } NMActStageReturn -nm_modem_act_stage1_prepare(NMModem * self, - NMActRequest * req, +nm_modem_act_stage1_prepare(NMModem *self, + NMActRequest *req, NMDeviceStateReason *out_failure_reason) { - NMModemPrivate * priv = NM_MODEM_GET_PRIVATE(self); + NMModemPrivate *priv = NM_MODEM_GET_PRIVATE(self); gs_unref_ptrarray GPtrArray *hints = NULL; - const char * setting_name = NULL; + const char *setting_name = NULL; NMSecretAgentGetSecretsFlags flags = NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION; - NMConnection * connection; + NMConnection *connection; + NMDevice *device; g_return_val_if_fail(NM_IS_ACT_REQUEST(req), NM_ACT_STAGE_RETURN_FAILURE); - if (priv->act_request) - g_object_unref(priv->act_request); - priv->act_request = g_object_ref(req); + nm_g_object_ref_set(&priv->act_req, req); + device = nm_active_connection_get_device(NM_ACTIVE_CONNECTION(priv->act_req)); + g_return_val_if_fail(NM_IS_DEVICE(device), NM_ACT_STAGE_RETURN_FAILURE); connection = nm_act_request_get_applied_connection(req); g_return_val_if_fail(connection, NM_ACT_STAGE_RETURN_FAILURE); + nm_g_object_ref_set(&priv->device, device); + setting_name = nm_connection_need_secrets(connection, &hints); if (!setting_name) { nm_assert(!hints); @@ -1015,24 +961,99 @@ nm_modem_act_stage1_prepare(NMModem * self, modem_secrets_cb, self); g_return_val_if_fail(priv->secrets_id, NM_ACT_STAGE_RETURN_FAILURE); - g_signal_emit(self, signals[AUTH_REQUESTED], 0); + nm_modem_emit_auth_requested(self); return NM_ACT_STAGE_RETURN_POSTPONE; } /*****************************************************************************/ -void -nm_modem_act_stage2_config(NMModem *self) +NMActStageReturn +nm_modem_act_stage2_config(NMModem *self, NMDevice *device, NMDeviceStateReason *out_failure_reason) { NMModemPrivate *priv; + gboolean needs_ppp; - g_return_if_fail(NM_IS_MODEM(self)); + g_return_val_if_fail(NM_IS_MODEM(self), NM_ACT_STAGE_RETURN_FAILURE); + g_return_val_if_fail(NM_IS_DEVICE(device), NM_ACT_STAGE_RETURN_FAILURE); priv = NM_MODEM_GET_PRIVATE(self); + + g_return_val_if_fail(priv->device == device, NM_ACT_STAGE_RETURN_FAILURE); + /* Clear secrets tries counter since secrets were successfully used * already if we get here. */ priv->secrets_tries = 0; + + needs_ppp = + (priv->ip4_method == NM_MODEM_IP_METHOD_PPP || priv->ip6_method == NM_MODEM_IP_METHOD_PPP); + + if (needs_ppp && !priv->ppp_mgr) { + const char *ppp_name = NULL; + gs_free_error GError *error = NULL; + guint ip_timeout; + guint baud_override; + NMActRequest *req; + + req = nm_device_get_act_request(device); + g_return_val_if_fail(req, NM_ACT_STAGE_RETURN_FAILURE); + + if (NM_MODEM_GET_CLASS(self)->get_user_pass) { + NMConnection *connection = nm_act_request_get_applied_connection(req); + + g_return_val_if_fail(connection, NM_ACT_STAGE_RETURN_FAILURE); + if (!NM_MODEM_GET_CLASS(self)->get_user_pass(self, connection, &ppp_name, NULL)) + return NM_ACT_STAGE_RETURN_FAILURE; + } + + if (!priv->data_port) { + _LOGW("error starting PPP (no data port)"); + NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_PPP_START_FAILED); + return NM_ACT_STAGE_RETURN_FAILURE; + } + + /* Check if ModemManager requested a specific IP timeout to be used. If 0 reported, + * use the default one (30s) */ + if (priv->mm_ip_timeout > 0) { + _LOGI("using modem-specified IP timeout: %u seconds", priv->mm_ip_timeout); + ip_timeout = priv->mm_ip_timeout; + } else + ip_timeout = 30; + + /* Some tty drivers and modems ignore port speed, but pppd requires the + * port speed to be > 0 or it exits. If the port speed is 0 pass an + * explicit speed to pppd to prevent the exit. + * https://bugzilla.redhat.com/show_bug.cgi?id=1281731 + */ + if (port_speed_is_zero(priv->data_port)) + baud_override = 57600; + else + baud_override = 0; + + priv->ppp_mgr = nm_ppp_mgr_start(&((const NMPppMgrConfig){ + .netns = nm_device_get_netns(device), + .parent_iface = priv->data_port, + .callback = _ppp_mgr_callback, + .user_data = self, + .act_req = req, + .ppp_username = ppp_name, + .timeout_secs = ip_timeout, + .baud_override = baud_override, + }), + &error); + if (!priv->ppp_mgr) { + _LOGW("PPP failed to start: %s", error->message); + *out_failure_reason = NM_DEVICE_STATE_REASON_PPP_START_FAILED; + return NM_ACT_STAGE_RETURN_FAILURE; + } + + return NM_ACT_STAGE_RETURN_POSTPONE; + } + + if (needs_ppp && nm_ppp_mgr_get_state(priv->ppp_mgr) < NM_PPP_MGR_STATE_HAVE_IFINDEX) + return NM_ACT_STAGE_RETURN_POSTPONE; + + return NM_ACT_STAGE_RETURN_SUCCESS; } /*****************************************************************************/ @@ -1044,7 +1065,7 @@ nm_modem_check_connection_compatible(NMModem *self, NMConnection *connection, GE if (nm_streq0(nm_connection_get_connection_type(connection), NM_SETTING_GSM_SETTING_NAME)) { NMSettingGsm *s_gsm; - const char * str; + const char *str; s_gsm = _nm_connection_check_main_setting(connection, NM_SETTING_GSM_SETTING_NAME, error); if (!s_gsm) @@ -1098,11 +1119,11 @@ nm_modem_check_connection_compatible(NMModem *self, NMConnection *connection, GE /*****************************************************************************/ gboolean -nm_modem_complete_connection(NMModem * self, - const char * iface, - NMConnection * connection, +nm_modem_complete_connection(NMModem *self, + const char *iface, + NMConnection *connection, NMConnection *const *existing_connections, - GError ** error) + GError **error) { NMModemClass *klass; @@ -1126,27 +1147,26 @@ deactivate_cleanup(NMModem *self, NMDevice *device, gboolean stop_ppp_manager) { NMModemPrivate *priv; int ifindex; + int IS_IPv4; g_return_if_fail(NM_IS_MODEM(self)); priv = NM_MODEM_GET_PRIVATE(self); + for (IS_IPv4 = 1; IS_IPv4 >= 0; IS_IPv4--) { + priv->ip_data_x[IS_IPv4].stage3_started = FALSE; + nm_clear_g_source_inst(&priv->ip_data_x[IS_IPv4].stage3_on_idle_source); + } + priv->secrets_tries = 0; - if (priv->act_request) { + if (priv->act_req) { cancel_get_secrets(self); - g_object_unref(priv->act_request); - priv->act_request = NULL; + g_clear_object(&priv->act_req); } + g_clear_object(&priv->device); - priv->in_bytes = priv->out_bytes = 0; - - if (priv->ppp_manager) { - g_signal_handlers_disconnect_by_data(priv->ppp_manager, self); - if (stop_ppp_manager) - nm_ppp_manager_stop(priv->ppp_manager, NULL, NULL, NULL); - g_clear_object(&priv->ppp_manager); - } + _ppp_mgr_cleanup(self); if (device) { g_return_if_fail(NM_IS_DEVICE(device)); @@ -1170,15 +1190,15 @@ deactivate_cleanup(NMModem *self, NMDevice *device, gboolean stop_ppp_manager) priv->mm_ip_timeout = 0; priv->ip4_method = NM_MODEM_IP_METHOD_UNKNOWN; priv->ip6_method = NM_MODEM_IP_METHOD_UNKNOWN; - _set_ip_ifindex(self, -1, NULL); + _set_ip_ifindex(self, -1); } /*****************************************************************************/ typedef struct { - NMModem * self; - NMDevice * device; - GCancellable * cancellable; + NMModem *self; + NMDevice *device; + GCancellable *cancellable; NMModemDeactivateCallback callback; gpointer callback_user_data; } DeactivateContext; @@ -1216,7 +1236,7 @@ _deactivate_call_disconnect(DeactivateContext *ctx) } static void -_deactivate_ppp_manager_stop_cb(NMPPPManager * ppp_manager, +_deactivate_ppp_manager_stop_cb(NMPPPManager *ppp_manager, NMPPPManagerStopHandle *handle, gboolean was_cancelled, gpointer user_data) @@ -1239,15 +1259,15 @@ _deactivate_ppp_manager_stop_cb(NMPPPManager * ppp_manager, } void -nm_modem_deactivate_async(NMModem * self, - NMDevice * device, - GCancellable * cancellable, +nm_modem_deactivate_async(NMModem *self, + NMDevice *device, + GCancellable *cancellable, NMModemDeactivateCallback callback, gpointer user_data) { - NMModemPrivate * priv = NM_MODEM_GET_PRIVATE(self); + NMModemPrivate *priv = NM_MODEM_GET_PRIVATE(self); DeactivateContext *ctx; - NMPPPManager * ppp_manager; + NMPPPManager *ppp_manager; g_return_if_fail(NM_IS_MODEM(self)); g_return_if_fail(NM_IS_DEVICE(device)); @@ -1307,11 +1327,11 @@ nm_modem_device_state_changed(NMModem *self, NMDeviceState new_state, NMDeviceSt case NM_DEVICE_STATE_UNAVAILABLE: case NM_DEVICE_STATE_FAILED: case NM_DEVICE_STATE_DISCONNECTED: - if (priv->act_request) { + if (priv->act_req) { cancel_get_secrets(self); - g_object_unref(priv->act_request); - priv->act_request = NULL; + g_clear_object(&priv->act_req); } + g_clear_object(&priv->device); if (was_connected) { /* Don't bother warning on FAILED since the modem is already gone */ @@ -1377,32 +1397,27 @@ nm_modem_get_ip_ifindex(NMModem *self) } static void -_set_ip_ifindex(NMModem *self, int ifindex, const char *ifname) +_set_ip_ifindex(NMModem *self, int ifindex) { NMModemPrivate *priv = NM_MODEM_GET_PRIVATE(self); nm_assert(ifindex >= -1); - nm_assert((ifindex > 0) == !!ifname); - - if (!nm_streq0(priv->ip_iface, ifname)) { - g_free(priv->ip_iface); - priv->ip_iface = g_strdup(ifname); - } if (priv->ip_ifindex != ifindex) { + _LOGD("signal: ifindex changed: %d", ifindex); priv->ip_ifindex = ifindex; _notify(self, PROP_IP_IFINDEX); } } gboolean -nm_modem_set_data_port(NMModem * self, - NMPlatform * platform, - const char * data_port, +nm_modem_set_data_port(NMModem *self, + NMPlatform *platform, + const char *data_port, NMModemIPMethod ip4_method, NMModemIPMethod ip6_method, guint timeout, - GError ** error) + GError **error) { NMModemPrivate *priv; gboolean is_ppp; @@ -1477,10 +1492,10 @@ nm_modem_set_data_port(NMModem * self, priv->ip6_method = ip6_method; if (is_ppp) { priv->data_port = g_strdup(data_port); - _set_ip_ifindex(self, -1, NULL); + _set_ip_ifindex(self, -1); } else { priv->data_port = NULL; - _set_ip_ifindex(self, ifindex, data_port); + _set_ip_ifindex(self, ifindex); } return TRUE; } @@ -1488,96 +1503,34 @@ nm_modem_set_data_port(NMModem * self, gboolean nm_modem_owns_port(NMModem *self, const char *iface) { - NMModemPrivate *priv = NM_MODEM_GET_PRIVATE(self); + NMModemPrivate *priv = NM_MODEM_GET_PRIVATE(self); + NMPlatform *platform; + const NMPlatformLink *plink; g_return_val_if_fail(iface != NULL, FALSE); if (NM_MODEM_GET_CLASS(self)->owns_port) return NM_MODEM_GET_CLASS(self)->owns_port(self, iface); - return NM_IN_STRSET(iface, priv->ip_iface, priv->data_port, priv->control_port); -} - -gboolean -nm_modem_get_iid(NMModem *self, NMUtilsIPv6IfaceId *out_iid) -{ - g_return_val_if_fail(NM_IS_MODEM(self), FALSE); - - *out_iid = NM_MODEM_GET_PRIVATE(self)->iid; - return TRUE; -} - -/*****************************************************************************/ - -void -nm_modem_get_route_parameters(NMModem *self, - guint32 *out_ip4_route_table, - guint32 *out_ip4_route_metric, - guint32 *out_ip6_route_table, - guint32 *out_ip6_route_metric) -{ - NMModemPrivate *priv; - - g_return_if_fail(NM_IS_MODEM(self)); - - priv = NM_MODEM_GET_PRIVATE(self); - NM_SET_OUT(out_ip4_route_table, priv->ip4_route_table); - NM_SET_OUT(out_ip4_route_metric, priv->ip4_route_metric); - NM_SET_OUT(out_ip6_route_table, priv->ip6_route_table); - NM_SET_OUT(out_ip6_route_metric, priv->ip6_route_metric); -} - -void -nm_modem_set_route_parameters(NMModem *self, - guint32 ip4_route_table, - guint32 ip4_route_metric, - guint32 ip6_route_table, - guint32 ip6_route_metric) -{ - NMModemPrivate *priv; - - g_return_if_fail(NM_IS_MODEM(self)); - - priv = NM_MODEM_GET_PRIVATE(self); - if (priv->ip4_route_table != ip4_route_table || priv->ip4_route_metric != ip4_route_metric - || priv->ip6_route_table != ip6_route_table || priv->ip6_route_metric != ip6_route_metric) { - priv->ip4_route_table = ip4_route_table; - priv->ip4_route_metric = ip4_route_metric; - priv->ip6_route_table = ip6_route_table; - priv->ip6_route_metric = ip6_route_metric; - - _LOGT("route-parameters: table-v4: %u, metric-v4: %u, table-v6: %u, metric-v6: %u", - priv->ip4_route_table, - priv->ip4_route_metric, - priv->ip6_route_table, - priv->ip6_route_metric); - } - - if (priv->ppp_manager) { - nm_ppp_manager_set_route_parameters(priv->ppp_manager, - priv->ip4_route_table, - priv->ip4_route_metric, - priv->ip6_route_table, - priv->ip6_route_metric); - } -} + if (NM_IN_STRSET(iface, priv->data_port, priv->control_port)) + return TRUE; -void -nm_modem_set_route_parameters_from_device(NMModem *self, NMDevice *device) -{ - g_return_if_fail(NM_IS_DEVICE(device)); + /* FIXME(parent-child-relationship): the whole notion of "owns-port" is wrong. + * When we have a name (iface) it must be always clear what this name is (which + * domain). Mixing data_port, control_port and devlink names is wrong. Looking + * up devlinks by name is also wrong (use ifindex). */ + if (priv->ip_ifindex > 0 && (platform = _get_platform(self)) + && (plink = nm_platform_link_get(platform, priv->ip_ifindex)) + && nm_streq(iface, plink->name)) + return TRUE; - nm_modem_set_route_parameters(self, - nm_device_get_route_table(device, AF_INET), - nm_device_get_route_metric(device, AF_INET), - nm_device_get_route_table(device, AF_INET6), - nm_device_get_route_metric(device, AF_INET6)); + return FALSE; } /*****************************************************************************/ void -nm_modem_get_capabilities(NMModem * self, +nm_modem_get_capabilities(NMModem *self, NMDeviceModemCapabilities *modem_caps, NMDeviceModemCapabilities *current_caps) { @@ -1593,9 +1546,10 @@ _nm_modem_set_operator_code(NMModem *self, const char *operator_code) { NMModemPrivate *priv = NM_MODEM_GET_PRIVATE(self); - if (g_strcmp0(priv->operator_code, operator_code) != 0) { + if (!nm_streq0(priv->operator_code, operator_code)) { g_free(priv->operator_code); priv->operator_code = g_strdup(operator_code); + _LOGD("signal: operator-code changed: %s%s%s", NM_PRINT_FMT_QUOTE_STRING(operator_code)); _notify(self, PROP_OPERATOR_CODE); } } @@ -1605,9 +1559,10 @@ _nm_modem_set_apn(NMModem *self, const char *apn) { NMModemPrivate *priv = NM_MODEM_GET_PRIVATE(self); - if (g_strcmp0(priv->apn, apn) != 0) { + if (!nm_streq0(priv->apn, apn)) { g_free(priv->apn); priv->apn = g_strdup(apn); + _LOGD("signal: apn changed: %s%s%s", NM_PRINT_FMT_QUOTE_STRING(apn)); _notify(self, PROP_APN); } } @@ -1615,7 +1570,7 @@ _nm_modem_set_apn(NMModem *self, const char *apn) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMModem * self = NM_MODEM(object); + NMModem *self = NM_MODEM(object); NMModemPrivate *priv = NM_MODEM_GET_PRIVATE(self); switch (prop_id) { @@ -1665,7 +1620,7 @@ static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { NMModemPrivate *priv = NM_MODEM_GET_PRIVATE(object); - const char * s; + const char *s; switch (prop_id) { case PROP_PATH: @@ -1726,11 +1681,7 @@ nm_modem_init(NMModem *self) self->_priv = G_TYPE_INSTANCE_GET_PRIVATE(self, NM_TYPE_MODEM, NMModemPrivate); priv = self->_priv; - priv->ip_ifindex = -1; - priv->ip4_route_table = RT_TABLE_MAIN; - priv->ip4_route_metric = 700; - priv->ip6_route_table = RT_TABLE_MAIN; - priv->ip6_route_metric = 700; + priv->ip_ifindex = -1; } static void @@ -1752,7 +1703,8 @@ dispose(GObject *object) { NMModemPrivate *priv = NM_MODEM_GET_PRIVATE(object); - g_clear_object(&priv->act_request); + g_clear_object(&priv->act_req); + g_clear_object(&priv->device); G_OBJECT_CLASS(nm_modem_parent_class)->dispose(object); } @@ -1767,7 +1719,6 @@ finalize(GObject *object) g_free(priv->driver); g_free(priv->control_port); g_free(priv->data_port); - g_free(priv->ip_iface); g_free(priv->device_id); g_free(priv->sim_id); g_free(priv->sim_operator_id); @@ -1790,9 +1741,8 @@ nm_modem_class_init(NMModemClass *klass) object_class->dispose = dispose; object_class->finalize = finalize; - klass->modem_act_stage1_prepare = modem_act_stage1_prepare; - klass->stage3_ip6_config_request = stage3_ip6_config_request; - klass->deactivate_cleanup = deactivate_cleanup; + klass->modem_act_stage1_prepare = modem_act_stage1_prepare; + klass->deactivate_cleanup = deactivate_cleanup; obj_properties[PROP_UID] = g_param_spec_string(NM_MODEM_UID, @@ -1904,43 +1854,28 @@ nm_modem_class_init(NMModemClass *klass) 1, G_TYPE_UINT); - signals[IP4_CONFIG_RESULT] = g_signal_new(NM_MODEM_IP4_CONFIG_RESULT, - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, - NULL, - NULL, - G_TYPE_NONE, - 2, - G_TYPE_OBJECT, - G_TYPE_POINTER); - - /** - * NMModem::ip6-config-result: - * @modem: the #NMModem on which the signal is emitted - * @config: the #NMIP6Config to apply to the modem's data port - * @do_slaac: %TRUE if IPv6 SLAAC should be started - * @error: a #GError if any error occurred during IP configuration - * - * This signal is emitted when IPv6 configuration has completed or failed. - * If @error is set the configuration failed. If @config is set, then + /* + * This signal is emitted when IP configuration has completed or failed. + * If @error is set the configuration failed. If @l3cd is set, then * the details should be applied to the data port before any further - * configuration (like SLAAC) is done. @do_slaac indicates whether SLAAC - * should be started after applying @config to the data port. + * configuration (like SLAAC) is done. @do_auto indicates whether DHCPv4/SLAAC + * should be started after applying @l3cd to the data port. */ - signals[IP6_CONFIG_RESULT] = g_signal_new(NM_MODEM_IP6_CONFIG_RESULT, - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, - NULL, - NULL, - G_TYPE_NONE, - 3, - G_TYPE_OBJECT, - G_TYPE_BOOLEAN, - G_TYPE_POINTER); + signals[NEW_CONFIG] = g_signal_new(NM_MODEM_NEW_CONFIG, + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_FIRST, + 0, + NULL, + NULL, + NULL, + G_TYPE_NONE, + 6, + G_TYPE_INT, /* int addr_family */ + G_TYPE_POINTER, /* const NML3ConfigData *l3cd */ + G_TYPE_BOOLEAN, /* gboolean do_auto */ + G_TYPE_POINTER, /* const NMUtilsIPv6IfaceId *iid */ + G_TYPE_INT, /* NMDeviceStateReason failure_reason */ + G_TYPE_POINTER); /* GError *error */ signals[PREPARE_RESULT] = g_signal_new(NM_MODEM_PREPARE_RESULT, G_OBJECT_CLASS_TYPE(object_class), diff --git a/src/core/devices/wwan/nm-modem.h b/src/core/devices/wwan/nm-modem.h index 4bc81ff8..ca541073 100644 --- a/src/core/devices/wwan/nm-modem.h +++ b/src/core/devices/wwan/nm-modem.h @@ -32,15 +32,14 @@ #define NM_MODEM_APN "apn" /* Signals */ -#define NM_MODEM_PPP_STATS "ppp-stats" -#define NM_MODEM_PPP_FAILED "ppp-failed" -#define NM_MODEM_PREPARE_RESULT "prepare-result" -#define NM_MODEM_IP4_CONFIG_RESULT "ip4-config-result" -#define NM_MODEM_IP6_CONFIG_RESULT "ip6-config-result" -#define NM_MODEM_AUTH_REQUESTED "auth-requested" -#define NM_MODEM_AUTH_RESULT "auth-result" -#define NM_MODEM_REMOVED "removed" -#define NM_MODEM_STATE_CHANGED "state-changed" +#define NM_MODEM_PPP_STATS "ppp-stats" +#define NM_MODEM_PPP_FAILED "ppp-failed" +#define NM_MODEM_PREPARE_RESULT "prepare-result" +#define NM_MODEM_NEW_CONFIG "new-config" +#define NM_MODEM_AUTH_REQUESTED "auth-requested" +#define NM_MODEM_AUTH_RESULT "auth-result" +#define NM_MODEM_REMOVED "removed" +#define NM_MODEM_STATE_CHANGED "state-changed" typedef enum { NM_MODEM_IP_METHOD_UNKNOWN = 0, @@ -101,44 +100,36 @@ typedef void (*_NMModemDisconnectCallback)(NMModem *modem, GError *error, gpoint typedef struct { GObjectClass parent; - void (*get_capabilities)(NMModem * self, + void (*get_capabilities)(NMModem *self, NMDeviceModemCapabilities *modem_caps, NMDeviceModemCapabilities *current_caps); - gboolean (*get_user_pass)(NMModem * modem, + gboolean (*get_user_pass)(NMModem *modem, NMConnection *connection, - const char ** user, - const char ** pass); + const char **user, + const char **pass); - gboolean (*check_connection_compatible_with_modem)(NMModem * modem, + gboolean (*check_connection_compatible_with_modem)(NMModem *modem, NMConnection *connection, - GError ** error); + GError **error); - gboolean (*complete_connection)(NMModem * modem, - const char * iface, - NMConnection * connection, + gboolean (*complete_connection)(NMModem *modem, + const char *iface, + NMConnection *connection, NMConnection *const *existing_connections, - GError ** error); + GError **error); - NMActStageReturn (*modem_act_stage1_prepare)(NMModem * modem, - NMConnection * connection, + NMActStageReturn (*modem_act_stage1_prepare)(NMModem *modem, + NMConnection *connection, NMDeviceStateReason *out_failure_reason); - NMActStageReturn (*static_stage3_ip4_config_start)(NMModem * self, - NMActRequest * req, - NMDeviceStateReason *out_failure_reason); - - /* Request the IP6 config; when the config returns the modem - * subclass should emit the ip6_config_result signal. - */ - NMActStageReturn (*stage3_ip6_config_request)(NMModem * self, - NMDeviceStateReason *out_failure_reason); + void (*stage3_ip_config_start)(NMModem *self, int addr_family, NMModemIPMethod method); void (*set_mm_enabled)(NMModem *self, gboolean enabled); - void (*disconnect)(NMModem * self, + void (*disconnect)(NMModem *self, gboolean warn, - GCancellable * cancellable, + GCancellable *cancellable, _NMModemDisconnectCallback callback, gpointer user_data); @@ -161,65 +152,43 @@ const char *nm_modem_get_driver(NMModem *modem); const char *nm_modem_get_device_id(NMModem *modem); const char *nm_modem_get_sim_id(NMModem *modem); const char *nm_modem_get_sim_operator_id(NMModem *modem); -gboolean nm_modem_get_iid(NMModem *modem, NMUtilsIPv6IfaceId *out_iid); const char *nm_modem_get_operator_code(NMModem *modem); const char *nm_modem_get_apn(NMModem *modem); -gboolean nm_modem_set_data_port(NMModem * self, - NMPlatform * platform, - const char * data_port, +gboolean nm_modem_set_data_port(NMModem *self, + NMPlatform *platform, + const char *data_port, NMModemIPMethod ip4_method, NMModemIPMethod ip6_method, guint timeout, - GError ** error); + GError **error); gboolean nm_modem_owns_port(NMModem *modem, const char *iface); -void nm_modem_get_capabilities(NMModem * self, +void nm_modem_get_capabilities(NMModem *self, NMDeviceModemCapabilities *modem_caps, NMDeviceModemCapabilities *current_caps); gboolean nm_modem_check_connection_compatible(NMModem *self, NMConnection *connection, GError **error); -gboolean nm_modem_complete_connection(NMModem * self, - const char * iface, - NMConnection * connection, +gboolean nm_modem_complete_connection(NMModem *self, + const char *iface, + NMConnection *connection, NMConnection *const *existing_connections, - GError ** error); - -void nm_modem_get_route_parameters(NMModem *self, - guint32 *out_ip4_route_table, - guint32 *out_ip4_route_metric, - guint32 *out_ip6_route_table, - guint32 *out_ip6_route_metric); - -void nm_modem_set_route_parameters(NMModem *self, - guint32 ip4_route_table, - guint32 ip4_route_metric, - guint32 ip6_route_table, - guint32 ip6_route_metric); - -void nm_modem_set_route_parameters_from_device(NMModem *modem, NMDevice *device); + GError **error); -NMActStageReturn nm_modem_act_stage1_prepare(NMModem * modem, - NMActRequest * req, +NMActStageReturn nm_modem_act_stage1_prepare(NMModem *modem, + NMActRequest *req, NMDeviceStateReason *out_failure_reason); -void nm_modem_act_stage2_config(NMModem *modem); +NMActStageReturn nm_modem_act_stage2_config(NMModem *self, + NMDevice *device, + NMDeviceStateReason *out_failure_reason); -NMActStageReturn nm_modem_stage3_ip4_config_start(NMModem * modem, - NMDevice * device, - gboolean * out_autoip4, - NMDeviceStateReason *out_failure_reason); +gboolean nm_modem_stage3_ip_config_start(NMModem *self, int addr_family, NMDevice *device); -NMActStageReturn nm_modem_stage3_ip6_config_start(NMModem * modem, - NMDevice * device, - NMDeviceStateReason *out_failure_reason); - -void nm_modem_ip4_pre_commit(NMModem *modem, NMDevice *device, NMIP4Config *config); - -void nm_modem_get_secrets(NMModem * modem, +void nm_modem_get_secrets(NMModem *modem, const char *setting_name, gboolean request_new, const char *hint); @@ -228,9 +197,9 @@ void nm_modem_deactivate(NMModem *modem, NMDevice *device); typedef void (*NMModemDeactivateCallback)(NMModem *self, GError *error, gpointer user_data); -void nm_modem_deactivate_async(NMModem * self, - NMDevice * device, - GCancellable * cancellable, +void nm_modem_deactivate_async(NMModem *self, + NMDevice *device, + GCancellable *cancellable, NMModemDeactivateCallback callback, gpointer user_data); @@ -242,13 +211,15 @@ void nm_modem_set_mm_enabled(NMModem *self, gboolean enabled); NMModemState nm_modem_get_state(NMModem *self); void nm_modem_set_state(NMModem *self, NMModemState new_state, const char *reason); void nm_modem_set_prev_state(NMModem *self, const char *reason); -const char * nm_modem_state_to_string(NMModemState state); +const char *nm_modem_state_to_string(NMModemState state); NMModemIPType nm_modem_get_supported_ip_types(NMModem *self); /* For the modem-manager only */ void nm_modem_emit_removed(NMModem *self); +void nm_modem_emit_auth_requested(NMModem *self); + void nm_modem_emit_prepare_result(NMModem *self, gboolean success, NMDeviceStateReason reason); void nm_modem_emit_ppp_failed(NMModem *self, NMDeviceStateReason reason); @@ -256,7 +227,23 @@ void nm_modem_emit_ppp_failed(NMModem *self, NMDeviceStateReason reason); GArray *nm_modem_get_connection_ip_type(NMModem *self, NMConnection *connection, GError **error); /* For subclasses */ -void nm_modem_emit_ip6_config_result(NMModem *self, NMIP6Config *config, GError *error); + +void nm_modem_emit_signal_new_config(NMModem *self, + int addr_family, + const NML3ConfigData *l3cd, + gboolean do_slaac, + const NMUtilsIPv6IfaceId *iid, + NMDeviceStateReason failure_reason, + GError *error); +void nm_modem_emit_signal_new_config_success(NMModem *self, + int addr_family, + const NML3ConfigData *l3cd, + gboolean do_auto, + const NMUtilsIPv6IfaceId *iid); +void nm_modem_emit_signal_new_config_failure(NMModem *self, + int addr_family, + NMDeviceStateReason failure_reason, + GError *error); const char *nm_modem_ip_type_to_string(NMModemIPType ip_type); diff --git a/src/core/devices/wwan/nm-service-providers.c b/src/core/devices/wwan/nm-service-providers.c index 89add6c5..83f21565 100644 --- a/src/core/devices/wwan/nm-service-providers.c +++ b/src/core/devices/wwan/nm-service-providers.c @@ -22,33 +22,33 @@ typedef enum { } ParseContextState; typedef struct { - char * mccmnc; + char *mccmnc; NMServiceProvidersGsmApnCallback callback; gpointer user_data; - GCancellable * cancellable; - GMarkupParseContext * ctx; + GCancellable *cancellable; + GMarkupParseContext *ctx; char buffer[4096]; - char * text_buffer; + char *text_buffer; ParseContextState state; gboolean mccmnc_matched; gboolean found_internet_apn; - char * apn; - char * username; - char * password; - char * gateway; - char * auth_method; - GSList * dns; + char *apn; + char *username; + char *password; + char *gateway; + char *auth_method; + GSList *dns; } ParseContext; /*****************************************************************************/ static void parser_toplevel_start(ParseContext *parse_context, - const char * name, - const char ** attribute_names, - const char ** attribute_values) + const char *name, + const char **attribute_names, + const char **attribute_values) { int i; @@ -72,9 +72,9 @@ parser_toplevel_start(ParseContext *parse_context, static void parser_country_start(ParseContext *parse_context, - const char * name, - const char ** attribute_names, - const char ** attribute_values) + const char *name, + const char **attribute_names, + const char **attribute_values) { if (strcmp(name, "provider") == 0) parse_context->state = PARSER_PROVIDER; @@ -82,9 +82,9 @@ parser_country_start(ParseContext *parse_context, static void parser_provider_start(ParseContext *parse_context, - const char * name, - const char ** attribute_names, - const char ** attribute_values) + const char *name, + const char **attribute_names, + const char **attribute_values) { parse_context->mccmnc_matched = FALSE; if (strcmp(name, "gsm") == 0) @@ -95,9 +95,9 @@ parser_provider_start(ParseContext *parse_context, static void parser_gsm_start(ParseContext *parse_context, - const char * name, - const char ** attribute_names, - const char ** attribute_values) + const char *name, + const char **attribute_names, + const char **attribute_values) { int i; @@ -140,9 +140,9 @@ parser_gsm_start(ParseContext *parse_context, static void parser_gsm_apn_start(ParseContext *parse_context, - const char * name, - const char ** attribute_names, - const char ** attribute_values) + const char *name, + const char **attribute_names, + const char **attribute_values) { int i; @@ -167,11 +167,11 @@ parser_gsm_apn_start(ParseContext *parse_context, static void parser_start_element(GMarkupParseContext *context, - const char * element_name, - const char ** attribute_names, - const char ** attribute_values, + const char *element_name, + const char **attribute_names, + const char **attribute_values, gpointer user_data, - GError ** error) + GError **error) { ParseContext *parse_context = user_data; @@ -265,9 +265,9 @@ parser_cdma_end(ParseContext *parse_context, const char *name) static void parser_end_element(GMarkupParseContext *context, - const char * element_name, + const char *element_name, gpointer user_data, - GError ** error) + GError **error) { ParseContext *parse_context = user_data; @@ -298,10 +298,10 @@ parser_end_element(GMarkupParseContext *context, static void parser_text(GMarkupParseContext *context, - const char * text, + const char *text, gsize text_len, gpointer user_data, - GError ** error) + GError **error) { ParseContext *parse_context = user_data; @@ -360,7 +360,7 @@ stream_read_cb(GObject *source_object, GAsyncResult *res, gpointer user_data) GInputStream *stream = G_INPUT_STREAM(source_object); ParseContext *parse_context = user_data; gssize len; - GError * error = NULL; + GError *error = NULL; len = g_input_stream_read_finish(stream, res, &error); if (len == -1) { @@ -411,9 +411,9 @@ read_next_chunk(GInputStream *stream, ParseContext *parse_context) static void file_read_cb(GObject *source_object, GAsyncResult *res, gpointer user_data) { - GFile * file = G_FILE(source_object); - ParseContext * parse_context = user_data; - GFileInputStream *stream; + GFile *file = G_FILE(source_object); + ParseContext *parse_context = user_data; + GFileInputStream *stream; gs_free_error GError *error = NULL; stream = g_file_read_finish(file, res, &error); @@ -431,13 +431,13 @@ file_read_cb(GObject *source_object, GAsyncResult *res, gpointer user_data) /*****************************************************************************/ void -nm_service_providers_find_gsm_apn(const char * service_providers, - const char * mccmnc, - GCancellable * cancellable, +nm_service_providers_find_gsm_apn(const char *service_providers, + const char *mccmnc, + GCancellable *cancellable, NMServiceProvidersGsmApnCallback callback, gpointer user_data) { - GFile * file; + GFile *file; ParseContext *parse_context; parse_context = g_slice_new0(ParseContext); diff --git a/src/core/devices/wwan/nm-service-providers.h b/src/core/devices/wwan/nm-service-providers.h index 959f660a..cf90ef1e 100644 --- a/src/core/devices/wwan/nm-service-providers.h +++ b/src/core/devices/wwan/nm-service-providers.h @@ -6,18 +6,18 @@ #ifndef __NETWORKMANAGER_SERVICE_PROVIDERS_H__ #define __NETWORKMANAGER_SERVICE_PROVIDERS_H__ -typedef void (*NMServiceProvidersGsmApnCallback)(const char * apn, - const char * username, - const char * password, - const char * gateway, - const char * auth_method, +typedef void (*NMServiceProvidersGsmApnCallback)(const char *apn, + const char *username, + const char *password, + const char *gateway, + const char *auth_method, const GSList *dns, - GError * error, + GError *error, gpointer user_data); -void nm_service_providers_find_gsm_apn(const char * service_providers, - const char * mccmnc, - GCancellable * cancellable, +void nm_service_providers_find_gsm_apn(const char *service_providers, + const char *mccmnc, + GCancellable *cancellable, NMServiceProvidersGsmApnCallback callback, gpointer user_data); diff --git a/src/core/devices/wwan/nm-wwan-factory.c b/src/core/devices/wwan/nm-wwan-factory.c index 0d802ae1..169407c7 100644 --- a/src/core/devices/wwan/nm-wwan-factory.c +++ b/src/core/devices/wwan/nm-wwan-factory.c @@ -52,7 +52,7 @@ NM_DEVICE_FACTORY_DECLARE_TYPES(NM_DEVICE_FACTORY_DECLARE_LINK_TYPES( NM_SETTING_CDMA_SETTING_NAME)) G_MODULE_EXPORT NMDeviceFactory * - nm_device_factory_create(GError **error) +nm_device_factory_create(GError **error) { return g_object_new(NM_TYPE_WWAN_FACTORY, NULL); } @@ -62,9 +62,9 @@ G_MODULE_EXPORT NMDeviceFactory * static void modem_added_cb(NMModemManager *manager, NMModem *modem, gpointer user_data) { - NMWwanFactory * self = NM_WWAN_FACTORY(user_data); + NMWwanFactory *self = NM_WWAN_FACTORY(user_data); gs_unref_object NMDevice *device = NULL; - const char * driver; + const char *driver; if (nm_modem_is_claimed(modem)) return; @@ -89,11 +89,11 @@ modem_added_cb(NMModemManager *manager, NMModem *modem, gpointer user_data) } static NMDevice * -create_device(NMDeviceFactory * factory, - const char * iface, +create_device(NMDeviceFactory *factory, + const char *iface, const NMPlatformLink *plink, - NMConnection * connection, - gboolean * out_ignore) + NMConnection *connection, + gboolean *out_ignore) { g_return_val_if_fail(plink, NULL); g_return_val_if_fail(plink->type == NM_LINK_TYPE_WWAN_NET, NULL); @@ -104,7 +104,7 @@ create_device(NMDeviceFactory * factory, static void start(NMDeviceFactory *factory) { - NMWwanFactory * self = NM_WWAN_FACTORY(factory); + NMWwanFactory *self = NM_WWAN_FACTORY(factory); NMWwanFactoryPrivate *priv = NM_WWAN_FACTORY_GET_PRIVATE(self); priv->mm = g_object_ref(nm_modem_manager_get()); @@ -121,7 +121,7 @@ nm_wwan_factory_init(NMWwanFactory *self) static void dispose(GObject *object) { - NMWwanFactory * self = NM_WWAN_FACTORY(object); + NMWwanFactory *self = NM_WWAN_FACTORY(object); NMWwanFactoryPrivate *priv = NM_WWAN_FACTORY_GET_PRIVATE(self); if (priv->mm) @@ -135,7 +135,7 @@ dispose(GObject *object) static void nm_wwan_factory_class_init(NMWwanFactoryClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDeviceFactoryClass *factory_class = NM_DEVICE_FACTORY_CLASS(klass); object_class->dispose = dispose; diff --git a/src/core/devices/wwan/tests/test-service-providers.c b/src/core/devices/wwan/tests/test-service-providers.c index f95cccf8..e808b391 100644 --- a/src/core/devices/wwan/tests/test-service-providers.c +++ b/src/core/devices/wwan/tests/test-service-providers.c @@ -10,13 +10,13 @@ #include "nm-test-utils-core.h" static void -test_positive_cb(const char * apn, - const char * username, - const char * password, - const char * gateway, - const char * auth_method, +test_positive_cb(const char *apn, + const char *username, + const char *password, + const char *gateway, + const char *auth_method, const GSList *dns, - GError * error, + GError *error, gpointer user_data) { GMainLoop *loop = user_data; @@ -55,13 +55,13 @@ test_positive(void) /*****************************************************************************/ static void -test_negative_cb(const char * apn, - const char * username, - const char * password, - const char * gateway, - const char * auth_method, +test_negative_cb(const char *apn, + const char *username, + const char *password, + const char *gateway, + const char *auth_method, const GSList *dns, - GError * error, + GError *error, gpointer user_data) { GMainLoop *loop = user_data; @@ -88,13 +88,13 @@ test_negative(void) /*****************************************************************************/ static void -test_nonexistent_cb(const char * apn, - const char * username, - const char * password, - const char * gateway, - const char * auth_method, +test_nonexistent_cb(const char *apn, + const char *username, + const char *password, + const char *gateway, + const char *auth_method, const GSList *dns, - GError * error, + GError *error, gpointer user_data) { GMainLoop *loop = user_data; diff --git a/src/core/dhcp/nm-dhcp-client-logging.h b/src/core/dhcp/nm-dhcp-client-logging.h index d69b3ebd..2b0d8d06 100644 --- a/src/core/dhcp/nm-dhcp-client-logging.h +++ b/src/core/dhcp/nm-dhcp-client-logging.h @@ -39,8 +39,8 @@ _nm_dhcp_client_get_domain(NMDhcpClient *self) * expensive to determine the correct value then what we could * safe. */ \ if (nm_logging_enabled(_level, _NMLOG_DOMAIN)) { \ - NMDhcpClient * _self = (NMDhcpClient *) (self); \ - const char * __ifname = _self ? nm_dhcp_client_get_iface(_self) : NULL; \ + NMDhcpClient *_self = (NMDhcpClient *) (self); \ + const char *__ifname = _self ? nm_dhcp_client_get_iface(_self) : NULL; \ const NMLogDomain _domain = _nm_dhcp_client_get_domain(_self); \ \ nm_log(_level, \ diff --git a/src/core/dhcp/nm-dhcp-client.c b/src/core/dhcp/nm-dhcp-client.c index f88c79c0..ec910389 100644 --- a/src/core/dhcp/nm-dhcp-client.c +++ b/src/core/dhcp/nm-dhcp-client.c @@ -20,9 +20,13 @@ #include "NetworkManagerUtils.h" #include "nm-utils.h" +#include "nm-l3cfg.h" +#include "nm-l3-config-data.h" #include "nm-dhcp-utils.h" #include "nm-dhcp-options.h" #include "libnm-platform/nm-platform.h" +#include "nm-hostname-manager.h" +#include "libnm-systemd-shared/nm-sd-utils-shared.h" #include "nm-dhcp-client-logging.h" @@ -32,53 +36,24 @@ enum { SIGNAL_NOTIFY, LAST_SIGNAL }; static guint signals[LAST_SIGNAL] = {0}; -NM_GOBJECT_PROPERTIES_DEFINE(NMDhcpClient, - PROP_ADDR_FAMILY, - PROP_ANYCAST_ADDRESS, - PROP_FLAGS, - PROP_HWADDR, - PROP_BROADCAST_HWADDR, - PROP_IFACE, - PROP_IFINDEX, - PROP_MULTI_IDX, - PROP_ROUTE_METRIC, - PROP_ROUTE_TABLE, - PROP_TIMEOUT, - PROP_UUID, - PROP_IAID, - PROP_IAID_EXPLICIT, - PROP_HOSTNAME, - PROP_HOSTNAME_FLAGS, - PROP_MUD_URL, - PROP_VENDOR_CLASS_IDENTIFIER, - PROP_REJECT_SERVERS, ); +NM_GOBJECT_PROPERTIES_DEFINE(NMDhcpClient, PROP_CONFIG, ); typedef struct _NMDhcpClientPrivate { - NMDedupMultiIndex * multi_idx; - char * iface; - GBytes * hwaddr; - GBytes * bcast_hwaddr; - char * uuid; - GBytes * client_id; - char * hostname; - const char ** reject_servers; - char * mud_url; - char * anycast_address; - GBytes * vendor_class_identifier; - pid_t pid; - guint timeout_id; - guint watch_id; - int addr_family; - int ifindex; - guint32 route_table; - guint32 route_metric; - guint32 timeout; - guint32 iaid; - NMDhcpState state; - NMDhcpHostnameFlags hostname_flags; - NMDhcpClientFlags client_flags; - bool iaid_explicit : 1; - bool is_stopped : 1; + NMDhcpClientConfig config; + const NML3ConfigData *l3cd; + GSource *no_lease_timeout_source; + GSource *ipv6_lladdr_timeout_source; + GBytes *effective_client_id; + pid_t pid; + guint watch_id; + NMDhcpState state; + bool iaid_explicit : 1; + bool is_stopped : 1; + struct { + gulong id; + bool wait_dhcp_commit : 1; + bool wait_ll_address : 1; + } l3cfg_notify; } NMDhcpClientPrivate; G_DEFINE_ABSTRACT_TYPE(NMDhcpClient, nm_dhcp_client, G_TYPE_OBJECT) @@ -87,6 +62,11 @@ G_DEFINE_ABSTRACT_TYPE(NMDhcpClient, nm_dhcp_client, G_TYPE_OBJECT) /*****************************************************************************/ +static void +l3_cfg_notify_cb(NML3Cfg *l3cfg, const NML3ConfigNotifyData *notify_data, NMDhcpClient *self); + +/*****************************************************************************/ + /* we use pid=-1 for invalid PIDs. Ensure that pid_t can hold negative values. */ G_STATIC_ASSERT(!(((pid_t) -1) > 0)); @@ -98,178 +78,55 @@ _emit_notify(NMDhcpClient *self, const NMDhcpClientNotifyData *notify_data) g_signal_emit(G_OBJECT(self), signals[SIGNAL_NOTIFY], 0, notify_data); } -static void -_emit_notify_state_changed(NMDhcpClient *self, - NMDhcpState dhcp_state, - NMIPConfig * ip_config, - GHashTable * options) -{ - const NMDhcpClientNotifyData notify_data = { - .notify_type = NM_DHCP_CLIENT_NOTIFY_TYPE_STATE_CHANGED, - .state_changed = - { - .dhcp_state = dhcp_state, - .ip_config = ip_config, - .options = options, - }, - }; - - _emit_notify(self, ¬ify_data); -} - /*****************************************************************************/ -pid_t -nm_dhcp_client_get_pid(NMDhcpClient *self) -{ - g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), -1); - - return NM_DHCP_CLIENT_GET_PRIVATE(self)->pid; -} - -NMDedupMultiIndex * -nm_dhcp_client_get_multi_idx(NMDhcpClient *self) -{ - g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), NULL); - - return NM_DHCP_CLIENT_GET_PRIVATE(self)->multi_idx; -} - -const char * -nm_dhcp_client_get_iface(NMDhcpClient *self) -{ - g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), NULL); - - return NM_DHCP_CLIENT_GET_PRIVATE(self)->iface; -} - -int -nm_dhcp_client_get_ifindex(NMDhcpClient *self) -{ - g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), -1); - - return NM_DHCP_CLIENT_GET_PRIVATE(self)->ifindex; -} - -int -nm_dhcp_client_get_addr_family(NMDhcpClient *self) -{ - g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), AF_UNSPEC); - - return NM_DHCP_CLIENT_GET_PRIVATE(self)->addr_family; -} - -const char * -nm_dhcp_client_get_uuid(NMDhcpClient *self) -{ - g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), NULL); - - return NM_DHCP_CLIENT_GET_PRIVATE(self)->uuid; -} - -GBytes * -nm_dhcp_client_get_hw_addr(NMDhcpClient *self) -{ - g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), NULL); - - return NM_DHCP_CLIENT_GET_PRIVATE(self)->hwaddr; -} - -GBytes * -nm_dhcp_client_get_broadcast_hw_addr(NMDhcpClient *self) -{ - g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), NULL); - - return NM_DHCP_CLIENT_GET_PRIVATE(self)->bcast_hwaddr; -} - -guint32 -nm_dhcp_client_get_route_table(NMDhcpClient *self) -{ - g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), RT_TABLE_MAIN); - - return NM_DHCP_CLIENT_GET_PRIVATE(self)->route_table; -} - -void -nm_dhcp_client_set_route_table(NMDhcpClient *self, guint32 route_table) +static void +connect_l3cfg_notify(NMDhcpClient *self) { NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); + gboolean do_connect; - if (route_table != priv->route_table) { - priv->route_table = route_table; - _notify(self, PROP_ROUTE_TABLE); - } -} - -guint32 -nm_dhcp_client_get_route_metric(NMDhcpClient *self) -{ - g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), G_MAXUINT32); - - return NM_DHCP_CLIENT_GET_PRIVATE(self)->route_metric; -} - -void -nm_dhcp_client_set_route_metric(NMDhcpClient *self, guint32 route_metric) -{ - NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); + do_connect = priv->l3cfg_notify.wait_dhcp_commit | priv->l3cfg_notify.wait_ll_address; - if (route_metric != priv->route_metric) { - priv->route_metric = route_metric; - _notify(self, PROP_ROUTE_METRIC); + if (!do_connect) { + nm_clear_g_signal_handler(priv->config.l3cfg, &priv->l3cfg_notify.id); + return; } -} -guint32 -nm_dhcp_client_get_timeout(NMDhcpClient *self) -{ - g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), 0); - - return NM_DHCP_CLIENT_GET_PRIVATE(self)->timeout; -} - -guint32 -nm_dhcp_client_get_iaid(NMDhcpClient *self) -{ - g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), 0); - - return NM_DHCP_CLIENT_GET_PRIVATE(self)->iaid; -} - -gboolean -nm_dhcp_client_get_iaid_explicit(NMDhcpClient *self) -{ - g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), FALSE); - - return NM_DHCP_CLIENT_GET_PRIVATE(self)->iaid_explicit; + if (priv->l3cfg_notify.id == 0) { + priv->l3cfg_notify.id = g_signal_connect(priv->config.l3cfg, + NM_L3CFG_SIGNAL_NOTIFY, + G_CALLBACK(l3_cfg_notify_cb), + self); + } } -GBytes * -nm_dhcp_client_get_client_id(NMDhcpClient *self) +pid_t +nm_dhcp_client_get_pid(NMDhcpClient *self) { - g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), NULL); + g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), -1); - return NM_DHCP_CLIENT_GET_PRIVATE(self)->client_id; + return NM_DHCP_CLIENT_GET_PRIVATE(self)->pid; } static void -_set_client_id(NMDhcpClient *self, GBytes *client_id, gboolean take) +_set_effective_client_id(NMDhcpClient *self, GBytes *client_id, gboolean take) { NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); nm_assert(!client_id || g_bytes_get_size(client_id) >= 2); - if (priv->client_id == client_id - || (priv->client_id && client_id && g_bytes_equal(priv->client_id, client_id))) { + if (priv->effective_client_id == client_id + || (priv->effective_client_id && client_id + && g_bytes_equal(priv->effective_client_id, client_id))) { if (take && client_id) g_bytes_unref(client_id); return; } - if (priv->client_id) - g_bytes_unref(priv->client_id); - priv->client_id = client_id; + if (priv->effective_client_id) + g_bytes_unref(priv->effective_client_id); + priv->effective_client_id = client_id; if (!take && client_id) g_bytes_ref(client_id); @@ -277,94 +134,20 @@ _set_client_id(NMDhcpClient *self, GBytes *client_id, gboolean take) gs_free char *s = NULL; _LOGT("%s: set %s", - nm_dhcp_client_get_addr_family(self) == AF_INET6 ? "duid" : "client-id", - priv->client_id ? (s = nm_dhcp_utils_duid_to_string(priv->client_id)) : "default"); + priv->config.addr_family == AF_INET6 ? "duid" : "client-id", + priv->effective_client_id + ? (s = nm_dhcp_utils_duid_to_string(priv->effective_client_id)) + : "default"); } } void -nm_dhcp_client_set_client_id(NMDhcpClient *self, GBytes *client_id) +nm_dhcp_client_set_effective_client_id(NMDhcpClient *self, GBytes *client_id) { g_return_if_fail(NM_IS_DHCP_CLIENT(self)); g_return_if_fail(!client_id || g_bytes_get_size(client_id) >= 2); - _set_client_id(self, client_id, FALSE); -} - -void -nm_dhcp_client_set_client_id_bin(NMDhcpClient *self, - guint8 type, - const guint8 *client_id, - gsize len) -{ - guint8 *buf; - GBytes *b; - - g_return_if_fail(NM_IS_DHCP_CLIENT(self)); - g_return_if_fail(client_id); - g_return_if_fail(len > 0); - - buf = g_malloc(len + 1); - buf[0] = type; - memcpy(buf + 1, client_id, len); - b = g_bytes_new_take(buf, len + 1); - _set_client_id(self, b, TRUE); -} - -const char * -nm_dhcp_client_get_anycast_address(NMDhcpClient *self) -{ - g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), NULL); - - return NM_DHCP_CLIENT_GET_PRIVATE(self)->anycast_address; -} - -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; -} - -NMDhcpHostnameFlags -nm_dhcp_client_get_hostname_flags(NMDhcpClient *self) -{ - g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), NM_DHCP_HOSTNAME_FLAG_NONE); - - return NM_DHCP_CLIENT_GET_PRIVATE(self)->hostname_flags; -} - -NMDhcpClientFlags -nm_dhcp_client_get_client_flags(NMDhcpClient *self) -{ - g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), NM_DHCP_CLIENT_FLAGS_NONE); - - return NM_DHCP_CLIENT_GET_PRIVATE(self)->client_flags; -} - -const char * -nm_dhcp_client_get_mud_url(NMDhcpClient *self) -{ - g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), NULL); - - return NM_DHCP_CLIENT_GET_PRIVATE(self)->mud_url; -} - -GBytes * -nm_dhcp_client_get_vendor_class_identifier(NMDhcpClient *self) -{ - g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), NULL); - - return NM_DHCP_CLIENT_GET_PRIVATE(self)->vendor_class_identifier; -} - -const char *const * -nm_dhcp_client_get_reject_servers(NMDhcpClient *self) -{ - g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), NULL); - - return (const char *const *) NM_DHCP_CLIENT_GET_PRIVATE(self)->reject_servers; + _set_effective_client_id(self, client_id, FALSE); } /*****************************************************************************/ @@ -412,14 +195,6 @@ reason_to_state(NMDhcpClient *self, const char *iface, const char *reason) /*****************************************************************************/ -static void -timeout_cleanup(NMDhcpClient *self) -{ - NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); - - nm_clear_g_source(&priv->timeout_id); -} - static void watch_cleanup(NMDhcpClient *self) { @@ -457,95 +232,181 @@ stop(NMDhcpClient *self, gboolean release) if (priv->pid > 0) { /* Clean up the watch handler since we're explicitly killing the daemon */ watch_cleanup(self); - nm_dhcp_client_stop_pid(priv->pid, priv->iface); + nm_dhcp_client_stop_pid(priv->pid, priv->config.iface); } priv->pid = -1; } -void -nm_dhcp_client_set_state(NMDhcpClient *self, - NMDhcpState new_state, - NMIPConfig * ip_config, - GHashTable * options) +static gboolean +_no_lease_timeout(gpointer user_data) { + NMDhcpClient *self = user_data; NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); - if (NM_IN_SET(new_state, NM_DHCP_STATE_BOUND, NM_DHCP_STATE_EXTENDED)) { - g_return_if_fail(NM_IS_IP_CONFIG_ADDR_FAMILY(ip_config, priv->addr_family)); - g_return_if_fail(options); + nm_clear_g_source_inst(&priv->no_lease_timeout_source); + + _emit_notify(self, + &((NMDhcpClientNotifyData){ + .notify_type = NM_DHCP_CLIENT_NOTIFY_TYPE_NO_LEASE_TIMEOUT, + })); + return G_SOURCE_CONTINUE; +} + +const NMDhcpClientConfig * +nm_dhcp_client_get_config(NMDhcpClient *self) +{ + NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); + + return &priv->config; +} + +static void +schedule_no_lease_timeout(NMDhcpClient *self) +{ + NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); + + if (priv->no_lease_timeout_source) + return; + + if (priv->config.timeout == NM_DHCP_TIMEOUT_INFINITY) { + _LOGI("activation: beginning transaction (no timeout)"); + priv->no_lease_timeout_source = g_source_ref(nm_g_source_sentinel_get(0)); } else { - g_return_if_fail(!ip_config); - g_return_if_fail(!options); + _LOGI("activation: beginning transaction (timeout in %u seconds)", + (guint) priv->config.timeout); + priv->no_lease_timeout_source = + nm_g_timeout_add_seconds_source(priv->config.timeout, _no_lease_timeout, self); } +} + +void +nm_dhcp_client_set_state(NMDhcpClient *self, NMDhcpState new_state, const NML3ConfigData *l3cd) +{ + NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); + GHashTable *options; + const int IS_IPv4 = NM_IS_IPv4(priv->config.addr_family); + nm_auto_unref_l3cd const NML3ConfigData *l3cd_merged = NULL; + + g_return_if_fail(NM_IS_DHCP_CLIENT(self)); + + if (NM_IN_SET(new_state, NM_DHCP_STATE_BOUND, NM_DHCP_STATE_EXTENDED)) { + g_return_if_fail(NM_IS_L3_CONFIG_DATA(l3cd)); + g_return_if_fail(nm_l3_config_data_get_dhcp_lease(l3cd, priv->config.addr_family)); + } else + g_return_if_fail(!l3cd); + + if (l3cd) + nm_l3_config_data_seal(l3cd); - if (new_state >= NM_DHCP_STATE_BOUND) - timeout_cleanup(self); if (new_state >= NM_DHCP_STATE_TIMEOUT) watch_cleanup(self); - /* The client may send same-state transitions for RENEW/REBIND events and - * the lease may have changed, so handle same-state transitions for the - * EXTENDED and BOUND states. Ignore same-state transitions for other - * events since the lease won't have changed and the state was already handled. - */ - if ((priv->state == new_state) - && !NM_IN_SET(new_state, NM_DHCP_STATE_BOUND, NM_DHCP_STATE_EXTENDED)) - return; + if (!IS_IPv4 && l3cd) { + if (nm_dhcp_utils_merge_new_dhcp6_lease(priv->l3cd, l3cd, &l3cd_merged)) { + l3cd = nm_l3_config_data_seal(l3cd_merged); + } + } - if (_LOGD_ENABLED()) { - gs_free const char **keys = NULL; - guint i, nkeys; + if (priv->l3cd == l3cd) + return; - keys = nm_strdict_get_keys(options, TRUE, &nkeys); - for (i = 0; i < nkeys; i++) { - _LOGD("option %-20s => '%s'", keys[i], (char *) g_hash_table_lookup(options, keys[i])); - } + if (l3cd) { + nm_clear_g_source_inst(&priv->no_lease_timeout_source); + } else { + if (priv->l3cd) + schedule_no_lease_timeout(self); } - if (_LOGT_ENABLED() && priv->addr_family == AF_INET6) { - gs_free char *event_id = NULL; + /* FIXME(l3cfg:dhcp): the API of NMDhcpClient is changing to expose a simpler API. + * The internals like NMDhcpState should not be exposed (or possibly dropped in large + * parts). */ + + nm_l3_config_data_reset(&priv->l3cd, l3cd); + + options = l3cd ? nm_dhcp_lease_get_options( + nm_l3_config_data_get_dhcp_lease(l3cd, priv->config.addr_family)) + : NULL; + + if (_LOGD_ENABLED()) { + if (options) { + gs_free const char **keys = NULL; + guint nkeys; + guint i; + + keys = nm_strdict_get_keys(options, TRUE, &nkeys); + for (i = 0; i < nkeys; i++) { + _LOGD("option %-20s => '%s'", + keys[i], + (char *) g_hash_table_lookup(options, keys[i])); + } + + if (priv->config.addr_family == AF_INET6) { + gs_free char *event_id = NULL; - event_id = nm_dhcp_utils_get_dhcp6_event_id(options); - if (event_id) - _LOGT("event-id: \"%s\"", event_id); + event_id = nm_dhcp_utils_get_dhcp6_event_id(options); + if (event_id) + _LOGT("event-id: \"%s\"", event_id); + } + } } if (_LOGI_ENABLED()) { const char *req_str = - NM_IS_IPv4(priv->addr_family) - ? nm_dhcp_option_request_string(AF_INET, NM_DHCP_OPTION_DHCP4_NM_IP_ADDRESS) - : nm_dhcp_option_request_string(AF_INET6, NM_DHCP_OPTION_DHCP6_NM_IP_ADDRESS); + IS_IPv4 ? nm_dhcp_option_request_string(AF_INET, NM_DHCP_OPTION_DHCP4_NM_IP_ADDRESS) + : nm_dhcp_option_request_string(AF_INET6, NM_DHCP_OPTION_DHCP6_NM_IP_ADDRESS); const char *addr = nm_g_hash_table_lookup(options, req_str); - _LOGI("state changed %s -> %s%s%s%s", - nm_dhcp_state_to_string(priv->state), - nm_dhcp_state_to_string(new_state), + _LOGI("state changed %s%s%s%s", + priv->l3cd ? "new lease" : "no lease", NM_PRINT_FMT_QUOTED(addr, ", address=", addr, "", "")); } - priv->state = new_state; - - _emit_notify_state_changed(self, new_state, ip_config, options); -} - -static gboolean -transaction_timeout(gpointer user_data) -{ - NMDhcpClient * self = NM_DHCP_CLIENT(user_data); - NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); + /* FIXME(l3cfg:dhcp:acd): NMDhcpClient must also do ACD. It needs acd_timeout_msec + * as a configuration parameter (in NMDhcpClientConfig). When ACD is enabled, + * when a new lease gets announced, it must first use NML3Cfg to run ACD on the + * interface (the previous lease -- if any -- will still be used at that point). + * If ACD fails, we call nm_dhcp_client_decline() and try to get a different + * lease. + * If ACD passes, we need to notify the new lease, and the user (NMDevice) may + * then configure the address. We need to watch the configured addresses (in NML3Cfg), + * and if the address appears there, we need to accept the lease. That is complicated + * but necessary, because we can only accept the lease after we configured the + * address. + * + * As a whole, ACD is transparent for the user (NMDevice). It's entirely managed + * by NMDhcpClient. Note that we do ACD through NML3Cfg, which centralizes IP handling + * for one interface, so for example if the same address happens to be configured + * as a static address (bypassing ACD), then NML3Cfg is aware of that and signals + * immediate success. */ + + if (nm_dhcp_client_can_accept(self) && new_state == NM_DHCP_STATE_BOUND && priv->l3cd + && nm_l3_config_data_get_num_addresses(priv->l3cd, priv->config.addr_family) > 0) { + priv->l3cfg_notify.wait_dhcp_commit = TRUE; + } else { + priv->l3cfg_notify.wait_dhcp_commit = FALSE; + } + connect_l3cfg_notify(self); - priv->timeout_id = 0; - _LOGW("request timed out"); - nm_dhcp_client_set_state(self, NM_DHCP_STATE_TIMEOUT, NULL, NULL); - return G_SOURCE_REMOVE; + { + const NMDhcpClientNotifyData notify_data = { + .notify_type = NM_DHCP_CLIENT_NOTIFY_TYPE_LEASE_UPDATE, + .lease_update = + { + .l3cd = priv->l3cd, + .accepted = !priv->l3cfg_notify.wait_dhcp_commit, + }, + }; + + _emit_notify(self, ¬ify_data); + } } static void daemon_watch_cb(GPid pid, int status, gpointer user_data) { - NMDhcpClient * self = NM_DHCP_CLIENT(user_data); + NMDhcpClient *self = NM_DHCP_CLIENT(user_data); NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); - gs_free char * desc = NULL; + gs_free char *desc = NULL; g_return_if_fail(priv->watch_id); priv->watch_id = 0; @@ -554,22 +415,7 @@ daemon_watch_cb(GPid pid, int status, gpointer user_data) priv->pid = -1; - nm_dhcp_client_set_state(self, NM_DHCP_STATE_TERMINATED, NULL, NULL); -} - -void -nm_dhcp_client_start_timeout(NMDhcpClient *self) -{ - NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); - - g_return_if_fail(priv->timeout_id == 0); - - /* Set up a timeout on the transaction to kill it after the timeout */ - - if (priv->timeout == NM_DHCP_TIMEOUT_INFINITY) - return; - - priv->timeout_id = g_timeout_add_seconds(priv->timeout, transaction_timeout, self); + nm_dhcp_client_set_state(self, NM_DHCP_STATE_TERMINATED, NULL); } void @@ -580,8 +426,6 @@ nm_dhcp_client_watch_child(NMDhcpClient *self, pid_t pid) g_return_if_fail(priv->pid == -1); priv->pid = pid; - nm_dhcp_client_start_timeout(self); - g_return_if_fail(priv->watch_id == 0); priv->watch_id = g_child_watch_add(pid, daemon_watch_cb, self); } @@ -595,14 +439,10 @@ nm_dhcp_client_stop_watch_child(NMDhcpClient *self, pid_t pid) priv->pid = -1; watch_cleanup(self); - timeout_cleanup(self); } gboolean -nm_dhcp_client_start_ip4(NMDhcpClient *self, - GBytes * client_id, - const char * last_ip4_address, - GError ** error) +nm_dhcp_client_start_ip4(NMDhcpClient *self, GError **error) { NMDhcpClientPrivate *priv; @@ -610,24 +450,25 @@ nm_dhcp_client_start_ip4(NMDhcpClient *self, priv = NM_DHCP_CLIENT_GET_PRIVATE(self); g_return_val_if_fail(priv->pid == -1, FALSE); - g_return_val_if_fail(priv->addr_family == AF_INET, FALSE); - g_return_val_if_fail(priv->uuid != NULL, FALSE); + g_return_val_if_fail(priv->config.addr_family == AF_INET, FALSE); + g_return_val_if_fail(priv->config.uuid, FALSE); - if (priv->timeout == NM_DHCP_TIMEOUT_INFINITY) - _LOGI("activation: beginning transaction (no timeout)"); - else - _LOGI("activation: beginning transaction (timeout in %u seconds)", (guint) priv->timeout); - - nm_dhcp_client_set_client_id(self, client_id); + schedule_no_lease_timeout(self); - return NM_DHCP_CLIENT_GET_CLASS(self)->ip4_start(self, last_ip4_address, error); + return NM_DHCP_CLIENT_GET_CLASS(self)->ip4_start(self, error); } gboolean nm_dhcp_client_accept(NMDhcpClient *self, GError **error) { + NMDhcpClientPrivate *priv; + g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), FALSE); + priv = NM_DHCP_CLIENT_GET_PRIVATE(self); + + g_return_val_if_fail(priv->l3cd, FALSE); + if (NM_DHCP_CLIENT_GET_CLASS(self)->accept) { return NM_DHCP_CLIENT_GET_CLASS(self)->accept(self, error); } @@ -652,8 +493,14 @@ nm_dhcp_client_can_accept(NMDhcpClient *self) gboolean nm_dhcp_client_decline(NMDhcpClient *self, const char *error_message, GError **error) { + NMDhcpClientPrivate *priv; + g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), FALSE); + priv = NM_DHCP_CLIENT_GET_PRIVATE(self); + + g_return_val_if_fail(priv->l3cd, FALSE); + if (NM_DHCP_CLIENT_GET_CLASS(self)->decline) { return NM_DHCP_CLIENT_GET_CLASS(self)->decline(self, error_message, error); } @@ -667,43 +514,185 @@ get_duid(NMDhcpClient *self) return NULL; } +static gboolean +ipv6_lladdr_timeout(gpointer user_data) +{ + NMDhcpClient *self = user_data; + NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); + + nm_clear_g_source_inst(&priv->ipv6_lladdr_timeout_source); + + _emit_notify( + self, + &((NMDhcpClientNotifyData){ + .notify_type = NM_DHCP_CLIENT_NOTIFY_TYPE_IT_LOOKS_BAD, + .it_looks_bad.reason = "timeout reached while waiting for an IPv6 link-local address", + })); + return G_SOURCE_CONTINUE; +} + +static const NMPlatformIP6Address * +ipv6_lladdr_find(NMDhcpClient *self) +{ + NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); + NML3Cfg *l3cfg; + NMPLookup lookup; + NMDedupMultiIter iter; + const NMPObject *obj; + + l3cfg = priv->config.l3cfg; + nmp_lookup_init_object(&lookup, NMP_OBJECT_TYPE_IP6_ADDRESS, nm_l3cfg_get_ifindex(l3cfg)); + + nm_platform_iter_obj_for_each (&iter, nm_l3cfg_get_platform(l3cfg), &lookup, &obj) { + const NMPlatformIP6Address *pladdr = NMP_OBJECT_CAST_IP6_ADDRESS(obj); + + if (!IN6_IS_ADDR_LINKLOCAL(&pladdr->address)) + continue; + if (NM_FLAGS_HAS(pladdr->n_ifa_flags, IFA_F_TENTATIVE) + && !NM_FLAGS_HAS(pladdr->n_ifa_flags, IFA_F_OPTIMISTIC)) + continue; + return pladdr; + } + return NULL; +} + +static void +l3_cfg_notify_cb(NML3Cfg *l3cfg, const NML3ConfigNotifyData *notify_data, NMDhcpClient *self) +{ + NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); + + nm_assert(l3cfg == priv->config.l3cfg); + + switch (notify_data->notify_type) { + case NM_L3_CONFIG_NOTIFY_TYPE_PLATFORM_CHANGE_ON_IDLE: + { + const NMPlatformIP6Address *addr; + gs_free_error GError *error = NULL; + + if (!priv->l3cfg_notify.wait_ll_address) + return; + + addr = ipv6_lladdr_find(self); + if (addr) { + _LOGD("got IPv6LL address, starting transaction"); + priv->l3cfg_notify.wait_ll_address = FALSE; + connect_l3cfg_notify(self); + nm_clear_g_source_inst(&priv->ipv6_lladdr_timeout_source); + + schedule_no_lease_timeout(self); + + if (!NM_DHCP_CLIENT_GET_CLASS(self)->ip6_start(self, &addr->address, &error)) { + _emit_notify(self, + &((NMDhcpClientNotifyData){ + .notify_type = NM_DHCP_CLIENT_NOTIFY_TYPE_IT_LOOKS_BAD, + .it_looks_bad.reason = error->message, + })); + } + } + + break; + } + case NM_L3_CONFIG_NOTIFY_TYPE_POST_COMMIT: + { + const NML3ConfigData *committed_l3cd; + NMDedupMultiIter ipconf_iter; + const NMPlatformIPAddress *lease_address; + gs_free_error GError *error = NULL; + + /* A new configuration was committed to the interface. If we previously + * got a lease, check whether we are waiting for the address to be + * configured. If the address was added, we can proceed accepting the + * lease and notifying NMDevice. */ + + if (!priv->l3cfg_notify.wait_dhcp_commit) + return; + + nm_l3_config_data_iter_ip_address_for_each (&ipconf_iter, + priv->l3cd, + priv->config.addr_family, + &lease_address) + break; + nm_assert(lease_address); + committed_l3cd = nm_l3cfg_get_combined_l3cd(l3cfg, TRUE); + + if (priv->config.addr_family == AF_INET) { + const NMPlatformIP4Address *address4 = (const NMPlatformIP4Address *) lease_address; + + if (!nm_l3_config_data_lookup_address_4(committed_l3cd, + address4->address, + address4->plen, + address4->peer_address)) + return; + } else { + const NMPlatformIP6Address *address6 = (const NMPlatformIP6Address *) lease_address; + + if (!nm_l3_config_data_lookup_address_6(committed_l3cd, &address6->address)) + return; + } + + priv->l3cfg_notify.wait_dhcp_commit = FALSE; + connect_l3cfg_notify(self); + + _LOGD("accept address"); + + if (!nm_dhcp_client_accept(self, &error)) { + gs_free char *reason = g_strdup_printf("error accepting lease: %s", error->message); + + _emit_notify(self, + &((NMDhcpClientNotifyData){ + .notify_type = NM_DHCP_CLIENT_NOTIFY_TYPE_IT_LOOKS_BAD, + .it_looks_bad.reason = reason, + })); + return; + } + + _emit_notify( + self, + &((NMDhcpClientNotifyData){.notify_type = NM_DHCP_CLIENT_NOTIFY_TYPE_LEASE_UPDATE, + .lease_update = { + .l3cd = priv->l3cd, + .accepted = TRUE, + }})); + break; + }; + default: + /* ignore */; + } +} + gboolean -nm_dhcp_client_start_ip6(NMDhcpClient * self, - GBytes * client_id, - gboolean enforce_duid, - const struct in6_addr * ll_addr, - NMSettingIP6ConfigPrivacy privacy, - guint needed_prefixes, - GError ** error) +nm_dhcp_client_start_ip6(NMDhcpClient *self, GError **error) { - NMDhcpClientPrivate *priv; - gs_unref_bytes GBytes *own_client_id = NULL; + NMDhcpClientPrivate *priv; + gs_unref_bytes GBytes *own_client_id = NULL; + const NMPlatformIP6Address *addr; g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), FALSE); - g_return_val_if_fail(client_id, FALSE); - priv = NM_DHCP_CLIENT_GET_PRIVATE(self); g_return_val_if_fail(priv->pid == -1, FALSE); - g_return_val_if_fail(priv->addr_family == AF_INET6, FALSE); - g_return_val_if_fail(priv->uuid != NULL, FALSE); - g_return_val_if_fail(!priv->client_id, FALSE); + g_return_val_if_fail(priv->config.addr_family == AF_INET6, FALSE); + g_return_val_if_fail(priv->config.uuid, FALSE); + g_return_val_if_fail(!priv->effective_client_id, FALSE); - if (!enforce_duid) + if (!priv->config.v6.enforce_duid) own_client_id = NM_DHCP_CLIENT_GET_CLASS(self)->get_duid(self); - _set_client_id(self, own_client_id ?: client_id, FALSE); + _set_effective_client_id(self, own_client_id ?: priv->config.client_id, FALSE); - if (priv->timeout == NM_DHCP_TIMEOUT_INFINITY) - _LOGI("activation: beginning transaction (no timeout)"); - else - _LOGI("activation: beginning transaction (timeout in %u seconds)", (guint) priv->timeout); + addr = ipv6_lladdr_find(self); + if (!addr) { + _LOGD("waiting for IPv6LL address"); + priv->l3cfg_notify.wait_ll_address = TRUE; + connect_l3cfg_notify(self); + priv->ipv6_lladdr_timeout_source = + nm_g_timeout_add_seconds_source(10, ipv6_lladdr_timeout, self); + return TRUE; + } - return NM_DHCP_CLIENT_GET_CLASS(self)->ip6_start(self, - ll_addr, - privacy, - needed_prefixes, - error); + schedule_no_lease_timeout(self); + + return NM_DHCP_CLIENT_GET_CLASS(self)->ip6_start(self, &addr->address, error); } void @@ -711,7 +700,7 @@ nm_dhcp_client_stop_existing(const char *pid_file, const char *binary_name) { guint64 start_time; pid_t pid, ppid; - const char * exe; + const char *exe; char proc_path[NM_STRLEN("/proc/%lu/cmdline") + 100]; gs_free char *pid_contents = NULL, *proc_contents = NULL; @@ -780,6 +769,10 @@ nm_dhcp_client_stop(NMDhcpClient *self, gboolean release) priv->is_stopped = TRUE; + priv->l3cfg_notify.wait_dhcp_commit = FALSE; + priv->l3cfg_notify.wait_ll_address = FALSE; + connect_l3cfg_notify(self); + /* Kill the DHCP client */ old_pid = priv->pid; NM_DHCP_CLIENT_GET_CLASS(self)->stop(self, release); @@ -789,7 +782,7 @@ nm_dhcp_client_stop(NMDhcpClient *self, gboolean release) _LOGI("canceled DHCP transaction"); nm_assert(priv->pid == -1); - nm_dhcp_client_set_state(self, NM_DHCP_STATE_TERMINATED, NULL, NULL); + nm_dhcp_client_set_state(self, NM_DHCP_STATE_TERMINATED, NULL); } /*****************************************************************************/ @@ -799,10 +792,10 @@ bytearray_variant_to_string(NMDhcpClient *self, GVariant *value, const char *key { const guint8 *array; gsize length; - GString * str; + GString *str; int i; unsigned char c; - char * converted = NULL; + char *converted = NULL; g_return_val_if_fail(value != NULL, NULL); @@ -879,7 +872,7 @@ maybe_add_option(NMDhcpClient *self, GHashTable *hash, const char *key, GVariant */ if ((priv_opt_num = label_is_unknown_xyz(key)) > 0) { gs_free guint8 *check_val = NULL; - char * hex_str = NULL; + char *hex_str = NULL; gsize len; /* dhclient passes values from dhcp private options in its own "string" format: @@ -915,18 +908,16 @@ nm_dhcp_client_emit_ipv6_prefix_delegated(NMDhcpClient *self, const NMPlatformIP gboolean nm_dhcp_client_handle_event(gpointer unused, - const char * iface, + const char *iface, int pid, - GVariant * options, - const char * reason, + GVariant *options, + const char *reason, NMDhcpClient *self) { - NMDhcpClientPrivate *priv; - guint32 old_state; - guint32 new_state; - gs_unref_hashtable GHashTable *str_options = NULL; - gs_unref_object NMIPConfig *ip_config = NULL; - NMPlatformIP6Address prefix = { + NMDhcpClientPrivate *priv; + guint32 new_state; + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + NMPlatformIP6Address prefix = { 0, }; @@ -938,25 +929,26 @@ nm_dhcp_client_handle_event(gpointer unused, priv = NM_DHCP_CLIENT_GET_PRIVATE(self); - if (g_strcmp0(priv->iface, iface) != 0) + if (!nm_streq0(priv->config.iface, iface)) return FALSE; if (priv->pid != pid) return FALSE; - old_state = priv->state; - new_state = reason_to_state(self, priv->iface, reason); + new_state = reason_to_state(self, priv->config.iface, reason); + if (new_state == NM_DHCP_STATE_NOOP) + return TRUE; + _LOGD("DHCP state '%s' -> '%s' (reason: '%s')", - nm_dhcp_state_to_string(old_state), + nm_dhcp_state_to_string(priv->state), nm_dhcp_state_to_string(new_state), reason); - - if (new_state == NM_DHCP_STATE_NOOP) - return TRUE; + priv->state = new_state; if (NM_IN_SET(new_state, NM_DHCP_STATE_BOUND, NM_DHCP_STATE_EXTENDED)) { - GVariantIter iter; - const char * name; - GVariant * value; + gs_unref_hashtable GHashTable *str_options = NULL; + GVariantIter iter; + const char *name; + GVariant *value; /* Copy options */ str_options = g_hash_table_new_full(nm_str_hash, g_str_equal, g_free, g_free); @@ -968,25 +960,29 @@ nm_dhcp_client_handle_event(gpointer unused, /* Create the IP config */ if (g_hash_table_size(str_options) > 0) { - if (priv->addr_family == AF_INET) { - ip_config = NM_IP_CONFIG_CAST( - nm_dhcp_utils_ip4_config_from_options(nm_dhcp_client_get_multi_idx(self), - priv->ifindex, - priv->iface, - str_options, - priv->route_table, - priv->route_metric)); + if (priv->config.addr_family == AF_INET) { + l3cd = nm_dhcp_utils_ip4_config_from_options( + nm_l3cfg_get_multi_idx(priv->config.l3cfg), + nm_l3cfg_get_ifindex(priv->config.l3cfg), + priv->config.iface, + str_options); } else { - prefix = nm_dhcp_utils_ip6_prefix_from_options(str_options); - ip_config = NM_IP_CONFIG_CAST(nm_dhcp_utils_ip6_config_from_options( - nm_dhcp_client_get_multi_idx(self), - priv->ifindex, - priv->iface, + prefix = nm_dhcp_utils_ip6_prefix_from_options(str_options); + l3cd = nm_dhcp_utils_ip6_config_from_options( + nm_l3cfg_get_multi_idx(priv->config.l3cfg), + nm_l3cfg_get_ifindex(priv->config.l3cfg), + priv->config.iface, str_options, - NM_FLAGS_HAS(priv->client_flags, NM_DHCP_CLIENT_FLAGS_INFO_ONLY))); + priv->config.v6.info_only); } } else g_warn_if_reached(); + + if (l3cd) { + nm_l3_config_data_set_dhcp_lease_from_options(l3cd, + priv->config.addr_family, + g_steal_pointer(&str_options)); + } } if (!IN6_IS_ADDR_UNSPECIFIED(&prefix.address)) { @@ -994,17 +990,16 @@ nm_dhcp_client_handle_event(gpointer unused, * of the DHCP client instance. Instead, we just signal the prefix * to the device. */ nm_dhcp_client_emit_ipv6_prefix_delegated(self, &prefix); - } else { - /* Fail if no valid IP config was received */ - if (NM_IN_SET(new_state, NM_DHCP_STATE_BOUND, NM_DHCP_STATE_EXTENDED) && !ip_config) { - _LOGW("client bound but IP config not received"); - new_state = NM_DHCP_STATE_FAIL; - nm_clear_pointer(&str_options, g_hash_table_unref); - } + return TRUE; + } - nm_dhcp_client_set_state(self, new_state, ip_config, str_options); + /* Fail if no valid IP config was received */ + if (NM_IN_SET(new_state, NM_DHCP_STATE_BOUND, NM_DHCP_STATE_EXTENDED) && !l3cd) { + _LOGW("client bound but IP config not received"); + new_state = NM_DHCP_STATE_FAIL; } + nm_dhcp_client_set_state(self, new_state, l3cd); return TRUE; } @@ -1016,18 +1011,18 @@ nm_dhcp_client_server_id_is_rejected(NMDhcpClient *self, gconstpointer addr) guint i; /* IPv6 not implemented yet */ - nm_assert(priv->addr_family == AF_INET); + nm_assert(priv->config.addr_family == AF_INET); - if (!priv->reject_servers || !priv->reject_servers[0]) + if (!priv->config.reject_servers || !priv->config.reject_servers[0]) return FALSE; - for (i = 0; priv->reject_servers[i]; i++) { + for (i = 0; priv->config.reject_servers[i]; i++) { in_addr_t r_addr; in_addr_t mask; int r_prefix; if (!nm_utils_parse_inaddr_prefix_bin(AF_INET, - priv->reject_servers[i], + priv->config.reject_servers[i], NULL, &r_addr, &r_prefix)) @@ -1040,146 +1035,148 @@ nm_dhcp_client_server_id_is_rejected(NMDhcpClient *self, gconstpointer addr) return FALSE; } -/*****************************************************************************/ +static void +config_init(NMDhcpClientConfig *config, const NMDhcpClientConfig *src) +{ + *config = *src; + + g_object_ref(config->l3cfg); + + if (config->hwaddr) + g_bytes_ref(config->hwaddr); + if (config->bcast_hwaddr) + g_bytes_ref(config->bcast_hwaddr); + if (config->vendor_class_identifier) + g_bytes_ref(config->vendor_class_identifier); + if (config->client_id) + g_bytes_ref(config->client_id); + + config->iface = g_strdup(config->iface); + config->uuid = g_strdup(config->uuid); + config->anycast_address = g_strdup(config->anycast_address); + config->hostname = g_strdup(config->hostname); + config->mud_url = g_strdup(config->mud_url); + + config->reject_servers = (const char *const *) nm_strv_dup(config->reject_servers, -1, TRUE); + + if (config->addr_family == AF_INET) { + config->v4.last_address = g_strdup(config->v4.last_address); + } else if (config->addr_family == AF_INET6) { + config->hwaddr = NULL; + config->bcast_hwaddr = NULL; + config->use_fqdn = TRUE; + } else { + nm_assert_not_reached(); + } + + if (!config->hostname && config->send_hostname) { + const char *hostname; + gs_free char *hostname_tmp = NULL; + + hostname = nm_hostname_manager_get_static_hostname(nm_hostname_manager_get()); + + if (nm_utils_is_specific_hostname(hostname)) { + if (config->addr_family == AF_INET) { + char *dot; + + hostname_tmp = g_strdup(hostname); + dot = strchr(hostname_tmp, '.'); + if (dot) + *dot = '\0'; + } + config->hostname = hostname_tmp ? g_steal_pointer(&hostname_tmp) : g_strdup(hostname); + } + } + + if (config->hostname) { + if (!config->send_hostname) { + nm_clear_g_free((gpointer *) &config->hostname); + } else if ((config->use_fqdn && !nm_sd_dns_name_is_valid(config->hostname)) + || (!config->use_fqdn && !nm_sd_hostname_is_valid(config->hostname, FALSE))) { + nm_log_warn(LOGD_DHCP, + "dhcp%c: %s '%s' is invalid, will be ignored", + nm_utils_addr_family_to_char(config->addr_family), + config->use_fqdn ? "FQDN" : "hostname", + config->hostname); + nm_clear_g_free((gpointer *) &config->hostname); + } + } +} static void -get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +config_clear(NMDhcpClientConfig *config) { - NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(object); + g_object_unref(config->l3cfg); - switch (prop_id) { - case PROP_IFACE: - g_value_set_string(value, priv->iface); - break; - case PROP_IFINDEX: - g_value_set_int(value, priv->ifindex); - break; - case PROP_HWADDR: - g_value_set_boxed(value, priv->hwaddr); - break; - case PROP_BROADCAST_HWADDR: - g_value_set_boxed(value, priv->bcast_hwaddr); - break; - case PROP_ADDR_FAMILY: - g_value_set_int(value, priv->addr_family); - break; - case PROP_UUID: - g_value_set_string(value, priv->uuid); - break; - case PROP_IAID: - g_value_set_uint(value, priv->iaid); - break; - case PROP_IAID_EXPLICIT: - g_value_set_boolean(value, priv->iaid_explicit); - break; - case PROP_HOSTNAME: - g_value_set_string(value, priv->hostname); - break; - case PROP_ROUTE_METRIC: - g_value_set_uint(value, priv->route_metric); - break; - case PROP_ROUTE_TABLE: - g_value_set_uint(value, priv->route_table); - break; - case PROP_TIMEOUT: - g_value_set_uint(value, priv->timeout); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; + nm_clear_pointer(&config->hwaddr, g_bytes_unref); + nm_clear_pointer(&config->bcast_hwaddr, g_bytes_unref); + nm_clear_pointer(&config->vendor_class_identifier, g_bytes_unref); + nm_clear_pointer(&config->client_id, g_bytes_unref); + + nm_clear_g_free((gpointer *) &config->iface); + nm_clear_g_free((gpointer *) &config->uuid); + nm_clear_g_free((gpointer *) &config->anycast_address); + nm_clear_g_free((gpointer *) &config->hostname); + nm_clear_g_free((gpointer *) &config->mud_url); + + nm_clear_pointer((gpointer *) &config->reject_servers, g_strfreev); + + if (config->addr_family == AF_INET) { + nm_clear_g_free((gpointer *) &config->v4.last_address); } } +int +nm_dhcp_client_get_addr_family(NMDhcpClient *self) +{ + NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); + + return priv->config.addr_family; +} + +const char * +nm_dhcp_client_get_iface(NMDhcpClient *self) +{ + NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); + + return priv->config.iface; +} + +NMDedupMultiIndex * +nm_dhcp_client_get_multi_idx(NMDhcpClient *self) +{ + NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); + + return nm_l3cfg_get_multi_idx(priv->config.l3cfg); +} + +int +nm_dhcp_client_get_ifindex(NMDhcpClient *self) +{ + NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); + + return nm_l3cfg_get_ifindex(priv->config.l3cfg); +} + +GBytes * +nm_dhcp_client_get_effective_client_id(NMDhcpClient *self) +{ + NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); + + return priv->effective_client_id; +} + +/*****************************************************************************/ + static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(object); - guint flags; switch (prop_id) { - case PROP_FLAGS: - /* construct-only */ - flags = g_value_get_uint(value); - nm_assert(!NM_FLAGS_ANY(flags, ~((guint) NM_DHCP_CLIENT_FLAGS_ALL))); - priv->client_flags = flags; - break; - case PROP_MULTI_IDX: - /* construct-only */ - priv->multi_idx = g_value_get_pointer(value); - if (!priv->multi_idx) - g_return_if_reached(); - nm_dedup_multi_index_ref(priv->multi_idx); - break; - case PROP_IFACE: - /* construct-only */ - priv->iface = g_value_dup_string(value); - g_return_if_fail(priv->iface); - nm_assert(nm_utils_ifname_valid_kernel(priv->iface, NULL)); - break; - case PROP_IFINDEX: - /* construct-only */ - priv->ifindex = g_value_get_int(value); - g_return_if_fail(priv->ifindex > 0); - break; - case PROP_HWADDR: - /* construct-only */ - priv->hwaddr = g_value_dup_boxed(value); - break; - case PROP_ANYCAST_ADDRESS: - /* construct-only */ - priv->anycast_address = g_value_dup_string(value); - break; - case PROP_BROADCAST_HWADDR: - /* construct-only */ - priv->bcast_hwaddr = g_value_dup_boxed(value); - break; - case PROP_ADDR_FAMILY: - /* construct-only */ - priv->addr_family = g_value_get_int(value); - if (!NM_IN_SET(priv->addr_family, AF_INET, AF_INET6)) - g_return_if_reached(); - break; - case PROP_UUID: - /* construct-only */ - priv->uuid = g_value_dup_string(value); - break; - case PROP_IAID: - /* construct-only */ - priv->iaid = g_value_get_uint(value); - break; - case PROP_IAID_EXPLICIT: - /* construct-only */ - priv->iaid_explicit = g_value_get_boolean(value); - break; - case PROP_HOSTNAME: - /* construct-only */ - priv->hostname = g_value_dup_string(value); - break; - case PROP_HOSTNAME_FLAGS: + case PROP_CONFIG: /* construct-only */ - priv->hostname_flags = g_value_get_uint(value); - break; - case PROP_MUD_URL: - /* construct-only */ - priv->mud_url = g_value_dup_string(value); - break; - case PROP_ROUTE_TABLE: - priv->route_table = g_value_get_uint(value); - break; - case PROP_ROUTE_METRIC: - priv->route_metric = g_value_get_uint(value); - break; - case PROP_TIMEOUT: - /* construct-only */ - priv->timeout = g_value_get_uint(value); - break; - case PROP_VENDOR_CLASS_IDENTIFIER: - /* construct-only */ - priv->vendor_class_identifier = g_value_dup_boxed(value); - break; - case PROP_REJECT_SERVERS: - /* construct-only */ - priv->reject_servers = nm_strv_dup_packed(g_value_get_boxed(value), -1); + config_init(&priv->config, g_value_get_pointer(value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); @@ -1200,53 +1197,31 @@ nm_dhcp_client_init(NMDhcpClient *self) priv->pid = -1; } -#if NM_MORE_ASSERTS static void -constructed(GObject *object) +dispose(GObject *object) { - NMDhcpClient * self = NM_DHCP_CLIENT(object); + NMDhcpClient *self = NM_DHCP_CLIENT(object); NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); - /* certain flags only make sense with certain address family. Assert - * for that. */ - if (NM_IS_IPv4(priv->addr_family)) - nm_assert(!NM_FLAGS_ANY(priv->client_flags, NM_DHCP_CLIENT_FLAGS_INFO_ONLY)); - else { - nm_assert(NM_FLAGS_HAS(priv->client_flags, NM_DHCP_CLIENT_FLAGS_USE_FQDN)); - nm_assert(!NM_FLAGS_ANY(priv->client_flags, NM_DHCP_CLIENT_FLAGS_REQUEST_BROADCAST)); - } + nm_dhcp_client_stop(self, FALSE); - nm_assert(!priv->anycast_address || nm_utils_hwaddr_valid(priv->anycast_address, ETH_ALEN)); + watch_cleanup(self); + + nm_clear_g_source_inst(&priv->no_lease_timeout_source); + nm_clear_g_source_inst(&priv->ipv6_lladdr_timeout_source); - G_OBJECT_CLASS(nm_dhcp_client_parent_class)->constructed(object); + G_OBJECT_CLASS(nm_dhcp_client_parent_class)->dispose(object); } -#endif static void -dispose(GObject *object) +finalize(GObject *object) { - NMDhcpClient * self = NM_DHCP_CLIENT(object); + NMDhcpClient *self = NM_DHCP_CLIENT(object); NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); - nm_dhcp_client_stop(self, FALSE); - - watch_cleanup(self); - timeout_cleanup(self); - - nm_clear_g_free(&priv->iface); - nm_clear_g_free(&priv->hostname); - nm_clear_g_free(&priv->uuid); - nm_clear_g_free(&priv->anycast_address); - nm_clear_g_free(&priv->mud_url); - nm_clear_g_free(&priv->reject_servers); - nm_clear_pointer(&priv->client_id, g_bytes_unref); - nm_clear_pointer(&priv->hwaddr, g_bytes_unref); - nm_clear_pointer(&priv->bcast_hwaddr, g_bytes_unref); - nm_clear_pointer(&priv->vendor_class_identifier, g_bytes_unref); - - G_OBJECT_CLASS(nm_dhcp_client_parent_class)->dispose(object); + config_clear(&priv->config); - priv->multi_idx = nm_dedup_multi_index_unref(priv->multi_idx); + G_OBJECT_CLASS(nm_dhcp_client_parent_class)->finalize(object); } static void @@ -1256,165 +1231,19 @@ nm_dhcp_client_class_init(NMDhcpClientClass *client_class) g_type_class_add_private(client_class, sizeof(NMDhcpClientPrivate)); -#if NM_MORE_ASSERTS - object_class->constructed = constructed; -#endif object_class->dispose = dispose; - object_class->get_property = get_property; + object_class->finalize = finalize; object_class->set_property = set_property; client_class->stop = stop; client_class->get_duid = get_duid; - obj_properties[PROP_MULTI_IDX] = - g_param_spec_pointer(NM_DHCP_CLIENT_MULTI_IDX, + obj_properties[PROP_CONFIG] = + g_param_spec_pointer(NM_DHCP_CLIENT_CONFIG, "", "", G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_IFACE] = - g_param_spec_string(NM_DHCP_CLIENT_INTERFACE, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - - obj_properties[PROP_IFINDEX] = - g_param_spec_int(NM_DHCP_CLIENT_IFINDEX, - "", - "", - -1, - G_MAXINT, - -1, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - - obj_properties[PROP_HWADDR] = - g_param_spec_boxed(NM_DHCP_CLIENT_HWADDR, - "", - "", - G_TYPE_BYTES, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - - obj_properties[PROP_BROADCAST_HWADDR] = - g_param_spec_boxed(NM_DHCP_CLIENT_BROADCAST_HWADDR, - "", - "", - G_TYPE_BYTES, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - - obj_properties[PROP_ADDR_FAMILY] = - g_param_spec_int(NM_DHCP_CLIENT_ADDR_FAMILY, - "", - "", - 0, - G_MAXINT, - AF_UNSPEC, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - - obj_properties[PROP_ANYCAST_ADDRESS] = - g_param_spec_string(NM_DHCP_CLIENT_ANYCAST_ADDRESS, - "", - "", - NULL, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - - obj_properties[PROP_UUID] = - g_param_spec_string(NM_DHCP_CLIENT_UUID, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - - obj_properties[PROP_IAID] = - g_param_spec_uint(NM_DHCP_CLIENT_IAID, - "", - "", - 0, - G_MAXUINT32, - 0, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - - obj_properties[PROP_IAID_EXPLICIT] = - g_param_spec_boolean(NM_DHCP_CLIENT_IAID_EXPLICIT, - "", - "", - FALSE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - - obj_properties[PROP_HOSTNAME] = - g_param_spec_string(NM_DHCP_CLIENT_HOSTNAME, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - - obj_properties[PROP_HOSTNAME_FLAGS] = - g_param_spec_uint(NM_DHCP_CLIENT_HOSTNAME_FLAGS, - "", - "", - 0, - G_MAXUINT32, - NM_DHCP_HOSTNAME_FLAG_NONE, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - - obj_properties[PROP_MUD_URL] = - g_param_spec_string(NM_DHCP_CLIENT_MUD_URL, - "", - "", - NULL, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - - obj_properties[PROP_ROUTE_TABLE] = - g_param_spec_uint(NM_DHCP_CLIENT_ROUTE_TABLE, - "", - "", - 0, - G_MAXUINT32, - RT_TABLE_MAIN, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - obj_properties[PROP_ROUTE_METRIC] = - g_param_spec_uint(NM_DHCP_CLIENT_ROUTE_METRIC, - "", - "", - 0, - G_MAXUINT32, - 0, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - G_STATIC_ASSERT_EXPR(G_MAXINT32 == NM_DHCP_TIMEOUT_INFINITY); - obj_properties[PROP_TIMEOUT] = - g_param_spec_uint(NM_DHCP_CLIENT_TIMEOUT, - "", - "", - 1, - G_MAXINT32, - NM_DHCP_TIMEOUT_DEFAULT, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - - obj_properties[PROP_FLAGS] = - g_param_spec_uint(NM_DHCP_CLIENT_FLAGS, - "", - "", - 0, - G_MAXUINT32, - 0, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - - obj_properties[PROP_VENDOR_CLASS_IDENTIFIER] = - g_param_spec_boxed(NM_DHCP_CLIENT_VENDOR_CLASS_IDENTIFIER, - "", - "", - G_TYPE_BYTES, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - - obj_properties[PROP_REJECT_SERVERS] = - g_param_spec_boxed(NM_DHCP_CLIENT_REJECT_SERVERS, - "", - "", - G_TYPE_STRV, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); signals[SIGNAL_NOTIFY] = diff --git a/src/core/dhcp/nm-dhcp-client.h b/src/core/dhcp/nm-dhcp-client.h index 2e7e0216..249bd013 100644 --- a/src/core/dhcp/nm-dhcp-client.h +++ b/src/core/dhcp/nm-dhcp-client.h @@ -8,8 +8,6 @@ #include "nm-setting-ip4-config.h" #include "nm-setting-ip6-config.h" -#include "nm-ip4-config.h" -#include "nm-ip6-config.h" #include "nm-dhcp-utils.h" #define NM_DHCP_TIMEOUT_DEFAULT ((guint32) 45) /* default DHCP timeout, in seconds */ @@ -24,25 +22,7 @@ #define NM_DHCP_CLIENT_GET_CLASS(obj) \ (G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_DHCP_CLIENT, NMDhcpClientClass)) -#define NM_DHCP_CLIENT_ADDR_FAMILY "addr-family" -#define NM_DHCP_CLIENT_ANYCAST_ADDRESS "anycast-address" -#define NM_DHCP_CLIENT_FLAGS "flags" -#define NM_DHCP_CLIENT_HWADDR "hwaddr" -#define NM_DHCP_CLIENT_BROADCAST_HWADDR "broadcast-hwaddr" -#define NM_DHCP_CLIENT_IFINDEX "ifindex" -#define NM_DHCP_CLIENT_INTERFACE "iface" -#define NM_DHCP_CLIENT_MULTI_IDX "multi-idx" -#define NM_DHCP_CLIENT_HOSTNAME "hostname" -#define NM_DHCP_CLIENT_MUD_URL "mud-url" -#define NM_DHCP_CLIENT_ROUTE_METRIC "route-metric" -#define NM_DHCP_CLIENT_ROUTE_TABLE "route-table" -#define NM_DHCP_CLIENT_TIMEOUT "timeout" -#define NM_DHCP_CLIENT_UUID "uuid" -#define NM_DHCP_CLIENT_IAID "iaid" -#define NM_DHCP_CLIENT_IAID_EXPLICIT "iaid-explicit" -#define NM_DHCP_CLIENT_HOSTNAME_FLAGS "hostname-flags" -#define NM_DHCP_CLIENT_VENDOR_CLASS_IDENTIFIER "vendor-class-identifier" -#define NM_DHCP_CLIENT_REJECT_SERVERS "reject-servers" +#define NM_DHCP_CLIENT_CONFIG "config" #define NM_DHCP_CLIENT_NOTIFY "dhcp-notify" @@ -59,7 +39,27 @@ typedef enum { } NMDhcpState; typedef enum _nm_packed { - NM_DHCP_CLIENT_NOTIFY_TYPE_STATE_CHANGED, + NM_DHCP_CLIENT_NOTIFY_TYPE_LEASE_UPDATE, + + /* When NM_DHCP_CLIENT_NO_LEASE_TIMEOUT expired and the state + * switched from NM_DHCP_CLIENT_STATE_NO_LEASE to + * NM_DHCP_CLIENT_STATE_NO_LEASE_WITH_TIMEOUT. */ + NM_DHCP_CLIENT_NOTIFY_TYPE_NO_LEASE_TIMEOUT, + + /* NMDhcpClient will indefinitely try to get/renew the lease. + * As such, it's never officially in a non-recoverable state. + * However, there are cases when it really looks like we won't + * be able to get a lease. For example, if the underlying interface + * is layer 3 only, if we have no IPv6 link local address for a prolonged + * time, or if dhclient is not installed. + * But even these cases are potentially recoverable. This is only + * a hint to the user (which they might ignore). + * + * In particular, NM_DHCP_CLIENT_NOTIFY_TYPE_NO_LEASE_TIMEOUT might mean + * that the DHCP is currently not running, but that could change + * at any moment and from client's side, it does not look bad. */ + NM_DHCP_CLIENT_NOTIFY_TYPE_IT_LOOKS_BAD, + NM_DHCP_CLIENT_NOTIFY_TYPE_PREFIX_DELEGATED, } NMDhcpClientNotifyType; @@ -67,18 +67,124 @@ typedef struct { NMDhcpClientNotifyType notify_type; union { struct { - NMIPConfig *ip_config; - GHashTable *options; - NMDhcpState dhcp_state; - } state_changed; + /* This is either the new lease information we just received, + * or NULL (if a previous lease timed out). It can also be the + * previous lease, that was injected. */ + const NML3ConfigData *l3cd; + bool accepted; + } lease_update; struct { const NMPlatformIP6Address *prefix; } prefix_delegated; + struct { + const char *reason; + } it_looks_bad; }; } NMDhcpClientNotifyData; const char *nm_dhcp_state_to_string(NMDhcpState state); +/* FIXME(l3cfg:dhcp:config): nm_dhcp_manager_start_ip[46]() has a gazillion of parameters, + * those get passed on as CONSTRUCT_ONLY properties to the NMDhcpClient. Drop + * all these parameters, and let the caller provide one NMDhcpClientConfig + * instance. There will be only one GObject property (NM_DHCP_CLIENT_CONFIG), + * which is CONSTRUCT_ONLY and takes a (mandatory) G_TYPE_POINTER for the + * configuration. + * + * Since NMDhcpClientConfig has an addr_family, we also don't need separate + * nm_dhcp_manager_start_ip[46]() methods. */ +typedef struct { + int addr_family; + + /* The NML3Cfg instance is the manager object for the ifindex on which + * NMDhcpClient is supposed to run. */ + NML3Cfg *l3cfg; + + /* FIXME(l3cfg:dhcp:previous-lease): most parameters of NMDhcpClient are immutable, + * so to change them (during reapply), we need to create and start + * a new NMDhcpClient instance. + * + * However, while the restart happens, we want to stick to the previous + * lease (if any). Allow the caller to provide such a previous lease, + * and if present, the instance starts by pretending that it just received + * this lease, before really starting. */ + const NML3ConfigData *previous_lease; + + const char *iface; + + /* The hardware address */ + GBytes *hwaddr; + + /* The broadcast hardware address */ + GBytes *bcast_hwaddr; + + /* Timeout in seconds before reporting failure */ + guint32 timeout; + + /* Flags for the hostname and FQDN DHCP options */ + NMDhcpHostnameFlags hostname_flags; + + /* The UUID of the connection. Used mainly to build + * lease file names. */ + const char *uuid; + + /* Set to reduce the number of broadcast packets when the + * anycast hardware address of the DHCP service is known. */ + const char *anycast_address; + + /* The hostname or FQDN to send. */ + const char *hostname; + + /* The Manufacturer Usage Description (RFC 8520) URL to send */ + const char *mud_url; + + /* The value for the Vendor Class Identifier option */ + GBytes *vendor_class_identifier; + + /* A list of servers from which offers should be rejected */ + const char *const *reject_servers; + + /* The client identifier (DHCPv4) or DUID (DHCPv6) to send */ + GBytes *client_id; + + /* Whether to send the hostname or FQDN option */ + bool send_hostname : 1; + + /* Whether to send the hostname as HOSTNAME option or FQDN. + * For DHCPv6 this is always TRUE. */ + bool use_fqdn : 1; + + union { + struct { + /* Set BOOTP broadcast flag in request packets, so that servers + * will always broadcast replies. */ + bool request_broadcast : 1; + + /* The address from the previous lease */ + const char *last_address; + } v4; + struct { + /* If set, the DUID from the connection is used; otherwise + * the one from an existing lease is used. */ + gboolean enforce_duid; + + /* The IAID to use */ + guint32 iaid; + + /* Whether the IAID was explicitly set in the connection or + * as global default */ + gboolean iaid_explicit; + + /* Number to prefixes (IA_PD) to request */ + guint needed_prefixes; + + /* Use Information-request to get stateless configuration + * parameters (don't request a IA_NA) */ + bool info_only : 1; + } v6; + }; +} NMDhcpClientConfig; + struct _NMDhcpClientPrivate; typedef struct { @@ -100,17 +206,13 @@ typedef enum _nm_packed { typedef struct { GObjectClass parent; - gboolean (*ip4_start)(NMDhcpClient *self, const char *last_ip4_address, GError **error); + gboolean (*ip4_start)(NMDhcpClient *self, GError **error); gboolean (*accept)(NMDhcpClient *self, GError **error); gboolean (*decline)(NMDhcpClient *self, const char *error_message, GError **error); - gboolean (*ip6_start)(NMDhcpClient * self, - const struct in6_addr * ll_addr, - NMSettingIP6ConfigPrivacy privacy, - guint needed_prefixes, - GError ** error); + gboolean (*ip6_start)(NMDhcpClient *self, const struct in6_addr *ll_addr, GError **error); void (*stop)(NMDhcpClient *self, gboolean release); @@ -128,64 +230,25 @@ typedef struct { GType nm_dhcp_client_get_type(void); -struct _NMDedupMultiIndex *nm_dhcp_client_get_multi_idx(NMDhcpClient *self); - -pid_t nm_dhcp_client_get_pid(NMDhcpClient *self); - -int nm_dhcp_client_get_addr_family(NMDhcpClient *self); - -const char *nm_dhcp_client_get_iface(NMDhcpClient *self); - -int nm_dhcp_client_get_ifindex(NMDhcpClient *self); - -const char *nm_dhcp_client_get_uuid(NMDhcpClient *self); - -GBytes *nm_dhcp_client_get_duid(NMDhcpClient *self); - -GBytes *nm_dhcp_client_get_hw_addr(NMDhcpClient *self); - -GBytes *nm_dhcp_client_get_broadcast_hw_addr(NMDhcpClient *self); - -const char *nm_dhcp_client_get_anycast_address(NMDhcpClient *self); - -guint32 nm_dhcp_client_get_route_table(NMDhcpClient *self); - -void nm_dhcp_client_set_route_table(NMDhcpClient *self, guint32 route_table); +gboolean nm_dhcp_client_start_ip4(NMDhcpClient *self, GError **error); +gboolean nm_dhcp_client_start_ip6(NMDhcpClient *self, GError **error); -guint32 nm_dhcp_client_get_route_metric(NMDhcpClient *self); +const NMDhcpClientConfig *nm_dhcp_client_get_config(NMDhcpClient *self); -void nm_dhcp_client_set_route_metric(NMDhcpClient *self, guint32 route_metric); - -guint32 nm_dhcp_client_get_timeout(NMDhcpClient *self); - -guint32 nm_dhcp_client_get_iaid(NMDhcpClient *self); - -gboolean nm_dhcp_client_get_iaid_explicit(NMDhcpClient *self); - -GBytes *nm_dhcp_client_get_client_id(NMDhcpClient *self); - -const char * nm_dhcp_client_get_hostname(NMDhcpClient *self); -const char * nm_dhcp_client_get_mud_url(NMDhcpClient *self); -const char *const *nm_dhcp_client_get_reject_servers(NMDhcpClient *self); - -NMDhcpHostnameFlags nm_dhcp_client_get_hostname_flags(NMDhcpClient *self); - -NMDhcpClientFlags nm_dhcp_client_get_client_flags(NMDhcpClient *self); - -GBytes *nm_dhcp_client_get_vendor_class_identifier(NMDhcpClient *self); - -gboolean nm_dhcp_client_start_ip4(NMDhcpClient *self, - GBytes * client_id, - const char * last_ip4_address, - GError ** error); +pid_t nm_dhcp_client_get_pid(NMDhcpClient *self); -gboolean nm_dhcp_client_start_ip6(NMDhcpClient * self, - GBytes * client_id, - gboolean enforce_duid, - const struct in6_addr * ll_addr, - NMSettingIP6ConfigPrivacy privacy, - guint needed_prefixes, - GError ** error); +static inline const NML3ConfigData * +nm_dhcp_client_get_lease(NMDhcpClient *self) +{ + /* FIXME(l3cfg:dhcp:previous-lease): this function returns the currently + * valid, exposed lease. + * + * Note that NMDhcpClient should accept as construct argument a *previous* lease, + * and (if that lease is still valid), pretend that it's good to use. The point is + * so that during reapply we keep using the current address, until a new lease + * was received. */ + return NULL; +} gboolean nm_dhcp_client_accept(NMDhcpClient *self, GError **error); gboolean nm_dhcp_client_can_accept(NMDhcpClient *self); @@ -205,29 +268,29 @@ void nm_dhcp_client_watch_child(NMDhcpClient *self, pid_t pid); void nm_dhcp_client_stop_watch_child(NMDhcpClient *self, pid_t pid); -void nm_dhcp_client_set_state(NMDhcpClient *self, - NMDhcpState new_state, - NMIPConfig * ip_config, - GHashTable * options); /* str:str hash */ +void +nm_dhcp_client_set_state(NMDhcpClient *self, NMDhcpState new_state, const NML3ConfigData *l3cd); gboolean nm_dhcp_client_handle_event(gpointer unused, - const char * iface, + const char *iface, int pid, - GVariant * options, - const char * reason, + GVariant *options, + const char *reason, NMDhcpClient *self); -void nm_dhcp_client_set_client_id(NMDhcpClient *self, GBytes *client_id); -void nm_dhcp_client_set_client_id_bin(NMDhcpClient *self, - guint8 type, - const guint8 *client_id, - gsize len); - -void nm_dhcp_client_emit_ipv6_prefix_delegated(NMDhcpClient * self, +void nm_dhcp_client_emit_ipv6_prefix_delegated(NMDhcpClient *self, const NMPlatformIP6Address *prefix); gboolean nm_dhcp_client_server_id_is_rejected(NMDhcpClient *self, gconstpointer addr); +int nm_dhcp_client_get_addr_family(NMDhcpClient *self); +const char *nm_dhcp_client_get_iface(NMDhcpClient *self); +NMDedupMultiIndex *nm_dhcp_client_get_multi_idx(NMDhcpClient *self); +int nm_dhcp_client_get_ifindex(NMDhcpClient *self); + +void nm_dhcp_client_set_effective_client_id(NMDhcpClient *self, GBytes *client_id); +GBytes *nm_dhcp_client_get_effective_client_id(NMDhcpClient *self); + /***************************************************************************** * Client data *****************************************************************************/ diff --git a/src/core/dhcp/nm-dhcp-dhclient-utils.c b/src/core/dhcp/nm-dhcp-dhclient-utils.c index 341ac7b2..74e6b905 100644 --- a/src/core/dhcp/nm-dhcp-dhclient-utils.c +++ b/src/core/dhcp/nm-dhcp-dhclient-utils.c @@ -15,7 +15,6 @@ #include "libnm-glib-aux/nm-dedup-multi.h" #include "nm-dhcp-utils.h" -#include "nm-ip4-config.h" #include "nm-utils.h" #include "libnm-platform/nm-platform.h" #include "NetworkManagerUtils.h" @@ -98,9 +97,9 @@ grab_request_options(GPtrArray *store, const char *line) } static void -add_ip4_config(GString * str, - GBytes * client_id, - const char * hostname, +add_ip4_config(GString *str, + GBytes *client_id, + const char *hostname, gboolean use_fqdn, NMDhcpHostnameFlags hostname_flags) { @@ -205,10 +204,12 @@ static GBytes * read_client_id(const char *str) { gs_free char *s = NULL; - char * p; - int i = 0, j = 0; + char *p; + int i = 0; + int j = 0; + gsize l; - nm_assert(!strncmp(str, CLIENTID_TAG, NM_STRLEN(CLIENTID_TAG))); + nm_assert(NM_STR_HAS_PREFIX(str, CLIENTID_TAG)); str += NM_STRLEN(CLIENTID_TAG); if (!g_ascii_isspace(*str)) @@ -249,8 +250,9 @@ read_client_id(const char *str) /* Otherwise, try to read a hexadecimal sequence */ s = g_strdup(str); g_strchomp(s); - if (s[strlen(s) - 1] == ';') - s[strlen(s) - 1] = '\0'; + l = strlen(s); + if (l > 0 && s[l - 1] == ';') + s[l - 1] = '\0'; return nm_utils_hexstr2bin(s); } @@ -259,7 +261,7 @@ static gboolean read_interface(const char *line, char *interface, guint size) { gs_free char *dup = g_strdup(line + NM_STRLEN("interface")); - char * ptr = dup, *end; + char *ptr = dup, *end; while (g_ascii_isspace(*ptr)) ptr++; @@ -288,25 +290,25 @@ read_interface(const char *line, char *interface, guint size) } char * -nm_dhcp_dhclient_create_config(const char * interface, +nm_dhcp_dhclient_create_config(const char *interface, int addr_family, - GBytes * client_id, - const char * anycast_address, - const char * hostname, + GBytes *client_id, + const char *anycast_address, + const char *hostname, guint32 timeout, gboolean use_fqdn, NMDhcpHostnameFlags hostname_flags, - const char * mud_url, - const char *const * reject_servers, - const char * orig_path, - const char * orig_contents, - GBytes ** out_new_client_id) + const char *mud_url, + const char *const *reject_servers, + const char *orig_path, + const char *orig_contents, + GBytes **out_new_client_id) { - nm_auto_free_gstring GString *new_contents = NULL; - gs_unref_ptrarray GPtrArray *fqdn_opts = NULL; - gs_unref_ptrarray GPtrArray *reqs = NULL; - gboolean reset_reqlist = FALSE; - int i; + nm_auto_free_gstring GString *new_contents = NULL; + gs_unref_ptrarray GPtrArray *fqdn_opts = NULL; + gs_unref_ptrarray GPtrArray *reqs = NULL; + gboolean reset_reqlist = FALSE; + int i; g_return_val_if_fail(!anycast_address || nm_utils_hwaddr_valid(anycast_address, ETH_ALEN), NULL); @@ -318,8 +320,8 @@ nm_dhcp_dhclient_create_config(const char * interface, reqs = g_ptr_array_new_full(5, g_free); if (orig_contents) { - gs_free const char **lines = NULL; - gsize line_i; + gs_free const char **lines = NULL; + gsize line_i; nm_auto_free_gstring GString *blocks_stack = NULL; guint blocks_skip = 0; gboolean in_alsoreq = FALSE; @@ -385,11 +387,10 @@ nm_dhcp_dhclient_create_config(const char * interface, * fail the dhcp process before dhcp-timeout. So, always skip importing timeout * as we will need to add one greater than dhcp-timeout. */ - if (!strncmp(p, TIMEOUT_TAG, strlen(TIMEOUT_TAG)) - || !strncmp(p, RETRY_TAG, strlen(RETRY_TAG))) + if (NM_STR_HAS_PREFIX(p, TIMEOUT_TAG) || NM_STR_HAS_PREFIX(p, RETRY_TAG)) continue; - if (!strncmp(p, CLIENTID_TAG, strlen(CLIENTID_TAG))) { + if (NM_STR_HAS_PREFIX(p, CLIENTID_TAG)) { /* Override config file "dhcp-client-id" and use one from the connection */ if (client_id) continue; @@ -402,16 +403,16 @@ nm_dhcp_dhclient_create_config(const char * interface, /* Override config file hostname and use one from the connection */ if (hostname) { - if (strncmp(p, HOSTNAME4_TAG, strlen(HOSTNAME4_TAG)) == 0) + if (NM_STR_HAS_PREFIX(p, HOSTNAME4_TAG)) continue; - if (strncmp(p, FQDN_TAG, strlen(FQDN_TAG)) == 0) + if (NM_STR_HAS_PREFIX(p, FQDN_TAG)) continue; } /* To let user's FQDN options (except "fqdn.fqdn") override the * default ones set by NM, add them later */ - if (!strncmp(p, FQDN_TAG_PREFIX, NM_STRLEN(FQDN_TAG_PREFIX))) { + if (NM_STR_HAS_PREFIX(p, FQDN_TAG_PREFIX)) { if (!fqdn_opts) fqdn_opts = g_ptr_array_new_full(5, g_free); g_ptr_array_add(fqdn_opts, g_strdup(p + NM_STRLEN(FQDN_TAG_PREFIX))); @@ -423,9 +424,9 @@ nm_dhcp_dhclient_create_config(const char * interface, continue; /* Check for "request" */ - if (!strncmp(p, REQ_TAG, strlen(REQ_TAG))) { + if (NM_STR_HAS_PREFIX(p, REQ_TAG)) { in_req = TRUE; - p += strlen(REQ_TAG); + p += NM_STRLEN(REQ_TAG); g_ptr_array_set_size(reqs, 0); reset_reqlist = TRUE; } @@ -437,9 +438,9 @@ nm_dhcp_dhclient_create_config(const char * interface, } /* Check for "also require" */ - if (!strncmp(p, ALSOREQ_TAG, strlen(ALSOREQ_TAG))) { + if (NM_STR_HAS_PREFIX(p, ALSOREQ_TAG)) { in_alsoreq = TRUE; - p += strlen(ALSOREQ_TAG); + p += NM_STRLEN(ALSOREQ_TAG); } if (in_alsoreq) { @@ -526,10 +527,10 @@ nm_dhcp_dhclient_create_config(const char * interface, char * nm_dhcp_dhclient_escape_duid(GBytes *duid) { - char * escaped; + char *escaped; const guint8 *s, *s0; gsize len; - char * d; + char *d; g_return_val_if_fail(duid, NULL); @@ -563,7 +564,7 @@ isoctal(const guint8 *p) GBytes * nm_dhcp_dhclient_unescape_duid(const char *duid) { - GByteArray * unescaped; + GByteArray *unescaped; const guint8 *p = (const guint8 *) duid; guint i, len; guint8 octal; @@ -610,7 +611,7 @@ error: GBytes * nm_dhcp_dhclient_read_duid(const char *leasefile, GError **error) { - gs_free char * contents = NULL; + gs_free char *contents = NULL; gs_free const char **contents_v = NULL; gsize i; @@ -623,7 +624,7 @@ nm_dhcp_dhclient_read_duid(const char *leasefile, GError **error) contents_v = nm_strsplit_set(contents, "\n\r"); for (i = 0; contents_v && contents_v[i]; i++) { const char *p = nm_str_skip_leading_spaces(contents_v[i]); - GBytes * duid; + GBytes *duid; if (!NM_STR_HAS_PREFIX(p, DUID_PREFIX)) continue; @@ -648,10 +649,10 @@ nm_dhcp_dhclient_read_duid(const char *leasefile, GError **error) gboolean nm_dhcp_dhclient_save_duid(const char *leasefile, GBytes *duid, GError **error) { - gs_free char * escaped_duid = NULL; - gs_free const char **lines = NULL; - nm_auto_free_gstring GString *s = NULL; - const char *const * iter; + gs_free char *escaped_duid = NULL; + gs_free const char **lines = NULL; + nm_auto_free_gstring GString *s = NULL; + const char *const *iter; gsize len = 0; g_return_val_if_fail(leasefile != NULL, FALSE); diff --git a/src/core/dhcp/nm-dhcp-dhclient-utils.h b/src/core/dhcp/nm-dhcp-dhclient-utils.h index ed7c1c7c..0ce7dd90 100644 --- a/src/core/dhcp/nm-dhcp-dhclient-utils.h +++ b/src/core/dhcp/nm-dhcp-dhclient-utils.h @@ -9,19 +9,19 @@ #include "nm-setting-ip4-config.h" #include "nm-setting-ip6-config.h" -char *nm_dhcp_dhclient_create_config(const char * interface, +char *nm_dhcp_dhclient_create_config(const char *interface, int addr_family, - GBytes * client_id, - const char * anycast_addr, - const char * hostname, + GBytes *client_id, + const char *anycast_addr, + const char *hostname, guint32 timeout, gboolean use_fqdn, NMDhcpHostnameFlags hostname_flags, - const char * mud_url, - const char *const * reject_servers, - const char * orig_path, - const char * orig_contents, - GBytes ** out_new_client_id); + const char *mud_url, + const char *const *reject_servers, + const char *orig_path, + const char *orig_contents, + GBytes **out_new_client_id); char *nm_dhcp_dhclient_escape_duid(GBytes *duid); diff --git a/src/core/dhcp/nm-dhcp-dhclient.c b/src/core/dhcp/nm-dhcp-dhclient.c index 970a51f5..28d40c07 100644 --- a/src/core/dhcp/nm-dhcp-dhclient.c +++ b/src/core/dhcp/nm-dhcp-dhclient.c @@ -59,10 +59,10 @@ static GType nm_dhcp_dhclient_get_type(void); /*****************************************************************************/ typedef struct { - char * conf_file; - const char * def_leasefile; - char * lease_file; - char * pid_file; + char *conf_file; + const char *def_leasefile; + char *lease_file; + char *pid_file; NMDhcpListener *dhcp_listener; } NMDhcpDhclientPrivate; @@ -105,7 +105,7 @@ static char * get_dhclient_leasefile(int addr_family, const char *iface, const char *uuid, - char ** out_preferred_path) + char **out_preferred_path) { gs_free char *path = NULL; @@ -145,21 +145,21 @@ get_dhclient_leasefile(int addr_family, } static gboolean -merge_dhclient_config(NMDhcpDhclient * self, +merge_dhclient_config(NMDhcpDhclient *self, int addr_family, - const char * iface, - const char * conf_file, - GBytes * client_id, - const char * anycast_address, - const char * hostname, + const char *iface, + const char *conf_file, + GBytes *client_id, + const char *anycast_address, + const char *hostname, guint32 timeout, gboolean use_fqdn, NMDhcpHostnameFlags hostname_flags, - const char * mud_url, - const char *const * reject_servers, - const char * orig_path, - GBytes ** out_new_client_id, - GError ** error) + const char *mud_url, + const char *const *reject_servers, + const char *orig_path, + GBytes **out_new_client_id, + GError **error) { gs_free char *orig = NULL; gs_free char *new = NULL; @@ -274,19 +274,19 @@ find_existing_config(NMDhcpDhclient *self, int addr_family, const char *iface, c * config file along with the NM options. */ static char * -create_dhclient_config(NMDhcpDhclient * self, +create_dhclient_config(NMDhcpDhclient *self, int addr_family, - const char * iface, - const char * uuid, - GBytes * client_id, - const char * anycast_address, - const char * hostname, + const char *iface, + const char *uuid, + GBytes *client_id, + const char *anycast_address, + const char *hostname, guint32 timeout, gboolean use_fqdn, NMDhcpHostnameFlags hostname_flags, - const char * mud_url, - const char *const * reject_servers, - GBytes ** out_new_client_id) + const char *mud_url, + const char *const *reject_servers, + GBytes **out_new_client_id) { gs_free char *orig = NULL; char *new = NULL; @@ -330,29 +330,31 @@ create_dhclient_config(NMDhcpDhclient * self, static gboolean dhclient_start(NMDhcpClient *client, - const char * mode_opt, + const char *mode_opt, gboolean release, - pid_t * out_pid, - int prefixes, - GError ** error) + pid_t *out_pid, + GError **error) { - NMDhcpDhclient * self = NM_DHCP_DHCLIENT(client); - NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE(self); + NMDhcpDhclient *self = NM_DHCP_DHCLIENT(client); + NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE(self); gs_unref_ptrarray GPtrArray *argv = NULL; pid_t pid; - gs_free_error GError *local = NULL; - const char * iface; - const char * uuid; - const char * system_bus_address; - const char * dhclient_path; - char * binary_name; - gs_free char * cmd_str = NULL; - gs_free char * pid_file = NULL; - gs_free char * system_bus_address_env = NULL; - gs_free char * preferred_leasefile_path = NULL; - const int addr_family = nm_dhcp_client_get_addr_family(client); + gs_free_error GError *local = NULL; + const char *iface; + const char *uuid; + const char *system_bus_address; + const char *dhclient_path; + char *binary_name; + gs_free char *cmd_str = NULL; + gs_free char *pid_file = NULL; + gs_free char *system_bus_address_env = NULL; + gs_free char *preferred_leasefile_path = NULL; + int addr_family; + const NMDhcpClientConfig *client_config; g_return_val_if_fail(!priv->pid_file, FALSE); + client_config = nm_dhcp_client_get_config(client); + addr_family = client_config->addr_family; NM_SET_OUT(out_pid, 0); @@ -362,8 +364,8 @@ dhclient_start(NMDhcpClient *client, return FALSE; } - iface = nm_dhcp_client_get_iface(client); - uuid = nm_dhcp_client_get_uuid(client); + iface = client_config->iface; + uuid = client_config->uuid; pid_file = g_strdup_printf(NMRUNDIR "/dhclient%s-%s.pid", _addr_family_to_path_part(addr_family), @@ -409,9 +411,7 @@ dhclient_start(NMDhcpClient *client, /* Save the DUID to the leasefile dhclient will actually use */ if (addr_family == AF_INET6) { - if (!nm_dhcp_dhclient_save_duid(priv->lease_file, - nm_dhcp_client_get_client_id(client), - &local)) { + if (!nm_dhcp_dhclient_save_duid(priv->lease_file, client_config->client_id, &local)) { nm_utils_error_set(error, NM_UTILS_ERROR_UNKNOWN, "failed to save DUID to '%s': %s", @@ -434,13 +434,13 @@ dhclient_start(NMDhcpClient *client, if (release) g_ptr_array_add(argv, (gpointer) "-r"); - if (!release - && NM_FLAGS_HAS(nm_dhcp_client_get_client_flags(NM_DHCP_CLIENT(self)), - NM_DHCP_CLIENT_FLAGS_REQUEST_BROADCAST)) { + if (!release && client_config->addr_family == AF_INET && client_config->v4.request_broadcast) { g_ptr_array_add(argv, (gpointer) "-B"); } if (addr_family == AF_INET6) { + guint prefixes = client_config->v6.needed_prefixes; + g_ptr_array_add(argv, (gpointer) "-6"); if (prefixes > 0 && nm_streq0(mode_opt, "-S")) { @@ -513,29 +513,28 @@ dhclient_start(NMDhcpClient *client, } static gboolean -ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) +ip4_start(NMDhcpClient *client, GError **error) { - NMDhcpDhclient * self = NM_DHCP_DHCLIENT(client); - NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE(self); - GBytes * client_id; - gs_unref_bytes GBytes *new_client_id = NULL; - - client_id = nm_dhcp_client_get_client_id(client); - - priv->conf_file = create_dhclient_config( - self, - AF_INET, - nm_dhcp_client_get_iface(client), - nm_dhcp_client_get_uuid(client), - client_id, - nm_dhcp_client_get_anycast_address(client), - nm_dhcp_client_get_hostname(client), - nm_dhcp_client_get_timeout(client), - NM_FLAGS_HAS(nm_dhcp_client_get_client_flags(client), NM_DHCP_CLIENT_FLAGS_USE_FQDN), - nm_dhcp_client_get_hostname_flags(client), - nm_dhcp_client_get_mud_url(client), - nm_dhcp_client_get_reject_servers(client), - &new_client_id); + NMDhcpDhclient *self = NM_DHCP_DHCLIENT(client); + NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE(self); + gs_unref_bytes GBytes *new_client_id = NULL; + const NMDhcpClientConfig *client_config; + + client_config = nm_dhcp_client_get_config(client); + + priv->conf_file = create_dhclient_config(self, + AF_INET, + client_config->iface, + client_config->uuid, + client_config->client_id, + client_config->anycast_address, + client_config->hostname, + client_config->timeout, + client_config->use_fqdn, + client_config->hostname_flags, + client_config->mud_url, + client_config->reject_servers, + &new_client_id); if (!priv->conf_file) { nm_utils_error_set_literal(error, NM_UTILS_ERROR_UNKNOWN, @@ -544,36 +543,35 @@ ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) } if (new_client_id) { - nm_assert(!client_id); - nm_dhcp_client_set_client_id(client, new_client_id); + nm_assert(!client_config->client_id); + nm_dhcp_client_set_effective_client_id(client, new_client_id); } - return dhclient_start(client, NULL, FALSE, NULL, 0, error); + return dhclient_start(client, NULL, FALSE, NULL, error); } static gboolean -ip6_start(NMDhcpClient * client, - const struct in6_addr * ll_addr, - NMSettingIP6ConfigPrivacy privacy, - guint needed_prefixes, - GError ** error) +ip6_start(NMDhcpClient *client, const struct in6_addr *ll_addr, GError **error) { - NMDhcpDhclient * self = NM_DHCP_DHCLIENT(client); - NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE(self); + NMDhcpDhclient *self = NM_DHCP_DHCLIENT(client); + NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE(self); + const NMDhcpClientConfig *config; - if (nm_dhcp_client_get_iaid_explicit(client)) + config = nm_dhcp_client_get_config(client); + + if (config->v6.iaid_explicit) _LOGW("dhclient does not support specifying an IAID for DHCPv6, it will be ignored"); priv->conf_file = create_dhclient_config(self, AF_INET6, - nm_dhcp_client_get_iface(client), - nm_dhcp_client_get_uuid(client), + config->iface, + config->uuid, NULL, - nm_dhcp_client_get_anycast_address(client), - nm_dhcp_client_get_hostname(client), - nm_dhcp_client_get_timeout(client), + config->anycast_address, + config->hostname, + config->timeout, TRUE, - nm_dhcp_client_get_hostname_flags(client), - nm_dhcp_client_get_mud_url(client), + config->hostname_flags, + config->mud_url, NULL, NULL); if (!priv->conf_file) { @@ -583,21 +581,13 @@ ip6_start(NMDhcpClient * client, return FALSE; } - return dhclient_start(client, - NM_FLAGS_HAS(nm_dhcp_client_get_client_flags(NM_DHCP_CLIENT(self)), - NM_DHCP_CLIENT_FLAGS_INFO_ONLY) - ? "-S" - : "-N", - FALSE, - NULL, - needed_prefixes, - error); + return dhclient_start(client, config->v6.needed_prefixes ? "-S" : "-N", FALSE, NULL, error); } static void stop(NMDhcpClient *client, gboolean release) { - NMDhcpDhclient * self = NM_DHCP_DHCLIENT(client); + NMDhcpDhclient *self = NM_DHCP_DHCLIENT(client); NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE(self); int errsv; @@ -625,7 +615,7 @@ stop(NMDhcpClient *client, gboolean release) if (release) { pid_t rpid = -1; - if (dhclient_start(client, NULL, TRUE, &rpid, 0, NULL)) { + if (dhclient_start(client, NULL, TRUE, &rpid, NULL)) { /* Wait a few seconds for the release to happen */ nm_dhcp_client_stop_pid(rpid, nm_dhcp_client_get_iface(client)); } @@ -635,16 +625,19 @@ stop(NMDhcpClient *client, gboolean release) static GBytes * get_duid(NMDhcpClient *client) { - NMDhcpDhclient * self = NM_DHCP_DHCLIENT(client); - NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE(self); - GBytes * duid = NULL; - gs_free char * leasefile = NULL; - GError * error = NULL; + NMDhcpDhclient *self = NM_DHCP_DHCLIENT(client); + NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE(self); + const NMDhcpClientConfig *client_config; + GBytes *duid = NULL; + gs_free char *leasefile = NULL; + GError *error = NULL; + + client_config = nm_dhcp_client_get_config(client); /* Look in interface-specific leasefile first for backwards compat */ leasefile = get_dhclient_leasefile(AF_INET6, nm_dhcp_client_get_iface(client), - nm_dhcp_client_get_uuid(client), + client_config->uuid, NULL); if (leasefile) { _LOGD("looking for DUID in '%s'", leasefile); @@ -719,7 +712,7 @@ static void nm_dhcp_dhclient_class_init(NMDhcpDhclientClass *dhclient_class) { NMDhcpClientClass *client_class = NM_DHCP_CLIENT_CLASS(dhclient_class); - GObjectClass * object_class = G_OBJECT_CLASS(dhclient_class); + GObjectClass *object_class = G_OBJECT_CLASS(dhclient_class); object_class->dispose = dispose; diff --git a/src/core/dhcp/nm-dhcp-dhcpcanon.c b/src/core/dhcp/nm-dhcp-dhcpcanon.c index f993ffb9..87e43fa8 100644 --- a/src/core/dhcp/nm-dhcp-dhcpcanon.c +++ b/src/core/dhcp/nm-dhcp-dhcpcanon.c @@ -34,10 +34,10 @@ static GType nm_dhcp_dhcpcanon_get_type(void); /*****************************************************************************/ typedef struct { - char * conf_file; - const char * def_leasefile; - char * lease_file; - char * pid_file; + char *conf_file; + const char *def_leasefile; + char *lease_file; + char *pid_file; NMDhcpListener *dhcp_listener; } NMDhcpDhcpcanonPrivate; @@ -65,25 +65,25 @@ nm_dhcp_dhcpcanon_get_path(void) static gboolean dhcpcanon_start(NMDhcpClient *client, - const char * mode_opt, - GBytes * duid, + const char *mode_opt, + GBytes *duid, gboolean release, - pid_t * out_pid, + pid_t *out_pid, guint needed_prefixes, - GError ** error) + GError **error) { - NMDhcpDhcpcanon * self = NM_DHCP_DHCPCANON(client); - NMDhcpDhcpcanonPrivate *priv = NM_DHCP_DHCPCANON_GET_PRIVATE(self); + NMDhcpDhcpcanon *self = NM_DHCP_DHCPCANON(client); + NMDhcpDhcpcanonPrivate *priv = NM_DHCP_DHCPCANON_GET_PRIVATE(self); gs_unref_ptrarray GPtrArray *argv = NULL; pid_t pid; - gs_free_error GError *local = NULL; - const char * iface; - const char * system_bus_address; - const char * dhcpcanon_path; - gs_free char * binary_name = NULL; - gs_free char * pid_file = NULL; - gs_free char * system_bus_address_env = NULL; - int addr_family; + gs_free_error GError *local = NULL; + const char *iface; + const char *system_bus_address; + const char *dhcpcanon_path; + gs_free char *binary_name = NULL; + gs_free char *pid_file = NULL; + gs_free char *system_bus_address_env = NULL; + int addr_family; g_return_val_if_fail(!priv->pid_file, FALSE); @@ -160,7 +160,7 @@ dhcpcanon_start(NMDhcpClient *client, } static gboolean -ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) +ip4_start(NMDhcpClient *client, GError **error) { return dhcpcanon_start(client, NULL, NULL, FALSE, NULL, 0, error); } @@ -168,7 +168,7 @@ ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) static void stop(NMDhcpClient *client, gboolean release) { - NMDhcpDhcpcanon * self = NM_DHCP_DHCPCANON(client); + NMDhcpDhcpcanon *self = NM_DHCP_DHCPCANON(client); NMDhcpDhcpcanonPrivate *priv = NM_DHCP_DHCPCANON_GET_PRIVATE(self); int errsv; @@ -222,7 +222,7 @@ static void nm_dhcp_dhcpcanon_class_init(NMDhcpDhcpcanonClass *dhcpcanon_class) { NMDhcpClientClass *client_class = NM_DHCP_CLIENT_CLASS(dhcpcanon_class); - GObjectClass * object_class = G_OBJECT_CLASS(dhcpcanon_class); + GObjectClass *object_class = G_OBJECT_CLASS(dhcpcanon_class); object_class->dispose = dispose; diff --git a/src/core/dhcp/nm-dhcp-dhcpcd.c b/src/core/dhcp/nm-dhcp-dhcpcd.c index 7522156b..45f96ec9 100644 --- a/src/core/dhcp/nm-dhcp-dhcpcd.c +++ b/src/core/dhcp/nm-dhcp-dhcpcd.c @@ -64,21 +64,19 @@ nm_dhcp_dhcpcd_get_path(void) } static gboolean -ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) +ip4_start(NMDhcpClient *client, GError **error) { - NMDhcpDhcpcd * self = NM_DHCP_DHCPCD(client); + NMDhcpDhcpcd *self = NM_DHCP_DHCPCD(client); + const NMDhcpClientConfig *client_config; gs_unref_ptrarray GPtrArray *argv = NULL; pid_t pid; - GError * local; - gs_free char * cmd_str = NULL; - const char * iface; - const char * dhcpcd_path; - const char * hostname; + GError *local; + gs_free char *cmd_str = NULL; + const char *dhcpcd_path; pid = nm_dhcp_client_get_pid(client); g_return_val_if_fail(pid == -1, FALSE); - - iface = nm_dhcp_client_get_iface(client); + client_config = nm_dhcp_client_get_config(client); dhcpcd_path = nm_dhcp_dhcpcd_get_path(); if (!dhcpcd_path) { @@ -115,21 +113,19 @@ ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) */ g_ptr_array_add(argv, (gpointer) "-4"); - hostname = nm_dhcp_client_get_hostname(client); - - if (hostname) { - if (NM_FLAGS_HAS(nm_dhcp_client_get_client_flags(client), NM_DHCP_CLIENT_FLAGS_USE_FQDN)) { + if (client_config->hostname) { + if (client_config->use_fqdn) { g_ptr_array_add(argv, (gpointer) "-h"); - g_ptr_array_add(argv, (gpointer) hostname); + g_ptr_array_add(argv, (gpointer) client_config->hostname); g_ptr_array_add(argv, (gpointer) "-F"); g_ptr_array_add(argv, (gpointer) "both"); } else { g_ptr_array_add(argv, (gpointer) "-h"); - g_ptr_array_add(argv, (gpointer) hostname); + g_ptr_array_add(argv, (gpointer) client_config->hostname); } } - g_ptr_array_add(argv, (gpointer) iface); + g_ptr_array_add(argv, (gpointer) client_config->iface); g_ptr_array_add(argv, NULL); _LOGD("running: %s", (cmd_str = g_strjoinv(" ", (char **) argv->pdata))); @@ -223,7 +219,7 @@ static void nm_dhcp_dhcpcd_class_init(NMDhcpDhcpcdClass *dhcpcd_class) { NMDhcpClientClass *client_class = NM_DHCP_CLIENT_CLASS(dhcpcd_class); - GObjectClass * object_class = G_OBJECT_CLASS(dhcpcd_class); + GObjectClass *object_class = G_OBJECT_CLASS(dhcpcd_class); object_class->dispose = dispose; diff --git a/src/core/dhcp/nm-dhcp-helper.c b/src/core/dhcp/nm-dhcp-helper.c index fd666676..41862f2b 100644 --- a/src/core/dhcp/nm-dhcp-helper.c +++ b/src/core/dhcp/nm-dhcp-helper.c @@ -61,9 +61,9 @@ build_signal_parameters(void) for (environ_iter = (const char *const *) environ; *environ_iter; environ_iter++) { static const char *const ignore_with_prefix_list[] = {"PATH", "SHLVL", "_", "PWD", "dhc_dbus", NULL}; - const char * item = *environ_iter; - gs_free char * name = NULL; - const char * val; + const char *item = *environ_iter; + gs_free char *name = NULL; + const char *val; const char *const *p; val = strchr(item, '='); @@ -119,13 +119,13 @@ int main(int argc, char *argv[]) { gs_unref_object GDBusConnection *connection = NULL; - gs_free_error GError *error = NULL; - gs_unref_variant GVariant *parameters = NULL; - gs_unref_variant GVariant *result = NULL; - gboolean success = FALSE; - guint try_count; - gint64 time_start; - gint64 time_end; + gs_free_error GError *error = NULL; + gs_unref_variant GVariant *parameters = NULL; + gs_unref_variant GVariant *result = NULL; + gboolean success = FALSE; + guint try_count; + gint64 time_start; + gint64 time_end; /* Connecting to the unix socket can fail with EAGAIN if there are too * many pending connections and the server can't accept them in time diff --git a/src/core/dhcp/nm-dhcp-listener.c b/src/core/dhcp/nm-dhcp-listener.c index ae2c40f1..2c567593 100644 --- a/src/core/dhcp/nm-dhcp-listener.c +++ b/src/core/dhcp/nm-dhcp-listener.c @@ -50,7 +50,7 @@ typedef struct { NMDBusManager *dbus_mgr; gulong new_conn_id; gulong dis_conn_id; - GHashTable * connections; + GHashTable *connections; } NMDhcpListenerPrivate; struct _NMDhcpListener { @@ -98,10 +98,10 @@ NM_DEFINE_SINGLETON_GETTER(NMDhcpListener, nm_dhcp_listener_get, NM_TYPE_DHCP_LI static char * get_option(GVariant *options, const char *key) { - GVariant * value; + GVariant *value; const guchar *bytes, *s; gsize len; - char * converted, *d; + char *converted, *d; if (!g_variant_lookup(options, key, "@ay", &value)) return NULL; @@ -130,9 +130,9 @@ get_option(GVariant *options, const char *key) static void _method_call_handle(NMDhcpListener *self, GVariant *parameters) { - gs_free char * iface = NULL; - gs_free char * pid_str = NULL; - gs_free char * reason = NULL; + gs_free char *iface = NULL; + gs_free char *pid_str = NULL; + gs_free char *reason = NULL; gs_unref_variant GVariant *options = NULL; int pid; gboolean handled = FALSE; @@ -169,12 +169,12 @@ _method_call_handle(NMDhcpListener *self, GVariant *parameters) } static void -_method_call(GDBusConnection * connection, - const char * sender, - const char * object_path, - const char * interface_name, - const char * method_name, - GVariant * parameters, +_method_call(GDBusConnection *connection, + const char *sender, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data) { @@ -219,14 +219,14 @@ _dbus_connection_register_object(NMDhcpListener *self, GDBusConnection *connecti } static void -new_connection_cb(NMDBusManager * mgr, - GDBusConnection * connection, +new_connection_cb(NMDBusManager *mgr, + GDBusConnection *connection, GDBusObjectManager *manager, - NMDhcpListener * self) + NMDhcpListener *self) { NMDhcpListenerPrivate *priv = NM_DHCP_LISTENER_GET_PRIVATE(self); guint registration_id; - GError * error = NULL; + GError *error = NULL; /* it is important to register the object during the new-connection signal, * as this avoids races with the connecting object. */ diff --git a/src/core/dhcp/nm-dhcp-manager.c b/src/core/dhcp/nm-dhcp-manager.c index 3cb89393..f353e637 100644 --- a/src/core/dhcp/nm-dhcp-manager.c +++ b/src/core/dhcp/nm-dhcp-manager.c @@ -17,7 +17,6 @@ #include #include "libnm-glib-aux/nm-dedup-multi.h" -#include "libnm-systemd-shared/nm-sd-utils-shared.h" #include "nm-config.h" #include "NetworkManagerUtils.h" @@ -26,7 +25,6 @@ typedef struct { const NMDhcpClientFactory *client_factory; - char * default_hostname; } NMDhcpManagerPrivate; struct _NMDhcpManager { @@ -129,136 +127,54 @@ _client_factory_get_gtype(const NMDhcpClientFactory *client_factory, int addr_fa /*****************************************************************************/ -static NMDhcpClient * -client_start(NMDhcpManager * self, - int addr_family, - NMDedupMultiIndex * multi_idx, - const char * iface, - int ifindex, - GBytes * hwaddr, - GBytes * bcast_hwaddr, - const char * uuid, - guint32 route_table, - guint32 route_metric, - const struct in6_addr * ipv6_ll_addr, - GBytes * dhcp_client_id, - gboolean enforce_duid, - guint32 iaid, - gboolean iaid_explicit, - guint32 timeout, - NMDhcpClientFlags client_flags, - const char * anycast_address, - const char * hostname, - NMDhcpHostnameFlags hostname_flags, - const char * mud_url, - NMSettingIP6ConfigPrivacy privacy, - const char * last_ip4_address, - guint needed_prefixes, - GBytes * vendor_class_identifier, - const char *const * reject_servers, - GError ** error) +NMDhcpClient * +nm_dhcp_manager_start_client(NMDhcpManager *self, NMDhcpClientConfig *config, GError **error) { - NMDhcpManagerPrivate *priv; + NMDhcpManagerPrivate *priv; gs_unref_object NMDhcpClient *client = NULL; gboolean success = FALSE; gsize hwaddr_len; GType gtype; g_return_val_if_fail(NM_IS_DHCP_MANAGER(self), NULL); - g_return_val_if_fail(iface, NULL); - g_return_val_if_fail(ifindex > 0, NULL); - g_return_val_if_fail(uuid != NULL, NULL); - g_return_val_if_fail(!dhcp_client_id || g_bytes_get_size(dhcp_client_id) >= 2, NULL); - g_return_val_if_fail(!vendor_class_identifier - || g_bytes_get_size(vendor_class_identifier) <= 255, + g_return_val_if_fail(config, NULL); + g_return_val_if_fail(config->iface, NULL); + g_return_val_if_fail(config->l3cfg, NULL); + g_return_val_if_fail(config->uuid != NULL, NULL); + g_return_val_if_fail(!config->client_id || g_bytes_get_size(config->client_id) >= 2, NULL); + g_return_val_if_fail(!config->vendor_class_identifier + || g_bytes_get_size(config->vendor_class_identifier) <= 255, NULL); g_return_val_if_fail(!error || !*error, NULL); - nm_assert(!NM_FLAGS_ANY(client_flags, ~NM_DHCP_CLIENT_FLAGS_ALL)); - if (addr_family == AF_INET) { - if (!hwaddr || !bcast_hwaddr) { + if (config->addr_family == AF_INET) { + if (!config->hwaddr || !config->bcast_hwaddr) { nm_utils_error_set(error, NM_UTILS_ERROR_UNKNOWN, "missing %s address", - hwaddr ? "broadcast" : "MAC"); + config->hwaddr ? "broadcast" : "MAC"); return NULL; } - hwaddr_len = g_bytes_get_size(hwaddr); + hwaddr_len = g_bytes_get_size(config->hwaddr); if (hwaddr_len == 0 || hwaddr_len > _NM_UTILS_HWADDR_LEN_MAX) { nm_utils_error_set(error, NM_UTILS_ERROR_UNKNOWN, "invalid MAC address"); g_return_val_if_reached(NULL); } - nm_assert(g_bytes_get_size(hwaddr) == g_bytes_get_size(bcast_hwaddr)); - } else { - hwaddr = NULL; - bcast_hwaddr = NULL; - } - - if (hostname) { - gboolean use_fqdn = NM_FLAGS_HAS(client_flags, NM_DHCP_CLIENT_FLAGS_USE_FQDN); - - if ((use_fqdn && !nm_sd_dns_name_is_valid(hostname)) - || (!use_fqdn && !nm_sd_hostname_is_valid(hostname, FALSE))) { - nm_log_warn(LOGD_DHCP, - "dhcp%c: %s '%s' is invalid, will be ignored", - nm_utils_addr_family_to_char(addr_family), - use_fqdn ? "FQDN" : "hostname", - hostname); - hostname = NULL; - } + nm_assert(g_bytes_get_size(config->hwaddr) == g_bytes_get_size(config->bcast_hwaddr)); } priv = NM_DHCP_MANAGER_GET_PRIVATE(self); - gtype = _client_factory_get_gtype(priv->client_factory, addr_family); + gtype = _client_factory_get_gtype(priv->client_factory, config->addr_family); nm_log_trace(LOGD_DHCP, "dhcp%c: creating IPv%c DHCP client of type %s", - nm_utils_addr_family_to_char(addr_family), - nm_utils_addr_family_to_char(addr_family), + nm_utils_addr_family_to_char(config->addr_family), + nm_utils_addr_family_to_char(config->addr_family), g_type_name(gtype)); - client = g_object_new(gtype, - NM_DHCP_CLIENT_MULTI_IDX, - multi_idx, - NM_DHCP_CLIENT_ADDR_FAMILY, - addr_family, - NM_DHCP_CLIENT_INTERFACE, - iface, - NM_DHCP_CLIENT_IFINDEX, - ifindex, - NM_DHCP_CLIENT_HWADDR, - hwaddr, - NM_DHCP_CLIENT_BROADCAST_HWADDR, - bcast_hwaddr, - NM_DHCP_CLIENT_UUID, - uuid, - NM_DHCP_CLIENT_IAID, - (guint) iaid, - NM_DHCP_CLIENT_IAID_EXPLICIT, - iaid_explicit, - NM_DHCP_CLIENT_HOSTNAME, - hostname, - NM_DHCP_CLIENT_MUD_URL, - mud_url, - NM_DHCP_CLIENT_ROUTE_TABLE, - (guint) route_table, - NM_DHCP_CLIENT_ROUTE_METRIC, - (guint) route_metric, - NM_DHCP_CLIENT_TIMEOUT, - (guint) timeout, - NM_DHCP_CLIENT_HOSTNAME_FLAGS, - (guint) hostname_flags, - NM_DHCP_CLIENT_VENDOR_CLASS_IDENTIFIER, - vendor_class_identifier, - NM_DHCP_CLIENT_REJECT_SERVERS, - reject_servers, - NM_DHCP_CLIENT_FLAGS, - (guint) client_flags, - NM_DHCP_CLIENT_ANYCAST_ADDRESS, - anycast_address, - NULL); + client = g_object_new(gtype, NM_DHCP_CLIENT_CONFIG, config, NULL); /* unfortunately, our implementations work differently per address-family regarding client-id/DUID. * @@ -286,16 +202,10 @@ client_start(NMDhcpManager * self, * default outside of NetworkManager API. */ - if (addr_family == AF_INET) { - success = nm_dhcp_client_start_ip4(client, dhcp_client_id, last_ip4_address, error); + if (config->addr_family == AF_INET) { + success = nm_dhcp_client_start_ip4(client, error); } else { - success = nm_dhcp_client_start_ip6(client, - dhcp_client_id, - enforce_duid, - ipv6_ll_addr, - privacy, - needed_prefixes, - error); + success = nm_dhcp_client_start_ip6(client, error); } if (!success) @@ -304,178 +214,6 @@ client_start(NMDhcpManager * self, return g_steal_pointer(&client); } -/* Caller owns a reference to the NMDhcpClient on return */ -NMDhcpClient * -nm_dhcp_manager_start_ip4(NMDhcpManager * self, - NMDedupMultiIndex * multi_idx, - const char * iface, - int ifindex, - GBytes * hwaddr, - GBytes * bcast_hwaddr, - const char * uuid, - guint32 route_table, - guint32 route_metric, - NMDhcpClientFlags client_flags, - gboolean send_hostname, - const char * dhcp_hostname, - const char * dhcp_fqdn, - NMDhcpHostnameFlags hostname_flags, - const char * mud_url, - GBytes * dhcp_client_id, - guint32 timeout, - const char * anycast_address, - const char * last_ip_address, - GBytes * vendor_class_identifier, - const char *const * reject_servers, - GError ** error) -{ - NMDhcpManagerPrivate *priv; - const char * hostname = NULL; - gs_free char * hostname_tmp = NULL; - gboolean use_fqdn = FALSE; - char * dot; - - /* these flags are set automatically/prohibited, and not free to set to the caller. */ - nm_assert(!NM_FLAGS_ANY(client_flags, - NM_DHCP_CLIENT_FLAGS_USE_FQDN | NM_DHCP_CLIENT_FLAGS_INFO_ONLY)); - - g_return_val_if_fail(NM_IS_DHCP_MANAGER(self), NULL); - priv = NM_DHCP_MANAGER_GET_PRIVATE(self); - - if (send_hostname) { - /* Use, in order of preference: - * 1. FQDN from configuration - * 2. hostname from configuration - * 3. system hostname (only host part) - */ - if (dhcp_fqdn) { - hostname = dhcp_fqdn; - use_fqdn = TRUE; - } else if (dhcp_hostname) - hostname = dhcp_hostname; - else { - hostname = priv->default_hostname; - if (hostname) { - hostname_tmp = g_strdup(hostname); - dot = strchr(hostname_tmp, '.'); - if (dot) - *dot = '\0'; - hostname = hostname_tmp; - } - } - } - - return client_start( - self, - AF_INET, - multi_idx, - iface, - ifindex, - hwaddr, - bcast_hwaddr, - uuid, - route_table, - route_metric, - NULL, - dhcp_client_id, - FALSE, - 0, - FALSE, - timeout, - client_flags | (use_fqdn ? NM_DHCP_CLIENT_FLAGS_USE_FQDN : NM_DHCP_CLIENT_FLAGS_NONE), - anycast_address, - hostname, - hostname_flags, - mud_url, - 0, - last_ip_address, - 0, - vendor_class_identifier, - reject_servers, - error); -} - -/* Caller owns a reference to the NMDhcpClient on return */ -NMDhcpClient * -nm_dhcp_manager_start_ip6(NMDhcpManager * self, - NMDedupMultiIndex * multi_idx, - const char * iface, - int ifindex, - const struct in6_addr * ll_addr, - const char * uuid, - guint32 route_table, - guint32 route_metric, - NMDhcpClientFlags client_flags, - gboolean send_hostname, - const char * dhcp_hostname, - NMDhcpHostnameFlags hostname_flags, - const char * mud_url, - GBytes * duid, - gboolean enforce_duid, - guint32 iaid, - gboolean iaid_explicit, - guint32 timeout, - const char * anycast_address, - NMSettingIP6ConfigPrivacy privacy, - guint needed_prefixes, - GError ** error) -{ - NMDhcpManagerPrivate *priv; - const char * hostname = NULL; - - /* this flag is set automatically, and not free to set to the caller. */ - nm_assert(!NM_FLAGS_ANY(client_flags, NM_DHCP_CLIENT_FLAGS_USE_FQDN)); - - g_return_val_if_fail(NM_IS_DHCP_MANAGER(self), NULL); - priv = NM_DHCP_MANAGER_GET_PRIVATE(self); - - if (send_hostname) { - /* Always prefer the explicit dhcp-hostname if given */ - hostname = dhcp_hostname ?: priv->default_hostname; - } - return client_start(self, - AF_INET6, - multi_idx, - iface, - ifindex, - NULL, - NULL, - uuid, - route_table, - route_metric, - ll_addr, - duid, - enforce_duid, - iaid, - iaid_explicit, - timeout, - client_flags | NM_DHCP_CLIENT_FLAGS_USE_FQDN, - anycast_address, - hostname, - hostname_flags, - mud_url, - privacy, - NULL, - needed_prefixes, - NULL, - NULL, - error); -} - -void -nm_dhcp_manager_set_default_hostname(NMDhcpManager *manager, const char *hostname) -{ - NMDhcpManagerPrivate *priv = NM_DHCP_MANAGER_GET_PRIVATE(manager); - - nm_clear_g_free(&priv->default_hostname); - - /* Never send 'localhost'-type names to the DHCP server */ - if (!nm_utils_is_specific_hostname(hostname)) - return; - - priv->default_hostname = g_strdup(hostname); -} - const char * nm_dhcp_manager_get_config(NMDhcpManager *self) { @@ -500,10 +238,10 @@ nmtst_dhcp_manager_unget(gpointer self) static void nm_dhcp_manager_init(NMDhcpManager *self) { - NMDhcpManagerPrivate * priv = NM_DHCP_MANAGER_GET_PRIVATE(self); - NMConfig * config = nm_config_get(); - gs_free char * client_free = NULL; - const char * client; + NMDhcpManagerPrivate *priv = NM_DHCP_MANAGER_GET_PRIVATE(self); + NMConfig *config = nm_config_get(); + gs_free char *client_free = NULL; + const char *client; int i; const NMDhcpClientFactory *client_factory = NULL; @@ -527,37 +265,30 @@ nm_dhcp_manager_init(NMDhcpManager *self) NM_CONFIG_KEYFILE_KEY_MAIN_DHCP, NM_CONFIG_GET_VALUE_STRIP | NM_CONFIG_GET_VALUE_NO_EMPTY); client = client_free; - if (nm_config_get_configure_and_quit(config) == NM_CONFIG_CONFIGURE_AND_QUIT_ENABLED) { - client_factory = &_nm_dhcp_client_factory_internal; - if (client && !nm_streq(client, client_factory->name)) - nm_log_info(LOGD_DHCP, - "dhcp-init: Using internal DHCP client since configure-and-quit is set."); - } else { - if (client) { - client_factory = _client_factory_available(_client_factory_find_by_name(client)); - if (!client_factory) - nm_log_warn(LOGD_DHCP, "dhcp-init: DHCP client '%s' not available", client); - } - if (!client_factory) { - client_factory = _client_factory_find_by_name("" NM_CONFIG_DEFAULT_MAIN_DHCP); + if (client) { + client_factory = _client_factory_available(_client_factory_find_by_name(client)); + if (!client_factory) + nm_log_warn(LOGD_DHCP, "dhcp-init: DHCP client '%s' not available", client); + } + if (!client_factory) { + client_factory = _client_factory_find_by_name("" NM_CONFIG_DEFAULT_MAIN_DHCP); + if (!client_factory) + nm_log_err(LOGD_DHCP, + "dhcp-init: default DHCP client '%s' is not installed", + NM_CONFIG_DEFAULT_MAIN_DHCP); + else { + client_factory = _client_factory_available(client_factory); if (!client_factory) - nm_log_err(LOGD_DHCP, - "dhcp-init: default DHCP client '%s' is not installed", - NM_CONFIG_DEFAULT_MAIN_DHCP); - else { - client_factory = _client_factory_available(client_factory); - if (!client_factory) - nm_log_info(LOGD_DHCP, - "dhcp-init: default DHCP client '%s' is not available", - NM_CONFIG_DEFAULT_MAIN_DHCP); - } + nm_log_info(LOGD_DHCP, + "dhcp-init: default DHCP client '%s' is not available", + NM_CONFIG_DEFAULT_MAIN_DHCP); } - if (!client_factory) { - for (i = 0; i < (int) G_N_ELEMENTS(_nm_dhcp_manager_factories); i++) { - client_factory = _client_factory_available(_nm_dhcp_manager_factories[i]); - if (client_factory) - break; - } + } + if (!client_factory) { + for (i = 0; i < (int) G_N_ELEMENTS(_nm_dhcp_manager_factories); i++) { + client_factory = _client_factory_available(_nm_dhcp_manager_factories[i]); + if (client_factory) + break; } } @@ -572,21 +303,6 @@ nm_dhcp_manager_init(NMDhcpManager *self) priv->client_factory = client_factory; } -static void -dispose(GObject *object) -{ - NMDhcpManager * self = NM_DHCP_MANAGER(object); - NMDhcpManagerPrivate *priv = NM_DHCP_MANAGER_GET_PRIVATE(self); - - G_OBJECT_CLASS(nm_dhcp_manager_parent_class)->dispose(object); - - nm_clear_g_free(&priv->default_hostname); -} - static void nm_dhcp_manager_class_init(NMDhcpManagerClass *manager_class) -{ - GObjectClass *object_class = G_OBJECT_CLASS(manager_class); - - object_class->dispose = dispose; -} +{} diff --git a/src/core/dhcp/nm-dhcp-manager.h b/src/core/dhcp/nm-dhcp-manager.h index ce160437..bbd68236 100644 --- a/src/core/dhcp/nm-dhcp-manager.h +++ b/src/core/dhcp/nm-dhcp-manager.h @@ -8,7 +8,6 @@ #define __NETWORKMANAGER_DHCP_MANAGER_H__ #include "nm-dhcp-client.h" -#include "nm-ip4-config.h" #include "nm-dhcp-config.h" #define NM_TYPE_DHCP_MANAGER (nm_dhcp_manager_get_type()) @@ -32,51 +31,8 @@ const char *nm_dhcp_manager_get_config(NMDhcpManager *self); void nm_dhcp_manager_set_default_hostname(NMDhcpManager *manager, const char *hostname); -NMDhcpClient *nm_dhcp_manager_start_ip4(NMDhcpManager * manager, - struct _NMDedupMultiIndex *multi_idx, - const char * iface, - int ifindex, - GBytes * hwaddr, - GBytes * bcast_hwaddr, - const char * uuid, - guint32 route_table, - guint32 route_metric, - NMDhcpClientFlags client_flags, - gboolean send_hostname, - const char * dhcp_hostname, - const char * dhcp_fqdn, - NMDhcpHostnameFlags hostname_flags, - const char * mud_url, - GBytes * dhcp_client_id, - guint32 timeout, - const char * anycast_address, - const char * last_ip_address, - GBytes * vendor_class_identifier, - const char *const * reject_servers, - GError ** error); - -NMDhcpClient *nm_dhcp_manager_start_ip6(NMDhcpManager * manager, - struct _NMDedupMultiIndex *multi_idx, - const char * iface, - int ifindex, - const struct in6_addr * ll_addr, - const char * uuid, - guint32 route_table, - guint32 route_metric, - NMDhcpClientFlags client_flags, - gboolean send_hostname, - const char * dhcp_hostname, - NMDhcpHostnameFlags hostname_flags, - const char * mud_url, - GBytes * duid, - gboolean enforce_duid, - guint32 iaid, - gboolean iaid_explicit, - guint32 timeout, - const char * anycast_address, - NMSettingIP6ConfigPrivacy privacy, - guint needed_prefixes, - GError ** error); +NMDhcpClient * +nm_dhcp_manager_start_client(NMDhcpManager *manager, NMDhcpClientConfig *config, GError **error); /* For testing only */ extern const char *nm_dhcp_helper_path; diff --git a/src/core/dhcp/nm-dhcp-nettools.c b/src/core/dhcp/nm-dhcp-nettools.c index 56b485dd..d7fbe356 100644 --- a/src/core/dhcp/nm-dhcp-nettools.c +++ b/src/core/dhcp/nm-dhcp-nettools.c @@ -17,6 +17,7 @@ #include "libnm-std-aux/unaligned.h" #include "libnm-glib-aux/nm-str-buf.h" +#include "nm-l3-config-data.h" #include "nm-utils.h" #include "nm-config.h" #include "nm-dhcp-utils.h" @@ -47,11 +48,11 @@ typedef struct _NMDhcpNettoolsClass NMDhcpNettoolsClass; /*****************************************************************************/ typedef struct { - NDhcp4Client * client; + NDhcp4Client *client; NDhcp4ClientProbe *probe; NDhcp4ClientLease *lease; - GSource * event_source; - char * lease_file; + GSource *event_source; + char *lease_file; } NMDhcpNettoolsPrivate; struct _NMDhcpNettools { @@ -85,8 +86,8 @@ set_error_nettools(GError **error, int r, const char *message) static inline int _client_lease_query(NDhcp4ClientLease *lease, uint8_t option, - const uint8_t ** datap, - size_t * n_datap) + const uint8_t **datap, + size_t *n_datap) { return n_dhcp4_client_lease_query(lease, option, (guint8 **) datap, n_datap); } @@ -99,11 +100,11 @@ _client_lease_query(NDhcp4ClientLease *lease, static gboolean lease_option_consume_route(const uint8_t **datap, - size_t * n_datap, + size_t *n_datap, gboolean classless, - in_addr_t * destp, - uint8_t * plenp, - in_addr_t * gatewayp) + in_addr_t *destp, + uint8_t *plenp, + in_addr_t *gatewayp) { in_addr_t dest; in_addr_t gateway; @@ -151,9 +152,9 @@ lease_option_consume_route(const uint8_t **datap, static gboolean lease_parse_address(NDhcp4ClientLease *lease, - NMIP4Config * ip4_config, - GHashTable * options, - GError ** error) + NML3ConfigData *l3cd, + GHashTable *options, + GError **error) { struct in_addr a_address; in_addr_t a_netmask; @@ -163,7 +164,7 @@ lease_parse_address(NDhcp4ClientLease *lease, guint32 a_lifetime; guint32 a_timestamp; guint64 a_expiry; - const guint8 * l_data; + const guint8 *l_data; gsize l_data_len; int r; @@ -256,26 +257,26 @@ lease_parse_address(NDhcp4ClientLease *lease, a_next_server.s_addr); } - nm_ip4_config_add_address(ip4_config, - &((const NMPlatformIP4Address){ - .address = a_address.s_addr, - .peer_address = a_address.s_addr, - .plen = a_plen, - .addr_source = NM_IP_CONFIG_SOURCE_DHCP, - .timestamp = a_timestamp, - .lifetime = a_lifetime, - .preferred = a_lifetime, - })); + nm_l3_config_data_add_address_4(l3cd, + &((const NMPlatformIP4Address){ + .address = a_address.s_addr, + .peer_address = a_address.s_addr, + .plen = a_plen, + .addr_source = NM_IP_CONFIG_SOURCE_DHCP, + .timestamp = a_timestamp, + .lifetime = a_lifetime, + .preferred = a_lifetime, + })); return TRUE; } static void -lease_parse_address_list(NDhcp4ClientLease * lease, - NMIP4Config * ip4_config, +lease_parse_address_list(NDhcp4ClientLease *lease, + NML3ConfigData *l3cd, NMDhcpOptionDhcp4Options option, - GHashTable * options, - NMStrBuf * sbuf) + GHashTable *options, + NMStrBuf *sbuf) { const guint8 *l_data; gsize l_data_len; @@ -304,13 +305,13 @@ lease_parse_address_list(NDhcp4ClientLease * lease, * See https://github.com/systemd/systemd/issues/4524. */ continue; } - nm_ip4_config_add_nameserver(ip4_config, addr); + nm_l3_config_data_add_nameserver(l3cd, AF_INET, &addr); break; case NM_DHCP_OPTION_DHCP4_NIS_SERVERS: - nm_ip4_config_add_nis_server(ip4_config, addr); + nm_l3_config_data_add_nis_server(l3cd, addr); break; case NM_DHCP_OPTION_DHCP4_NETBIOS_NAMESERVER: - nm_ip4_config_add_wins(ip4_config, addr); + nm_l3_config_data_add_wins(l3cd, addr); break; case NM_DHCP_OPTION_DHCP4_NTP_SERVER: break; @@ -324,11 +325,9 @@ lease_parse_address_list(NDhcp4ClientLease * lease, static void lease_parse_routes(NDhcp4ClientLease *lease, - NMIP4Config * ip4_config, - GHashTable * options, - guint32 route_table, - guint32 route_metric, - NMStrBuf * sbuf) + NML3ConfigData *l3cd, + GHashTable *options, + NMStrBuf *sbuf) { char dest_str[NM_UTILS_INET_ADDRSTRLEN]; char gateway_str[NM_UTILS_INET_ADDRSTRLEN]; @@ -336,9 +335,9 @@ lease_parse_routes(NDhcp4ClientLease *lease, in_addr_t gateway; uint8_t plen; guint32 m; - gboolean has_router_from_classless = FALSE; - gboolean has_classless = FALSE; - guint32 default_route_metric = route_metric; + gboolean has_router_from_classless = FALSE; + gboolean has_classless = FALSE; + guint32 default_route_metric_offset = 0; const guint8 *l_data; gsize l_data_len; int r; @@ -367,26 +366,22 @@ lease_parse_routes(NDhcp4ClientLease *lease, if (plen == 0) { /* if there are multiple default routes, we add them with differing * metrics. */ - m = default_route_metric; - if (default_route_metric < G_MAXUINT32) - default_route_metric++; - + m = default_route_metric_offset++; has_router_from_classless = TRUE; - } else { - m = route_metric; - } - - nm_ip4_config_add_route( - ip4_config, - &((const NMPlatformIP4Route){ - .network = dest, - .plen = plen, - .gateway = gateway, - .rt_source = NM_IP_CONFIG_SOURCE_DHCP, - .metric = m, - .table_coerced = nm_platform_route_table_coerce(route_table), - }), - NULL); + } else + m = 0; + + nm_l3_config_data_add_route_4(l3cd, + &((const NMPlatformIP4Route){ + .network = dest, + .plen = plen, + .gateway = gateway, + .rt_source = NM_IP_CONFIG_SOURCE_DHCP, + .table_any = TRUE, + .table_coerced = 0, + .metric_any = TRUE, + .metric = m, + })); } has_classless = TRUE; @@ -419,17 +414,17 @@ lease_parse_routes(NDhcp4ClientLease *lease, continue; } - nm_ip4_config_add_route( - ip4_config, - &((const NMPlatformIP4Route){ - .network = dest, - .plen = plen, - .gateway = gateway, - .rt_source = NM_IP_CONFIG_SOURCE_DHCP, - .metric = route_metric, - .table_coerced = nm_platform_route_table_coerce(route_table), - }), - NULL); + nm_l3_config_data_add_route_4(l3cd, + &((const NMPlatformIP4Route){ + .network = dest, + .plen = plen, + .gateway = gateway, + .rt_source = NM_IP_CONFIG_SOURCE_DHCP, + .table_any = TRUE, + .table_coerced = 0, + .metric_any = TRUE, + .metric = 0, + })); } nm_dhcp_option_add_option(options, @@ -463,19 +458,17 @@ lease_parse_routes(NDhcp4ClientLease *lease, /* if there are multiple default routes, we add them with differing * metrics. */ - m = default_route_metric; - if (default_route_metric < G_MAXUINT32) - default_route_metric++; - - nm_ip4_config_add_route( - ip4_config, - &((const NMPlatformIP4Route){ - .rt_source = NM_IP_CONFIG_SOURCE_DHCP, - .gateway = gateway, - .table_coerced = nm_platform_route_table_coerce(route_table), - .metric = m, - }), - NULL); + m = default_route_metric_offset++; + + nm_l3_config_data_add_route_4(l3cd, + &((const NMPlatformIP4Route){ + .rt_source = NM_IP_CONFIG_SOURCE_DHCP, + .gateway = gateway, + .table_any = TRUE, + .table_coerced = 0, + .metric_any = TRUE, + .metric = m, + })); } nm_dhcp_option_add_option(options, @@ -486,10 +479,10 @@ lease_parse_routes(NDhcp4ClientLease *lease, } static void -lease_parse_search_domains(NDhcp4ClientLease *lease, NMIP4Config *ip4_config, GHashTable *options) +lease_parse_search_domains(NDhcp4ClientLease *lease, NML3ConfigData *l3cd, GHashTable *options) { gs_strfreev char **domains = NULL; - const guint8 * l_data; + const guint8 *l_data; gsize l_data_len; guint i; int r; @@ -504,7 +497,7 @@ lease_parse_search_domains(NDhcp4ClientLease *lease, NMIP4Config *ip4_config, GH return; for (i = 0; domains[i]; i++) - nm_ip4_config_add_search(ip4_config, domains[i]); + nm_l3_config_data_add_search(l3cd, AF_INET, domains[i]); nm_dhcp_option_take_option(options, AF_INET, @@ -539,34 +532,31 @@ lease_parse_private_options(NDhcp4ClientLease *lease, GHashTable *options) } } -static NMIP4Config * +static NML3ConfigData * lease_to_ip4_config(NMDedupMultiIndex *multi_idx, - const char * iface, + const char *iface, int ifindex, NDhcp4ClientLease *lease, - guint32 route_table, - guint32 route_metric, - GHashTable ** out_options, - GError ** error) + GError **error) { - nm_auto_str_buf NMStrBuf sbuf = NM_STR_BUF_INIT(0, FALSE); - gs_unref_object NMIP4Config *ip4_config = NULL; - gs_unref_hashtable GHashTable *options = NULL; - const guint8 * l_data; - gsize l_data_len; - const char * v_str; - guint16 v_u16; - gboolean v_bool; - in_addr_t v_inaddr; - struct in_addr v_inaddr_s; - int r; + nm_auto_str_buf NMStrBuf sbuf = NM_STR_BUF_INIT(0, FALSE); + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + gs_unref_hashtable GHashTable *options = NULL; + const guint8 *l_data; + gsize l_data_len; + const char *v_str; + guint16 v_u16; + in_addr_t v_inaddr; + struct in_addr v_inaddr_s; + int r; g_return_val_if_fail(lease != NULL, NULL); - ip4_config = nm_ip4_config_new(multi_idx, ifindex); - options = nm_dhcp_option_create_options_dict(); + l3cd = nm_l3_config_data_new(multi_idx, ifindex, NM_IP_CONFIG_SOURCE_DHCP); + + options = nm_dhcp_option_create_options_dict(); - if (!lease_parse_address(lease, ip4_config, options, error)) + if (!lease_parse_address(lease, l3cd, options, error)) return NULL; r = n_dhcp4_client_lease_get_server_identifier(lease, &v_inaddr_s); @@ -585,13 +575,9 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, v_inaddr); } - lease_parse_routes(lease, ip4_config, options, route_table, route_metric, &sbuf); + lease_parse_routes(lease, l3cd, options, &sbuf); - lease_parse_address_list(lease, - ip4_config, - NM_DHCP_OPTION_DHCP4_DOMAIN_NAME_SERVER, - options, - &sbuf); + lease_parse_address_list(lease, l3cd, NM_DHCP_OPTION_DHCP4_DOMAIN_NAME_SERVER, options, &sbuf); r = _client_lease_query(lease, NM_DHCP_OPTION_DHCP4_DOMAIN_NAME, &l_data, &l_data_len); if (r == 0 && nm_dhcp_lease_data_parse_cstr(l_data, l_data_len, &l_data_len)) { @@ -616,7 +602,7 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, nm_str_buf_append_required_delimiter(&sbuf, ' '); nm_str_buf_append(&sbuf, s); - nm_ip4_config_add_domain(ip4_config, s); + nm_l3_config_data_add_domain(l3cd, AF_INET, s); } } @@ -628,18 +614,17 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, } } - lease_parse_search_domains(lease, ip4_config, options); + lease_parse_search_domains(lease, l3cd, options); r = _client_lease_query(lease, NM_DHCP_OPTION_DHCP4_INTERFACE_MTU, &l_data, &l_data_len); if (r == 0 && nm_dhcp_lease_data_parse_mtu(l_data, l_data_len, &v_u16)) { nm_dhcp_option_add_option_u64(options, AF_INET, NM_DHCP_OPTION_DHCP4_INTERFACE_MTU, v_u16); - nm_ip4_config_set_mtu(ip4_config, v_u16, NM_IP_CONFIG_SOURCE_DHCP); + nm_l3_config_data_set_mtu(l3cd, v_u16); } r = _client_lease_query(lease, NM_DHCP_OPTION_DHCP4_VENDOR_SPECIFIC, &l_data, &l_data_len); - v_bool = - (r == 0) && memmem(l_data, l_data_len, "ANDROID_METERED", NM_STRLEN("ANDROID_METERED")); - nm_ip4_config_set_metered(ip4_config, v_bool); + if ((r == 0) && memmem(l_data, l_data_len, "ANDROID_METERED", NM_STRLEN("ANDROID_METERED"))) + nm_l3_config_data_set_metered(l3cd, TRUE); r = _client_lease_query(lease, NM_DHCP_OPTION_DHCP4_HOST_NAME, &l_data, &l_data_len); if (r == 0) { @@ -650,7 +635,7 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, } } - lease_parse_address_list(lease, ip4_config, NM_DHCP_OPTION_DHCP4_NTP_SERVER, options, &sbuf); + lease_parse_address_list(lease, l3cd, NM_DHCP_OPTION_DHCP4_NTP_SERVER, options, &sbuf); r = _client_lease_query(lease, NM_DHCP_OPTION_DHCP4_ROOT_PATH, &l_data, &l_data_len); if (r == 0 && nm_dhcp_lease_data_parse_cstr(l_data, l_data_len, &l_data_len)) { @@ -681,11 +666,17 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, * We reject NUL characters inside the string (except trailing NULs). * Otherwise, we allow any encoding and backslash-escape the result to * UTF-8. */ - nm_dhcp_option_add_option_utf8safe_escape(options, - AF_INET, - NM_DHCP_OPTION_DHCP4_PRIVATE_PROXY_AUTODISCOVERY, - l_data, - l_data_len); + gs_free char *to_free = NULL; + const char *escaped; + + escaped = nm_utils_buf_utf8safe_escape((char *) l_data, l_data_len, 0, &to_free); + nm_dhcp_option_add_option(options, + AF_INET, + NM_DHCP_OPTION_DHCP4_PRIVATE_PROXY_AUTODISCOVERY, + escaped ?: ""); + + nm_l3_config_data_set_proxy_method(l3cd, NM_PROXY_CONFIG_METHOD_AUTO); + nm_l3_config_data_set_proxy_pac_url(l3cd, escaped ?: ""); } r = _client_lease_query(lease, NM_DHCP_OPTION_DHCP4_NIS_DOMAIN, &l_data, &l_data_len); @@ -700,7 +691,7 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, &to_free); nm_dhcp_option_add_option(options, AF_INET, NM_DHCP_OPTION_DHCP4_NIS_DOMAIN, v_str ?: ""); - nm_ip4_config_set_nis_domain(ip4_config, v_str ?: ""); + nm_l3_config_data_set_nis_domain(l3cd, v_str ?: ""); } r = n_dhcp4_client_lease_get_file(lease, &v_str); @@ -728,18 +719,17 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, v_str ?: ""); } - lease_parse_address_list(lease, ip4_config, NM_DHCP_OPTION_DHCP4_NIS_SERVERS, options, &sbuf); + lease_parse_address_list(lease, l3cd, NM_DHCP_OPTION_DHCP4_NIS_SERVERS, options, &sbuf); - lease_parse_address_list(lease, - ip4_config, - NM_DHCP_OPTION_DHCP4_NETBIOS_NAMESERVER, - options, - &sbuf); + lease_parse_address_list(lease, l3cd, NM_DHCP_OPTION_DHCP4_NETBIOS_NAMESERVER, options, &sbuf); lease_parse_private_options(lease, options); - NM_SET_OUT(out_options, g_steal_pointer(&options)); - return g_steal_pointer(&ip4_config); + nm_dhcp_option_add_requests_to_options(options, AF_INET); + + nm_l3_config_data_set_dhcp_lease_from_options(l3cd, AF_INET, g_steal_pointer(&options)); + + return g_steal_pointer(&l3cd); } /*****************************************************************************/ @@ -750,7 +740,7 @@ lease_save(NMDhcpNettools *self, NDhcp4ClientLease *lease, const char *lease_fil struct in_addr a_address; nm_auto_str_buf NMStrBuf sbuf = NM_STR_BUF_INIT(NM_UTILS_GET_NEXT_REALLOC_SIZE_104, FALSE); char addr_str[NM_UTILS_INET_ADDRSTRLEN]; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; nm_assert(lease); nm_assert(lease_file); @@ -771,47 +761,44 @@ lease_save(NMDhcpNettools *self, NDhcp4ClientLease *lease, const char *lease_fil static void bound4_handle(NMDhcpNettools *self, NDhcp4ClientLease *lease, gboolean extended) { - NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE(self); - const char * iface = nm_dhcp_client_get_iface(NM_DHCP_CLIENT(self)); - gs_unref_object NMIP4Config *ip4_config = NULL; - gs_unref_hashtable GHashTable *options = NULL; - GError * error = NULL; + NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE(self); + NMDhcpClient *client = NM_DHCP_CLIENT(self); + const NMDhcpClientConfig *client_config; + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + GError *error = NULL; _LOGT("lease available (%s)", extended ? "extended" : "new"); - - ip4_config = lease_to_ip4_config(nm_dhcp_client_get_multi_idx(NM_DHCP_CLIENT(self)), - iface, - nm_dhcp_client_get_ifindex(NM_DHCP_CLIENT(self)), - lease, - nm_dhcp_client_get_route_table(NM_DHCP_CLIENT(self)), - nm_dhcp_client_get_route_metric(NM_DHCP_CLIENT(self)), - &options, - &error); - if (!ip4_config) { - _LOGW("%s", error->message); + client_config = nm_dhcp_client_get_config(client); + l3cd = lease_to_ip4_config(nm_dhcp_client_get_multi_idx(client), + client_config->iface, + nm_dhcp_client_get_ifindex(client), + lease, + &error); + if (!l3cd) { + _LOGW("failure to parse lease: %s", error->message); g_clear_error(&error); - nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_FAIL, NULL, NULL); + nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_FAIL, NULL); return; } - nm_dhcp_option_add_requests_to_options(options, AF_INET); lease_save(self, lease, priv->lease_file); nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), extended ? NM_DHCP_STATE_EXTENDED : NM_DHCP_STATE_BOUND, - NM_IP_CONFIG_CAST(ip4_config), - options); + l3cd); } static void dhcp4_event_handle(NMDhcpNettools *self, NDhcp4ClientEvent *event) { - NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE(self); - struct in_addr server_id; - char addr_str[INET_ADDRSTRLEN]; - int r; + NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE(self); + const NMDhcpClientConfig *client_config; + struct in_addr server_id; + char addr_str[INET_ADDRSTRLEN]; + int r; _LOGT("client event %d", event->event); + client_config = nm_dhcp_client_get_config(NM_DHCP_CLIENT(self)); switch (event->event) { case N_DHCP4_CLIENT_EVENT_OFFER: @@ -835,10 +822,10 @@ dhcp4_event_handle(NMDhcpNettools *self, NDhcp4ClientEvent *event) break; case N_DHCP4_CLIENT_EVENT_RETRACTED: case N_DHCP4_CLIENT_EVENT_EXPIRED: - nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_EXPIRE, NULL, NULL); + nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_EXPIRE, NULL); break; case N_DHCP4_CLIENT_EVENT_CANCELLED: - nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_FAIL, NULL, NULL); + nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_FAIL, NULL); break; case N_DHCP4_CLIENT_EVENT_GRANTED: priv->lease = n_dhcp4_client_lease_ref(event->granted.lease); @@ -861,7 +848,7 @@ dhcp4_event_handle(NMDhcpNettools *self, NDhcp4ClientEvent *event) NULL, NULL, "dhcp4 (%s): %s", - nm_dhcp_client_get_iface(NM_DHCP_CLIENT(self)), + client_config->iface, event->log.message); } } break; @@ -874,9 +861,9 @@ dhcp4_event_handle(NMDhcpNettools *self, NDhcp4ClientEvent *event) static gboolean dhcp4_event_cb(int fd, GIOCondition condition, gpointer user_data) { - NMDhcpNettools * self = user_data; + NMDhcpNettools *self = user_data; NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE(self); - NDhcp4ClientEvent * event; + NDhcp4ClientEvent *event; int r; r = n_dhcp4_client_dispatch(priv->client); @@ -890,13 +877,12 @@ dhcp4_event_cb(int fd, GIOCondition condition, gpointer user_data) */ _LOGE("error %d dispatching events", r); nm_clear_g_source_inst(&priv->event_source); - nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_FAIL, NULL, NULL); + nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_FAIL, NULL); return G_SOURCE_REMOVE; } - while (!n_dhcp4_client_pop_event(priv->client, &event) && event) { + while (!n_dhcp4_client_pop_event(priv->client, &event) && event) dhcp4_event_handle(self, event); - } return G_SOURCE_CONTINUE; } @@ -906,31 +892,34 @@ nettools_create(NMDhcpNettools *self, GError **error) { NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE(self); nm_auto(n_dhcp4_client_config_freep) NDhcp4ClientConfig *config = NULL; - nm_auto(n_dhcp4_client_unrefp) NDhcp4Client * client = NULL; - GBytes * hwaddr; - GBytes * bcast_hwaddr; - const uint8_t * hwaddr_arr; - const uint8_t * bcast_hwaddr_arr; + nm_auto(n_dhcp4_client_unrefp) NDhcp4Client *client = NULL; + GBytes *hwaddr; + GBytes *bcast_hwaddr; + const uint8_t *hwaddr_arr; + const uint8_t *bcast_hwaddr_arr; gsize hwaddr_len; gsize bcast_hwaddr_len; - GBytes * client_id; - gs_unref_bytes GBytes *client_id_new = NULL; - const uint8_t * client_id_arr; - size_t client_id_len; - int r, fd, arp_type, transport; + GBytes *client_id; + gs_unref_bytes GBytes *client_id_new = NULL; + const uint8_t *client_id_arr; + size_t client_id_len; + int r, fd, arp_type, transport; + const NMDhcpClientConfig *client_config; + + client_config = nm_dhcp_client_get_config(NM_DHCP_CLIENT(self)); g_return_val_if_fail(!priv->client, FALSE); /* TODO: honor nm_dhcp_client_get_anycast_address() */ - hwaddr = nm_dhcp_client_get_hw_addr(NM_DHCP_CLIENT(self)); + hwaddr = client_config->hwaddr; if (!hwaddr || !(hwaddr_arr = g_bytes_get_data(hwaddr, &hwaddr_len)) || (arp_type = nm_utils_arp_type_detect_from_hwaddrlen(hwaddr_len)) < 0) { nm_utils_error_set_literal(error, NM_UTILS_ERROR_UNKNOWN, "invalid MAC address"); return FALSE; } - bcast_hwaddr = nm_dhcp_client_get_broadcast_hw_addr(NM_DHCP_CLIENT(self)); + bcast_hwaddr = client_config->bcast_hwaddr; bcast_hwaddr_arr = g_bytes_get_data(bcast_hwaddr, &bcast_hwaddr_len); switch (arp_type) { @@ -947,7 +936,7 @@ nettools_create(NMDhcpNettools *self, GError **error) /* Note that we always set a client-id. In particular for infiniband that is necessary, * see https://tools.ietf.org/html/rfc4390#section-2.1 . */ - client_id = nm_dhcp_client_get_client_id(NM_DHCP_CLIENT(self)); + client_id = client_config->client_id; if (!client_id) { client_id_new = nm_utils_dhcp_client_id_mac(arp_type, hwaddr_arr, hwaddr_len); client_id = client_id_new; @@ -971,10 +960,7 @@ nettools_create(NMDhcpNettools *self, GError **error) n_dhcp4_client_config_set_transport(config, transport); n_dhcp4_client_config_set_mac(config, hwaddr_arr, hwaddr_len); n_dhcp4_client_config_set_broadcast_mac(config, bcast_hwaddr_arr, bcast_hwaddr_len); - n_dhcp4_client_config_set_request_broadcast( - config, - NM_FLAGS_HAS(nm_dhcp_client_get_client_flags(NM_DHCP_CLIENT(self)), - NM_DHCP_CLIENT_FLAGS_REQUEST_BROADCAST)); + n_dhcp4_client_config_set_request_broadcast(config, client_config->v4.request_broadcast); r = n_dhcp4_client_config_set_client_id(config, client_id_arr, NM_MIN(client_id_len, 1 + _NM_MAX_CLIENT_ID_LEN)); @@ -1005,7 +991,7 @@ nettools_create(NMDhcpNettools *self, GError **error) static gboolean _accept(NMDhcpClient *client, GError **error) { - NMDhcpNettools * self = NM_DHCP_NETTOOLS(client); + NMDhcpNettools *self = NM_DHCP_NETTOOLS(client); NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE(self); int r; @@ -1027,13 +1013,13 @@ _accept(NMDhcpClient *client, GError **error) static gboolean decline(NMDhcpClient *client, const char *error_message, GError **error) { - NMDhcpNettools * self = NM_DHCP_NETTOOLS(client); + NMDhcpNettools *self = NM_DHCP_NETTOOLS(client); NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE(self); int r; g_return_val_if_fail(priv->lease, FALSE); - _LOGT("dhcp4-client: decline"); + _LOGT("dhcp4-client: decline (%s)", error_message); r = n_dhcp4_client_lease_decline(priv->lease, error_message); if (r) { @@ -1063,19 +1049,20 @@ fqdn_flags_to_wire(NMDhcpHostnameFlags flags) } static gboolean -ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) +ip4_start(NMDhcpClient *client, GError **error) { nm_auto(n_dhcp4_client_probe_config_freep) NDhcp4ClientProbeConfig *config = NULL; - NMDhcpNettools * self = NM_DHCP_NETTOOLS(client); - NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE(self); - gs_free char * lease_file = NULL; - struct in_addr last_addr = {0}; - const char * hostname; - const char * mud_url; - GBytes * vendor_class_identifier; - int r, i; + NMDhcpNettools *self = NM_DHCP_NETTOOLS(client); + NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE(self); + const NMDhcpClientConfig *client_config; + gs_free char *lease_file = NULL; + struct in_addr last_addr = {0}; + int r, i; + + client_config = nm_dhcp_client_get_config(client); g_return_val_if_fail(!priv->probe, FALSE); + g_return_val_if_fail(client_config, FALSE); if (!nettools_create(self, error)) return FALSE; @@ -1094,12 +1081,12 @@ ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) nm_dhcp_utils_get_leasefile_path(AF_INET, "internal", - nm_dhcp_client_get_iface(client), - nm_dhcp_client_get_uuid(client), + client_config->iface, + client_config->uuid, &lease_file); - if (last_ip4_address) - inet_pton(AF_INET, last_ip4_address, &last_addr); + if (client_config->v4.last_address) + inet_pton(AF_INET, client_config->v4.last_address, &last_addr); else { /* * TODO: we stick to the systemd-networkd lease file format. Quite easy for now to @@ -1129,31 +1116,33 @@ ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) } } - mud_url = nm_dhcp_client_get_mud_url(client); - if (mud_url) { + if (client_config->mud_url) { r = n_dhcp4_client_probe_config_append_option(config, NM_DHCP_OPTION_DHCP4_MUD_URL, - mud_url, - strlen(mud_url)); + client_config->mud_url, + strlen(client_config->mud_url)); if (r) { set_error_nettools(error, r, "failed to set MUD URL"); return FALSE; } } - hostname = nm_dhcp_client_get_hostname(client); - if (hostname) { - if (NM_FLAGS_HAS(nm_dhcp_client_get_client_flags(client), NM_DHCP_CLIENT_FLAGS_USE_FQDN)) { + + if (client_config->hostname) { + if (client_config->use_fqdn) { uint8_t buffer[255]; NMDhcpHostnameFlags flags; size_t fqdn_len; - flags = nm_dhcp_client_get_hostname_flags(client); + flags = client_config->hostname_flags; buffer[0] = fqdn_flags_to_wire(flags); buffer[1] = 0; /* RCODE1 (deprecated) */ buffer[2] = 0; /* RCODE2 (deprecated) */ if (flags & NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED) { - r = nm_sd_dns_name_to_wire_format(hostname, buffer + 3, sizeof(buffer) - 3, FALSE); + r = nm_sd_dns_name_to_wire_format(client_config->hostname, + buffer + 3, + sizeof(buffer) - 3, + FALSE); if (r <= 0) { if (r < 0) nm_utils_error_set_errno(error, r, "failed to convert DHCP FQDN: %s"); @@ -1163,12 +1152,12 @@ ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) } fqdn_len = r; } else { - fqdn_len = strlen(hostname); + fqdn_len = strlen(client_config->hostname); if (fqdn_len > sizeof(buffer) - 3) { nm_utils_error_set(error, r, "failed to set DHCP FQDN: name too long"); return FALSE; } - memcpy(buffer + 3, hostname, fqdn_len); + memcpy(buffer + 3, client_config->hostname, fqdn_len); } r = n_dhcp4_client_probe_config_append_option(config, @@ -1182,8 +1171,8 @@ ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) } else { r = n_dhcp4_client_probe_config_append_option(config, NM_DHCP_OPTION_DHCP4_HOST_NAME, - hostname, - strlen(hostname)); + client_config->hostname, + strlen(client_config->hostname)); if (r) { set_error_nettools(error, r, "failed to set DHCP hostname"); return FALSE; @@ -1191,12 +1180,11 @@ ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) } } - vendor_class_identifier = nm_dhcp_client_get_vendor_class_identifier(client); - if (vendor_class_identifier) { + if (client_config->vendor_class_identifier) { const void *option_data; gsize option_size; - option_data = g_bytes_get_data(vendor_class_identifier, &option_size); + option_data = g_bytes_get_data(client_config->vendor_class_identifier, &option_size); nm_assert(option_data); nm_assert(option_size <= 255); @@ -1220,15 +1208,13 @@ ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) } _LOGT("dhcp-client4: start " NM_HASH_OBFUSCATE_PTR_FMT, NM_HASH_OBFUSCATE_PTR(priv->client)); - - nm_dhcp_client_start_timeout(client); return TRUE; } static void stop(NMDhcpClient *client, gboolean release) { - NMDhcpNettools * self = NM_DHCP_NETTOOLS(client); + NMDhcpNettools *self = NM_DHCP_NETTOOLS(client); NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE(self); NM_DHCP_CLIENT_CLASS(nm_dhcp_nettools_parent_class)->stop(client, release); @@ -1262,7 +1248,7 @@ static void nm_dhcp_nettools_class_init(NMDhcpNettoolsClass *class) { NMDhcpClientClass *client_class = NM_DHCP_CLIENT_CLASS(class); - GObjectClass * object_class = G_OBJECT_CLASS(class); + GObjectClass *object_class = G_OBJECT_CLASS(class); object_class->dispose = dispose; diff --git a/src/core/dhcp/nm-dhcp-options.c b/src/core/dhcp/nm-dhcp-options.c index 011f23e4..96fef81a 100644 --- a/src/core/dhcp/nm-dhcp-options.c +++ b/src/core/dhcp/nm-dhcp-options.c @@ -201,6 +201,7 @@ const NMDhcpOption _nm_dhcp_option_dhcp6_options[] = { REQ(NM_DHCP_OPTION_DHCP6_DOMAIN_LIST, "dhcp6_domain_search", TRUE), REQ(NM_DHCP_OPTION_DHCP6_SNTP_SERVERS, "dhcp6_sntp_servers", TRUE), REQ(NM_DHCP_OPTION_DHCP6_FQDN, "fqdn_fqdn", FALSE), + REQ(NM_DHCP_OPTION_DHCP6_NTP_SERVER, "dhcp6_ntp_servers", TRUE), REQ(NM_DHCP_OPTION_DHCP6_MUD_URL, "dhcp6_mud_url", FALSE), /* Internal values */ @@ -235,6 +236,7 @@ static const NMDhcpOption *const _sorted_options_6[G_N_ELEMENTS(_nm_dhcp_option_ A(13), A(14), A(15), + A(16), #undef A }; @@ -247,7 +249,7 @@ _sorted_options_generate_sort(gconstpointer pa, gconstpointer pb, gpointer user_ const NMDhcpOption *const *b = pb; NM_CMP_DIRECT((*a)->option_num, (*b)->option_num); - return nm_assert_unreachable_val(0); + return 0; } static char * @@ -272,7 +274,6 @@ _sorted_options_generate(const NMDhcpOption *base, const NMDhcpOption *const *so _nm_unused static void _ASSERT_sorted(int IS_IPv4, const NMDhcpOption *const *const sorted, int n) - { const NMDhcpOption *const options = IS_IPv4 ? _nm_dhcp_option_dhcp4_options : _nm_dhcp_option_dhcp6_options; @@ -283,6 +284,16 @@ _ASSERT_sorted(int IS_IPv4, const NMDhcpOption *const *const sorted, int n) for (i = 0; i < n; i++) { const NMDhcpOption *opt = sorted[i]; + if (!opt || opt < options || opt >= &options[n]) { + g_error("%s:%d: _sorted_options_%c[%d] must be a valid pointer into " + "_nm_dhcp_option_dhcp%c_options, but is %p", + __FILE__, + __LINE__, + IS_IPv4 ? '4' : '6', + i, + IS_IPv4 ? '4' : '6', + opt); + } g_assert(opt); g_assert(opt >= options); g_assert(opt < &options[n]); @@ -291,7 +302,7 @@ _ASSERT_sorted(int IS_IPv4, const NMDhcpOption *const *const sorted, int n) const NMDhcpOption *opt2 = sorted[j]; if (opt == opt2) { - g_error("%s:%d: the _sorted_options_%c at [%d] (opt=%u, %s) is duplicated at " + g_error("%s:%d: _sorted_options_%c[%d] (opt=%u, %s) is duplicated at " "[%d] (SORT: %s)", __FILE__, __LINE__, @@ -308,7 +319,7 @@ _ASSERT_sorted(int IS_IPv4, const NMDhcpOption *const *const sorted, int n) const NMDhcpOption *opt2 = sorted[i - 1]; if (opt2->option_num >= opt->option_num) { - g_error("%s:%d: the _sorted_options_%c at [%d] (opt=%u, %s) should come before " + g_error("%s:%d: _sorted_options_%c[%d] (opt=%u, %s) should come before " "[%d] (opt=%u, %s) (SORT: %s)", __FILE__, __LINE__, @@ -396,14 +407,14 @@ nm_dhcp_option_add_option(GHashTable *options, int addr_family, guint option, co } void -nm_dhcp_option_add_option_utf8safe_escape(GHashTable * options, +nm_dhcp_option_add_option_utf8safe_escape(GHashTable *options, int addr_family, guint option, const guint8 *data, gsize n_data) { gs_free char *to_free = NULL; - const char * escaped; + const char *escaped; escaped = nm_utils_buf_utf8safe_escape((char *) data, n_data, diff --git a/src/core/dhcp/nm-dhcp-options.h b/src/core/dhcp/nm-dhcp-options.h index 8ed2039d..4c978c4f 100644 --- a/src/core/dhcp/nm-dhcp-options.h +++ b/src/core/dhcp/nm-dhcp-options.h @@ -163,6 +163,7 @@ typedef enum { NM_DHCP_OPTION_DHCP6_DOMAIN_LIST = 24, NM_DHCP_OPTION_DHCP6_SNTP_SERVERS = 31, NM_DHCP_OPTION_DHCP6_FQDN = 39, + NM_DHCP_OPTION_DHCP6_NTP_SERVER = 56, /* RFC 5908 */ NM_DHCP_OPTION_DHCP6_MUD_URL = 112, /* Internal values */ @@ -187,7 +188,7 @@ typedef struct { } NMDhcpOption; extern const NMDhcpOption _nm_dhcp_option_dhcp4_options[143]; -extern const NMDhcpOption _nm_dhcp_option_dhcp6_options[16]; +extern const NMDhcpOption _nm_dhcp_option_dhcp6_options[17]; static inline const char * nm_dhcp_option_get_name(const NMDhcpOption *option) @@ -210,7 +211,7 @@ nm_dhcp_option_request_string(int addr_family, guint option) void nm_dhcp_option_take_option(GHashTable *options, int addr_family, guint option, char *value); void nm_dhcp_option_add_option(GHashTable *options, int addr_family, guint option, const char *value); -void nm_dhcp_option_add_option_utf8safe_escape(GHashTable * options, +void nm_dhcp_option_add_option_utf8safe_escape(GHashTable *options, int addr_family, guint option, const guint8 *data, diff --git a/src/core/dhcp/nm-dhcp-systemd.c b/src/core/dhcp/nm-dhcp-systemd.c index af1d2238..0884def3 100644 --- a/src/core/dhcp/nm-dhcp-systemd.c +++ b/src/core/dhcp/nm-dhcp-systemd.c @@ -17,6 +17,7 @@ #include "libnm-std-aux/unaligned.h" #include "nm-utils.h" +#include "nm-l3-config-data.h" #include "nm-dhcp-utils.h" #include "nm-dhcp-options.h" #include "nm-core-utils.h" @@ -46,13 +47,11 @@ static GType nm_dhcp_systemd_get_type(void); /*****************************************************************************/ typedef struct { - sd_dhcp_client * client4; + sd_dhcp_client *client4; sd_dhcp6_client *client6; - char * lease_file; + char *lease_file; guint request_count; - - bool privacy : 1; } NMDhcpSystemdPrivate; struct _NMDhcpSystemd { @@ -70,45 +69,41 @@ G_DEFINE_TYPE(NMDhcpSystemd, nm_dhcp_systemd, NM_TYPE_DHCP_CLIENT) /*****************************************************************************/ -static NMIP4Config * +static NML3ConfigData * lease_to_ip4_config(NMDedupMultiIndex *multi_idx, - const char * iface, + const char *iface, int ifindex, - sd_dhcp_lease * lease, - guint32 route_table, - guint32 route_metric, - GHashTable ** out_options, - GError ** error) + sd_dhcp_lease *lease, + GError **error) { - gs_unref_object NMIP4Config *ip4_config = NULL; - gs_unref_hashtable GHashTable *options = NULL; - const struct in_addr * addr_list; - char addr_str[NM_UTILS_INET_ADDRSTRLEN]; - const char * s; - nm_auto_free_gstring GString *str = NULL; - nm_auto_free sd_dhcp_route **routes = NULL; - const char *const * search_domains = NULL; - guint16 mtu; - int i, num; - const void * data; - gsize data_len; - gboolean metered = FALSE; - gboolean has_router_from_classless = FALSE; - gboolean has_classless_route = FALSE; - gboolean has_static_route = FALSE; - const gint32 ts = nm_utils_get_monotonic_timestamp_sec(); - gint64 ts_time = time(NULL); - struct in_addr a_address; - struct in_addr a_netmask; - struct in_addr a_next_server; - struct in_addr server_id; - struct in_addr broadcast; - const struct in_addr * a_router; - guint32 a_plen; - guint32 a_lifetime; - guint32 renewal; - guint32 rebinding; - gs_free nm_sd_dhcp_option *private_options = NULL; + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + gs_unref_hashtable GHashTable *options = NULL; + const struct in_addr *addr_list; + char addr_str[NM_UTILS_INET_ADDRSTRLEN]; + const char *s; + nm_auto_free_gstring GString *str = NULL; + nm_auto_free sd_dhcp_route **routes = NULL; + const char *const *search_domains = NULL; + guint16 mtu; + int i, num; + const void *data; + gsize data_len; + gboolean has_router_from_classless = FALSE; + gboolean has_classless_route = FALSE; + gboolean has_static_route = FALSE; + const gint32 ts = nm_utils_get_monotonic_timestamp_sec(); + gint64 ts_time = time(NULL); + struct in_addr a_address; + struct in_addr a_netmask; + struct in_addr a_next_server; + struct in_addr server_id; + struct in_addr broadcast; + const struct in_addr *a_router; + guint32 a_plen; + guint32 a_lifetime; + guint32 renewal; + guint32 rebinding; + gs_free nm_sd_dhcp_option *private_options = NULL; nm_assert(lease != NULL); @@ -133,9 +128,9 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, return NULL; } - ip4_config = nm_ip4_config_new(multi_idx, ifindex); + l3cd = nm_l3_config_data_new(multi_idx, ifindex, NM_IP_CONFIG_SOURCE_DHCP); - options = out_options ? nm_dhcp_option_create_options_dict() : NULL; + options = nm_dhcp_option_create_options_dict(); _nm_utils_inet4_ntop(a_address.s_addr, addr_str); nm_dhcp_option_add_option(options, AF_INET, NM_DHCP_OPTION_DHCP4_NM_IP_ADDRESS, addr_str); @@ -160,16 +155,16 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, nm_dhcp_option_add_option(options, AF_INET, NM_DHCP_OPTION_DHCP4_NM_NEXT_SERVER, addr_str); } - nm_ip4_config_add_address(ip4_config, - &((const NMPlatformIP4Address){ - .address = a_address.s_addr, - .peer_address = a_address.s_addr, - .plen = a_plen, - .addr_source = NM_IP_CONFIG_SOURCE_DHCP, - .timestamp = ts, - .lifetime = a_lifetime, - .preferred = a_lifetime, - })); + nm_l3_config_data_add_address_4(l3cd, + &((const NMPlatformIP4Address){ + .address = a_address.s_addr, + .peer_address = a_address.s_addr, + .plen = a_plen, + .addr_source = NM_IP_CONFIG_SOURCE_DHCP, + .timestamp = ts, + .lifetime = a_lifetime, + .preferred = a_lifetime, + })); if (sd_dhcp_lease_get_server_identifier(lease, &server_id) >= 0) { _nm_utils_inet4_ntop(server_id.s_addr, addr_str); @@ -193,7 +188,7 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, * See https://github.com/systemd/systemd/issues/4524. */ continue; } - nm_ip4_config_add_nameserver(ip4_config, addr_list[i].s_addr); + nm_l3_config_data_add_nameserver(l3cd, AF_INET, &addr_list[i].s_addr); } nm_dhcp_option_add_option(options, AF_INET, @@ -206,7 +201,7 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, nm_gstring_prepare(&str); for (i = 0; i < num; i++) { g_string_append(nm_gstring_add_space_delimiter(str), search_domains[i]); - nm_ip4_config_add_search(ip4_config, search_domains[i]); + nm_l3_config_data_add_search(l3cd, AF_INET, search_domains[i]); } nm_dhcp_option_add_option(options, AF_INET, @@ -216,7 +211,7 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, if (sd_dhcp_lease_get_domainname(lease, &s) >= 0) { gs_strfreev char **domains = NULL; - char ** d; + char **d; nm_dhcp_option_add_option(options, AF_INET, NM_DHCP_OPTION_DHCP4_DOMAIN_NAME, s); @@ -224,7 +219,7 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, * As systemd escapes such characters, split them at \\032. */ domains = g_strsplit(s, "\\032", 0); for (d = domains; *d; d++) - nm_ip4_config_add_domain(ip4_config, *d); + nm_l3_config_data_add_domain(l3cd, AF_INET, *d); } if (sd_dhcp_lease_get_hostname(lease, &s) >= 0) { @@ -233,9 +228,9 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, num = sd_dhcp_lease_get_routes(lease, &routes); if (num > 0) { - nm_auto_free_gstring GString *str_classless = NULL; - nm_auto_free_gstring GString *str_static = NULL; - guint32 default_route_metric = route_metric; + nm_auto_free_gstring GString *str_classless = NULL; + nm_auto_free_gstring GString *str_static = NULL; + guint32 default_route_metric_offset = 0; for (i = 0; i < num; i++) { switch (sd_dhcp_route_get_option(routes[i])) { @@ -307,25 +302,22 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, if (r_plen == 0) { /* if there are multiple default routes, we add them with differing * metrics. */ - m = default_route_metric; - if (default_route_metric < G_MAXUINT32) - default_route_metric++; - + m = default_route_metric_offset++; has_router_from_classless = TRUE; } else - m = route_metric; - - nm_ip4_config_add_route( - ip4_config, - &((const NMPlatformIP4Route){ - .network = network_net, - .plen = r_plen, - .gateway = r_gateway.s_addr, - .rt_source = NM_IP_CONFIG_SOURCE_DHCP, - .metric = m, - .table_coerced = nm_platform_route_table_coerce(route_table), - }), - NULL); + m = 0; + + nm_l3_config_data_add_route_4(l3cd, + &((const NMPlatformIP4Route){ + .network = network_net, + .plen = r_plen, + .gateway = r_gateway.s_addr, + .rt_source = NM_IP_CONFIG_SOURCE_DHCP, + .metric_any = TRUE, + .metric = m, + .table_any = TRUE, + .table_coerced = 0, + })); } if (str_classless && str_classless->len > 0) @@ -342,7 +334,7 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, num = sd_dhcp_lease_get_router(lease, &a_router); if (num > 0) { - guint32 default_route_metric = route_metric; + guint32 default_route_metric_offset = 0; nm_gstring_prepare(&str); for (i = 0; i < num; i++) { @@ -368,26 +360,24 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, /* if there are multiple default routes, we add them with differing * metrics. */ - m = default_route_metric; - if (default_route_metric < G_MAXUINT32) - default_route_metric++; - - nm_ip4_config_add_route( - ip4_config, - &((const NMPlatformIP4Route){ - .rt_source = NM_IP_CONFIG_SOURCE_DHCP, - .gateway = a_router[i].s_addr, - .table_coerced = nm_platform_route_table_coerce(route_table), - .metric = m, - }), - NULL); + m = default_route_metric_offset++; + + nm_l3_config_data_add_route_4(l3cd, + &((const NMPlatformIP4Route){ + .rt_source = NM_IP_CONFIG_SOURCE_DHCP, + .gateway = a_router[i].s_addr, + .table_any = TRUE, + .table_coerced = 0, + .metric_any = TRUE, + .metric = m, + })); } nm_dhcp_option_add_option(options, AF_INET, NM_DHCP_OPTION_DHCP4_ROUTER, str->str); } if (sd_dhcp_lease_get_mtu(lease, &mtu) >= 0 && mtu) { nm_dhcp_option_add_option_u64(options, AF_INET, NM_DHCP_OPTION_DHCP4_INTERFACE_MTU, mtu); - nm_ip4_config_set_mtu(ip4_config, mtu, NM_IP_CONFIG_SOURCE_DHCP); + nm_l3_config_data_set_mtu(l3cd, mtu); } num = sd_dhcp_lease_get_ntp(lease, &addr_list); @@ -422,9 +412,10 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, nm_dhcp_option_add_option(options, AF_INET, NM_DHCP_OPTION_DHCP4_NEW_TZDB_TIMEZONE, s); } - if (sd_dhcp_lease_get_vendor_specific(lease, &data, &data_len) >= 0) - metered = !!memmem(data, data_len, "ANDROID_METERED", NM_STRLEN("ANDROID_METERED")); - nm_ip4_config_set_metered(ip4_config, metered); + if (sd_dhcp_lease_get_vendor_specific(lease, &data, &data_len) >= 0) { + if (!!memmem(data, data_len, "ANDROID_METERED", NM_STRLEN("ANDROID_METERED"))) + nm_l3_config_data_set_metered(l3cd, TRUE); + } num = nm_sd_dhcp_lease_get_private_options(lease, &private_options); if (num > 0) { @@ -432,16 +423,22 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, guint8 code = private_options[i].code; const guint8 *l_data = private_options[i].data; gsize l_data_len = private_options[i].data_len; - char * option_string; + char *option_string; if (code == NM_DHCP_OPTION_DHCP4_PRIVATE_PROXY_AUTODISCOVERY) { if (nm_dhcp_lease_data_parse_cstr(l_data, l_data_len, &l_data_len)) { - nm_dhcp_option_add_option_utf8safe_escape( - options, - AF_INET, - NM_DHCP_OPTION_DHCP4_PRIVATE_PROXY_AUTODISCOVERY, - l_data, - l_data_len); + gs_free char *to_free = NULL; + const char *escaped; + + escaped = + nm_utils_buf_utf8safe_escape((char *) l_data, l_data_len, 0, &to_free); + nm_dhcp_option_add_option(options, + AF_INET, + NM_DHCP_OPTION_DHCP4_PRIVATE_PROXY_AUTODISCOVERY, + escaped ?: ""); + + nm_l3_config_data_set_proxy_method(l3cd, NM_PROXY_CONFIG_METHOD_AUTO); + nm_l3_config_data_set_proxy_pac_url(l3cd, escaped ?: ""); } continue; } @@ -458,8 +455,12 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, nm_dhcp_option_take_option(options, AF_INET, code, option_string); } } - NM_SET_OUT(out_options, g_steal_pointer(&options)); - return g_steal_pointer(&ip4_config); + + nm_dhcp_option_add_requests_to_options(options, AF_INET); + + nm_l3_config_data_set_dhcp_lease_from_options(l3cd, AF_INET, g_steal_pointer(&options)); + + return g_steal_pointer(&l3cd); } /*****************************************************************************/ @@ -467,52 +468,46 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, static void bound4_handle(NMDhcpSystemd *self, gboolean extended) { - NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE(self); - const char * iface = nm_dhcp_client_get_iface(NM_DHCP_CLIENT(self)); - gs_unref_object NMIP4Config *ip4_config = NULL; - gs_unref_hashtable GHashTable *options = NULL; - sd_dhcp_lease * lease = NULL; - GError * error = NULL; + NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE(self); + const char *iface = nm_dhcp_client_get_iface(NM_DHCP_CLIENT(self)); + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + sd_dhcp_lease *lease = NULL; + GError *error = NULL; if (sd_dhcp_client_get_lease(priv->client4, &lease) < 0 || !lease) { _LOGW("no lease!"); - nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_FAIL, NULL, NULL); + nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_FAIL, NULL); return; } _LOGD("lease available"); - ip4_config = lease_to_ip4_config(nm_dhcp_client_get_multi_idx(NM_DHCP_CLIENT(self)), - iface, - nm_dhcp_client_get_ifindex(NM_DHCP_CLIENT(self)), - lease, - nm_dhcp_client_get_route_table(NM_DHCP_CLIENT(self)), - nm_dhcp_client_get_route_metric(NM_DHCP_CLIENT(self)), - &options, - &error); - if (!ip4_config) { + l3cd = lease_to_ip4_config(nm_dhcp_client_get_multi_idx(NM_DHCP_CLIENT(self)), + iface, + nm_dhcp_client_get_ifindex(NM_DHCP_CLIENT(self)), + lease, + &error); + if (!l3cd) { _LOGW("%s", error->message); g_clear_error(&error); - nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_FAIL, NULL, NULL); + nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_FAIL, NULL); return; } - nm_dhcp_option_add_requests_to_options(options, AF_INET); dhcp_lease_save(lease, priv->lease_file); nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), extended ? NM_DHCP_STATE_EXTENDED : NM_DHCP_STATE_BOUND, - NM_IP_CONFIG_CAST(ip4_config), - options); + l3cd); } static int dhcp_event_cb(sd_dhcp_client *client, int event, gpointer user_data) { - NMDhcpSystemd * self = NM_DHCP_SYSTEMD(user_data); + NMDhcpSystemd *self = NM_DHCP_SYSTEMD(user_data); NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE(self); char addr_str[INET_ADDRSTRLEN]; - sd_dhcp_lease * lease = NULL; + sd_dhcp_lease *lease = NULL; struct in_addr addr; int r; @@ -522,10 +517,10 @@ dhcp_event_cb(sd_dhcp_client *client, int event, gpointer user_data) switch (event) { case SD_DHCP_CLIENT_EVENT_EXPIRED: - nm_dhcp_client_set_state(NM_DHCP_CLIENT(user_data), NM_DHCP_STATE_EXPIRE, NULL, NULL); + nm_dhcp_client_set_state(NM_DHCP_CLIENT(user_data), NM_DHCP_STATE_EXPIRE, NULL); break; case SD_DHCP_CLIENT_EVENT_STOP: - nm_dhcp_client_set_state(NM_DHCP_CLIENT(user_data), NM_DHCP_STATE_FAIL, NULL, NULL); + nm_dhcp_client_set_state(NM_DHCP_CLIENT(user_data), NM_DHCP_STATE_FAIL, NULL); break; case SD_DHCP_CLIENT_EVENT_RENEW: case SD_DHCP_CLIENT_EVENT_IP_CHANGE: @@ -558,32 +553,35 @@ dhcp_event_cb(sd_dhcp_client *client, int event, gpointer user_data) } static gboolean -ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) +ip4_start(NMDhcpClient *client, GError **error) { - nm_auto(sd_dhcp_client_unrefp) sd_dhcp_client *sd_client = NULL; - NMDhcpSystemd * self = NM_DHCP_SYSTEMD(client); - NMDhcpSystemdPrivate * priv = NM_DHCP_SYSTEMD_GET_PRIVATE(self); - gs_free char * lease_file = NULL; - GBytes * hwaddr; - const uint8_t * hwaddr_arr; + nm_auto(sd_dhcp_client_unrefp) sd_dhcp_client *sd_client = NULL; + NMDhcpSystemd *self = NM_DHCP_SYSTEMD(client); + NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE(self); + const NMDhcpClientConfig *client_config; + gs_free char *lease_file = NULL; + GBytes *hwaddr; + const uint8_t *hwaddr_arr; gsize hwaddr_len; int arp_type; - GBytes * client_id; - gs_unref_bytes GBytes *client_id_new = NULL; - GBytes * vendor_class_identifier; - const uint8_t * client_id_arr; - size_t client_id_len; - struct in_addr last_addr = {0}; - const char * hostname; - const char * mud_url; - int r, i; - GBytes * bcast_hwaddr; - const uint8_t * bcast_hwaddr_arr; - gsize bcast_hwaddr_len; + GBytes *client_id; + gs_unref_bytes GBytes *client_id_new = NULL; + GBytes *vendor_class_identifier; + const uint8_t *client_id_arr; + size_t client_id_len; + struct in_addr last_addr = {0}; + const char *hostname; + const char *mud_url; + int r, i; + GBytes *bcast_hwaddr; + const uint8_t *bcast_hwaddr_arr; + gsize bcast_hwaddr_len; g_return_val_if_fail(!priv->client4, FALSE); g_return_val_if_fail(!priv->client6, FALSE); + client_config = nm_dhcp_client_get_config(client); + /* TODO: honor nm_dhcp_client_get_anycast_address() */ r = sd_dhcp_client_new(&sd_client, FALSE); @@ -600,7 +598,7 @@ ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) return FALSE; } - hwaddr = nm_dhcp_client_get_hw_addr(client); + hwaddr = client_config->hwaddr; if (!hwaddr || !(hwaddr_arr = g_bytes_get_data(hwaddr, &hwaddr_len)) || (arp_type = nm_utils_arp_type_detect_from_hwaddrlen(hwaddr_len)) < 0) { nm_utils_error_set_literal(error, NM_UTILS_ERROR_UNKNOWN, "invalid MAC address"); @@ -608,7 +606,8 @@ ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) } bcast_hwaddr_arr = NULL; - if ((bcast_hwaddr = nm_dhcp_client_get_broadcast_hw_addr(NM_DHCP_CLIENT(self)))) { + bcast_hwaddr = client_config->bcast_hwaddr; + if (bcast_hwaddr) { bcast_hwaddr_arr = g_bytes_get_data(bcast_hwaddr, &bcast_hwaddr_len); if (bcast_hwaddr_len != hwaddr_len) bcast_hwaddr_arr = NULL; @@ -632,12 +631,12 @@ ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) nm_dhcp_utils_get_leasefile_path(AF_INET, "internal", - nm_dhcp_client_get_iface(client), - nm_dhcp_client_get_uuid(client), + client_config->iface, + client_config->uuid, &lease_file); - if (last_ip4_address) - inet_pton(AF_INET, last_ip4_address, &last_addr); + if (client_config->v4.last_address) + inet_pton(AF_INET, client_config->v4.last_address, &last_addr); else { nm_auto(sd_dhcp_lease_unrefp) sd_dhcp_lease *lease = NULL; @@ -646,9 +645,7 @@ ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) sd_dhcp_lease_get_address(lease, &last_addr); } - r = sd_dhcp_client_set_request_broadcast(sd_client, - NM_FLAGS_HAS(nm_dhcp_client_get_client_flags(client), - NM_DHCP_CLIENT_FLAGS_REQUEST_BROADCAST)); + r = sd_dhcp_client_set_request_broadcast(sd_client, client_config->v4.request_broadcast); nm_assert(r >= 0); if (last_addr.s_addr) { @@ -659,7 +656,7 @@ ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) } } - client_id = nm_dhcp_client_get_client_id(client); + client_id = client_config->client_id; if (!client_id) { client_id_new = nm_utils_dhcp_client_id_mac(arp_type, hwaddr_arr, hwaddr_len); client_id = client_id_new; @@ -694,7 +691,7 @@ ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) } } - hostname = nm_dhcp_client_get_hostname(client); + hostname = client_config->hostname; if (hostname) { /* FIXME: sd-dhcp decides which hostname/FQDN option to send (12 or 81) * only based on whether the hostname has a domain part or not. At the @@ -707,7 +704,7 @@ ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) } } - mud_url = nm_dhcp_client_get_mud_url(client); + mud_url = client_config->mud_url; if (mud_url) { r = sd_dhcp_client_set_mud_url(sd_client, mud_url); if (r < 0) { @@ -716,7 +713,7 @@ ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) } } - vendor_class_identifier = nm_dhcp_client_get_vendor_class_identifier(client); + vendor_class_identifier = client_config->vendor_class_identifier; if (vendor_class_identifier) { const char *option_data; gsize len; @@ -745,7 +742,7 @@ ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) g_free(priv->lease_file); priv->lease_file = g_steal_pointer(&lease_file); - nm_dhcp_client_set_client_id(client, client_id); + nm_dhcp_client_set_effective_client_id(client, client_id); r = sd_dhcp_client_start(priv->client4); if (r < 0) { @@ -755,36 +752,37 @@ ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) return FALSE; } - nm_dhcp_client_start_timeout(client); return TRUE; } -static NMIP6Config * +static NML3ConfigData * lease_to_ip6_config(NMDedupMultiIndex *multi_idx, - const char * iface, + const char *iface, int ifindex, - sd_dhcp6_lease * lease, + sd_dhcp6_lease *lease, gboolean info_only, - GHashTable ** out_options, gint32 ts, - GError ** error) + GError **error) { - gs_unref_object NMIP6Config *ip6_config = NULL; - gs_unref_hashtable GHashTable *options = NULL; - struct in6_addr tmp_addr; - const struct in6_addr * dns; - uint32_t lft_pref, lft_valid; - char addr_str[NM_UTILS_INET_ADDRSTRLEN]; - char ** domains; - const char * s; - nm_auto_free_gstring GString *str = NULL; - int num, i; + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + gs_unref_hashtable GHashTable *options = NULL; + struct in6_addr tmp_addr; + const struct in6_addr *dns; + uint32_t lft_pref, lft_valid; + char addr_str[NM_UTILS_INET_ADDRSTRLEN]; + char **domains; + char **ntp_fqdns; + const struct in6_addr *ntp_addrs; + const char *s; + nm_auto_free_gstring GString *str = NULL; + gboolean has_any_addresses = FALSE; + int num, i; nm_assert(lease); - ip6_config = nm_ip6_config_new(multi_idx, ifindex); + l3cd = nm_l3_config_data_new(multi_idx, ifindex, NM_IP_CONFIG_SOURCE_DHCP); - options = out_options ? nm_dhcp_option_create_options_dict() : NULL; + options = nm_dhcp_option_create_options_dict(); sd_dhcp6_lease_reset_address_iter(lease); nm_gstring_prepare(&str); @@ -798,15 +796,19 @@ lease_to_ip6_config(NMDedupMultiIndex *multi_idx, .addr_source = NM_IP_CONFIG_SOURCE_DHCP, }; - nm_ip6_config_add_address(ip6_config, &address); + nm_l3_config_data_add_address_6(l3cd, &address); _nm_utils_inet6_ntop(&tmp_addr, addr_str); g_string_append(nm_gstring_add_space_delimiter(str), addr_str); - }; - if (str->len) + + has_any_addresses = TRUE; + } + + if (str->len) { nm_dhcp_option_add_option(options, AF_INET6, NM_DHCP_OPTION_DHCP6_NM_IP_ADDRESS, str->str); + } - if (!info_only && nm_ip6_config_get_num_addresses(ip6_config) == 0) { + if (!info_only && !has_any_addresses) { g_set_error_literal(error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED, @@ -820,7 +822,7 @@ lease_to_ip6_config(NMDedupMultiIndex *multi_idx, for (i = 0; i < num; i++) { _nm_utils_inet6_ntop(&dns[i], addr_str); g_string_append(nm_gstring_add_space_delimiter(str), addr_str); - nm_ip6_config_add_nameserver(ip6_config, &dns[i]); + nm_l3_config_data_add_nameserver(l3cd, AF_INET6, &dns[i]); } nm_dhcp_option_add_option(options, AF_INET6, NM_DHCP_OPTION_DHCP6_DNS_SERVERS, str->str); } @@ -830,7 +832,7 @@ lease_to_ip6_config(NMDedupMultiIndex *multi_idx, nm_gstring_prepare(&str); for (i = 0; i < num; i++) { g_string_append(nm_gstring_add_space_delimiter(str), domains[i]); - nm_ip6_config_add_search(ip6_config, domains[i]); + nm_l3_config_data_add_search(l3cd, AF_INET6, domains[i]); } nm_dhcp_option_add_option(options, AF_INET6, NM_DHCP_OPTION_DHCP6_DOMAIN_LIST, str->str); } @@ -839,51 +841,72 @@ lease_to_ip6_config(NMDedupMultiIndex *multi_idx, nm_dhcp_option_add_option(options, AF_INET6, NM_DHCP_OPTION_DHCP6_FQDN, s); } - NM_SET_OUT(out_options, g_steal_pointer(&options)); - return g_steal_pointer(&ip6_config); + /* RFC 5908, section 4 states: "This option MUST include one, and only + * one, time source suboption." It is not clear why systemd chose to + * return array of addresses and FQDNs. Given there seem to be no + * technical obstacles to including multiple options, let's just + * pass on whatever systemd tells us. + */ + nm_gstring_prepare(&str); + num = sd_dhcp6_lease_get_ntp_fqdn(lease, &ntp_fqdns); + if (num > 0) { + for (i = 0; i < num; i++) { + g_string_append(nm_gstring_add_space_delimiter(str), ntp_fqdns[i]); + } + } + num = sd_dhcp6_lease_get_ntp_addrs(lease, &ntp_addrs); + if (num > 0) { + for (i = 0; i < num; i++) { + _nm_utils_inet6_ntop(&ntp_addrs[i], addr_str); + g_string_append(nm_gstring_add_space_delimiter(str), addr_str); + } + } + if (str->len) { + nm_dhcp_option_add_option(options, AF_INET6, NM_DHCP_OPTION_DHCP6_NTP_SERVER, str->str); + } + + nm_l3_config_data_set_dhcp_lease_from_options(l3cd, AF_INET6, g_steal_pointer(&options)); + + return g_steal_pointer(&l3cd); } static void bound6_handle(NMDhcpSystemd *self) { - NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE(self); - const gint32 ts = nm_utils_get_monotonic_timestamp_sec(); - const char * iface = nm_dhcp_client_get_iface(NM_DHCP_CLIENT(self)); - gs_unref_object NMIP6Config *ip6_config = NULL; - gs_unref_hashtable GHashTable *options = NULL; - gs_free_error GError *error = NULL; - NMPlatformIP6Address prefix = {0}; - sd_dhcp6_lease * lease = NULL; + NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE(self); + const gint32 ts = nm_utils_get_monotonic_timestamp_sec(); + const char *iface = nm_dhcp_client_get_iface(NM_DHCP_CLIENT(self)); + const NMDhcpClientConfig *client_config; + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + gs_free_error GError *error = NULL; + NMPlatformIP6Address prefix = {0}; + sd_dhcp6_lease *lease = NULL; + + client_config = nm_dhcp_client_get_config(NM_DHCP_CLIENT(self)); if (sd_dhcp6_client_get_lease(priv->client6, &lease) < 0 || !lease) { _LOGW(" no lease!"); - nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_FAIL, NULL, NULL); + nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_FAIL, NULL); return; } _LOGD("lease available"); - ip6_config = - lease_to_ip6_config(nm_dhcp_client_get_multi_idx(NM_DHCP_CLIENT(self)), - iface, - nm_dhcp_client_get_ifindex(NM_DHCP_CLIENT(self)), - lease, - NM_FLAGS_HAS(nm_dhcp_client_get_client_flags(NM_DHCP_CLIENT(self)), - NM_DHCP_CLIENT_FLAGS_INFO_ONLY), - &options, - ts, - &error); - - if (!ip6_config) { + l3cd = lease_to_ip6_config(nm_dhcp_client_get_multi_idx(NM_DHCP_CLIENT(self)), + iface, + nm_dhcp_client_get_ifindex(NM_DHCP_CLIENT(self)), + lease, + client_config->v6.info_only, + ts, + &error); + + if (!l3cd) { _LOGW("%s", error->message); - nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_FAIL, NULL, NULL); + nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_FAIL, NULL); return; } - nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), - NM_DHCP_STATE_BOUND, - NM_IP_CONFIG_CAST(ip6_config), - options); + nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_BOUND, l3cd); sd_dhcp6_lease_reset_pd_prefix_iter(lease); while (!sd_dhcp6_lease_get_pd(lease, @@ -899,7 +922,7 @@ bound6_handle(NMDhcpSystemd *self) static void dhcp6_event_cb(sd_dhcp6_client *client, int event, gpointer user_data) { - NMDhcpSystemd * self = NM_DHCP_SYSTEMD(user_data); + NMDhcpSystemd *self = NM_DHCP_SYSTEMD(user_data); NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE(self); nm_assert(priv->client6 == client); @@ -908,11 +931,11 @@ dhcp6_event_cb(sd_dhcp6_client *client, int event, gpointer user_data) switch (event) { case SD_DHCP6_CLIENT_EVENT_RETRANS_MAX: - nm_dhcp_client_set_state(NM_DHCP_CLIENT(user_data), NM_DHCP_STATE_TIMEOUT, NULL, NULL); + nm_dhcp_client_set_state(NM_DHCP_CLIENT(user_data), NM_DHCP_STATE_TIMEOUT, NULL); break; case SD_DHCP6_CLIENT_EVENT_RESEND_EXPIRE: case SD_DHCP6_CLIENT_EVENT_STOP: - nm_dhcp_client_set_state(NM_DHCP_CLIENT(user_data), NM_DHCP_STATE_FAIL, NULL, NULL); + nm_dhcp_client_set_state(NM_DHCP_CLIENT(user_data), NM_DHCP_STATE_FAIL, NULL); break; case SD_DHCP6_CLIENT_EVENT_IP_ACQUIRE: case SD_DHCP6_CLIENT_EVENT_INFORMATION_REQUEST: @@ -925,29 +948,29 @@ dhcp6_event_cb(sd_dhcp6_client *client, int event, gpointer user_data) } static gboolean -ip6_start(NMDhcpClient * client, - const struct in6_addr * ll_addr, - NMSettingIP6ConfigPrivacy privacy, - guint needed_prefixes, - GError ** error) +ip6_start(NMDhcpClient *client, const struct in6_addr *ll_addr, GError **error) { - NMDhcpSystemd * self = NM_DHCP_SYSTEMD(client); - NMDhcpSystemdPrivate * priv = NM_DHCP_SYSTEMD_GET_PRIVATE(self); + NMDhcpSystemd *self = NM_DHCP_SYSTEMD(client); + NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE(self); nm_auto(sd_dhcp6_client_unrefp) sd_dhcp6_client *sd_client = NULL; - const char * hostname; - const char * mud_url; + const NMDhcpClientConfig *client_config; + const char *hostname; + const char *mud_url; int r, i; - const guint8 * duid_arr; + const guint8 *duid_arr; gsize duid_len; - GBytes * duid; + GBytes *duid; + gboolean prefix_delegation; g_return_val_if_fail(!priv->client4, FALSE); g_return_val_if_fail(!priv->client6, FALSE); + client_config = nm_dhcp_client_get_config(client); + /* TODO: honor nm_dhcp_client_get_anycast_address() */ - if (!(duid = nm_dhcp_client_get_client_id(client)) - || !(duid_arr = g_bytes_get_data(duid, &duid_len)) || duid_len < 2) { + duid = nm_dhcp_client_get_effective_client_id(client); + if (!duid || !(duid_arr = g_bytes_get_data(duid, &duid_len)) || duid_len < 2) { nm_utils_error_set_literal(error, NM_UTILS_ERROR_UNKNOWN, "missing DUID"); g_return_val_if_reached(FALSE); } @@ -960,13 +983,13 @@ ip6_start(NMDhcpClient * client, _LOGT("dhcp-client6: set %p", sd_client); - if (NM_FLAGS_HAS(nm_dhcp_client_get_client_flags(client), NM_DHCP_CLIENT_FLAGS_INFO_ONLY)) { + if (client_config->v6.info_only) { sd_dhcp6_client_set_address_request(sd_client, 0); - if (needed_prefixes == 0) + if (client_config->v6.needed_prefixes == 0) sd_dhcp6_client_set_information_request(sd_client, 1); } - r = sd_dhcp6_client_set_iaid(sd_client, nm_dhcp_client_get_iaid(client)); + r = sd_dhcp6_client_set_iaid(sd_client, client_config->v6.iaid); if (r < 0) { nm_utils_error_set_errno(error, r, "failed to set IAID: %s"); return FALSE; @@ -1002,7 +1025,7 @@ ip6_start(NMDhcpClient * client, } } - mud_url = nm_dhcp_client_get_mud_url(client); + mud_url = client_config->mud_url; if (mud_url) { r = sd_dhcp6_client_set_request_mud_url(sd_client, mud_url); if (r < 0) { @@ -1011,16 +1034,19 @@ ip6_start(NMDhcpClient * client, } } - if (needed_prefixes > 0) { - if (needed_prefixes > 1) + prefix_delegation = FALSE; + if (client_config->v6.needed_prefixes > 0) { + if (client_config->v6.needed_prefixes > 1) { + /* FIXME: systemd-networkd API only allows to request a + * single prefix */ _LOGW("dhcp-client6: only one prefix request is supported"); - /* FIXME: systemd-networkd API only allows to request a - * single prefix */ - r = sd_dhcp6_client_set_prefix_delegation(sd_client, TRUE); - if (r < 0) { - nm_utils_error_set_errno(error, r, "failed to enable prefix delegation: %s"); - return FALSE; } + prefix_delegation = TRUE; + } + r = sd_dhcp6_client_set_prefix_delegation(sd_client, prefix_delegation); + if (r < 0) { + nm_utils_error_set_errno(error, r, "failed to enable prefix delegation: %s"); + return FALSE; } r = sd_dhcp6_client_set_local_address(sd_client, ll_addr); @@ -1029,7 +1055,7 @@ ip6_start(NMDhcpClient * client, return FALSE; } - hostname = nm_dhcp_client_get_hostname(client); + hostname = client_config->hostname; r = sd_dhcp6_client_set_fqdn(sd_client, hostname); if (r < 0) { nm_utils_error_set_errno(error, r, "failed to set DHCP hostname: %s"); @@ -1052,14 +1078,13 @@ ip6_start(NMDhcpClient * client, return FALSE; } - nm_dhcp_client_start_timeout(client); return TRUE; } static void stop(NMDhcpClient *client, gboolean release) { - NMDhcpSystemd * self = NM_DHCP_SYSTEMD(client); + NMDhcpSystemd *self = NM_DHCP_SYSTEMD(client); NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE(self); int r = 0; @@ -1113,7 +1138,7 @@ 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); + GObjectClass *object_class = G_OBJECT_CLASS(sdhcp_class); object_class->dispose = dispose; diff --git a/src/core/dhcp/nm-dhcp-utils.c b/src/core/dhcp/nm-dhcp-utils.c index 3cc6987a..4a138086 100644 --- a/src/core/dhcp/nm-dhcp-utils.c +++ b/src/core/dhcp/nm-dhcp-utils.c @@ -14,6 +14,7 @@ #include "libnm-systemd-shared/nm-sd-utils-shared.h" #include "nm-dhcp-utils.h" +#include "nm-l3-config-data.h" #include "nm-utils.h" #include "nm-config.h" #include "NetworkManagerUtils.h" @@ -24,15 +25,13 @@ /*****************************************************************************/ static gboolean -ip4_process_dhcpcd_rfc3442_routes(const char * iface, - const char * str, - guint32 route_table, - guint32 route_metric, - NMIP4Config *ip4_config, - guint32 * gwaddr) +ip4_process_dhcpcd_rfc3442_routes(const char *iface, + const char *str, + NML3ConfigData *l3cd, + guint32 *gwaddr) { gs_free const char **routes = NULL; - const char ** r; + const char **r; gboolean have_routes = FALSE; routes = nm_strsplit_set(str, " "); @@ -45,10 +44,9 @@ ip4_process_dhcpcd_rfc3442_routes(const char * iface, } for (r = routes; *r; r += 2) { - char * slash; - NMPlatformIP4Route route; - int rt_cidr = 32; - guint32 rt_addr, rt_route; + char *slash; + int rt_cidr = 32; + guint32 rt_addr, rt_route; slash = strchr(*r, '/'); if (slash) { @@ -89,14 +87,18 @@ ip4_process_dhcpcd_rfc3442_routes(const char * iface, *r, rt_cidr, *(r + 1)); - memset(&route, 0, sizeof(route)); - route.network = nm_utils_ip4_address_clear_host_address(rt_addr, rt_cidr); - route.plen = rt_cidr; - route.gateway = rt_route; - route.rt_source = NM_IP_CONFIG_SOURCE_DHCP; - route.metric = route_metric; - route.table_coerced = nm_platform_route_table_coerce(route_table); - nm_ip4_config_add_route(ip4_config, &route, NULL); + + nm_l3_config_data_add_route_4( + l3cd, + &((const NMPlatformIP4Route){ + .network = nm_utils_ip4_address_clear_host_address(rt_addr, rt_cidr), + .plen = rt_cidr, + .gateway = rt_route, + .rt_source = NM_IP_CONFIG_SOURCE_DHCP, + .metric_any = TRUE, + .table_any = TRUE, + + })); } } @@ -107,7 +109,7 @@ static gboolean process_dhclient_rfc3442_route(const char *const **p_octets, NMPlatformIP4Route *route) { const char *const *o = *p_octets; - gs_free char * next_hop = NULL; + gs_free char *next_hop = NULL; int addr_len; int v_plen; in_addr_t tmp_addr; @@ -125,7 +127,7 @@ process_dhclient_rfc3442_route(const char *const **p_octets, NMPlatformIP4Route return FALSE; if (v_plen > 0) { - const char * addr[4] = {"0", "0", "0", "0"}; + const char *addr[4] = {"0", "0", "0", "0"}; gs_free char *str_addr = NULL; int i; @@ -153,15 +155,13 @@ process_dhclient_rfc3442_route(const char *const **p_octets, NMPlatformIP4Route } static gboolean -ip4_process_dhclient_rfc3442_routes(const char * iface, - const char * str, - guint32 route_table, - guint32 route_metric, - NMIP4Config *ip4_config, - guint32 * gwaddr) +ip4_process_dhclient_rfc3442_routes(const char *iface, + const char *str, + NML3ConfigData *l3cd, + guint32 *gwaddr) { gs_free const char **octets = NULL; - const char *const * o; + const char *const *o; gboolean have_routes = FALSE; octets = nm_strsplit_set_with_empty(str, " ."); @@ -189,9 +189,12 @@ ip4_process_dhclient_rfc3442_routes(const char * iface, /* normal route */ route.rt_source = NM_IP_CONFIG_SOURCE_DHCP; - route.metric = route_metric; - route.table_coerced = nm_platform_route_table_coerce(route_table); - nm_ip4_config_add_route(ip4_config, &route, NULL); + route.table_any = TRUE; + route.table_coerced = 0; + route.metric_any = TRUE; + route.metric = 0; + + nm_l3_config_data_add_route_4(l3cd, &route); _LOG2I(LOGD_DHCP4, iface, @@ -206,17 +209,15 @@ ip4_process_dhclient_rfc3442_routes(const char * iface, } static gboolean -ip4_process_classless_routes(const char * iface, - GHashTable * options, - guint32 route_table, - guint32 route_metric, - NMIP4Config *ip4_config, - guint32 * gwaddr) +ip4_process_classless_routes(const char *iface, + GHashTable *options, + NML3ConfigData *l3cd, + guint32 *gwaddr) { const char *str, *p; g_return_val_if_fail(options != NULL, FALSE); - g_return_val_if_fail(ip4_config != NULL, FALSE); + g_return_val_if_fail(l3cd != NULL, FALSE); *gwaddr = 0; @@ -251,7 +252,7 @@ ip4_process_classless_routes(const char * iface, if (!str) str = g_hash_table_lookup(options, "ms_classless_static_routes"); - if (!str || !strlen(str)) + if (nm_str_is_empty(str)) return FALSE; p = str; @@ -265,32 +266,18 @@ ip4_process_classless_routes(const char * iface, if (strchr(str, '/')) { /* dhcpcd format */ - return ip4_process_dhcpcd_rfc3442_routes(iface, - str, - route_table, - route_metric, - ip4_config, - gwaddr); + return ip4_process_dhcpcd_rfc3442_routes(iface, str, l3cd, gwaddr); } - return ip4_process_dhclient_rfc3442_routes(iface, - str, - route_table, - route_metric, - ip4_config, - gwaddr); + return ip4_process_dhclient_rfc3442_routes(iface, str, l3cd, gwaddr); } static void -process_classful_routes(const char * iface, - GHashTable * options, - guint32 route_table, - guint32 route_metric, - NMIP4Config *ip4_config) +process_classful_routes(const char *iface, GHashTable *options, NML3ConfigData *l3cd) { gs_free const char **searches = NULL; - const char ** s; - const char * str; + const char **s; + const char *str; str = g_hash_table_lookup(options, "static_routes"); if (!str) @@ -320,8 +307,10 @@ process_classful_routes(const char * iface, // FIXME: ensure the IP address and route are sane - memset(&route, 0, sizeof(route)); - route.network = rt_addr; + route = (NMPlatformIP4Route){ + .network = rt_addr, + }; + /* RFC 2132, updated by RFC 3442: * The Static Routes option (option 33) does not provide a subnet mask * for each route - it is assumed that the subnet mask is implicit in @@ -333,12 +322,15 @@ process_classful_routes(const char * iface, } route.gateway = rt_route; route.rt_source = NM_IP_CONFIG_SOURCE_DHCP; - route.metric = route_metric; - route.table_coerced = nm_platform_route_table_coerce(route_table); + route.table_any = TRUE; + route.table_coerced = 0; + route.metric_any = TRUE; + route.metric = 0; route.network = nm_utils_ip4_address_clear_host_address(route.network, route.plen); - nm_ip4_config_add_route(ip4_config, &route, NULL); + nm_l3_config_data_add_route_4(l3cd, &route); + _LOG2I(LOGD_DHCP, iface, " static route %s", @@ -347,16 +339,16 @@ process_classful_routes(const char * iface, } static void -process_domain_search(const char *iface, const char *str, GFunc add_func, gpointer user_data) +process_domain_search(int addr_family, const char *iface, const char *str, NML3ConfigData *l3cd) { gs_free const char **searches = NULL; - gs_free char * unescaped = NULL; - const char ** s; - char * p; + gs_free char *unescaped = NULL; + const char **s; + char *p; int i; g_return_if_fail(str != NULL); - g_return_if_fail(add_func != NULL); + nm_assert(l3cd); unescaped = g_strdup(str); @@ -379,46 +371,43 @@ process_domain_search(const char *iface, const char *str, GFunc add_func, gpoint searches = nm_strsplit_set(unescaped, " "); for (s = searches; searches && *s; s++) { _LOG2I(LOGD_DHCP, iface, " domain search '%s'", *s); - add_func((gpointer) *s, user_data); + nm_l3_config_data_add_search(l3cd, addr_family, *s); } } -static void -ip4_add_domain_search(gpointer data, gpointer user_data) -{ - nm_ip4_config_add_search(NM_IP4_CONFIG(user_data), (const char *) data); -} - -NMIP4Config * +NML3ConfigData * nm_dhcp_utils_ip4_config_from_options(NMDedupMultiIndex *multi_idx, int ifindex, - const char * iface, - GHashTable * options, - guint32 route_table, - guint32 route_metric) + const char *iface, + GHashTable *options) { - gs_unref_object NMIP4Config *ip4_config = NULL; - guint32 tmp_addr; - in_addr_t addr; - NMPlatformIP4Address address; - char * str = NULL; - gboolean gateway_has = FALSE; - guint32 gateway = 0; - guint8 plen = 0; - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + guint32 tmp_addr; + in_addr_t addr; + NMPlatformIP4Address address; + char *str = NULL; + gboolean gateway_has = FALSE; + guint32 gateway = 0; + guint8 plen = 0; + char sbuf[NM_UTILS_INET_ADDRSTRLEN]; + guint32 now; g_return_val_if_fail(options != NULL, NULL); - ip4_config = nm_ip4_config_new(multi_idx, ifindex); - memset(&address, 0, sizeof(address)); - address.timestamp = nm_utils_get_monotonic_timestamp_sec(); + l3cd = nm_l3_config_data_new(multi_idx, ifindex, NM_IP_CONFIG_SOURCE_DHCP); + + now = nm_utils_get_monotonic_timestamp_sec(); + + address = (NMPlatformIP4Address){ + .timestamp = now, + }; str = g_hash_table_lookup(options, "ip_address"); - if (str && (inet_pton(AF_INET, str, &addr) > 0)) - _LOG2I(LOGD_DHCP4, iface, " address %s", str); - else + if (!str || !nm_utils_parse_inaddr_bin(AF_INET, str, NULL, &addr)) return NULL; + _LOG2I(LOGD_DHCP4, iface, " address %s", str); + str = g_hash_table_lookup(options, "subnet_mask"); if (str && (inet_pton(AF_INET, str, &tmp_addr) > 0)) { plen = nm_utils_ip4_netmask_to_prefix(tmp_addr); @@ -433,13 +422,8 @@ nm_dhcp_utils_ip4_config_from_options(NMDedupMultiIndex *multi_idx, /* Routes: if the server returns classless static routes, we MUST ignore * the 'static_routes' option. */ - if (!ip4_process_classless_routes(iface, - options, - route_table, - route_metric, - ip4_config, - &gateway)) - process_classful_routes(iface, options, route_table, route_metric, ip4_config); + if (!ip4_process_classless_routes(iface, options, l3cd, &gateway)) + process_classful_routes(iface, options, l3cd); if (gateway) { _LOG2I(LOGD_DHCP4, iface, " gateway %s", _nm_utils_inet4_ntop(gateway, sbuf)); @@ -451,9 +435,9 @@ nm_dhcp_utils_ip4_config_from_options(NMDedupMultiIndex *multi_idx, str = g_hash_table_lookup(options, "routers"); if (str) { gs_free const char **routers = nm_strsplit_set(str, " "); - const char ** s; + const char **s; - for (s = routers; routers && *s; s++) { + for (s = routers; *s; s++) { /* FIXME: how to handle multiple routers? */ if (inet_pton(AF_INET, *s, &gateway) > 0) { _LOG2I(LOGD_DHCP4, iface, " gateway %s", *s); @@ -469,11 +453,13 @@ nm_dhcp_utils_ip4_config_from_options(NMDedupMultiIndex *multi_idx, const NMPlatformIP4Route r = { .rt_source = NM_IP_CONFIG_SOURCE_DHCP, .gateway = gateway, - .table_coerced = nm_platform_route_table_coerce(route_table), - .metric = route_metric, + .table_any = TRUE, + .table_coerced = 0, + .metric_any = TRUE, + .metric = 0, }; - nm_ip4_config_add_route(ip4_config, &r, NULL); + nm_l3_config_data_add_route_4(l3cd, &r); } str = g_hash_table_lookup(options, "dhcp_lease_time"); @@ -483,7 +469,8 @@ nm_dhcp_utils_ip4_config_from_options(NMDedupMultiIndex *multi_idx, } address.addr_source = NM_IP_CONFIG_SOURCE_DHCP; - nm_ip4_config_add_address(ip4_config, &address); + + nm_l3_config_data_add_address_4(l3cd, &address); str = g_hash_table_lookup(options, "host_name"); if (str) @@ -492,12 +479,12 @@ nm_dhcp_utils_ip4_config_from_options(NMDedupMultiIndex *multi_idx, str = g_hash_table_lookup(options, "domain_name_servers"); if (str) { gs_free const char **dns = nm_strsplit_set(str, " "); - const char ** s; + const char **s; for (s = dns; dns && *s; s++) { if (inet_pton(AF_INET, *s, &tmp_addr) > 0) { if (tmp_addr) { - nm_ip4_config_add_nameserver(ip4_config, tmp_addr); + nm_l3_config_data_add_nameserver(l3cd, AF_INET, &tmp_addr); _LOG2I(LOGD_DHCP4, iface, " nameserver '%s'", *s); } } else @@ -508,27 +495,27 @@ nm_dhcp_utils_ip4_config_from_options(NMDedupMultiIndex *multi_idx, str = g_hash_table_lookup(options, "domain_name"); if (str) { gs_free const char **domains = nm_strsplit_set(str, " "); - const char ** s; + const char **s; for (s = domains; domains && *s; s++) { _LOG2I(LOGD_DHCP4, iface, " domain name '%s'", *s); - nm_ip4_config_add_domain(ip4_config, *s); + nm_l3_config_data_add_domain(l3cd, AF_INET, *s); } } str = g_hash_table_lookup(options, "domain_search"); if (str) - process_domain_search(iface, str, ip4_add_domain_search, ip4_config); + process_domain_search(AF_INET, iface, str, l3cd); str = g_hash_table_lookup(options, "netbios_name_servers"); if (str) { gs_free const char **nbns = nm_strsplit_set(str, " "); - const char ** s; + const char **s; for (s = nbns; nbns && *s; s++) { if (inet_pton(AF_INET, *s, &tmp_addr) > 0) { if (tmp_addr) { - nm_ip4_config_add_wins(ip4_config, tmp_addr); + nm_l3_config_data_add_wins(l3cd, tmp_addr); _LOG2I(LOGD_DHCP4, iface, " wins '%s'", *s); } } else @@ -546,24 +533,24 @@ nm_dhcp_utils_ip4_config_from_options(NMDedupMultiIndex *multi_idx, return NULL; if (int_mtu > 576) - nm_ip4_config_set_mtu(ip4_config, int_mtu, NM_IP_CONFIG_SOURCE_DHCP); + nm_l3_config_data_set_mtu(l3cd, int_mtu); } str = g_hash_table_lookup(options, "nis_domain"); if (str) { _LOG2I(LOGD_DHCP4, iface, " NIS domain '%s'", str); - nm_ip4_config_set_nis_domain(ip4_config, str); + nm_l3_config_data_add_domain(l3cd, AF_INET, str); } str = g_hash_table_lookup(options, "nis_servers"); if (str) { gs_free const char **nis = nm_strsplit_set(str, " "); - const char ** s; + const char **s; for (s = nis; nis && *s; s++) { if (inet_pton(AF_INET, *s, &tmp_addr) > 0) { if (tmp_addr) { - nm_ip4_config_add_nis_server(ip4_config, tmp_addr); + nm_l3_config_data_add_nis_server(l3cd, tmp_addr); _LOG2I(LOGD_DHCP4, iface, " nis '%s'", *s); } } else @@ -572,28 +559,29 @@ nm_dhcp_utils_ip4_config_from_options(NMDedupMultiIndex *multi_idx, } str = g_hash_table_lookup(options, "vendor_encapsulated_options"); - nm_ip4_config_set_metered(ip4_config, str && strstr(str, "ANDROID_METERED")); + if (str && strstr(str, "ANDROID_METERED")) + nm_l3_config_data_set_metered(l3cd, TRUE); - return g_steal_pointer(&ip4_config); + str = g_hash_table_lookup(options, "wpad"); + if (str) { + nm_l3_config_data_set_proxy_method(l3cd, NM_PROXY_CONFIG_METHOD_AUTO); + nm_l3_config_data_set_proxy_pac_url(l3cd, str); + } + + return g_steal_pointer(&l3cd); } /*****************************************************************************/ -static void -ip6_add_domain_search(gpointer data, gpointer user_data) -{ - nm_ip6_config_add_search(NM_IP6_CONFIG(user_data), (const char *) data); -} - NMPlatformIP6Address nm_dhcp_utils_ip6_prefix_from_options(GHashTable *options) { - gs_strfreev char ** split_addr = NULL; + gs_strfreev char **split_addr = NULL; NMPlatformIP6Address address = { 0, }; struct in6_addr tmp_addr; - char * str = NULL; + char *str = NULL; int prefix; g_return_val_if_fail(options != NULL, address); @@ -635,25 +623,29 @@ nm_dhcp_utils_ip6_prefix_from_options(GHashTable *options) return address; } -NMIP6Config * +NML3ConfigData * nm_dhcp_utils_ip6_config_from_options(NMDedupMultiIndex *multi_idx, int ifindex, - const char * iface, - GHashTable * options, + const char *iface, + GHashTable *options, gboolean info_only) { - gs_unref_object NMIP6Config *ip6_config = NULL; - struct in6_addr tmp_addr; - NMPlatformIP6Address address; - char * str = NULL; + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + struct in6_addr tmp_addr; + NMPlatformIP6Address address; + char *str = NULL; + guint32 now; g_return_val_if_fail(options != NULL, NULL); - memset(&address, 0, sizeof(address)); - address.plen = 128; - address.timestamp = nm_utils_get_monotonic_timestamp_sec(); + now = nm_utils_get_monotonic_timestamp_sec(); + + address = (NMPlatformIP6Address){ + .plen = 128, + .timestamp = now, + }; - ip6_config = nm_ip6_config_new(multi_idx, ifindex); + l3cd = nm_l3_config_data_new(multi_idx, ifindex, NM_IP_CONFIG_SOURCE_DHCP); str = g_hash_table_lookup(options, "max_life"); if (str) { @@ -676,7 +668,7 @@ nm_dhcp_utils_ip6_config_from_options(NMDedupMultiIndex *multi_idx, address.address = tmp_addr; address.addr_source = NM_IP_CONFIG_SOURCE_DHCP; - nm_ip6_config_add_address(ip6_config, &address); + nm_l3_config_data_add_address_6(l3cd, &address); _LOG2I(LOGD_DHCP6, iface, " address %s", str); } else if (info_only == FALSE) { /* No address in Managed mode is a hard error */ @@ -690,12 +682,12 @@ nm_dhcp_utils_ip6_config_from_options(NMDedupMultiIndex *multi_idx, str = g_hash_table_lookup(options, "dhcp6_name_servers"); if (str) { gs_free const char **dns = nm_strsplit_set(str, " "); - const char ** s; + const char **s; for (s = dns; dns && *s; s++) { if (inet_pton(AF_INET6, *s, &tmp_addr) > 0) { if (!IN6_IS_ADDR_UNSPECIFIED(&tmp_addr)) { - nm_ip6_config_add_nameserver(ip6_config, &tmp_addr); + nm_l3_config_data_add_nameserver(l3cd, AF_INET6, &tmp_addr); _LOG2I(LOGD_DHCP6, iface, " nameserver '%s'", *s); } } else @@ -705,9 +697,9 @@ nm_dhcp_utils_ip6_config_from_options(NMDedupMultiIndex *multi_idx, str = g_hash_table_lookup(options, "dhcp6_domain_search"); if (str) - process_domain_search(iface, str, ip6_add_domain_search, ip6_config); + process_domain_search(AF_INET6, iface, str, l3cd); - return g_steal_pointer(&ip6_config); + return g_steal_pointer(&l3cd); } char * @@ -739,7 +731,7 @@ nm_dhcp_utils_client_id_string_to_bytes(const char *client_id) { GBytes *bytes = NULL; guint len; - char * c; + char *c; g_return_val_if_fail(client_id && client_id[0], NULL); @@ -784,7 +776,7 @@ nm_dhcp_utils_get_leasefile_path(int addr_family, const char *plugin_name, const char *iface, const char *uuid, - char ** out_leasefile_path) + char **out_leasefile_path) { gs_free char *rundir_path = NULL; gs_free char *statedir_path = NULL; @@ -838,6 +830,65 @@ nm_dhcp_utils_get_dhcp6_event_id(GHashTable *lease) return g_strdup_printf("%s|%s", iaid, start); } +gboolean +nm_dhcp_utils_merge_new_dhcp6_lease(const NML3ConfigData *l3cd_old, + const NML3ConfigData *l3cd_new, + const NML3ConfigData **out_l3cd_merged) +{ + nm_auto_unref_l3cd_init NML3ConfigData *l3cd_merged = NULL; + const NMPlatformIP6Address *addr; + NMDhcpLease *lease_old; + NMDhcpLease *lease_new; + NMDedupMultiIter iter; + const char *start; + const char *iaid; + + nm_assert(out_l3cd_merged); + nm_assert(!*out_l3cd_merged); + + if (!l3cd_old) + return FALSE; + if (!l3cd_new) + return FALSE; + + lease_new = nm_l3_config_data_get_dhcp_lease(l3cd_new, AF_INET6); + if (!lease_new) + return FALSE; + + lease_old = nm_l3_config_data_get_dhcp_lease(l3cd_old, AF_INET6); + if (!lease_old) + return FALSE; + + start = nm_dhcp_lease_lookup_option(lease_new, "life_starts"); + if (!start) + return FALSE; + iaid = nm_dhcp_lease_lookup_option(lease_new, "iaid"); + if (!iaid) + return FALSE; + + if (!nm_streq0(start, nm_dhcp_lease_lookup_option(lease_old, "life_starts"))) + return FALSE; + if (!nm_streq0(iaid, nm_dhcp_lease_lookup_option(lease_old, "iaid"))) + return FALSE; + + /* If the server sends multiple IPv6 addresses, we receive a state + * changed event for each of them. Use the event ID to merge IPv6 + * addresses from the same transaction into a single configuration. + **/ + + l3cd_merged = nm_l3_config_data_new_clone(l3cd_old, -1); + + nm_l3_config_data_iter_ip6_address_for_each (&iter, l3cd_new, &addr) + nm_l3_config_data_add_address_6(l3cd_merged, addr); + + /* FIXME(l3cfg): Note that we keep the original NMDhcpLease. All we take from the new lease are the + * addresses. Maybe this is not right and we should merge the leases too?? */ + nm_l3_config_data_set_dhcp_lease(l3cd_merged, AF_INET6, lease_old); + + *out_l3cd_merged = nm_l3_config_data_ref_and_seal(g_steal_pointer(&l3cd_merged)); + return TRUE; +} + /*****************************************************************************/ gboolean @@ -922,7 +973,7 @@ gboolean nm_dhcp_lease_data_parse_domain(const guint8 *data, gsize n_data, char **out_val) { gs_free char *str1_free = NULL; - const char * str1; + const char *str1; gs_free char *s = NULL; /* this is mostly the same as systemd's lease_parse_domain(). */ @@ -959,7 +1010,11 @@ nm_dhcp_lease_data_parse_in_addr(const guint8 *data, gsize n_data, in_addr_t *ou * - option 28, https://tools.ietf.org/html/rfc2132#section-5.3 */ - if (n_data != 4) + /* Some DHCP servers send duplicate options, and we concatenate them + * according to RFC 3396 section 7. Therefore, it's possible that a + * option carrying a IPv4 address has a length > 4. + */ + if (n_data < 4) return FALSE; *out_val = unaligned_read_ne32(data); @@ -1000,17 +1055,17 @@ lease_option_print_label(NMStrBuf *sbuf, size_t n_label, const uint8_t **datap, } static char * -lease_option_print_domain_name(const uint8_t * cache, - size_t * n_cachep, +lease_option_print_domain_name(const uint8_t *cache, + size_t *n_cachep, const uint8_t **datap, - size_t * n_datap) + size_t *n_datap) { nm_auto_str_buf NMStrBuf sbuf = NM_STR_BUF_INIT(NM_UTILS_GET_NEXT_REALLOC_SIZE_40, FALSE); - const uint8_t * domain; + const uint8_t *domain; size_t n_domain; size_t n_cache = *n_cachep; - const uint8_t ** domainp = datap; - size_t * n_domainp = n_datap; + const uint8_t **domainp = datap; + size_t *n_domainp = n_datap; gboolean first = TRUE; uint8_t c; @@ -1096,7 +1151,7 @@ lease_option_print_domain_name(const uint8_t * cache, char ** nm_dhcp_lease_data_parse_search_list(const guint8 *data, gsize n_data) { - GPtrArray * array = NULL; + GPtrArray *array = NULL; const guint8 *cache = data; gsize n_cache = 0; diff --git a/src/core/dhcp/nm-dhcp-utils.h b/src/core/dhcp/nm-dhcp-utils.h index 69715f90..bef50c52 100644 --- a/src/core/dhcp/nm-dhcp-utils.h +++ b/src/core/dhcp/nm-dhcp-utils.h @@ -8,21 +8,18 @@ #include -#include "nm-ip4-config.h" -#include "nm-ip6-config.h" - -NMIP4Config *nm_dhcp_utils_ip4_config_from_options(struct _NMDedupMultiIndex *multi_idx, - int ifindex, - const char * iface, - GHashTable * options, - guint32 route_table, - guint32 route_metric); - -NMIP6Config *nm_dhcp_utils_ip6_config_from_options(struct _NMDedupMultiIndex *multi_idx, - int ifindex, - const char * iface, - GHashTable * options, - gboolean info_only); +#include "nm-l3-config-data.h" + +NML3ConfigData *nm_dhcp_utils_ip4_config_from_options(struct _NMDedupMultiIndex *multi_idx, + int ifindex, + const char *iface, + GHashTable *options); + +NML3ConfigData *nm_dhcp_utils_ip6_config_from_options(struct _NMDedupMultiIndex *multi_idx, + int ifindex, + const char *iface, + GHashTable *options, + gboolean info_only); NMPlatformIP6Address nm_dhcp_utils_ip6_prefix_from_options(GHashTable *options); @@ -34,10 +31,14 @@ gboolean nm_dhcp_utils_get_leasefile_path(int addr_family, const char *plugin_name, const char *iface, const char *uuid, - char ** out_leasefile_path); + char **out_leasefile_path); char *nm_dhcp_utils_get_dhcp6_event_id(GHashTable *lease); +gboolean nm_dhcp_utils_merge_new_dhcp6_lease(const NML3ConfigData *l3cd_old, + const NML3ConfigData *l3cd_new, + const NML3ConfigData **out_l3cd_merged); + /*****************************************************************************/ static inline gboolean @@ -65,6 +66,6 @@ gboolean nm_dhcp_lease_data_parse_mtu(const guint8 *data, gsize n_data, guint16 gboolean nm_dhcp_lease_data_parse_cstr(const guint8 *data, gsize n_data, gsize *out_new_len); gboolean nm_dhcp_lease_data_parse_domain(const guint8 *data, gsize n_data, char **out_val); gboolean nm_dhcp_lease_data_parse_in_addr(const guint8 *data, gsize n_data, in_addr_t *out_val); -char ** nm_dhcp_lease_data_parse_search_list(const guint8 *data, gsize n_data); +char **nm_dhcp_lease_data_parse_search_list(const guint8 *data, gsize n_data); #endif /* __NETWORKMANAGER_DHCP_UTILS_H__ */ diff --git a/src/core/dhcp/tests/test-dhcp-dhclient.c b/src/core/dhcp/tests/test-dhcp-dhclient.c index 9c6865cc..aaa0dbc3 100644 --- a/src/core/dhcp/tests/test-dhcp-dhclient.c +++ b/src/core/dhcp/tests/test-dhcp-dhclient.c @@ -15,7 +15,6 @@ #include "dhcp/nm-dhcp-dhclient-utils.h" #include "dhcp/nm-dhcp-utils.h" #include "nm-utils.h" -#include "nm-ip4-config.h" #include "libnm-platform/nm-platform.h" #include "nm-test-utils-core.h" @@ -24,18 +23,18 @@ #define TEST_MUDURL "https://example.com/mud.json" static void -test_config(const char * orig, - const char * expected, +test_config(const char *orig, + const char *expected, int addr_family, - const char * hostname, + const char *hostname, guint32 timeout, gboolean use_fqdn, NMDhcpHostnameFlags hostname_flags, - const char * dhcp_client_id, - GBytes * expected_new_client_id, - const char * iface, - const char * anycast_addr, - const char * mud_url) + const char *dhcp_client_id, + GBytes *expected_new_client_id, + const char *iface, + const char *anycast_addr, + const char *mud_url) { gs_free char *new = NULL; gs_unref_bytes GBytes *client_id = NULL; @@ -826,7 +825,7 @@ test_one_duid(const char *escaped, const guint8 *unescaped, guint len) { gs_unref_bytes GBytes *t1 = NULL; gs_unref_bytes GBytes *t2 = NULL; - gs_free char * w = NULL; + gs_free char *w = NULL; t1 = nm_dhcp_dhclient_unescape_duid(escaped); g_assert(t1); @@ -874,7 +873,7 @@ test_read_duid_from_leasefile(void) const guint8 expected[] = {0x00, 0x01, 0x00, 0x01, 0x18, 0x79, 0xa6, 0x13, 0x60, 0x67, 0x20, 0xec, 0x4c, 0x70}; gs_unref_bytes GBytes *duid = NULL; - GError * error = NULL; + GError *error = NULL; duid = nm_dhcp_dhclient_read_duid(TEST_DIR "/test-dhclient-duid.leases", &error); nmtst_assert_success(duid, error); @@ -899,7 +898,7 @@ static void _save_duid(const char *path, const guint8 *duid_bin, gsize duid_len) { gs_unref_bytes GBytes *duid = NULL; - GError * error = NULL; + GError *error = NULL; gboolean success; g_assert(path); @@ -915,12 +914,12 @@ static void test_write_duid(void) { const guint8 duid[] = {000, 001, 000, 001, 027, 'X', 0350, 'X', 0, '#', 025, 010, '~', 0254}; - const char * expected_contents = + const char *expected_contents = "default-duid \"\\000\\001\\000\\001\\027X\\350X\\000#\\025\\010~\\254\";\n"; - GError * error = NULL; + GError *error = NULL; gs_free char *contents = NULL; gboolean success; - const char * path = "test-dhclient-write-duid.leases"; + const char *path = "test-dhclient-write-duid.leases"; _save_duid(path, duid, G_N_ELEMENTS(duid)); @@ -941,10 +940,10 @@ test_write_existing_duid(void) "default-duid \"\\000\\001\\000\\001\\027X\\350X\\000#\\025\\010~\\254\";\n"; const char *expected_contents = "default-duid \"\\000\\001\\000\\001\\023o\\023n\\000\\\"\\372\\214\\326\\302\";\n"; - GError * error = NULL; + GError *error = NULL; gs_free char *contents = NULL; gboolean success; - const char * path = "test-dhclient-write-existing-duid.leases"; + const char *path = "test-dhclient-write-existing-duid.leases"; success = g_file_set_contents(path, original_contents, -1, &error); nmtst_assert_success(success, error); @@ -968,11 +967,11 @@ static void test_write_existing_commented_duid(void) { #define ORIG_CONTENTS "#default-duid \"\\000\\001\\000\\001\\027X\\350X\\000#\\025\\010~\\254\";\n" - const char * expected_contents = "default-duid \"" DUID "\";\n" ORIG_CONTENTS; - GError * error = NULL; + const char *expected_contents = "default-duid \"" DUID "\";\n" ORIG_CONTENTS; + GError *error = NULL; gs_free char *contents = NULL; gboolean success; - const char * path = "test-dhclient-write-existing-commented-duid.leases"; + const char *path = "test-dhclient-write-existing-commented-duid.leases"; success = g_file_set_contents(path, ORIG_CONTENTS, -1, &error); nmtst_assert_success(success, error); @@ -995,9 +994,9 @@ test_write_existing_multiline_duid(void) #define ORIG_CONTENTS \ "### Commented old DUID ###\n" \ "#default-duid \"\\000\\001\\000\\001\\027X\\350X\\000#\\025\\010~\\254\";\n" - const char * expected_contents = "default-duid \"" DUID "\";\n" ORIG_CONTENTS; - GError * error = NULL; - gs_free char * contents = NULL; + const char *expected_contents = "default-duid \"" DUID "\";\n" ORIG_CONTENTS; + GError *error = NULL; + gs_free char *contents = NULL; gboolean success; nmtst_auto_unlinkfile char *path = g_strdup("test-dhclient-write-existing-multiline-duid.leases"); diff --git a/src/core/dhcp/tests/test-dhcp-utils.c b/src/core/dhcp/tests/test-dhcp-utils.c index 4d47e7e2..f021b642 100644 --- a/src/core/dhcp/tests/test-dhcp-utils.c +++ b/src/core/dhcp/tests/test-dhcp-utils.c @@ -20,20 +20,18 @@ /*****************************************************************************/ -static NMIP4Config * -_ip4_config_from_options(int ifindex, const char *iface, GHashTable *options, guint32 route_metric) +static const NML3ConfigData * +_ip4_config_from_options(int ifindex, const char *iface, GHashTable *options) { nm_auto_unref_dedup_multi_index NMDedupMultiIndex *multi_idx = nm_dedup_multi_index_new(); - NMIP4Config * config; - - config = nm_dhcp_utils_ip4_config_from_options(multi_idx, - ifindex, - iface, - options, - RT_TABLE_MAIN, - route_metric); - g_assert(config); - return config; + NML3ConfigData *l3cd; + + l3cd = nm_dhcp_utils_ip4_config_from_options(multi_idx, ifindex, iface, options); + g_assert(NM_IS_L3_CONFIG_DATA(l3cd)); + g_assert(!nm_l3_config_data_is_sealed(l3cd)); + if (nmtst_get_rand_bool()) + nm_l3_config_data_seal(l3cd); + return l3cd; } typedef struct { @@ -74,58 +72,57 @@ static const Option generic_options[] = { static void test_generic_options(void) { - GHashTable * options; - gs_unref_object NMIP4Config *ip4_config = NULL; - const NMPlatformIP4Address * address; - const NMPlatformIP4Route * route; - guint32 tmp; - const char * expected_addr = "192.168.1.106"; - const char * expected_gw = "192.168.1.1"; - const char * expected_dns1 = "216.254.95.2"; - const char * expected_dns2 = "216.231.41.2"; - const char * expected_search1 = "foobar.com"; - const char * expected_search2 = "blah.foobar.com"; - const char * expected_route1_dest = "10.1.1.5"; - const char * expected_route1_gw = "10.1.1.1"; - const char * expected_route2_dest = "100.99.88.56"; - const char * expected_route2_gw = "10.1.1.1"; - - options = fill_table(generic_options, NULL); - ip4_config = _ip4_config_from_options(1, "eth0", options, 0); - - /* IP4 address */ - g_assert_cmpint(nm_ip4_config_get_num_addresses(ip4_config), ==, 1); - address = _nmtst_ip4_config_get_address(ip4_config, 0); + gs_unref_hashtable GHashTable *options = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; + const NMPlatformIP4Address *address; + const NMPlatformIP4Route *route; + guint32 tmp; + const char *expected_addr = "192.168.1.106"; + const char *expected_gw = "192.168.1.1"; + const char *expected_dns1 = "216.254.95.2"; + const char *expected_dns2 = "216.231.41.2"; + const char *expected_search1 = "foobar.com"; + const char *expected_search2 = "blah.foobar.com"; + const char *expected_route1_dest = "10.1.1.5"; + const char *expected_route1_gw = "10.1.1.1"; + const char *expected_route2_dest = "100.99.88.56"; + const char *expected_route2_gw = "10.1.1.1"; + const char *const *strarr; + const in_addr_t *ia_arr; + guint u; + + options = fill_table(generic_options, NULL); + l3cd = _ip4_config_from_options(1, "eth0", options); + + g_assert_cmpint(nm_l3_config_data_get_num_addresses(l3cd, AF_INET), ==, 1); + address = nmtst_l3_config_data_get_address_at_4(l3cd, 0); g_assert(inet_pton(AF_INET, expected_addr, &tmp) > 0); g_assert(address->address == tmp); g_assert(address->peer_address == tmp); g_assert_cmpint(address->plen, ==, 24); - /* Gateway */ - g_assert(inet_pton(AF_INET, expected_gw, &tmp) > 0); - g_assert(nmtst_ip4_config_get_gateway(ip4_config) == tmp); + nmtst_assert_ip_address(AF_INET, + nmtst_l3_config_data_get_best_gateway(l3cd, AF_INET), + expected_gw); - g_assert_cmpint(nm_ip4_config_get_num_wins(ip4_config), ==, 0); + g_assert(!nm_l3_config_data_get_wins(l3cd, &u)); + g_assert_cmpint(u, ==, 0); - g_assert_cmpint(nm_ip4_config_get_mtu(ip4_config), ==, 987); + g_assert_cmpint(nm_l3_config_data_get_mtu(l3cd), ==, 987); - /* Domain searches */ - g_assert_cmpint(nm_ip4_config_get_num_searches(ip4_config), ==, 2); - g_assert_cmpstr(nm_ip4_config_get_search(ip4_config, 0), ==, expected_search1); - g_assert_cmpstr(nm_ip4_config_get_search(ip4_config, 1), ==, expected_search2); + strarr = nm_l3_config_data_get_searches(l3cd, AF_INET, &u); + g_assert_cmpint(u, ==, 2); + g_assert_cmpstr(strarr[0], ==, expected_search1); + g_assert_cmpstr(strarr[1], ==, expected_search2); - /* DNS servers */ - g_assert_cmpint(nm_ip4_config_get_num_nameservers(ip4_config), ==, 2); - g_assert(inet_pton(AF_INET, expected_dns1, &tmp) > 0); - g_assert(nm_ip4_config_get_nameserver(ip4_config, 0) == tmp); - g_assert(inet_pton(AF_INET, expected_dns2, &tmp) > 0); - g_assert(nm_ip4_config_get_nameserver(ip4_config, 1) == tmp); + ia_arr = nm_l3_config_data_get_nameservers(l3cd, AF_INET, &u); + g_assert_cmpint(u, ==, 2); + nmtst_assert_ip4_address(ia_arr[0], expected_dns1); + nmtst_assert_ip4_address(ia_arr[1], expected_dns2); - /* Routes */ - g_assert_cmpint(nm_ip4_config_get_num_routes(ip4_config), ==, 3); + g_assert_cmpint(nm_l3_config_data_get_num_routes(l3cd, AF_INET), ==, 3); - /* Route #1 */ - route = _nmtst_ip4_config_get_route(ip4_config, 0); + route = nmtst_l3_config_data_get_route_at_4(l3cd, 0); g_assert(inet_pton(AF_INET, expected_route1_dest, &tmp) > 0); g_assert(route->network == tmp); g_assert(inet_pton(AF_INET, expected_route1_gw, &tmp) > 0); @@ -133,76 +130,70 @@ test_generic_options(void) g_assert_cmpint(route->plen, ==, 32); g_assert_cmpint(route->metric, ==, 0); - /* Route #2 */ - route = _nmtst_ip4_config_get_route(ip4_config, 1); + route = nmtst_l3_config_data_get_route_at_4(l3cd, 1); g_assert(route->network == nmtst_inet4_from_string(expected_route2_dest)); g_assert(route->gateway == nmtst_inet4_from_string(expected_route2_gw)); g_assert_cmpint(route->plen, ==, 32); g_assert_cmpint(route->metric, ==, 0); - route = _nmtst_ip4_config_get_route(ip4_config, 2); + route = nmtst_l3_config_data_get_route_at_4(l3cd, 2); g_assert(route->network == nmtst_inet4_from_string("0.0.0.0")); g_assert(route->gateway == nmtst_inet4_from_string("192.168.1.1")); g_assert_cmpint(route->plen, ==, 0); g_assert_cmpint(route->metric, ==, 0); - - g_hash_table_destroy(options); } static void test_wins_options(void) { - GHashTable * options; - gs_unref_object NMIP4Config *ip4_config = NULL; - const NMPlatformIP4Address * address; - guint32 tmp; - const char * expected_wins1 = "63.12.199.5"; - const char * expected_wins2 = "150.4.88.120"; - static const Option data[] = {{"netbios_name_servers", "63.12.199.5 150.4.88.120"}, + gs_unref_hashtable GHashTable *options = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; + const NMPlatformIP4Address *address; + const char *expected_wins1 = "63.12.199.5"; + const char *expected_wins2 = "150.4.88.120"; + static const Option data[] = {{"netbios_name_servers", "63.12.199.5 150.4.88.120"}, {NULL, NULL}}; + const in_addr_t *ia_arr; + guint u; - options = fill_table(generic_options, NULL); - options = fill_table(data, options); - ip4_config = _ip4_config_from_options(1, "eth0", options, 0); + options = fill_table(generic_options, NULL); + options = fill_table(data, options); + l3cd = _ip4_config_from_options(1, "eth0", options); - /* IP4 address */ - g_assert_cmpint(nm_ip4_config_get_num_addresses(ip4_config), ==, 1); - address = _nmtst_ip4_config_get_address(ip4_config, 0); + g_assert_cmpint(nm_l3_config_data_get_num_addresses(l3cd, AF_INET), ==, 1); + address = nmtst_l3_config_data_get_address_at_4(l3cd, 0); g_assert(address); - g_assert_cmpint(nm_ip4_config_get_num_wins(ip4_config), ==, 2); - g_assert(inet_pton(AF_INET, expected_wins1, &tmp) > 0); - g_assert(nm_ip4_config_get_wins(ip4_config, 0) == tmp); - g_assert(inet_pton(AF_INET, expected_wins2, &tmp) > 0); - g_assert(nm_ip4_config_get_wins(ip4_config, 1) == tmp); - g_hash_table_destroy(options); + ia_arr = nm_l3_config_data_get_wins(l3cd, &u); + g_assert_cmpint(u, ==, 2); + nmtst_assert_ip4_address(ia_arr[0], expected_wins1); + nmtst_assert_ip4_address(ia_arr[1], expected_wins2); } static void test_vendor_option_metered(void) { - GHashTable * options; - gs_unref_object NMIP4Config *ip4_config = NULL; + gs_unref_hashtable GHashTable *options = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; static const Option data[] = {{"vendor_encapsulated_options", "ANDROID_METERED"}, {NULL, NULL}}; - options = fill_table(generic_options, NULL); - ip4_config = _ip4_config_from_options(1, "eth0", options, 0); - g_assert(nm_ip4_config_get_metered(ip4_config) == FALSE); - g_hash_table_destroy(options); - g_clear_object(&ip4_config); - - options = fill_table(generic_options, NULL); - options = fill_table(data, options); - ip4_config = _ip4_config_from_options(1, "eth0", options, 0); - g_assert(nm_ip4_config_get_metered(ip4_config) == TRUE); - g_hash_table_destroy(options); + options = fill_table(generic_options, NULL); + l3cd = _ip4_config_from_options(1, "eth0", options); + g_assert(nm_l3_config_data_get_metered(l3cd) == NM_TERNARY_DEFAULT); + nm_clear_pointer(&options, g_hash_table_destroy); + nm_clear_l3cd(&l3cd); + + options = fill_table(generic_options, NULL); + options = fill_table(data, options); + l3cd = _ip4_config_from_options(1, "eth0", options); + g_assert(nm_l3_config_data_get_metered(l3cd) == TRUE); } static void test_parse_search_list(void) { guint8 *data; - char ** domains; + char **domains; data = (guint8[]){0x05, 'l', 'o', 'c', 'a', 'l', 0x00}; domains = nm_dhcp_lease_data_parse_search_list(data, 7); @@ -252,18 +243,18 @@ test_parse_search_list(void) } static void -ip4_test_route(NMIP4Config *ip4_config, - guint route_num, - const char * expected_dest, - const char * expected_gw, - guint expected_prefix) +ip4_test_route(const NML3ConfigData *l3cd, + guint route_num, + const char *expected_dest, + const char *expected_gw, + guint expected_prefix) { const NMPlatformIP4Route *route; guint32 tmp; g_assert(expected_prefix <= 32); - route = _nmtst_ip4_config_get_route(ip4_config, route_num); + route = nmtst_l3_config_data_get_route_at_4(l3cd, route_num); g_assert(inet_pton(AF_INET, expected_dest, &tmp) > 0); g_assert(route->network == tmp); g_assert(inet_pton(AF_INET, expected_gw, &tmp) > 0); @@ -272,110 +263,105 @@ ip4_test_route(NMIP4Config *ip4_config, g_assert_cmpint(route->metric, ==, 0); } -static void -ip4_test_gateway(NMIP4Config *ip4_config, const char *expected_gw) -{ - guint32 tmp; - - g_assert_cmpint(nm_ip4_config_get_num_addresses(ip4_config), ==, 1); - g_assert(inet_pton(AF_INET, expected_gw, &tmp) > 0); - g_assert(nmtst_ip4_config_get_gateway(ip4_config) == tmp); -} +#define ip4_test_gateway(l3cd, expected_gw) \ + G_STMT_START \ + { \ + const NML3ConfigData *_l3cd = (l3cd); \ + \ + g_assert_cmpint(nm_l3_config_data_get_num_addresses(_l3cd, AF_INET), ==, 1); \ + nmtst_assert_ip_address(AF_INET, \ + nmtst_l3_config_data_get_best_gateway(_l3cd, AF_INET), \ + expected_gw); \ + } \ + G_STMT_END static void test_classless_static_routes_1(void) { - GHashTable * options; - gs_unref_object NMIP4Config *ip4_config = NULL; - const char * expected_route1_dest = "192.168.10.0"; - const char * expected_route1_gw = "192.168.1.1"; - const char * expected_route2_dest = "10.0.0.0"; - const char * expected_route2_gw = "10.17.66.41"; - static const Option data[] = { + gs_unref_hashtable GHashTable *options = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; + const char *expected_route1_dest = "192.168.10.0"; + const char *expected_route1_gw = "192.168.1.1"; + const char *expected_route2_dest = "10.0.0.0"; + const char *expected_route2_gw = "10.17.66.41"; + static const Option data[] = { /* dhclient custom format */ {"rfc3442_classless_static_routes", "24 192 168 10 192 168 1 1 8 10 10 17 66 41"}, {NULL, NULL}}; - options = fill_table(generic_options, NULL); - options = fill_table(data, options); - ip4_config = _ip4_config_from_options(1, "eth0", options, 0); + options = fill_table(generic_options, NULL); + options = fill_table(data, options); + l3cd = _ip4_config_from_options(1, "eth0", options); /* IP4 routes */ - g_assert_cmpint(nm_ip4_config_get_num_routes(ip4_config), ==, 3); - ip4_test_route(ip4_config, 0, expected_route1_dest, expected_route1_gw, 24); - ip4_test_route(ip4_config, 1, expected_route2_dest, expected_route2_gw, 8); - ip4_test_route(ip4_config, 2, "0.0.0.0", "192.168.1.1", 0); - - g_hash_table_destroy(options); + g_assert_cmpint(nm_l3_config_data_get_num_routes(l3cd, AF_INET), ==, 3); + ip4_test_route(l3cd, 0, expected_route1_dest, expected_route1_gw, 24); + ip4_test_route(l3cd, 1, expected_route2_dest, expected_route2_gw, 8); + ip4_test_route(l3cd, 2, "0.0.0.0", "192.168.1.1", 0); } static void test_classless_static_routes_2(void) { - GHashTable * options; - gs_unref_object NMIP4Config *ip4_config = NULL; - const char * expected_route1_dest = "192.168.10.0"; - const char * expected_route1_gw = "192.168.1.1"; - const char * expected_route2_dest = "10.0.0.0"; - const char * expected_route2_gw = "10.17.66.41"; - static const Option data[] = { + gs_unref_hashtable GHashTable *options = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; + const char *expected_route1_dest = "192.168.10.0"; + const char *expected_route1_gw = "192.168.1.1"; + const char *expected_route2_dest = "10.0.0.0"; + const char *expected_route2_gw = "10.17.66.41"; + static const Option data[] = { /* dhcpcd format */ {"classless_static_routes", "192.168.10.0/24 192.168.1.1 10.0.0.0/8 10.17.66.41"}, {NULL, NULL}}; - options = fill_table(generic_options, NULL); - options = fill_table(data, options); - ip4_config = _ip4_config_from_options(1, "eth0", options, 0); + options = fill_table(generic_options, NULL); + options = fill_table(data, options); + l3cd = _ip4_config_from_options(1, "eth0", options); /* IP4 routes */ - g_assert_cmpint(nm_ip4_config_get_num_routes(ip4_config), ==, 3); - ip4_test_route(ip4_config, 0, expected_route1_dest, expected_route1_gw, 24); - ip4_test_route(ip4_config, 1, expected_route2_dest, expected_route2_gw, 8); - ip4_test_route(ip4_config, 2, "0.0.0.0", expected_route1_gw, 0); - - g_hash_table_destroy(options); + g_assert_cmpint(nm_l3_config_data_get_num_routes(l3cd, AF_INET), ==, 3); + ip4_test_route(l3cd, 0, expected_route1_dest, expected_route1_gw, 24); + ip4_test_route(l3cd, 1, expected_route2_dest, expected_route2_gw, 8); + ip4_test_route(l3cd, 2, "0.0.0.0", expected_route1_gw, 0); } static void test_fedora_dhclient_classless_static_routes(void) { - GHashTable * options; - gs_unref_object NMIP4Config *ip4_config = NULL; - const char * expected_route1_dest = "129.210.177.128"; - const char * expected_route1_gw = "192.168.0.113"; - const char * expected_route2_dest = "2.0.0.0"; - const char * expected_route2_gw = "10.34.255.6"; - const char * expected_gateway = "192.168.0.113"; - static const Option data[] = { + gs_unref_hashtable GHashTable *options = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; + const char *expected_route1_dest = "129.210.177.128"; + const char *expected_route1_gw = "192.168.0.113"; + const char *expected_route2_dest = "2.0.0.0"; + const char *expected_route2_gw = "10.34.255.6"; + const char *expected_gateway = "192.168.0.113"; + static const Option data[] = { /* Fedora dhclient format */ {"classless_static_routes", "0 192.168.0.113 25.129.210.177.132 192.168.0.113 7.2 10.34.255.6"}, {NULL, NULL}}; - options = fill_table(generic_options, NULL); - options = fill_table(data, options); - ip4_config = _ip4_config_from_options(1, "eth0", options, 0); + options = fill_table(generic_options, NULL); + options = fill_table(data, options); + l3cd = _ip4_config_from_options(1, "eth0", options); /* IP4 routes */ - g_assert_cmpint(nm_ip4_config_get_num_routes(ip4_config), ==, 3); - ip4_test_route(ip4_config, 0, expected_route1_dest, expected_route1_gw, 25); - ip4_test_route(ip4_config, 1, expected_route2_dest, expected_route2_gw, 7); - ip4_test_route(ip4_config, 2, "0.0.0.0", expected_route1_gw, 0); + g_assert_cmpint(nm_l3_config_data_get_num_routes(l3cd, AF_INET), ==, 3); + ip4_test_route(l3cd, 0, expected_route1_dest, expected_route1_gw, 25); + ip4_test_route(l3cd, 1, expected_route2_dest, expected_route2_gw, 7); + ip4_test_route(l3cd, 2, "0.0.0.0", expected_route1_gw, 0); - /* Gateway */ - ip4_test_gateway(ip4_config, expected_gateway); - - g_hash_table_destroy(options); + ip4_test_gateway(l3cd, expected_gateway); } static void test_dhclient_invalid_classless_routes_1(void) { - GHashTable * options; - gs_unref_object NMIP4Config *ip4_config = NULL; - const char * expected_route1_dest = "192.168.10.0"; - const char * expected_route1_gw = "192.168.1.1"; - static const Option data[] = { + gs_unref_hashtable GHashTable *options = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; + const char *expected_route1_dest = "192.168.10.0"; + const char *expected_route1_gw = "192.168.1.1"; + static const Option data[] = { /* dhclient format */ {"rfc3442_classless_static_routes", "24 192 168 10 192 168 1 1 45 10 17 66 41"}, {NULL, NULL}}; @@ -384,27 +370,25 @@ test_dhclient_invalid_classless_routes_1(void) options = fill_table(data, options); NMTST_EXPECT_NM_WARN("*ignoring invalid classless static routes*"); - ip4_config = _ip4_config_from_options(1, "eth0", options, 0); + l3cd = _ip4_config_from_options(1, "eth0", options); g_test_assert_expected_messages(); /* IP4 routes */ - g_assert_cmpint(nm_ip4_config_get_num_routes(ip4_config), ==, 2); - ip4_test_route(ip4_config, 0, expected_route1_dest, expected_route1_gw, 24); - ip4_test_route(ip4_config, 1, "0.0.0.0", expected_route1_gw, 0); - - g_hash_table_destroy(options); + g_assert_cmpint(nm_l3_config_data_get_num_routes(l3cd, AF_INET), ==, 2); + ip4_test_route(l3cd, 0, expected_route1_dest, expected_route1_gw, 24); + ip4_test_route(l3cd, 1, "0.0.0.0", expected_route1_gw, 0); } static void test_dhcpcd_invalid_classless_routes_1(void) { - GHashTable * options; - gs_unref_object NMIP4Config *ip4_config = NULL; - const char * expected_route1_dest = "10.1.1.5"; - const char * expected_route1_gw = "10.1.1.1"; - const char * expected_route2_dest = "100.99.88.56"; - const char * expected_route2_gw = "10.1.1.1"; - static const Option data[] = { + gs_unref_hashtable GHashTable *options = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; + const char *expected_route1_dest = "10.1.1.5"; + const char *expected_route1_gw = "10.1.1.1"; + const char *expected_route2_dest = "100.99.88.56"; + const char *expected_route2_gw = "10.1.1.1"; + static const Option data[] = { /* dhcpcd format */ {"classless_static_routes", "192.168.10.0/24 192.168.1.1 10.0.adfadf/44 10.17.66.41"}, {NULL, NULL}}; @@ -413,30 +397,28 @@ test_dhcpcd_invalid_classless_routes_1(void) options = fill_table(data, options); NMTST_EXPECT_NM_WARN("*ignoring invalid classless static routes*"); - ip4_config = _ip4_config_from_options(1, "eth0", options, 0); + l3cd = _ip4_config_from_options(1, "eth0", options); g_test_assert_expected_messages(); /* Test falling back to old-style static routes if the classless static * routes are invalid. */ - g_assert_cmpint(nm_ip4_config_get_num_routes(ip4_config), ==, 3); - ip4_test_route(ip4_config, 0, expected_route1_dest, expected_route1_gw, 32); - ip4_test_route(ip4_config, 1, expected_route2_dest, expected_route2_gw, 32); - ip4_test_route(ip4_config, 2, "0.0.0.0", "192.168.1.1", 0); - - g_hash_table_destroy(options); + g_assert_cmpint(nm_l3_config_data_get_num_routes(l3cd, AF_INET), ==, 3); + ip4_test_route(l3cd, 0, expected_route1_dest, expected_route1_gw, 32); + ip4_test_route(l3cd, 1, expected_route2_dest, expected_route2_gw, 32); + ip4_test_route(l3cd, 2, "0.0.0.0", "192.168.1.1", 0); } static void test_dhclient_invalid_classless_routes_2(void) { - GHashTable * options; - gs_unref_object NMIP4Config *ip4_config = NULL; - const char * expected_route1_dest = "10.1.1.5"; - const char * expected_route1_gw = "10.1.1.1"; - const char * expected_route2_dest = "100.99.88.56"; - const char * expected_route2_gw = "10.1.1.1"; - static const Option data[] = { + gs_unref_hashtable GHashTable *options = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; + const char *expected_route1_dest = "10.1.1.5"; + const char *expected_route1_gw = "10.1.1.1"; + const char *expected_route2_dest = "100.99.88.56"; + const char *expected_route2_gw = "10.1.1.1"; + static const Option data[] = { {"rfc3442_classless_static_routes", "45 10 17 66 41 24 192 168 10 192 168 1 1"}, {NULL, NULL}}; @@ -444,30 +426,28 @@ test_dhclient_invalid_classless_routes_2(void) options = fill_table(data, options); NMTST_EXPECT_NM_WARN("*ignoring invalid classless static routes*"); - ip4_config = _ip4_config_from_options(1, "eth0", options, 0); + l3cd = _ip4_config_from_options(1, "eth0", options); g_test_assert_expected_messages(); /* Test falling back to old-style static routes if the classless static * routes are invalid. */ - g_assert_cmpint(nm_ip4_config_get_num_routes(ip4_config), ==, 3); - ip4_test_route(ip4_config, 0, expected_route1_dest, expected_route1_gw, 32); - ip4_test_route(ip4_config, 1, expected_route2_dest, expected_route2_gw, 32); - ip4_test_route(ip4_config, 2, "0.0.0.0", "192.168.1.1", 0); - - g_hash_table_destroy(options); + g_assert_cmpint(nm_l3_config_data_get_num_routes(l3cd, AF_INET), ==, 3); + ip4_test_route(l3cd, 0, expected_route1_dest, expected_route1_gw, 32); + ip4_test_route(l3cd, 1, expected_route2_dest, expected_route2_gw, 32); + ip4_test_route(l3cd, 2, "0.0.0.0", "192.168.1.1", 0); } static void test_dhcpcd_invalid_classless_routes_2(void) { - GHashTable * options; - gs_unref_object NMIP4Config *ip4_config = NULL; - const char * expected_route1_dest = "10.1.1.5"; - const char * expected_route1_gw = "10.1.1.1"; - const char * expected_route2_dest = "100.99.88.56"; - const char * expected_route2_gw = "10.1.1.1"; - static const Option data[] = { + gs_unref_hashtable GHashTable *options = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; + const char *expected_route1_dest = "10.1.1.5"; + const char *expected_route1_gw = "10.1.1.1"; + const char *expected_route2_dest = "100.99.88.56"; + const char *expected_route2_gw = "10.1.1.1"; + static const Option data[] = { {"classless_static_routes", "10.0.adfadf/44 10.17.66.41 192.168.10.0/24 192.168.1.1"}, {NULL, NULL}}; @@ -475,7 +455,7 @@ test_dhcpcd_invalid_classless_routes_2(void) options = fill_table(data, options); NMTST_EXPECT_NM_WARN("*ignoring invalid classless static routes*"); - ip4_config = _ip4_config_from_options(1, "eth0", options, 0); + l3cd = _ip4_config_from_options(1, "eth0", options); g_test_assert_expected_messages(); /* Test falling back to old-style static routes if the classless static @@ -483,22 +463,20 @@ test_dhcpcd_invalid_classless_routes_2(void) */ /* Routes */ - g_assert_cmpint(nm_ip4_config_get_num_routes(ip4_config), ==, 3); - ip4_test_route(ip4_config, 0, expected_route1_dest, expected_route1_gw, 32); - ip4_test_route(ip4_config, 1, expected_route2_dest, expected_route2_gw, 32); - ip4_test_route(ip4_config, 2, "0.0.0.0", "192.168.1.1", 0); - - g_hash_table_destroy(options); + g_assert_cmpint(nm_l3_config_data_get_num_routes(l3cd, AF_INET), ==, 3); + ip4_test_route(l3cd, 0, expected_route1_dest, expected_route1_gw, 32); + ip4_test_route(l3cd, 1, expected_route2_dest, expected_route2_gw, 32); + ip4_test_route(l3cd, 2, "0.0.0.0", "192.168.1.1", 0); } static void test_dhclient_invalid_classless_routes_3(void) { - GHashTable * options; - gs_unref_object NMIP4Config *ip4_config = NULL; - const char * expected_route1_dest = "192.168.10.0"; - const char * expected_route1_gw = "192.168.1.1"; - static const Option data[] = { + gs_unref_hashtable GHashTable *options = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; + const char *expected_route1_dest = "192.168.10.0"; + const char *expected_route1_gw = "192.168.1.1"; + static const Option data[] = { {"rfc3442_classless_static_routes", "24 192 168 10 192 168 1 1 32 128 10 17 66 41"}, {NULL, NULL}}; @@ -506,25 +484,23 @@ test_dhclient_invalid_classless_routes_3(void) options = fill_table(data, options); NMTST_EXPECT_NM_WARN("*ignoring invalid classless static routes*"); - ip4_config = _ip4_config_from_options(1, "eth0", options, 0); + l3cd = _ip4_config_from_options(1, "eth0", options); g_test_assert_expected_messages(); /* IP4 routes */ - g_assert_cmpint(nm_ip4_config_get_num_routes(ip4_config), ==, 2); - ip4_test_route(ip4_config, 0, expected_route1_dest, expected_route1_gw, 24); - ip4_test_route(ip4_config, 1, "0.0.0.0", expected_route1_gw, 0); - - g_hash_table_destroy(options); + g_assert_cmpint(nm_l3_config_data_get_num_routes(l3cd, AF_INET), ==, 2); + ip4_test_route(l3cd, 0, expected_route1_dest, expected_route1_gw, 24); + ip4_test_route(l3cd, 1, "0.0.0.0", expected_route1_gw, 0); } static void test_dhcpcd_invalid_classless_routes_3(void) { - GHashTable * options; - gs_unref_object NMIP4Config *ip4_config = NULL; - const char * expected_route1_dest = "192.168.10.0"; - const char * expected_route1_gw = "192.168.1.1"; - static Option data[] = { + gs_unref_hashtable GHashTable *options = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; + const char *expected_route1_dest = "192.168.10.0"; + const char *expected_route1_gw = "192.168.1.1"; + static Option data[] = { {"classless_static_routes", "192.168.10.0/24 192.168.1.1 128/32 10.17.66.41"}, {NULL, NULL}}; @@ -532,133 +508,124 @@ test_dhcpcd_invalid_classless_routes_3(void) options = fill_table(data, options); NMTST_EXPECT_NM_WARN("*DHCP provided invalid classless static route*"); - ip4_config = _ip4_config_from_options(1, "eth0", options, 0); + l3cd = _ip4_config_from_options(1, "eth0", options); g_test_assert_expected_messages(); /* IP4 routes */ - g_assert_cmpint(nm_ip4_config_get_num_routes(ip4_config), ==, 2); - ip4_test_route(ip4_config, 0, expected_route1_dest, expected_route1_gw, 24); - ip4_test_route(ip4_config, 1, "0.0.0.0", expected_route1_gw, 0); - - g_hash_table_destroy(options); + g_assert_cmpint(nm_l3_config_data_get_num_routes(l3cd, AF_INET), ==, 2); + ip4_test_route(l3cd, 0, expected_route1_dest, expected_route1_gw, 24); + ip4_test_route(l3cd, 1, "0.0.0.0", expected_route1_gw, 0); } static void test_dhclient_gw_in_classless_routes(void) { - GHashTable * options; - gs_unref_object NMIP4Config *ip4_config = NULL; - const char * expected_route1_dest = "192.168.10.0"; - const char * expected_route1_gw = "192.168.1.1"; - const char * expected_gateway = "192.2.3.4"; - static Option data[] = { + gs_unref_hashtable GHashTable *options = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; + const char *expected_route1_dest = "192.168.10.0"; + const char *expected_route1_gw = "192.168.1.1"; + const char *expected_gateway = "192.2.3.4"; + static Option data[] = { {"rfc3442_classless_static_routes", "24 192 168 10 192 168 1 1 0 192 2 3 4"}, {NULL, NULL}}; - options = fill_table(generic_options, NULL); - options = fill_table(data, options); - ip4_config = _ip4_config_from_options(1, "eth0", options, 0); + options = fill_table(generic_options, NULL); + options = fill_table(data, options); + l3cd = _ip4_config_from_options(1, "eth0", options); /* IP4 routes */ - g_assert_cmpint(nm_ip4_config_get_num_routes(ip4_config), ==, 2); - ip4_test_route(ip4_config, 0, expected_route1_dest, expected_route1_gw, 24); - ip4_test_route(ip4_config, 1, "0.0.0.0", "192.2.3.4", 0); - - /* Gateway */ - ip4_test_gateway(ip4_config, expected_gateway); + g_assert_cmpint(nm_l3_config_data_get_num_routes(l3cd, AF_INET), ==, 2); + ip4_test_route(l3cd, 0, expected_route1_dest, expected_route1_gw, 24); + ip4_test_route(l3cd, 1, "0.0.0.0", "192.2.3.4", 0); - g_hash_table_destroy(options); + ip4_test_gateway(l3cd, expected_gateway); } static void test_dhcpcd_gw_in_classless_routes(void) { - GHashTable * options; - gs_unref_object NMIP4Config *ip4_config = NULL; - const char * expected_route1_dest = "192.168.10.0"; - const char * expected_route1_gw = "192.168.1.1"; - const char * expected_gateway = "192.2.3.4"; - static Option data[] = { + gs_unref_hashtable GHashTable *options = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; + const char *expected_route1_dest = "192.168.10.0"; + const char *expected_route1_gw = "192.168.1.1"; + const char *expected_gateway = "192.2.3.4"; + static Option data[] = { {"classless_static_routes", "192.168.10.0/24 192.168.1.1 0.0.0.0/0 192.2.3.4"}, {NULL, NULL}}; - options = fill_table(generic_options, NULL); - options = fill_table(data, options); - ip4_config = _ip4_config_from_options(1, "eth0", options, 0); + options = fill_table(generic_options, NULL); + options = fill_table(data, options); + l3cd = _ip4_config_from_options(1, "eth0", options); /* IP4 routes */ - g_assert_cmpint(nm_ip4_config_get_num_routes(ip4_config), ==, 2); - ip4_test_route(ip4_config, 0, expected_route1_dest, expected_route1_gw, 24); - ip4_test_route(ip4_config, 1, "0.0.0.0", "192.2.3.4", 0); - - /* Gateway */ - ip4_test_gateway(ip4_config, expected_gateway); + g_assert_cmpint(nm_l3_config_data_get_num_routes(l3cd, AF_INET), ==, 2); + ip4_test_route(l3cd, 0, expected_route1_dest, expected_route1_gw, 24); + ip4_test_route(l3cd, 1, "0.0.0.0", "192.2.3.4", 0); - g_hash_table_destroy(options); + ip4_test_gateway(l3cd, expected_gateway); } static void test_escaped_domain_searches(void) { - GHashTable * options; - gs_unref_object NMIP4Config *ip4_config = NULL; - const char * expected_search0 = "host1"; - const char * expected_search1 = "host2"; - const char * expected_search2 = "host3"; + gs_unref_hashtable GHashTable *options = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; + const char *expected_search0 = "host1"; + const char *expected_search1 = "host2"; + const char *expected_search2 = "host3"; static const Option data[] = {{"domain_search", "host1\\032host2\\032host3"}, {NULL, NULL}}; + const char *const *strarr; + guint u; - options = fill_table(generic_options, NULL); - options = fill_table(data, options); - ip4_config = _ip4_config_from_options(1, "eth0", options, 0); - - /* domain searches */ - g_assert_cmpint(nm_ip4_config_get_num_searches(ip4_config), ==, 3); - g_assert_cmpstr(nm_ip4_config_get_search(ip4_config, 0), ==, expected_search0); - g_assert_cmpstr(nm_ip4_config_get_search(ip4_config, 1), ==, expected_search1); - g_assert_cmpstr(nm_ip4_config_get_search(ip4_config, 2), ==, expected_search2); + options = fill_table(generic_options, NULL); + options = fill_table(data, options); + l3cd = _ip4_config_from_options(1, "eth0", options); - g_hash_table_destroy(options); + strarr = nm_l3_config_data_get_searches(l3cd, AF_INET, &u); + g_assert_cmpint(u, ==, 3); + g_assert_cmpstr(strarr[0], ==, expected_search0); + g_assert_cmpstr(strarr[1], ==, expected_search1); + g_assert_cmpstr(strarr[2], ==, expected_search2); } static void test_invalid_escaped_domain_searches(void) { - GHashTable * options; - gs_unref_object NMIP4Config *ip4_config = NULL; + gs_unref_hashtable GHashTable *options = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; static const Option data[] = {{"domain_search", "host1\\aahost2\\032host3"}, {NULL, NULL}}; + const char *const *strarr; + guint u; options = fill_table(generic_options, NULL); options = fill_table(data, options); NMTST_EXPECT_NM_WARN("*invalid domain search*"); - ip4_config = _ip4_config_from_options(1, "eth0", options, 0); + l3cd = _ip4_config_from_options(1, "eth0", options); g_test_assert_expected_messages(); - /* domain searches */ - g_assert_cmpint(nm_ip4_config_get_num_searches(ip4_config), ==, 0); - - g_hash_table_destroy(options); + strarr = nm_l3_config_data_get_searches(l3cd, AF_INET, &u); + g_assert_cmpint(u, ==, 0); + g_assert(!strarr); } static void test_ip4_missing_prefix(const char *ip, guint32 expected_prefix) { - GHashTable * options; - gs_unref_object NMIP4Config *ip4_config = NULL; - const NMPlatformIP4Address * address; + gs_unref_hashtable GHashTable *options = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; + const NMPlatformIP4Address *address; options = fill_table(generic_options, NULL); g_hash_table_insert(options, "ip_address", (gpointer) ip); g_hash_table_remove(options, "subnet_mask"); - ip4_config = _ip4_config_from_options(1, "eth0", options, 0); + l3cd = _ip4_config_from_options(1, "eth0", options); - g_assert_cmpint(nm_ip4_config_get_num_addresses(ip4_config), ==, 1); - address = _nmtst_ip4_config_get_address(ip4_config, 0); + g_assert_cmpint(nm_l3_config_data_get_num_addresses(l3cd, AF_INET), ==, 1); + address = nmtst_l3_config_data_get_address_at_4(l3cd, 0); g_assert(address); g_assert_cmpint(address->plen, ==, expected_prefix); - - g_hash_table_destroy(options); } static void @@ -682,9 +649,9 @@ test_ip4_missing_prefix_8(void) static void test_ip4_prefix_classless(void) { - GHashTable * options; - gs_unref_object NMIP4Config *ip4_config = NULL; - const NMPlatformIP4Address * address; + gs_unref_hashtable GHashTable *options = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; + const NMPlatformIP4Address *address; /* Ensure that the missing-subnet-mask handler doesn't mangle classless * subnet masks at all. The handler should trigger only if the server @@ -695,21 +662,19 @@ test_ip4_prefix_classless(void) g_hash_table_insert(options, "ip_address", "172.16.54.22"); g_hash_table_insert(options, "subnet_mask", "255.255.252.0"); - ip4_config = _ip4_config_from_options(1, "eth0", options, 0); + l3cd = _ip4_config_from_options(1, "eth0", options); - g_assert_cmpint(nm_ip4_config_get_num_addresses(ip4_config), ==, 1); - address = _nmtst_ip4_config_get_address(ip4_config, 0); + g_assert_cmpint(nm_l3_config_data_get_num_addresses(l3cd, AF_INET), ==, 1); + address = nmtst_l3_config_data_get_address_at_4(l3cd, 0); g_assert(address); g_assert_cmpint(address->plen, ==, 22); - - 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; \ + const char *p; \ gsize l; \ \ b = nm_dhcp_utils_client_id_string_to_bytes(src); \ @@ -729,12 +694,12 @@ test_ip4_prefix_classless(void) 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 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:"; + 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)); diff --git a/src/core/dns/nm-dns-dnsmasq.c b/src/core/dns/nm-dns-dnsmasq.c index 126e0a21..f0abf564 100644 --- a/src/core/dns/nm-dns-dnsmasq.c +++ b/src/core/dns/nm-dns-dnsmasq.c @@ -19,10 +19,9 @@ #include "libnm-core-intern/nm-core-internal.h" #include "libnm-platform/nm-platform.h" #include "nm-utils.h" -#include "nm-ip4-config.h" -#include "nm-ip6-config.h" #include "nm-dbus-manager.h" #include "NetworkManagerUtils.h" +#include "nm-l3-config-data.h" #define PIDFILE NMRUNDIR "/dnsmasq.pid" #define CONFDIR NMCONFDIR "/dnsmasq.d" @@ -47,8 +46,8 @@ G_STATIC_ASSERT(WAIT_MSEC_AFTER_SIGKILL + 100 <= NM_SHUTDOWN_TIMEOUT_MS_WATCHDOG typedef void (*GlPidSpawnAsyncNotify)(GCancellable *cancellable, GPid pid, - const int * p_exit_code, - GError * error, + const int *p_exit_code, + GError *error, gpointer notify_user_data); typedef struct { @@ -60,10 +59,10 @@ typedef struct { } GlPidKillExternalData; typedef struct { - const char * dm_binary; + const char *dm_binary; GlPidSpawnAsyncNotify notify; gpointer notify_user_data; - GCancellable * cancellable; + GCancellable *cancellable; } GlPidSpawnAsyncData; static struct { @@ -167,9 +166,9 @@ process_gone: static gboolean _gl_pid_kill_external(void) { - gs_free char *contents = NULL; - gs_free char *cmdline_contents = NULL; - gs_free_error GError *error = NULL; + gs_free char *contents = NULL; + gs_free char *cmdline_contents = NULL; + gs_free_error GError *error = NULL; gint64 pid64; GPid pid = 0; guint64 p_start_time = 0; @@ -482,7 +481,7 @@ static void _gl_pid_spawn_next_step(void) { gs_free_error GError *error = NULL; - const char * argv[15]; + const char *argv[15]; GPid pid = 0; guint argv_idx; @@ -611,8 +610,8 @@ _gl_pid_spawn_next_step(void) * asynchronously. */ static void -_gl_pid_spawn(const char * dm_binary, - GCancellable * cancellable, +_gl_pid_spawn(const char *dm_binary, + GCancellable *cancellable, GlPidSpawnAsyncNotify notify, gpointer notify_user_data) { @@ -719,10 +718,10 @@ static gboolean start_dnsmasq(NMDnsDnsmasq *self, gboolean force_start, GError * /*****************************************************************************/ static void -add_dnsmasq_nameserver(NMDnsDnsmasq * self, +add_dnsmasq_nameserver(NMDnsDnsmasq *self, GVariantBuilder *servers, - const char * ip, - const char * domain) + const char *ip, + const char *domain) { g_return_if_fail(ip); @@ -779,8 +778,8 @@ ip_addr_to_string(int addr_family, gconstpointer addr, const char *iface, char * } static void -add_global_config(NMDnsDnsmasq * self, - GVariantBuilder * dnsmasq_servers, +add_global_config(NMDnsDnsmasq *self, + GVariantBuilder *dnsmasq_servers, const NMGlobalDnsConfig *config) { guint i, j; @@ -790,7 +789,7 @@ add_global_config(NMDnsDnsmasq * self, for (i = 0; i < nm_global_dns_config_get_num_domains(config); i++) { NMGlobalDnsDomain *domain = nm_global_dns_config_get_domain(config, i); const char *const *servers = nm_global_dns_domain_get_servers(domain); - const char * name = nm_global_dns_domain_get_name(domain); + const char *name = nm_global_dns_domain_get_name(domain); g_return_if_fail(name); @@ -806,20 +805,22 @@ add_global_config(NMDnsDnsmasq * self, static void add_ip_config(NMDnsDnsmasq *self, GVariantBuilder *servers, const NMDnsConfigIPData *ip_data) { - NMIPConfig * ip_config = ip_data->ip_config; - gconstpointer addr; - const char * iface, *domain; + const char *iface; + const char *domain; char ip_addr_to_string_buf[IP_ADDR_TO_STRING_BUFLEN]; - int addr_family; - guint i, j, num; + gconstpointer nameservers; + guint num; + guint i; + guint j; - iface = nm_platform_link_get_name(NM_PLATFORM_GET, ip_data->data->ifindex); - addr_family = nm_ip_config_get_addr_family(ip_config); + iface = nm_platform_link_get_name(NM_PLATFORM_GET, ip_data->data->ifindex); - num = nm_ip_config_get_num_nameservers(ip_config); + nameservers = nm_l3_config_data_get_nameservers(ip_data->l3cd, ip_data->addr_family, &num); for (i = 0; i < num; i++) { - addr = nm_ip_config_get_nameserver(ip_config, i); - ip_addr_to_string(addr_family, addr, iface, ip_addr_to_string_buf); + gconstpointer addr; + + addr = nm_ip_addr_from_packed_array(ip_data->addr_family, nameservers, i); + ip_addr_to_string(ip_data->addr_family, addr, iface, ip_addr_to_string_buf); if (!ip_data->domains.has_default_route_explicit && ip_data->domains.has_default_route) add_dnsmasq_nameserver(self, servers, ip_addr_to_string_buf, NULL); @@ -844,10 +845,10 @@ add_ip_config(NMDnsDnsmasq *self, GVariantBuilder *servers, const NMDnsConfigIPD } static GVariant * -create_update_args(NMDnsDnsmasq * self, +create_update_args(NMDnsDnsmasq *self, const NMGlobalDnsConfig *global_config, - const CList * ip_config_lst_head, - const char * hostname) + const CList *ip_data_lst_head, + const char *hostname) { GVariantBuilder servers; const NMDnsConfigIPData *ip_data; @@ -857,7 +858,7 @@ create_update_args(NMDnsDnsmasq * self, if (global_config) add_global_config(self, &servers, global_config); else { - c_list_for_each_entry (ip_data, ip_config_lst_head, ip_config_lst) + c_list_for_each_entry (ip_data, ip_data_lst_head, ip_data_lst) add_ip_config(self, &servers, ip_data); } @@ -869,8 +870,8 @@ create_update_args(NMDnsDnsmasq * self, static void dnsmasq_update_done(GObject *source_object, GAsyncResult *res, gpointer user_data) { - NMDnsDnsmasq *self; - gs_free_error GError *error = NULL; + NMDnsDnsmasq *self; + gs_free_error GError *error = NULL; gs_unref_variant GVariant *response = NULL; response = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source_object), res, &error); @@ -966,15 +967,15 @@ name_owner_changed(NMDnsDnsmasq *self, const char *name_owner) static void name_owner_changed_cb(GDBusConnection *connection, - const char * sender_name, - const char * object_path, - const char * interface_name, - const char * signal_name, - GVariant * parameters, + const char *sender_name, + const char *object_path, + const char *interface_name, + const char *signal_name, + GVariant *parameters, gpointer user_data) { NMDnsDnsmasq *self = user_data; - const char * new_owner; + const char *new_owner; if (!g_variant_is_of_type(parameters, G_VARIANT_TYPE("(sss)"))) return; @@ -1006,11 +1007,11 @@ spawn_timeout_cb(gpointer user_data) static void spawn_notify(GCancellable *cancellable, GPid pid, - const int * p_exit_code, - GError * error, + const int *p_exit_code, + GError *error, gpointer notify_user_data) { - NMDnsDnsmasq * self; + NMDnsDnsmasq *self; NMDnsDnsmasqPrivate *priv; if (nm_utils_error_is_cancelled(error)) @@ -1043,7 +1044,7 @@ spawn_notify(GCancellable *cancellable, static gboolean _burst_retry_timeout_cb(gpointer user_data) { - NMDnsDnsmasq * self = user_data; + NMDnsDnsmasq *self = user_data; NMDnsDnsmasqPrivate *priv = NM_DNS_DNSMASQ_GET_PRIVATE(self); priv->burst_retry_timeout_id = 0; @@ -1057,7 +1058,7 @@ static gboolean start_dnsmasq(NMDnsDnsmasq *self, gboolean force_start, GError **error) { NMDnsDnsmasqPrivate *priv = NM_DNS_DNSMASQ_GET_PRIVATE(self); - const char * dm_binary; + const char *dm_binary; gint64 now; if (G_LIKELY(priv->main_cancellable)) { @@ -1120,13 +1121,13 @@ start_dnsmasq(NMDnsDnsmasq *self, gboolean force_start, GError **error) } static gboolean -update(NMDnsPlugin * plugin, +update(NMDnsPlugin *plugin, const NMGlobalDnsConfig *global_config, - const CList * ip_config_lst_head, - const char * hostname, - GError ** error) + const CList *ip_data_lst_head, + const char *hostname, + GError **error) { - NMDnsDnsmasq * self = NM_DNS_DNSMASQ(plugin); + NMDnsDnsmasq *self = NM_DNS_DNSMASQ(plugin); NMDnsDnsmasqPrivate *priv = NM_DNS_DNSMASQ_GET_PRIVATE(self); if (!start_dnsmasq(self, TRUE, error)) @@ -1134,7 +1135,7 @@ update(NMDnsPlugin * plugin, nm_clear_pointer(&priv->set_server_ex_args, g_variant_unref); priv->set_server_ex_args = - g_variant_ref_sink(create_update_args(self, global_config, ip_config_lst_head, hostname)); + g_variant_ref_sink(create_update_args(self, global_config, ip_data_lst_head, hostname)); send_dnsmasq_update(self); return TRUE; @@ -1145,7 +1146,7 @@ update(NMDnsPlugin * plugin, static void stop(NMDnsPlugin *plugin) { - NMDnsDnsmasq * self = NM_DNS_DNSMASQ(plugin); + NMDnsDnsmasq *self = NM_DNS_DNSMASQ(plugin); NMDnsDnsmasqPrivate *priv = NM_DNS_DNSMASQ_GET_PRIVATE(self); priv->is_stopped = TRUE; @@ -1172,7 +1173,7 @@ nm_dns_dnsmasq_new(void) static void dispose(GObject *object) { - NMDnsDnsmasq * self = NM_DNS_DNSMASQ(object); + NMDnsDnsmasq *self = NM_DNS_DNSMASQ(object); NMDnsDnsmasqPrivate *priv = NM_DNS_DNSMASQ_GET_PRIVATE(self); priv->is_stopped = TRUE; @@ -1192,7 +1193,7 @@ static void nm_dns_dnsmasq_class_init(NMDnsDnsmasqClass *dns_class) { NMDnsPluginClass *plugin_class = NM_DNS_PLUGIN_CLASS(dns_class); - GObjectClass * object_class = G_OBJECT_CLASS(dns_class); + GObjectClass *object_class = G_OBJECT_CLASS(dns_class); object_class->dispose = dispose; diff --git a/src/core/dns/nm-dns-manager.c b/src/core/dns/nm-dns-manager.c index f0ec0c89..efbf847b 100644 --- a/src/core/dns/nm-dns-manager.c +++ b/src/core/dns/nm-dns-manager.c @@ -7,6 +7,8 @@ #include "src/core/nm-default-daemon.h" +#include "nm-dns-manager.h" + #include #include #include @@ -22,22 +24,21 @@ #include #endif -#include "libnm-glib-aux/nm-str-buf.h" -#include "nm-utils.h" #include "libnm-core-intern/nm-core-internal.h" -#include "nm-dns-manager.h" -#include "nm-ip4-config.h" -#include "nm-ip6-config.h" +#include "libnm-glib-aux/nm-str-buf.h" + #include "NetworkManagerUtils.h" +#include "devices/nm-device.h" #include "nm-config.h" #include "nm-dbus-object.h" -#include "devices/nm-device.h" -#include "nm-manager.h" - -#include "nm-dns-plugin.h" #include "nm-dns-dnsmasq.h" +#include "nm-dns-plugin.h" #include "nm-dns-systemd-resolved.h" #include "nm-dns-unbound.h" +#include "nm-ip-config.h" +#include "nm-l3-config-data.h" +#include "nm-manager.h" +#include "nm-utils.h" #define HASH_LEN NM_UTILS_CHECKSUM_LENGTH_SHA1 @@ -60,11 +61,11 @@ typedef enum { SR_SUCCESS, SR_NOTFOUND, SR_ERROR } SpawnResult; typedef struct { - GPtrArray * nameservers; - GPtrArray * searches; - GPtrArray * options; + GPtrArray *nameservers; + GPtrArray *searches; + GPtrArray *options; const char *nis_domain; - GPtrArray * nis_servers; + GPtrArray *nis_servers; NMTernary has_trust_ad; } NMResolvConfData; @@ -84,16 +85,18 @@ typedef struct { GHashTable *configs_dict; CList configs_lst_head; - CList ip_config_lst_head; + CList ip_data_lst_head; GVariant *config_variant; - bool ip_config_lst_need_sort : 1; + bool ip_data_lst_need_sort : 1; bool configs_lst_need_sort : 1; bool dns_touched : 1; bool is_stopped : 1; + bool config_changed : 1; + char *hostname; guint updates_queue; @@ -101,9 +104,9 @@ typedef struct { guint8 prev_hash[HASH_LEN]; /* Hash when begin_updates() was called */ NMDnsManagerResolvConfManager rc_manager; - char * mode; - NMDnsPlugin * sd_resolve_plugin; - NMDnsPlugin * plugin; + char *mode; + NMDnsPlugin *sd_resolve_plugin; + NMDnsPlugin *plugin; NMConfig *config; @@ -159,11 +162,6 @@ NM_DEFINE_SINGLETON_GETTER(NMDnsManager, nm_dns_manager_get, NM_TYPE_DNS_MANAGER /*****************************************************************************/ -static void -_ip_config_dns_priority_changed(gpointer config, GParamSpec *pspec, NMDnsConfigIPData *ip_data); - -/*****************************************************************************/ - static gboolean domain_is_valid(const char *domain, gboolean check_public_suffix) { @@ -208,6 +206,24 @@ static NM_UTILS_LOOKUP_STR_DEFINE( /*****************************************************************************/ +static int +_dns_config_ip_data_get_dns_priority1(const NML3ConfigData *l3cd, int addr_family) +{ + int prio; + + if (!nm_l3_config_data_get_dns_priority(l3cd, addr_family, &prio)) + return 0; + + nm_assert(prio != 0); + return prio; +} + +static int +_dns_config_ip_data_get_dns_priority(const NMDnsConfigIPData *ip_data) +{ + return _dns_config_ip_data_get_dns_priority1(ip_data->l3cd, ip_data->addr_family); +} + static void _ASSERT_dns_config_data(const NMDnsConfigData *data) { @@ -221,9 +237,9 @@ _ASSERT_dns_config_ip_data(const NMDnsConfigIPData *ip_data) { nm_assert(ip_data); _ASSERT_dns_config_data(ip_data->data); - nm_assert(NM_IS_IP_CONFIG(ip_data->ip_config)); + nm_assert(NM_IS_L3_CONFIG_DATA(ip_data->l3cd)); nm_assert(c_list_contains(&ip_data->data->data_lst_head, &ip_data->data_lst)); - nm_assert(ip_data->data->ifindex == nm_ip_config_get_ifindex(ip_data->ip_config)); + nm_assert(ip_data->data->ifindex == nm_l3_config_data_get_ifindex(ip_data->l3cd)); #if NM_MORE_ASSERTS > 5 { gboolean has_default = FALSE; @@ -243,37 +259,36 @@ _ASSERT_dns_config_ip_data(const NMDnsConfigIPData *ip_data) if (ip_data->domains.has_default_route_exclusive) nm_assert(ip_data->domains.has_default_route); } + nm_assert(_dns_config_ip_data_get_dns_priority(ip_data) != 0); #endif } static NMDnsConfigIPData * -_dns_config_ip_data_new(NMDnsConfigData * data, - NMIPConfig * ip_config, - NMDnsIPConfigType ip_config_type) +_dns_config_ip_data_new(NMDnsConfigData *data, + int addr_family, + gconstpointer source_tag, + const NML3ConfigData *l3cd, + NMDnsIPConfigType ip_config_type) { NMDnsConfigIPData *ip_data; _ASSERT_dns_config_data(data); - nm_assert(NM_IS_IP_CONFIG(ip_config)); + nm_assert(NM_IS_L3_CONFIG_DATA(l3cd)); nm_assert(ip_config_type != NM_DNS_IP_CONFIG_TYPE_REMOVED); ip_data = g_slice_new(NMDnsConfigIPData); *ip_data = (NMDnsConfigIPData){ .data = data, - .ip_config = g_object_ref(ip_config), + .source_tag = source_tag, + .l3cd = nm_l3_config_data_ref_and_seal(l3cd), .ip_config_type = ip_config_type, + .addr_family = addr_family, }; c_list_link_tail(&data->data_lst_head, &ip_data->data_lst); - c_list_link_tail(&NM_DNS_MANAGER_GET_PRIVATE(data->self)->ip_config_lst_head, - &ip_data->ip_config_lst); - - /* We also need to set priv->ip_config_lst_need_sort, but the caller will do that! */ + c_list_link_tail(&NM_DNS_MANAGER_GET_PRIVATE(data->self)->ip_data_lst_head, + &ip_data->ip_data_lst); - g_signal_connect(ip_config, - NM_IS_IP4_CONFIG(ip_config) ? "notify::" NM_IP4_CONFIG_DNS_PRIORITY - : "notify::" NM_IP6_CONFIG_DNS_PRIORITY, - G_CALLBACK(_ip_config_dns_priority_changed), - ip_data); + /* We also need to set priv->ip_data_lst_need_sort, but the caller will do that! */ _ASSERT_dns_config_ip_data(ip_data); return ip_data; @@ -285,35 +300,15 @@ _dns_config_ip_data_free(NMDnsConfigIPData *ip_data) _ASSERT_dns_config_ip_data(ip_data); c_list_unlink_stale(&ip_data->data_lst); - c_list_unlink_stale(&ip_data->ip_config_lst); + c_list_unlink_stale(&ip_data->ip_data_lst); g_free(ip_data->domains.search); g_strfreev(ip_data->domains.reverse); - g_signal_handlers_disconnect_by_func(ip_data->ip_config, - _ip_config_dns_priority_changed, - ip_data); - - g_object_unref(ip_data->ip_config); + nm_l3_config_data_unref(ip_data->l3cd); nm_g_slice_free(ip_data); } -static NMDnsConfigIPData * -_dns_config_data_find_ip_config(NMDnsConfigData *data, NMIPConfig *ip_config) -{ - NMDnsConfigIPData *ip_data; - - _ASSERT_dns_config_data(data); - - c_list_for_each_entry (ip_data, &data->data_lst_head, data_lst) { - _ASSERT_dns_config_ip_data(ip_data); - - if (ip_data->ip_config == ip_config) - return ip_data; - } - return NULL; -} - static void _dns_config_data_free(NMDnsConfigData *data) { @@ -325,14 +320,13 @@ _dns_config_data_free(NMDnsConfigData *data) } static int -_mgr_get_ip_config_lst_cmp(const CList *a_lst, const CList *b_lst, const void *user_data) +_mgr_get_ip_data_lst_cmp(const CList *a_lst, const CList *b_lst, const void *user_data) { - const NMDnsConfigIPData *a = c_list_entry(a_lst, NMDnsConfigIPData, ip_config_lst); - const NMDnsConfigIPData *b = c_list_entry(b_lst, NMDnsConfigIPData, ip_config_lst); + const NMDnsConfigIPData *a = c_list_entry(a_lst, NMDnsConfigIPData, ip_data_lst); + const NMDnsConfigIPData *b = c_list_entry(b_lst, NMDnsConfigIPData, ip_data_lst); /* Configurations with lower priority value first */ - NM_CMP_DIRECT(nm_ip_config_get_dns_priority(a->ip_config), - nm_ip_config_get_dns_priority(b->ip_config)); + NM_CMP_DIRECT(_dns_config_ip_data_get_dns_priority(a), _dns_config_ip_data_get_dns_priority(b)); /* Sort according to type (descendingly) */ NM_CMP_FIELD(b, a, ip_config_type); @@ -341,16 +335,16 @@ _mgr_get_ip_config_lst_cmp(const CList *a_lst, const CList *b_lst, const void *u } static CList * -_mgr_get_ip_config_lst_head(NMDnsManager *self) +_mgr_get_ip_data_lst_head(NMDnsManager *self) { NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE(self); - if (G_UNLIKELY(priv->ip_config_lst_need_sort)) { - priv->ip_config_lst_need_sort = FALSE; - c_list_sort(&priv->ip_config_lst_head, _mgr_get_ip_config_lst_cmp, NULL); + if (G_UNLIKELY(priv->ip_data_lst_need_sort)) { + priv->ip_data_lst_need_sort = FALSE; + c_list_sort(&priv->ip_data_lst_head, _mgr_get_ip_data_lst_cmp, NULL); } - return &priv->ip_config_lst_head; + return &priv->ip_data_lst_head; } static int @@ -382,7 +376,7 @@ NMDnsPlugin * nm_dns_manager_get_systemd_resolved(NMDnsManager *self) { NMDnsManagerPrivate *priv; - NMDnsPlugin * plugin = NULL; + NMDnsPlugin *plugin = NULL; g_return_val_if_fail(NM_IS_DNS_MANAGER(self), FALSE); @@ -430,28 +424,33 @@ add_dns_option_item(GPtrArray *array, const char *str) } static void -add_dns_domains(GPtrArray * array, - const NMIPConfig *ip_config, - gboolean include_routing, - gboolean dup) +add_dns_domains(GPtrArray *array, + int addr_family, + const NML3ConfigData *l3cd, + gboolean include_routing, + gboolean dup) { - guint num_domains, num_searches, i; - const char *str; + const char *const *domains; + const char *const *searches; + guint num_domains; + guint num_searches; + guint i; + const char *str; - num_domains = nm_ip_config_get_num_domains(ip_config); - num_searches = nm_ip_config_get_num_searches(ip_config); + domains = nm_l3_config_data_get_domains(l3cd, addr_family, &num_domains); + searches = nm_l3_config_data_get_searches(l3cd, addr_family, &num_searches); for (i = 0; i < num_searches; i++) { - str = nm_ip_config_get_search(ip_config, i); + str = searches[i]; if (!include_routing && domain_is_routing(str)) continue; if (!domain_is_valid(nm_utils_parse_dns_domain(str, NULL), FALSE)) continue; add_string_item(array, str, dup); } - if (num_domains > 1 || !num_searches) { + if (num_domains > 1 || num_searches == 0) { for (i = 0; i < num_domains; i++) { - str = nm_ip_config_get_domain(ip_config, i); + str = domains[i]; if (!include_routing && domain_is_routing(str)) continue; if (!domain_is_valid(nm_utils_parse_dns_domain(str, NULL), FALSE)) @@ -462,26 +461,24 @@ add_dns_domains(GPtrArray * array, } static void -merge_one_ip_config(NMResolvConfData *rc, int ifindex, const NMIPConfig *ip_config) +merge_one_l3cd(NMResolvConfData *rc, int addr_family, int ifindex, const NML3ConfigData *l3cd) { - int addr_family; - char buf[NM_UTILS_INET_ADDRSTRLEN + 50]; - gboolean has_trust_ad; - guint num_nameservers; - guint num; - guint i; + char buf[NM_UTILS_INET_ADDRSTRLEN + 50]; + gboolean has_trust_ad; + guint num_nameservers; + guint num; + guint i; + gconstpointer nameservers; + const char *const *strv; - addr_family = nm_ip_config_get_addr_family(ip_config); + nm_assert(ifindex == nm_l3_config_data_get_ifindex(l3cd)); - nm_assert_addr_family(addr_family); - nm_assert(ifindex > 0); - nm_assert(ifindex == nm_ip_config_get_ifindex(ip_config)); - - num_nameservers = nm_ip_config_get_num_nameservers(ip_config); + nameservers = nm_l3_config_data_get_nameservers(l3cd, addr_family, &num_nameservers); for (i = 0; i < num_nameservers; i++) { const NMIPAddr *addr; - addr = nm_ip_config_get_nameserver(ip_config, i); + addr = nm_ip_addr_from_packed_array(addr_family, nameservers, i); + if (addr_family == AF_INET) nm_utils_inet_ntop(addr_family, addr, buf); else if (IN6_IS_ADDR_V4MAPPED(addr)) @@ -502,22 +499,23 @@ merge_one_ip_config(NMResolvConfData *rc, int ifindex, const NMIPConfig *ip_conf add_string_item(rc->nameservers, buf, TRUE); } - add_dns_domains(rc->searches, ip_config, FALSE, TRUE); + add_dns_domains(rc->searches, addr_family, l3cd, FALSE, TRUE); has_trust_ad = FALSE; - num = nm_ip_config_get_num_dns_options(ip_config); + strv = nm_l3_config_data_get_dns_options(l3cd, addr_family, &num); for (i = 0; i < num; i++) { - const char *option = nm_ip_config_get_dns_option(ip_config, i); + const char *option = strv[i]; if (nm_streq(option, NM_SETTING_DNS_OPTION_TRUST_AD)) { has_trust_ad = TRUE; continue; } - add_dns_option_item(rc->options, nm_ip_config_get_dns_option(ip_config, i)); + add_dns_option_item(rc->options, option); } + if (num_nameservers == 0) { - /* If the @ip_config contributes no DNS servers, ignore whether trust-ad is set or unset - * for this @ip_config. */ + /* If the @l3cd contributes no DNS servers, ignore whether trust-ad is set or unset + * for this @l3cd. */ } else if (has_trust_ad) { /* We only set has_trust_ad to TRUE, if all IP configs agree (or don't contribute). * Once set to FALSE, it doesn't get reset. */ @@ -527,20 +525,17 @@ merge_one_ip_config(NMResolvConfData *rc, int ifindex, const NMIPConfig *ip_conf rc->has_trust_ad = NM_TERNARY_FALSE; if (addr_family == AF_INET) { - const NMIP4Config *ip4_config = (const NMIP4Config *) ip_config; + const in_addr_t *nis_servers; + const char *nis_domain; - /* NIS stuff */ - num = nm_ip4_config_get_num_nis_servers(ip4_config); - for (i = 0; i < num; i++) { - add_string_item(rc->nis_servers, - _nm_utils_inet4_ntop(nm_ip4_config_get_nis_server(ip4_config, i), buf), - TRUE); - } + nis_servers = nm_l3_config_data_get_nis_servers(l3cd, &num); + for (i = 0; i < num; i++) + add_string_item(rc->nis_servers, _nm_utils_inet4_ntop(nis_servers[i], buf), TRUE); - if (nm_ip4_config_get_nis_domain(ip4_config)) { + if ((nis_domain = nm_l3_config_data_get_nis_domain(l3cd))) { /* FIXME: handle multiple domains */ if (!rc->nis_domain) - rc->nis_domain = nm_ip4_config_get_nis_domain(ip4_config); + rc->nis_domain = nis_domain; } } } @@ -548,7 +543,7 @@ merge_one_ip_config(NMResolvConfData *rc, int ifindex, const NMIPConfig *ip_conf static GPid run_netconfig(NMDnsManager *self, GError **error, int *stdin_fd) { - char * argv[5]; + char *argv[5]; gs_free char *tmp = NULL; GPid pid = -1; @@ -586,9 +581,9 @@ netconfig_construct_str(NMDnsManager *self, GString *str, const char *key, const } static void -netconfig_construct_strv(NMDnsManager * self, - GString * str, - const char * key, +netconfig_construct_strv(NMDnsManager *self, + GString *str, + const char *key, const char *const *values) { if (values) { @@ -600,18 +595,18 @@ netconfig_construct_strv(NMDnsManager * self, } static SpawnResult -dispatch_netconfig(NMDnsManager * self, +dispatch_netconfig(NMDnsManager *self, const char *const *searches, const char *const *nameservers, - const char * nis_domain, + const char *nis_domain, const char *const *nis_servers, - GError ** error) + GError **error) { - GPid pid; - int fd; - int errsv; - int status; - gssize l; + GPid pid; + int fd; + int errsv; + int status; + gssize l; nm_auto_free_gstring GString *str = NULL; pid = run_netconfig(self, error, &fd); @@ -768,11 +763,11 @@ write_resolv_conf_contents(FILE *f, const char *content, GError **error) } static gboolean -write_resolv_conf(FILE * f, +write_resolv_conf(FILE *f, const char *const *searches, const char *const *nameservers, const char *const *options, - GError ** error) + GError **error) { gs_free char *content = NULL; @@ -782,17 +777,17 @@ write_resolv_conf(FILE * f, static SpawnResult dispatch_resolvconf(NMDnsManager *self, - char ** searches, - char ** nameservers, - char ** options, - GError ** error) + char **searches, + char **nameservers, + char **options, + GError **error) { gs_free char *cmd = NULL; - FILE * f; + FILE *f; gboolean success = FALSE; int errsv; int err; - char * argv[] = {RESOLVCONF_PATH, "-d", "NetworkManager", NULL}; + char *argv[] = {RESOLVCONF_PATH, "-d", "NetworkManager", NULL}; int status; if (!g_file_test(RESOLVCONF_PATH, G_FILE_TEST_IS_EXECUTABLE)) { @@ -883,13 +878,13 @@ _read_link_cached(const char *path, gboolean *is_cached, char **cached) #define NO_STUB_RESOLV_CONF NMRUNDIR "/no-stub-resolv.conf" static void -update_resolv_conf_no_stub(NMDnsManager * self, +update_resolv_conf_no_stub(NMDnsManager *self, const char *const *searches, const char *const *nameservers, const char *const *options) { gs_free char *content = NULL; - GError * local = NULL; + GError *local = NULL; content = create_resolv_conf(searches, nameservers, options); @@ -903,14 +898,14 @@ update_resolv_conf_no_stub(NMDnsManager * self, } static SpawnResult -update_resolv_conf(NMDnsManager * self, - const char *const * searches, - const char *const * nameservers, - const char *const * options, - GError ** error, +update_resolv_conf(NMDnsManager *self, + const char *const *searches, + const char *const *nameservers, + const char *const *options, + GError **error, NMDnsManagerResolvConfManager rc_manager) { - FILE * f; + FILE *f; gboolean success; gs_free char *content = NULL; SpawnResult write_file_result = SR_SUCCESS; @@ -923,10 +918,10 @@ update_resolv_conf(NMDnsManager * self, if (rc_manager == NM_DNS_MANAGER_RESOLV_CONF_MAN_FILE || (rc_manager == NM_DNS_MANAGER_RESOLV_CONF_MAN_SYMLINK && !_read_link_cached(_PATH_RESCONF, &resconf_link_cached, &resconf_link))) { - gs_free char * rc_path_syml = NULL; + gs_free char *rc_path_syml = NULL; nm_auto_free char *rc_path_real = NULL; - const char * rc_path = _PATH_RESCONF; - GError * local = NULL; + const char *rc_path = _PATH_RESCONF; + GError *local = NULL; if (rc_manager == NM_DNS_MANAGER_RESOLV_CONF_MAN_FILE) { rc_path_real = realpath(_PATH_RESCONF, NULL); @@ -1110,7 +1105,7 @@ static void compute_hash(NMDnsManager *self, const NMGlobalDnsConfig *global, guint8 buffer[static HASH_LEN]) { nm_auto_free_checksum GChecksum *sum = NULL; - NMDnsConfigIPData * ip_data; + NMDnsConfigIPData *ip_data; sum = g_checksum_new(G_CHECKSUM_SHA1); nm_assert(HASH_LEN == g_checksum_type_get_length(G_CHECKSUM_SHA1)); @@ -1122,9 +1117,9 @@ compute_hash(NMDnsManager *self, const NMGlobalDnsConfig *global, guint8 buffer[ /* FIXME(ip-config-checksum): this relies on the fact that an IP * configuration without DNS parameters gives a zero checksum. */ - head = _mgr_get_ip_config_lst_head(self); - c_list_for_each_entry (ip_data, head, ip_config_lst) - nm_ip_config_hash(ip_data->ip_config, sum, TRUE); + head = _mgr_get_ip_data_lst_head(self); + c_list_for_each_entry (ip_data, head, ip_data_lst) + nm_ip_config_dns_hash(ip_data->l3cd, sum, ip_data->addr_family); } nm_utils_checksum_get_digest_len(sum, buffer, HASH_LEN); @@ -1172,19 +1167,21 @@ merge_global_dns_config(NMResolvConfData *rc, NMGlobalDnsConfig *global_conf) } static const char * -get_nameserver_list(const NMIPConfig *config, NMStrBuf *tmp_strbuf) +get_nameserver_list(int addr_family, const NML3ConfigData *l3cd, NMStrBuf *tmp_strbuf) { - char buf[NM_UTILS_INET_ADDRSTRLEN]; - int addr_family; - guint num; - guint i; + char buf[NM_UTILS_INET_ADDRSTRLEN]; + guint num; + guint i; + gconstpointer nameservers; nm_str_buf_reset(tmp_strbuf); - addr_family = nm_ip_config_get_addr_family(config); - num = nm_ip_config_get_num_nameservers(config); + nameservers = nm_l3_config_data_get_nameservers(l3cd, addr_family, &num); for (i = 0; i < num; i++) { - nm_utils_inet_ntop(addr_family, nm_ip_config_get_nameserver(config, i), buf); + const NMIPAddr *addr; + + addr = nm_ip_addr_from_packed_array(addr_family, nameservers, i); + nm_utils_inet_ntop(addr_family, addr->addr_ptr, buf); if (i > 0) nm_str_buf_append_c(tmp_strbuf, ' '); nm_str_buf_append(tmp_strbuf, buf); @@ -1203,22 +1200,22 @@ _ptrarray_to_strv(GPtrArray *parray) } static void -_collect_resolv_conf_data(NMDnsManager * self, +_collect_resolv_conf_data(NMDnsManager *self, NMGlobalDnsConfig *global_config, - char *** out_searches, - char *** out_options, - char *** out_nameservers, - char *** out_nis_servers, - const char ** out_nis_domain) + char ***out_searches, + char ***out_options, + char ***out_nameservers, + char ***out_nis_servers, + const char **out_nis_domain) { NMDnsManagerPrivate *priv; NMResolvConfData rc = { - .nameservers = g_ptr_array_new(), - .searches = g_ptr_array_new(), - .options = g_ptr_array_new(), - .nis_domain = NULL, - .nis_servers = g_ptr_array_new(), - .has_trust_ad = NM_TERNARY_DEFAULT, + .nameservers = g_ptr_array_new(), + .searches = g_ptr_array_new(), + .options = g_ptr_array_new(), + .nis_domain = NULL, + .nis_servers = g_ptr_array_new(), + .has_trust_ad = NM_TERNARY_DEFAULT, }; priv = NM_DNS_MANAGER_GET_PRIVATE(self); @@ -1227,36 +1224,39 @@ _collect_resolv_conf_data(NMDnsManager * self, merge_global_dns_config(&rc, global_config); else { nm_auto_str_buf NMStrBuf tmp_strbuf = NM_STR_BUF_INIT(0, FALSE); - int prio; int first_prio = 0; const NMDnsConfigIPData *ip_data; - const CList * head; + const CList *head; gboolean is_first = TRUE; - head = _mgr_get_ip_config_lst_head(self); - c_list_for_each_entry (ip_data, head, ip_config_lst) { + head = _mgr_get_ip_data_lst_head(self); + c_list_for_each_entry (ip_data, head, ip_data_lst) { gboolean skip = FALSE; + int dns_priority; _ASSERT_dns_config_ip_data(ip_data); - prio = nm_ip_config_get_dns_priority(ip_data->ip_config); + if (!nm_l3_config_data_get_dns_priority(ip_data->l3cd, + ip_data->addr_family, + &dns_priority)) + nm_assert_not_reached(); if (is_first) { is_first = FALSE; - first_prio = prio; - } else if (first_prio < 0 && first_prio != prio) + first_prio = dns_priority; + } else if (first_prio < 0 && first_prio != dns_priority) skip = TRUE; _LOGT("config: %8d %-7s v%c %-5d %s: %s", - prio, + dns_priority, _config_type_to_string(ip_data->ip_config_type), - nm_utils_addr_family_to_char(nm_ip_config_get_addr_family(ip_data->ip_config)), + nm_utils_addr_family_to_char(ip_data->addr_family), ip_data->data->ifindex, skip ? "" : "", - get_nameserver_list(ip_data->ip_config, &tmp_strbuf)); + get_nameserver_list(ip_data->addr_family, ip_data->l3cd, &tmp_strbuf)); if (!skip) - merge_one_ip_config(&rc, ip_data->data->ifindex, ip_data->ip_config); + merge_one_l3cd(&rc, ip_data->addr_family, ip_data->data->ifindex, ip_data->l3cd); } } @@ -1292,27 +1292,32 @@ _collect_resolv_conf_data(NMDnsManager * self, /*****************************************************************************/ static char ** -get_ip_rdns_domains(NMIPConfig *ip_config) +get_ip_rdns_domains(int addr_family, const NML3ConfigData *l3cd) { - int addr_family = nm_ip_config_get_addr_family(ip_config); - char ** strv; - GPtrArray * domains; - NMDedupMultiIter ipconf_iter; - const NMPlatformIPAddress *address; - const NMPlatformIPRoute * route; - - nm_assert_addr_family(addr_family); + const int IS_IPv4 = NM_IS_IPv4(addr_family); + char **strv; + GPtrArray *domains; + NMDedupMultiIter ipconf_iter; + const NMPObject *obj; domains = g_ptr_array_sized_new(5); - nm_ip_config_iter_ip_address_for_each (&ipconf_iter, ip_config, &address) { + nm_l3_config_data_iter_obj_for_each (&ipconf_iter, + l3cd, + &obj, + NMP_OBJECT_TYPE_IP_ADDRESS(IS_IPv4)) { nm_utils_get_reverse_dns_domains_ip(addr_family, - address->address_ptr, - address->plen, + NMP_OBJECT_CAST_IP_ADDRESS(obj)->address_ptr, + NMP_OBJECT_CAST_IP_ADDRESS(obj)->plen, domains); } - nm_ip_config_iter_ip_route_for_each (&ipconf_iter, ip_config, &route) { + nm_l3_config_data_iter_obj_for_each (&ipconf_iter, + l3cd, + &obj, + NMP_OBJECT_TYPE_IP_ROUTE(IS_IPv4)) { + const NMPlatformIPRoute *route = NMP_OBJECT_CAST_IP_ROUTE(obj); + if (!NM_PLATFORM_IP_ROUTE_IS_DEFAULT(route)) { nm_utils_get_reverse_dns_domains_ip(addr_family, route->network_ptr, @@ -1345,11 +1350,11 @@ _domain_track_get_priority(GHashTable *ht, const char *domain, int *out_priority /* Check if the domain is shadowed by a parent domain with more negative priority */ static gboolean -_domain_track_is_shadowed(GHashTable * ht, - const char * domain, +_domain_track_is_shadowed(GHashTable *ht, + const char *domain, int priority, const char **out_parent, - int * out_parent_priority) + int *out_parent_priority) { char *parent; int parent_priority; @@ -1388,18 +1393,18 @@ _domain_track_is_shadowed(GHashTable * ht, static void _mgr_configs_data_construct(NMDnsManager *self) { - NMDnsConfigIPData *ip_data; + NMDnsConfigIPData *ip_data; gs_unref_hashtable GHashTable *ht = NULL; gs_unref_hashtable GHashTable *wildcard_entries = NULL; - CList * head; + CList *head; int prev_priority = G_MININT; - head = _mgr_get_ip_config_lst_head(self); + head = _mgr_get_ip_data_lst_head(self); #if NM_MORE_ASSERTS /* we call _mgr_configs_data_clear() at the end of update. We * don't expect any domain settings here. */ - c_list_for_each_entry (ip_data, head, ip_config_lst) { + c_list_for_each_entry (ip_data, head, ip_data_lst) { nm_assert(!ip_data->domains.search); nm_assert(!ip_data->domains.reverse); nm_assert(!ip_data->domains.has_default_route_explicit); @@ -1408,15 +1413,17 @@ _mgr_configs_data_construct(NMDnsManager *self) } #endif - c_list_for_each_entry (ip_data, head, ip_config_lst) { - NMIPConfig *ip_config = ip_data->ip_config; - gboolean add_wildcard = FALSE; + c_list_for_each_entry (ip_data, head, ip_data_lst) { + gboolean add_wildcard = FALSE; + guint num; - if (!nm_ip_config_get_num_nameservers(ip_config)) + nm_l3_config_data_get_nameservers(ip_data->l3cd, ip_data->addr_family, &num); + if (num == 0) continue; - if (nm_ip_config_best_default_route_get(ip_config)) + if (nm_l3_config_data_get_best_default_route(ip_data->l3cd, ip_data->addr_family)) { + /* FIXME(l3cfg): the best-default route of a l3cd is not significant! */ add_wildcard = TRUE; - else { + } else { /* If a VPN has never-default=no but doesn't get a default * route (this can happen for example when the server * pushes routes with openconnect), and there are no @@ -1424,9 +1431,10 @@ _mgr_configs_data_construct(NMDnsManager *self) * by the server would be unused. It is preferable in this * case to use the VPN DNS server for all queries. */ if (ip_data->ip_config_type == NM_DNS_IP_CONFIG_TYPE_VPN - && !nm_ip_config_get_never_default(ip_data->ip_config) - && nm_ip_config_get_num_searches(ip_data->ip_config) == 0 - && nm_ip_config_get_num_domains(ip_data->ip_config) == 0) + && nm_l3_config_data_get_never_default(ip_data->l3cd, ip_data->addr_family) + == NM_TERNARY_FALSE + && !nm_l3_config_data_get_searches(ip_data->l3cd, ip_data->addr_family, &num) + && !nm_l3_config_data_get_domains(ip_data->l3cd, ip_data->addr_family, &num)) add_wildcard = TRUE; } @@ -1437,29 +1445,33 @@ _mgr_configs_data_construct(NMDnsManager *self) } } - c_list_for_each_entry (ip_data, head, ip_config_lst) { - NMIPConfig * ip_config = ip_data->ip_config; - int priority; - const char **domains; - guint n_searches; - guint n_domains; - guint num_dom1; - guint num_dom2; - guint n_domains_allocated; - guint i; - gboolean has_default_route_maybe = FALSE; - gboolean has_default_route_explicit = FALSE; - gboolean has_default_route_auto = FALSE; - - if (!nm_ip_config_get_num_nameservers(ip_config)) + c_list_for_each_entry (ip_data, head, ip_data_lst) { + int priority; + const char **domains; + const char *const *strv_searches; + const char *const *strv_domains; + guint n_searches; + guint n_domains; + guint num_dom1; + guint num_dom2; + guint n_domains_allocated; + guint i; + gboolean has_default_route_maybe = FALSE; + gboolean has_default_route_explicit = FALSE; + gboolean has_default_route_auto = FALSE; + guint num; + + nm_l3_config_data_get_nameservers(ip_data->l3cd, ip_data->addr_family, &num); + if (num == 0) continue; - n_searches = nm_ip_config_get_num_searches(ip_config); - n_domains = nm_ip_config_get_num_domains(ip_config); + strv_searches = + nm_l3_config_data_get_searches(ip_data->l3cd, ip_data->addr_family, &n_searches); + strv_domains = + nm_l3_config_data_get_domains(ip_data->l3cd, ip_data->addr_family, &n_domains); - priority = nm_ip_config_get_dns_priority(ip_config); + priority = _dns_config_ip_data_get_dns_priority(ip_data); - nm_assert(priority != 0); nm_assert(prev_priority <= priority); prev_priority = priority; @@ -1487,10 +1499,10 @@ _mgr_configs_data_construct(NMDnsManager *self) /* searches are preferred over domains */ if (n_searches > 0) { for (i = 0; i < n_searches; i++) - domains[num_dom1++] = nm_ip_config_get_search(ip_config, i); + domains[num_dom1++] = strv_searches[i]; } else { for (i = 0; i < n_domains; i++) - domains[num_dom1++] = nm_ip_config_get_domain(ip_config, i); + domains[num_dom1++] = strv_domains[i]; } nm_assert(num_dom1 < n_domains_allocated); @@ -1578,8 +1590,8 @@ _mgr_configs_data_construct(NMDnsManager *self) nm_assert(!ip_data->domains.search); nm_assert(!ip_data->domains.reverse); - ip_data->domains.search = domains; - ip_data->domains.reverse = get_ip_rdns_domains(ip_config); + ip_data->domains.search = domains; + ip_data->domains.reverse = get_ip_rdns_domains(ip_data->addr_family, ip_data->l3cd); ip_data->domains.has_default_route_explicit = has_default_route_explicit; ip_data->domains.has_default_route_exclusive = has_default_route_explicit || (priority < 0 && has_default_route_auto); @@ -1609,10 +1621,10 @@ static void _mgr_configs_data_clear(NMDnsManager *self) { NMDnsConfigIPData *ip_data; - CList * head; + CList *head; - head = _mgr_get_ip_config_lst_head(self); - c_list_for_each_entry (ip_data, head, ip_config_lst) { + head = _mgr_get_ip_data_lst_head(self); + c_list_for_each_entry (ip_data, head, ip_data_lst) { nm_clear_g_free(&ip_data->domains.search); nm_clear_pointer(&ip_data->domains.reverse, g_strfreev); ip_data->domains.has_default_route_explicit = FALSE; @@ -1626,23 +1638,25 @@ _mgr_configs_data_clear(NMDnsManager *self) static gboolean update_dns(NMDnsManager *self, gboolean no_caching, gboolean force_emit, GError **error) { - NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE(self); - const char * nis_domain = NULL; - gs_strfreev char ** searches = NULL; - gs_strfreev char ** options = NULL; - gs_strfreev char ** nameservers = NULL; - gs_strfreev char ** nis_servers = NULL; - gboolean caching = FALSE; - gboolean do_update = TRUE; - gboolean resolv_conf_updated = FALSE; - SpawnResult result = SR_SUCCESS; - NMConfigData * data; - NMGlobalDnsConfig * global_config; + NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE(self); + const char *nis_domain = NULL; + gs_strfreev char **searches = NULL; + gs_strfreev char **options = NULL; + gs_strfreev char **nameservers = NULL; + gs_strfreev char **nis_servers = NULL; + gboolean caching = FALSE; + gboolean do_update = TRUE; + gboolean resolv_conf_updated = FALSE; + SpawnResult result = SR_SUCCESS; + NMConfigData *data; + NMGlobalDnsConfig *global_config; gs_free_error GError *local_error = NULL; GError **const p_local_error = error ? &local_error : NULL; nm_assert(!error || !*error); + priv->config_changed = FALSE; + if (priv->is_stopped) { _LOGD("update-dns: not updating resolv.conf (is stopped)"); return TRUE; @@ -1680,15 +1694,15 @@ update_dns(NMDnsManager *self, gboolean no_caching, gboolean force_emit, GError if (priv->sd_resolve_plugin) { nm_dns_plugin_update(priv->sd_resolve_plugin, global_config, - _mgr_get_ip_config_lst_head(self), + _mgr_get_ip_data_lst_head(self), priv->hostname, NULL); } /* Let any plugins do their thing first */ if (priv->plugin) { - NMDnsPlugin * plugin = priv->plugin; - const char * plugin_name = nm_dns_plugin_get_name(plugin); + NMDnsPlugin *plugin = priv->plugin; + const char *plugin_name = nm_dns_plugin_get_name(plugin); gs_free_error GError *plugin_error = NULL; if (nm_dns_plugin_is_caching(plugin)) { @@ -1702,7 +1716,7 @@ update_dns(NMDnsManager *self, gboolean no_caching, gboolean force_emit, GError _LOGD("update-dns: updating plugin %s", plugin_name); if (!nm_dns_plugin_update(plugin, global_config, - _mgr_get_ip_config_lst_head(self), + _mgr_get_ip_data_lst_head(self), priv->hostname, &plugin_error)) { _LOGW("update-dns: plugin %s update failed: %s", plugin_name, plugin_error->message); @@ -1834,51 +1848,107 @@ plugin_skip:; /*****************************************************************************/ -static void -_ip_config_dns_priority_changed(gpointer config, GParamSpec *pspec, NMDnsConfigIPData *ip_data) -{ - _ASSERT_dns_config_ip_data(ip_data); - - NM_DNS_MANAGER_GET_PRIVATE(ip_data->data->self)->ip_config_lst_need_sort = TRUE; -} - gboolean -nm_dns_manager_set_ip_config(NMDnsManager * self, - NMIPConfig * ip_config, - NMDnsIPConfigType ip_config_type) +nm_dns_manager_set_ip_config(NMDnsManager *self, + int addr_family, + gconstpointer source_tag, + const NML3ConfigData *l3cd, + NMDnsIPConfigType ip_config_type, + gboolean replace_all) { NMDnsManagerPrivate *priv; - NMDnsConfigIPData * ip_data; - NMDnsConfigData * data; + NMDnsConfigData *data; int ifindex; + gboolean changed = FALSE; + NMDnsConfigIPData *ip_data = NULL; + int dns_priority; + gboolean any_removed = FALSE; g_return_val_if_fail(NM_IS_DNS_MANAGER(self), FALSE); - g_return_val_if_fail(NM_IS_IP_CONFIG(ip_config), FALSE); + g_return_val_if_fail(!l3cd || NM_IS_L3_CONFIG_DATA(l3cd), FALSE); + g_return_val_if_fail(source_tag, FALSE); + + if (addr_family == AF_UNSPEC) { + /* Setting AF_UNSPEC is a shortcut for calling this function twice for AF_INET and + * AF_INET6. */ + if (nm_dns_manager_set_ip_config(self, + AF_INET, + source_tag, + l3cd, + ip_config_type, + replace_all)) + changed = TRUE; + if (nm_dns_manager_set_ip_config(self, + AF_INET6, + source_tag, + l3cd, + ip_config_type, + replace_all)) + changed = TRUE; + return changed; + } - ifindex = nm_ip_config_get_ifindex(ip_config); - g_return_val_if_fail(ifindex > 0, FALSE); + nm_assert_addr_family(addr_family); priv = NM_DNS_MANAGER_GET_PRIVATE(self); - data = g_hash_table_lookup(priv->configs_dict, &ifindex); - if (!data) - ip_data = NULL; - else - ip_data = _dns_config_data_find_ip_config(data, ip_config); + data = NULL; + if (l3cd) { + ifindex = nm_l3_config_data_get_ifindex(l3cd); + nm_assert(ifindex > 0); + data = g_hash_table_lookup(priv->configs_dict, &ifindex); + } + + if (data) { + NMDnsConfigIPData *ip_data_iter; + NMDnsConfigIPData *ip_data_safe; - if (ip_config_type == NM_DNS_IP_CONFIG_TYPE_REMOVED) { - if (!ip_data) - return FALSE; - /* deleting a config doesn't invalidate the configs' sort order. */ - _dns_config_ip_data_free(ip_data); - if (c_list_is_empty(&data->data_lst_head)) - g_hash_table_remove(priv->configs_dict, &ifindex); - goto changed; + c_list_for_each_entry_safe (ip_data_iter, ip_data_safe, &data->data_lst_head, data_lst) { + _ASSERT_dns_config_ip_data(ip_data_iter); + + if (ip_data_iter->source_tag != source_tag) + continue; + if (ip_data_iter->addr_family != addr_family) + continue; + + if (ip_config_type != NM_DNS_IP_CONFIG_TYPE_REMOVED && ip_data_iter->l3cd == l3cd) { + nm_assert(!ip_data); + ip_data = ip_data_iter; + continue; + } + + if (!replace_all && l3cd && ip_data_iter->l3cd != l3cd) + continue; + + if (!l3cd || ip_config_type == NM_DNS_IP_CONFIG_TYPE_REMOVED + || nm_l3_config_data_cmp_full(l3cd, + ip_data_iter->l3cd, + NM_L3_CONFIG_CMP_FLAGS_DNS + | NM_L3_CONFIG_CMP_FLAGS_ROUTES_ID) + != 0) { + changed = TRUE; + } + + any_removed = TRUE; + _dns_config_ip_data_free(ip_data_iter); + } } + if (ip_config_type == NM_DNS_IP_CONFIG_TYPE_REMOVED) + goto done; + + if (!l3cd) + goto done; + if (ip_data && ip_data->ip_config_type == ip_config_type) { /* nothing to do. */ - return FALSE; + goto done; + } + + dns_priority = _dns_config_ip_data_get_dns_priority1(l3cd, addr_family); + if (dns_priority == 0) { + /* no DNS priority for this address family. Skip it! */ + goto done; } if (!data) { @@ -1894,14 +1964,34 @@ nm_dns_manager_set_ip_config(NMDnsManager * self, priv->configs_lst_need_sort = TRUE; } - if (!ip_data) - ip_data = _dns_config_ip_data_new(data, ip_config, ip_config_type); - else + if (!ip_data) { + ip_data = _dns_config_ip_data_new(data, addr_family, source_tag, l3cd, ip_config_type); + if (!any_removed) + changed = TRUE; + } else { ip_data->ip_config_type = ip_config_type; + changed = TRUE; + } + + if (changed) + priv->ip_data_lst_need_sort = TRUE; + + nm_assert(l3cd); + nm_assert(ip_config_type != NM_DNS_IP_CONFIG_TYPE_REMOVED); + nm_assert(ip_data->addr_family == addr_family); + nm_assert(ip_data->source_tag == source_tag); + nm_assert(ip_data->l3cd == l3cd); + nm_assert(ip_data->ip_config_type == ip_config_type); + +done: + if (!changed) + return FALSE; + + priv->config_changed = TRUE; - priv->ip_config_lst_need_sort = TRUE; + if (data && c_list_is_empty(&data->data_lst_head)) + g_hash_table_remove(priv->configs_dict, data); -changed: if (!priv->updates_queue) { gs_free_error GError *error = NULL; @@ -1924,22 +2014,18 @@ nm_dns_manager_set_initial_hostname(NMDnsManager *self, const char *hostname) void nm_dns_manager_set_hostname(NMDnsManager *self, const char *hostname, gboolean skip_update) { - NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE(self); - const char * filtered = NULL; + NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE(self); /* Certain hostnames we don't want to include in resolv.conf 'searches' */ if (hostname && nm_utils_is_specific_hostname(hostname) && !strstr(hostname, ".in-addr.arpa") && strchr(hostname, '.')) { - filtered = hostname; - } + /* pass */ + } else + hostname = NULL; - if ((!priv->hostname && !filtered) - || (priv->hostname && filtered && !strcmp(priv->hostname, filtered))) + if (!nm_strdup_reset(&priv->hostname, hostname)) return; - g_free(priv->hostname); - priv->hostname = g_strdup(filtered); - if (skip_update) return; @@ -1957,6 +2043,7 @@ nm_dns_manager_begin_updates(NMDnsManager *self, const char *func) NMDnsManagerPrivate *priv; g_return_if_fail(self != NULL); + priv = NM_DNS_MANAGER_GET_PRIVATE(self); /* Save current hash when starting a new batch */ @@ -1971,9 +2058,8 @@ nm_dns_manager_begin_updates(NMDnsManager *self, const char *func) void nm_dns_manager_end_updates(NMDnsManager *self, const char *func) { - NMDnsManagerPrivate *priv; + NMDnsManagerPrivate *priv; gs_free_error GError *error = NULL; - gboolean changed; guint8 new[HASH_LEN]; g_return_if_fail(self != NULL); @@ -1982,11 +2068,11 @@ nm_dns_manager_end_updates(NMDnsManager *self, const char *func) g_return_if_fail(priv->updates_queue > 0); compute_hash(self, nm_config_data_get_global_dns_config(nm_config_get_data(priv->config)), new); - changed = (memcmp(new, priv->prev_hash, sizeof(new)) != 0) ? TRUE : FALSE; - _LOGD("(%s): DNS configuration %s", func, changed ? "changed" : "did not change"); + priv->config_changed = (memcmp(new, priv->prev_hash, sizeof(new)) != 0) ? TRUE : FALSE; + _LOGD("(%s): DNS configuration %s", func, priv->config_changed ? "changed" : "did not change"); priv->updates_queue--; - if ((priv->updates_queue > 0) || (changed == FALSE)) { + if ((priv->updates_queue > 0) || !priv->config_changed) { _LOGD("(%s): no DNS changes to commit (%d)", func, priv->updates_queue); return; } @@ -1995,8 +2081,6 @@ nm_dns_manager_end_updates(NMDnsManager *self, const char *func) _LOGD("(%s): committing DNS changes (%d)", func, priv->updates_queue); if (!update_dns(self, FALSE, FALSE, &error)) _LOGW("could not commit DNS changes: %s", error->message); - - memset(priv->prev_hash, 0, sizeof(priv->prev_hash)); } void @@ -2116,7 +2200,7 @@ _resolvconf_resolved_managed(void) return FALSE; if (S_ISLNK(st.st_mode)) { - gs_free char * full_path = NULL; + gs_free char *full_path = NULL; nm_auto_free char *real_path = NULL; /* see if resolv.conf is a symlink with a target that is @@ -2168,9 +2252,9 @@ _resolvconf_resolved_managed(void) static void init_resolv_conf_mode(NMDnsManager *self, gboolean force_reload_plugin) { - NMDnsManagerPrivate * priv = NM_DNS_MANAGER_GET_PRIVATE(self); + NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE(self); NMDnsManagerResolvConfManager rc_manager; - const char * mode; + const char *mode; gboolean systemd_resolved; gboolean param_changed = FALSE; gboolean plugin_changed = FALSE; @@ -2313,12 +2397,14 @@ again: } static void -config_changed_cb(NMConfig * config, - NMConfigData * config_data, +config_changed_cb(NMConfig *config, + NMConfigData *config_data, NMConfigChangeFlags changes, - NMConfigData * old_data, - NMDnsManager * self) + NMConfigData *old_data, + NMDnsManager *self) { + NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE(self); + if (NM_FLAGS_ANY(changes, NM_CONFIG_CHANGE_DNS_MODE | NM_CONFIG_CHANGE_RC_MANAGER | NM_CONFIG_CHANGE_CAUSE_SIGHUP | NM_CONFIG_CHANGE_CAUSE_DNS_FULL)) { @@ -2338,6 +2424,7 @@ config_changed_cb(NMConfig * config, | NM_CONFIG_CHANGE_GLOBAL_DNS_CONFIG)) { gs_free_error GError *error = NULL; + priv->config_changed = TRUE; if (!update_dns(self, FALSE, TRUE, &error)) _LOGW("could not commit DNS changes: %s", error->message); } @@ -2355,7 +2442,7 @@ _get_global_config_variant(NMGlobalDnsConfig *global) for (i = 0; i < num; i++) { GVariantBuilder conf_builder; GVariantBuilder item_builder; - const char * domain_name; + const char *domain_name; const char *const *servers; g_variant_builder_init(&conf_builder, G_VARIANT_TYPE("a{sv}")); @@ -2395,12 +2482,12 @@ _get_global_config_variant(NMGlobalDnsConfig *global) static GVariant * _get_config_variant(NMDnsManager *self) { - NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE(self); - NMGlobalDnsConfig * global_config; - gs_free char * str = NULL; - GVariantBuilder builder; - NMDnsConfigIPData * ip_data; - const CList * head; + NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE(self); + NMGlobalDnsConfig *global_config; + gs_free char *str = NULL; + GVariantBuilder builder; + NMDnsConfigIPData *ip_data; + const CList *head; gs_unref_ptrarray GPtrArray *array_domains = NULL; if (priv->config_variant) @@ -2415,51 +2502,54 @@ _get_config_variant(NMDnsManager *self) g_variant_builder_init(&builder, G_VARIANT_TYPE("aa{sv}")); - head = _mgr_get_ip_config_lst_head(self); - c_list_for_each_entry (ip_data, head, ip_config_lst) { - const NMIPConfig *ip_config = ip_data->ip_config; - GVariantBuilder entry_builder; - GVariantBuilder strv_builder; - guint i, num; - const int addr_family = nm_ip_config_get_addr_family(ip_config); - char buf[NM_UTILS_INET_ADDRSTRLEN]; - const NMIPAddr * addr; - const char * ifname; - - num = nm_ip_config_get_num_nameservers(ip_config); - if (!num) + head = _mgr_get_ip_data_lst_head(self); + c_list_for_each_entry (ip_data, head, ip_data_lst) { + GVariantBuilder entry_builder; + GVariantBuilder strv_builder; + guint num; + guint num_domains; + guint num_searches; + guint i; + char buf[NM_UTILS_INET_ADDRSTRLEN]; + const char *ifname; + gconstpointer nameservers; + + nameservers = nm_l3_config_data_get_nameservers(ip_data->l3cd, ip_data->addr_family, &num); + if (num == 0) continue; g_variant_builder_init(&entry_builder, G_VARIANT_TYPE("a{sv}")); g_variant_builder_init(&strv_builder, G_VARIANT_TYPE("as")); for (i = 0; i < num; i++) { - addr = nm_ip_config_get_nameserver(ip_config, i); - g_variant_builder_add(&strv_builder, "s", nm_utils_inet_ntop(addr_family, addr, buf)); + const NMIPAddr *addr; + + addr = nm_ip_addr_from_packed_array(ip_data->addr_family, nameservers, i); + g_variant_builder_add(&strv_builder, + "s", + nm_utils_inet_ntop(ip_data->addr_family, addr, buf)); } g_variant_builder_add(&entry_builder, "{sv}", "nameservers", g_variant_builder_end(&strv_builder)); - num = nm_ip_config_get_num_domains(ip_config); - num += nm_ip_config_get_num_searches(ip_config); + nm_l3_config_data_get_domains(ip_data->l3cd, ip_data->addr_family, &num_domains); + nm_l3_config_data_get_searches(ip_data->l3cd, ip_data->addr_family, &num_searches); + num = num_domains + num_searches; if (num > 0) { if (!array_domains) array_domains = g_ptr_array_sized_new(num); else g_ptr_array_set_size(array_domains, 0); - add_dns_domains(array_domains, ip_config, TRUE, FALSE); + add_dns_domains(array_domains, ip_data->addr_family, ip_data->l3cd, TRUE, FALSE); if (array_domains->len) { - g_variant_builder_init(&strv_builder, G_VARIANT_TYPE("as")); - for (i = 0; i < array_domains->len; i++) { - g_variant_builder_add(&strv_builder, "s", array_domains->pdata[i]); - } g_variant_builder_add(&entry_builder, "{sv}", "domains", - g_variant_builder_end(&strv_builder)); + g_variant_new_strv((const char *const *) array_domains->pdata, + array_domains->len)); } } @@ -2474,7 +2564,7 @@ _get_config_variant(NMDnsManager *self) g_variant_builder_add(&entry_builder, "{sv}", "priority", - g_variant_new_int32(nm_ip_config_get_dns_priority(ip_config))); + g_variant_new_int32(_dns_config_ip_data_get_dns_priority(ip_data))); g_variant_builder_add( &entry_builder, @@ -2494,7 +2584,7 @@ _get_config_variant(NMDnsManager *self) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMDnsManager * self = NM_DNS_MANAGER(object); + NMDnsManager *self = NM_DNS_MANAGER(object); NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE(self); switch (prop_id) { @@ -2521,7 +2611,7 @@ nm_dns_manager_init(NMDnsManager *self) _LOGT("creating..."); c_list_init(&priv->configs_lst_head); - c_list_init(&priv->ip_config_lst_head); + c_list_init(&priv->ip_data_lst_head); priv->config = g_object_ref(nm_config_get()); @@ -2531,9 +2621,7 @@ nm_dns_manager_init(NMDnsManager *self) (GDestroyNotify) _dns_config_data_free, NULL); - /* Set the initial hash */ compute_hash(self, NULL, NM_DNS_MANAGER_GET_PRIVATE(self)->hash); - g_signal_connect(G_OBJECT(priv->config), NM_CONFIG_SIGNAL_CONFIG_CHANGED, G_CALLBACK(config_changed_cb), @@ -2544,9 +2632,9 @@ nm_dns_manager_init(NMDnsManager *self) static void dispose(GObject *object) { - NMDnsManager * self = NM_DNS_MANAGER(object); + NMDnsManager *self = NM_DNS_MANAGER(object); NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE(self); - NMDnsConfigIPData * ip_data, *ip_data_safe; + NMDnsConfigIPData *ip_data, *ip_data_safe; _LOGT("disposing"); @@ -2559,7 +2647,7 @@ dispose(GObject *object) g_clear_object(&priv->sd_resolve_plugin); _clear_plugin(self); - c_list_for_each_entry_safe (ip_data, ip_data_safe, &priv->ip_config_lst_head, ip_config_lst) + c_list_for_each_entry_safe (ip_data, ip_data_safe, &priv->ip_data_lst_head, ip_data_lst) _dns_config_ip_data_free(ip_data); nm_clear_pointer(&priv->configs_dict, g_hash_table_destroy); @@ -2577,7 +2665,7 @@ dispose(GObject *object) static void finalize(GObject *object) { - NMDnsManager * self = NM_DNS_MANAGER(object); + NMDnsManager *self = NM_DNS_MANAGER(object); NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE(self); g_free(priv->hostname); @@ -2602,7 +2690,7 @@ static const NMDBusInterfaceInfoExtended interface_info_dns_manager = { static void nm_dns_manager_class_init(NMDnsManagerClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); object_class->dispose = dispose; diff --git a/src/core/dns/nm-dns-manager.h b/src/core/dns/nm-dns-manager.h index 1972a5dd..84821ece 100644 --- a/src/core/dns/nm-dns-manager.h +++ b/src/core/dns/nm-dns-manager.h @@ -8,8 +8,7 @@ #ifndef __NETWORKMANAGER_DNS_MANAGER_H__ #define __NETWORKMANAGER_DNS_MANAGER_H__ -#include "nm-ip4-config.h" -#include "nm-ip6-config.h" +#include "c-list/src/c-list.h" #include "nm-setting-connection.h" #include "nm-dns-plugin.h" @@ -28,13 +27,15 @@ struct _NMDnsManager; typedef struct { struct _NMDnsConfigData *data; - NMIPConfig * ip_config; + gconstpointer source_tag; + const NML3ConfigData *l3cd; CList data_lst; - CList ip_config_lst; + CList ip_data_lst; NMDnsIPConfigType ip_config_type; + int addr_family; struct { const char **search; - char ** reverse; + char **reverse; /* Whether "search" explicitly contains a default route "~" * or "". It is redundant information, but for faster lookup. */ @@ -97,9 +98,12 @@ NMDnsManager *nm_dns_manager_get(void); void nm_dns_manager_begin_updates(NMDnsManager *self, const char *func); void nm_dns_manager_end_updates(NMDnsManager *self, const char *func); -gboolean nm_dns_manager_set_ip_config(NMDnsManager * self, - NMIPConfig * ip_config, - NMDnsIPConfigType ip_config_type); +gboolean nm_dns_manager_set_ip_config(NMDnsManager *self, + int addr_family, + gconstpointer source_tag, + const NML3ConfigData *l3cd, + NMDnsIPConfigType ip_config_type, + gboolean replace_all); void nm_dns_manager_set_initial_hostname(NMDnsManager *self, const char *hostname); void nm_dns_manager_set_hostname(NMDnsManager *self, const char *hostname, gboolean skip_update); diff --git a/src/core/dns/nm-dns-plugin.c b/src/core/dns/nm-dns-plugin.c index e5035f06..2126da77 100644 --- a/src/core/dns/nm-dns-plugin.c +++ b/src/core/dns/nm-dns-plugin.c @@ -57,11 +57,11 @@ G_DEFINE_ABSTRACT_TYPE(NMDnsPlugin, nm_dns_plugin, G_TYPE_OBJECT) /*****************************************************************************/ gboolean -nm_dns_plugin_update(NMDnsPlugin * self, +nm_dns_plugin_update(NMDnsPlugin *self, const NMGlobalDnsConfig *global_config, - const CList * ip_config_lst_head, - const char * hostname, - GError ** error) + const CList *ip_config_lst_head, + const char *hostname, + GError **error) { g_return_val_if_fail(NM_DNS_PLUGIN_GET_CLASS(self)->update != NULL, FALSE); diff --git a/src/core/dns/nm-dns-plugin.h b/src/core/dns/nm-dns-plugin.h index 82ca7d6b..bc854cce 100644 --- a/src/core/dns/nm-dns-plugin.h +++ b/src/core/dns/nm-dns-plugin.h @@ -31,11 +31,11 @@ typedef struct { * 'global_config' is the optional global DNS * configuration. */ - gboolean (*update)(NMDnsPlugin * self, + gboolean (*update)(NMDnsPlugin *self, const NMGlobalDnsConfig *global_config, - const CList * ip_config_lst_head, - const char * hostname, - GError ** error); + const CList *ip_config_lst_head, + const char *hostname, + GError **error); void (*stop)(NMDnsPlugin *self); @@ -55,11 +55,11 @@ gboolean nm_dns_plugin_is_caching(NMDnsPlugin *self); const char *nm_dns_plugin_get_name(NMDnsPlugin *self); -gboolean nm_dns_plugin_update(NMDnsPlugin * self, +gboolean nm_dns_plugin_update(NMDnsPlugin *self, const NMGlobalDnsConfig *global_config, - const CList * ip_config_lst_head, - const char * hostname, - GError ** error); + const CList *ip_config_lst_head, + const char *hostname, + GError **error); void nm_dns_plugin_stop(NMDnsPlugin *self); diff --git a/src/core/dns/nm-dns-systemd-resolved.c b/src/core/dns/nm-dns-systemd-resolved.c index 445f8498..a043e855 100644 --- a/src/core/dns/nm-dns-systemd-resolved.c +++ b/src/core/dns/nm-dns-systemd-resolved.c @@ -21,10 +21,9 @@ #include "libnm-core-intern/nm-core-internal.h" #include "libnm-platform/nm-platform.h" #include "nm-utils.h" -#include "nm-ip4-config.h" -#include "nm-ip6-config.h" #include "nm-dbus-manager.h" #include "nm-manager.h" +#include "nm-l3-config-data.h" #include "nm-setting-connection.h" #include "devices/nm-device.h" #include "NetworkManagerUtils.h" @@ -47,8 +46,8 @@ typedef struct { typedef struct { CList request_queue_lst; - const char * operation; - GVariant * argument; + const char *operation; + GVariant *argument; NMDnsSystemdResolved *self; int ifindex; } RequestItem; @@ -56,8 +55,8 @@ typedef struct { struct _NMDnsSystemdResolvedResolveHandle { CList handle_lst; NMDnsSystemdResolved *self; - GSource * timeout_source; - GCancellable * handle_cancellable; + GSource *timeout_source; + GCancellable *handle_cancellable; gpointer callback_user_data; guint timeout_msec; bool is_failing_on_idle; @@ -76,11 +75,11 @@ struct _NMDnsSystemdResolvedResolveHandle { typedef struct { GDBusConnection *dbus_connection; - GHashTable * dirty_interfaces; - GCancellable * cancellable; - GSource * try_start_timeout_source; + GHashTable *dirty_interfaces; + GCancellable *cancellable; + GSource *try_start_timeout_source; CList request_queue_lst_head; - char * dbus_owner; + char *dbus_owner; CList handle_lst_head; guint name_owner_changed_id; bool send_updates_warn_ratelimited : 1; @@ -157,12 +156,12 @@ _request_item_free(RequestItem *request_item) static void _request_item_append(NMDnsSystemdResolved *self, - const char * operation, + const char *operation, int ifindex, - GVariant * argument) + GVariant *argument) { NMDnsSystemdResolvedPrivate *priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self); - RequestItem * request_item; + RequestItem *request_item; request_item = g_slice_new(RequestItem); *request_item = (RequestItem){ @@ -186,11 +185,11 @@ _interface_config_free(InterfaceConfig *config) static void call_done(GObject *source, GAsyncResult *r, gpointer user_data) { - gs_unref_variant GVariant *v = NULL; - gs_free_error GError * error = NULL; - NMDnsSystemdResolved * self; + gs_unref_variant GVariant *v = NULL; + gs_free_error GError *error = NULL; + NMDnsSystemdResolved *self; NMDnsSystemdResolvedPrivate *priv; - RequestItem * request_item; + RequestItem *request_item; NMLogLevel log_level; v = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), r, &error); @@ -244,42 +243,44 @@ call_done(GObject *source, GAsyncResult *r, gpointer user_data) static gboolean update_add_ip_config(NMDnsSystemdResolved *self, - GVariantBuilder * dns, - GVariantBuilder * domains, - NMDnsConfigIPData * data) + GVariantBuilder *dns, + GVariantBuilder *domains, + NMDnsConfigIPData *ip_data) { - int addr_family; - gsize addr_size; - guint i, n; - gboolean is_routing; - const char *domain; - gboolean has_config = FALSE; - - addr_family = nm_ip_config_get_addr_family(data->ip_config); - addr_size = nm_utils_addr_family_to_size(addr_family); - - if ((!data->domains.search || !data->domains.search[0]) - && !data->domains.has_default_route_exclusive && !data->domains.has_default_route) + gsize addr_size; + guint n; + guint i; + gboolean is_routing; + const char *domain; + gboolean has_config = FALSE; + gconstpointer nameservers; + + addr_size = nm_utils_addr_family_to_size(ip_data->addr_family); + + if ((!ip_data->domains.search || !ip_data->domains.search[0]) + && !ip_data->domains.has_default_route_exclusive && !ip_data->domains.has_default_route) return FALSE; - n = nm_ip_config_get_num_nameservers(data->ip_config); + nameservers = nm_l3_config_data_get_nameservers(ip_data->l3cd, ip_data->addr_family, &n); for (i = 0; i < n; i++) { g_variant_builder_open(dns, G_VARIANT_TYPE("(iay)")); - g_variant_builder_add(dns, "i", addr_family); + g_variant_builder_add(dns, "i", ip_data->addr_family); g_variant_builder_add_value( dns, - nm_g_variant_new_ay(nm_ip_config_get_nameserver(data->ip_config, i), addr_size)); + nm_g_variant_new_ay(nm_ip_addr_from_packed_array(ip_data->addr_family, nameservers, i), + addr_size)); g_variant_builder_close(dns); has_config = TRUE; } - if (!data->domains.has_default_route_explicit && data->domains.has_default_route_exclusive) { + if (!ip_data->domains.has_default_route_explicit + && ip_data->domains.has_default_route_exclusive) { g_variant_builder_add(domains, "(sb)", ".", TRUE); has_config = TRUE; } - if (data->domains.search) { - for (i = 0; data->domains.search[i]; i++) { - domain = nm_utils_parse_dns_domain(data->domains.search[i], &is_routing); + if (ip_data->domains.search) { + for (i = 0; ip_data->domains.search[i]; i++) { + domain = nm_utils_parse_dns_domain(ip_data->domains.search[i], &is_routing); g_variant_builder_add(domains, "(sb)", domain[0] ? domain : ".", is_routing); has_config = TRUE; } @@ -292,7 +293,7 @@ static void free_pending_updates(NMDnsSystemdResolved *self) { NMDnsSystemdResolvedPrivate *priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self); - RequestItem * request_item; + RequestItem *request_item; while ((request_item = c_list_first_entry(&priv->request_queue_lst_head, RequestItem, request_queue_lst))) @@ -304,11 +305,11 @@ prepare_one_interface(NMDnsSystemdResolved *self, InterfaceConfig *ic) { GVariantBuilder dns; GVariantBuilder domains; - NMCListElem * elem; + NMCListElem *elem; NMSettingConnectionMdns mdns = NM_SETTING_CONNECTION_MDNS_DEFAULT; NMSettingConnectionLlmnr llmnr = NM_SETTING_CONNECTION_LLMNR_DEFAULT; NMSettingConnectionDnsOverTls dns_over_tls = NM_SETTING_CONNECTION_DNS_OVER_TLS_DEFAULT; - const char * mdns_arg = NULL, *llmnr_arg = NULL, *dns_over_tls_arg = NULL; + const char *mdns_arg = NULL, *llmnr_arg = NULL, *dns_over_tls_arg = NULL; gboolean has_config = FALSE; gboolean has_default_route = FALSE; @@ -321,19 +322,17 @@ prepare_one_interface(NMDnsSystemdResolved *self, InterfaceConfig *ic) g_variant_builder_open(&domains, G_VARIANT_TYPE("a(sb)")); c_list_for_each_entry (elem, &ic->configs_lst_head, lst) { - NMDnsConfigIPData *data = elem->data; - NMIPConfig * ip_config = data->ip_config; + NMDnsConfigIPData *ip_data = elem->data; - has_config |= update_add_ip_config(self, &dns, &domains, data); + has_config |= update_add_ip_config(self, &dns, &domains, ip_data); - if (data->domains.has_default_route) + if (ip_data->domains.has_default_route) has_default_route = TRUE; - if (NM_IS_IP4_CONFIG(ip_config)) { - mdns = NM_MAX(mdns, nm_ip4_config_mdns_get(NM_IP4_CONFIG(ip_config))); - llmnr = NM_MAX(llmnr, nm_ip4_config_llmnr_get(NM_IP4_CONFIG(ip_config))); - dns_over_tls = - NM_MAX(dns_over_tls, nm_ip4_config_dns_over_tls_get(NM_IP4_CONFIG(ip_config))); + if (NM_IS_IPv4(ip_data->addr_family)) { + mdns = NM_MAX(mdns, nm_l3_config_data_get_mdns(ip_data->l3cd)); + llmnr = NM_MAX(llmnr, nm_l3_config_data_get_llmnr(ip_data->l3cd)); + dns_over_tls = NM_MAX(dns_over_tls, nm_l3_config_data_get_dns_over_tls(ip_data->l3cd)); } } @@ -417,8 +416,8 @@ prepare_one_interface(NMDnsSystemdResolved *self, InterfaceConfig *ic) static gboolean _ensure_resolved_running_timeout(gpointer user_data) { - NMDnsSystemdResolved * self = user_data; - NMDnsSystemdResolvedPrivate * priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self); + NMDnsSystemdResolved *self = user_data; + NMDnsSystemdResolvedPrivate *priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self); NMDnsSystemdResolvedResolveHandle *handle; nm_clear_g_source_inst(&priv->try_start_timeout_source); @@ -479,8 +478,8 @@ ensure_resolved_running(NMDnsSystemdResolved *self) static void send_updates(NMDnsSystemdResolved *self) { - NMDnsSystemdResolvedPrivate * priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self); - RequestItem * request_item; + NMDnsSystemdResolvedPrivate *priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self); + RequestItem *request_item; NMDnsSystemdResolvedResolveHandle *handle; if (!priv->send_updates_waiting) { @@ -549,31 +548,31 @@ start_resolve: } static gboolean -update(NMDnsPlugin * plugin, +update(NMDnsPlugin *plugin, const NMGlobalDnsConfig *global_config, - const CList * ip_config_lst_head, - const char * hostname, - GError ** error) + const CList *ip_data_lst_head, + const char *hostname, + GError **error) { - NMDnsSystemdResolved * self = NM_DNS_SYSTEMD_RESOLVED(plugin); - NMDnsSystemdResolvedPrivate *priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self); - gs_unref_hashtable GHashTable *interfaces = NULL; - gs_free gpointer * interfaces_keys = NULL; - guint interfaces_len; - int ifindex; - gpointer pointer; - NMDnsConfigIPData *ip_data; - GHashTableIter iter; - guint i; + NMDnsSystemdResolved *self = NM_DNS_SYSTEMD_RESOLVED(plugin); + NMDnsSystemdResolvedPrivate *priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self); + gs_unref_hashtable GHashTable *interfaces = NULL; + gs_free gpointer *interfaces_keys = NULL; + guint interfaces_len; + int ifindex; + gpointer pointer; + NMDnsConfigIPData *ip_data; + GHashTableIter iter; + guint i; interfaces = g_hash_table_new_full(nm_direct_hash, NULL, NULL, (GDestroyNotify) _interface_config_free); - c_list_for_each_entry (ip_data, ip_config_lst_head, ip_config_lst) { + c_list_for_each_entry (ip_data, ip_data_lst_head, ip_data_lst) { InterfaceConfig *ic = NULL; ifindex = ip_data->data->ifindex; - nm_assert(ifindex == nm_ip_config_get_ifindex(ip_data->ip_config)); + nm_assert(ifindex == nm_l3_config_data_get_ifindex(ip_data->l3cd)); ic = g_hash_table_lookup(interfaces, GINT_TO_POINTER(ifindex)); if (!ic) { @@ -654,16 +653,16 @@ name_owner_changed(NMDnsSystemdResolved *self, const char *owner) static void name_owner_changed_cb(GDBusConnection *connection, - const char * sender_name, - const char * object_path, - const char * interface_name, - const char * signal_name, - GVariant * parameters, + const char *sender_name, + const char *object_path, + const char *interface_name, + const char *signal_name, + GVariant *parameters, gpointer user_data) { - NMDnsSystemdResolved * self = user_data; + NMDnsSystemdResolved *self = user_data; NMDnsSystemdResolvedPrivate *priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self); - const char * new_owner; + const char *new_owner; if (!g_variant_is_of_type(parameters, G_VARIANT_TYPE("(sss)"))) return; @@ -684,7 +683,7 @@ name_owner_changed_cb(GDBusConnection *connection, static void get_name_owner_cb(const char *name_owner, GError *error, gpointer user_data) { - NMDnsSystemdResolved * self; + NMDnsSystemdResolved *self; NMDnsSystemdResolvedPrivate *priv; if (!name_owner && g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) @@ -718,13 +717,13 @@ nm_dns_systemd_resolved_is_running(NMDnsSystemdResolved *self) /*****************************************************************************/ static void -_resolve_complete(NMDnsSystemdResolvedResolveHandle * handle, +_resolve_complete(NMDnsSystemdResolvedResolveHandle *handle, const NMDnsSystemdResolvedAddressResult *names, guint names_len, guint64 flags, - GError * error) + GError *error) { - NMDnsSystemdResolved * self; + NMDnsSystemdResolved *self; NMDnsSystemdResolvedPrivate *priv; g_return_if_fail(handle && NM_IS_DNS_SYSTEMD_RESOLVED(handle->self)); @@ -760,16 +759,16 @@ _resolve_complete_error(NMDnsSystemdResolvedResolveHandle *handle, GError *error static void _resolve_handle_call_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - gs_unref_variant GVariant *v = NULL; - gs_free_error GError * error = NULL; + gs_unref_variant GVariant *v = NULL; + gs_free_error GError *error = NULL; NMDnsSystemdResolvedResolveHandle *handle; - NMDnsSystemdResolved * self; - GVariantIter * v_names_iter; + NMDnsSystemdResolved *self; + GVariantIter *v_names_iter; guint64 v_flags; int v_ifindex; - char * v_name; - gs_unref_array GArray *v_names = NULL; - gs_free char * ss = NULL; + char *v_name; + gs_unref_array GArray *v_names = NULL; + gs_free char *ss = NULL; v = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), result, &error); if (nm_utils_error_is_cancelled(error)) @@ -824,7 +823,7 @@ static gboolean _resolve_failing_on_idle(gpointer user_data) { NMDnsSystemdResolvedResolveHandle *handle = user_data; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; nm_utils_error_set_literal(&error, NM_UTILS_ERROR_NOT_READY, @@ -837,7 +836,7 @@ static gboolean _resolve_handle_timeout(gpointer user_data) { NMDnsSystemdResolvedResolveHandle *handle = user_data; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; nm_utils_error_set_literal(&error, NM_UTILS_ERROR_UNKNOWN, "timeout for request"); _resolve_complete_error(handle, error); @@ -901,16 +900,16 @@ _resolve_start(NMDnsSystemdResolved *self, NMDnsSystemdResolvedResolveHandle *ha } NMDnsSystemdResolvedResolveHandle * -nm_dns_systemd_resolved_resolve_address(NMDnsSystemdResolved * self, +nm_dns_systemd_resolved_resolve_address(NMDnsSystemdResolved *self, int ifindex, int addr_family, - const NMIPAddr * addr, + const NMIPAddr *addr, guint64 flags, guint timeout_msec, NMDnsSystemdResolvedResolveAddressCallback callback, gpointer user_data) { - NMDnsSystemdResolvedPrivate * priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self); + NMDnsSystemdResolvedPrivate *priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self); NMDnsSystemdResolvedResolveHandle *handle; char addr_str[NM_UTILS_INET_ADDRSTRLEN]; @@ -999,8 +998,8 @@ nm_dns_systemd_resolved_new(void) static void dispose(GObject *object) { - NMDnsSystemdResolved * self = NM_DNS_SYSTEMD_RESOLVED(object); - NMDnsSystemdResolvedPrivate * priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self); + NMDnsSystemdResolved *self = NM_DNS_SYSTEMD_RESOLVED(object); + NMDnsSystemdResolvedPrivate *priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self); NMDnsSystemdResolvedResolveHandle *handle; while ((handle = c_list_first_entry(&priv->handle_lst_head, @@ -1032,7 +1031,7 @@ static void nm_dns_systemd_resolved_class_init(NMDnsSystemdResolvedClass *dns_class) { NMDnsPluginClass *plugin_class = NM_DNS_PLUGIN_CLASS(dns_class); - GObjectClass * object_class = G_OBJECT_CLASS(dns_class); + GObjectClass *object_class = G_OBJECT_CLASS(dns_class); object_class->dispose = dispose; diff --git a/src/core/dns/nm-dns-systemd-resolved.h b/src/core/dns/nm-dns-systemd-resolved.h index 9f973318..02bc524c 100644 --- a/src/core/dns/nm-dns-systemd-resolved.h +++ b/src/core/dns/nm-dns-systemd-resolved.h @@ -41,19 +41,19 @@ typedef struct { } NMDnsSystemdResolvedAddressResult; typedef void (*NMDnsSystemdResolvedResolveAddressCallback)( - NMDnsSystemdResolved * self, - NMDnsSystemdResolvedResolveHandle * handle, + NMDnsSystemdResolved *self, + NMDnsSystemdResolvedResolveHandle *handle, const NMDnsSystemdResolvedAddressResult *names, guint names_len, guint64 flags, - GError * error, + GError *error, gpointer user_data); NMDnsSystemdResolvedResolveHandle * -nm_dns_systemd_resolved_resolve_address(NMDnsSystemdResolved * self, +nm_dns_systemd_resolved_resolve_address(NMDnsSystemdResolved *self, int ifindex, int addr_family, - const NMIPAddr * addr, + const NMIPAddr *addr, guint64 flags, guint timeout_msec, NMDnsSystemdResolvedResolveAddressCallback callback, diff --git a/src/core/dns/nm-dns-unbound.c b/src/core/dns/nm-dns-unbound.c index 15df3acf..f5a53332 100644 --- a/src/core/dns/nm-dns-unbound.c +++ b/src/core/dns/nm-dns-unbound.c @@ -25,14 +25,14 @@ G_DEFINE_TYPE(NMDnsUnbound, nm_dns_unbound, NM_TYPE_DNS_PLUGIN) /*****************************************************************************/ static gboolean -update(NMDnsPlugin * plugin, +update(NMDnsPlugin *plugin, const NMGlobalDnsConfig *global_config, - const CList * ip_config_lst_head, - const char * hostname, - GError ** error) + const CList *ip_config_lst_head, + const char *hostname, + GError **error) { - char * argv[] = {DNSSEC_TRIGGER_PATH, "--async", "--update", NULL}; - gs_free_error GError *local = NULL; + char *argv[] = {DNSSEC_TRIGGER_PATH, "--async", "--update", NULL}; + gs_free_error GError *local = NULL; int status; /* TODO: We currently call a script installed with the dnssec-trigger diff --git a/src/core/dnsmasq/nm-dnsmasq-manager.c b/src/core/dnsmasq/nm-dnsmasq-manager.c index e8697e81..4ab91e7e 100644 --- a/src/core/dnsmasq/nm-dnsmasq-manager.c +++ b/src/core/dnsmasq/nm-dnsmasq-manager.c @@ -17,6 +17,7 @@ #include "nm-dnsmasq-utils.h" #include "nm-utils.h" #include "NetworkManagerUtils.h" +#include "nm-l3-config-data.h" #include "libnm-core-intern/nm-core-internal.h" #define CONFDIR NMCONFDIR "/dnsmasq-shared.d" @@ -61,7 +62,7 @@ G_DEFINE_TYPE(NMDnsMasqManager, nm_dnsmasq_manager, G_TYPE_OBJECT) static void dm_watch_cb(GPid pid, int status, gpointer user_data) { - NMDnsMasqManager * manager = NM_DNSMASQ_MANAGER(user_data); + NMDnsMasqManager *manager = NM_DNSMASQ_MANAGER(user_data); NMDnsMasqManagerPrivate *priv = NM_DNSMASQ_MANAGER_GET_PRIVATE(manager); guint err; @@ -85,24 +86,28 @@ dm_watch_cb(GPid pid, int status, gpointer user_data) } static GPtrArray * -create_dm_cmd_line(const char * iface, - const NMIP4Config *ip4_config, - const char * pidfile, - gboolean announce_android_metered, - GError ** error) +create_dm_cmd_line(const char *iface, + const NML3ConfigData *l3cd, + const char *pidfile, + gboolean announce_android_metered, + GError **error) { - gs_unref_ptrarray GPtrArray *cmd = NULL; - nm_auto_free_gstring GString *s = NULL; + gs_unref_ptrarray GPtrArray *cmd = NULL; + nm_auto_free_gstring GString *s = NULL; char first[INET_ADDRSTRLEN]; char last[INET_ADDRSTRLEN]; char listen_address_s[INET_ADDRSTRLEN]; - char tmpaddr[INET_ADDRSTRLEN]; - gs_free char * error_desc = NULL; - const char * dm_binary; - const NMPlatformIP4Address * listen_address; - guint i, n; - - listen_address = nm_ip4_config_get_first_address(ip4_config); + char sbuf_addr[INET_ADDRSTRLEN]; + gs_free char *error_desc = NULL; + const char *dm_binary; + const NMPlatformIP4Address *listen_address; + const in_addr_t *ipv4arr; + const char *const *strarr; + guint n; + guint i; + + listen_address = NMP_OBJECT_CAST_IP4_ADDRESS( + nm_l3_config_data_get_first_obj(l3cd, NMP_OBJECT_TYPE_IP4_ADDRESS, NULL)); g_return_val_if_fail(listen_address, NULL); @@ -151,28 +156,28 @@ create_dm_cmd_line(const char * iface, nm_strv_ptrarray_add_string_printf(cmd, "--dhcp-range=%s,%s,60m", first, last); - if (nm_ip4_config_best_default_route_get(ip4_config)) { + if (nm_l3_config_data_get_best_default_route(l3cd, AF_INET)) { nm_strv_ptrarray_add_string_concat(cmd, "--dhcp-option=option:router,", listen_address_s); } - if ((n = nm_ip4_config_get_num_nameservers(ip4_config))) { + ipv4arr = nm_l3_config_data_get_nameservers(l3cd, AF_INET, &n); + if (n > 0) { nm_gstring_prepare(&s); g_string_append(s, "--dhcp-option=option:dns-server"); for (i = 0; i < n; i++) { g_string_append_c(s, ','); - g_string_append( - s, - _nm_utils_inet4_ntop(nm_ip4_config_get_nameserver(ip4_config, i), tmpaddr)); + g_string_append(s, _nm_utils_inet4_ntop(ipv4arr[i], sbuf_addr)); } nm_strv_ptrarray_take_gstring(cmd, &s); } - if ((n = nm_ip4_config_get_num_searches(ip4_config))) { + strarr = nm_l3_config_data_get_searches(l3cd, AF_INET, &n); + if (n > 0) { nm_gstring_prepare(&s); g_string_append(s, "--dhcp-option=option:domain-search"); for (i = 0; i < n; i++) { g_string_append_c(s, ','); - g_string_append(s, nm_ip4_config_get_search(ip4_config, i)); + g_string_append(s, strarr[i]); } nm_strv_ptrarray_take_gstring(cmd, &s); } @@ -203,10 +208,10 @@ create_dm_cmd_line(const char * iface, static void kill_existing_by_pidfile(const char *pidfile) { - char * contents = NULL; + char *contents = NULL; pid_t pid; char proc_path[250]; - char * cmdline_contents = NULL; + char *cmdline_contents = NULL; guint64 start_time; const char *exe; @@ -237,25 +242,25 @@ out: } gboolean -nm_dnsmasq_manager_start(NMDnsMasqManager *manager, - NMIP4Config * ip4_config, - gboolean announce_android_metered, - GError ** error) +nm_dnsmasq_manager_start(NMDnsMasqManager *manager, + const NML3ConfigData *l3cd, + gboolean announce_android_metered, + GError **error) { - NMDnsMasqManagerPrivate *priv; gs_unref_ptrarray GPtrArray *dm_cmd = NULL; - gs_free char * cmd_str = NULL; + gs_free char *cmd_str = NULL; + NMDnsMasqManagerPrivate *priv; g_return_val_if_fail(NM_IS_DNSMASQ_MANAGER(manager), FALSE); g_return_val_if_fail(!error || !*error, FALSE); - g_return_val_if_fail(nm_ip4_config_get_num_addresses(ip4_config) > 0, FALSE); + g_return_val_if_fail(NM_IS_L3_CONFIG_DATA(l3cd), FALSE); + g_return_val_if_fail(nm_l3_config_data_get_num_addresses(l3cd, AF_INET) > 0, FALSE); priv = NM_DNSMASQ_MANAGER_GET_PRIVATE(manager); kill_existing_by_pidfile(priv->pidfile); - dm_cmd = - create_dm_cmd_line(priv->iface, ip4_config, priv->pidfile, announce_android_metered, error); + dm_cmd = create_dm_cmd_line(priv->iface, l3cd, priv->pidfile, announce_android_metered, error); if (!dm_cmd) return FALSE; @@ -310,7 +315,7 @@ nm_dnsmasq_manager_init(NMDnsMasqManager *manager) NMDnsMasqManager * nm_dnsmasq_manager_new(const char *iface) { - NMDnsMasqManager * manager; + NMDnsMasqManager *manager; NMDnsMasqManagerPrivate *priv; manager = g_object_new(NM_TYPE_DNSMASQ_MANAGER, NULL); diff --git a/src/core/dnsmasq/nm-dnsmasq-manager.h b/src/core/dnsmasq/nm-dnsmasq-manager.h index 272d1cea..7fd4199e 100644 --- a/src/core/dnsmasq/nm-dnsmasq-manager.h +++ b/src/core/dnsmasq/nm-dnsmasq-manager.h @@ -6,8 +6,6 @@ #ifndef __NETWORKMANAGER_DNSMASQ_MANAGER_H__ #define __NETWORKMANAGER_DNSMASQ_MANAGER_H__ -#include "nm-ip4-config.h" - #define NM_TYPE_DNSMASQ_MANAGER (nm_dnsmasq_manager_get_type()) #define NM_DNSMASQ_MANAGER(obj) \ (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_DNSMASQ_MANAGER, NMDnsMasqManager)) @@ -35,10 +33,10 @@ GType nm_dnsmasq_manager_get_type(void); NMDnsMasqManager *nm_dnsmasq_manager_new(const char *iface); -gboolean nm_dnsmasq_manager_start(NMDnsMasqManager *manager, - NMIP4Config * ip4_config, - gboolean announce_android_metered, - GError ** error); +gboolean nm_dnsmasq_manager_start(NMDnsMasqManager *manager, + const NML3ConfigData *l3cd, + gboolean announce_android_metered, + GError **error); void nm_dnsmasq_manager_stop(NMDnsMasqManager *manager); diff --git a/src/core/dnsmasq/nm-dnsmasq-utils.c b/src/core/dnsmasq/nm-dnsmasq-utils.c index c2791b9e..7f799878 100644 --- a/src/core/dnsmasq/nm-dnsmasq-utils.c +++ b/src/core/dnsmasq/nm-dnsmasq-utils.c @@ -14,9 +14,9 @@ gboolean nm_dnsmasq_utils_get_range(const NMPlatformIP4Address *addr, - char * out_first, - char * out_last, - char ** out_error_desc) + char *out_first, + char *out_last, + char **out_error_desc) { guint32 host = addr->address; guint8 prefix = addr->plen; diff --git a/src/core/dnsmasq/nm-dnsmasq-utils.h b/src/core/dnsmasq/nm-dnsmasq-utils.h index 1fabc9ba..1a2b8b64 100644 --- a/src/core/dnsmasq/nm-dnsmasq-utils.h +++ b/src/core/dnsmasq/nm-dnsmasq-utils.h @@ -9,8 +9,8 @@ #include "libnm-platform/nm-platform.h" gboolean nm_dnsmasq_utils_get_range(const NMPlatformIP4Address *addr, - char * out_first, - char * out_last, - char ** out_error_desc); + char *out_first, + char *out_last, + char **out_error_desc); #endif /* __NETWORKMANAGER_DNSMASQ_UTILS_H__ */ diff --git a/src/core/main-utils.c b/src/core/main-utils.c index 48f143c3..444e122e 100644 --- a/src/core/main-utils.c +++ b/src/core/main-utils.c @@ -172,8 +172,8 @@ nm_main_utils_ensure_not_running_pidfile(const char *pidfile) gs_free char *proc_cmdline = NULL; gsize len = 0; long pid; - const char * process_name; - const char * prgname = g_get_prgname(); + const char *process_name; + const char *prgname = g_get_prgname(); g_return_if_fail(prgname); @@ -209,30 +209,21 @@ nm_main_utils_ensure_not_running_pidfile(const char *pidfile) } } -void -nm_main_utils_ensure_root() -{ - if (getuid() != 0) { - fprintf(stderr, _("You must be root to run %s!\n"), g_get_prgname() ?: ""); - exit(1); - } -} - gboolean -nm_main_utils_early_setup(const char * progname, - int * argc, - char ** argv[], +nm_main_utils_early_setup(const char *progname, + int *argc, + char **argv[], GOptionEntry *options, void (*option_context_hook)(gpointer user_data, GOptionContext *opt_ctx), gpointer option_context_hook_data, const char *summary) { GOptionContext *opt_ctx = NULL; - GError * error = NULL; + GError *error = NULL; gboolean success = FALSE; int i; - const char * opt_fmt_log_level = NULL, *opt_fmt_log_domains = NULL; - const char ** opt_loc_log_level = NULL, **opt_loc_log_domains = NULL; + const char *opt_fmt_log_level = NULL, *opt_fmt_log_domains = NULL; + const char **opt_loc_log_level = NULL, **opt_loc_log_domains = 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 diff --git a/src/core/main-utils.h b/src/core/main-utils.h index 2eb731a1..1c3e7a1c 100644 --- a/src/core/main-utils.h +++ b/src/core/main-utils.h @@ -6,8 +6,6 @@ #ifndef __MAIN_UTILS_H__ #define __MAIN_UTILS_H__ -void nm_main_utils_ensure_root(void); - void nm_main_utils_setup_signals(GMainLoop *main_loop); void nm_main_utils_ensure_statedir(void); @@ -17,18 +15,15 @@ gboolean nm_main_utils_write_pidfile(const char *pidfile); void nm_main_utils_ensure_not_running_pidfile(const char *pidfile); -gboolean nm_main_utils_early_setup(const char * progname, - int * argc, - char ** argv[], +gboolean nm_main_utils_early_setup(const char *progname, + int *argc, + char **argv[], GOptionEntry *options, void (*option_context_hook)(gpointer user_data, GOptionContext *opt_ctx), gpointer option_context_hook_data, const char *summary); -/* The following functions are not implemented inside nm-main-utils.c, instead - * main.c and nm-iface-helper.c */ - void nm_main_config_reload(int signal); #endif /* __MAIN_UTILS_H__ */ diff --git a/src/core/main.c b/src/core/main.c index 7d448a59..e39a9614 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -54,9 +54,9 @@ static struct { gboolean become_daemon; gboolean g_fatal_warnings; gboolean run_from_build_dir; - char * opt_log_level; - char * opt_log_domains; - char * pidfile; + char *opt_log_level; + char *opt_log_domains; + char *pidfile; } global_opt = { .become_daemon = TRUE, }; @@ -153,9 +153,9 @@ static int print_config(NMConfigCmdLineOptions *config_cli) { gs_unref_object NMConfig *config = NULL; - gs_free_error GError *error = NULL; - NMConfigData * config_data; - const char *const * warnings; + gs_free_error GError *error = NULL; + NMConfigData *config_data; + const char *const *warnings; nm_logging_setup("OFF", "ALL", NULL, NULL); @@ -259,7 +259,7 @@ do_early_setup(int *argc, char **argv[], NMConfigCmdLineOptions *config_cli) static gboolean _dbus_manager_init(NMConfig *config) { - NMDBusManager * busmgr; + NMDBusManager *busmgr; NMConfigConfigureAndQuitType c_a_q_type; busmgr = nm_dbus_manager_get(); @@ -269,16 +269,6 @@ _dbus_manager_init(NMConfig *config) if (c_a_q_type == NM_CONFIG_CONFIGURE_AND_QUIT_DISABLED) return nm_dbus_manager_acquire_bus(busmgr, TRUE); - if (c_a_q_type == NM_CONFIG_CONFIGURE_AND_QUIT_ENABLED) { - /* D-Bus is useless in configure and quit mode -- we're eventually dropping - * off and potential clients would have no way of knowing whether we're - * finished already or didn't start yet. - * - * But we still create a nm_dbus_manager_get_dbus_connection() D-Bus connection - * so that we can talk to other services like firewalld. */ - return nm_dbus_manager_acquire_bus(busmgr, FALSE); - } - nm_assert(c_a_q_type == NM_CONFIG_CONFIGURE_AND_QUIT_INITRD); /* in initrd we don't have D-Bus at all. Don't even try to get the G_BUS_TYPE_SYSTEM * connection. And of course don't claim the D-Bus name. */ @@ -292,16 +282,16 @@ _dbus_manager_init(NMConfig *config) int main(int argc, char *argv[]) { - gboolean success = FALSE; - NMManager * manager = NULL; - NMConfig * config; - gs_free_error GError * error = NULL; + gboolean success = FALSE; + NMManager *manager = NULL; + NMConfig *config; + gs_free_error GError *error = NULL; gboolean wrote_pidfile = FALSE; - char * bad_domains = NULL; + char *bad_domains = NULL; NMConfigCmdLineOptions *config_cli; guint sd_id = 0; - GError * error_invalid_logging_config = NULL; - const char *const * warnings; + GError *error_invalid_logging_config = NULL; + const char *const *warnings; int errsv; _nm_utils_is_manager_process = TRUE; @@ -338,8 +328,6 @@ main(int argc, char *argv[]) exit(result); } - nm_main_utils_ensure_root(); - nm_main_utils_ensure_not_running_pidfile(global_opt.pidfile); nm_main_utils_ensure_statedir(); diff --git a/src/core/meson.build b/src/core/meson.build index 6e00928e..2148d23b 100644 --- a/src/core/meson.build +++ b/src/core/meson.build @@ -54,8 +54,6 @@ libNetworkManagerBase = static_library( 'nm-l3-ipv6ll.c', 'nm-l3cfg.c', 'nm-ip-config.c', - 'nm-ip4-config.c', - 'nm-ip6-config.c', ), dependencies: [ core_default_dep, @@ -93,7 +91,6 @@ endif libNetworkManager = static_library( 'NetworkManager', sources: files( - 'devices/nm-acd-manager.c', 'devices/nm-device-6lowpan.c', 'devices/nm-device-bond.c', 'devices/nm-device-bridge.c', @@ -130,9 +127,10 @@ libNetworkManager = static_library( 'dnsmasq/nm-dnsmasq-manager.c', 'dnsmasq/nm-dnsmasq-utils.c', 'ppp/nm-ppp-manager-call.c', - 'settings/plugins/keyfile/nms-keyfile-storage.c', + 'ppp/nm-ppp-mgr.c', 'settings/plugins/keyfile/nms-keyfile-plugin.c', 'settings/plugins/keyfile/nms-keyfile-reader.c', + 'settings/plugins/keyfile/nms-keyfile-storage.c', 'settings/plugins/keyfile/nms-keyfile-utils.c', 'settings/plugins/keyfile/nms-keyfile-writer.c', 'settings/nm-agent-manager.c', @@ -169,7 +167,6 @@ libNetworkManager = static_library( 'nm-manager.c', 'nm-pacrunner-manager.c', 'nm-policy.c', - 'nm-proxy-config.c', 'nm-rfkill-manager.c', 'nm-session-monitor.c', 'nm-sleep-monitor.c', @@ -183,40 +180,6 @@ libNetworkManager = static_library( ], ) -executable( - 'nm-iface-helper', - 'nm-iface-helper.c', - dependencies: [ - core_default_dep, - glib_dep, - libudev_dep, - libndp_dep, - dl_dep, - ], - link_with: [ - libNetworkManagerBase, - libnm_core_aux_intern, - libnm_core_impl, - libnm_crypto, - libnm_systemd_core, - libnm_platform, - libnm_systemd_shared, - libnm_base, - libnm_udev_aux, - libnm_log_core, - libnm_glib_aux, - libnm_std_aux, - libn_acd, - libn_dhcp4, - libc_rbtree, - libc_siphash, - ], - link_args: ldflags_linker_script_binary, - link_depends: linker_script_binary, - install: true, - install_dir: nm_libexecdir, -) - if enable_tests test_c_flags = [] if require_root_tests diff --git a/src/core/ndisc/nm-fake-ndisc.c b/src/core/ndisc/nm-fake-ndisc.c index ffe07ab6..5aea273e 100644 --- a/src/core/ndisc/nm-fake-ndisc.c +++ b/src/core/ndisc/nm-fake-ndisc.c @@ -10,6 +10,7 @@ #include #include "nm-ndisc-private.h" +#include "nm-l3cfg.h" #define _NMLOG_PREFIX_NAME "ndisc-fake" @@ -20,10 +21,10 @@ typedef struct { guint when; NMNDiscDHCPLevel dhcp_level; - GArray * gateways; - GArray * prefixes; - GArray * dns_servers; - GArray * dns_domains; + GArray *gateways; + GArray *prefixes; + GArray *dns_servers; + GArray *dns_domains; int hop_limit; guint32 mtu; } FakeRa; @@ -97,7 +98,7 @@ find_ra(GSList *ras, guint id) } guint -nm_fake_ndisc_add_ra(NMFakeNDisc * self, +nm_fake_ndisc_add_ra(NMFakeNDisc *self, guint seconds_after_previous, NMNDiscDHCPLevel dhcp_level, int hop_limit, @@ -105,7 +106,7 @@ nm_fake_ndisc_add_ra(NMFakeNDisc * self, { NMFakeNDiscPrivate *priv = NM_FAKE_NDISC_GET_PRIVATE(self); static guint counter = 1; - FakeRa * ra; + FakeRa *ra; ra = g_malloc0(sizeof(*ra)); ra->id = counter++; @@ -124,15 +125,15 @@ nm_fake_ndisc_add_ra(NMFakeNDisc * self, } void -nm_fake_ndisc_add_gateway(NMFakeNDisc * self, +nm_fake_ndisc_add_gateway(NMFakeNDisc *self, guint ra_id, - const char * addr, + const char *addr, gint64 expiry_msec, NMIcmpv6RouterPref preference) { NMFakeNDiscPrivate *priv = NM_FAKE_NDISC_GET_PRIVATE(self); - FakeRa * ra = find_ra(priv->ras, ra_id); - NMNDiscGateway * gw; + FakeRa *ra = find_ra(priv->ras, ra_id); + NMNDiscGateway *gw; g_assert(ra); @@ -144,18 +145,18 @@ nm_fake_ndisc_add_gateway(NMFakeNDisc * self, } void -nm_fake_ndisc_add_prefix(NMFakeNDisc * self, +nm_fake_ndisc_add_prefix(NMFakeNDisc *self, guint ra_id, - const char * network, + const char *network, guint plen, - const char * gateway, + const char *gateway, gint64 expiry_msec, gint64 expiry_preferred_msec, NMIcmpv6RouterPref preference) { NMFakeNDiscPrivate *priv = NM_FAKE_NDISC_GET_PRIVATE(self); - FakeRa * ra = find_ra(priv->ras, ra_id); - FakePrefix * prefix; + FakeRa *ra = find_ra(priv->ras, ra_id); + FakePrefix *prefix; g_assert(ra); @@ -175,12 +176,12 @@ nm_fake_ndisc_add_prefix(NMFakeNDisc * self, void nm_fake_ndisc_add_dns_server(NMFakeNDisc *self, guint ra_id, - const char * address, + const char *address, gint64 expiry_msec) { NMFakeNDiscPrivate *priv = NM_FAKE_NDISC_GET_PRIVATE(self); - FakeRa * ra = find_ra(priv->ras, ra_id); - NMNDiscDNSServer * dns; + FakeRa *ra = find_ra(priv->ras, ra_id); + NMNDiscDNSServer *dns; g_assert(ra); @@ -195,8 +196,8 @@ void nm_fake_ndisc_add_dns_domain(NMFakeNDisc *self, guint ra_id, const char *domain, gint64 expiry_msec) { NMFakeNDiscPrivate *priv = NM_FAKE_NDISC_GET_PRIVATE(self); - FakeRa * ra = find_ra(priv->ras, ra_id); - NMNDiscDNSDomain * dns; + FakeRa *ra = find_ra(priv->ras, ra_id); + NMNDiscDNSDomain *dns; g_assert(ra); @@ -225,11 +226,11 @@ send_rs(NMNDisc *ndisc, GError **error) static gboolean receive_ra(gpointer user_data) { - NMFakeNDisc * self = user_data; - NMFakeNDiscPrivate * priv = NM_FAKE_NDISC_GET_PRIVATE(self); - NMNDisc * ndisc = NM_NDISC(self); + NMFakeNDisc *self = user_data; + NMFakeNDiscPrivate *priv = NM_FAKE_NDISC_GET_PRIVATE(self); + NMNDisc *ndisc = NM_NDISC(self); NMNDiscDataInternal *rdata = ndisc->rdata; - FakeRa * ra = priv->ras->data; + FakeRa *ra = priv->ras->data; NMNDiscConfigMap changed = 0; const gint64 now_msec = nm_utils_get_monotonic_timestamp_msec(); guint i; @@ -253,7 +254,7 @@ receive_ra(gpointer user_data) } for (i = 0; i < ra->prefixes->len; i++) { - FakePrefix * item = &g_array_index(ra->prefixes, FakePrefix, i); + FakePrefix *item = &g_array_index(ra->prefixes, FakePrefix, i); const NMNDiscRoute route = { .network = item->network, .plen = item->plen, @@ -322,7 +323,7 @@ static void start(NMNDisc *ndisc) { NMFakeNDiscPrivate *priv = NM_FAKE_NDISC_GET_PRIVATE(ndisc); - FakeRa * ra; + FakeRa *ra; /* Queue up the first fake RA */ g_assert(priv->ras); @@ -354,28 +355,23 @@ nm_fake_ndisc_init(NMFakeNDisc *fake_ndisc) {} NMNDisc * -nm_fake_ndisc_new(int ifindex, const char *ifname) +nm_fake_ndisc_new(NML3Cfg *l3cfg) { - return g_object_new(NM_TYPE_FAKE_NDISC, - NM_NDISC_IFINDEX, - ifindex, - NM_NDISC_IFNAME, - ifname, - NM_NDISC_NODE_TYPE, - (int) NM_NDISC_NODE_TYPE_HOST, - NM_NDISC_STABLE_TYPE, - (int) NM_UTILS_STABLE_TYPE_UUID, - NM_NDISC_NETWORK_ID, - "fake", - NM_NDISC_MAX_ADDRESSES, - NM_NDISC_MAX_ADDRESSES_DEFAULT, - NM_NDISC_ROUTER_SOLICITATIONS, - NM_NDISC_ROUTER_SOLICITATIONS_DEFAULT, - NM_NDISC_ROUTER_SOLICITATION_INTERVAL, - NM_NDISC_RFC4861_RTR_SOLICITATION_INTERVAL, - NM_NDISC_RA_TIMEOUT, - 30u, - NULL); + const NMNDiscConfig config = { + .l3cfg = g_object_ref(NM_L3CFG(l3cfg)), + .ifname = nm_l3cfg_get_ifname(l3cfg, TRUE), + .node_type = NM_NDISC_NODE_TYPE_HOST, + .stable_type = NM_UTILS_STABLE_TYPE_UUID, + .network_id = "fake", + .max_addresses = NM_NDISC_MAX_ADDRESSES_DEFAULT, + .router_solicitations = NM_NDISC_ROUTER_SOLICITATIONS_DEFAULT, + .router_solicitation_interval = NM_NDISC_RFC4861_RTR_SOLICITATION_INTERVAL, + .ra_timeout = 30u, + .addr_gen_mode = NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64, + .ip6_privacy = NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR, + }; + + return g_object_new(NM_TYPE_FAKE_NDISC, NM_NDISC_CONFIG, &config, NULL); } static void diff --git a/src/core/ndisc/nm-fake-ndisc.h b/src/core/ndisc/nm-fake-ndisc.h index 677f15fc..91c2c21c 100644 --- a/src/core/ndisc/nm-fake-ndisc.h +++ b/src/core/ndisc/nm-fake-ndisc.h @@ -24,37 +24,37 @@ typedef struct _NMFakeRNDiscClass NMFakeNDiscClass; GType nm_fake_ndisc_get_type(void); -NMNDisc *nm_fake_ndisc_new(int ifindex, const char *ifname); +NMNDisc *nm_fake_ndisc_new(NML3Cfg *l3cfg); -guint nm_fake_ndisc_add_ra(NMFakeNDisc * self, +guint nm_fake_ndisc_add_ra(NMFakeNDisc *self, guint seconds, NMNDiscDHCPLevel dhcp_level, int hop_limit, guint32 mtu); -void nm_fake_ndisc_add_gateway(NMFakeNDisc * self, +void nm_fake_ndisc_add_gateway(NMFakeNDisc *self, guint ra_id, - const char * addr, + const char *addr, gint64 expiry_msec, NMIcmpv6RouterPref preference); -void nm_fake_ndisc_add_prefix(NMFakeNDisc * self, +void nm_fake_ndisc_add_prefix(NMFakeNDisc *self, guint ra_id, - const char * network, + const char *network, guint plen, - const char * gateway, + const char *gateway, gint64 expiry_msec, gint64 expiry_preferred_msec, NMIcmpv6RouterPref preference); void nm_fake_ndisc_add_dns_server(NMFakeNDisc *self, guint ra_id, - const char * address, + const char *address, gint64 expiry_msec); void nm_fake_ndisc_add_dns_domain(NMFakeNDisc *self, guint ra_id, - const char * domain, + const char *domain, gint64 expiry_msec); void nm_fake_ndisc_emit_new_ras(NMFakeNDisc *self); diff --git a/src/core/ndisc/nm-lndp-ndisc.c b/src/core/ndisc/nm-lndp-ndisc.c index 552b0e4b..313756a6 100644 --- a/src/core/ndisc/nm-lndp-ndisc.c +++ b/src/core/ndisc/nm-lndp-ndisc.c @@ -9,16 +9,16 @@ #include #include -/* stdarg.h included because of a bug in ndp.h */ #include #include -#include "libnm-glib-aux/nm-str-buf.h" -#include "libnm-systemd-shared/nm-sd-utils-shared.h" -#include "nm-ndisc-private.h" #include "NetworkManagerUtils.h" +#include "libnm-glib-aux/nm-str-buf.h" #include "libnm-platform/nm-platform.h" #include "libnm-platform/nmp-netns.h" +#include "libnm-systemd-shared/nm-sd-utils-shared.h" +#include "nm-l3cfg.h" +#include "nm-ndisc-private.h" #define _NMLOG_PREFIX_NAME "ndisc-lndp" @@ -26,7 +26,7 @@ typedef struct { struct ndp *ndp; - GSource * event_source; + GSource *event_source; } NMLndpNDiscPrivate; /*****************************************************************************/ @@ -53,7 +53,7 @@ static gboolean send_rs(NMNDisc *ndisc, GError **error) { NMLndpNDiscPrivate *priv = NM_LNDP_NDISC_GET_PRIVATE(ndisc); - struct ndp_msg * msg; + struct ndp_msg *msg; int errsv; errsv = ndp_msg_new(&msg, NDP_MSG_RS); @@ -112,10 +112,10 @@ _route_preference_coerce(enum ndp_route_preference pref) static int receive_ra(struct ndp *ndp, struct ndp_msg *msg, gpointer user_data) { - NMNDisc * ndisc = (NMNDisc *) user_data; + NMNDisc *ndisc = (NMNDisc *) user_data; NMNDiscDataInternal *rdata = ndisc->rdata; NMNDiscConfigMap changed = 0; - struct ndp_msgra * msgra = ndp_msgra(msg); + struct ndp_msgra *msgra = ndp_msgra(msg); struct in6_addr gateway_addr; const gint64 now_msec = nm_utils_get_monotonic_timestamp_msec(); int offset; @@ -386,11 +386,11 @@ G_STATIC_ASSERT(sizeof(NMLndpDnsslOption) == 8u); static gboolean send_ra(NMNDisc *ndisc, GError **error) { - NMLndpNDiscPrivate * priv = NM_LNDP_NDISC_GET_PRIVATE(ndisc); - NMNDiscDataInternal * rdata = ndisc->rdata; + NMLndpNDiscPrivate *priv = NM_LNDP_NDISC_GET_PRIVATE(ndisc); + NMNDiscDataInternal *rdata = ndisc->rdata; int errsv; - struct in6_addr * addr; - struct ndp_msg * msg; + struct in6_addr *addr; + struct ndp_msg *msg; guint i; nm_auto_str_buf NMStrBuf sbuf = NM_STR_BUF_INIT(0, FALSE); @@ -417,7 +417,7 @@ send_ra(NMNDisc *ndisc, GError **error) /* The device let us know about all addresses that the device got * whose prefixes are suitable for delegating. Let's announce them. */ for (i = 0; i < rdata->addresses->len; i++) { - const NMNDiscAddress * address = &g_array_index(rdata->addresses, NMNDiscAddress, i); + const NMNDiscAddress *address = &g_array_index(rdata->addresses, NMNDiscAddress, i); struct nd_opt_prefix_info *prefix; prefix = _ndp_msg_add_option(msg, sizeof(*prefix)); @@ -573,9 +573,9 @@ receive_rs(struct ndp *ndp, struct ndp_msg *msg, gpointer user_data) static gboolean event_ready(int fd, GIOCondition condition, gpointer user_data) { - gs_unref_object NMNDisc *ndisc = g_object_ref(NM_NDISC(user_data)); + gs_unref_object NMNDisc *ndisc = g_object_ref(NM_NDISC(user_data)); nm_auto_pop_netns NMPNetns *netns = NULL; - NMLndpNDiscPrivate * priv = NM_LNDP_NDISC_GET_PRIVATE(ndisc); + NMLndpNDiscPrivate *priv = NM_LNDP_NDISC_GET_PRIVATE(ndisc); _LOGD("processing libndp events"); @@ -669,72 +669,39 @@ nm_lndp_ndisc_init(NMLndpNDisc *lndp_ndisc) {} NMNDisc * -nm_lndp_ndisc_new(NMPlatform * platform, - int ifindex, - const char * ifname, - NMUtilsStableType stable_type, - const char * network_id, - NMSettingIP6ConfigAddrGenMode addr_gen_mode, - NMNDiscNodeType node_type, - int max_addresses, - int router_solicitations, - int router_solicitation_interval, - guint32 ra_timeout, - GError ** error) +nm_lndp_ndisc_new(const NMNDiscConfig *config) { nm_auto_pop_netns NMPNetns *netns = NULL; - NMNDisc * ndisc; - NMLndpNDiscPrivate * priv; + gs_unref_object NMNDisc *ndisc = NULL; + NMLndpNDiscPrivate *priv; int errsv; - g_return_val_if_fail(NM_IS_PLATFORM(platform), NULL); - g_return_val_if_fail(!error || !*error, NULL); - g_return_val_if_fail(network_id, NULL); + g_return_val_if_fail(config, NULL); + g_return_val_if_fail(NM_IS_L3CFG(config->l3cfg), NULL); + g_return_val_if_fail(config->network_id, NULL); - if (!nm_platform_netns_push(platform, &netns)) - return NULL; + if (!nm_platform_netns_push(nm_l3cfg_get_platform(config->l3cfg), &netns)) { + /* The inability to change the name space is also considered + * a fatal error. We have a FD open to the file descriptor, and + * it's unclear how to handle (or recover from) a failure to setns(). */ + g_return_val_if_reached(NULL); + } - ndisc = g_object_new(NM_TYPE_LNDP_NDISC, - NM_NDISC_PLATFORM, - platform, - NM_NDISC_STABLE_TYPE, - (int) stable_type, - NM_NDISC_IFINDEX, - ifindex, - NM_NDISC_IFNAME, - ifname, - NM_NDISC_NETWORK_ID, - network_id, - NM_NDISC_ADDR_GEN_MODE, - (int) addr_gen_mode, - NM_NDISC_NODE_TYPE, - (int) node_type, - NM_NDISC_MAX_ADDRESSES, - max_addresses, - NM_NDISC_ROUTER_SOLICITATIONS, - router_solicitations, - NM_NDISC_ROUTER_SOLICITATION_INTERVAL, - router_solicitation_interval, - NM_NDISC_RA_TIMEOUT, - (guint) ra_timeout, - NULL); + ndisc = g_object_new(NM_TYPE_LNDP_NDISC, NM_NDISC_CONFIG, config, NULL); priv = NM_LNDP_NDISC_GET_PRIVATE(ndisc); errsv = ndp_open(&priv->ndp); if (errsv != 0) { - errsv = nm_errno_native(errsv); - g_set_error(error, - NM_UTILS_ERROR, - NM_UTILS_ERROR_UNKNOWN, - "failure creating libndp socket: %s (%d)", - nm_strerror_native(errsv), - errsv); - g_object_unref(ndisc); - return NULL; + /* This is serious. It might be ENOMEM or the inability to open (or modify) + * a file descriptor. In all cases there is not much reason trying to recover + * from that. File descriptors are a basic resource, that we just require (just + * like memory). */ + g_return_val_if_reached(NULL); } - return ndisc; + + return g_steal_pointer(&ndisc); } static void @@ -754,8 +721,9 @@ nm_lndp_ndisc_class_init(NMLndpNDiscClass *klass) NMNDiscClass *ndisc_class = NM_NDISC_CLASS(klass); object_class->dispose = dispose; - ndisc_class->start = start; - ndisc_class->stop = stop; - ndisc_class->send_rs = send_rs; - ndisc_class->send_ra = send_ra; + + ndisc_class->start = start; + ndisc_class->stop = stop; + ndisc_class->send_rs = send_rs; + ndisc_class->send_ra = send_ra; } diff --git a/src/core/ndisc/nm-lndp-ndisc.h b/src/core/ndisc/nm-lndp-ndisc.h index 151f4bf7..711a95e1 100644 --- a/src/core/ndisc/nm-lndp-ndisc.h +++ b/src/core/ndisc/nm-lndp-ndisc.h @@ -23,17 +23,6 @@ typedef struct _NMLndpNDiscClass NMLndpNDiscClass; GType nm_lndp_ndisc_get_type(void); -NMNDisc *nm_lndp_ndisc_new(NMPlatform * platform, - int ifindex, - const char * ifname, - NMUtilsStableType stable_type, - const char * network_id, - NMSettingIP6ConfigAddrGenMode addr_gen_mode, - NMNDiscNodeType node_type, - int max_addresses, - int router_solicitations, - int router_solicitation_interval, - guint32 ra_timeout, - GError ** error); +NMNDisc *nm_lndp_ndisc_new(const NMNDiscConfig *config); #endif /* __NETWORKMANAGER_LNDP_NDISC_H__ */ diff --git a/src/core/ndisc/nm-ndisc-private.h b/src/core/ndisc/nm-ndisc-private.h index 04739124..1479e566 100644 --- a/src/core/ndisc/nm-ndisc-private.h +++ b/src/core/ndisc/nm-ndisc-private.h @@ -45,7 +45,7 @@ gboolean nm_ndisc_add_dns_domain(NMNDisc *ndisc, const NMNDiscDNSDomain *new_ite if (nm_logging_enabled(__level, __domain)) { \ NMNDisc *const __self = (self); \ char __prefix[64]; \ - const char * __ifname = __self ? nm_ndisc_get_ifname(__self) : NULL; \ + const char *__ifname = __self ? nm_ndisc_get_ifname(__self) : NULL; \ \ _nm_log(__level, \ __domain, \ diff --git a/src/core/ndisc/nm-ndisc.c b/src/core/ndisc/nm-ndisc.c index d7b1a2e1..969eacfa 100644 --- a/src/core/ndisc/nm-ndisc.c +++ b/src/core/ndisc/nm-ndisc.c @@ -7,16 +7,17 @@ #include "nm-ndisc.h" -#include #include +#include -#include "nm-setting-ip6-config.h" - -#include "nm-ndisc-private.h" -#include "nm-utils.h" +#include "libnm-platform/nm-platform-utils.h" #include "libnm-platform/nm-platform.h" #include "libnm-platform/nmp-netns.h" #include "nm-l3-config-data.h" +#include "nm-l3cfg.h" +#include "nm-ndisc-private.h" +#include "nm-setting-ip6-config.h" +#include "nm-utils.h" #define _NMLOG_PREFIX_NAME "ndisc" @@ -38,6 +39,8 @@ struct _NMNDiscPrivate { /* this *must* be the first field. */ NMNDiscDataInternal rdata; + const NML3ConfigData *l3cd; + char *last_error; GSource *ra_timeout_source; @@ -54,38 +57,27 @@ struct _NMNDiscPrivate { GSource *timeout_expire_source; NMUtilsIPv6IfaceId iid; + gboolean iid_is_token; - /* immutable values: */ - int ifindex; - char * ifname; - char * network_id; - guint max_addresses; - NMSettingIP6ConfigAddrGenMode addr_gen_mode; - NMUtilsStableType stable_type; - guint32 ra_timeout; - gint32 router_solicitations; - gint32 router_solicitation_interval; - NMNDiscNodeType node_type; - - NMPlatform *platform; - NMPNetns * netns; + /* immutable values from here on: */ + + union { + const NMNDiscConfig config; + NMNDiscConfig config_; + }; + + NMPNetns *netns; }; typedef struct _NMNDiscPrivate NMNDiscPrivate; -NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_PLATFORM, - PROP_IFINDEX, - PROP_IFNAME, - PROP_STABLE_TYPE, - PROP_NETWORK_ID, - PROP_ADDR_GEN_MODE, - PROP_MAX_ADDRESSES, - PROP_RA_TIMEOUT, - PROP_ROUTER_SOLICITATIONS, - PROP_ROUTER_SOLICITATION_INTERVAL, - PROP_NODE_TYPE, ); +NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_CONFIG, ); -enum { CONFIG_RECEIVED, RA_TIMEOUT_SIGNAL, LAST_SIGNAL }; +enum { + CONFIG_RECEIVED, + RA_TIMEOUT_SIGNAL, + LAST_SIGNAL, +}; static guint signals[LAST_SIGNAL] = {0}; @@ -111,18 +103,14 @@ NM_UTILS_LOOKUP_STR_DEFINE(nm_ndisc_dhcp_level_to_string, /*****************************************************************************/ NML3ConfigData * -nm_ndisc_data_to_l3cd(NMDedupMultiIndex * multi_idx, +nm_ndisc_data_to_l3cd(NMDedupMultiIndex *multi_idx, int ifindex, - const NMNDiscData * rdata, + const NMNDiscData *rdata, NMSettingIP6ConfigPrivacy ip6_privacy, - guint32 route_table, - guint32 route_metric, - gboolean kernel_support_rta_pref, - gboolean kernel_support_extended_ifa_flags) + NMUtilsIPv6IfaceId *token) { nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; guint32 ifa_flags; - guint8 plen; guint i; const gint32 now_sec = nm_utils_get_monotonic_timestamp_sec(); @@ -130,20 +118,11 @@ nm_ndisc_data_to_l3cd(NMDedupMultiIndex * multi_idx, nm_l3_config_data_set_ip6_privacy(l3cd, ip6_privacy); - /* Check, whether kernel is 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. */ - ifa_flags = 0; - if (kernel_support_extended_ifa_flags) { - ifa_flags |= IFA_F_NOPREFIXROUTE; - if (NM_IN_SET(ip6_privacy, - NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR, - NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR)) - ifa_flags |= IFA_F_MANAGETEMPADDR; - plen = 64; - } else - plen = 128; + ifa_flags = IFA_F_NOPREFIXROUTE; + if (NM_IN_SET(ip6_privacy, + NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR, + NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR)) + ifa_flags |= IFA_F_MANAGETEMPADDR; for (i = 0; i < rdata->addresses_n; i++) { const NMNDiscAddress *ndisc_addr = &rdata->addresses[i]; @@ -152,7 +131,7 @@ nm_ndisc_data_to_l3cd(NMDedupMultiIndex * multi_idx, a = (NMPlatformIP6Address){ .ifindex = ifindex, .address = ndisc_addr->address, - .plen = plen, + .plen = 64, .timestamp = now_sec, .lifetime = _nm_ndisc_lifetime_from_expiry(((gint64) now_sec) * 1000, ndisc_addr->expiry_msec, @@ -178,8 +157,10 @@ nm_ndisc_data_to_l3cd(NMDedupMultiIndex * multi_idx, .plen = ndisc_route->plen, .gateway = ndisc_route->gateway, .rt_source = NM_IP_CONFIG_SOURCE_NDISC, - .table_coerced = nm_platform_route_table_coerce(route_table), - .metric = route_metric, + .table_any = TRUE, + .table_coerced = 0, + .metric_any = TRUE, + .metric = 0, .rt_pref = ndisc_route->preference, }; nm_assert((NMIcmpv6RouterPref) r.rt_pref == ndisc_route->preference); @@ -188,12 +169,13 @@ nm_ndisc_data_to_l3cd(NMDedupMultiIndex * multi_idx, } if (rdata->gateways_n > 0) { - const NMIcmpv6RouterPref first_pref = rdata->gateways[0].preference; - NMPlatformIP6Route r = { + NMPlatformIP6Route r = { .rt_source = NM_IP_CONFIG_SOURCE_NDISC, .ifindex = ifindex, - .table_coerced = nm_platform_route_table_coerce(route_table), - .metric = route_metric, + .table_any = TRUE, + .table_coerced = 0, + .metric_any = TRUE, + .metric = 0, }; for (i = 0; i < rdata->gateways_n; i++) { @@ -201,13 +183,6 @@ nm_ndisc_data_to_l3cd(NMDedupMultiIndex * multi_idx, r.rt_pref = rdata->gateways[i].preference; nm_assert((NMIcmpv6RouterPref) r.rt_pref == rdata->gateways[i].preference); nm_l3_config_data_add_route_6(l3cd, &r); - - if (first_pref != rdata->gateways[i].preference && !kernel_support_rta_pref) { - /* We are unable to configure a router preference. Hence, we skip all gateways - * with a different preference from the first gateway. Note, that the gateways - * are sorted in order of highest to lowest preference. */ - break; - } } } @@ -222,6 +197,8 @@ nm_ndisc_data_to_l3cd(NMDedupMultiIndex * multi_idx, nm_l3_config_data_set_ndisc_retrans_timer_msec(l3cd, rdata->retrans_timer_ms); nm_l3_config_data_set_ip6_mtu(l3cd, rdata->mtu); + if (token) + nm_l3_config_data_set_ip6_token(l3cd, *token); return g_steal_pointer(&l3cd); } @@ -315,7 +292,7 @@ nm_ndisc_get_ifindex(NMNDisc *self) { g_return_val_if_fail(NM_IS_NDISC(self), 0); - return NM_NDISC_GET_PRIVATE(self)->ifindex; + return nm_l3cfg_get_ifindex(NM_NDISC_GET_PRIVATE(self)->config.l3cfg); } const char * @@ -323,7 +300,7 @@ nm_ndisc_get_ifname(NMNDisc *self) { g_return_val_if_fail(NM_IS_NDISC(self), NULL); - return NM_NDISC_GET_PRIVATE(self)->ifname; + return NM_NDISC_GET_PRIVATE(self)->config.ifname; } NMNDiscNodeType @@ -331,7 +308,7 @@ nm_ndisc_get_node_type(NMNDisc *self) { g_return_val_if_fail(NM_IS_NDISC(self), NM_NDISC_NODE_TYPE_INVALID); - return NM_NDISC_GET_PRIVATE(self)->node_type; + return NM_NDISC_GET_PRIVATE(self)->config.node_type; } /*****************************************************************************/ @@ -391,15 +368,28 @@ _data_complete(NMNDiscDataInternal *data) return &data->public; } -void +static void nm_ndisc_emit_config_change(NMNDisc *self, NMNDiscConfigMap changed) { + NMNDiscPrivate *priv = NM_NDISC_GET_PRIVATE(self); + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; + const NMNDiscData *rdata; + _config_changed_log(self, changed); - g_signal_emit(self, - signals[CONFIG_RECEIVED], - 0, - _data_complete(&NM_NDISC_GET_PRIVATE(self)->rdata), - (guint) changed); + + rdata = _data_complete(&NM_NDISC_GET_PRIVATE(self)->rdata), + + l3cd = nm_ndisc_data_to_l3cd(nm_l3cfg_get_multi_idx(priv->config.l3cfg), + nm_l3cfg_get_ifindex(priv->config.l3cfg), + rdata, + priv->config.ip6_privacy, + priv->iid_is_token ? &priv->iid : NULL); + l3cd = nm_l3_config_data_seal(l3cd); + + if (!nm_l3_config_data_equal(priv->l3cd, l3cd)) + NM_SWAP(&priv->l3cd, &l3cd); + + g_signal_emit(self, signals[CONFIG_RECEIVED], 0, rdata, (guint) changed, priv->l3cd); } /*****************************************************************************/ @@ -474,16 +464,16 @@ static gboolean complete_address(NMNDisc *ndisc, NMNDiscAddress *addr) { NMNDiscPrivate *priv; - GError * error = NULL; + GError *error = NULL; g_return_val_if_fail(NM_IS_NDISC(ndisc), FALSE); priv = NM_NDISC_GET_PRIVATE(ndisc); - if (priv->addr_gen_mode == NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY) { - if (!nm_utils_ipv6_addr_set_stable_privacy_may_fail(priv->stable_type, + if (priv->config.addr_gen_mode == NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY) { + if (!nm_utils_ipv6_addr_set_stable_privacy_may_fail(priv->config.stable_type, &addr->address, - priv->ifname, - priv->network_id, + priv->config.ifname, + priv->config.network_id, addr->dad_counter++, &error)) { _LOGW("complete-address: failed to generate an stable-privacy address: %s", @@ -511,15 +501,15 @@ complete_address(NMNDisc *ndisc, NMNDiscAddress *addr) } static gboolean -nm_ndisc_add_address(NMNDisc * ndisc, +nm_ndisc_add_address(NMNDisc *ndisc, const NMNDiscAddress *new_item, gint64 now_msec, gboolean from_ra) { - NMNDiscPrivate * priv = NM_NDISC_GET_PRIVATE(ndisc); + NMNDiscPrivate *priv = NM_NDISC_GET_PRIVATE(ndisc); NMNDiscDataInternal *rdata = &priv->rdata; - NMNDiscAddress * new2; - NMNDiscAddress * existing = NULL; + NMNDiscAddress *new2; + NMNDiscAddress *existing = NULL; guint i; nm_assert(new_item); @@ -608,7 +598,7 @@ nm_ndisc_add_address(NMNDisc * ndisc, * what the kernel does, because it considers *all* addresses (including * static and other temporary addresses). **/ - if (rdata->addresses->len >= priv->max_addresses) + if (rdata->addresses->len >= priv->config.max_addresses) return FALSE; if (new_item->expiry_msec <= now_msec) @@ -640,7 +630,7 @@ nm_ndisc_complete_and_add_address(NMNDisc *ndisc, const NMNDiscAddress *new_item gboolean nm_ndisc_add_route(NMNDisc *ndisc, const NMNDiscRoute *new_item, gint64 now_msec) { - NMNDiscPrivate * priv; + NMNDiscPrivate *priv; NMNDiscDataInternal *rdata; guint i; guint insert_idx = G_MAXUINT; @@ -709,7 +699,7 @@ nm_ndisc_add_route(NMNDisc *ndisc, const NMNDiscRoute *new_item, gint64 now_msec gboolean nm_ndisc_add_dns_server(NMNDisc *ndisc, const NMNDiscDNSServer *new_item, gint64 now_msec) { - NMNDiscPrivate * priv; + NMNDiscPrivate *priv; NMNDiscDataInternal *rdata; guint i; @@ -747,9 +737,9 @@ nm_ndisc_add_dns_server(NMNDisc *ndisc, const NMNDiscDNSServer *new_item, gint64 gboolean nm_ndisc_add_dns_domain(NMNDisc *ndisc, const NMNDiscDNSDomain *new_item, gint64 now_msec) { - NMNDiscPrivate * priv; + NMNDiscPrivate *priv; NMNDiscDataInternal *rdata; - NMNDiscDNSDomain * item; + NMNDiscDNSDomain *item; guint i; priv = NM_NDISC_GET_PRIVATE(ndisc); @@ -824,13 +814,13 @@ solicit_retransmit_time_jitter(gint32 solicit_retransmit_time_msec) static gboolean solicit_timer_cb(gpointer user_data) { - const gint32 TIMEOUT_APPROX_THRESHOLD_SEC = 10000; - nm_auto_pop_netns NMPNetns *netns = NULL; - NMNDisc * ndisc = user_data; - NMNDiscClass * klass = NM_NDISC_GET_CLASS(ndisc); - NMNDiscPrivate * priv = NM_NDISC_GET_PRIVATE(ndisc); - gs_free_error GError *error = NULL; - gint32 timeout_msec; + const gint32 TIMEOUT_APPROX_THRESHOLD_SEC = 10000; + nm_auto_pop_netns NMPNetns *netns = NULL; + NMNDisc *ndisc = user_data; + NMNDiscClass *klass = NM_NDISC_GET_CLASS(ndisc); + NMNDiscPrivate *priv = NM_NDISC_GET_PRIVATE(ndisc); + gs_free_error GError *error = NULL; + gint32 timeout_msec; if (!nm_ndisc_netns_push(ndisc, &netns)) { nm_utils_error_set(&error, @@ -899,7 +889,7 @@ solicit_timer_start(NMNDisc *ndisc) g_random_int() % ((guint32) (NM_NDISC_RFC4861_MAX_RTR_SOLICITATION_DELAY * 1000 / 4)); _LOGD("solicit: schedule sending first solicitation (of %d) in %.3f seconds", - priv->router_solicitations, + priv->config.router_solicitations, ((double) delay_msec) / 1000); priv->solicit_retransmit_time_msec = 0; @@ -913,9 +903,9 @@ static gboolean announce_router(NMNDisc *ndisc) { nm_auto_pop_netns NMPNetns *netns = NULL; - NMNDiscClass * klass = NM_NDISC_GET_CLASS(ndisc); - NMNDiscPrivate * priv = NM_NDISC_GET_PRIVATE(ndisc); - GError * error = NULL; + NMNDiscClass *klass = NM_NDISC_GET_CLASS(ndisc); + NMNDiscPrivate *priv = NM_NDISC_GET_PRIVATE(ndisc); + GError *error = NULL; if (!nm_ndisc_netns_push(ndisc, &netns)) return G_SOURCE_REMOVE; @@ -997,30 +987,82 @@ announce_router_solicited(NMNDisc *ndisc) /*****************************************************************************/ void -nm_ndisc_set_config(NMNDisc * ndisc, - const GArray *addresses, - const GArray *dns_servers, - const GArray *dns_domains) +nm_ndisc_set_config(NMNDisc *ndisc, const NML3ConfigData *l3cd) { - gboolean changed = FALSE; - guint i; + gboolean changed = FALSE; + const struct in6_addr *in6arr; + const char *const *strvarr; + NMDedupMultiIter iter; + const NMPObject *obj; + guint len; + guint i; + + nm_assert(NM_IS_NDISC(ndisc)); + nm_assert(nm_ndisc_get_node_type(ndisc) == NM_NDISC_NODE_TYPE_ROUTER); + + nm_l3_config_data_iter_obj_for_each (&iter, l3cd, &obj, NMP_OBJECT_TYPE_IP6_ADDRESS) { + const NMPlatformIP6Address *addr = NMP_OBJECT_CAST_IP6_ADDRESS(obj); + guint32 preferred; + guint32 lifetime; + NMNDiscAddress a; + + if (IN6_IS_ADDR_UNSPECIFIED(&addr->address) || IN6_IS_ADDR_LINKLOCAL(&addr->address)) + continue; + + if (addr->n_ifa_flags & IFA_F_TENTATIVE || addr->n_ifa_flags & IFA_F_DADFAILED) + continue; + + if (addr->plen != 64) + continue; - for (i = 0; i < addresses->len; i++) { - if (nm_ndisc_add_address(ndisc, &g_array_index(addresses, NMNDiscAddress, i), 0, FALSE)) + lifetime = nmp_utils_lifetime_get(addr->timestamp, + addr->lifetime, + addr->preferred, + NM_NDISC_EXPIRY_BASE_TIMESTAMP / 1000, + &preferred); + if (!lifetime) + continue; + + a = (NMNDiscAddress){ + .address = addr->address, + .expiry_msec = _nm_ndisc_lifetime_to_expiry(NM_NDISC_EXPIRY_BASE_TIMESTAMP, lifetime), + .expiry_preferred_msec = + _nm_ndisc_lifetime_to_expiry(NM_NDISC_EXPIRY_BASE_TIMESTAMP, preferred), + }; + + if (nm_ndisc_add_address(ndisc, &a, 0, FALSE)) changed = TRUE; } - for (i = 0; i < dns_servers->len; i++) { - if (nm_ndisc_add_dns_server(ndisc, - &g_array_index(dns_servers, NMNDiscDNSServer, i), - G_MININT64)) + in6arr = NULL; + len = 0; + if (l3cd) + in6arr = nm_l3_config_data_get_nameservers(l3cd, AF_INET6, &len); + for (i = 0; i < len; i++) { + NMNDiscDNSServer n; + + n = (NMNDiscDNSServer){ + .address = in6arr[i], + .expiry_msec = _nm_ndisc_lifetime_to_expiry(NM_NDISC_EXPIRY_BASE_TIMESTAMP, + NM_NDISC_ROUTER_LIFETIME), + }; + if (nm_ndisc_add_dns_server(ndisc, &n, G_MININT64)) changed = TRUE; } - for (i = 0; i < dns_domains->len; i++) { - if (nm_ndisc_add_dns_domain(ndisc, - &g_array_index(dns_domains, NMNDiscDNSDomain, i), - G_MININT64)) + strvarr = NULL; + len = 0; + if (l3cd) + strvarr = nm_l3_config_data_get_searches(l3cd, AF_INET6, &len); + for (i = 0; i < len; i++) { + NMNDiscDNSDomain n; + + n = (NMNDiscDNSDomain){ + .domain = (char *) strvarr[i], + .expiry_msec = _nm_ndisc_lifetime_to_expiry(NM_NDISC_EXPIRY_BASE_TIMESTAMP, + NM_NDISC_ROUTER_LIFETIME), + }; + if (nm_ndisc_add_dns_domain(ndisc, &n, G_MININT64)) changed = TRUE; } @@ -1048,20 +1090,21 @@ nm_ndisc_set_config(NMNDisc * ndisc, * Returns: %TRUE if addresses need to be regenerated, %FALSE otherwise. **/ gboolean -nm_ndisc_set_iid(NMNDisc *ndisc, const NMUtilsIPv6IfaceId iid) +nm_ndisc_set_iid(NMNDisc *ndisc, const NMUtilsIPv6IfaceId iid, gboolean is_token) { - NMNDiscPrivate * priv; + NMNDiscPrivate *priv; NMNDiscDataInternal *rdata; g_return_val_if_fail(NM_IS_NDISC(ndisc), FALSE); - priv = NM_NDISC_GET_PRIVATE(ndisc); - rdata = &priv->rdata; + priv = NM_NDISC_GET_PRIVATE(ndisc); + priv->iid_is_token = is_token; + rdata = &priv->rdata; if (priv->iid.id != iid.id) { priv->iid = iid; - if (priv->addr_gen_mode == NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY) + if (priv->config.addr_gen_mode == NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY) return FALSE; if (rdata->addresses->len) { @@ -1090,7 +1133,7 @@ void nm_ndisc_start(NMNDisc *ndisc) { nm_auto_pop_netns NMPNetns *netns = NULL; - NMNDiscPrivate * priv; + NMNDiscPrivate *priv; g_return_if_fail(NM_IS_NDISC(ndisc)); @@ -1100,26 +1143,26 @@ nm_ndisc_start(NMNDisc *ndisc) nm_assert(!priv->ra_timeout_source); _LOGD("starting neighbor discovery for ifindex %d%s", - priv->ifindex, - priv->node_type == NM_NDISC_NODE_TYPE_HOST ? " (solicit)" : " (announce)"); + nm_l3cfg_get_ifindex(priv->config.l3cfg), + priv->config.node_type == NM_NDISC_NODE_TYPE_HOST ? " (solicit)" : " (announce)"); if (!nm_ndisc_netns_push(ndisc, &netns)) return; NM_NDISC_GET_CLASS(ndisc)->start(ndisc); - if (priv->node_type == NM_NDISC_NODE_TYPE_HOST) { + if (priv->config.node_type == NM_NDISC_NODE_TYPE_HOST) { G_STATIC_ASSERT_EXPR(NM_RA_TIMEOUT_DEFAULT == 0); G_STATIC_ASSERT_EXPR(NM_RA_TIMEOUT_INFINITY == G_MAXINT32); - nm_assert(priv->ra_timeout > 0u); - nm_assert(priv->ra_timeout <= NM_RA_TIMEOUT_INFINITY); + nm_assert(priv->config.ra_timeout > 0u); + nm_assert(priv->config.ra_timeout <= NM_RA_TIMEOUT_INFINITY); - if (priv->ra_timeout < NM_RA_TIMEOUT_INFINITY) { + if (priv->config.ra_timeout < NM_RA_TIMEOUT_INFINITY) { guint timeout_msec; - _LOGD("scheduling RA timeout in %u seconds", priv->ra_timeout); - if (priv->ra_timeout < G_MAXUINT / 1000u) - timeout_msec = priv->ra_timeout * 1000u; + _LOGD("scheduling RA timeout in %u seconds", priv->config.ra_timeout); + if (priv->config.ra_timeout < G_MAXUINT / 1000u) + timeout_msec = priv->config.ra_timeout * 1000u; else timeout_msec = G_MAXUINT; priv->ra_timeout_source = nm_g_timeout_add_source(timeout_msec, ra_timeout_cb, ndisc); @@ -1129,8 +1172,8 @@ nm_ndisc_start(NMNDisc *ndisc) return; } - nm_assert(priv->ra_timeout == 0u); - nm_assert(priv->node_type == NM_NDISC_NODE_TYPE_ROUTER); + nm_assert(priv->config.ra_timeout == 0u); + nm_assert(priv->config.node_type == NM_NDISC_NODE_TYPE_ROUTER); announce_router_initial(ndisc); } @@ -1138,8 +1181,8 @@ void nm_ndisc_stop(NMNDisc *ndisc) { nm_auto_pop_netns NMPNetns *netns = NULL; - NMNDiscDataInternal * rdata; - NMNDiscPrivate * priv; + NMNDiscDataInternal *rdata; + NMNDiscPrivate *priv; g_return_if_fail(NM_IS_NDISC(ndisc)); @@ -1147,7 +1190,7 @@ nm_ndisc_stop(NMNDisc *ndisc) nm_assert(NM_NDISC_GET_CLASS(ndisc)->stop); - _LOGD("stopping neighbor discovery for ifindex %d", priv->ifindex); + _LOGD("stopping neighbor discovery for ifindex %d", nm_l3cfg_get_ifindex(priv->config.l3cfg)); if (!nm_ndisc_netns_push(ndisc, &netns)) return; @@ -1230,7 +1273,7 @@ config_map_to_string(NMNDiscConfigMap map, char *p) static void _config_changed_log(NMNDisc *ndisc, NMNDiscConfigMap changed) { - NMNDiscPrivate * priv; + NMNDiscPrivate *priv; NMNDiscDataInternal *rdata; guint i; char changedstr[CONFIG_MAP_MAX_STR]; @@ -1319,7 +1362,7 @@ static void clean_gateways(NMNDisc *ndisc, gint64 now_msec, NMNDiscConfigMap *changed, gint64 *next_msec) { NMNDiscDataInternal *rdata = &NM_NDISC_GET_PRIVATE(ndisc)->rdata; - NMNDiscGateway * arr; + NMNDiscGateway *arr; guint i; guint j; @@ -1350,9 +1393,9 @@ clean_gateways(NMNDisc *ndisc, gint64 now_msec, NMNDiscConfigMap *changed, gint6 static void clean_addresses(NMNDisc *ndisc, gint64 now_msec, NMNDiscConfigMap *changed, gint64 *next_msec) { - NMNDiscPrivate * priv = NM_NDISC_GET_PRIVATE(ndisc); + NMNDiscPrivate *priv = NM_NDISC_GET_PRIVATE(ndisc); NMNDiscDataInternal *rdata = &NM_NDISC_GET_PRIVATE(ndisc)->rdata; - NMNDiscAddress * arr; + NMNDiscAddress *arr; guint i; guint j; @@ -1374,7 +1417,7 @@ clean_addresses(NMNDisc *ndisc, gint64 now_msec, NMNDiscConfigMap *changed, gint g_array_set_size(rdata->addresses, j); } - if (_array_set_size_max(rdata->gateways, priv->max_addresses)) + if (_array_set_size_max(rdata->gateways, priv->config.max_addresses)) *changed |= NM_NDISC_CONFIG_ADDRESSES; } @@ -1382,7 +1425,7 @@ static void clean_routes(NMNDisc *ndisc, gint64 now_msec, NMNDiscConfigMap *changed, gint64 *next_msec) { NMNDiscDataInternal *rdata = &NM_NDISC_GET_PRIVATE(ndisc)->rdata; - NMNDiscRoute * arr; + NMNDiscRoute *arr; guint i; guint j; @@ -1412,7 +1455,7 @@ static void clean_dns_servers(NMNDisc *ndisc, gint64 now_msec, NMNDiscConfigMap *changed, gint64 *next_msec) { NMNDiscDataInternal *rdata = &NM_NDISC_GET_PRIVATE(ndisc)->rdata; - NMNDiscDNSServer * arr; + NMNDiscDNSServer *arr; guint i; guint j; @@ -1442,7 +1485,7 @@ static void clean_dns_domains(NMNDisc *ndisc, gint64 now_msec, NMNDiscConfigMap *changed, gint64 *next_msec) { NMNDiscDataInternal *rdata = &NM_NDISC_GET_PRIVATE(ndisc)->rdata; - NMNDiscDNSDomain * arr; + NMNDiscDNSDomain *arr; guint i; guint j; @@ -1549,7 +1592,7 @@ _calc_pre_expiry_rs_msec_worker(gint64 *earliest_expiry_msec, static gint64 calc_pre_expiry_rs_msec(NMNDisc *ndisc) { - NMNDiscPrivate * priv = NM_NDISC_GET_PRIVATE(ndisc); + NMNDiscPrivate *priv = NM_NDISC_GET_PRIVATE(ndisc); NMNDiscDataInternal *rdata = &priv->rdata; gint64 expiry_msec = NM_NDISC_EXPIRY_INFINITY; guint i; @@ -1657,10 +1700,10 @@ ipv6_sysctl_get(NMPlatform *platform, void nm_ndisc_get_sysctl(NMPlatform *platform, const char *ifname, - int * out_max_addresses, - int * out_router_solicitations, - int * out_router_solicitation_interval, - guint32 * out_default_ra_timeout) + int *out_max_addresses, + int *out_router_solicitations, + int *out_router_solicitation_interval, + guint32 *out_default_ra_timeout) { int router_solicitation_interval = 0; int router_solicitations = 0; @@ -1699,86 +1742,88 @@ nm_ndisc_get_sysctl(NMPlatform *platform, /*****************************************************************************/ +static void +_config_clear(NMNDiscConfig *config) +{ + g_clear_object(&config->l3cfg); + nm_clear_g_free((gpointer *) &config->ifname); + nm_clear_g_free((gpointer *) &config->network_id); +} + +static void +_config_init(NMNDiscConfig *config, const NMNDiscConfig *src) +{ + nm_assert(config); + g_return_if_fail(src); + + /* we only allow to set @config if it was cleared (or is not yet initialized). */ + nm_assert(!config->l3cfg); + nm_assert(!config->ifname); + nm_assert(!config->network_id); + + g_return_if_fail(NM_IS_L3CFG(src->l3cfg)); + + *config = *src; + + g_object_ref(config->l3cfg); + config->ifname = g_strdup(config->ifname); + config->network_id = g_strdup(config->network_id); + + if (config->max_addresses <= 0) + config->max_addresses = _SIZE_MAX_ADDRESSES; + else if (config->max_addresses > 3u * _SIZE_MAX_ADDRESSES) + config->max_addresses = 3u * _SIZE_MAX_ADDRESSES; + + /* This setter is only used in specific circumstances, and in this case, + * we expect that @src only contains valid settings. We thus assert that to + * be the case.*/ + g_return_if_fail(config->ifname && config->ifname[0]); + g_return_if_fail(config->network_id); + g_return_if_fail(config->stable_type >= NM_UTILS_STABLE_TYPE_UUID + && config->stable_type <= NM_UTILS_STABLE_TYPE_RANDOM); + g_return_if_fail(config->addr_gen_mode >= NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64 + && config->addr_gen_mode + <= NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY); + nm_assert(config->max_addresses >= 0 && config->max_addresses <= G_MAXINT32); + G_STATIC_ASSERT_EXPR(G_MAXINT32 == NM_RA_TIMEOUT_INFINITY); + g_return_if_fail(config->ra_timeout <= NM_RA_TIMEOUT_INFINITY); + g_return_if_fail(config->router_solicitations > 0 + && config->router_solicitations <= G_MAXINT32); + g_return_if_fail(config->router_solicitation_interval > 0 + && config->router_solicitation_interval <= G_MAXINT32); + g_return_if_fail( + NM_IN_SET(config->node_type, NM_NDISC_NODE_TYPE_HOST, NM_NDISC_NODE_TYPE_ROUTER)); + g_return_if_fail(NM_IN_SET(config->ip6_privacy, + NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED, + NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR, + NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR)); +} + +/*****************************************************************************/ + static void dns_domain_free(gpointer data) { g_free(((NMNDiscDNSDomain *) (data))->domain); } +/*****************************************************************************/ + static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - NMNDisc * self = NM_NDISC(object); + NMNDisc *self = NM_NDISC(object); NMNDiscPrivate *priv = NM_NDISC_GET_PRIVATE(self); - int i; switch (prop_id) { - case PROP_PLATFORM: + case PROP_CONFIG: /* construct-only */ - priv->platform = g_value_get_object(value) ?: NM_PLATFORM_GET; - if (!priv->platform) - g_return_if_reached(); - - g_object_ref(priv->platform); - - priv->netns = nm_platform_netns_get(priv->platform); - if (priv->netns) - g_object_ref(priv->netns); + _config_init(&priv->config_, g_value_get_pointer(value)); + priv->netns = + nm_g_object_ref(nm_platform_netns_get(nm_l3cfg_get_platform(priv->config.l3cfg))); g_return_if_fail(!priv->netns || priv->netns == nmp_netns_get_current()); break; - case PROP_IFINDEX: - /* construct-only */ - priv->ifindex = g_value_get_int(value); - g_return_if_fail(priv->ifindex > 0); - break; - case PROP_IFNAME: - /* construct-only */ - priv->ifname = g_value_dup_string(value); - g_return_if_fail(priv->ifname && priv->ifname[0]); - break; - case PROP_STABLE_TYPE: - /* construct-only */ - priv->stable_type = g_value_get_int(value); - break; - case PROP_NETWORK_ID: - /* construct-only */ - priv->network_id = g_value_dup_string(value); - g_return_if_fail(priv->network_id); - break; - case PROP_ADDR_GEN_MODE: - /* construct-only */ - priv->addr_gen_mode = g_value_get_int(value); - break; - case PROP_MAX_ADDRESSES: - /* construct-only */ - i = g_value_get_int(value); - nm_assert(i >= 0); - priv->max_addresses = i; - - if (priv->max_addresses <= 0) - priv->max_addresses = _SIZE_MAX_ADDRESSES; - else if (priv->max_addresses > 3u * _SIZE_MAX_ADDRESSES) - priv->max_addresses = 3u * _SIZE_MAX_ADDRESSES; - break; - case PROP_RA_TIMEOUT: - /* construct-only */ - priv->ra_timeout = g_value_get_uint(value); - nm_assert(priv->ra_timeout <= NM_RA_TIMEOUT_INFINITY); - break; - case PROP_ROUTER_SOLICITATIONS: - /* construct-only */ - priv->router_solicitations = g_value_get_int(value); - break; - case PROP_ROUTER_SOLICITATION_INTERVAL: - /* construct-only */ - priv->router_solicitation_interval = g_value_get_int(value); - break; - case PROP_NODE_TYPE: - /* construct-only */ - priv->node_type = g_value_get_int(value); - nm_assert(NM_IN_SET(priv->node_type, NM_NDISC_NODE_TYPE_HOST, NM_NDISC_NODE_TYPE_ROUTER)); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; @@ -1788,7 +1833,7 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps static void nm_ndisc_init(NMNDisc *ndisc) { - NMNDiscPrivate * priv; + NMNDiscPrivate *priv; NMNDiscDataInternal *rdata; priv = G_TYPE_INSTANCE_GET_PRIVATE(ndisc, NM_TYPE_NDISC, NMNDiscPrivate); @@ -1808,7 +1853,7 @@ nm_ndisc_init(NMNDisc *ndisc) static void dispose(GObject *object) { - NMNDisc * ndisc = NM_NDISC(object); + NMNDisc *ndisc = NM_NDISC(object); NMNDiscPrivate *priv = NM_NDISC_GET_PRIVATE(ndisc); nm_clear_g_source_inst(&priv->ra_timeout_source); @@ -1824,13 +1869,10 @@ dispose(GObject *object) static void finalize(GObject *object) { - NMNDisc * ndisc = NM_NDISC(object); - NMNDiscPrivate * priv = NM_NDISC_GET_PRIVATE(ndisc); + NMNDisc *ndisc = NM_NDISC(object); + NMNDiscPrivate *priv = NM_NDISC_GET_PRIVATE(ndisc); NMNDiscDataInternal *rdata = &priv->rdata; - g_free(priv->ifname); - g_free(priv->network_id); - g_array_unref(rdata->gateways); g_array_unref(rdata->addresses); g_array_unref(rdata->routes); @@ -1838,7 +1880,10 @@ finalize(GObject *object) g_array_unref(rdata->dns_domains); g_clear_object(&priv->netns); - g_clear_object(&priv->platform); + + _config_clear(&priv->config_); + + nm_clear_l3cd(&priv->l3cd); G_OBJECT_CLASS(nm_ndisc_parent_class)->finalize(object); } @@ -1854,89 +1899,12 @@ nm_ndisc_class_init(NMNDiscClass *klass) object_class->dispose = dispose; object_class->finalize = finalize; - obj_properties[PROP_PLATFORM] = - g_param_spec_object(NM_NDISC_PLATFORM, - "", - "", - NM_TYPE_PLATFORM, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_IFINDEX] = - g_param_spec_int(NM_NDISC_IFINDEX, - "", - "", - 0, - G_MAXINT, - 0, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_IFNAME] = - g_param_spec_string(NM_NDISC_IFNAME, - "", - "", - NULL, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_STABLE_TYPE] = - g_param_spec_int(NM_NDISC_STABLE_TYPE, - "", - "", - NM_UTILS_STABLE_TYPE_UUID, - NM_UTILS_STABLE_TYPE_RANDOM, - NM_UTILS_STABLE_TYPE_UUID, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_NETWORK_ID] = - g_param_spec_string(NM_NDISC_NETWORK_ID, - "", - "", - NULL, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_ADDR_GEN_MODE] = - g_param_spec_int(NM_NDISC_ADDR_GEN_MODE, - "", - "", - NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64, - NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY, - NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_MAX_ADDRESSES] = - g_param_spec_int(NM_NDISC_MAX_ADDRESSES, - "", - "", - 0, - G_MAXINT32, - NM_NDISC_MAX_ADDRESSES_DEFAULT, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - G_STATIC_ASSERT_EXPR(G_MAXINT32 == NM_RA_TIMEOUT_INFINITY); - obj_properties[PROP_RA_TIMEOUT] = - g_param_spec_uint(NM_NDISC_RA_TIMEOUT, - "", - "", - 0, - G_MAXINT32, - 0, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_ROUTER_SOLICITATIONS] = - g_param_spec_int(NM_NDISC_ROUTER_SOLICITATIONS, - "", - "", - 1, - G_MAXINT32, - NM_NDISC_ROUTER_SOLICITATIONS_DEFAULT, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_ROUTER_SOLICITATION_INTERVAL] = - g_param_spec_int(NM_NDISC_ROUTER_SOLICITATION_INTERVAL, - "", - "", - 1, - G_MAXINT32, - NM_NDISC_RFC4861_RTR_SOLICITATION_INTERVAL, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_NODE_TYPE] = - g_param_spec_int(NM_NDISC_NODE_TYPE, - "", - "", - NM_NDISC_NODE_TYPE_INVALID, - NM_NDISC_NODE_TYPE_ROUTER, - NM_NDISC_NODE_TYPE_INVALID, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + obj_properties[PROP_CONFIG] = + g_param_spec_pointer(NM_NDISC_CONFIG, + "", + "", + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); signals[CONFIG_RECEIVED] = g_signal_new(NM_NDISC_CONFIG_RECEIVED, @@ -1947,9 +1915,14 @@ nm_ndisc_class_init(NMNDiscClass *klass) NULL, NULL, G_TYPE_NONE, - 2, - G_TYPE_POINTER, - G_TYPE_UINT); + 3, + G_TYPE_POINTER + /* (const NMNDiscData *)rdata */, + G_TYPE_UINT + /* (guint) changed_i */, + G_TYPE_POINTER + /* (const NML3ConfigData *) l3cd */ + ); signals[RA_TIMEOUT_SIGNAL] = g_signal_new(NM_NDISC_RA_TIMEOUT_SIGNAL, G_OBJECT_CLASS_TYPE(klass), G_SIGNAL_RUN_FIRST, diff --git a/src/core/ndisc/nm-ndisc.h b/src/core/ndisc/nm-ndisc.h index 5b827528..079ec037 100644 --- a/src/core/ndisc/nm-ndisc.h +++ b/src/core/ndisc/nm-ndisc.h @@ -26,17 +26,7 @@ #define NM_IS_NDISC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NM_TYPE_NDISC)) #define NM_NDISC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_NDISC, NMNDiscClass)) -#define NM_NDISC_PLATFORM "platform" -#define NM_NDISC_IFINDEX "ifindex" -#define NM_NDISC_IFNAME "ifname" -#define NM_NDISC_NETWORK_ID "network-id" -#define NM_NDISC_ADDR_GEN_MODE "addr-gen-mode" -#define NM_NDISC_STABLE_TYPE "stable-type" -#define NM_NDISC_NODE_TYPE "node-type" -#define NM_NDISC_MAX_ADDRESSES "max-addresses" -#define NM_NDISC_RA_TIMEOUT "ra-timeout" -#define NM_NDISC_ROUTER_SOLICITATIONS "router-solicitations" -#define NM_NDISC_ROUTER_SOLICITATION_INTERVAL "router-solicitation-interval" +#define NM_NDISC_CONFIG "config" #define NM_NDISC_CONFIG_RECEIVED "config-received" #define NM_NDISC_RA_TIMEOUT_SIGNAL "ra-timeout-signal" @@ -133,7 +123,7 @@ typedef struct { } NMNDiscDNSServer; typedef struct { - char * domain; + char *domain; gint64 expiry_msec; } NMNDiscDNSDomain; @@ -169,6 +159,20 @@ typedef enum { #define NM_NDISC_ROUTER_ADVERT_MAX_INTERVAL 600 /* RFC4861, MaxRtrAdvInterval default */ #define NM_NDISC_ROUTER_LIFETIME 900 /* 1.5 * NM_NDISC_ROUTER_ADVERT_MAX_INTERVAL */ +typedef struct { + NML3Cfg *l3cfg; + const char *ifname; + const char *network_id; + int max_addresses; + int router_solicitations; + int router_solicitation_interval; + guint32 ra_timeout; + NMUtilsStableType stable_type; + NMSettingIP6ConfigAddrGenMode addr_gen_mode; + NMNDiscNodeType node_type; + NMSettingIP6ConfigPrivacy ip6_privacy; +} NMNDiscConfig; + struct _NMNDiscPrivate; struct _NMNDiscDataInternal; @@ -185,9 +189,9 @@ typedef struct { guint dns_servers_n; guint dns_domains_n; - const NMNDiscGateway * gateways; - const NMNDiscAddress * addresses; - const NMNDiscRoute * routes; + const NMNDiscGateway *gateways; + const NMNDiscAddress *addresses; + const NMNDiscRoute *routes; const NMNDiscDNSServer *dns_servers; const NMNDiscDNSDomain *dns_domains; } NMNDiscData; @@ -201,7 +205,7 @@ typedef struct { typedef struct { GObject parent; union { - struct _NMNDiscPrivate * _priv; + struct _NMNDiscPrivate *_priv; struct _NMNDiscDataInternal *rdata; }; } NMNDisc; @@ -217,24 +221,19 @@ typedef struct { GType nm_ndisc_get_type(void); -void nm_ndisc_emit_config_change(NMNDisc *self, NMNDiscConfigMap changed); - int nm_ndisc_get_ifindex(NMNDisc *self); -const char * nm_ndisc_get_ifname(NMNDisc *self); +const char *nm_ndisc_get_ifname(NMNDisc *self); NMNDiscNodeType nm_ndisc_get_node_type(NMNDisc *self); -gboolean nm_ndisc_set_iid(NMNDisc *ndisc, const NMUtilsIPv6IfaceId iid); +gboolean nm_ndisc_set_iid(NMNDisc *ndisc, const NMUtilsIPv6IfaceId iid, gboolean is_token); void nm_ndisc_start(NMNDisc *ndisc); void nm_ndisc_stop(NMNDisc *ndisc); NMNDiscConfigMap nm_ndisc_dad_failed(NMNDisc *ndisc, const struct in6_addr *address, gboolean emit_changed_signal); -void nm_ndisc_set_config(NMNDisc * ndisc, - const GArray *addresses, - const GArray *dns_servers, - const GArray *dns_domains); +void nm_ndisc_set_config(NMNDisc *ndisc, const NML3ConfigData *l3cd); NMPlatform *nm_ndisc_get_platform(NMNDisc *self); -NMPNetns * nm_ndisc_netns_get(NMNDisc *self); +NMPNetns *nm_ndisc_netns_get(NMNDisc *self); gboolean nm_ndisc_netns_push(NMNDisc *self, NMPNetns **netns); static inline gboolean @@ -268,22 +267,19 @@ nm_ndisc_dad_addr_is_fail_candidate(NMPlatform *platform, const NMPObject *obj) void nm_ndisc_get_sysctl(NMPlatform *platform, const char *ifname, - int * out_max_addresses, - int * out_router_solicitations, - int * out_router_solicitation_interval, - guint32 * out_default_ra_timeout); + int *out_max_addresses, + int *out_router_solicitations, + int *out_router_solicitation_interval, + guint32 *out_default_ra_timeout); /*****************************************************************************/ struct _NML3ConfigData; -struct _NML3ConfigData *nm_ndisc_data_to_l3cd(NMDedupMultiIndex * multi_idx, +struct _NML3ConfigData *nm_ndisc_data_to_l3cd(NMDedupMultiIndex *multi_idx, int ifindex, - const NMNDiscData * rdata, + const NMNDiscData *rdata, NMSettingIP6ConfigPrivacy ip6_privacy, - guint32 route_table, - guint32 route_metric, - gboolean kernel_support_rta_pref, - gboolean kernel_support_extended_ifa_flags); + NMUtilsIPv6IfaceId *token); #endif /* __NETWORKMANAGER_NDISC_H__ */ diff --git a/src/core/ndisc/tests/test-ndisc-fake.c b/src/core/ndisc/tests/test-ndisc-fake.c index f201bc56..0763b64e 100644 --- a/src/core/ndisc/tests/test-ndisc-fake.c +++ b/src/core/ndisc/tests/test-ndisc-fake.c @@ -11,24 +11,29 @@ #include "ndisc/nm-fake-ndisc.h" #include "platform/nm-fake-platform.h" +#include "nm-netns.h" -#include "nm-test-utils-core.h" +#include "platform/tests/test-common.h" /*****************************************************************************/ static NMFakeNDisc * ndisc_new(void) { - NMNDisc * ndisc; - const int ifindex = 1; - const char * ifname = nm_platform_link_get_name(NM_PLATFORM_GET, ifindex); - NMUtilsIPv6IfaceId iid = {}; + gs_unref_object NML3Cfg *l3cfg = NULL; + NMNDisc *ndisc; + const int ifindex = 1; + NMUtilsIPv6IfaceId iid; - ndisc = nm_fake_ndisc_new(ifindex, ifname); - iid.id_u8[7] = 1; - nm_ndisc_set_iid(ndisc, iid); + l3cfg = nm_netns_l3cfg_acquire(NM_NETNS_GET, ifindex); + + ndisc = nm_fake_ndisc_new(l3cfg); g_assert(ndisc); + memset(&iid, 0, sizeof(iid)); + iid.id_u8[7] = 1; + nm_ndisc_set_iid(ndisc, iid, FALSE); + return NM_FAKE_NDISC(ndisc); } @@ -37,7 +42,7 @@ ndisc_new(void) static void match_gateway(const NMNDiscData *rdata, guint idx, - const char * addr, + const char *addr, gint64 expiry_msec, NMIcmpv6RouterPref pref) { @@ -57,7 +62,7 @@ match_gateway(const NMNDiscData *rdata, #define match_address(rdata, idx, addr, _expiry_msec, _expiry_preferred_msec) \ G_STMT_START \ { \ - const NMNDiscData * _rdata = (rdata); \ + const NMNDiscData *_rdata = (rdata); \ guint _idx = (idx); \ const NMNDiscAddress *_a; \ \ @@ -76,7 +81,7 @@ match_gateway(const NMNDiscData *rdata, #define match_route(rdata, idx, nw, pl, gw, _expiry_msec, pref) \ G_STMT_START \ { \ - const NMNDiscData * _rdata = (rdata); \ + const NMNDiscData *_rdata = (rdata); \ guint _idx = (idx); \ const NMNDiscRoute *_r; \ int _plen = (pl); \ @@ -140,9 +145,15 @@ typedef struct { /*****************************************************************************/ static void -test_simple_changed(NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_int, TestData *data) +test_simple_changed(NMNDisc *ndisc, + const NMNDiscData *rdata, + guint changed_i, + const NML3ConfigData *l3cd, + TestData *data) { - NMNDiscConfigMap changed = changed_int; + NMNDiscConfigMap changed = changed_i; + + _LOGT("test_simple: callback (counter=%u)", data->counter); switch (data->counter++) { case 0: @@ -180,12 +191,12 @@ test_simple_changed(NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_int, static void test_simple(void) { - nm_auto_unref_gmainloop GMainLoop *loop = g_main_loop_new(NULL, FALSE); - gs_unref_object NMFakeNDisc *ndisc = ndisc_new(); - const gint64 now_msec = nm_utils_get_monotonic_timestamp_msec(); - TestData data = { - .loop = loop, - .timestamp_msec_1 = now_msec, + nm_auto_unref_gmainloop GMainLoop *loop = g_main_loop_new(NULL, FALSE); + gs_unref_object NMFakeNDisc *ndisc = ndisc_new(); + const gint64 now_msec = nm_utils_get_monotonic_timestamp_msec(); + TestData data = { + .loop = loop, + .timestamp_msec_1 = now_msec, }; guint id; @@ -206,9 +217,11 @@ test_simple(void) g_signal_connect(ndisc, NM_NDISC_CONFIG_RECEIVED, G_CALLBACK(test_simple_changed), &data); + _LOGT("test_simple: start"); nm_ndisc_start(NM_NDISC(ndisc)); nmtst_main_loop_run_assert(data.loop, 15000); g_assert_cmpint(data.counter, ==, 2); + _LOGT("test_simple: done"); } /*****************************************************************************/ @@ -221,9 +234,13 @@ test_everything_rs_sent(NMNDisc *ndisc, TestData *data) } static void -test_everything_changed(NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_int, TestData *data) +test_everything_changed(NMNDisc *ndisc, + const NMNDiscData *rdata, + guint changed_i, + const NML3ConfigData *l3cd, + TestData *data) { - NMNDiscConfigMap changed = changed_int; + NMNDiscConfigMap changed = changed_i; if (data->counter == 0) { g_assert_cmpint(data->rs_counter, ==, 1); @@ -288,12 +305,12 @@ test_everything_changed(NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_ static void test_everything(void) { - nm_auto_unref_gmainloop GMainLoop *loop = g_main_loop_new(NULL, FALSE); - gs_unref_object NMFakeNDisc *ndisc = ndisc_new(); - const gint64 now_msec = nm_utils_get_monotonic_timestamp_msec(); - TestData data = { - .loop = loop, - .timestamp_msec_1 = now_msec, + nm_auto_unref_gmainloop GMainLoop *loop = g_main_loop_new(NULL, FALSE); + gs_unref_object NMFakeNDisc *ndisc = ndisc_new(); + const gint64 now_msec = nm_utils_get_monotonic_timestamp_msec(); + TestData data = { + .loop = loop, + .timestamp_msec_1 = now_msec, }; guint id; @@ -342,12 +359,13 @@ test_everything(void) } static void -test_preference_order_cb(NMNDisc * ndisc, - const NMNDiscData *rdata, - guint changed_int, - TestData * data) +test_preference_order_cb(NMNDisc *ndisc, + const NMNDiscData *rdata, + guint changed_i, + const NML3ConfigData *l3cd, + TestData *data) { - NMNDiscConfigMap changed = changed_int; + NMNDiscConfigMap changed = changed_i; if (data->counter == 1) { g_assert_cmpint(changed, @@ -391,12 +409,12 @@ test_preference_order_cb(NMNDisc * ndisc, static void test_preference_order(void) { - nm_auto_unref_gmainloop GMainLoop *loop = g_main_loop_new(NULL, FALSE); - gs_unref_object NMFakeNDisc *ndisc = ndisc_new(); - const gint64 now_msec = nm_utils_get_monotonic_timestamp_msec(); - TestData data = { - .loop = loop, - .timestamp_msec_1 = now_msec, + nm_auto_unref_gmainloop GMainLoop *loop = g_main_loop_new(NULL, FALSE); + gs_unref_object NMFakeNDisc *ndisc = ndisc_new(); + const gint64 now_msec = nm_utils_get_monotonic_timestamp_msec(); + TestData data = { + .loop = loop, + .timestamp_msec_1 = now_msec, }; guint id; @@ -434,12 +452,13 @@ test_preference_order(void) } static void -test_preference_changed_cb(NMNDisc * ndisc, - const NMNDiscData *rdata, - guint changed_int, - TestData * data) +test_preference_changed_cb(NMNDisc *ndisc, + const NMNDiscData *rdata, + guint changed_i, + const NML3ConfigData *l3cd, + TestData *data) { - NMNDiscConfigMap changed = changed_int; + NMNDiscConfigMap changed = changed_i; if (data->counter == 1) { g_assert_cmpint(changed, @@ -513,12 +532,12 @@ test_preference_changed_cb(NMNDisc * ndisc, static void test_preference_changed(void) { - nm_auto_unref_gmainloop GMainLoop *loop = g_main_loop_new(NULL, FALSE); - gs_unref_object NMFakeNDisc *ndisc = ndisc_new(); - const gint64 now_msec = nm_utils_get_monotonic_timestamp_msec(); - TestData data = { - .loop = loop, - .timestamp_msec_1 = now_msec, + nm_auto_unref_gmainloop GMainLoop *loop = g_main_loop_new(NULL, FALSE); + gs_unref_object NMFakeNDisc *ndisc = ndisc_new(); + const gint64 now_msec = nm_utils_get_monotonic_timestamp_msec(); + TestData data = { + .loop = loop, + .timestamp_msec_1 = now_msec, }; guint id; @@ -576,10 +595,11 @@ test_preference_changed(void) /*****************************************************************************/ static void -_test_dns_solicit_loop_changed(NMNDisc * ndisc, - const NMNDiscData *rdata, - guint changed_int, - TestData * data) +_test_dns_solicit_loop_changed(NMNDisc *ndisc, + const NMNDiscData *rdata, + guint changed_i, + const NML3ConfigData *l3cd, + TestData *data) { data->counter++; } @@ -593,12 +613,12 @@ _test_dns_solicit_loop_rs_sent(NMFakeNDisc *ndisc, TestData *data) static void test_dns_solicit_loop(void) { - nm_auto_unref_gmainloop GMainLoop *loop = g_main_loop_new(NULL, FALSE); - gs_unref_object NMFakeNDisc *ndisc = ndisc_new(); - const gint64 now_msec = nm_utils_get_monotonic_timestamp_msec(); - TestData data = { - .loop = loop, - .timestamp_msec_1 = now_msec, + nm_auto_unref_gmainloop GMainLoop *loop = g_main_loop_new(NULL, FALSE); + gs_unref_object NMFakeNDisc *ndisc = ndisc_new(); + const gint64 now_msec = nm_utils_get_monotonic_timestamp_msec(); + TestData data = { + .loop = loop, + .timestamp_msec_1 = now_msec, }; guint id; diff --git a/src/core/ndisc/tests/test-ndisc-linux.c b/src/core/ndisc/tests/test-ndisc-linux.c index 57021606..66c7e157 100644 --- a/src/core/ndisc/tests/test-ndisc-linux.c +++ b/src/core/ndisc/tests/test-ndisc-linux.c @@ -11,6 +11,8 @@ #include "ndisc/nm-lndp-ndisc.h" #include "libnm-platform/nm-linux-platform.h" +#include "nm-netns.h" +#include "nm-l3cfg.h" #include "nm-test-utils-core.h" @@ -19,16 +21,18 @@ NMTST_DEFINE(); int main(int argc, char **argv) { - GMainLoop * loop; - NMNDisc * ndisc; - int ifindex = 1; - const char * ifname; - NMUtilsIPv6IfaceId iid = {}; - GError * error = NULL; - int max_addresses; - int router_solicitations; - int router_solicitation_interval; - guint32 ra_timeout; + gs_unref_object NML3Cfg *l3cfg = NULL; + NMNDiscConfig config; + GMainLoop *loop; + NMNDisc *ndisc; + int ifindex = 1; + const char *ifname; + NMUtilsIPv6IfaceId iid = {}; + GError *error = NULL; + int max_addresses; + int router_solicitations; + int router_solicitation_interval; + guint32 ra_timeout; nmtst_init_with_logging(&argc, &argv, NULL, "DEFAULT"); @@ -56,18 +60,23 @@ main(int argc, char **argv) &router_solicitation_interval, &ra_timeout); - ndisc = nm_lndp_ndisc_new(NM_PLATFORM_GET, - ifindex, - ifname, - NM_UTILS_STABLE_TYPE_UUID, - "8ce666e8-d34d-4fb1-b858-f15a7al28086", - NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64, - NM_NDISC_NODE_TYPE_HOST, - max_addresses, - router_solicitations, - router_solicitation_interval, - ra_timeout, - &error); + l3cfg = nm_netns_l3cfg_acquire(NM_NETNS_GET, ifindex); + + config = (NMNDiscConfig){ + .l3cfg = l3cfg, + .ifname = nm_l3cfg_get_ifname(l3cfg, TRUE), + .stable_type = NM_UTILS_STABLE_TYPE_UUID, + .network_id = "8ce666e8-d34d-4fb1-b858-f15a7al28086", + .addr_gen_mode = NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64, + .node_type = NM_NDISC_NODE_TYPE_HOST, + .max_addresses = max_addresses, + .router_solicitations = router_solicitations, + .router_solicitation_interval = router_solicitation_interval, + .ra_timeout = ra_timeout, + .ip6_privacy = NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR, + }; + + ndisc = nm_lndp_ndisc_new(&config); if (!ndisc) { g_print("Failed to create NMNDisc instance: %s\n", error->message); g_error_free(error); @@ -75,7 +84,7 @@ main(int argc, char **argv) } iid.id_u8[7] = 1; - nm_ndisc_set_iid(ndisc, iid); + nm_ndisc_set_iid(ndisc, iid, FALSE); nm_ndisc_start(ndisc); g_main_loop_run(loop); diff --git a/src/core/nm-act-request.c b/src/core/nm-act-request.c index d0a2e0c7..55d1829e 100644 --- a/src/core/nm-act-request.c +++ b/src/core/nm-act-request.c @@ -24,8 +24,7 @@ #include "settings/nm-settings-connection.h" typedef struct { - CList call_ids_lst_head; - NMFirewallConfig *firewall_config; + CList call_ids_lst_head; } NMActRequestPrivate; struct _NMActRequest { @@ -73,7 +72,7 @@ nm_act_request_get_applied_connection(NMActRequest *req) struct _NMActRequestGetSecretsCallId { CList call_ids_lst; - NMActRequest * self; + NMActRequest *self; NMActRequestSecretsFunc callback; gpointer callback_data; NMSettingsConnectionCallId *call_id; @@ -92,15 +91,15 @@ _get_secrets_call_id_free(NMActRequestGetSecretsCallId *call_id) } static void -get_secrets_cb(NMSettingsConnection * connection, +get_secrets_cb(NMSettingsConnection *connection, NMSettingsConnectionCallId *call_id_s, - const char * agent_username, - const char * setting_name, - GError * error, + const char *agent_username, + const char *setting_name, + GError *error, gpointer user_data) { NMActRequestGetSecretsCallId *call_id = user_data; - NMActRequestPrivate * priv; + NMActRequestPrivate *priv; g_return_if_fail(call_id && call_id->call_id == call_id_s); g_return_if_fail(NM_IS_ACT_REQUEST(call_id->self)); @@ -142,19 +141,19 @@ get_secrets_cb(NMSettingsConnection * connection, * Returns: a call-id. */ NMActRequestGetSecretsCallId * -nm_act_request_get_secrets(NMActRequest * self, +nm_act_request_get_secrets(NMActRequest *self, gboolean ref_self, - const char * setting_name, + const char *setting_name, NMSecretAgentGetSecretsFlags flags, - const char *const * hints, + const char *const *hints, NMActRequestSecretsFunc callback, gpointer callback_data) { - NMActRequestPrivate * priv; + NMActRequestPrivate *priv; NMActRequestGetSecretsCallId *call_id; - NMSettingsConnectionCallId * call_id_s; - NMSettingsConnection * settings_connection; - NMConnection * applied_connection; + NMSettingsConnectionCallId *call_id_s; + NMSettingsConnection *settings_connection; + NMConnection *applied_connection; g_return_val_if_fail(NM_IS_ACT_REQUEST(self), NULL); @@ -250,36 +249,6 @@ nm_act_request_clear_secrets(NMActRequest *self) /*****************************************************************************/ -NMFirewallConfig * -nm_act_request_get_shared(NMActRequest *req) -{ - g_return_val_if_fail(NM_IS_ACT_REQUEST(req), FALSE); - - return NM_ACT_REQUEST_GET_PRIVATE(req)->firewall_config; -} - -void -nm_act_request_set_shared(NMActRequest *req, NMFirewallConfig *rules) -{ - NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE(req); - - g_return_if_fail(NM_IS_ACT_REQUEST(req)); - - if (priv->firewall_config == rules) - return; - - if (priv->firewall_config) { - nm_firewall_config_apply(priv->firewall_config, FALSE); - priv->firewall_config = NULL; - } - if (rules) { - priv->firewall_config = rules; - nm_firewall_config_apply(priv->firewall_config, TRUE); - } -} - -/*****************************************************************************/ - static void device_notify(GObject *object, GParamSpec *pspec, gpointer self) { @@ -288,7 +257,7 @@ device_notify(GObject *object, GParamSpec *pspec, gpointer self) static void device_state_changed(NMActiveConnection *active, - NMDevice * device, + NMDevice *device, NMDeviceState new_state, NMDeviceState old_state) { @@ -375,7 +344,7 @@ device_state_changed(NMActiveConnection *active, static void master_failed(NMActiveConnection *self) { - NMDevice * device; + NMDevice *device; NMDeviceState device_state; /* If the connection has an active device, fail it */ @@ -402,8 +371,8 @@ static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { NMActiveConnection *active; - NMDevice * device; - char * name; + NMDevice *device; + char *name; switch (prop_id) { case PROP_IP4_CONFIG: @@ -463,14 +432,14 @@ nm_act_request_init(NMActRequest *req) * Returns: the new activation request on success, %NULL on error. */ NMActRequest * -nm_act_request_new(NMSettingsConnection * settings_connection, - NMConnection * applied_connection, - const char * specific_object, - NMAuthSubject * subject, +nm_act_request_new(NMSettingsConnection *settings_connection, + NMConnection *applied_connection, + const char *specific_object, + NMAuthSubject *subject, NMActivationType activation_type, NMActivationReason activation_reason, NMActivationStateFlags initial_state_flags, - NMDevice * device) + NMDevice *device) { g_return_val_if_fail(!settings_connection || NM_IS_SETTINGS_CONNECTION(settings_connection), NULL); @@ -500,26 +469,21 @@ nm_act_request_new(NMSettingsConnection * settings_connection, static void dispose(GObject *object) { - NMActRequest * self = NM_ACT_REQUEST(object); - NMActRequestPrivate * priv = NM_ACT_REQUEST_GET_PRIVATE(self); + NMActRequest *self = NM_ACT_REQUEST(object); + NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE(self); NMActRequestGetSecretsCallId *call_id, *call_id_safe; /* Kill any in-progress secrets requests */ c_list_for_each_entry_safe (call_id, call_id_safe, &priv->call_ids_lst_head, call_ids_lst) _do_cancel_secrets(self, call_id, TRUE); - if (priv->firewall_config) { - nm_firewall_config_apply(priv->firewall_config, FALSE); - nm_clear_pointer(&priv->firewall_config, nm_firewall_config_free); - } - G_OBJECT_CLASS(nm_act_request_parent_class)->dispose(object); } static void nm_act_request_class_init(NMActRequestClass *req_class) { - GObjectClass * object_class = G_OBJECT_CLASS(req_class); + GObjectClass *object_class = G_OBJECT_CLASS(req_class); NMActiveConnectionClass *active_class = NM_ACTIVE_CONNECTION_CLASS(req_class); /* virtual methods */ diff --git a/src/core/nm-act-request.h b/src/core/nm-act-request.h index 9c702d31..9075d5b7 100644 --- a/src/core/nm-act-request.h +++ b/src/core/nm-act-request.h @@ -23,14 +23,14 @@ typedef struct _NMActRequestGetSecretsCallId NMActRequestGetSecretsCallId; GType nm_act_request_get_type(void); -NMActRequest *nm_act_request_new(NMSettingsConnection * settings_connection, - NMConnection * applied_connection, - const char * specific_object, - NMAuthSubject * subject, +NMActRequest *nm_act_request_new(NMSettingsConnection *settings_connection, + NMConnection *applied_connection, + const char *specific_object, + NMAuthSubject *subject, NMActivationType activation_type, NMActivationReason activation_reason, NMActivationStateFlags initial_state_flags, - NMDevice * device); + NMDevice *device); NMSettingsConnection *nm_act_request_get_settings_connection(NMActRequest *req); @@ -38,27 +38,19 @@ NMConnection *nm_act_request_get_applied_connection(NMActRequest *req); /*****************************************************************************/ -struct _NMFirewallConfig; - -struct _NMFirewallConfig *nm_act_request_get_shared(NMActRequest *req); - -void nm_act_request_set_shared(NMActRequest *req, struct _NMFirewallConfig *rules); - -/*****************************************************************************/ - /* Secrets handling */ -typedef void (*NMActRequestSecretsFunc)(NMActRequest * req, +typedef void (*NMActRequestSecretsFunc)(NMActRequest *req, NMActRequestGetSecretsCallId *call_id, - NMSettingsConnection * connection, - GError * error, + NMSettingsConnection *connection, + GError *error, gpointer user_data); -NMActRequestGetSecretsCallId *nm_act_request_get_secrets(NMActRequest * req, +NMActRequestGetSecretsCallId *nm_act_request_get_secrets(NMActRequest *req, gboolean take_ref, - const char * setting_name, + const char *setting_name, NMSecretAgentGetSecretsFlags flags, - const char *const * hints, + const char *const *hints, NMActRequestSecretsFunc callback, gpointer callback_data); diff --git a/src/core/nm-active-connection.c b/src/core/nm-active-connection.c index 4cd6d488..49568f7c 100644 --- a/src/core/nm-active-connection.c +++ b/src/core/nm-active-connection.c @@ -23,9 +23,9 @@ typedef struct _NMActiveConnectionPrivate { NMDBusTrackObjPath settings_connection; - NMConnection * applied_connection; - char * specific_object; - NMDevice * device; + NMConnection *applied_connection; + char *specific_object; + NMDevice *device; guint64 version_id; @@ -48,7 +48,7 @@ typedef struct _NMActiveConnectionPrivate { * reason never changes. */ NMActivationReason activation_reason : 4; - NMAuthSubject * subject; + NMAuthSubject *subject; NMActiveConnection *master; NMActiveConnection *parent; @@ -107,7 +107,7 @@ static const GDBusSignalInfo signal_info_state_changed; static void check_master_ready(NMActiveConnection *self); static void _device_cleanup(NMActiveConnection *self); static void _settings_connection_flags_changed(NMSettingsConnection *settings_connection, - NMActiveConnection * self); + NMActiveConnection *self); static void _set_activation_type_managed(NMActiveConnection *self); static void auth_complete(NMActiveConnection *self, gboolean result, const char *message); @@ -239,7 +239,7 @@ emit_state_changed(NMActiveConnection *self, guint state, guint reason) } void -nm_active_connection_set_state(NMActiveConnection * self, +nm_active_connection_set_state(NMActiveConnection *self, NMActiveConnectionState new_state, NMActiveConnectionStateReason reason) { @@ -314,9 +314,9 @@ nm_active_connection_set_state(NMActiveConnection * self, } void -nm_active_connection_set_state_fail(NMActiveConnection * self, +nm_active_connection_set_state_fail(NMActiveConnection *self, NMActiveConnectionStateReason reason, - const char * error_desc) + const char *error_desc) { NMActiveConnectionState s; @@ -350,7 +350,7 @@ nm_active_connection_get_state_flags(NMActiveConnection *self) } void -nm_active_connection_set_state_flags_full(NMActiveConnection * self, +nm_active_connection_set_state_flags_full(NMActiveConnection *self, NMActivationStateFlags state_flags, NMActivationStateFlags mask) { @@ -432,7 +432,7 @@ static void _set_applied_connection_take(NMActiveConnection *self, NMConnection *applied_connection) { NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE(self); - NMSettingConnection * s_con; + NMSettingConnection *s_con; NMActivationStateFlags flags_val = 0; nm_assert(NM_IS_CONNECTION(applied_connection)); @@ -458,7 +458,7 @@ _set_applied_connection_take(NMActiveConnection *self, NMConnection *applied_con } void -nm_active_connection_set_settings_connection(NMActiveConnection * self, +nm_active_connection_set_settings_connection(NMActiveConnection *self, NMSettingsConnection *sett_conn) { NMActiveConnectionPrivate *priv; @@ -489,7 +489,7 @@ nm_active_connection_set_settings_connection(NMActiveConnection * self, } gboolean -nm_active_connection_has_unmodified_applied_connection(NMActiveConnection * self, +nm_active_connection_has_unmodified_applied_connection(NMActiveConnection *self, NMSettingCompareFlags compare_flags) { NMActiveConnectionPrivate *priv; @@ -615,13 +615,13 @@ nm_active_connection_get_device(NMActiveConnection *self) } static void -device_state_changed(NMDevice * device, +device_state_changed(NMDevice *device, NMDeviceState new_state, NMDeviceState old_state, NMDeviceStateReason reason, gpointer user_data) { - NMActiveConnection * self = NM_ACTIVE_CONNECTION(user_data); + NMActiveConnection *self = NM_ACTIVE_CONNECTION(user_data); NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE(self); /* When already deactivated or before activation, device state changes are useless */ @@ -641,9 +641,9 @@ device_state_changed(NMDevice * device, static void device_master_changed(GObject *object, GParamSpec *pspec, gpointer user_data) { - NMDevice * device = NM_DEVICE(object); - NMActiveConnection * self = NM_ACTIVE_CONNECTION(user_data); - NMActiveConnection * master; + NMDevice *device = NM_DEVICE(object); + NMActiveConnection *self = NM_ACTIVE_CONNECTION(user_data); + NMActiveConnection *master; NMActiveConnectionState master_state; if (NM_ACTIVE_CONNECTION(nm_device_get_act_request(device)) != self) @@ -667,7 +667,7 @@ static void device_metered_changed(GObject *object, GParamSpec *pspec, gpointer user_data) { NMActiveConnection *self = (NMActiveConnection *) user_data; - NMDevice * device = NM_DEVICE(object); + NMDevice *device = NM_DEVICE(object); g_return_if_fail(NM_IS_ACTIVE_CONNECTION(self)); g_signal_emit(self, signals[DEVICE_METERED_CHANGED], 0, nm_device_get_metered(device)); @@ -677,8 +677,8 @@ gboolean nm_active_connection_set_device(NMActiveConnection *self, NMDevice *device) { NMActiveConnectionPrivate *priv; - gs_unref_object NMDevice *old_device = NULL; - NMMetered old_metered, new_metered; + gs_unref_object NMDevice *old_device = NULL; + NMMetered old_metered, new_metered; g_return_val_if_fail(NM_IS_ACTIVE_CONNECTION(self), FALSE); g_return_val_if_fail(!device || NM_IS_DEVICE(device), FALSE); @@ -810,7 +810,7 @@ check_master_ready(NMActiveConnection *self) static void master_state_cb(NMActiveConnection *master, GParamSpec *pspec, gpointer user_data) { - NMActiveConnection * self = NM_ACTIVE_CONNECTION(user_data); + NMActiveConnection *self = NM_ACTIVE_CONNECTION(user_data); NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE(self); NMActiveConnectionState master_state = nm_active_connection_get_state(master); @@ -961,7 +961,7 @@ nm_active_connection_get_keep_alive(NMActiveConnection *self) static void _settings_connection_flags_changed(NMSettingsConnection *settings_connection, - NMActiveConnection * self) + NMActiveConnection *self) { NMDevice *device; @@ -1008,7 +1008,7 @@ parent_destroyed(gpointer user_data, GObject *parent) static void parent_state_cb(NMActiveConnection *parent_ac, GParamSpec *pspec, gpointer user_data) { - NMActiveConnection * self = user_data; + NMActiveConnection *self = user_data; NMActiveConnectionState parent_state = nm_active_connection_get_state(parent_ac); if (parent_state < NM_ACTIVE_CONNECTION_STATE_ACTIVATED) @@ -1059,7 +1059,7 @@ nm_active_connection_set_parent(NMActiveConnection *self, NMActiveConnection *pa static void auth_complete(NMActiveConnection *self, gboolean result, const char *message) { - NMActiveConnectionPrivate * priv = NM_ACTIVE_CONNECTION_GET_PRIVATE(self); + NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE(self); NMActiveConnectionAuthResultFunc result_func; gpointer user_data; @@ -1092,15 +1092,15 @@ auth_complete_keep_alive(NMActiveConnection *self, gboolean result, const char * } static void -auth_done(NMAuthManager * auth_mgr, +auth_done(NMAuthManager *auth_mgr, NMAuthManagerCallId *auth_call_id, gboolean is_authorized, gboolean is_challenge, - GError * error, + GError *error, gpointer user_data) { - NMActiveConnection * self = NM_ACTIVE_CONNECTION(user_data); + NMActiveConnection *self = NM_ACTIVE_CONNECTION(user_data); NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE(self); NMAuthCallResult result; @@ -1163,14 +1163,14 @@ auth_done(NMAuthManager * auth_mgr, * activation request. */ void -nm_active_connection_authorize(NMActiveConnection * self, - NMConnection * initial_connection, +nm_active_connection_authorize(NMActiveConnection *self, + NMConnection *initial_connection, NMActiveConnectionAuthResultFunc result_func, gpointer user_data) { NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE(self); - const char * wifi_permission = NULL; - NMConnection * connection; + const char *wifi_permission = NULL; + NMConnection *connection; g_return_if_fail(result_func); g_return_if_fail(!priv->auth.call_id_network_control); @@ -1270,10 +1270,10 @@ _device_cleanup(NMActiveConnection *self) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMActiveConnection * self = NM_ACTIVE_CONNECTION(object); + NMActiveConnection *self = NM_ACTIVE_CONNECTION(object); NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE(self); - char ** strv; - NMDevice * master_device = NULL; + char **strv; + NMDevice *master_device = NULL; switch (prop_id) { /* note that while priv->settings_connection.obj might not be set initially, @@ -1363,11 +1363,11 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - NMActiveConnection * self = (NMActiveConnection *) object; + NMActiveConnection *self = (NMActiveConnection *) object; NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE(self); - const char * tmp; - NMSettingsConnection * sett_conn; - NMConnection * acon; + const char *tmp; + NMSettingsConnection *sett_conn; + NMConnection *acon; int i; switch (prop_id) { @@ -1477,7 +1477,7 @@ nm_active_connection_init(NMActiveConnection *self) static void constructed(GObject *object) { - NMActiveConnection * self = (NMActiveConnection *) object; + NMActiveConnection *self = (NMActiveConnection *) object; NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE(self); G_OBJECT_CLASS(nm_active_connection_parent_class)->constructed(object); @@ -1512,7 +1512,7 @@ constructed(GObject *object) static void dispose(GObject *object) { - NMActiveConnection * self = NM_ACTIVE_CONNECTION(object); + NMActiveConnection *self = NM_ACTIVE_CONNECTION(object); NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE(self); nm_assert(!c_list_is_linked(&self->active_connections_lst)); @@ -1544,7 +1544,7 @@ dispose(GObject *object) static void finalize(GObject *object) { - NMActiveConnection * self = NM_ACTIVE_CONNECTION(object); + NMActiveConnection *self = NM_ACTIVE_CONNECTION(object); NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE(self); nm_dbus_track_obj_path_set(&priv->settings_connection, NULL, FALSE); @@ -1609,7 +1609,7 @@ static const NMDBusInterfaceInfoExtended interface_info_active_connection = { static void nm_active_connection_class_init(NMActiveConnectionClass *ac_class) { - GObjectClass * object_class = G_OBJECT_CLASS(ac_class); + GObjectClass *object_class = G_OBJECT_CLASS(ac_class); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(ac_class); g_type_class_add_private(ac_class, sizeof(NMActiveConnectionPrivate)); diff --git a/src/core/nm-active-connection.h b/src/core/nm-active-connection.h index 15c68e6e..28d4246e 100644 --- a/src/core/nm-active-connection.h +++ b/src/core/nm-active-connection.h @@ -75,14 +75,14 @@ typedef struct { * device states >= DISCONNECTED. */ void (*device_state_changed)(NMActiveConnection *connection, - NMDevice * device, + NMDevice *device, NMDeviceState new_state, NMDeviceState old_state); void (*master_failed)(NMActiveConnection *connection); void (*device_changed)(NMActiveConnection *connection, - NMDevice * new_device, - NMDevice * old_device); + NMDevice *new_device, + NMDevice *old_device); void (*device_metered_changed)(NMActiveConnection *connection, NMMetered new_value); @@ -96,24 +96,24 @@ GType nm_active_connection_get_type(void); typedef void (*NMActiveConnectionAuthResultFunc)(NMActiveConnection *self, gboolean success, - const char * error_desc, + const char *error_desc, gpointer user_data); -void nm_active_connection_authorize(NMActiveConnection * self, - NMConnection * initial_connection, +void nm_active_connection_authorize(NMActiveConnection *self, + NMConnection *initial_connection, NMActiveConnectionAuthResultFunc result_func, gpointer user_data); NMSettingsConnection *nm_active_connection_get_settings_connection(NMActiveConnection *self); -NMConnection * nm_active_connection_get_applied_connection(NMActiveConnection *self); +NMConnection *nm_active_connection_get_applied_connection(NMActiveConnection *self); NMSettingsConnection *_nm_active_connection_get_settings_connection(NMActiveConnection *self); -void nm_active_connection_set_settings_connection(NMActiveConnection * self, +void nm_active_connection_set_settings_connection(NMActiveConnection *self, NMSettingsConnection *connection); gboolean -nm_active_connection_has_unmodified_applied_connection(NMActiveConnection * self, +nm_active_connection_has_unmodified_applied_connection(NMActiveConnection *self, NMSettingCompareFlags compare_flags); const char *nm_active_connection_get_settings_connection_id(NMActiveConnection *self); @@ -121,7 +121,7 @@ const char *nm_active_connection_get_settings_connection_id(NMActiveConnection * const char *nm_active_connection_get_specific_object(NMActiveConnection *self); void nm_active_connection_set_specific_object(NMActiveConnection *self, - const char * specific_object); + const char *specific_object); void nm_active_connection_set_default(NMActiveConnection *self, int addr_family, gboolean is_default); @@ -130,17 +130,20 @@ gboolean nm_active_connection_get_default(NMActiveConnection *self, int addr_fam NMActiveConnectionState nm_active_connection_get_state(NMActiveConnection *self); -void nm_active_connection_set_state(NMActiveConnection * self, +void nm_active_connection_set_state(NMActiveConnection *self, NMActiveConnectionState state, NMActiveConnectionStateReason reason); -void nm_active_connection_set_state_fail(NMActiveConnection * active, +void nm_active_connection_set_state_fail(NMActiveConnection *active, NMActiveConnectionStateReason reason, - const char * error_desc); + const char *error_desc); + +#define NM_ACTIVATION_STATE_FLAG_IP_READY_X(IS_IPv4) \ + ((IS_IPv4) ? NM_ACTIVATION_STATE_FLAG_IP4_READY : NM_ACTIVATION_STATE_FLAG_IP6_READY) NMActivationStateFlags nm_active_connection_get_state_flags(NMActiveConnection *self); -void nm_active_connection_set_state_flags_full(NMActiveConnection * self, +void nm_active_connection_set_state_flags_full(NMActiveConnection *self, NMActivationStateFlags state_flags, NMActivationStateFlags mask); @@ -151,7 +154,7 @@ nm_active_connection_set_state_flags(NMActiveConnection *self, NMActivationState } static inline void -nm_active_connection_set_state_flags_clear(NMActiveConnection * self, +nm_active_connection_set_state_flags_clear(NMActiveConnection *self, NMActivationStateFlags state_flags) { nm_active_connection_set_state_flags_full(self, NM_ACTIVATION_STATE_FLAG_NONE, state_flags); diff --git a/src/core/nm-audit-manager.c b/src/core/nm-audit-manager.c index 477e1798..dd96d834 100644 --- a/src/core/nm-audit-manager.c +++ b/src/core/nm-audit-manager.c @@ -30,7 +30,7 @@ typedef enum _nm_packed { } AuditBackend; typedef struct { - const char * name; + const char *name; AuditBackend backends; bool need_encoding; NMValueType value_type; @@ -84,9 +84,9 @@ NM_DEFINE_SINGLETON_GETTER(NMAuditManager, nm_audit_manager_get, NM_TYPE_AUDIT_M /*****************************************************************************/ static void -_audit_field_init_string(AuditField * field, - const char * name, - const char * str, +_audit_field_init_string(AuditField *field, + const char *name, + const char *str, gboolean need_encoding, AuditBackend backends) { @@ -165,10 +165,10 @@ build_message(NMStrBuf *strbuf, AuditBackend backend, GPtrArray *fields) static void nm_audit_log(NMAuditManager *self, - GPtrArray * fields, - const char * file, + GPtrArray *fields, + const char *file, guint line, - const char * func, + const char *func, gboolean success) { nm_auto_str_buf NMStrBuf strbuf = NM_STR_BUF_INIT(0, FALSE); @@ -210,23 +210,23 @@ nm_audit_log(NMAuditManager *self, static void _audit_log_helper(NMAuditManager *self, - GPtrArray * fields, - const char * file, + GPtrArray *fields, + const char *file, guint line, - const char * func, - const char * op, + const char *func, + const char *op, gboolean result, gpointer subject_context, - const char * reason) + const char *reason) { - AuditField op_field; - AuditField pid_field; - AuditField uid_field; - AuditField result_field; - AuditField reason_field; - gulong pid; - gulong uid; - NMAuthSubject * subject = NULL; + AuditField op_field; + AuditField pid_field; + AuditField uid_field; + AuditField result_field; + AuditField reason_field; + gulong pid; + gulong uid; + NMAuthSubject *subject = NULL; gs_unref_object NMAuthSubject *subject_free = NULL; _audit_field_init_string(&op_field, "op", op, FALSE, BACKEND_ALL); @@ -284,16 +284,16 @@ nm_audit_manager_audit_enabled(NMAuditManager *self) } void -_nm_audit_manager_log_connection_op(NMAuditManager * self, - const char * file, +_nm_audit_manager_log_connection_op(NMAuditManager *self, + const char *file, guint line, - const char * func, - const char * op, + const char *func, + const char *op, NMSettingsConnection *connection, gboolean result, - const char * args, + const char *args, gpointer subject_context, - const char * reason) + const char *reason) { gs_unref_ptrarray GPtrArray *fields = NULL; AuditField uuid_field; @@ -330,14 +330,14 @@ _nm_audit_manager_log_connection_op(NMAuditManager * self, void _nm_audit_manager_log_generic_op(NMAuditManager *self, - const char * file, + const char *file, guint line, - const char * func, - const char * op, - const char * arg, + const char *func, + const char *op, + const char *arg, gboolean result, gpointer subject_context, - const char * reason) + const char *reason) { gs_unref_ptrarray GPtrArray *fields = NULL; AuditField arg_field; @@ -355,15 +355,15 @@ _nm_audit_manager_log_generic_op(NMAuditManager *self, void _nm_audit_manager_log_device_op(NMAuditManager *self, - const char * file, + const char *file, guint line, - const char * func, - const char * op, - NMDevice * device, + const char *func, + const char *op, + NMDevice *device, gboolean result, - const char * args, + const char *args, gpointer subject_context, - const char * reason) + const char *reason) { gs_unref_ptrarray GPtrArray *fields = NULL; AuditField interface_field; @@ -402,7 +402,7 @@ static void init_auditd(NMAuditManager *self) { NMAuditManagerPrivate *priv = NM_AUDIT_MANAGER_GET_PRIVATE(self); - NMConfigData * data = nm_config_get_data(priv->config); + NMConfigData *data = nm_config_get_data(priv->config); int errsv; if (nm_config_data_get_value_boolean(data, @@ -427,11 +427,11 @@ init_auditd(NMAuditManager *self) } static void -config_changed_cb(NMConfig * config, - NMConfigData * config_data, +config_changed_cb(NMConfig *config, + NMConfigData *config_data, NMConfigChangeFlags changes, - NMConfigData * old_data, - NMAuditManager * self) + NMConfigData *old_data, + NMAuditManager *self) { if (NM_FLAGS_HAS(changes, NM_CONFIG_CHANGE_VALUES)) init_auditd(self); @@ -461,7 +461,7 @@ static void dispose(GObject *object) { #if HAVE_LIBAUDIT - NMAuditManager * self = NM_AUDIT_MANAGER(object); + NMAuditManager *self = NM_AUDIT_MANAGER(object); NMAuditManagerPrivate *priv = NM_AUDIT_MANAGER_GET_PRIVATE(self); if (priv->config) { diff --git a/src/core/nm-audit-manager.h b/src/core/nm-audit-manager.h index fdabbf28..3a7ea7c0 100644 --- a/src/core/nm-audit-manager.h +++ b/src/core/nm-audit-manager.h @@ -133,36 +133,36 @@ gboolean nm_audit_manager_audit_enabled(NMAuditManager *self); } \ G_STMT_END -void _nm_audit_manager_log_connection_op(NMAuditManager * self, - const char * file, +void _nm_audit_manager_log_connection_op(NMAuditManager *self, + const char *file, guint line, - const char * func, - const char * op, + const char *func, + const char *op, NMSettingsConnection *connection, gboolean result, - const char * args, + const char *args, gpointer subject_context, - const char * reason); + const char *reason); void _nm_audit_manager_log_generic_op(NMAuditManager *self, - const char * file, + const char *file, guint line, - const char * func, - const char * op, - const char * arg, + const char *func, + const char *op, + const char *arg, gboolean result, gpointer subject_context, - const char * reason); + const char *reason); void _nm_audit_manager_log_device_op(NMAuditManager *self, - const char * file, + const char *file, guint line, - const char * func, - const char * op, - NMDevice * device, + const char *func, + const char *op, + NMDevice *device, gboolean result, - const char * args, + const char *args, gpointer subject_context, - const char * reason); + const char *reason); #endif /* __NM_AUDIT_MANAGER_H__ */ diff --git a/src/core/nm-auth-manager.c b/src/core/nm-auth-manager.c index 5c0e465a..0f7e0c0d 100644 --- a/src/core/nm-auth-manager.c +++ b/src/core/nm-auth-manager.c @@ -35,8 +35,8 @@ static guint signals[LAST_SIGNAL] = {0}; typedef struct { CList calls_lst_head; GDBusConnection *dbus_connection; - GCancellable * main_cancellable; - char * name_owner; + GCancellable *main_cancellable; + char *name_owner; guint64 call_numid_counter; guint changed_id; guint name_owner_changed_id; @@ -138,8 +138,8 @@ typedef enum { struct _NMAuthManagerCallId { CList calls_lst; - NMAuthManager * self; - GCancellable * dbus_cancellable; + NMAuthManager *self; + GCancellable *dbus_cancellable; NMAuthManagerCheckAuthorizationCallback callback; gpointer user_data; guint64 call_numid; @@ -173,7 +173,7 @@ static void _call_id_invoke_callback(NMAuthManagerCallId *call_id, gboolean is_authorized, gboolean is_challenge, - GError * error) + GError *error) { c_list_unlink(&call_id->calls_lst); @@ -185,9 +185,9 @@ _call_id_invoke_callback(NMAuthManagerCallId *call_id, static void cancel_check_authorization_cb(GObject *source, GAsyncResult *res, gpointer user_data) { - NMAuthManagerCallId *call_id = user_data; - gs_unref_variant GVariant *value = NULL; - gs_free_error GError *error = NULL; + NMAuthManagerCallId *call_id = user_data; + gs_unref_variant GVariant *value = NULL; + gs_free_error GError *error = NULL; value = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), res, &error); if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) @@ -203,13 +203,13 @@ cancel_check_authorization_cb(GObject *source, GAsyncResult *res, gpointer user_ static void _call_check_authorize_cb(GObject *proxy, GAsyncResult *res, gpointer user_data) { - NMAuthManagerCallId * call_id = user_data; - NMAuthManager * self; - NMAuthManagerPrivate *priv; - gs_unref_variant GVariant *value = NULL; - gs_free_error GError *error = NULL; - gboolean is_authorized = FALSE; - gboolean is_challenge = FALSE; + NMAuthManagerCallId *call_id = user_data; + NMAuthManager *self; + NMAuthManagerPrivate *priv; + gs_unref_variant GVariant *value = NULL; + gs_free_error GError *error = NULL; + gboolean is_authorized = FALSE; + gboolean is_challenge = FALSE; /* we need to clear the cancelable, to signal for _call_id_free() that we * are not in a pending call. @@ -299,17 +299,17 @@ _call_on_idle(gpointer user_data) * which @self must be live long enough). */ NMAuthManagerCallId * -nm_auth_manager_check_authorization(NMAuthManager * self, - NMAuthSubject * subject, - const char * action_id, +nm_auth_manager_check_authorization(NMAuthManager *self, + NMAuthSubject *subject, + const char *action_id, gboolean allow_user_interaction, NMAuthManagerCheckAuthorizationCallback callback, gpointer user_data) { - NMAuthManagerPrivate * priv; + NMAuthManagerPrivate *priv; PolkitCheckAuthorizationFlags flags; char subject_buf[64]; - NMAuthManagerCallId * call_id; + NMAuthManagerCallId *call_id; g_return_val_if_fail(NM_IS_AUTH_MANAGER(self), NULL); g_return_val_if_fail(NM_IN_SET(nm_auth_subject_get_subject_type(subject), @@ -358,10 +358,10 @@ nm_auth_manager_check_authorization(NMAuthManager * self call_id->idle_is_authorized = (priv->auth_polkit_mode == NM_AUTH_POLKIT_MODE_ALLOW_ALL); call_id->idle_id = g_idle_add(_call_on_idle, call_id); } else { - GVariant * parameters; + GVariant *parameters; GVariantBuilder builder; - GVariant * subject_value; - GVariant * details_value; + GVariant *subject_value; + GVariant *details_value; subject_value = nm_auth_subject_unix_to_polkit_gvariant(subject); nm_assert(g_variant_is_floating(subject_value)); @@ -406,7 +406,7 @@ nm_auth_manager_check_authorization(NMAuthManager * self void nm_auth_manager_check_authorization_cancel(NMAuthManagerCallId *call_id) { - NMAuthManager *self; + NMAuthManager *self; gs_free_error GError *error = NULL; g_return_if_fail(call_id); @@ -428,14 +428,14 @@ nm_auth_manager_check_authorization_cancel(NMAuthManagerCallId *call_id) static void changed_signal_cb(GDBusConnection *connection, - const char * sender_name, - const char * object_path, - const char * interface_name, - const char * signal_name, - GVariant * parameters, + const char *sender_name, + const char *object_path, + const char *interface_name, + const char *signal_name, + GVariant *parameters, gpointer user_data) { - NMAuthManager * self = user_data; + NMAuthManager *self = user_data; NMAuthManagerPrivate *priv = NM_AUTH_MANAGER_GET_PRIVATE(self); gboolean valid_sender; @@ -454,7 +454,7 @@ _name_owner_changed(NMAuthManager *self, const char *name_owner, gboolean is_ini { NMAuthManagerPrivate *priv = NM_AUTH_MANAGER_GET_PRIVATE(self); gboolean is_changed; - gs_free char * old_name_owner = NULL; + gs_free char *old_name_owner = NULL; if (is_initial) priv->got_name_owner = TRUE; @@ -496,15 +496,15 @@ _name_owner_changed(NMAuthManager *self, const char *name_owner, gboolean is_ini static void _name_owner_changed_cb(GDBusConnection *connection, - const char * sender_name, - const char * object_path, - const char * interface_name, - const char * signal_name, - GVariant * parameters, + const char *sender_name, + const char *object_path, + const char *interface_name, + const char *signal_name, + GVariant *parameters, gpointer user_data) { NMAuthManager *self = user_data; - const char * new_owner; + const char *new_owner; if (!g_variant_is_of_type(parameters, G_VARIANT_TYPE("(sss)"))) return; @@ -607,10 +607,10 @@ nm_auth_manager_init(NMAuthManager *self) static void constructed(GObject *object) { - NMAuthManager * self = NM_AUTH_MANAGER(object); + NMAuthManager *self = NM_AUTH_MANAGER(object); NMAuthManagerPrivate *priv = NM_AUTH_MANAGER_GET_PRIVATE(self); NMLogLevel logl = LOGL_DEBUG; - const char * create_message; + const char *create_message; G_OBJECT_CLASS(nm_auth_manager_parent_class)->constructed(object); @@ -697,7 +697,7 @@ nm_auth_manager_setup(NMAuthPolkitMode auth_polkit_mode) static void dispose(GObject *object) { - NMAuthManager * self = NM_AUTH_MANAGER(object); + NMAuthManager *self = NM_AUTH_MANAGER(object); NMAuthManagerPrivate *priv = NM_AUTH_MANAGER_GET_PRIVATE(self); _LOGD("dispose"); diff --git a/src/core/nm-auth-manager.h b/src/core/nm-auth-manager.h index 0586322f..db6237d8 100644 --- a/src/core/nm-auth-manager.h +++ b/src/core/nm-auth-manager.h @@ -68,17 +68,17 @@ gboolean nm_auth_manager_get_polkit_enabled(NMAuthManager *self); typedef struct _NMAuthManagerCallId NMAuthManagerCallId; -typedef void (*NMAuthManagerCheckAuthorizationCallback)(NMAuthManager * self, +typedef void (*NMAuthManagerCheckAuthorizationCallback)(NMAuthManager *self, NMAuthManagerCallId *call_id, gboolean is_authorized, gboolean is_challenge, - GError * error, + GError *error, gpointer user_data); NMAuthManagerCallId * -nm_auth_manager_check_authorization(NMAuthManager * self, - NMAuthSubject * subject, - const char * action_id, +nm_auth_manager_check_authorization(NMAuthManager *self, + NMAuthSubject *subject, + const char *action_id, gboolean allow_user_interaction, NMAuthManagerCheckAuthorizationCallback callback, gpointer user_data); diff --git a/src/core/nm-auth-utils.c b/src/core/nm-auth-utils.c index da17b1a4..cef926fd 100644 --- a/src/core/nm-auth-utils.c +++ b/src/core/nm-auth-utils.c @@ -18,7 +18,7 @@ /*****************************************************************************/ typedef struct { - const char * tag; + const char *tag; gpointer data; GDestroyNotify destroy; } ChainData; @@ -33,7 +33,7 @@ struct _NMAuthChain { CList auth_call_lst_head; GDBusMethodInvocation *context; - NMAuthSubject * subject; + NMAuthSubject *subject; GCancellable *cancellable; @@ -56,9 +56,9 @@ G_STATIC_ASSERT(G_STRUCT_OFFSET(NMAuthChain, parent_lst) == 0); typedef struct { CList auth_call_lst; - NMAuthChain * chain; + NMAuthChain *chain; NMAuthManagerCallId *call_id; - const char * permission; + const char *permission; NMAuthCallResult result; } AuthCall; @@ -105,7 +105,7 @@ static gboolean _cancellable_idle_cb(gpointer user_data) { NMAuthChain *self = user_data; - AuthCall * call; + AuthCall *call; nm_assert(g_cancellable_is_cancelled(self->cancellable)); nm_assert(self->cancellable_idle_source); @@ -260,8 +260,8 @@ nm_auth_chain_steal_data(NMAuthChain *self, const char *tag) * It is a bug to add the same tag more than once. */ void -nm_auth_chain_set_data_unsafe(NMAuthChain * self, - const char * tag, +nm_auth_chain_set_data_unsafe(NMAuthChain *self, + const char *tag, gpointer data, GDestroyNotify data_destroy) { @@ -351,15 +351,15 @@ nm_auth_chain_get_context(NMAuthChain *self) /*****************************************************************************/ static void -pk_call_cb(NMAuthManager * auth_manager, +pk_call_cb(NMAuthManager *auth_manager, NMAuthManagerCallId *call_id, gboolean is_authorized, gboolean is_challenge, - GError * error, + GError *error, gpointer user_data) { NMAuthChain *self; - AuthCall * call; + AuthCall *call; nm_assert(call_id); @@ -490,7 +490,7 @@ nm_auth_chain_new_context(GDBusMethodInvocation *context, gpointer user_data) { NMAuthSubject *subject; - NMAuthChain * chain; + NMAuthChain *chain; g_return_val_if_fail(context, NULL); nm_assert(done_func); @@ -505,7 +505,7 @@ nm_auth_chain_new_context(GDBusMethodInvocation *context, } NMAuthChain * -nm_auth_chain_new_subject(NMAuthSubject * subject, +nm_auth_chain_new_subject(NMAuthSubject *subject, GDBusMethodInvocation *context, NMAuthChainResultFunc done_func, gpointer user_data) @@ -603,7 +603,7 @@ gboolean nm_auth_is_subject_in_acl(NMConnection *connection, NMAuthSubject *subject, char **out_error_desc) { NMSettingConnection *s_con; - gs_free char * user = NULL; + gs_free char *user = NULL; gulong uid; g_return_val_if_fail(connection, FALSE); @@ -647,11 +647,11 @@ nm_auth_is_subject_in_acl(NMConnection *connection, NMAuthSubject *subject, char } gboolean -nm_auth_is_subject_in_acl_set_error(NMConnection * connection, +nm_auth_is_subject_in_acl_set_error(NMConnection *connection, NMAuthSubject *subject, GQuark err_domain, int err_code, - GError ** error) + GError **error) { char *error_desc = NULL; @@ -666,12 +666,12 @@ nm_auth_is_subject_in_acl_set_error(NMConnection * connection, } gboolean -nm_auth_is_invocation_in_acl_set_error(NMConnection * connection, +nm_auth_is_invocation_in_acl_set_error(NMConnection *connection, GDBusMethodInvocation *invocation, GQuark err_domain, int err_code, - NMAuthSubject ** out_subject, - GError ** error) + NMAuthSubject **out_subject, + GError **error) { gs_unref_object NMAuthSubject *subject = NULL; gboolean success; diff --git a/src/core/nm-auth-utils.h b/src/core/nm-auth-utils.h index 999dacf5..cb65833c 100644 --- a/src/core/nm-auth-utils.h +++ b/src/core/nm-auth-utils.h @@ -14,7 +14,7 @@ typedef struct _NMAuthChain NMAuthChain; -typedef void (*NMAuthChainResultFunc)(NMAuthChain * chain, +typedef void (*NMAuthChainResultFunc)(NMAuthChain *chain, GDBusMethodInvocation *context, gpointer user_data); @@ -22,7 +22,7 @@ NMAuthChain *nm_auth_chain_new_context(GDBusMethodInvocation *context, NMAuthChainResultFunc done_func, gpointer user_data); -NMAuthChain *nm_auth_chain_new_subject(NMAuthSubject * subject, +NMAuthChain *nm_auth_chain_new_subject(NMAuthSubject *subject, GDBusMethodInvocation *context, NMAuthChainResultFunc done_func, gpointer user_data); @@ -34,8 +34,8 @@ gpointer nm_auth_chain_get_data(NMAuthChain *chain, const char *tag); gpointer nm_auth_chain_steal_data(NMAuthChain *chain, const char *tag); -void nm_auth_chain_set_data_unsafe(NMAuthChain * chain, - const char * tag, +void nm_auth_chain_set_data_unsafe(NMAuthChain *chain, + const char *tag, gpointer data, GDestroyNotify data_destroy); @@ -45,7 +45,7 @@ void nm_auth_chain_set_data_unsafe(NMAuthChain * chain, NMAuthCallResult nm_auth_chain_get_result(NMAuthChain *chain, const char *permission); void nm_auth_chain_add_call_unsafe(NMAuthChain *chain, - const char * permission, + const char *permission, gboolean allow_interaction); #define nm_auth_chain_add_call(chain, permission, allow_interaction) \ @@ -79,17 +79,17 @@ nm_auth_chain_parent_lst_list(NMAuthChain *self) gboolean nm_auth_is_subject_in_acl(NMConnection *connection, NMAuthSubject *subject, char **out_error_desc); -gboolean nm_auth_is_subject_in_acl_set_error(NMConnection * connection, +gboolean nm_auth_is_subject_in_acl_set_error(NMConnection *connection, NMAuthSubject *subject, GQuark err_domain, int err_code, - GError ** error); + GError **error); -gboolean nm_auth_is_invocation_in_acl_set_error(NMConnection * connection, +gboolean nm_auth_is_invocation_in_acl_set_error(NMConnection *connection, GDBusMethodInvocation *invocation, GQuark err_domain, int err_code, - NMAuthSubject ** out_subject, - GError ** error); + NMAuthSubject **out_subject, + GError **error); #endif /* __NETWORKMANAGER_MANAGER_AUTH_H__ */ diff --git a/src/core/nm-checkpoint-manager.c b/src/core/nm-checkpoint-manager.c index b8c9101a..4a3e7aaf 100644 --- a/src/core/nm-checkpoint-manager.c +++ b/src/core/nm-checkpoint-manager.c @@ -18,7 +18,7 @@ /*****************************************************************************/ struct _NMCheckpointManager { - NMManager * _manager; + NMManager *_manager; GParamSpec *property_spec; CList checkpoints_lst_head; }; @@ -70,7 +70,7 @@ destroy_checkpoint(NMCheckpointManager *self, NMCheckpoint *checkpoint, gboolean static GVariant * rollback_checkpoint(NMCheckpointManager *self, NMCheckpoint *checkpoint) { - GVariant * result; + GVariant *result; const CList *iter; nm_assert(c_list_contains(&self->checkpoints_lst_head, &checkpoint->checkpoints_lst)); @@ -95,23 +95,23 @@ rollback_checkpoint(NMCheckpointManager *self, NMCheckpoint *checkpoint) static void rollback_timeout_cb(NMCheckpoint *checkpoint, gpointer user_data) { - NMCheckpointManager *self = user_data; + NMCheckpointManager *self = user_data; gs_unref_variant GVariant *result = NULL; result = rollback_checkpoint(self, checkpoint); } NMCheckpoint * -nm_checkpoint_manager_create(NMCheckpointManager * self, - const char *const * device_paths, +nm_checkpoint_manager_create(NMCheckpointManager *self, + const char *const *device_paths, guint32 rollback_timeout, NMCheckpointCreateFlags flags, - GError ** error) + GError **error) { - NMManager * manager; - NMCheckpoint * checkpoint; + NMManager *manager; + NMCheckpoint *checkpoint; gs_unref_ptrarray GPtrArray *devices = NULL; - NMDevice * device; + NMDevice *device; g_return_val_if_fail(self, FALSE); g_return_val_if_fail(!error || !*error, FALSE); @@ -233,9 +233,9 @@ nm_checkpoint_manager_destroy(NMCheckpointManager *self, const char *path, GErro gboolean nm_checkpoint_manager_rollback(NMCheckpointManager *self, - const char * path, - GVariant ** results, - GError ** error) + const char *path, + GVariant **results, + GError **error) { NMCheckpoint *checkpoint; @@ -279,7 +279,7 @@ const char ** nm_checkpoint_manager_get_checkpoint_paths(NMCheckpointManager *self, guint *out_length) { NMCheckpoint *checkpoint; - const char ** strv; + const char **strv; guint num, i = 0; num = c_list_length(&self->checkpoints_lst_head); @@ -297,9 +297,9 @@ nm_checkpoint_manager_get_checkpoint_paths(NMCheckpointManager *self, guint *out gboolean nm_checkpoint_manager_adjust_rollback_timeout(NMCheckpointManager *self, - const char * path, + const char *path, guint32 add_timeout, - GError ** error) + GError **error) { NMCheckpoint *checkpoint; diff --git a/src/core/nm-checkpoint-manager.h b/src/core/nm-checkpoint-manager.h index 7fe86d60..e4e29f48 100644 --- a/src/core/nm-checkpoint-manager.h +++ b/src/core/nm-checkpoint-manager.h @@ -19,26 +19,26 @@ void nm_checkpoint_manager_free(NMCheckpointManager *self); NMCheckpoint * nm_checkpoint_manager_lookup_by_path(NMCheckpointManager *self, const char *path, GError **error); -NMCheckpoint *nm_checkpoint_manager_create(NMCheckpointManager * self, - const char *const * device_names, +NMCheckpoint *nm_checkpoint_manager_create(NMCheckpointManager *self, + const char *const *device_names, guint32 rollback_timeout, NMCheckpointCreateFlags flags, - GError ** error); + GError **error); void nm_checkpoint_manager_destroy_all(NMCheckpointManager *self); gboolean nm_checkpoint_manager_destroy(NMCheckpointManager *self, const char *path, GError **error); gboolean nm_checkpoint_manager_rollback(NMCheckpointManager *self, - const char * path, - GVariant ** results, - GError ** error); + const char *path, + GVariant **results, + GError **error); gboolean nm_checkpoint_manager_adjust_rollback_timeout(NMCheckpointManager *self, - const char * path, + const char *path, guint32 add_timeout, - GError ** error); + GError **error); const char **nm_checkpoint_manager_get_checkpoint_paths(NMCheckpointManager *self, - guint * out_length); + guint *out_length); #endif /* __NM_CHECKPOINT_MANAGER_H__ */ diff --git a/src/core/nm-checkpoint.c b/src/core/nm-checkpoint.c index 164f4a86..0153af97 100644 --- a/src/core/nm-checkpoint.c +++ b/src/core/nm-checkpoint.c @@ -22,12 +22,12 @@ /*****************************************************************************/ typedef struct { - char * original_dev_path; - char * original_dev_name; + char *original_dev_path; + char *original_dev_name; NMDeviceType dev_type; - NMDevice * device; - NMConnection * applied_connection; - NMConnection * settings_connection; + NMDevice *device; + NMConnection *applied_connection; + NMConnection *settings_connection; guint64 ac_version_id; NMDeviceState state; bool is_software : 1; @@ -43,14 +43,14 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMCheckpoint, PROP_DEVICES, PROP_CREATED, PROP_ROLL struct _NMCheckpointPrivate { /* properties */ GHashTable *devices; - GPtrArray * removed_devices; + GPtrArray *removed_devices; gint64 created_at_ms; guint32 rollback_timeout_s; guint timeout_id; /* private members */ - NMManager * manager; + NMManager *manager; NMCheckpointCreateFlags flags; - GHashTable * connection_uuids; + GHashTable *connection_uuids; gulong dev_removed_id; NMCheckpointTimeoutCallback timeout_cb; @@ -105,7 +105,7 @@ nm_checkpoint_log_destroy(NMCheckpoint *self) } void -nm_checkpoint_set_timeout_callback(NMCheckpoint * self, +nm_checkpoint_set_timeout_callback(NMCheckpoint *self, NMCheckpointTimeoutCallback callback, gpointer user_data) { @@ -137,7 +137,7 @@ nm_checkpoint_includes_devices_of(NMCheckpoint *self, NMCheckpoint *cp_for_devic NMCheckpointPrivate *priv = NM_CHECKPOINT_GET_PRIVATE(self); NMCheckpointPrivate *priv2 = NM_CHECKPOINT_GET_PRIVATE(cp_for_devices); GHashTableIter iter; - NMDevice * device; + NMDevice *device; g_hash_table_iter_init(&iter, priv2->devices); while (g_hash_table_iter_next(&iter, (gpointer *) &device, NULL)) { @@ -148,16 +148,16 @@ nm_checkpoint_includes_devices_of(NMCheckpoint *self, NMCheckpoint *cp_for_devic } static NMSettingsConnection * -find_settings_connection(NMCheckpoint * self, +find_settings_connection(NMCheckpoint *self, DeviceCheckpoint *dev_checkpoint, - gboolean * need_update, - gboolean * need_activation) + gboolean *need_update, + gboolean *need_activation) { - NMCheckpointPrivate * priv = NM_CHECKPOINT_GET_PRIVATE(self); - NMActiveConnection * active; + NMCheckpointPrivate *priv = NM_CHECKPOINT_GET_PRIVATE(self); + NMActiveConnection *active; NMSettingsConnection *sett_conn; - const char * uuid, *ac_uuid; - const CList * tmp_clist; + const char *uuid, *ac_uuid; + const CList *tmp_clist; *need_activation = FALSE; *need_update = FALSE; @@ -205,10 +205,10 @@ find_settings_connection(NMCheckpoint * self, static gboolean restore_and_activate_connection(NMCheckpoint *self, DeviceCheckpoint *dev_checkpoint) { - NMCheckpointPrivate * priv = NM_CHECKPOINT_GET_PRIVATE(self); - NMSettingsConnection *connection; - gs_unref_object NMAuthSubject * subject = NULL; - GError * local_error = NULL; + NMCheckpointPrivate *priv = NM_CHECKPOINT_GET_PRIVATE(self); + NMSettingsConnection *connection; + gs_unref_object NMAuthSubject *subject = NULL; + GError *local_error = NULL; gboolean need_update, need_activation; NMSettingsConnectionPersistMode persist_mode; NMSettingsConnectionIntFlags sett_flags; @@ -315,9 +315,9 @@ GVariant * nm_checkpoint_rollback(NMCheckpoint *self) { NMCheckpointPrivate *priv = NM_CHECKPOINT_GET_PRIVATE(self); - DeviceCheckpoint * dev_checkpoint; + DeviceCheckpoint *dev_checkpoint; GHashTableIter iter; - NMDevice * device; + NMDevice *device; GVariantBuilder builder; uint i; @@ -424,7 +424,7 @@ next_dev: } if (NM_FLAGS_HAS(priv->flags, NM_CHECKPOINT_CREATE_FLAG_DELETE_NEW_CONNECTIONS)) { - NMSettingsConnection *con; + NMSettingsConnection *con; gs_free NMSettingsConnection **list = NULL; g_return_val_if_fail(priv->connection_uuids, NULL); @@ -447,7 +447,7 @@ next_dev: } if (NM_FLAGS_HAS(priv->flags, NM_CHECKPOINT_CREATE_FLAG_DISCONNECT_NEW_DEVICES)) { - const CList * tmp_lst; + const CList *tmp_lst; NMDeviceState state; nm_manager_for_each_device (priv->manager, device, tmp_lst) { @@ -485,7 +485,7 @@ static void _move_dev_to_removed_devices(NMDevice *device, NMCheckpoint *checkpoint) { NMCheckpointPrivate *priv = NM_CHECKPOINT_GET_PRIVATE(checkpoint); - DeviceCheckpoint * dev_checkpoint; + DeviceCheckpoint *dev_checkpoint; g_return_if_fail(device); @@ -514,11 +514,11 @@ _dev_exported_changed(NMDBusObject *obj, NMCheckpoint *checkpoint) static DeviceCheckpoint * device_checkpoint_create(NMCheckpoint *checkpoint, NMDevice *device) { - DeviceCheckpoint * dev_checkpoint; - NMConnection * applied_connection; + DeviceCheckpoint *dev_checkpoint; + NMConnection *applied_connection; NMSettingsConnection *settings_connection; - const char * path; - NMActRequest * act_request; + const char *path; + NMActRequest *act_request; nm_assert(NM_IS_DEVICE(device)); nm_assert(nm_device_is_real(device)); @@ -567,7 +567,7 @@ device_checkpoint_create(NMCheckpoint *checkpoint, NMDevice *device) static gboolean _timeout_cb(gpointer user_data) { - NMCheckpoint * self = user_data; + NMCheckpoint *self = user_data; NMCheckpointPrivate *priv = NM_CHECKPOINT_GET_PRIVATE(self); priv->timeout_id = 0; @@ -619,7 +619,7 @@ nm_checkpoint_adjust_rollback_timeout(NMCheckpoint *self, guint32 add_timeout) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMCheckpoint * self = NM_CHECKPOINT(object); + NMCheckpoint *self = NM_CHECKPOINT(object); NMCheckpointPrivate *priv = NM_CHECKPOINT_GET_PRIVATE(self); switch (prop_id) { @@ -663,13 +663,13 @@ _device_removed(NMManager *manager, NMDevice *device, gpointer user_data) } NMCheckpoint * -nm_checkpoint_new(NMManager * manager, - GPtrArray * devices, +nm_checkpoint_new(NMManager *manager, + GPtrArray *devices, guint32 rollback_timeout_s, NMCheckpointCreateFlags flags) { - NMCheckpoint * self; - NMCheckpointPrivate * priv; + NMCheckpoint *self; + NMCheckpointPrivate *priv; NMSettingsConnection *const *con; gint64 rollback_timeout_ms; guint i; @@ -719,7 +719,7 @@ nm_checkpoint_new(NMManager * manager, static void dispose(GObject *object) { - NMCheckpoint * self = NM_CHECKPOINT(object); + NMCheckpoint *self = NM_CHECKPOINT(object); NMCheckpointPrivate *priv = NM_CHECKPOINT_GET_PRIVATE(self); nm_assert(c_list_is_empty(&self->checkpoints_lst)); @@ -750,7 +750,7 @@ static const NMDBusInterfaceInfoExtended interface_info_checkpoint = { static void nm_checkpoint_class_init(NMCheckpointClass *checkpoint_class) { - GObjectClass * object_class = G_OBJECT_CLASS(checkpoint_class); + GObjectClass *object_class = G_OBJECT_CLASS(checkpoint_class); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(checkpoint_class); g_type_class_add_private(object_class, sizeof(NMCheckpointPrivate)); diff --git a/src/core/nm-checkpoint.h b/src/core/nm-checkpoint.h index 28c936fa..db33b6e7 100644 --- a/src/core/nm-checkpoint.h +++ b/src/core/nm-checkpoint.h @@ -34,8 +34,8 @@ typedef struct _NMCheckpointClass NMCheckpointClass; GType nm_checkpoint_get_type(void); -NMCheckpoint *nm_checkpoint_new(NMManager * manager, - GPtrArray * devices, +NMCheckpoint *nm_checkpoint_new(NMManager *manager, + GPtrArray *devices, guint32 rollback_timeout, NMCheckpointCreateFlags flags); @@ -43,7 +43,7 @@ typedef void (*NMCheckpointTimeoutCallback)(NMCheckpoint *self, gpointer user_da void nm_checkpoint_log_destroy(NMCheckpoint *self); -void nm_checkpoint_set_timeout_callback(NMCheckpoint * self, +void nm_checkpoint_set_timeout_callback(NMCheckpoint *self, NMCheckpointTimeoutCallback callback, gpointer user_data); diff --git a/src/core/nm-config-data.c b/src/core/nm-config-data.c index 1cb8a43c..ddb7787f 100644 --- a/src/core/nm-config-data.c +++ b/src/core/nm-config-data.c @@ -17,18 +17,18 @@ /*****************************************************************************/ typedef struct { - char * group_name; + char *group_name; gboolean stop_match; struct { /* have a separate boolean field @has, because a @spec with * value %NULL does not necessarily mean, that the property * "match-device" was unspecified. */ gboolean has; - GSList * spec; + GSList *spec; } match_device; union { struct { - GSList * allowed_connections; + GSList *allowed_connections; gboolean allowed_connections_has; } device; }; @@ -40,15 +40,15 @@ typedef struct { } MatchSectionInfo; struct _NMGlobalDnsDomain { - char * name; + char *name; char **servers; char **options; }; struct _NMGlobalDnsConfig { - char ** searches; - char ** options; - GHashTable * domains; + char **searches; + char **options; + GHashTable *domains; const char **domain_list; gboolean internal; }; @@ -83,8 +83,8 @@ typedef struct { struct { gboolean enabled; - char * uri; - char * response; + char *uri; + char *response; guint interval; } connectivity; @@ -92,7 +92,7 @@ typedef struct { struct { /* from /var/lib/NetworkManager/no-auto-default.state */ - char ** arr; + char **arr; GSList *specs; /* from main.no-auto-default setting in NetworkManager.conf. */ @@ -158,9 +158,9 @@ nm_config_data_has_group(const NMConfigData *self, const char *group) } char * -nm_config_data_get_value(const NMConfigData * self, - const char * group, - const char * key, +nm_config_data_get_value(const NMConfigData *self, + const char *group, + const char *key, NMConfigGetValueFlags flags) { g_return_val_if_fail(NM_IS_CONFIG_DATA(self), NULL); @@ -174,9 +174,9 @@ nm_config_data_get_value(const NMConfigData * self, } gboolean -nm_config_data_has_value(const NMConfigData * self, - const char * group, - const char * key, +nm_config_data_has_value(const NMConfigData *self, + const char *group, + const char *key, NMConfigGetValueFlags flags) { gs_free char *value = NULL; @@ -192,8 +192,8 @@ nm_config_data_has_value(const NMConfigData * self, int nm_config_data_get_value_boolean(const NMConfigData *self, - const char * group, - const char * key, + const char *group, + const char *key, int default_value) { char *str; @@ -217,8 +217,8 @@ nm_config_data_get_value_boolean(const NMConfigData *self, gint64 nm_config_data_get_value_int64(const NMConfigData *self, - const char * group, - const char * key, + const char *group, + const char *key, guint base, gint64 min, gint64 max, @@ -226,7 +226,7 @@ nm_config_data_get_value_int64(const NMConfigData *self, { int errsv; gint64 val; - char * str; + char *str; g_return_val_if_fail(NM_IS_CONFIG_DATA(self), fallback); g_return_val_if_fail(group && *group, fallback); @@ -248,9 +248,9 @@ nm_config_data_get_value_int64(const NMConfigData *self, char ** nm_config_data_get_plugins(const NMConfigData *self, gboolean allow_default) { - gs_free_error GError * error = NULL; + gs_free_error GError *error = NULL; const NMConfigDataPrivate *priv; - char ** list; + char **list; g_return_val_if_fail(self, NULL); @@ -406,7 +406,7 @@ GKeyFile * nm_config_data_clone_keyfile_intern(const NMConfigData *self) { const NMConfigDataPrivate *priv; - GKeyFile * keyfile; + GKeyFile *keyfile; g_return_val_if_fail(NM_IS_CONFIG_DATA(self), FALSE); @@ -461,7 +461,7 @@ static NMAuthPolkitMode _config_data_get_main_auth_polkit(const NMConfigData *self, gboolean *out_invalid_config) { NMAuthPolkitMode auth_polkit_mode; - gs_free char * str = NULL; + gs_free char *str = NULL; str = nm_config_data_get_value(self, NM_CONFIG_KEYFILE_GROUP_MAIN, @@ -560,7 +560,7 @@ _merge_keyfiles(GKeyFile *keyfile_user, GKeyFile *keyfile_intern) { gs_strfreev char **groups = NULL; guint g, k; - GKeyFile * keyfile; + GKeyFile *keyfile; gsize ngroups; keyfile = nm_config_create_keyfile(); @@ -577,7 +577,7 @@ _merge_keyfiles(GKeyFile *keyfile_user, GKeyFile *keyfile_intern) * have lowest priority last. */ _nm_config_sort_groups(groups, ngroups); for (g = 0; groups[g]; g++) { - const char * group = groups[g]; + const char *group = groups[g]; gs_strfreev char **keys = NULL; gboolean is_intern, is_atomic = FALSE; @@ -597,7 +597,7 @@ _merge_keyfiles(GKeyFile *keyfile_user, GKeyFile *keyfile_intern) } for (k = 0; keys[k]; k++) { - const char * key = keys[k]; + const char *key = keys[k]; gs_free char *value = NULL; if (is_atomic && nm_streq(key, NM_CONFIG_KEYFILE_KEY_ATOMIC_SECTION_WAS)) @@ -711,20 +711,23 @@ static const struct { {NM_CONFIG_KEYFILE_GROUP_MAIN, NM_CONFIG_KEYFILE_KEY_MAIN_IWD_CONFIG_PATH, ""}, {NM_CONFIG_KEYFILE_GROUP_LOGGING, "backend", NM_CONFIG_DEFAULT_LOGGING_BACKEND}, {NM_CONFIG_KEYFILE_GROUP_LOGGING, "audit", NM_CONFIG_DEFAULT_LOGGING_AUDIT}, + {NM_CONFIG_KEYFILE_GROUPPREFIX_DEVICE, + NM_CONFIG_KEYFILE_KEY_DEVICE_WIFI_BACKEND, + NM_CONFIG_DEFAULT_WIFI_BACKEND}, }; void -nm_config_data_log(const NMConfigData * self, - const char * prefix, - const char * key_prefix, - const char * no_auto_default_file, +nm_config_data_log(const NMConfigData *self, + const char *prefix, + const char *key_prefix, + const char *no_auto_default_file, /* FILE* */ gpointer print_stream) { - const NMConfigDataPrivate *priv; - gs_strfreev char ** groups = NULL; - gsize ngroups; - guint g, k, i; - FILE * stream = print_stream; + const NMConfigDataPrivate *priv; + gs_strfreev char **groups = NULL; + gsize ngroups; + guint g, k, i; + FILE *stream = print_stream; gs_unref_ptrarray GPtrArray *groups_full = NULL; gboolean print_default = !!stream; @@ -792,7 +795,7 @@ nm_config_data_log(const NMConfigData * self, _LOG(stream, prefix, "config-data[%p]: %u groups", self, groups_full->len); for (g = 0; g < groups_full->len; g++) { - const char * group = groups_full->pdata[g]; + const char *group = groups_full->pdata[g]; gs_strfreev char **keys = NULL; gboolean is_atomic; @@ -818,7 +821,7 @@ nm_config_data_log(const NMConfigData * self, keys = g_key_file_get_keys(priv->keyfile, group, NULL, NULL); for (k = 0; keys && keys[k]; k++) { - const char * key = keys[k]; + const char *key = keys[k]; gs_free char *value = NULL; value = g_key_file_get_value(priv->keyfile, group, key, NULL); @@ -929,6 +932,59 @@ nm_global_dns_config_is_empty(const NMGlobalDnsConfig *dns_config) return !dns_config->searches && !dns_config->options && !dns_config->domain_list; } +int +nm_global_dns_config_cmp(const NMGlobalDnsConfig *a, + const NMGlobalDnsConfig *b, + gboolean check_internal) +{ + guint i; + + NM_CMP_SELF(a, b); + + NM_CMP_RETURN( + nm_strv_cmp_n(a->searches ?: NM_STRV_EMPTY(), -1, b->searches ?: NM_STRV_EMPTY(), -1)); + + NM_CMP_RETURN( + nm_strv_cmp_n(a->options ?: NM_STRV_EMPTY(), -1, b->options ?: NM_STRV_EMPTY(), -1)); + + NM_CMP_RETURN(nm_strv_cmp_n(a->domain_list ?: NM_STRV_EMPTY_CC(), + -1, + b->domain_list ?: NM_STRV_EMPTY_CC(), + -1)); + + if (a->domain_list) { + for (i = 0; a->domain_list[i]; i++) { + const NMGlobalDnsDomain *domain_a; + const NMGlobalDnsDomain *domain_b; + + nm_assert(nm_streq(a->domain_list[i], b->domain_list[i])); + + domain_a = g_hash_table_lookup(a->domains, a->domain_list[i]); + nm_assert(domain_a); + + domain_b = g_hash_table_lookup(b->domains, b->domain_list[i]); + nm_assert(domain_b); + + NM_CMP_FIELD_STR0(domain_a, domain_b, name); + + NM_CMP_RETURN(nm_strv_cmp_n(domain_a->servers ?: NM_STRV_EMPTY(), + -1, + domain_b->servers ?: NM_STRV_EMPTY(), + -1)); + + NM_CMP_RETURN(nm_strv_cmp_n(domain_a->options ?: NM_STRV_EMPTY(), + -1, + domain_b->options ?: NM_STRV_EMPTY(), + -1)); + } + } + + if (check_internal) + NM_CMP_FIELD(a, b, internal); + + return 0; +} + void nm_global_dns_config_update_checksum(const NMGlobalDnsConfig *dns_config, GChecksum *sum) { @@ -1033,11 +1089,11 @@ static NMGlobalDnsConfig * load_global_dns(GKeyFile *keyfile, gboolean internal) { NMGlobalDnsConfig *dns_config; - char * group, *domain_prefix; + char *group, *domain_prefix; gs_strfreev char **groups = NULL; int g, i, j, domain_prefix_len; gboolean default_found = FALSE; - char ** strv; + char **strv; group = internal ? NM_CONFIG_KEYFILE_GROUP_INTERN_GLOBAL_DNS : NM_CONFIG_KEYFILE_GROUP_GLOBAL_DNS; @@ -1090,8 +1146,8 @@ load_global_dns(GKeyFile *keyfile, gboolean internal) groups = g_key_file_get_groups(keyfile, NULL); for (g = 0; groups[g]; g++) { - char * name; - char ** servers = NULL, **options = NULL; + char *name; + char **servers = NULL, **options = NULL; NMGlobalDnsDomain *domain; if (!g_str_has_prefix(groups[g], domain_prefix) || !groups[g][domain_prefix_len]) @@ -1226,8 +1282,8 @@ global_dns_domain_from_dbus(char *name, GVariant *variant) { NMGlobalDnsDomain *domain; GVariantIter iter; - char ** strv, *key; - GVariant * val; + char **strv, *key; + GVariant *val; int i, j; if (!g_variant_is_of_type(variant, G_VARIANT_TYPE("a{sv}"))) @@ -1279,9 +1335,9 @@ NMGlobalDnsConfig * nm_global_dns_config_from_dbus(const GValue *value, GError **error) { NMGlobalDnsConfig *dns_config; - GVariant * variant, *val; + GVariant *variant, *val; GVariantIter iter; - char ** strv, *key; + char **strv, *key; int i, j; if (!G_VALUE_HOLDS_VARIANT(value)) { @@ -1326,8 +1382,8 @@ nm_global_dns_config_from_dbus(const GValue *value, GError **error) && g_variant_is_of_type(val, G_VARIANT_TYPE("a{sv}"))) { NMGlobalDnsDomain *domain; GVariantIter domain_iter; - GVariant * v; - char * k; + GVariant *v; + char *k; g_variant_iter_init(&domain_iter, val); while (g_variant_iter_next(&domain_iter, "{&sv}", &k, &v)) { @@ -1400,12 +1456,12 @@ global_dns_equal(NMGlobalDnsConfig *old, NMGlobalDnsConfig *new) static const MatchSectionInfo * _match_section_infos_lookup(const MatchSectionInfo *match_section_infos, - GKeyFile * keyfile, - const char * property, - NMDevice * device, - const NMPlatformLink * pllink, - const char * match_device_type, - const char ** out_value) + GKeyFile *keyfile, + const char *property, + NMDevice *device, + const NMPlatformLink *pllink, + const char *match_device_type, + const char **out_value) { const char *match_dhcp_plugin; @@ -1456,13 +1512,13 @@ out: const char * nm_config_data_get_device_config(const NMConfigData *self, - const char * property, - NMDevice * device, - gboolean * has_match) + const char *property, + NMDevice *device, + gboolean *has_match) { const NMConfigDataPrivate *priv; - const MatchSectionInfo * connection_info; - const char * value; + const MatchSectionInfo *connection_info; + const char *value; NM_SET_OUT(has_match, FALSE); @@ -1483,15 +1539,15 @@ nm_config_data_get_device_config(const NMConfigData *self, } const char * -nm_config_data_get_device_config_by_pllink(const NMConfigData * self, - const char * property, +nm_config_data_get_device_config_by_pllink(const NMConfigData *self, + const char *property, const NMPlatformLink *pllink, - const char * match_device_type, - gboolean * has_match) + const char *match_device_type, + gboolean *has_match) { const NMConfigDataPrivate *priv; - const MatchSectionInfo * connection_info; - const char * value; + const MatchSectionInfo *connection_info; + const char *value; g_return_val_if_fail(self, NULL); g_return_val_if_fail(property && *property, NULL); @@ -1511,8 +1567,8 @@ nm_config_data_get_device_config_by_pllink(const NMConfigData * self, gboolean nm_config_data_get_device_config_boolean(const NMConfigData *self, - const char * property, - NMDevice * device, + const char *property, + NMDevice *device, int val_no_match, int val_invalid) { @@ -1527,8 +1583,8 @@ nm_config_data_get_device_config_boolean(const NMConfigData *self, gint64 nm_config_data_get_device_config_int64(const NMConfigData *self, - const char * property, - NMDevice * device, + const char *property, + NMDevice *device, int base, gint64 min, gint64 max, @@ -1548,12 +1604,12 @@ nm_config_data_get_device_config_int64(const NMConfigData *self, const GSList * nm_config_data_get_device_allowed_connections_specs(const NMConfigData *self, - NMDevice * device, - gboolean * has_match) + NMDevice *device, + gboolean *has_match) { const NMConfigDataPrivate *priv; - const MatchSectionInfo * connection_info; - const GSList * ret = NULL; + const MatchSectionInfo *connection_info; + const GSList *ret = NULL; g_return_val_if_fail(self, NULL); @@ -1579,11 +1635,11 @@ nm_config_data_get_device_allowed_connections_specs(const NMConfigData *self, const char * nm_config_data_get_connection_default(const NMConfigData *self, - const char * property, - NMDevice * device) + const char *property, + NMDevice *device) { const NMConfigDataPrivate *priv; - const char * value; + const char *value; g_return_val_if_fail(self, NULL); g_return_val_if_fail(property && *property, NULL); @@ -1616,8 +1672,8 @@ nm_config_data_get_connection_default(const NMConfigData *self, gint64 nm_config_data_get_connection_default_int64(const NMConfigData *self, - const char * property, - NMDevice * device, + const char *property, + NMDevice *device, gint64 min, gint64 max, gint64 fallback) @@ -1650,11 +1706,11 @@ _match_section_info_get_str(const MatchSectionInfo *m, GKeyFile *keyfile, const static void _match_section_info_init(MatchSectionInfo *connection_info, - GKeyFile * keyfile, - char * group, + GKeyFile *keyfile, + char *group, gboolean is_device) { - char ** keys = NULL; + char **keys = NULL; gsize n_keys; gsize i; gsize j; @@ -1686,7 +1742,7 @@ _match_section_info_init(MatchSectionInfo *connection_info, for (i = 0, j = 0; i < n_keys; i++) { gs_free char *key = g_steal_pointer(&keys[i]); - char * value; + char *value; if (NM_IN_STRSET(key, NM_CONFIG_KEYFILE_KEY_STOP_MATCH, NM_CONFIG_KEYFILE_KEY_MATCH_DEVICE)) continue; @@ -1749,11 +1805,11 @@ _match_section_infos_free(MatchSectionInfo *match_section_infos) static MatchSectionInfo * _match_section_infos_construct(GKeyFile *keyfile, gboolean is_device) { - char ** groups; + char **groups; gsize i, j, ngroups; - char * connection_tag = NULL; + char *connection_tag = NULL; MatchSectionInfo *match_section_infos = NULL; - const char * prefix; + const char *prefix; prefix = is_device ? NM_CONFIG_KEYFILE_GROUPPREFIX_DEVICE : NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION; @@ -1920,7 +1976,7 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - NMConfigData * self = NM_CONFIG_DATA(object); + NMConfigData *self = NM_CONFIG_DATA(object); NMConfigDataPrivate *priv = NM_CONFIG_DATA_GET_PRIVATE(self); switch (prop_id) { @@ -1951,9 +2007,9 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps case PROP_NO_AUTO_DEFAULT: /* construct-only */ { - const char *const * value_arr_orig = g_value_get_boxed(value); + const char *const *value_arr_orig = g_value_get_boxed(value); gs_free const char **value_arr = NULL; - GSList * specs = NULL; + GSList *specs = NULL; gsize i, j; gsize len; @@ -1970,7 +2026,7 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps for (i = 0; i < len; i++) { const char *s = value_arr[i]; gboolean is_mac; - char * spec; + char *spec; if (NM_STR_HAS_PREFIX(s, NM_MATCH_SPEC_INTERFACE_NAME_TAG "=")) is_mac = FALSE; @@ -2006,9 +2062,9 @@ nm_config_data_init(NMConfigData *self) static void constructed(GObject *object) { - NMConfigData * self = NM_CONFIG_DATA(object); + NMConfigData *self = NM_CONFIG_DATA(object); NMConfigDataPrivate *priv = NM_CONFIG_DATA_GET_PRIVATE(self); - char * str; + char *str; priv->keyfile = _merge_keyfiles(priv->keyfile_user, priv->keyfile_intern); @@ -2092,11 +2148,11 @@ constructed(GObject *object) } NMConfigData * -nm_config_data_new(const char * config_main_file, - const char * config_description, +nm_config_data_new(const char *config_main_file, + const char *config_description, const char *const *no_auto_default, - GKeyFile * keyfile_user, - GKeyFile * keyfile_intern) + GKeyFile *keyfile_user, + GKeyFile *keyfile_intern) { return g_object_new(NM_TYPE_CONFIG_DATA, NM_CONFIG_DATA_CONFIG_MAIN_FILE, @@ -2133,7 +2189,7 @@ nm_config_data_new_update_keyfile_intern(const NMConfigData *base, GKeyFile *key NMConfigData * nm_config_data_new_update_no_auto_default(const NMConfigData *base, - const char *const * no_auto_default) + const char *const *no_auto_default) { const NMConfigDataPrivate *priv = NM_CONFIG_DATA_GET_PRIVATE(base); diff --git a/src/core/nm-config-data.h b/src/core/nm-config-data.h index 92a7cb5c..fdc7e1fc 100644 --- a/src/core/nm-config-data.h +++ b/src/core/nm-config-data.h @@ -125,49 +125,49 @@ typedef struct _NMGlobalDnsDomain NMGlobalDnsDomain; GType nm_config_data_get_type(void); -NMConfigData *nm_config_data_new(const char * config_main_file, - const char * config_description, +NMConfigData *nm_config_data_new(const char *config_main_file, + const char *config_description, const char *const *no_auto_default, - GKeyFile * keyfile_user, - GKeyFile * keyfile_intern); + GKeyFile *keyfile_user, + GKeyFile *keyfile_intern); NMConfigData *nm_config_data_new_update_keyfile_intern(const NMConfigData *base, - GKeyFile * keyfile_intern); + GKeyFile *keyfile_intern); NMConfigData *nm_config_data_new_update_no_auto_default(const NMConfigData *base, - const char *const * no_auto_default); + const char *const *no_auto_default); NMConfigChangeFlags nm_config_data_diff(NMConfigData *old_data, NMConfigData *new_data); -void nm_config_data_log(const NMConfigData * self, - const char * prefix, - const char * key_prefix, - const char * no_auto_default_file, +void nm_config_data_log(const NMConfigData *self, + const char *prefix, + const char *key_prefix, + const char *no_auto_default_file, /* FILE* */ gpointer print_stream); const char *nm_config_data_get_config_main_file(const NMConfigData *config_data); const char *nm_config_data_get_config_description(const NMConfigData *config_data); gboolean nm_config_data_has_group(const NMConfigData *self, const char *group); -gboolean nm_config_data_has_value(const NMConfigData * self, - const char * group, - const char * key, +gboolean nm_config_data_has_value(const NMConfigData *self, + const char *group, + const char *key, NMConfigGetValueFlags flags); -char * nm_config_data_get_value(const NMConfigData * config_data, - const char * group, - const char * key, +char *nm_config_data_get_value(const NMConfigData *config_data, + const char *group, + const char *key, NMConfigGetValueFlags flags); int nm_config_data_get_value_boolean(const NMConfigData *self, - const char * group, - const char * key, + const char *group, + const char *key, int default_value); gint64 nm_config_data_get_value_int64(const NMConfigData *self, - const char * group, - const char * key, + const char *group, + const char *key, guint base, gint64 min, gint64 max, gint64 fallback); -char ** nm_config_data_get_plugins(const NMConfigData *config_data, gboolean allow_default); +char **nm_config_data_get_plugins(const NMConfigData *config_data, gboolean allow_default); gboolean nm_config_data_get_connectivity_enabled(const NMConfigData *config_data); const char *nm_config_data_get_connectivity_uri(const NMConfigData *config_data); guint nm_config_data_get_connectivity_interval(const NMConfigData *config_data); @@ -195,9 +195,9 @@ const char *nm_config_data_get_iwd_config_path(const NMConfigData *self); extern const char *__start_connection_defaults[]; extern const char *__stop_connection_defaults[]; -#define NM_CON_DEFAULT_NOP(name) \ - static const char * NM_UNIQ_T(connection_default, NM_UNIQ) \ - _nm_used _nm_retain _nm_section("connection_defaults") = "" name +#define NM_CON_DEFAULT_NOP(name) \ + static const char *NM_UNIQ_T(connection_default, NM_UNIQ) \ + _nm_used _nm_retain _nm_section("connection_defaults") = "" name #define NM_CON_DEFAULT(name) \ ({ \ @@ -208,35 +208,35 @@ extern const char *__stop_connection_defaults[]; }) const char *nm_config_data_get_connection_default(const NMConfigData *self, - const char * property, - NMDevice * device); + const char *property, + NMDevice *device); gint64 nm_config_data_get_connection_default_int64(const NMConfigData *self, - const char * property, - NMDevice * device, + const char *property, + NMDevice *device, gint64 min, gint64 max, gint64 fallback); const char *nm_config_data_get_device_config(const NMConfigData *self, - const char * property, - NMDevice * device, - gboolean * has_match); + const char *property, + NMDevice *device, + gboolean *has_match); -const char *nm_config_data_get_device_config_by_pllink(const NMConfigData * self, - const char * property, +const char *nm_config_data_get_device_config_by_pllink(const NMConfigData *self, + const char *property, const NMPlatformLink *pllink, - const char * match_device_type, - gboolean * has_match); + const char *match_device_type, + gboolean *has_match); gboolean nm_config_data_get_device_config_boolean(const NMConfigData *self, - const char * property, - NMDevice * device, + const char *property, + NMDevice *device, int val_no_match, int val_invalid); gint64 nm_config_data_get_device_config_int64(const NMConfigData *self, - const char * property, - NMDevice * device, + const char *property, + NMDevice *device, int base, gint64 min, gint64 max, @@ -244,11 +244,11 @@ gint64 nm_config_data_get_device_config_int64(const NMConfigData *self, gint64 val_invalid); const GSList *nm_config_data_get_device_allowed_connections_specs(const NMConfigData *self, - NMDevice * device, - gboolean * has_match); + NMDevice *device, + gboolean *has_match); -char ** nm_config_data_get_groups(const NMConfigData *self); -char ** nm_config_data_get_keys(const NMConfigData *self, const char *group); +char **nm_config_data_get_groups(const NMConfigData *self); +char **nm_config_data_get_keys(const NMConfigData *self, const char *group); gboolean nm_config_data_is_intern_atomic_group(const NMConfigData *self, const char *group); GKeyFile *nm_config_data_clone_keyfile_intern(const NMConfigData *self); @@ -258,12 +258,15 @@ const char *const *nm_global_dns_config_get_options(const NMGlobalDnsConfig *dns guint nm_global_dns_config_get_num_domains(const NMGlobalDnsConfig *dns_config); NMGlobalDnsDomain *nm_global_dns_config_get_domain(const NMGlobalDnsConfig *dns_config, guint i); NMGlobalDnsDomain *nm_global_dns_config_lookup_domain(const NMGlobalDnsConfig *dns_config, - const char * name); -const char * nm_global_dns_domain_get_name(const NMGlobalDnsDomain *domain); + const char *name); +const char *nm_global_dns_domain_get_name(const NMGlobalDnsDomain *domain); const char *const *nm_global_dns_domain_get_servers(const NMGlobalDnsDomain *domain); const char *const *nm_global_dns_domain_get_options(const NMGlobalDnsDomain *domain); gboolean nm_global_dns_config_is_internal(const NMGlobalDnsConfig *dns_config); gboolean nm_global_dns_config_is_empty(const NMGlobalDnsConfig *dns_config); +int nm_global_dns_config_cmp(const NMGlobalDnsConfig *a, + const NMGlobalDnsConfig *b, + gboolean check_internal); void nm_global_dns_config_update_checksum(const NMGlobalDnsConfig *dns_config, GChecksum *sum); void nm_global_dns_config_free(NMGlobalDnsConfig *dns_config); @@ -284,6 +287,6 @@ GKeyFile *_nm_config_data_get_keyfile_intern(const NMConfigData *self); * including the header, forward declare the two functions that we need. */ struct _NMDhcpManager; struct _NMDhcpManager *nm_dhcp_manager_get(void); -const char * nm_dhcp_manager_get_config(struct _NMDhcpManager *self); +const char *nm_dhcp_manager_get_config(struct _NMDhcpManager *self); #endif /* NM_CONFIG_DATA_H */ diff --git a/src/core/nm-config.c b/src/core/nm-config.c index c41f5823..60a2f1df 100644 --- a/src/core/nm-config.c +++ b/src/core/nm-config.c @@ -29,17 +29,17 @@ /*****************************************************************************/ struct NMConfigCmdLineOptions { - char * config_main_file; - char * intern_config_file; - char * config_dir; - char * system_config_dir; - char * state_file; - char * no_auto_default_file; - char * plugins; + char *config_main_file; + char *intern_config_file; + char *config_dir; + char *system_config_dir; + char *state_file; + char *no_auto_default_file; + char *plugins; NMConfigConfigureAndQuitType configure_and_quit; gboolean is_debug; - char * connectivity_uri; + char *connectivity_uri; /* We store interval as signed internally to track whether it's * set or not via GOptionEntry @@ -152,8 +152,8 @@ nm_config_parse_boolean(const char *str, int default_value) int nm_config_keyfile_get_boolean(const GKeyFile *keyfile, - const char * section, - const char * key, + const char *section, + const char *key, int default_value) { gs_free char *str = NULL; @@ -168,8 +168,8 @@ nm_config_keyfile_get_boolean(const GKeyFile *keyfile, gint64 nm_config_keyfile_get_int64(const GKeyFile *keyfile, - const char * section, - const char * key, + const char *section, + const char *key, guint base, gint64 min, gint64 max, @@ -177,7 +177,7 @@ nm_config_keyfile_get_int64(const GKeyFile *keyfile, { gint64 v; int errsv; - char * str; + char *str; g_return_val_if_fail(keyfile, fallback); g_return_val_if_fail(section, fallback); @@ -194,9 +194,9 @@ nm_config_keyfile_get_int64(const GKeyFile *keyfile, } char * -nm_config_keyfile_get_value(const GKeyFile * keyfile, - const char * section, - const char * key, +nm_config_keyfile_get_value(const GKeyFile *keyfile, + const char *section, + const char *key, NMConfigGetValueFlags flags) { char *value; @@ -221,9 +221,9 @@ nm_config_keyfile_get_value(const GKeyFile * keyfile, } void -nm_config_keyfile_set_string_list(GKeyFile * keyfile, - const char * group, - const char * key, +nm_config_keyfile_set_string_list(GKeyFile *keyfile, + const char *group, + const char *key, const char *const *strv, gssize len) { @@ -332,7 +332,7 @@ static char ** no_auto_default_from_file(const char *no_auto_default_file) { gs_free char *data = NULL; - const char ** list = NULL; + const char **list = NULL; gsize i; if (no_auto_default_file && g_file_get_contents(no_auto_default_file, &data, NULL, NULL)) @@ -350,9 +350,9 @@ no_auto_default_from_file(const char *no_auto_default_file) } static gboolean -no_auto_default_to_file(const char * no_auto_default_file, +no_auto_default_to_file(const char *no_auto_default_file, const char *const *no_auto_default, - GError ** error) + GError **error) { nm_auto_free_gstring GString *data = NULL; gsize i; @@ -360,7 +360,7 @@ no_auto_default_to_file(const char * no_auto_default_file, data = g_string_new(""); for (i = 0; no_auto_default && no_auto_default[i]; i++) { gs_free char *s_to_free = NULL; - const char * s = no_auto_default[i]; + const char *s = no_auto_default[i]; s = nm_utils_str_utf8safe_escape(s, NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL @@ -390,14 +390,14 @@ nm_config_get_no_auto_default_for_device(NMConfig *self, NMDevice *device) void nm_config_set_no_auto_default_for_device(NMConfig *self, NMDevice *device) { - NMConfigPrivate * priv; - GError * error = NULL; - NMConfigData * new_data = NULL; - gs_free char * spec_to_free = NULL; - const char * ifname; - const char * hw_address; - const char * spec; - const char *const * no_auto_default_current; + NMConfigPrivate *priv; + GError *error = NULL; + NMConfigData *new_data = NULL; + gs_free char *spec_to_free = NULL; + const char *ifname; + const char *hw_address; + const char *spec; + const char *const *no_auto_default_current; gs_free const char **no_auto_default_new = NULL; gboolean is_fake; gsize len; @@ -529,7 +529,7 @@ nm_config_cmd_line_options_free(NMConfigCmdLineOptions *cli) static NMConfigConfigureAndQuitType string_to_configure_and_quit(const char *value, GError **error) { - NMConfigConfigureAndQuitType ret; + int v_bool; if (value == NULL) return NM_CONFIG_CONFIGURE_AND_QUIT_DISABLED; @@ -537,26 +537,29 @@ string_to_configure_and_quit(const char *value, GError **error) if (nm_streq(value, "initrd")) return NM_CONFIG_CONFIGURE_AND_QUIT_INITRD; - ret = nm_config_parse_boolean(value, NM_CONFIG_CONFIGURE_AND_QUIT_INVALID); - if (ret == NM_CONFIG_CONFIGURE_AND_QUIT_INVALID) - g_set_error(error, 1, 0, N_("'%s' is not valid"), value); + v_bool = nm_config_parse_boolean(value, -1); + if (v_bool == -1) { + nm_utils_error_set(error, NM_UTILS_ERROR_UNKNOWN, N_("'%s' is not valid"), value); + return NM_CONFIG_CONFIGURE_AND_QUIT_INVALID; + } + + if (v_bool) { + _LOGW("'[main].configure-and-quit=1' in \"NetworkManager.conf\" is no longer implemented " + "and has no effect"); + } - return ret; + return NM_CONFIG_CONFIGURE_AND_QUIT_DISABLED; } static gboolean parse_configure_and_quit(const char *option_name, const char *value, gpointer user_data, - GError ** error) + GError **error) { NMConfigCmdLineOptions *cli = user_data; - if (value == NULL) - cli->configure_and_quit = NM_CONFIG_CONFIGURE_AND_QUIT_ENABLED; - else - cli->configure_and_quit = string_to_configure_and_quit(value, error); - + cli->configure_and_quit = string_to_configure_and_quit(value, error); if (cli->configure_and_quit == NM_CONFIG_CONFIGURE_AND_QUIT_INVALID) { g_prefix_error(error, N_("Bad '%s' option: "), option_name); return FALSE; @@ -692,7 +695,7 @@ char *_nm_config_match_env = NULL; static gboolean ignore_config_snippet(GKeyFile *keyfile, gboolean is_base_config) { - GSList * specs; + GSList *specs; gboolean as_bool; NMMatchSpecMatchType match_type; @@ -825,7 +828,7 @@ _setting_is_string_list(const char *group, const char *key) } typedef struct { - char * group; + char *group; const char *const *keys; bool is_prefix : 1; bool is_connection : 1; @@ -924,12 +927,12 @@ check_config_key(const char *group, const char *key) { const ConfigGroup *g; const char *const *k; - const char ** ptr; + const char **ptr; #if NM_MORE_ASSERTS > 10 { static gboolean checked = FALSE; - const char ** ptr1, **ptr2; + const char **ptr1, **ptr2; /* check for duplicate elements in the static list */ @@ -969,16 +972,16 @@ check_config_key(const char *group, const char *key) } static gboolean -read_config(GKeyFile * keyfile, +read_config(GKeyFile *keyfile, gboolean is_base_config, const char *dirname, const char *path, - GPtrArray * warnings, - GError ** error) + GPtrArray *warnings, + GError **error) { nm_auto_unref_keyfile GKeyFile *kf = NULL; - gs_strfreev char ** groups = NULL; - gs_free char * path_free = NULL; + gs_strfreev char **groups = NULL; + gs_free char *path_free = NULL; gsize ngroups; gsize nkeys; int g; @@ -1030,7 +1033,7 @@ read_config(GKeyFile * keyfile, _nm_config_sort_groups(groups, ngroups); for (g = 0; groups && groups[g]; g++) { - const char * group = groups[g]; + const char *group = groups[g]; gs_strfreev char **keys = NULL; if (NM_STR_HAS_PREFIX(group, NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN)) { @@ -1042,7 +1045,7 @@ read_config(GKeyFile * keyfile, continue; for (k = 0; keys[k]; k++) { gs_free char *new_value = NULL; - const char * key; + const char *key; char last_char; gsize key_len; @@ -1071,10 +1074,10 @@ read_config(GKeyFile * keyfile, if (is_string_list || _setting_is_device_spec(group, base_key) || _setting_is_connection_spec(group, base_key)) { - gs_unref_ptrarray GPtrArray *new = g_ptr_array_new_with_free_func(g_free); - char ** iter_val; + gs_unref_ptrarray GPtrArray *new = g_ptr_array_new_with_free_func(g_free); + char **iter_val; gs_strfreev char **old_val = NULL; - gs_free char ** new_val = NULL; + gs_free char **new_val = NULL; if (is_string_list) { gs_free_error GError *old_error = NULL; @@ -1142,7 +1145,7 @@ read_config(GKeyFile * keyfile, new->len); else { nm_auto_free_slist GSList *specs = NULL; - gs_free char * specs_joined = NULL; + gs_free char *specs_joined = NULL; g_ptr_array_add(new, NULL); specs = nm_strv_to_gslist((char **) new->pdata, FALSE); @@ -1181,11 +1184,11 @@ read_config(GKeyFile * keyfile, } static gboolean -read_base_config(GKeyFile * keyfile, +read_base_config(GKeyFile *keyfile, const char *cli_config_main_file, - char ** out_config_main_file, - GPtrArray * warnings, - GError ** error) + char **out_config_main_file, + GPtrArray *warnings, + GError **error) { GError *my_error = NULL; @@ -1245,11 +1248,11 @@ read_base_config(GKeyFile * keyfile, static GPtrArray * _get_config_dir_files(const char *config_dir) { - GFile * dir; + GFile *dir; GFileEnumerator *direnum; - GFileInfo * info; - GPtrArray * confs; - const char * name; + GFileInfo *info; + GPtrArray *confs; + const char *name; g_return_val_if_fail(config_dir, NULL); @@ -1294,20 +1297,20 @@ _confs_to_description(GString *str, const GPtrArray *confs, const char *name) static GKeyFile * read_entire_config(const NMConfigCmdLineOptions *cli, - const char * config_dir, - const char * system_config_dir, - char ** out_config_main_file, - char ** out_config_description, - GPtrArray * warnings, - GError ** error) -{ - nm_auto_unref_keyfile GKeyFile *keyfile = NULL; - gs_unref_ptrarray GPtrArray *system_confs = NULL; - gs_unref_ptrarray GPtrArray *confs = NULL; - gs_unref_ptrarray GPtrArray *run_confs = NULL; - guint i; - gs_free char * o_config_main_file = NULL; - const char * run_config_dir = ""; + const char *config_dir, + const char *system_config_dir, + char **out_config_main_file, + char **out_config_description, + GPtrArray *warnings, + GError **error) +{ + nm_auto_unref_keyfile GKeyFile *keyfile = NULL; + gs_unref_ptrarray GPtrArray *system_confs = NULL; + gs_unref_ptrarray GPtrArray *confs = NULL; + gs_unref_ptrarray GPtrArray *run_confs = NULL; + guint i; + gs_free char *o_config_main_file = NULL; + const char *run_config_dir = ""; nm_assert(config_dir); nm_assert(system_config_dir); @@ -1383,16 +1386,13 @@ read_entire_config(const NMConfigCmdLineOptions *cli, switch (cli->configure_and_quit) { case NM_CONFIG_CONFIGURE_AND_QUIT_INVALID: - g_assert_not_reached(); + nm_assert_not_reached(); break; case NM_CONFIG_CONFIGURE_AND_QUIT_DISABLED: - /* do nothing */ - break; - case NM_CONFIG_CONFIGURE_AND_QUIT_ENABLED: - g_key_file_set_boolean(keyfile, - NM_CONFIG_KEYFILE_GROUP_MAIN, - "configure-and-quit", - TRUE); + g_key_file_set_string(keyfile, + NM_CONFIG_KEYFILE_GROUP_MAIN, + "configure-and-quit", + "no"); break; case NM_CONFIG_CONFIGURE_AND_QUIT_INITRD: g_key_file_set_string(keyfile, @@ -1472,7 +1472,7 @@ static char * _keyfile_serialize_section(GKeyFile *keyfile, const char *group) { gs_strfreev char **keys = NULL; - GString * str; + GString *str; guint k; if (keyfile) @@ -1484,7 +1484,7 @@ _keyfile_serialize_section(GKeyFile *keyfile, const char *group) str = g_string_new("1#"); for (k = 0; keys[k]; k++) { - const char * key = keys[k]; + const char *key = keys[k]; gs_free char *value = NULL; _string_append_val(str, key); @@ -1502,7 +1502,7 @@ nm_config_keyfile_has_global_dns_config(GKeyFile *keyfile, gboolean internal) { gs_strfreev char **groups = NULL; guint g; - const char * prefix; + const char *prefix; if (!keyfile) return FALSE; @@ -1543,13 +1543,13 @@ nm_config_keyfile_has_global_dns_config(GKeyFile *keyfile, gboolean internal) * Returns: a #GKeyFile instance with the internal configuration. */ static GKeyFile * -intern_config_read(const char * filename, - GKeyFile * keyfile_conf, +intern_config_read(const char *filename, + GKeyFile *keyfile_conf, const char *const *atomic_section_prefixes, - gboolean * out_needs_rewrite) + gboolean *out_needs_rewrite) { - GKeyFile * keyfile_intern; - GKeyFile * keyfile; + GKeyFile *keyfile_intern; + GKeyFile *keyfile; gboolean needs_rewrite = FALSE; gs_strfreev char **groups = NULL; guint g, k; @@ -1574,7 +1574,7 @@ intern_config_read(const char * filename, groups = g_key_file_get_groups(keyfile, NULL); for (g = 0; groups && groups[g]; g++) { gs_strfreev char **keys = NULL; - const char * group = groups[g]; + const char *group = groups[g]; gboolean is_intern, is_atomic; if (nm_streq(group, NM_CONFIG_KEYFILE_GROUP_CONFIG)) @@ -1613,7 +1613,7 @@ intern_config_read(const char * filename, for (k = 0; keys[k]; k++) { gs_free char *value_set = NULL; - const char * key = keys[k]; + const char *key = keys[k]; value_set = g_key_file_get_value(keyfile, group, key, NULL); @@ -1625,7 +1625,7 @@ intern_config_read(const char * filename, continue; g_key_file_set_value(keyfile_intern, group, key, value_set); } else if (NM_STR_HAS_PREFIX_WITH_MORE(key, NM_CONFIG_KEYFILE_KEYPREFIX_SET)) { - const char * key_base = &key[NM_STRLEN(NM_CONFIG_KEYFILE_KEYPREFIX_SET)]; + const char *key_base = &key[NM_STRLEN(NM_CONFIG_KEYFILE_KEYPREFIX_SET)]; gs_free char *value_was = NULL; gs_free char *value_conf = NULL; gs_free char *key_was = @@ -1646,7 +1646,7 @@ intern_config_read(const char * filename, has_intern = TRUE; g_key_file_set_value(keyfile_intern, group, key_base, value_set); } else if (NM_STR_HAS_PREFIX_WITH_MORE(key, NM_CONFIG_KEYFILE_KEYPREFIX_WAS)) { - const char * key_base = &key[NM_STRLEN(NM_CONFIG_KEYFILE_KEYPREFIX_WAS)]; + const char *key_base = &key[NM_STRLEN(NM_CONFIG_KEYFILE_KEYPREFIX_WAS)]; gs_free char *key_set = g_strdup_printf(NM_CONFIG_KEYFILE_KEYPREFIX_SET "%s", key_base); gs_free char *value_was = NULL; @@ -1715,8 +1715,8 @@ out: } static int -_intern_config_write_sort_fcn(const char ** a, - const char ** b, +_intern_config_write_sort_fcn(const char **a, + const char **b, const char *const *atomic_section_prefixes) { const char *g_a = *a; @@ -1745,17 +1745,17 @@ _intern_config_write_sort_fcn(const char ** a, } static gboolean -intern_config_write(const char * filename, - GKeyFile * keyfile_intern, - GKeyFile * keyfile_conf, +intern_config_write(const char *filename, + GKeyFile *keyfile_intern, + GKeyFile *keyfile_conf, const char *const *atomic_section_prefixes, - GError ** error) + GError **error) { - GKeyFile * keyfile; + GKeyFile *keyfile; gs_strfreev char **groups = NULL; guint g, k; gboolean success = FALSE; - GError * local = NULL; + GError *local = NULL; g_return_val_if_fail(filename, FALSE); @@ -1781,7 +1781,7 @@ intern_config_write(const char * filename, } for (g = 0; groups && groups[g]; g++) { gs_strfreev char **keys = NULL; - const char * group = groups[g]; + const char *group = groups[g]; gboolean is_intern, is_atomic; keys = g_key_file_get_keys(keyfile_intern, group, NULL, NULL); @@ -1816,7 +1816,7 @@ intern_config_write(const char * filename, } for (k = 0; keys[k]; k++) { - const char * key = keys[k]; + const char *key = keys[k]; gs_free char *value_set = NULL; gs_free char *key_set = NULL; @@ -1932,9 +1932,9 @@ intern_config_write(const char * filename, GSList * nm_config_get_match_spec(const GKeyFile *keyfile, - const char * group, - const char * key, - gboolean * out_has_key) + const char *group, + const char *key, + gboolean *out_has_key) { gs_free char *value = NULL; @@ -1952,9 +1952,9 @@ nm_config_get_match_spec(const GKeyFile *keyfile, gboolean nm_config_set_global_dns(NMConfig *self, NMGlobalDnsConfig *global_dns, GError **error) { - NMConfigPrivate * priv; - GKeyFile * keyfile; - char ** groups; + NMConfigPrivate *priv; + GKeyFile *keyfile; + char **groups; const NMGlobalDnsConfig *old_global_dns; guint i; @@ -2002,7 +2002,7 @@ nm_config_set_global_dns(NMConfig *self, NMGlobalDnsConfig *global_dns, GError * for (i = 0; i < nm_global_dns_config_get_num_domains(global_dns); i++) { NMGlobalDnsDomain *domain = nm_global_dns_config_get_domain(global_dns, i); - gs_free char * group_name = NULL; + gs_free char *group_name = NULL; group_name = g_strdup_printf(NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN_GLOBAL_DNS_DOMAIN "%s", nm_global_dns_domain_get_name(domain)); @@ -2032,7 +2032,7 @@ void nm_config_set_connectivity_check_enabled(NMConfig *self, gboolean enabled) { NMConfigPrivate *priv; - GKeyFile * keyfile; + GKeyFile *keyfile; g_return_if_fail(NM_IS_CONFIG(self)); @@ -2090,12 +2090,12 @@ nm_config_set_values(NMConfig *self, gboolean allow_write, gboolean force_rewrite) { - NMConfigPrivate * priv; - GKeyFile * keyfile_intern_current; - GKeyFile * keyfile_user; - GKeyFile * keyfile_new; - GError * local = NULL; - NMConfigData * new_data = NULL; + NMConfigPrivate *priv; + GKeyFile *keyfile_intern_current; + GKeyFile *keyfile_user; + GKeyFile *keyfile_new; + GError *local = NULL; + NMConfigData *new_data = NULL; gs_strfreev char **groups = NULL; int g; @@ -2191,9 +2191,9 @@ state_free(State *state) static State * state_new_from_file(const char *filename) { - GKeyFile * keyfile; + GKeyFile *keyfile; gs_free_error GError *error = NULL; - State * state; + State *state; state = state_new(); @@ -2250,9 +2250,9 @@ static void state_write(NMConfig *self) { NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE(self); - const char * filename; - GString * str; - GError * error = NULL; + const char *filename; + GString *str; + GError *error = NULL; if (priv->configure_and_quit != NM_CONFIG_CONFIGURE_AND_QUIT_DISABLED) return; @@ -2294,7 +2294,7 @@ state_write(NMConfig *self) void _nm_config_state_set(NMConfig *self, gboolean allow_persist, gboolean force_persist, ...) { - NMConfigPrivate * priv; + NMConfigPrivate *priv; va_list ap; NMConfigRunStatePropertyType property_type; @@ -2366,14 +2366,14 @@ static NM_UTILS_LOOKUP_STR_DEFINE( static NMConfigDeviceStateData * _config_device_state_data_new(int ifindex, GKeyFile *kf) { - NMConfigDeviceStateData * device_state; + NMConfigDeviceStateData *device_state; NMConfigDeviceStateManagedType managed_type = NM_CONFIG_DEVICE_STATE_MANAGED_TYPE_UNKNOWN; - gs_free char * connection_uuid = NULL; - gs_free char * perm_hw_addr_fake = NULL; + gs_free char *connection_uuid = NULL; + gs_free char *perm_hw_addr_fake = NULL; gsize connection_uuid_len; gsize perm_hw_addr_fake_len; NMTernary nm_owned; - char * p; + char *p; guint32 route_metric_default_effective; guint32 route_metric_default_aspired; @@ -2484,7 +2484,7 @@ nm_config_device_state_load(int ifindex) NMConfigDeviceStateData *device_state; char path[NM_STRLEN(NM_CONFIG_DEVICE_STATE_DIR "/") + DEVICE_STATE_FILENAME_LEN_MAX + 1]; nm_auto_unref_keyfile GKeyFile *kf = NULL; - const char * nm_owned_str; + const char *nm_owned_str; g_return_val_if_fail(ifindex > 0, NULL); @@ -2536,7 +2536,7 @@ GHashTable * nm_config_device_state_load_all(void) { GHashTable *states; - GDir * dir; + GDir *dir; const char *fn; int ifindex; @@ -2568,14 +2568,14 @@ nm_config_device_state_load_all(void) gboolean nm_config_device_state_write(int ifindex, NMConfigDeviceStateManagedType managed, - const char * perm_hw_addr_fake, - const char * connection_uuid, + const char *perm_hw_addr_fake, + const char *connection_uuid, NMTernary nm_owned, guint32 route_metric_default_aspired, guint32 route_metric_default_effective, - const char * next_server, - const char * root_path, - const char * dhcp_bootfile) + const char *next_server, + const char *root_path, + const char *dhcp_bootfile) { char path[NM_STRLEN(NM_CONFIG_DEVICE_STATE_DIR "/") + DEVICE_STATE_FILENAME_LEN_MAX + 1]; GError *local = NULL; @@ -2674,7 +2674,7 @@ nm_config_device_state_write(int ifindex, void nm_config_device_state_prune_stale(GHashTable *preserve_ifindexes, NMPlatform *preserve_in_platform) { - GDir * dir; + GDir *dir; const char *fn; char buf[NM_STRLEN(NM_CONFIG_DEVICE_STATE_DIR "/") + DEVICE_STATE_FILENAME_LEN_MAX + 1] = NM_CONFIG_DEVICE_STATE_DIR "/"; @@ -2759,14 +2759,14 @@ nm_config_device_state_get(NMConfig *self, int ifindex) void nm_config_reload(NMConfig *self, NMConfigChangeFlags reload_flags, gboolean emit_warnings) { - NMConfigPrivate * priv; - GError * error = NULL; - GKeyFile * keyfile, *keyfile_intern; - NMConfigData * new_data = NULL; - char * config_main_file = NULL; - char * config_description = NULL; - gs_strfreev char **no_auto_default = NULL; - gboolean intern_config_needs_rewrite; + NMConfigPrivate *priv; + GError *error = NULL; + GKeyFile *keyfile, *keyfile_intern; + NMConfigData *new_data = NULL; + char *config_main_file = NULL; + char *config_description = NULL; + gs_strfreev char **no_auto_default = NULL; + gboolean intern_config_needs_rewrite; gs_unref_ptrarray GPtrArray *warnings = NULL; guint i; @@ -2866,8 +2866,8 @@ NM_UTILS_FLAGS2STR_DEFINE(nm_config_change_flags_to_string, static void _set_config_data(NMConfig *self, NMConfigData *new_data, NMConfigChangeFlags reload_flags) { - NMConfigPrivate * priv = NM_CONFIG_GET_PRIVATE(self); - NMConfigData * old_data = priv->config_data; + NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE(self); + NMConfigData *old_data = priv->config_data; NMConfigChangeFlags changes, changes_diff; gboolean had_new_data = !!new_data; @@ -2948,10 +2948,10 @@ nm_config_setup(const NMConfigCmdLineOptions *cli, char **atomic_section_prefixe static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - NMConfig * self = NM_CONFIG(object); - NMConfigPrivate * priv = NM_CONFIG_GET_PRIVATE(self); + NMConfig *self = NM_CONFIG(object); + NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE(self); NMConfigCmdLineOptions *cli; - char ** strv; + char **strv; switch (prop_id) { case PROP_CMD_LINE_OPTIONS: @@ -2980,17 +2980,17 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps static gboolean init_sync(GInitable *initable, GCancellable *cancellable, GError **error) { - NMConfig * self = NM_CONFIG(initable); - NMConfigPrivate * priv = NM_CONFIG_GET_PRIVATE(self); + NMConfig *self = NM_CONFIG(initable); + NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE(self); nm_auto_unref_keyfile GKeyFile *keyfile = NULL; nm_auto_unref_keyfile GKeyFile *keyfile_intern = NULL; - gs_free char * config_main_file = NULL; - gs_free char * config_description = NULL; - gs_strfreev char ** no_auto_default = NULL; - gs_unref_ptrarray GPtrArray *warnings = NULL; - gs_free char * configure_and_quit = NULL; - gboolean intern_config_needs_rewrite; - const char * s; + gs_free char *config_main_file = NULL; + gs_free char *config_description = NULL; + gs_strfreev char **no_auto_default = NULL; + gs_unref_ptrarray GPtrArray *warnings = NULL; + gs_free char *configure_and_quit = NULL; + gboolean intern_config_needs_rewrite; + const char *s; if (priv->config_dir) { /* Object is already initialized. */ diff --git a/src/core/nm-config.h b/src/core/nm-config.h index 8279f4d2..2c23ff20 100644 --- a/src/core/nm-config.h +++ b/src/core/nm-config.h @@ -42,8 +42,7 @@ typedef enum { typedef enum { NM_CONFIG_CONFIGURE_AND_QUIT_INVALID = -1, NM_CONFIG_CONFIGURE_AND_QUIT_DISABLED = FALSE, - NM_CONFIG_CONFIGURE_AND_QUIT_ENABLED = TRUE, - NM_CONFIG_CONFIGURE_AND_QUIT_INITRD, + NM_CONFIG_CONFIGURE_AND_QUIT_INITRD = 2, } NMConfigConfigureAndQuitType; typedef struct { @@ -69,8 +68,8 @@ NMConfigData *nm_config_get_data_orig(NMConfig *config); #define NM_CONFIG_GET_DATA (nm_config_get_data(nm_config_get())) #define NM_CONFIG_GET_DATA_ORIG (nm_config_get_data_orig(nm_config_get())) -const char * nm_config_get_log_level(NMConfig *config); -const char * nm_config_get_log_domains(NMConfig *config); +const char *nm_config_get_log_level(NMConfig *config); +const char *nm_config_get_log_domains(NMConfig *config); NMConfigConfigureAndQuitType nm_config_get_configure_and_quit(NMConfig *config); gboolean nm_config_get_is_debug(NMConfig *config); @@ -87,7 +86,7 @@ void nm_config_set_values(NMConfig *self, NMConfigCmdLineOptions *nm_config_cmd_line_options_new(gboolean first_start); void nm_config_cmd_line_options_free(NMConfigCmdLineOptions *cli); void nm_config_cmd_line_options_add_to_entries(NMConfigCmdLineOptions *cli, - GOptionContext * opt_ctx); + GOptionContext *opt_ctx); gboolean nm_config_get_no_auto_default_for_device(NMConfig *config, NMDevice *device); void nm_config_set_no_auto_default_for_device(NMConfig *config, NMDevice *device); @@ -108,31 +107,31 @@ int nm_config_parse_boolean(const char *str, int default_value); GKeyFile *nm_config_create_keyfile(void); int nm_config_keyfile_get_boolean(const GKeyFile *keyfile, - const char * section, - const char * key, + const char *section, + const char *key, int default_value); gint64 nm_config_keyfile_get_int64(const GKeyFile *keyfile, - const char * section, - const char * key, + const char *section, + const char *key, guint base, gint64 min, gint64 max, gint64 fallback); -char * nm_config_keyfile_get_value(const GKeyFile * keyfile, - const char * section, - const char * key, +char *nm_config_keyfile_get_value(const GKeyFile *keyfile, + const char *section, + const char *key, NMConfigGetValueFlags flags); -void nm_config_keyfile_set_string_list(GKeyFile * keyfile, - const char * group, - const char * key, +void nm_config_keyfile_set_string_list(GKeyFile *keyfile, + const char *group, + const char *key, const char *const *strv, gssize len); gboolean nm_config_keyfile_has_global_dns_config(GKeyFile *keyfile, gboolean internal); GSList *nm_config_get_match_spec(const GKeyFile *keyfile, - const char * group, - const char * key, - gboolean * out_has_key); + const char *group, + const char *key, + gboolean *out_has_key); void _nm_config_sort_groups(char **groups, gsize ngroups); @@ -176,22 +175,22 @@ struct _NMConfigDeviceStateData { }; NMConfigDeviceStateData *nm_config_device_state_load(int ifindex); -GHashTable * nm_config_device_state_load_all(void); +GHashTable *nm_config_device_state_load_all(void); gboolean nm_config_device_state_write(int ifindex, NMConfigDeviceStateManagedType managed, - const char * perm_hw_addr_fake, - const char * connection_uuid, + const char *perm_hw_addr_fake, + const char *connection_uuid, NMTernary nm_owned, guint32 route_metric_default_aspired, guint32 route_metric_default_effective, - const char * next_server, - const char * root_path, - const char * dhcp_bootfile); + const char *next_server, + const char *root_path, + const char *dhcp_bootfile); void nm_config_device_state_prune_stale(GHashTable *preserve_ifindexes, NMPlatform *preserve_in_platform); -const GHashTable * nm_config_device_state_get_all(NMConfig *self); +const GHashTable *nm_config_device_state_get_all(NMConfig *self); const NMConfigDeviceStateData *nm_config_device_state_get(NMConfig *self, int ifindex); const char *const *nm_config_get_warnings(NMConfig *config); diff --git a/src/core/nm-connectivity.c b/src/core/nm-connectivity.c index 13fb0265..7199c9a2 100644 --- a/src/core/nm-connectivity.c +++ b/src/core/nm-connectivity.c @@ -15,6 +15,7 @@ #include #include "c-list/src/c-list.h" +#include "libnm-platform/nmp-object.h" #include "libnm-core-intern/nm-core-internal.h" #include "nm-config.h" #include "NetworkManagerUtils.h" @@ -58,22 +59,22 @@ typedef struct { struct _NMConnectivityCheckHandle { CList handles_lst; - NMConnectivity * self; + NMConnectivity *self; NMConnectivityCheckCallback callback; gpointer user_data; char *ifspec; const char *completed_log_message; - char * completed_log_message_free; + char *completed_log_message_free; #if WITH_CONCHECK struct { ConConfig *con_config; - GCancellable * resolve_cancellable; - CURLM * curl_mhandle; - CURL * curl_ehandle; + GCancellable *resolve_cancellable; + CURLM *curl_mhandle; + CURL *curl_ehandle; struct curl_slist *request_headers; struct curl_slist *hosts; @@ -91,7 +92,7 @@ struct _NMConnectivityCheckHandle { guint timeout_id; NMConnectivityState completed_state; - const char * completed_reason; + const char *completed_reason; }; enum { @@ -105,7 +106,7 @@ static guint signals[LAST_SIGNAL] = {0}; typedef struct { CList handles_lst_head; CList completed_handles_lst_head; - NMConfig * config; + NMConfig *config; ConConfig *con_config; guint interval; @@ -199,7 +200,7 @@ _con_config_get_response(const ConConfig *con_config) static void cb_data_complete(NMConnectivityCheckHandle *cb_data, NMConnectivityState state, - const char * log_message) + const char *log_message) { NMConnectivity *self; @@ -270,8 +271,8 @@ cb_data_complete(NMConnectivityCheckHandle *cb_data, static void cb_data_queue_completed(NMConnectivityCheckHandle *cb_data, NMConnectivityState state, - const char * log_message_static, - char * log_message_take /* take */) + const char *log_message_static, + char *log_message_take /* take */) { nm_assert(cb_data); nm_assert(NM_IS_CONNECTIVITY(cb_data->self)); @@ -294,8 +295,8 @@ cb_data_queue_completed(NMConnectivityCheckHandle *cb_data, static void _complete_queued(NMConnectivity *self) { - NMConnectivity * self_keep_alive = NULL; - NMConnectivityPrivate * priv = NM_CONNECTIVITY_GET_PRIVATE(self); + NMConnectivity *self_keep_alive = NULL; + NMConnectivityPrivate *priv = NM_CONNECTIVITY_GET_PRIVATE(self); NMConnectivityCheckHandle *cb_data; while ((cb_data = c_list_first_entry(&priv->completed_handles_lst_head, @@ -312,7 +313,7 @@ static gboolean _con_curl_check_connectivity(CURLM *mhandle, int sockfd, int ev_bitmask) { NMConnectivityCheckHandle *cb_data; - CURLMsg * msg; + CURLMsg *msg; int m_left; long response_code; CURLMcode ret; @@ -438,7 +439,7 @@ typedef struct { static gboolean _con_curl_socketevent_cb(int fd, GIOCondition condition, gpointer user_data) { - ConCurlSockData * fdp = user_data; + ConCurlSockData *fdp = user_data; NMConnectivityCheckHandle *cb_data = fdp->cb_data; int action = 0; gboolean fdp_destroyed = FALSE; @@ -475,7 +476,7 @@ static int multi_socket_cb(CURL *e_handle, curl_socket_t fd, int what, void *userdata, void *socketp) { NMConnectivityCheckHandle *cb_data = userdata; - ConCurlSockData * fdp = socketp; + ConCurlSockData *fdp = socketp; (void) _NM_ENSURE_TYPE(int, fd); @@ -542,7 +543,7 @@ easy_write_cb(void *buffer, size_t size, size_t nmemb, void *userdata) size_t len = size * nmemb; size_t response_len; size_t check_len; - const char * response; + const char *response; if (cb_data->completed_state != NM_CONNECTIVITY_UNKNOWN) { /* already completed. */ @@ -642,7 +643,7 @@ static void do_curl_request(NMConnectivityCheckHandle *cb_data) { CURLM *mhandle; - CURL * ehandle; + CURL *ehandle; long resolve; mhandle = curl_multi_init(); @@ -708,7 +709,7 @@ resolve_cb(GObject *object, GAsyncResult *res, gpointer user_data) int addr_family; gsize len = 0; gsize i; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; result = g_dbus_connection_call_finish(G_DBUS_CONNECTION(object), res, &error); if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) @@ -731,8 +732,8 @@ resolve_cb(GObject *object, GAsyncResult *res, gpointer user_data) for (i = 0; i < no_addresses; i++) { gs_unref_variant GVariant *address = NULL; char str_addr[NM_UTILS_INET_ADDRSTRLEN]; - gs_free char * host_entry = NULL; - const guchar * address_buf; + gs_free char *host_entry = NULL; + const guchar *address_buf; g_variant_get_child(addresses, i, "(ii@ay)", &ifindex, &addr_family, &address); @@ -760,10 +761,10 @@ resolve_cb(GObject *object, GAsyncResult *res, gpointer user_data) static NMConnectivityState check_platform_config(NMConnectivity *self, - NMPlatform * platform, + NMPlatform *platform, int ifindex, int addr_family, - const char ** reason) + const char **reason) { const NMDedupMultiHeadEntry *addresses; const NMDedupMultiHeadEntry *routes; @@ -797,7 +798,7 @@ check_platform_config(NMConnectivity *self, const NMPlatformIP4Route *route; gboolean found_global = FALSE; NMDedupMultiIter iter; - const NMPObject * plobj; + const NMPObject *plobj; /* For IPv4 also require a route with global scope. */ nmp_cache_iter_for_each (&iter, routes, &plobj) { @@ -826,15 +827,15 @@ check_platform_config(NMConnectivity *self, } NMConnectivityCheckHandle * -nm_connectivity_check_start(NMConnectivity * self, +nm_connectivity_check_start(NMConnectivity *self, int addr_family, - NMPlatform * platform, + NMPlatform *platform, int ifindex, - const char * iface, + const char *iface, NMConnectivityCheckCallback callback, gpointer user_data) { - NMConnectivityPrivate * priv; + NMConnectivityPrivate *priv; NMConnectivityCheckHandle *cb_data; static guint64 request_counter = 0; @@ -862,7 +863,7 @@ nm_connectivity_check_start(NMConnectivity * self, if (iface && ifindex > 0 && priv->enabled && priv->uri_valid) { gboolean has_systemd_resolved; NMConnectivityState state; - const char * reason; + const char *reason; cb_data->concheck.ch_ifindex = ifindex; @@ -1045,14 +1046,14 @@ update_config(NMConnectivity *self, NMConfigData *config_data) guint interval; gboolean enabled; gboolean changed = FALSE; - const char * cur_uri = priv->con_config ? priv->con_config->uri : NULL; - const char * cur_response = priv->con_config ? priv->con_config->response : NULL; - const char * new_response; - const char * new_uri; + const char *cur_uri = priv->con_config ? priv->con_config->uri : NULL; + const char *cur_response = priv->con_config ? priv->con_config->response : NULL; + const char *new_response; + const char *new_uri; gboolean new_uri_valid = priv->uri_valid; gboolean new_host_port = FALSE; - gs_free char * new_host = NULL; - gs_free char * new_port = NULL; + gs_free char *new_host = NULL; + gs_free char *new_port = NULL; new_uri = nm_config_data_get_connectivity_uri(config_data); if (!nm_streq0(new_uri, cur_uri)) { @@ -1134,11 +1135,11 @@ update_config(NMConnectivity *self, NMConfigData *config_data) } static void -config_changed_cb(NMConfig * config, - NMConfigData * config_data, +config_changed_cb(NMConfig *config, + NMConfigData *config_data, NMConfigChangeFlags changes, - NMConfigData * old_data, - NMConnectivity * self) + NMConfigData *old_data, + NMConnectivity *self) { update_config(self, config_data); } @@ -1177,8 +1178,8 @@ nm_connectivity_init(NMConnectivity *self) static void dispose(GObject *object) { - NMConnectivity * self = NM_CONNECTIVITY(object); - NMConnectivityPrivate * priv = NM_CONNECTIVITY_GET_PRIVATE(self); + NMConnectivity *self = NM_CONNECTIVITY(object); + NMConnectivityPrivate *priv = NM_CONNECTIVITY_GET_PRIVATE(self); NMConnectivityCheckHandle *cb_data; nm_assert(c_list_is_empty(&priv->completed_handles_lst_head)); diff --git a/src/core/nm-connectivity.h b/src/core/nm-connectivity.h index 0985df97..7b57a112 100644 --- a/src/core/nm-connectivity.h +++ b/src/core/nm-connectivity.h @@ -56,16 +56,16 @@ guint nm_connectivity_get_interval(NMConnectivity *self); typedef struct _NMConnectivityCheckHandle NMConnectivityCheckHandle; -typedef void (*NMConnectivityCheckCallback)(NMConnectivity * self, +typedef void (*NMConnectivityCheckCallback)(NMConnectivity *self, NMConnectivityCheckHandle *handle, NMConnectivityState state, gpointer user_data); -NMConnectivityCheckHandle *nm_connectivity_check_start(NMConnectivity * self, +NMConnectivityCheckHandle *nm_connectivity_check_start(NMConnectivity *self, int family, - NMPlatform * platform, + NMPlatform *platform, int ifindex, - const char * iface, + const char *iface, NMConnectivityCheckCallback callback, gpointer user_data); diff --git a/src/core/nm-core-utils.c b/src/core/nm-core-utils.c index 747e1c09..e05638e4 100644 --- a/src/core/nm-core-utils.c +++ b/src/core/nm-core-utils.c @@ -110,7 +110,7 @@ _nm_utils_set_testing(NMUtilsTestFlags flags) /*****************************************************************************/ -static GSList * _singletons = NULL; +static GSList *_singletons = NULL; static gboolean _singletons_shutdown = FALSE; static void @@ -292,7 +292,7 @@ typedef struct { } sync; }; NMUtilsKillChildAsyncCb callback; - void * user_data; + void *user_data; char log_name[1]; /* variable-length object, must be last element!! */ } KillChildAsyncData; @@ -304,9 +304,9 @@ typedef struct { static KillChildAsyncData * _kc_async_data_alloc(pid_t pid, NMLogDomain log_domain, - const char * log_name, + const char *log_name, NMUtilsKillChildAsyncCb callback, - void * user_data) + void *user_data) { KillChildAsyncData *data; size_t log_name_len; @@ -443,9 +443,9 @@ _kc_invoke_callback_idle(gpointer user_data) static void _kc_invoke_callback(pid_t pid, NMLogDomain log_domain, - const char * log_name, + const char *log_name, NMUtilsKillChildAsyncCb callback, - void * user_data, + void *user_data, gboolean success, int child_status) { @@ -482,10 +482,10 @@ void nm_utils_kill_child_async(pid_t pid, int sig, NMLogDomain log_domain, - const char * log_name, + const char *log_name, guint32 wait_before_kill_msec, NMUtilsKillChildAsyncCb callback, - void * user_data) + void *user_data) { int status = 0, errsv; pid_t ret; @@ -620,7 +620,7 @@ nm_utils_kill_child_sync(pid_t pid, int sig, NMLogDomain log_domain, const char *log_name, - int * child_status, + int *child_status, guint32 wait_before_kill_msec, guint32 sleep_duration_msec) { @@ -1176,14 +1176,14 @@ typedef struct { static gboolean match_device_s390_subchannels_parse(const char *s390_subchannels, - guint32 * out_a, - guint32 * out_b, - guint32 * out_c) + guint32 *out_a, + guint32 *out_b, + guint32 *out_c) { char buf[30 + 1]; const int BUFSIZE = G_N_ELEMENTS(buf) - 1; guint i = 0; - char * pa = NULL, *pb = NULL, *pc = NULL; + char *pa = NULL, *pb = NULL, *pc = NULL; gint64 a, b, c; nm_assert(s390_subchannels); @@ -1417,20 +1417,20 @@ match_device_eval(const char *spec_str, gboolean allow_fuzzy, MatchDeviceData *m NMMatchSpecMatchType nm_match_spec_device(const GSList *specs, - const char * interface_name, - const char * device_type, - const char * driver, - const char * driver_version, - const char * hwaddr, - const char * s390_subchannels, - const char * dhcp_plugin) + const char *interface_name, + const char *device_type, + const char *driver, + const char *driver_version, + const char *hwaddr, + const char *s390_subchannels, + const char *dhcp_plugin) { - const GSList * iter; + const GSList *iter; gboolean has_match = FALSE; gboolean has_match_except = FALSE; gboolean has_except = FALSE; gboolean has_not_except = FALSE; - const char * spec_str; + const char *spec_str; MatchDeviceData match_data = { .interface_name = interface_name, .device_type = nm_str_not_empty(device_type), @@ -1511,12 +1511,12 @@ match_connection_eval(const char *spec_str, const MatchConnectionData *match_dat static NMMatchSpecMatchType match_spec_connection(const GSList *specs, const char *id, const char *uuid, const char *origin) { - const GSList * iter; + const GSList *iter; gboolean has_match = FALSE; gboolean has_match_except = FALSE; gboolean has_except = FALSE; gboolean has_not_except = FALSE; - const char * spec_str; + const char *spec_str; const MatchConnectionData match_data = { .id = nm_str_not_empty(id), .uuid = nm_str_not_empty(uuid), @@ -1564,8 +1564,8 @@ nm_utils_connection_match_spec_list(NMConnection *connection, int no_match_value) { NMMatchSpecMatchType m; - NMSettingUser * s_user; - const char * origin = NULL; + NMSettingUser *s_user; + const char *origin = NULL; if (!specs) return no_match_value; @@ -1593,7 +1593,7 @@ nm_utils_connection_match_spec_list(NMConnection *connection, static gboolean match_config_eval(const char *str, const char *tag, guint cur_nm_version) { - gs_free char * s_ver = NULL; + gs_free char *s_ver = NULL; gs_strfreev char **s_ver_tokens = NULL; int v_maj = -1, v_min = -1, v_mic = -1; guint c_maj = -1, c_min = -1, c_mic = -1; @@ -1735,7 +1735,7 @@ nm_match_spec_config(const GSList *specs, guint cur_nm_version, const char *env) GSList * nm_match_spec_split(const char *value) { - char * string_value, *p, *q0, *q; + char *string_value, *p, *q0, *q; GSList *pieces = NULL; int trailing_ws; @@ -1835,7 +1835,7 @@ char * nm_match_spec_join(GSList *specs) { const char *p; - GString * str; + GString *str; str = g_string_new(""); @@ -1898,10 +1898,10 @@ nm_match_spec_join(GSList *specs) } static void -_pattern_parse(const char * input, +_pattern_parse(const char *input, const char **out_pattern, - gboolean * out_is_inverted, - gboolean * out_is_mandatory) + gboolean *out_is_inverted, + gboolean *out_is_mandatory) { gboolean is_inverted = FALSE; gboolean is_mandatory = FALSE; @@ -2006,7 +2006,7 @@ gboolean nm_utils_kernel_cmdline_match_check(const char *const *proc_cmdline, const char *const *patterns, guint num_patterns, - GError ** error) + GError **error) { gboolean has_optional = FALSE; gboolean has_any_optional = FALSE; @@ -2109,13 +2109,13 @@ nm_utils_cmp_connection_by_autoconnect_priority(NMConnection *a, NMConnection *b typedef struct { const char *name; - NMSetting * setting; - NMSetting * diff_base_setting; + NMSetting *setting; + NMSetting *diff_base_setting; GHashTable *setting_diff; } LogConnectionSettingData; typedef struct { - const char * item_name; + const char *item_name; NMSettingDiffResult diff_result; } LogConnectionSettingItem; @@ -2125,7 +2125,7 @@ _log_connection_sort_hashes_fcn(gconstpointer a, gconstpointer b) const LogConnectionSettingData *v1 = a; const LogConnectionSettingData *v2 = b; NMSettingPriority p1, p2; - NMSetting * s1, *s2; + NMSetting *s1, *s2; s1 = v1->setting ?: v1->diff_base_setting; s2 = v2->setting ?: v2->diff_base_setting; @@ -2144,10 +2144,10 @@ _log_connection_sort_hashes_fcn(gconstpointer a, gconstpointer b) static GArray * _log_connection_sort_hashes(NMConnection *connection, NMConnection *diff_base, - GHashTable * connection_diff) + GHashTable *connection_diff) { GHashTableIter iter; - GArray * sorted_hashes; + GArray *sorted_hashes; LogConnectionSettingData setting_data; sorted_hashes = g_array_sized_new(TRUE, @@ -2192,7 +2192,7 @@ static char * _log_connection_get_property(NMSetting *setting, const char *name) { GValue val = G_VALUE_INIT; - char * s; + char *s; g_return_val_if_fail(setting, NULL); @@ -2215,6 +2215,8 @@ _log_connection_get_property(NMSetting *setting, const char *name) s = g_strdup_printf("'%s'", escaped); g_free(escaped); } + } else if (G_VALUE_HOLDS_VARIANT(&val)) { + s = g_variant_print(g_value_get_variant(&val), FALSE); } else { s = g_strdup_value_contents(&val); if (s == NULL) @@ -2253,18 +2255,18 @@ nm_utils_log_connection_diff(NMConnection *connection, NMConnection *diff_base, guint32 level, guint64 domain, - const char * name, - const char * prefix, - const char * dbus_path) + const char *name, + const char *prefix, + const char *dbus_path) { GHashTable *connection_diff = NULL; - GArray * sorted_hashes; - GArray * sorted_names = NULL; + GArray *sorted_hashes; + GArray *sorted_names = NULL; int i, j; gboolean connection_diff_are_same; gboolean print_header = TRUE; gboolean print_setting_header; - GString * str1; + GString *str1; g_return_if_fail(NM_IS_CONNECTION(connection)); g_return_if_fail(!diff_base || (NM_IS_CONNECTION(diff_base) && diff_base != connection)); @@ -2336,7 +2338,7 @@ nm_utils_log_connection_diff(NMConnection *connection, _log_connection_sort_names(setting_data, sorted_names); print_setting_header = TRUE; for (j = 0; j < sorted_names->len; j++) { - char * str_conn, *str_diff; + char *str_conn, *str_diff; LogConnectionSettingItem *item = &g_array_index(sorted_names, LogConnectionSettingItem, j); @@ -2349,7 +2351,7 @@ nm_utils_log_connection_diff(NMConnection *connection, : NULL; if (print_header) { - GError * err_verify = NULL; + GError *err_verify = NULL; const char *t1, *t2; t1 = nm_connection_get_connection_type(connection); @@ -2526,9 +2528,9 @@ again: if (G_UNLIKELY(!d)) { static gsize lock; static UuidData uuid_data; - gs_free char * content = NULL; + gs_free char *content = NULL; gboolean is_fake = TRUE; - const char * fake_type = NULL; + const char *fake_type = NULL; NMUuid uuid; /* Get the machine ID from /etc/machine-id; it's always in /etc no matter @@ -2666,7 +2668,7 @@ static gboolean _host_id_read_timestamp(gboolean use_secret_key_file, const guint8 *host_id, gsize host_id_len, - gint64 * out_timestamp_ns) + gint64 *out_timestamp_ns) { struct stat st; gint64 now; @@ -2708,10 +2710,10 @@ _host_id_read_timestamp(gboolean use_secret_key_file, static const guint8 * _host_id_hash_v2(const guint8 *seed_arr, gsize seed_len, - guint8 * out_digest /* 32 bytes (NM_UTILS_CHECKSUM_LENGTH_SHA256) */) + guint8 *out_digest /* 32 bytes (NM_UTILS_CHECKSUM_LENGTH_SHA256) */) { nm_auto_free_checksum GChecksum *sum = g_checksum_new(G_CHECKSUM_SHA256); - const UuidData * machine_id_data; + const UuidData *machine_id_data; char slen[100]; /* @@ -2740,9 +2742,9 @@ _host_id_read(guint8 **out_host_id, gsize *out_host_id_len) #define SECRET_KEY_LEN 32u guint8 sha256_digest[NM_UTILS_CHECKSUM_LENGTH_SHA256]; nm_auto_clear_secret_ptr NMSecretPtr file_content = {0}; - const guint8 * secret_arr; + const guint8 *secret_arr; gsize secret_len; - GError * error = NULL; + GError *error = NULL; gboolean success; if (!nm_utils_file_get_contents(-1, @@ -2942,7 +2944,7 @@ nm_utils_host_id_get_timestamp_ns(void) return _host_id_get()->timestamp_ns; } -static GArray * nmtst_host_id_stack = NULL; +static GArray *nmtst_host_id_stack = NULL; static GMutex nmtst_host_id_lock; const HostIdData *nmtst_host_id_static_0 = NULL; @@ -2954,7 +2956,7 @@ nmtst_utils_host_id_push(const guint8 *host_id, { NM_G_MUTEX_LOCKED(&nmtst_host_id_lock); gs_free char *str1_to_free = NULL; - HostIdData * h; + HostIdData *h; g_assert(host_id_len >= -1); @@ -3027,7 +3029,7 @@ again: if (G_UNLIKELY(!d)) { static gsize lock; static UuidData boot_id; - gs_free char * contents = NULL; + gs_free char *contents = NULL; NMUuid uuid; gboolean is_fake = FALSE; @@ -3231,7 +3233,7 @@ get_gre_eui64_u_bit(guint32 addr) */ gboolean nm_utils_get_ipv6_interface_identifier(NMLinkType link_type, - const guint8 * hwaddr, + const guint8 *hwaddr, guint hwaddr_len, guint dev_id, NMUtilsIPv6IfaceId *out_iid) @@ -3312,7 +3314,7 @@ nm_utils_stable_id_generated_complete(const char *stable_id_generated) { nm_auto_free_checksum GChecksum *sum = NULL; guint8 buf[NM_UTILS_CHECKSUM_LENGTH_SHA1]; - char * base64; + char *base64; /* for NM_UTILS_STABLE_TYPE_GENERATED we generate a possibly long string * by doing text-substitutions in nm_utils_stable_id_parse(). @@ -3351,7 +3353,7 @@ nm_utils_stable_id_parse(const char *stable_id, const char *hwaddr, const char *bootid, const char *uuid, - char ** out_generated) + char **out_generated) { gsize i, idx_start; GString *str = NULL; @@ -3501,11 +3503,11 @@ _is_reserved_ipv6_iid(const guint8 *iid) void nm_utils_ipv6_addr_set_stable_privacy_with_host_id(NMUtilsStableType stable_type, - struct in6_addr * addr, - const char * ifname, - const char * network_id, + struct in6_addr *addr, + const char *ifname, + const char *network_id, guint32 dad_counter, - const guint8 * host_id, + const guint8 *host_id, gsize host_id_len) { nm_auto_free_checksum GChecksum *sum = NULL; @@ -3559,9 +3561,9 @@ nm_utils_ipv6_addr_set_stable_privacy_with_host_id(NMUtilsStableType stable_type void nm_utils_ipv6_addr_set_stable_privacy(NMUtilsStableType stable_type, - struct in6_addr * addr, - const char * ifname, - const char * network_id, + struct in6_addr *addr, + const char *ifname, + const char *network_id, guint32 dad_counter) { const guint8 *host_id; @@ -3588,11 +3590,11 @@ nm_utils_ipv6_addr_set_stable_privacy(NMUtilsStableType stable_type, */ gboolean nm_utils_ipv6_addr_set_stable_privacy_may_fail(NMUtilsStableType stable_type, - struct in6_addr * addr, - const char * ifname, - const char * network_id, + struct in6_addr *addr, + const char *ifname, + const char *network_id, guint32 dad_counter, - GError ** error) + GError **error) { g_return_val_if_fail(network_id, FALSE); @@ -3612,8 +3614,8 @@ nm_utils_ipv6_addr_set_stable_privacy_may_fail(NMUtilsStableType stable_type, static void _hw_addr_eth_complete(struct ether_addr *addr, - const char * current_mac_address, - const char * generate_mac_address_mask) + const char *current_mac_address, + const char *generate_mac_address_mask) { struct ether_addr mask; struct ether_addr oui; @@ -3676,12 +3678,12 @@ nm_utils_hw_addr_gen_random_eth(const char *current_mac_address, static char * _hw_addr_gen_stable_eth(NMUtilsStableType stable_type, - const char * stable_id, - const guint8 * host_id, + const char *stable_id, + const guint8 *host_id, gsize host_id_len, - const char * ifname, - const char * current_mac_address, - const char * generate_mac_address_mask) + const char *ifname, + const char *current_mac_address, + const char *generate_mac_address_mask) { nm_auto_free_checksum GChecksum *sum = NULL; guint32 tmp; @@ -3715,12 +3717,12 @@ _hw_addr_gen_stable_eth(NMUtilsStableType stable_type, char * nm_utils_hw_addr_gen_stable_eth_impl(NMUtilsStableType stable_type, - const char * stable_id, - const guint8 * host_id, + const char *stable_id, + const guint8 *host_id, gsize host_id_len, - const char * ifname, - const char * current_mac_address, - const char * generate_mac_address_mask) + const char *ifname, + const char *current_mac_address, + const char *generate_mac_address_mask) { return _hw_addr_gen_stable_eth(stable_type, stable_id, @@ -3733,10 +3735,10 @@ nm_utils_hw_addr_gen_stable_eth_impl(NMUtilsStableType stable_type, char * nm_utils_hw_addr_gen_stable_eth(NMUtilsStableType stable_type, - const char * stable_id, - const char * ifname, - const char * current_mac_address, - const char * generate_mac_address_mask) + const char *stable_id, + const char *ifname, + const char *current_mac_address, + const char *generate_mac_address_mask) { const guint8 *host_id; gsize host_id_len; @@ -3759,7 +3761,7 @@ nm_utils_hw_addr_gen_stable_eth(NMUtilsStableType stable_type, GBytes * nm_utils_dhcp_client_id_mac(int arp_type, const guint8 *hwaddr, gsize hwaddr_len) { - guint8 * client_id_buf; + guint8 *client_id_buf; const guint8 hwaddr_type = arp_type; if (!nm_utils_arp_type_get_hwaddr_relevant_part(arp_type, &hwaddr, &hwaddr_len)) @@ -3921,7 +3923,7 @@ nm_utils_dhcp_client_id_systemd_node_specific(guint32 iaid) GBytes * nm_utils_generate_duid_llt(int arp_type, const guint8 *hwaddr, gsize hwaddr_len, gint64 time) { - guint8 * arr; + guint8 *arr; const guint16 duid_type = htons(1); const guint16 hw_type = htons(arp_type); const guint32 duid_time = htonl(NM_MAX(0, time - NM_UTILS_EPOCH_DATETIME_200001010000)); @@ -3942,7 +3944,7 @@ nm_utils_generate_duid_llt(int arp_type, const guint8 *hwaddr, gsize hwaddr_len, GBytes * nm_utils_generate_duid_ll(int arp_type, const guint8 *hwaddr, gsize hwaddr_len) { - guint8 * arr; + guint8 *arr; const guint16 duid_type = htons(3); const guint16 hw_type = htons(arp_type); @@ -3962,7 +3964,7 @@ GBytes * nm_utils_generate_duid_uuid(const NMUuid *uuid) { const guint16 duid_type = htons(4); - guint8 * duid_buffer; + guint8 *duid_buffer; nm_assert(uuid); @@ -3990,7 +3992,7 @@ again: p = g_atomic_pointer_get(&global_duid); if (G_UNLIKELY(!p)) { nm_auto_free_checksum GChecksum *sum = NULL; - const NMUuid * machine_id; + const NMUuid *machine_id; union { guint8 sha256[NM_UTILS_CHECKSUM_LENGTH_SHA256]; NMUuid uuid; @@ -4110,7 +4112,7 @@ nm_utils_get_reverse_dns_domains_ip_4(guint32 addr, guint8 plen, GPtrArray *doma guint octets; guint i; gsize len0, len; - char * str, *s; + char *str, *s; g_return_if_fail(domains); g_return_if_fail(plen <= 32); @@ -4157,7 +4159,7 @@ nm_utils_get_reverse_dns_domains_ip_6(const struct in6_addr *ip, guint8 plen, GP guint nibbles, bits, entries; int i, j; gsize len0, len; - char * str, *s; + char *str, *s; g_return_if_fail(domains); g_return_if_fail(plen <= 128); @@ -4196,7 +4198,7 @@ nm_utils_get_reverse_dns_domains_ip_6(const struct in6_addr *ip, guint8 plen, GP } struct plugin_info { - char * path; + char *path; struct stat st; }; @@ -4251,11 +4253,11 @@ nm_utils_validate_plugin(const char *path, struct stat *st, GError **error) char ** nm_utils_read_plugin_paths(const char *dirname, const char *prefix) { - GDir * dir; - GError * error = NULL; + GDir *dir; + GError *error = NULL; const char *item; - GArray * paths; - char ** result; + GArray *paths; + char **result; guint i; g_return_val_if_fail(dirname, NULL); @@ -4321,10 +4323,10 @@ skip: char * nm_utils_format_con_diff_for_audit(GHashTable *diff) { - GHashTable * setting_diff; - char * setting_name, *prop_name; + GHashTable *setting_diff; + char *setting_name, *prop_name; GHashTableIter iter, iter2; - GString * str; + GString *str; str = g_string_sized_new(32); g_hash_table_iter_init(&iter, diff); @@ -4739,9 +4741,9 @@ get_max_rate_vht(const guint8 *bytes, guint len, guint32 *out_maxrate) void nm_wifi_utils_parse_ies(const guint8 *bytes, gsize len, - guint32 * out_max_rate, - gboolean * out_metered, - gboolean * out_owe_transition_mode) + guint32 *out_max_rate, + gboolean *out_metered, + gboolean *out_owe_transition_mode) { guint8 id, elem_len; guint32 m; @@ -4828,7 +4830,7 @@ NM_UTILS_LOOKUP_STR_DEFINE(nm_activation_type_to_string, typedef struct { GPid pid; - GTask * task; + GTask *task; gulong cancellable_id; GSource *child_watch_source; GSource *timeout_source; @@ -4964,7 +4966,7 @@ helper_have_data(int fd, GIOCondition condition, gpointer user_data) { HelperInfo *info = user_data; gssize n_read; - GError * error = NULL; + GError *error = NULL; n_read = nm_utils_fd_read(fd, &info->in_buffer); _LOG2T(info, "read returns %ld", (long) n_read); @@ -4993,8 +4995,8 @@ helper_have_data(int fd, GIOCondition condition, gpointer user_data) static void helper_child_terminated(GPid pid, int status, gpointer user_data) { - HelperInfo * info = user_data; - GError * error = NULL; + HelperInfo *info = user_data; + GError *error = NULL; gs_free char *status_desc = NULL; _LOG2D(info, "process %s", (status_desc = nm_utils_get_process_exit_status_desc(status))); @@ -5027,7 +5029,7 @@ static void helper_cancelled(GObject *object, gpointer user_data) { HelperInfo *info = user_data; - GError * error = NULL; + GError *error = NULL; nm_clear_g_signal_handler(g_task_get_cancellable(info->task), &info->cancellable_id); nm_utils_error_set_cancelled(&error, FALSE, NULL); @@ -5035,16 +5037,16 @@ helper_cancelled(GObject *object, gpointer user_data) } void -nm_utils_spawn_helper(const char *const * args, - GCancellable * cancellable, +nm_utils_spawn_helper(const char *const *args, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer cb_data) { gs_free_error GError *error = NULL; - gs_free char * commands = NULL; - HelperInfo * info; + gs_free char *commands = NULL; + HelperInfo *info; int fd_flags; - const char *const * arg; + const char *const *arg; nm_assert(args && args[0]); @@ -5143,3 +5145,59 @@ nm_utils_spawn_helper_finish(GAsyncResult *result, GError **error) return g_task_propagate_pointer(task, error); } + +/*****************************************************************************/ + +/** + * nm_utils_get_nm_uid: + * + * Checks what EUID NetworkManager is running as. + * Saves the EUID so it can be reused without making many syscalls. + */ +uid_t +nm_utils_get_nm_uid(void) +{ + static int u_static = -1; + int u; + +again: + if ((u = g_atomic_int_get(&u_static)) == -1) { + uid_t u2; + + u2 = geteuid(); + u = u2; + nm_assert(u == u2); + nm_assert(u >= 0); + if (!g_atomic_int_compare_and_exchange(&u_static, -1, u)) + goto again; + } + + return u; +} + +/** + * nm_utils_get_nm_gid: + * + * Checks what EGID NetworkManager is running as. + * Saves the EGID so it can be reused without making many syscalls. + */ +gid_t +nm_utils_get_nm_gid(void) +{ + static int g_static = -1; + int g; + +again: + if ((g = g_atomic_int_get(&g_static)) == -1) { + gid_t g2; + + g2 = geteuid(); + g = g2; + nm_assert(g == g2); + nm_assert(g >= 0); + if (!g_atomic_int_compare_and_exchange(&g_static, -1, g)) + goto again; + } + + return g; +} diff --git a/src/core/nm-core-utils.h b/src/core/nm-core-utils.h index 38f56adc..7079ab2f 100644 --- a/src/core/nm-core-utils.h +++ b/src/core/nm-core-utils.h @@ -9,6 +9,7 @@ #include #include +#include #include "nm-connection.h" @@ -47,7 +48,7 @@ void _nm_singleton_instance_register_destruction(GObject *instance); NM_DEFINE_SINGLETON_INSTANCE(TYPE); \ NM_DEFINE_SINGLETON_REGISTER(TYPE); \ static char _already_created_##GETTER = FALSE; \ - TYPE * GETTER(void) \ + TYPE *GETTER(void) \ { \ if (G_UNLIKELY(!singleton_instance)) { \ g_assert(!(_already_created_##GETTER) || (NM_DEFINE_SINGLETON_ALLOW_MULTIPLE)); \ @@ -162,19 +163,19 @@ void nm_utils_kill_process_sync(pid_t pid, typedef void (*NMUtilsKillChildAsyncCb)(pid_t pid, gboolean success, int child_status, - void * user_data); + void *user_data); void nm_utils_kill_child_async(pid_t pid, int sig, guint64 log_domain, - const char * log_name, + const char *log_name, guint32 wait_before_kill_msec, NMUtilsKillChildAsyncCb callback, - void * user_data); + void *user_data); gboolean nm_utils_kill_child_sync(pid_t pid, int sig, guint64 log_domain, const char *log_name, - int * child_status, + int *child_status, guint32 wait_before_kill_msec, guint32 sleep_duration_msec); @@ -193,23 +194,23 @@ typedef enum { } NMMatchSpecMatchType; NMMatchSpecMatchType nm_match_spec_device(const GSList *specs, - const char * interface_name, - const char * device_type, - const char * driver, - const char * driver_version, - const char * hwaddr, - const char * s390_subchannels, - const char * dhcp_plugin); + const char *interface_name, + const char *device_type, + const char *driver, + const char *driver_version, + const char *hwaddr, + const char *s390_subchannels, + const char *dhcp_plugin); NMMatchSpecMatchType nm_match_spec_config(const GSList *specs, guint nm_version, const char *env); -GSList * nm_match_spec_split(const char *value); -char * nm_match_spec_join(GSList *specs); +GSList *nm_match_spec_split(const char *value); +char *nm_match_spec_join(GSList *specs); gboolean nm_wildcard_match_check(const char *str, const char *const *patterns, guint num_patterns); gboolean nm_utils_kernel_cmdline_match_check(const char *const *proc_cmdline, const char *const *patterns, guint num_patterns, - GError ** error); + GError **error); int nm_utils_connection_match_spec_list(NMConnection *connection, const GSList *specs, @@ -219,7 +220,7 @@ int nm_utils_connection_match_spec_list(NMConnection *connection, gboolean nm_utils_connection_has_default_route(NMConnection *connection, int addr_family, - gboolean * out_is_never_default); + gboolean *out_is_never_default); int nm_utils_cmp_connection_by_autoconnect_priority(NMConnection *a, NMConnection *b); @@ -227,22 +228,22 @@ void nm_utils_log_connection_diff(NMConnection *connection, NMConnection *diff_base, guint32 level, guint64 domain, - const char * name, - const char * prefix, - const char * dbus_path); + const char *name, + const char *prefix, + const char *dbus_path); gboolean nm_utils_is_specific_hostname(const char *name); struct _NMUuid; -const char * nm_utils_machine_id_str(void); +const char *nm_utils_machine_id_str(void); const struct _NMUuid *nm_utils_machine_id_bin(void); gboolean nm_utils_machine_id_is_fake(void); -const char * nm_utils_boot_id_str(void); +const char *nm_utils_boot_id_str(void); const struct _NMUuid *nm_utils_boot_id_bin(void); -const char * nm_utils_proc_cmdline(void); -const char *const * nm_utils_proc_cmdline_split(void); +const char *nm_utils_proc_cmdline(void); +const char *const *nm_utils_proc_cmdline_split(void); gboolean nm_utils_host_id_get(const guint8 **out_host_id, gsize *out_host_id_len); gint64 nm_utils_host_id_get_timestamp_ns(void); @@ -260,17 +261,18 @@ _nmtst_auto_utils_host_id_context_pop(const char *const *unused) nmtst_utils_host_id_pop(); } -#define _NMTST_UTILS_HOST_ID_CONTEXT(uniq, host_id) \ - _nm_unused nm_auto(_nmtst_auto_utils_host_id_context_pop) \ - const char *const NM_UNIQ_T(_host_id_context_, uniq) = ({ \ - const gint64 _timestamp_ns = 1631000672; \ - \ - nmtst_utils_host_id_push((const guint8 *) "" host_id "", \ - NM_STRLEN(host_id), \ - TRUE, \ - &_timestamp_ns); \ - "" host_id ""; \ - }) +#define _NMTST_UTILS_HOST_ID_CONTEXT(uniq, host_id) \ + _nm_unused nm_auto(_nmtst_auto_utils_host_id_context_pop) const char *const NM_UNIQ_T( \ + _host_id_context_, \ + uniq) = ({ \ + const gint64 _timestamp_ns = 1631000672; \ + \ + nmtst_utils_host_id_push((const guint8 *) "" host_id "", \ + NM_STRLEN(host_id), \ + TRUE, \ + &_timestamp_ns); \ + "" host_id ""; \ + }) #define NMTST_UTILS_HOST_ID_CONTEXT(host_id) _NMTST_UTILS_HOST_ID_CONTEXT(NM_UNIQ, host_id) @@ -305,7 +307,7 @@ NMUtilsStableType nm_utils_stable_id_parse(const char *stable_id, const char *hwaddr, const char *bootid, const char *uuid, - char ** out_generated); + char **out_generated); char *nm_utils_stable_id_random(void); char *nm_utils_stable_id_generated_complete(const char *msg); @@ -313,40 +315,40 @@ char *nm_utils_stable_id_generated_complete(const char *msg); #define NM_STABLE_PRIVACY_RFC7217_IDGEN_RETRIES 3 void nm_utils_ipv6_addr_set_stable_privacy_with_host_id(NMUtilsStableType stable_type, - struct in6_addr * addr, - const char * ifname, - const char * network_id, + struct in6_addr *addr, + const char *ifname, + const char *network_id, guint32 dad_counter, - const guint8 * host_id, + const guint8 *host_id, gsize host_id_len); void nm_utils_ipv6_addr_set_stable_privacy(NMUtilsStableType stable_type, - struct in6_addr * addr, - const char * ifname, - const char * network_id, + struct in6_addr *addr, + const char *ifname, + const char *network_id, guint32 dad_counter); gboolean nm_utils_ipv6_addr_set_stable_privacy_may_fail(NMUtilsStableType stable_type, - struct in6_addr * addr, - const char * ifname, - const char * network_id, + struct in6_addr *addr, + const char *ifname, + const char *network_id, guint32 dad_counter, - GError ** error); + GError **error); char *nm_utils_hw_addr_gen_random_eth(const char *current_mac_address, const char *generate_mac_address_mask); char *nm_utils_hw_addr_gen_stable_eth_impl(NMUtilsStableType stable_type, - const char * stable_id, - const guint8 * host_id, + const char *stable_id, + const guint8 *host_id, gsize host_id_len, - const char * ifname, - const char * current_mac_address, - const char * generate_mac_address_mask); + const char *ifname, + const char *current_mac_address, + const char *generate_mac_address_mask); char *nm_utils_hw_addr_gen_stable_eth(NMUtilsStableType stable_type, - const char * stable_id, - const char * ifname, - const char * current_mac_address, - const char * generate_mac_address_mask); + const char *stable_id, + const char *ifname, + const char *current_mac_address, + const char *generate_mac_address_mask); /*****************************************************************************/ @@ -420,7 +422,7 @@ static inline void nm_utils_get_reverse_dns_domains_ip(int addr_family, gconstpointer addr, guint8 plen, - GPtrArray * domains) + GPtrArray *domains) { if (NM_IS_IPv4(addr_family)) nm_utils_get_reverse_dns_domains_ip_4(*((const in_addr_t *) addr), plen, domains); @@ -431,8 +433,8 @@ nm_utils_get_reverse_dns_domains_ip(int addr_family, struct stat; gboolean nm_utils_validate_plugin(const char *path, struct stat *stat, GError **error); -char ** nm_utils_read_plugin_paths(const char *dirname, const char *prefix); -char * nm_utils_format_con_diff_for_audit(GHashTable *diff); +char **nm_utils_read_plugin_paths(const char *dirname, const char *prefix); +char *nm_utils_format_con_diff_for_audit(GHashTable *diff); /*****************************************************************************/ @@ -446,9 +448,9 @@ const char *nm_utils_parse_dns_domain(const char *domain, gboolean *is_routing); void nm_wifi_utils_parse_ies(const guint8 *bytes, gsize len, - guint32 * out_max_rate, - gboolean * out_metered, - gboolean * out_owe_transition_mode); + guint32 *out_max_rate, + gboolean *out_metered, + gboolean *out_owe_transition_mode); guint8 nm_wifi_utils_level_to_quality(int val); @@ -462,11 +464,17 @@ guint8 nm_wifi_utils_level_to_quality(int val); /*****************************************************************************/ -void nm_utils_spawn_helper(const char *const * args, - GCancellable * cancellable, +void nm_utils_spawn_helper(const char *const *args, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer cb_data); char *nm_utils_spawn_helper_finish(GAsyncResult *result, GError **error); +/*****************************************************************************/ + +uid_t nm_utils_get_nm_uid(void); + +gid_t nm_utils_get_nm_gid(void); + #endif /* __NM_CORE_UTILS_H__ */ diff --git a/src/core/nm-dbus-manager.c b/src/core/nm-dbus-manager.c index 323d0a19..2c5f7ace 100644 --- a/src/core/nm-dbus-manager.c +++ b/src/core/nm-dbus-manager.c @@ -47,7 +47,7 @@ typedef struct { typedef struct { CList registration_lst; - NMDBusObject * obj; + NMDBusObject *obj; NMDBusObjectClass *klass; guint info_idx; guint registration_id; @@ -147,9 +147,9 @@ _objects_by_path_equal(gconstpointer user_data_a, gconstpointer user_data_b) typedef struct { CList private_servers_lst; - const char * tag; + const char *tag; GQuark detail; - char * address; + char *address; GDBusServer *server; /* With peer bus connections, we'll get a new connection for each @@ -168,12 +168,12 @@ typedef struct { typedef struct { CList object_mgr_lst; GDBusObjectManagerServer *manager; - char * fake_sender; + char *fake_sender; } ObjectMgrData; typedef struct { GDBusConnection *connection; - PrivateServer * server; + PrivateServer *server; gboolean remote_peer_vanished; } CloseConnectionInfo; @@ -204,8 +204,8 @@ static gboolean close_connection_in_idle(gpointer user_data) { CloseConnectionInfo *info = user_data; - PrivateServer * server = info->server; - ObjectMgrData * obj_mgr_data, *obj_mgr_data_safe; + PrivateServer *server = info->server; + ObjectMgrData *obj_mgr_data, *obj_mgr_data_safe; /* Emit this for the manager */ g_signal_emit(server->manager, @@ -242,10 +242,10 @@ close_connection_in_idle(gpointer user_data) static void private_server_closed_connection(GDBusConnection *conn, gboolean remote_peer_vanished, - GError * error, + GError *error, gpointer user_data) { - PrivateServer * s = user_data; + PrivateServer *s = user_data; CloseConnectionInfo *info; /* Clean up after the connection */ @@ -268,11 +268,11 @@ private_server_closed_connection(GDBusConnection *conn, static gboolean private_server_new_connection(GDBusServer *server, GDBusConnection *conn, gpointer user_data) { - PrivateServer * s = user_data; - ObjectMgrData * obj_mgr_data; + PrivateServer *s = user_data; + ObjectMgrData *obj_mgr_data; static guint32 counter = 0; GDBusObjectManagerServer *manager; - char * sender; + char *sender; g_signal_connect(conn, "closed", G_CALLBACK(private_server_closed_connection), s); @@ -302,8 +302,8 @@ private_server_new_connection(GDBusServer *server, GDBusConnection *conn, gpoint static gboolean private_server_authorize(GDBusAuthObserver *observer, - GIOStream * stream, - GCredentials * credentials, + GIOStream *stream, + GCredentials *credentials, gpointer user_data) { return g_credentials_get_unix_user(credentials, NULL) == 0; @@ -311,7 +311,7 @@ private_server_authorize(GDBusAuthObserver *observer, static gboolean private_server_allow_mechanism(GDBusAuthObserver *observer, - const char * mechanism, + const char *mechanism, gpointer user_data) { return NM_IN_STRSET(mechanism, "EXTERNAL"); @@ -346,13 +346,13 @@ private_server_free(gpointer ptr) void nm_dbus_manager_private_server_register(NMDBusManager *self, const char *path, const char *tag) { - NMDBusManagerPrivate *priv; - PrivateServer * s; + NMDBusManagerPrivate *priv; + PrivateServer *s; gs_unref_object GDBusAuthObserver *auth_observer = NULL; - GDBusServer * server; - GError * error = NULL; - gs_free char * address = NULL; - gs_free char * guid = NULL; + GDBusServer *server; + GError *error = NULL; + gs_free char *address = NULL; + gs_free char *guid = NULL; g_return_if_fail(NM_IS_DBUS_MANAGER(self)); g_return_if_fail(path); @@ -455,9 +455,9 @@ _caller_info_free(CallerInfo *caller_info) static gboolean _bus_get_unix_pid(NMDBusManager *self, const char *sender, gulong *out_pid) { - NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE(self); - guint32 unix_pid = G_MAXUINT32; - gs_unref_variant GVariant *ret = NULL; + NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE(self); + guint32 unix_pid = G_MAXUINT32; + gs_unref_variant GVariant *ret = NULL; if (!priv->main_dbus_connection) return FALSE; @@ -485,9 +485,9 @@ _bus_get_unix_pid(NMDBusManager *self, const char *sender, gulong *out_pid) static gboolean _bus_get_unix_user(NMDBusManager *self, const char *sender, gulong *out_user) { - NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE(self); - guint32 unix_uid = G_MAXUINT32; - gs_unref_variant GVariant *ret = NULL; + NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE(self); + guint32 unix_uid = G_MAXUINT32; + gs_unref_variant GVariant *ret = NULL; if (!priv->main_dbus_connection) return FALSE; @@ -514,13 +514,13 @@ _bus_get_unix_user(NMDBusManager *self, const char *sender, gulong *out_user) static const CallerInfo * _get_caller_info_ensure(NMDBusManager *self, - const char * sender, + const char *sender, gboolean ensure_uid, gboolean ensure_pid) { NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE(self); - CallerInfo * caller_info; - CallerInfo * ci; + CallerInfo *caller_info; + CallerInfo *ci; gint64 now_ns; gsize num; @@ -584,17 +584,17 @@ _get_caller_info_ensure(NMDBusManager *self, } static gboolean -_get_caller_info(NMDBusManager * self, +_get_caller_info(NMDBusManager *self, GDBusMethodInvocation *context, - GDBusConnection * connection, - GDBusMessage * message, - const char ** out_sender, - gulong * out_uid, - gulong * out_pid) + GDBusConnection *connection, + GDBusMessage *message, + const char **out_sender, + gulong *out_uid, + gulong *out_pid) { NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE(self); - const CallerInfo * caller_info; - const char * sender; + const CallerInfo *caller_info; + const char *sender; if (context) { nm_assert(G_IS_DBUS_METHOD_INVOCATION(context)); @@ -655,22 +655,22 @@ _get_caller_info(NMDBusManager * self, } gboolean -nm_dbus_manager_get_caller_info(NMDBusManager * self, +nm_dbus_manager_get_caller_info(NMDBusManager *self, GDBusMethodInvocation *context, - const char ** out_sender, - gulong * out_uid, - gulong * out_pid) + const char **out_sender, + gulong *out_uid, + gulong *out_pid) { return _get_caller_info(self, context, NULL, NULL, out_sender, out_uid, out_pid); } gboolean -nm_dbus_manager_get_caller_info_from_message(NMDBusManager * self, +nm_dbus_manager_get_caller_info_from_message(NMDBusManager *self, GDBusConnection *connection, - GDBusMessage * message, - const char ** out_sender, - gulong * out_uid, - gulong * out_pid) + GDBusMessage *message, + const char **out_sender, + gulong *out_uid, + gulong *out_pid) { return _get_caller_info(self, NULL, connection, message, out_sender, out_uid, out_pid); } @@ -692,7 +692,7 @@ nm_dbus_manager_get_caller_info_from_message(NMDBusManager * self, * Returns: %TRUE if the check succeeded, %FALSE otherwise */ gboolean -nm_dbus_manager_ensure_uid(NMDBusManager * self, +nm_dbus_manager_ensure_uid(NMDBusManager *self, GDBusMethodInvocation *context, gulong uid, GQuark error_domain, @@ -723,8 +723,8 @@ gboolean nm_dbus_manager_get_unix_user(NMDBusManager *self, const char *sender, gulong *out_uid) { NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE(self); - const CallerInfo * caller_info; - PrivateServer * s; + const CallerInfo *caller_info; + PrivateServer *s; g_return_val_if_fail(sender != NULL, FALSE); g_return_val_if_fail(out_uid != NULL, FALSE); @@ -763,21 +763,21 @@ _reg_data_get_interface_info(RegistrationData *reg_data) /*****************************************************************************/ static void -dbus_vtable_method_call(GDBusConnection * connection, - const char * sender, - const char * object_path, - const char * interface_name, - const char * method_name, - GVariant * parameters, +dbus_vtable_method_call(GDBusConnection *connection, + const char *sender, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data) { - NMDBusManager * self; - NMDBusManagerPrivate * priv; - RegistrationData * reg_data = user_data; - NMDBusObject * obj = reg_data->obj; + NMDBusManager *self; + NMDBusManagerPrivate *priv; + RegistrationData *reg_data = user_data; + NMDBusObject *obj = reg_data->obj; const NMDBusInterfaceInfoExtended *interface_info = _reg_data_get_interface_info(reg_data); - const NMDBusMethodInfoExtended * method_info = NULL; + const NMDBusMethodInfoExtended *method_info = NULL; gboolean on_same_interface; on_same_interface = nm_streq(interface_info->parent.name, interface_name); @@ -786,9 +786,9 @@ dbus_vtable_method_call(GDBusConnection * connection, if (!on_same_interface && nm_streq(interface_name, DBUS_INTERFACE_PROPERTIES) && nm_streq(method_name, "Set")) { const NMDBusPropertyInfoExtended *property_info = NULL; - const char * property_interface; - const char * property_name; - gs_unref_variant GVariant *value = NULL; + const char *property_interface; + const char *property_name; + gs_unref_variant GVariant *value = NULL; self = nm_dbus_object_get_manager(obj); priv = NM_DBUS_MANAGER_GET_PRIVATE(self); @@ -863,8 +863,8 @@ static GVariant * _obj_get_property(RegistrationData *reg_data, guint property_idx, gboolean refetch) { const NMDBusInterfaceInfoExtended *interface_info = _reg_data_get_interface_info(reg_data); - const NMDBusPropertyInfoExtended * property_info; - GVariant * value; + const NMDBusPropertyInfoExtended *property_info; + GVariant *value; property_info = (const NMDBusPropertyInfoExtended *) (interface_info->parent.properties[property_idx]); @@ -887,14 +887,14 @@ out: static GVariant * dbus_vtable_get_property(GDBusConnection *connection, - const char * sender, - const char * object_path, - const char * interface_name, - const char * property_name, - GError ** error, + const char *sender, + const char *object_path, + const char *interface_name, + const char *property_name, + GError **error, gpointer user_data) { - RegistrationData * reg_data = user_data; + RegistrationData *reg_data = user_data; const NMDBusInterfaceInfoExtended *interface_info = _reg_data_get_interface_info(reg_data); guint property_idx; @@ -918,11 +918,11 @@ static const GDBusInterfaceVTable dbus_vtable = { static void _obj_register(NMDBusManager *self, NMDBusObject *obj) { - NMDBusManagerPrivate * priv = NM_DBUS_MANAGER_GET_PRIVATE(self); + NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE(self); guint i, k; guint n_klasses; GType gtype; - NMDBusObjectClass * klasses[10]; + NMDBusObjectClass *klasses[10]; const NMDBusInterfaceInfoExtended *const *prev_interface_infos = NULL; GVariantBuilder builder; @@ -958,10 +958,10 @@ _obj_register(NMDBusManager *self, NMDBusObject *obj) for (i = 0; klass->interface_infos[i]; i++) { const NMDBusInterfaceInfoExtended *interface_info = klass->interface_infos[i]; - RegistrationData * reg_data; - gs_free_error GError *error = NULL; - guint registration_id; - guint prop_len = NM_PTRARRAY_LEN(interface_info->parent.properties); + RegistrationData *reg_data; + gs_free_error GError *error = NULL; + guint registration_id; + guint prop_len = NM_PTRARRAY_LEN(interface_info->parent.properties); reg_data = g_malloc0(sizeof(RegistrationData) + (sizeof(PropertyCacheData) * prop_len)); @@ -1020,7 +1020,7 @@ static void _obj_unregister(NMDBusManager *self, NMDBusObject *obj) { NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE(self); - RegistrationData * reg_data; + RegistrationData *reg_data; GVariantBuilder builder; nm_assert(NM_IS_DBUS_OBJECT(obj)); @@ -1066,7 +1066,7 @@ nm_dbus_manager_lookup_object(NMDBusManager *self, const char *path) { NMDBusManagerPrivate *priv; gpointer ptr; - NMDBusObject * obj; + NMDBusObject *obj; g_return_val_if_fail(NM_IS_DBUS_MANAGER(self), NULL); g_return_val_if_fail(path, NULL); @@ -1085,7 +1085,7 @@ nm_dbus_manager_lookup_object(NMDBusManager *self, const char *path) void _nm_dbus_manager_obj_export(NMDBusObject *obj) { - NMDBusManager * self; + NMDBusManager *self; NMDBusManagerPrivate *priv; g_return_if_fail(NM_IS_DBUS_OBJECT(obj)); @@ -1108,7 +1108,7 @@ _nm_dbus_manager_obj_export(NMDBusObject *obj) void _nm_dbus_manager_obj_unexport(NMDBusObject *obj) { - NMDBusManager * self; + NMDBusManager *self; NMDBusManagerPrivate *priv; g_return_if_fail(NM_IS_DBUS_OBJECT(obj)); @@ -1135,9 +1135,9 @@ _nm_dbus_manager_obj_unexport(NMDBusObject *obj) void _nm_dbus_manager_obj_notify(NMDBusObject *obj, guint n_pspecs, const GParamSpec *const *pspecs) { - NMDBusManager * self; + NMDBusManager *self; NMDBusManagerPrivate *priv; - RegistrationData * reg_data; + RegistrationData *reg_data; guint i, p; nm_assert(NM_IS_DBUS_OBJECT(obj)); @@ -1167,7 +1167,7 @@ _nm_dbus_manager_obj_notify(NMDBusObject *obj, guint n_pspecs, const GParamSpec gboolean has_properties = FALSE; GVariantBuilder builder; GVariantBuilder invalidated_builder; - GVariant * args; + GVariant *args; if (!interface_info->parent.properties) continue; @@ -1177,7 +1177,7 @@ _nm_dbus_manager_obj_notify(NMDBusObject *obj, guint n_pspecs, const GParamSpec (const NMDBusPropertyInfoExtended *) interface_info->parent.properties[i]; for (p = 0; p < n_pspecs; p++) { - const GParamSpec *pspec = pspecs[p]; + const GParamSpec *pspec = pspecs[p]; gs_unref_variant GVariant *value = NULL; if (!nm_streq(property_info->property_name, pspec->name)) @@ -1211,12 +1211,12 @@ _nm_dbus_manager_obj_notify(NMDBusObject *obj, guint n_pspecs, const GParamSpec } void -_nm_dbus_manager_obj_emit_signal(NMDBusObject * obj, +_nm_dbus_manager_obj_emit_signal(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const GDBusSignalInfo * signal_info, - GVariant * args) + const GDBusSignalInfo *signal_info, + GVariant *args) { - NMDBusManager * self; + NMDBusManager *self; NMDBusManagerPrivate *priv; g_return_if_fail(NM_IS_DBUS_OBJECT(obj)); @@ -1244,9 +1244,9 @@ _nm_dbus_manager_obj_emit_signal(NMDBusObject * obj, /*****************************************************************************/ static GVariantBuilder * -_obj_collect_properties_per_interface(NMDBusObject * obj, +_obj_collect_properties_per_interface(NMDBusObject *obj, RegistrationData *reg_data, - GVariantBuilder * builder) + GVariantBuilder *builder) { const NMDBusInterfaceInfoExtended *interface_info = _reg_data_get_interface_info(reg_data); guint i; @@ -1286,19 +1286,19 @@ _obj_collect_properties_all(NMDBusObject *obj, GVariantBuilder *builder) } static void -dbus_vtable_objmgr_method_call(GDBusConnection * connection, - const char * sender, - const char * object_path, - const char * interface_name, - const char * method_name, - GVariant * parameters, +dbus_vtable_objmgr_method_call(GDBusConnection *connection, + const char *sender, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data) { - NMDBusManager * self = user_data; + NMDBusManager *self = user_data; NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE(self); GVariantBuilder array_builder; - NMDBusObject * obj; + NMDBusObject *obj; nm_assert(nm_streq0(object_path, OBJECT_MANAGER_SERVER_BASE_PATH)); @@ -1368,12 +1368,12 @@ nm_dbus_manager_get_dbus_connection(NMDBusManager *self) } void -nm_dbus_manager_start(NMDBusManager * self, +nm_dbus_manager_start(NMDBusManager *self, NMDBusManagerSetPropertyHandler set_property_handler, gpointer set_property_handler_data) { NMDBusManagerPrivate *priv; - NMDBusObject * obj; + NMDBusObject *obj; g_return_if_fail(NM_IS_DBUS_MANAGER(self)); @@ -1397,9 +1397,9 @@ nm_dbus_manager_start(NMDBusManager * self, gboolean nm_dbus_manager_acquire_bus(NMDBusManager *self, gboolean request_name) { - NMDBusManagerPrivate *priv; - gs_free_error GError *error = NULL; - gs_unref_variant GVariant *ret = NULL; + NMDBusManagerPrivate *priv; + gs_free_error GError *error = NULL; + gs_unref_variant GVariant *ret = NULL; guint32 result; guint registration_id; @@ -1515,10 +1515,10 @@ nm_dbus_manager_init(NMDBusManager *self) static void dispose(GObject *object) { - NMDBusManager * self = NM_DBUS_MANAGER(object); + NMDBusManager *self = NM_DBUS_MANAGER(object); NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE(self); - PrivateServer * s, *s_safe; - CallerInfo * caller_info; + PrivateServer *s, *s_safe; + CallerInfo *caller_info; /* All exported NMDBusObject instances keep the manager alive, so we don't * expect any remaining objects. */ @@ -1578,11 +1578,11 @@ nm_dbus_manager_class_init(NMDBusManagerClass *klass) static NMAuthSubject * _new_unix_process(GDBusMethodInvocation *context, - GDBusConnection * connection, - GDBusMessage * message) + GDBusConnection *connection, + GDBusMessage *message) { NMAuthSubject *self; - const char * dbus_sender = NULL; + const char *dbus_sender = NULL; gulong uid = 0; gulong pid = 0; gboolean success; diff --git a/src/core/nm-dbus-manager.h b/src/core/nm-dbus-manager.h index 06876af0..d7ca78d1 100644 --- a/src/core/nm-dbus-manager.h +++ b/src/core/nm-dbus-manager.h @@ -27,13 +27,13 @@ GType nm_dbus_manager_get_type(void); NMDBusManager *nm_dbus_manager_get(void); -typedef void (*NMDBusManagerSetPropertyHandler)(NMDBusObject * obj, +typedef void (*NMDBusManagerSetPropertyHandler)(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusPropertyInfoExtended * property_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * value, + const NMDBusPropertyInfoExtended *property_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *value, gpointer user_data); gboolean nm_dbus_manager_acquire_bus(NMDBusManager *self, gboolean request_name); @@ -42,7 +42,7 @@ GDBusConnection *nm_dbus_manager_get_dbus_connection(NMDBusManager *self); #define NM_MAIN_DBUS_CONNECTION_GET (nm_dbus_manager_get_dbus_connection(nm_dbus_manager_get())) -void nm_dbus_manager_start(NMDBusManager * self, +void nm_dbus_manager_start(NMDBusManager *self, NMDBusManagerSetPropertyHandler set_property_handler, gpointer set_property_handler_data); @@ -56,18 +56,18 @@ void _nm_dbus_manager_obj_export(NMDBusObject *obj); void _nm_dbus_manager_obj_unexport(NMDBusObject *obj); void _nm_dbus_manager_obj_notify(NMDBusObject *obj, guint n_pspecs, const GParamSpec *const *pspecs); -void _nm_dbus_manager_obj_emit_signal(NMDBusObject * obj, +void _nm_dbus_manager_obj_emit_signal(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const GDBusSignalInfo * signal_info, - GVariant * args); + const GDBusSignalInfo *signal_info, + GVariant *args); -gboolean nm_dbus_manager_get_caller_info(NMDBusManager * self, +gboolean nm_dbus_manager_get_caller_info(NMDBusManager *self, GDBusMethodInvocation *context, - const char ** out_sender, - gulong * out_uid, - gulong * out_pid); + const char **out_sender, + gulong *out_uid, + gulong *out_pid); -gboolean nm_dbus_manager_ensure_uid(NMDBusManager * self, +gboolean nm_dbus_manager_ensure_uid(NMDBusManager *self, GDBusMethodInvocation *context, gulong uid, GQuark error_domain, @@ -75,12 +75,12 @@ gboolean nm_dbus_manager_ensure_uid(NMDBusManager * self, gboolean nm_dbus_manager_get_unix_user(NMDBusManager *self, const char *sender, gulong *out_uid); -gboolean nm_dbus_manager_get_caller_info_from_message(NMDBusManager * self, +gboolean nm_dbus_manager_get_caller_info_from_message(NMDBusManager *self, GDBusConnection *connection, - GDBusMessage * message, - const char ** out_sender, - gulong * out_uid, - gulong * out_pid); + GDBusMessage *message, + const char **out_sender, + gulong *out_uid, + gulong *out_pid); void nm_dbus_manager_private_server_register(NMDBusManager *self, const char *path, const char *tag); @@ -88,6 +88,6 @@ nm_dbus_manager_private_server_register(NMDBusManager *self, const char *path, c NMAuthSubject *nm_dbus_manager_new_auth_subject_from_context(GDBusMethodInvocation *context); NMAuthSubject *nm_dbus_manager_new_auth_subject_from_message(GDBusConnection *connection, - GDBusMessage * message); + GDBusMessage *message); #endif /* __NM_DBUS_MANAGER_H__ */ diff --git a/src/core/nm-dbus-object.c b/src/core/nm-dbus-object.c index 95077626..335b7e8b 100644 --- a/src/core/nm-dbus-object.c +++ b/src/core/nm-dbus-object.c @@ -87,7 +87,7 @@ _create_export_path(NMDBusObjectClass *klass) const char * nm_dbus_object_export(gpointer /* (NMDBusObject *) */ self) { - NMDBusObject * self1 = self; + NMDBusObject *self1 = self; static guint64 id_counter = 0; g_return_val_if_fail(NM_IS_DBUS_OBJECT(self1), NULL); @@ -207,10 +207,10 @@ _nm_dbus_object_clear_and_unexport(NMDBusObject **location) /*****************************************************************************/ void -nm_dbus_object_emit_signal_variant(NMDBusObject * self, +nm_dbus_object_emit_signal_variant(NMDBusObject *self, const NMDBusInterfaceInfoExtended *interface_info, - const GDBusSignalInfo * signal_info, - GVariant * args) + const GDBusSignalInfo *signal_info, + GVariant *args) { if (!self->internal.path) { nm_g_variant_unref_floating(args); @@ -220,10 +220,10 @@ nm_dbus_object_emit_signal_variant(NMDBusObject * self, } void -nm_dbus_object_emit_signal(NMDBusObject * self, +nm_dbus_object_emit_signal(NMDBusObject *self, const NMDBusInterfaceInfoExtended *interface_info, - const GDBusSignalInfo * signal_info, - const char * format, + const GDBusSignalInfo *signal_info, + const char *format, ...) { va_list ap; diff --git a/src/core/nm-dbus-object.h b/src/core/nm-dbus-object.h index ae089dd3..df22bd92 100644 --- a/src/core/nm-dbus-object.h +++ b/src/core/nm-dbus-object.h @@ -59,7 +59,7 @@ typedef struct { /* NMDBusObject and NMDBusManager cooperate strongly. Hence, there is an * internal data structure attached to the NMDBusObject accessible to both of them. */ struct _NMDBusObjectInternal { - char * path; + char *path; NMDBusManager *bus_manager; CList objects_lst; CList registration_lst_head; @@ -159,15 +159,15 @@ gboolean _nm_dbus_object_clear_and_unexport(NMDBusObject **location); #define nm_dbus_object_clear_and_unexport(location) \ _nm_dbus_object_clear_and_unexport(NM_CAST_PPTR(NMDBusObject, (location))) -void nm_dbus_object_emit_signal_variant(NMDBusObject * self, +void nm_dbus_object_emit_signal_variant(NMDBusObject *self, const NMDBusInterfaceInfoExtended *interface_info, - const GDBusSignalInfo * signal_info, - GVariant * args); + const GDBusSignalInfo *signal_info, + GVariant *args); -void nm_dbus_object_emit_signal(NMDBusObject * self, +void nm_dbus_object_emit_signal(NMDBusObject *self, const NMDBusInterfaceInfoExtended *interface_info, - const GDBusSignalInfo * signal_info, - const char * format, + const GDBusSignalInfo *signal_info, + const char *format, ...); #endif /* __NM_DBUS_OBJECT_H__ */ diff --git a/src/core/nm-dbus-utils.c b/src/core/nm-dbus-utils.c index 7f7b9fb9..096b647b 100644 --- a/src/core/nm-dbus-utils.c +++ b/src/core/nm-dbus-utils.c @@ -13,8 +13,8 @@ GDBusPropertyInfo * nm_dbus_utils_interface_info_lookup_property(const GDBusInterfaceInfo *interface_info, - const char * property_name, - guint * property_idx) + const char *property_name, + guint *property_idx) { guint i; @@ -39,7 +39,7 @@ nm_dbus_utils_interface_info_lookup_property(const GDBusInterfaceInfo *interface GDBusMethodInfo * nm_dbus_utils_interface_info_lookup_method(const GDBusInterfaceInfo *interface_info, - const char * method_name) + const char *method_name) { guint i; @@ -64,8 +64,8 @@ GVariant * nm_dbus_utils_get_property(GObject *obj, const char *signature, const char *property_name) { nm_auto_unset_gvalue GValue value = G_VALUE_INIT; - GParamSpec * pspec; - GVariant * variant; + GParamSpec *pspec; + GVariant *variant; nm_assert(G_IS_OBJECT(obj)); nm_assert(g_variant_type_string_is_valid(signature)); @@ -108,12 +108,12 @@ nm_dbus_utils_g_value_set_object_path_still_exported(GValue *value, gpointer obj void nm_dbus_utils_g_value_set_object_path_from_hash( - GValue * value, + GValue *value, GHashTable *hash /* has keys of NMDBusObject type. */, gboolean expect_all_exported) { - NMDBusObject * obj; - char ** strv; + NMDBusObject *obj; + char **strv; guint i, n; GHashTableIter iter; @@ -151,7 +151,7 @@ nm_dbus_utils_get_paths_for_clist(const CList *lst_head, { const CList *iter; const char **strv; - const char * path; + const char *path; gsize i, n; nm_assert(lst_head); @@ -243,7 +243,7 @@ void nm_dbus_track_obj_path_set(NMDBusTrackObjPath *track, gpointer obj, gboolean visible) { gs_unref_object NMDBusObject *old_obj = NULL; - const char * old_path; + const char *old_path; nm_assert(track); nm_assert(G_IS_OBJECT(track->_notify_target)); diff --git a/src/core/nm-dbus-utils.h b/src/core/nm-dbus-utils.h index 6585d43d..54b50634 100644 --- a/src/core/nm-dbus-utils.h +++ b/src/core/nm-dbus-utils.h @@ -13,7 +13,7 @@ struct _NMDBusMethodInfoExtended; struct _NMDBusPropertyInfoExtendedBase { GDBusPropertyInfo _parent; - const char * property_name; + const char *property_name; }; struct _NMDBusPropertyInfoExtendedReadWritable { @@ -37,7 +37,7 @@ typedef struct { * are accessible directly in the parent struct. */ struct { GDBusPropertyInfo parent; - const char * property_name; + const char *property_name; }; }; } NMDBusPropertyInfoExtended; @@ -81,13 +81,13 @@ G_STATIC_ASSERT(G_STRUCT_OFFSET(NMDBusPropertyInfoExtended, property_name) typedef struct _NMDBusMethodInfoExtended { GDBusMethodInfo parent; - void (*handle)(NMDBusObject * obj, + void (*handle)(NMDBusObject *obj, const struct _NMDBusInterfaceInfoExtended *interface_info, - const struct _NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters); + const struct _NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters); bool allow_during_shutdown; } NMDBusMethodInfoExtended; @@ -111,12 +111,12 @@ typedef struct _NMDBusInterfaceInfoExtended { GDBusPropertyInfo * nm_dbus_utils_interface_info_lookup_property(const GDBusInterfaceInfo *interface_info, - const char * property_name, - guint * property_idx); + const char *property_name, + guint *property_idx); GDBusMethodInfo * nm_dbus_utils_interface_info_lookup_method(const GDBusInterfaceInfo *interface_info, - const char * method_name); + const char *method_name); GVariant * nm_dbus_utils_get_property(GObject *obj, const char *signature, const char *property_name); @@ -134,7 +134,7 @@ void nm_dbus_utils_g_value_set_object_path(GValue *value, gpointer object); void nm_dbus_utils_g_value_set_object_path_still_exported(GValue *value, gpointer object); -void nm_dbus_utils_g_value_set_object_path_from_hash(GValue * value, +void nm_dbus_utils_g_value_set_object_path_from_hash(GValue *value, GHashTable *hash, gboolean expect_all_exported); @@ -145,7 +145,7 @@ typedef struct { gpointer const obj; gpointer _obj; }; - GObject * _notify_target; + GObject *_notify_target; const GParamSpec *_notify_pspec; gulong _notify_signal_id; union { diff --git a/src/core/nm-dcb.c b/src/core/nm-dcb.c index f048d999..2b90cfa5 100644 --- a/src/core/nm-dcb.c +++ b/src/core/nm-dcb.c @@ -18,12 +18,12 @@ do_helper(const char *iface, guint which, DcbFunc run_func, gpointer user_data, - GError ** error, + GError **error, const char *fmt, ...) { gs_free const char **split = NULL; - gs_free char * cmdline = NULL; + gs_free char *cmdline = NULL; gs_free const char **argv = NULL; gsize i; gsize u; @@ -70,7 +70,7 @@ _dcb_enable(const char *iface, gboolean enable, DcbFunc run_func, gpointer user_data, - GError ** error) + GError **error) { if (enable) return do_helper(iface, DCBTOOL, run_func, user_data, error, "dcb on"); @@ -114,11 +114,11 @@ _dcb_enable(const char *iface, G_STMT_END gboolean -_dcb_setup(const char * iface, +_dcb_setup(const char *iface, NMSettingDcb *s_dcb, DcbFunc run_func, gpointer user_data, - GError ** error) + GError **error) { NMSettingDcbFlags flags; guint i; @@ -246,11 +246,11 @@ _dcb_cleanup(const char *iface, DcbFunc run_func, gpointer user_data, GError **e } gboolean -_fcoe_setup(const char * iface, +_fcoe_setup(const char *iface, NMSettingDcb *s_dcb, DcbFunc run_func, gpointer user_data, - GError ** error) + GError **error) { NMSettingDcbFlags flags; @@ -283,8 +283,8 @@ run_helper(char **argv, guint which, gpointer user_data, GError **error) const char *helper_path; int exit_status = 0; gboolean success; - char * errmsg = NULL, *outmsg = NULL; - char * cmdline; + char *errmsg = NULL, *outmsg = NULL; + char *cmdline; helper_path = nm_utils_find_helper((which == DCBTOOL) ? "dcbtool" : "fcoeadm", NULL, error); if (!helper_path) diff --git a/src/core/nm-dcb.h b/src/core/nm-dcb.h index 7cb5e7ef..78c2590d 100644 --- a/src/core/nm-dcb.h +++ b/src/core/nm-dcb.h @@ -22,7 +22,7 @@ gboolean do_helper(const char *iface, guint which, DcbFunc run_func, gpointer user_data, - GError ** error, + GError **error, const char *fmt, ...) G_GNUC_PRINTF(6, 7); @@ -30,21 +30,21 @@ gboolean _dcb_enable(const char *iface, gboolean enable, DcbFunc run_func, gpointer user_data, - GError ** error); + GError **error); -gboolean _dcb_setup(const char * iface, +gboolean _dcb_setup(const char *iface, NMSettingDcb *s_dcb, DcbFunc run_func, gpointer user_data, - GError ** error); + GError **error); gboolean _dcb_cleanup(const char *iface, DcbFunc run_func, gpointer user_data, GError **error); -gboolean _fcoe_setup(const char * iface, +gboolean _fcoe_setup(const char *iface, NMSettingDcb *s_dcb, DcbFunc run_func, gpointer user_data, - GError ** error); + GError **error); gboolean _fcoe_cleanup(const char *iface, DcbFunc run_func, gpointer user_data, GError **error); diff --git a/src/core/nm-dhcp-config.c b/src/core/nm-dhcp-config.c index 8a029119..b32c9b70 100644 --- a/src/core/nm-dhcp-config.c +++ b/src/core/nm-dhcp-config.c @@ -8,9 +8,11 @@ #include "nm-dhcp-config.h" #include "nm-dbus-interface.h" +#include "NetworkManagerUtils.h" #include "nm-utils.h" #include "nm-dbus-object.h" #include "nm-core-utils.h" +#include "nm-l3-config-data.h" /*****************************************************************************/ @@ -46,10 +48,11 @@ static GType nm_dhcp6_config_get_type(void); /*****************************************************************************/ -NM_GOBJECT_PROPERTIES_DEFINE(NMDhcpConfig, PROP_OPTIONS, ); +NM_GOBJECT_PROPERTIES_DEFINE(NMDhcpConfig, PROP_L3CD, PROP_OPTIONS, ); typedef struct { - GVariant *options; + const NML3ConfigData *l3cd; + GVariant *options; } NMDhcpConfigPrivate; struct _NMDhcpConfig { @@ -76,18 +79,49 @@ nm_dhcp_config_get_addr_family(NMDhcpConfig *self) /*****************************************************************************/ +static GVariant * +_l3cd_to_options(const NML3ConfigData *l3cd, int addr_family) +{ + GVariant *options; + + options = NULL; + if (l3cd) { + NMDhcpLease *lease; + + lease = nm_l3_config_data_get_dhcp_lease(l3cd, addr_family); + if (lease) + options = nm_strdict_to_variant_asv(nm_dhcp_lease_get_options(lease)); + } + if (!options) + options = nm_g_variant_singleton_aLsvI(); + return g_variant_ref_sink(options); +} + void -nm_dhcp_config_set_options(NMDhcpConfig *self, GHashTable *options) +nm_dhcp_config_set_lease(NMDhcpConfig *self, const NML3ConfigData *l3cd) { - NMDhcpConfigPrivate *priv; + nm_auto_unref_l3cd const NML3ConfigData *l3cd_old = NULL; + gs_unref_variant GVariant *options2 = NULL; + NMDhcpConfigPrivate *priv; g_return_if_fail(NM_IS_DHCP_CONFIG(self)); - g_return_if_fail(options); priv = NM_DHCP_CONFIG_GET_PRIVATE(self); - nm_g_variant_unref(priv->options); - priv->options = g_variant_ref_sink(nm_strdict_to_variant_asv(options)); + if (priv->l3cd == l3cd) + return; + + l3cd_old = g_steal_pointer(&priv->l3cd); + if (l3cd) + priv->l3cd = nm_l3_config_data_ref_and_seal(l3cd); + + options2 = _l3cd_to_options(priv->l3cd, nm_dhcp_config_get_addr_family(self)); + + if (g_variant_equal(priv->options, options2)) + return; + + NM_SWAP(&priv->options, &options2); + _notify(self, PROP_OPTIONS); } @@ -95,19 +129,22 @@ const char * nm_dhcp_config_get_option(NMDhcpConfig *self, const char *key) { NMDhcpConfigPrivate *priv; - const char * value; + NMDhcpLease *lease; g_return_val_if_fail(NM_IS_DHCP_CONFIG(self), NULL); g_return_val_if_fail(key, NULL); priv = NM_DHCP_CONFIG_GET_PRIVATE(self); - if (priv->options && g_variant_lookup(priv->options, key, "&s", &value)) - return value; - else + if (!priv->l3cd) return NULL; + + lease = nm_l3_config_data_get_dhcp_lease(priv->l3cd, nm_dhcp_config_get_addr_family(self)); + return nm_dhcp_lease_lookup_option(lease, key); } +/*****************************************************************************/ + GVariant * nm_dhcp_config_get_options(NMDhcpConfig *self) { @@ -125,7 +162,25 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) switch (prop_id) { case PROP_OPTIONS: - g_value_set_variant(value, priv->options ?: nm_g_variant_singleton_aLsvI()); + g_value_set_variant(value, priv->options); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +static void +set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +{ + NMDhcpConfig *self = NM_DHCP_CONFIG(object); + NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE(self); + + switch (prop_id) { + case PROP_L3CD: + /* construct-only */ + priv->l3cd = nm_l3_config_data_ref_and_seal(g_value_get_pointer(value)); + priv->options = _l3cd_to_options(priv->l3cd, nm_dhcp_config_get_addr_family(self)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); @@ -140,11 +195,12 @@ nm_dhcp_config_init(NMDhcpConfig *self) {} NMDhcpConfig * -nm_dhcp_config_new(int addr_family) +nm_dhcp_config_new(int addr_family, const NML3ConfigData *l3cd) { - nm_assert_addr_family(addr_family); - - return g_object_new(addr_family != AF_INET ? NM_TYPE_DHCP6_CONFIG : NM_TYPE_DHCP4_CONFIG, NULL); + return g_object_new(NM_IS_IPv4(addr_family) ? NM_TYPE_DHCP4_CONFIG : NM_TYPE_DHCP6_CONFIG, + NM_DHCP_CONFIG_L3CD, + l3cd, + NULL); } static void @@ -152,7 +208,9 @@ finalize(GObject *object) { NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE(object); - nm_g_variant_unref(priv->options); + g_variant_unref(priv->options); + + nm_l3_config_data_unref(priv->l3cd); G_OBJECT_CLASS(nm_dhcp_config_parent_class)->finalize(object); } @@ -163,8 +221,15 @@ nm_dhcp_config_class_init(NMDhcpConfigClass *config_class) GObjectClass *object_class = G_OBJECT_CLASS(config_class); object_class->get_property = get_property; + object_class->set_property = set_property; object_class->finalize = finalize; + obj_properties[PROP_L3CD] = + g_param_spec_pointer(NM_DHCP_CONFIG_L3CD, + "", + "", + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + obj_properties[PROP_OPTIONS] = g_param_spec_variant(NM_DHCP_CONFIG_OPTIONS, "", "", diff --git a/src/core/nm-dhcp-config.h b/src/core/nm-dhcp-config.h index 9e68f2fb..cae0e11a 100644 --- a/src/core/nm-dhcp-config.h +++ b/src/core/nm-dhcp-config.h @@ -18,16 +18,17 @@ (G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_DHCP_CONFIG, NMDhcpConfigClass)) #define NM_DHCP_CONFIG_OPTIONS "options" +#define NM_DHCP_CONFIG_L3CD "l3cd" typedef struct _NMDhcpConfigClass NMDhcpConfigClass; GType nm_dhcp_config_get_type(void); -NMDhcpConfig *nm_dhcp_config_new(int addr_family); +NMDhcpConfig *nm_dhcp_config_new(int addr_family, const NML3ConfigData *l3cd); int nm_dhcp_config_get_addr_family(NMDhcpConfig *self); -void nm_dhcp_config_set_options(NMDhcpConfig *self, GHashTable *options); +void nm_dhcp_config_set_lease(NMDhcpConfig *self, const NML3ConfigData *l3cd); const char *nm_dhcp_config_get_option(NMDhcpConfig *self, const char *option); diff --git a/src/core/nm-dispatcher.c b/src/core/nm-dispatcher.c index b7719786..b6ff25ca 100644 --- a/src/core/nm-dispatcher.c +++ b/src/core/nm-dispatcher.c @@ -15,9 +15,7 @@ #include "nm-act-request.h" #include "devices/nm-device.h" #include "nm-dhcp-config.h" -#include "nm-proxy-config.h" -#include "nm-ip4-config.h" -#include "nm-ip6-config.h" +#include "nm-l3-config-data.h" #include "nm-manager.h" #include "settings/nm-settings-connection.h" #include "libnm-platform/nm-platform.h" @@ -56,8 +54,8 @@ struct NMDispatcherCallId { NMDispatcherFunc callback; gpointer user_data; - const char * log_ifname; - const char * log_con_uuid; + const char *log_ifname; + const char *log_con_uuid; NMDispatcherAction action; guint idle_id; guint32 request_id; @@ -76,7 +74,7 @@ struct NMDispatcherCallId { * Finally, cleanup the global structures. */ static struct { GDBusConnection *dbus_connection; - GHashTable * requests; + GHashTable *requests; guint request_id_counter; } gl; @@ -87,13 +85,13 @@ dispatcher_call_id_new(guint32 request_id, NMDispatcherAction action, NMDispatcherFunc callback, gpointer user_data, - const char * log_ifname, - const char * log_con_uuid) + const char *log_ifname, + const char *log_con_uuid) { NMDispatcherCallId *call_id; gsize l_log_ifname; gsize l_log_con_uuid; - char * extra_strings; + char *extra_strings; l_log_ifname = log_ifname ? (strlen(log_ifname) + 1) : 0u; l_log_con_uuid = log_con_uuid ? (strlen(log_con_uuid) + 1) : 0u; @@ -148,50 +146,47 @@ _init_dispatcher(void) /*****************************************************************************/ static void -dump_proxy_to_props(NMProxyConfig *proxy, GVariantBuilder *builder) +dump_proxy_to_props(const NML3ConfigData *l3cd, GVariantBuilder *builder) { - const char *pac_url = NULL, *pac_script = NULL; + const char *s; - if (nm_proxy_config_get_method(proxy) == NM_PROXY_CONFIG_METHOD_NONE) + if (nm_l3_config_data_get_proxy_method(l3cd) != NM_PROXY_CONFIG_METHOD_AUTO) return; - pac_url = nm_proxy_config_get_pac_url(proxy); - if (pac_url) { - g_variant_builder_add(builder, "{sv}", "pac-url", g_variant_new_string(pac_url)); - } + s = nm_l3_config_data_get_proxy_pac_url(l3cd); + if (s) + g_variant_builder_add(builder, "{sv}", "pac-url", g_variant_new_string(s)); - pac_script = nm_proxy_config_get_pac_script(proxy); - if (pac_script) { - g_variant_builder_add(builder, "{sv}", "pac-script", g_variant_new_string(pac_script)); - } + s = nm_l3_config_data_get_proxy_pac_script(l3cd); + if (s) + g_variant_builder_add(builder, "{sv}", "pac-script", g_variant_new_string(s)); } static void -dump_ip_to_props(NMIPConfig *ip, GVariantBuilder *builder) +dump_ip_to_props(const NML3ConfigData *l3cd, int addr_family, GVariantBuilder *builder) { - const int addr_family = nm_ip_config_get_addr_family(ip); - const int IS_IPv4 = NM_IS_IPv4(addr_family); - const NMPObject *obj; - GVariantBuilder int_builder; - NMDedupMultiIter ipconf_iter; - GVariant * var1; - GVariant * var2; - guint n; - guint i; - const NMPObject *default_route; + const int IS_IPv4 = NM_IS_IPv4(addr_family); + const NMPObject *obj; + GVariantBuilder int_builder; + NMDedupMultiIter ipconf_iter; + GVariant *var1; + GVariant *var2; + guint n; + guint i; + const NMPObject *default_route; + const char *const *strarr; + const in_addr_t *ip4arr; + gconstpointer iparr; if (IS_IPv4) g_variant_builder_init(&int_builder, G_VARIANT_TYPE("aau")); else g_variant_builder_init(&int_builder, G_VARIANT_TYPE("a(ayuay)")); - default_route = nm_ip_config_best_default_route_get(ip); - if (IS_IPv4) - nm_ip_config_iter_ip4_address_init(&ipconf_iter, NM_IP4_CONFIG(ip)); - else - nm_ip_config_iter_ip6_address_init(&ipconf_iter, NM_IP6_CONFIG(ip)); - while (nm_platform_dedup_multi_iter_next_obj(&ipconf_iter, - &obj, - NMP_OBJECT_TYPE_IP_ADDRESS(IS_IPv4))) { + default_route = nm_l3_config_data_get_best_default_route(l3cd, addr_family); + nm_l3_config_data_iter_obj_for_each (&ipconf_iter, + l3cd, + &obj, + NMP_OBJECT_TYPE_IP_ADDRESS(IS_IPv4)) { const NMPlatformIPXAddress *addr = NMP_OBJECT_CAST_IPX_ADDRESS(obj); if (IS_IPv4) { @@ -225,30 +220,28 @@ dump_ip_to_props(NMIPConfig *ip, GVariantBuilder *builder) g_variant_builder_init(&int_builder, G_VARIANT_TYPE("au")); else g_variant_builder_init(&int_builder, G_VARIANT_TYPE("aay")); - n = nm_ip_config_get_num_nameservers(ip); + iparr = nm_l3_config_data_get_nameservers(l3cd, addr_family, &n); for (i = 0; i < n; i++) { - if (IS_IPv4) { - g_variant_builder_add(&int_builder, - "u", - nm_ip4_config_get_nameserver(NM_IP4_CONFIG(ip), i)); - } else { - var1 = nm_g_variant_new_ay_in6addr(nm_ip6_config_get_nameserver(NM_IP6_CONFIG(ip), i)); + if (IS_IPv4) + g_variant_builder_add(&int_builder, "u", ((const in_addr_t *) iparr)[i]); + else { + var1 = nm_g_variant_new_ay_in6addr(&(((const struct in6_addr *) iparr)[i])); g_variant_builder_add(&int_builder, "@ay", var1); } } g_variant_builder_add(builder, "{sv}", "nameservers", g_variant_builder_end(&int_builder)); g_variant_builder_init(&int_builder, G_VARIANT_TYPE("as")); - n = nm_ip_config_get_num_domains(ip); + strarr = nm_l3_config_data_get_domains(l3cd, addr_family, &n); for (i = 0; i < n; i++) - g_variant_builder_add(&int_builder, "s", nm_ip_config_get_domain(ip, i)); + g_variant_builder_add(&int_builder, "s", strarr[i]); g_variant_builder_add(builder, "{sv}", "domains", g_variant_builder_end(&int_builder)); if (IS_IPv4) { g_variant_builder_init(&int_builder, G_VARIANT_TYPE("au")); - n = nm_ip4_config_get_num_wins(NM_IP4_CONFIG(ip)); + ip4arr = nm_l3_config_data_get_wins(l3cd, &n); for (i = 0; i < n; i++) - g_variant_builder_add(&int_builder, "u", nm_ip4_config_get_wins(NM_IP4_CONFIG(ip), i)); + g_variant_builder_add(&int_builder, "u", ip4arr[i]); g_variant_builder_add(builder, "{sv}", "wins-servers", g_variant_builder_end(&int_builder)); } @@ -256,13 +249,10 @@ dump_ip_to_props(NMIPConfig *ip, GVariantBuilder *builder) g_variant_builder_init(&int_builder, G_VARIANT_TYPE("aau")); else g_variant_builder_init(&int_builder, G_VARIANT_TYPE("a(ayuayu)")); - if (IS_IPv4) - nm_ip_config_iter_ip4_route_init(&ipconf_iter, NM_IP4_CONFIG(ip)); - else - nm_ip_config_iter_ip6_route_init(&ipconf_iter, NM_IP6_CONFIG(ip)); - while (nm_platform_dedup_multi_iter_next_obj(&ipconf_iter, - &obj, - NMP_OBJECT_TYPE_IP_ROUTE(IS_IPv4))) { + nm_l3_config_data_iter_obj_for_each (&ipconf_iter, + l3cd, + &obj, + NMP_OBJECT_TYPE_IP_ROUTE(IS_IPv4)) { const NMPlatformIPXRoute *route = NMP_OBJECT_CAST_IPX_ROUTE(obj); if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT(route)) @@ -291,18 +281,16 @@ dump_ip_to_props(NMIPConfig *ip, GVariantBuilder *builder) } static void -fill_device_props(NMDevice * device, +fill_device_props(NMDevice *device, GVariantBuilder *dev_builder, GVariantBuilder *proxy_builder, GVariantBuilder *ip4_builder, GVariantBuilder *ip6_builder, - GVariant ** dhcp4_props, - GVariant ** dhcp6_props) + GVariant **dhcp4_props, + GVariant **dhcp6_props) { - NMProxyConfig *proxy_config; - NMIP4Config * ip4_config; - NMIP6Config * ip6_config; - NMDhcpConfig * dhcp_config; + const NML3ConfigData *l3cd; + NMDhcpConfig *dhcp_config; /* If the action is for a VPN, send the VPN's IP interface instead of the device's */ g_variant_builder_add(dev_builder, @@ -329,17 +317,12 @@ fill_device_props(NMDevice * device, g_variant_new_object_path(nm_dbus_object_get_path(NM_DBUS_OBJECT(device)))); } - proxy_config = nm_device_get_proxy_config(device); - if (proxy_config) - dump_proxy_to_props(proxy_config, proxy_builder); - - ip4_config = nm_device_get_ip4_config(device); - if (ip4_config) - dump_ip_to_props(NM_IP_CONFIG(ip4_config), ip4_builder); - - ip6_config = nm_device_get_ip6_config(device); - if (ip6_config) - dump_ip_to_props(NM_IP_CONFIG(ip6_config), ip6_builder); + l3cd = nm_device_get_l3cd(device, TRUE); + if (l3cd) { + dump_ip_to_props(l3cd, AF_INET, ip4_builder); + dump_ip_to_props(l3cd, AF_INET6, ip6_builder); + dump_proxy_to_props(l3cd, proxy_builder); + } dhcp_config = nm_device_get_dhcp_config(device, AF_INET); if (dhcp_config) @@ -351,19 +334,16 @@ fill_device_props(NMDevice * device, } static void -fill_vpn_props(NMProxyConfig * proxy_config, - NMIP4Config * ip4_config, - NMIP6Config * ip6_config, - GVariantBuilder *proxy_builder, - GVariantBuilder *ip4_builder, - GVariantBuilder *ip6_builder) +fill_vpn_props(const NML3ConfigData *l3cd, + GVariantBuilder *proxy_builder, + GVariantBuilder *ip4_builder, + GVariantBuilder *ip6_builder) { - if (proxy_config) - dump_proxy_to_props(proxy_config, proxy_builder); - if (ip4_config) - dump_ip_to_props(NM_IP_CONFIG(ip4_config), ip4_builder); - if (ip6_config) - dump_ip_to_props(NM_IP_CONFIG(ip6_config), ip6_builder); + if (l3cd) { + dump_ip_to_props(l3cd, AF_INET, ip4_builder); + dump_ip_to_props(l3cd, AF_INET6, ip6_builder); + dump_proxy_to_props(l3cd, proxy_builder); + } } static const char * @@ -388,10 +368,10 @@ static void dispatcher_results_process(guint32 request_id, const char *log_ifname, const char *log_con_uuid, - GVariant * v_results) + GVariant *v_results) { nm_auto_free_variant_iter GVariantIter *results = NULL; - const char * script, *err; + const char *script, *err; guint32 result; g_variant_get(v_results, "(a(sus))", &results); @@ -419,9 +399,9 @@ dispatcher_results_process(guint32 request_id, static void dispatcher_done_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - gs_unref_variant GVariant *ret = NULL; - gs_free_error GError *error = NULL; - NMDispatcherCallId * call_id = user_data; + gs_unref_variant GVariant *ret = NULL; + gs_free_error GError *error = NULL; + NMDispatcherCallId *call_id = user_data; nm_assert((gpointer) source == gl.dbus_connection); @@ -473,36 +453,34 @@ action_to_string(NMDispatcherAction action) static gboolean _dispatcher_call(NMDispatcherAction action, gboolean blocking, - NMDevice * device, + NMDevice *device, NMSettingsConnection *settings_connection, - NMConnection * applied_connection, + NMConnection *applied_connection, gboolean activation_type_external, NMConnectivityState connectivity_state, - const char * vpn_iface, - NMProxyConfig * vpn_proxy_config, - NMIP4Config * vpn_ip4_config, - NMIP6Config * vpn_ip6_config, + const char *vpn_iface, + const NML3ConfigData *l3cd, NMDispatcherFunc callback, gpointer user_data, - NMDispatcherCallId ** out_call_id) + NMDispatcherCallId **out_call_id) { - GVariant * connection_dict; - GVariantBuilder connection_props; - GVariantBuilder device_props; - GVariantBuilder device_proxy_props; - GVariantBuilder device_ip4_props; - GVariantBuilder device_ip6_props; + GVariant *connection_dict; + GVariantBuilder connection_props; + GVariantBuilder device_props; + GVariantBuilder device_proxy_props; + GVariantBuilder device_ip4_props; + GVariantBuilder device_ip6_props; gs_unref_variant GVariant *parameters_floating = NULL; gs_unref_variant GVariant *device_dhcp4_props = NULL; gs_unref_variant GVariant *device_dhcp6_props = NULL; GVariantBuilder vpn_proxy_props; GVariantBuilder vpn_ip4_props; GVariantBuilder vpn_ip6_props; - NMDispatcherCallId * call_id; + NMDispatcherCallId *call_id; guint request_id; - const char * connectivity_state_string = "UNKNOWN"; - const char * log_ifname; - const char * log_con_uuid; + const char *connectivity_state_string = "UNKNOWN"; + const char *log_ifname; + const char *log_con_uuid; g_return_val_if_fail(!blocking || (!callback && !user_data), FALSE); @@ -593,13 +571,8 @@ _dispatcher_call(NMDispatcherAction action, &device_ip6_props, &device_dhcp4_props, &device_dhcp6_props); - if (vpn_ip4_config || vpn_ip6_config) { - fill_vpn_props(vpn_proxy_config, - vpn_ip4_config, - vpn_ip6_config, - &vpn_proxy_props, - &vpn_ip4_props, - &vpn_ip6_props); + if (l3cd) { + fill_vpn_props(l3cd, &vpn_proxy_props, &vpn_ip4_props, &vpn_ip6_props); } } @@ -625,8 +598,8 @@ _dispatcher_call(NMDispatcherAction action, /* Send the action to the dispatcher */ if (blocking) { - gs_unref_variant GVariant *ret = NULL; - gs_free_error GError *error = NULL; + gs_unref_variant GVariant *ret = NULL; + gs_free_error GError *error = NULL; ret = g_dbus_connection_call_sync(gl.dbus_connection, NM_DISPATCHER_DBUS_SERVICE, @@ -693,8 +666,6 @@ nm_dispatcher_call_hostname(NMDispatcherFunc callback, NM_CONNECTIVITY_UNKNOWN, NULL, NULL, - NULL, - NULL, callback, user_data, out_call_id); @@ -718,8 +689,8 @@ nm_dispatcher_call_hostname(NMDispatcherFunc callback, */ gboolean nm_dispatcher_call_device(NMDispatcherAction action, - NMDevice * device, - NMActRequest * act_request, + NMDevice *device, + NMActRequest *act_request, NMDispatcherFunc callback, gpointer user_data, NMDispatcherCallId **out_call_id) @@ -744,8 +715,6 @@ nm_dispatcher_call_device(NMDispatcherAction action, NM_CONNECTIVITY_UNKNOWN, NULL, NULL, - NULL, - NULL, callback, user_data, out_call_id); @@ -765,8 +734,8 @@ nm_dispatcher_call_device(NMDispatcherAction action, */ gboolean nm_dispatcher_call_device_sync(NMDispatcherAction action, - NMDevice * device, - NMActRequest * act_request) + NMDevice *device, + NMActRequest *act_request) { nm_assert(NM_IS_DEVICE(device)); if (!act_request) { @@ -790,8 +759,6 @@ nm_dispatcher_call_device_sync(NMDispatcherAction action, NULL, NULL, NULL, - NULL, - NULL, NULL); } @@ -802,9 +769,7 @@ nm_dispatcher_call_device_sync(NMDispatcherAction action, * @applied_connection: the currently applied connection * @parent_device: the parent #NMDevice of the VPN connection * @vpn_iface: the IP interface of the VPN tunnel, if any - * @vpn_proxy_config: the #NMProxyConfig of the VPN connection - * @vpn_ip4_config: the #NMIP4Config of the VPN connection - * @vpn_ip6_config: the #NMIP6Config of the VPN connection + * @vpn_l3cd: the #NML3ConfigData of the VPN connection * @callback: a caller-supplied callback to execute when done * @user_data: caller-supplied pointer passed to @callback * @out_call_id: on success, a call identifier which can be passed to @@ -818,15 +783,13 @@ nm_dispatcher_call_device_sync(NMDispatcherAction action, gboolean nm_dispatcher_call_vpn(NMDispatcherAction action, NMSettingsConnection *settings_connection, - NMConnection * applied_connection, - NMDevice * parent_device, - const char * vpn_iface, - NMProxyConfig * vpn_proxy_config, - NMIP4Config * vpn_ip4_config, - NMIP6Config * vpn_ip6_config, + NMConnection *applied_connection, + NMDevice *parent_device, + const char *vpn_iface, + const NML3ConfigData *l3cd, NMDispatcherFunc callback, gpointer user_data, - NMDispatcherCallId ** out_call_id) + NMDispatcherCallId **out_call_id) { return _dispatcher_call(action, FALSE, @@ -836,9 +799,7 @@ nm_dispatcher_call_vpn(NMDispatcherAction action, FALSE, NM_CONNECTIVITY_UNKNOWN, vpn_iface, - vpn_proxy_config, - vpn_ip4_config, - vpn_ip6_config, + l3cd, callback, user_data, out_call_id); @@ -851,9 +812,7 @@ nm_dispatcher_call_vpn(NMDispatcherAction action, * @applied_connection: the currently applied connection * @parent_device: the parent #NMDevice of the VPN connection * @vpn_iface: the IP interface of the VPN tunnel, if any - * @vpn_proxy_config: the #NMProxyConfig of the VPN connection - * @vpn_ip4_config: the #NMIP4Config of the VPN connection - * @vpn_ip6_config: the #NMIP6Config of the VPN connection + * @vpn_l3cd: the #NML3ConfigData of the VPN connection * * This method always invokes the dispatcher action synchronously and it may * take a long time to return. @@ -863,12 +822,10 @@ nm_dispatcher_call_vpn(NMDispatcherAction action, gboolean nm_dispatcher_call_vpn_sync(NMDispatcherAction action, NMSettingsConnection *settings_connection, - NMConnection * applied_connection, - NMDevice * parent_device, - const char * vpn_iface, - NMProxyConfig * vpn_proxy_config, - NMIP4Config * vpn_ip4_config, - NMIP6Config * vpn_ip6_config) + NMConnection *applied_connection, + NMDevice *parent_device, + const char *vpn_iface, + const NML3ConfigData *l3cd) { return _dispatcher_call(action, TRUE, @@ -878,9 +835,7 @@ nm_dispatcher_call_vpn_sync(NMDispatcherAction action, FALSE, NM_CONNECTIVITY_UNKNOWN, vpn_iface, - vpn_proxy_config, - vpn_ip4_config, - vpn_ip6_config, + l3cd, NULL, NULL, NULL); @@ -913,8 +868,6 @@ nm_dispatcher_call_connectivity(NMConnectivityState connectivity_state, connectivity_state, NULL, NULL, - NULL, - NULL, callback, user_data, out_call_id); diff --git a/src/core/nm-dispatcher.h b/src/core/nm-dispatcher.h index 8e4f01cb..73e0599a 100644 --- a/src/core/nm-dispatcher.h +++ b/src/core/nm-dispatcher.h @@ -36,36 +36,32 @@ gboolean nm_dispatcher_call_hostname(NMDispatcherFunc callback, NMDispatcherCallId **out_call_id); gboolean nm_dispatcher_call_device(NMDispatcherAction action, - NMDevice * device, - NMActRequest * act_request, + NMDevice *device, + NMActRequest *act_request, NMDispatcherFunc callback, gpointer user_data, NMDispatcherCallId **out_call_id); gboolean nm_dispatcher_call_device_sync(NMDispatcherAction action, - NMDevice * device, - NMActRequest * act_request); + NMDevice *device, + NMActRequest *act_request); gboolean nm_dispatcher_call_vpn(NMDispatcherAction action, NMSettingsConnection *settings_connection, - NMConnection * applied_connection, - NMDevice * parent_device, - const char * vpn_iface, - NMProxyConfig * vpn_proxy_config, - NMIP4Config * vpn_ip4_config, - NMIP6Config * vpn_ip6_config, + NMConnection *applied_connection, + NMDevice *parent_device, + const char *vpn_iface, + const NML3ConfigData *l3cd, NMDispatcherFunc callback, gpointer user_data, - NMDispatcherCallId ** out_call_id); + NMDispatcherCallId **out_call_id); gboolean nm_dispatcher_call_vpn_sync(NMDispatcherAction action, NMSettingsConnection *settings_connection, - NMConnection * applied_connection, - NMDevice * parent_device, - const char * vpn_iface, - NMProxyConfig * vpn_proxy_config, - NMIP4Config * vpn_ip4_config, - NMIP6Config * vpn_ip6_config); + NMConnection *applied_connection, + NMDevice *parent_device, + const char *vpn_iface, + const NML3ConfigData *l3cd); gboolean nm_dispatcher_call_connectivity(NMConnectivityState state, NMDispatcherFunc callback, diff --git a/src/core/nm-firewall-utils.c b/src/core/nm-firewall-utils.c index a2446553..ddac1137 100644 --- a/src/core/nm-firewall-utils.c +++ b/src/core/nm-firewall-utils.c @@ -115,7 +115,7 @@ static gboolean _share_iptables_call_v(const char *const *argv) { gs_free_error GError *error = NULL; - gs_free char * argv_str = NULL; + gs_free char *argv_str = NULL; int status; nm_log_dbg(LOGD_SHARING, "iptables: %s", (argv_str = g_strjoinv(" ", (char **) argv))); @@ -356,11 +356,11 @@ _share_iptables_set_shared(gboolean add, const char *ip_iface, in_addr_t addr, g /*****************************************************************************/ typedef struct { - GTask * task; - GSubprocess * subprocess; - GSource * timeout_source; + GTask *task; + GSubprocess *subprocess; + GSource *timeout_source; GCancellable *intern_cancellable; - char * identifier; + char *identifier; gulong cancellable_id; } FwNftCallData; @@ -386,8 +386,8 @@ _fw_nft_call_data_free(FwNftCallData *call_data, GError *error_take) static void _fw_nft_call_communicate_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - FwNftCallData *call_data = user_data; - gs_free_error GError *error = NULL; + FwNftCallData *call_data = user_data; + gs_free_error GError *error = NULL; gs_unref_bytes GBytes *stdout_buf = NULL; gs_unref_bytes GBytes *stderr_buf = NULL; @@ -487,14 +487,14 @@ _fw_nft_call_timeout_cb(gpointer user_data) } static void -_fw_nft_call(GBytes * stdin_buf, - GCancellable * cancellable, +_fw_nft_call(GBytes *stdin_buf, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer callback_user_data) { gs_unref_object GSubprocessLauncher *subprocess_launcher = NULL; - gs_free_error GError *error = NULL; - FwNftCallData * call_data; + gs_free_error GError *error = NULL; + FwNftCallData *call_data; call_data = g_slice_new(FwNftCallData); *call_data = (FwNftCallData){ @@ -566,7 +566,7 @@ _fw_nft_call_finish(GAsyncResult *result, GError **error) typedef struct { GMainLoop *loop; - GError ** error; + GError **error; gboolean success; } FwNftCallSyncData; @@ -586,8 +586,8 @@ _fw_nft_call_sync(GBytes *stdin_buf, GError **error) nm_g_main_context_push_thread_default(g_main_context_new()); nm_auto_unref_gmainloop GMainLoop *main_loop = g_main_loop_new(main_context, FALSE); FwNftCallSyncData data = (FwNftCallSyncData){ - .loop = main_loop, - .error = error, + .loop = main_loop, + .error = error, }; _fw_nft_call(stdin_buf, NULL, _fw_nft_call_sync_done, &data); @@ -601,11 +601,11 @@ _fw_nft_call_sync(GBytes *stdin_buf, GError **error) static void _fw_nft_set(gboolean add, const char *ip_iface, in_addr_t addr, guint8 plen) { - nm_auto_str_buf NMStrBuf strbuf = NM_STR_BUF_INIT(NM_UTILS_GET_NEXT_REALLOC_SIZE_1000, FALSE); - gs_unref_bytes GBytes *stdin_buf = NULL; - gs_free char * table_name = NULL; - gs_free char * ss1 = NULL; - char str_subnet[_SHARE_IPTABLES_SUBNET_TO_STR_LEN]; + nm_auto_str_buf NMStrBuf strbuf = NM_STR_BUF_INIT(NM_UTILS_GET_NEXT_REALLOC_SIZE_1000, FALSE); + gs_unref_bytes GBytes *stdin_buf = NULL; + gs_free char *table_name = NULL; + gs_free char *ss1 = NULL; + char str_subnet[_SHARE_IPTABLES_SUBNET_TO_STR_LEN]; table_name = _share_iptables_get_name(FALSE, "nm-shared", ip_iface); @@ -687,7 +687,7 @@ _fw_nft_set(gboolean add, const char *ip_iface, in_addr_t addr, guint8 plen) /*****************************************************************************/ struct _NMFirewallConfig { - char * ip_iface; + char *ip_iface; in_addr_t addr; guint8 plen; }; diff --git a/src/core/nm-firewalld-manager.c b/src/core/nm-firewalld-manager.c index 43ab278a..24dd7fd1 100644 --- a/src/core/nm-firewalld-manager.c +++ b/src/core/nm-firewalld-manager.c @@ -78,7 +78,7 @@ struct _NMFirewalldManagerCallId { union { struct { GCancellable *cancellable; - GVariant * arg; + GVariant *arg; } dbus; struct { guint id; @@ -179,15 +179,15 @@ nm_firewalld_manager_get_running(NMFirewalldManager *self) /*****************************************************************************/ static NMFirewalldManagerCallId * -_cb_info_create(NMFirewalldManager * self, +_cb_info_create(NMFirewalldManager *self, OpsType ops_type, - const char * iface, - const char * zone, + const char *iface, + const char *zone, NMFirewalldManagerAddRemoveCallback callback, gpointer user_data) { NMFirewalldManagerPrivate *priv = NM_FIREWALLD_MANAGER_GET_PRIVATE(self); - NMFirewalldManagerCallId * call_id; + NMFirewalldManagerCallId *call_id; call_id = g_slice_new0(NMFirewalldManagerCallId); @@ -230,7 +230,7 @@ _cb_info_complete(NMFirewalldManagerCallId *call_id, GError *error) static gboolean _handle_idle_cb(gpointer user_data) { - NMFirewalldManager * self; + NMFirewalldManager *self; NMFirewalldManagerCallId *call_id = user_data; nm_assert(call_id); @@ -267,10 +267,10 @@ _handle_idle_start(NMFirewalldManager *self, NMFirewalldManagerCallId *call_id) static void _handle_dbus_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - NMFirewalldManager * self; - NMFirewalldManagerCallId *call_id; - gs_free_error GError *error = NULL; - gs_unref_variant GVariant *ret = NULL; + NMFirewalldManager *self; + NMFirewalldManagerCallId *call_id; + gs_free_error GError *error = NULL; + gs_unref_variant GVariant *ret = NULL; ret = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), result, &error); @@ -322,8 +322,8 @@ static void _handle_dbus_start(NMFirewalldManager *self, NMFirewalldManagerCallId *call_id) { NMFirewalldManagerPrivate *priv = NM_FIREWALLD_MANAGER_GET_PRIVATE(self); - const char * dbus_method = NULL; - GVariant * arg; + const char *dbus_method = NULL; + GVariant *arg; nm_assert(call_id); nm_assert(priv->name_owner); @@ -366,15 +366,15 @@ _handle_dbus_start(NMFirewalldManager *self, NMFirewalldManagerCallId *call_id) } static NMFirewalldManagerCallId * -_start_request(NMFirewalldManager * self, +_start_request(NMFirewalldManager *self, OpsType ops_type, - const char * iface, - const char * zone, + const char *iface, + const char *zone, NMFirewalldManagerAddRemoveCallback callback, gpointer user_data) { NMFirewalldManagerPrivate *priv; - NMFirewalldManagerCallId * call_id; + NMFirewalldManagerCallId *call_id; g_return_val_if_fail(NM_IS_FIREWALLD_MANAGER(self), NULL); g_return_val_if_fail(iface && *iface, NULL); @@ -417,8 +417,8 @@ _start_request(NMFirewalldManager * self, NMFirewalldManagerCallId * nm_firewalld_manager_add_or_change_zone(NMFirewalldManager *self, - const char * iface, - const char * zone, + const char *iface, + const char *zone, gboolean add, /* TRUE == add, FALSE == change */ NMFirewalldManagerAddRemoveCallback callback, gpointer user_data) @@ -432,9 +432,9 @@ nm_firewalld_manager_add_or_change_zone(NMFirewalldManager *self, } NMFirewalldManagerCallId * -nm_firewalld_manager_remove_from_zone(NMFirewalldManager * self, - const char * iface, - const char * zone, +nm_firewalld_manager_remove_from_zone(NMFirewalldManager *self, + const char *iface, + const char *zone, NMFirewalldManagerAddRemoveCallback callback, gpointer user_data) { @@ -444,9 +444,9 @@ nm_firewalld_manager_remove_from_zone(NMFirewalldManager * self, void nm_firewalld_manager_cancel_call(NMFirewalldManagerCallId *call_id) { - NMFirewalldManager * self; + NMFirewalldManager *self; NMFirewalldManagerPrivate *priv; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; g_return_if_fail(call_id); g_return_if_fail(NM_IS_FIREWALLD_MANAGER(call_id->self)); @@ -470,7 +470,7 @@ static void name_owner_changed(NMFirewalldManager *self, const char *owner) { _nm_unused gs_unref_object NMFirewalldManager *self_keep_alive = g_object_ref(self); - NMFirewalldManagerPrivate * priv = NM_FIREWALLD_MANAGER_GET_PRIVATE(self); + NMFirewalldManagerPrivate *priv = NM_FIREWALLD_MANAGER_GET_PRIVATE(self); gboolean was_running; gboolean now_running; gboolean just_initied; @@ -532,14 +532,14 @@ name_owner_changed(NMFirewalldManager *self, const char *owner) static void reloaded_cb(GDBusConnection *connection, - const char * sender_name, - const char * object_path, - const char * interface_name, - const char * signal_name, - GVariant * parameters, + const char *sender_name, + const char *object_path, + const char *interface_name, + const char *signal_name, + GVariant *parameters, gpointer user_data) { - NMFirewalldManager * self = user_data; + NMFirewalldManager *self = user_data; NMFirewalldManagerPrivate *priv = NM_FIREWALLD_MANAGER_GET_PRIVATE(self); if (!nm_streq0(sender_name, priv->name_owner)) @@ -551,15 +551,15 @@ reloaded_cb(GDBusConnection *connection, static void name_owner_changed_cb(GDBusConnection *connection, - const char * sender_name, - const char * object_path, - const char * interface_name, - const char * signal_name, - GVariant * parameters, + const char *sender_name, + const char *object_path, + const char *interface_name, + const char *signal_name, + GVariant *parameters, gpointer user_data) { NMFirewalldManager *self = user_data; - const char * new_owner; + const char *new_owner; if (!g_variant_is_of_type(parameters, G_VARIANT_TYPE("(sss)"))) return; @@ -572,7 +572,7 @@ name_owner_changed_cb(GDBusConnection *connection, static void get_name_owner_cb(const char *name_owner, GError *error, gpointer user_data) { - NMFirewalldManager * self; + NMFirewalldManager *self; NMFirewalldManagerPrivate *priv; if (nm_utils_error_is_cancelled(error)) @@ -632,7 +632,7 @@ nm_firewalld_manager_init(NMFirewalldManager *self) static void dispose(GObject *object) { - NMFirewalldManager * self = NM_FIREWALLD_MANAGER(object); + NMFirewalldManager *self = NM_FIREWALLD_MANAGER(object); NMFirewalldManagerPrivate *priv = NM_FIREWALLD_MANAGER_GET_PRIVATE(self); /* as every pending operation takes a reference to the manager, diff --git a/src/core/nm-firewalld-manager.h b/src/core/nm-firewalld-manager.h index 1f76beba..a7e71486 100644 --- a/src/core/nm-firewalld-manager.h +++ b/src/core/nm-firewalld-manager.h @@ -36,22 +36,22 @@ NMFirewalldManager *nm_firewalld_manager_get(void); gboolean nm_firewalld_manager_get_running(NMFirewalldManager *self); -typedef void (*NMFirewalldManagerAddRemoveCallback)(NMFirewalldManager * self, +typedef void (*NMFirewalldManagerAddRemoveCallback)(NMFirewalldManager *self, NMFirewalldManagerCallId *call_id, - GError * error, + GError *error, gpointer user_data); NMFirewalldManagerCallId * -nm_firewalld_manager_add_or_change_zone(NMFirewalldManager * mgr, - const char * iface, - const char * zone, +nm_firewalld_manager_add_or_change_zone(NMFirewalldManager *mgr, + const char *iface, + const char *zone, gboolean add, NMFirewalldManagerAddRemoveCallback callback, gpointer user_data); NMFirewalldManagerCallId * -nm_firewalld_manager_remove_from_zone(NMFirewalldManager * mgr, - const char * iface, - const char * zone, +nm_firewalld_manager_remove_from_zone(NMFirewalldManager *mgr, + const char *iface, + const char *zone, NMFirewalldManagerAddRemoveCallback callback, gpointer user_data); diff --git a/src/core/nm-hostname-manager.c b/src/core/nm-hostname-manager.c index 32dc2db9..64c2531e 100644 --- a/src/core/nm-hostname-manager.c +++ b/src/core/nm-hostname-manager.c @@ -52,15 +52,15 @@ /*****************************************************************************/ -NM_GOBJECT_PROPERTIES_DEFINE(NMHostnameManager, PROP_HOSTNAME, ); +NM_GOBJECT_PROPERTIES_DEFINE(NMHostnameManager, PROP_STATIC_HOSTNAME, ); typedef struct { - char * current_hostname; + char *static_hostname; GFileMonitor *monitor; GFileMonitor *dhcp_monitor; gulong monitor_id; gulong dhcp_monitor_id; - GDBusProxy * hostnamed_proxy; + GDBusProxy *hostnamed_proxy; } NMHostnameManagerPrivate; struct _NMHostnameManager { @@ -103,9 +103,9 @@ _file_monitor_new(const char *path) static char * read_hostname_gentoo(const char *path) { - gs_free char * contents = NULL; + gs_free char *contents = NULL; gs_strfreev char **all_lines = NULL; - const char * tmp; + const char *tmp; guint i; if (!g_file_get_contents(path, &contents, NULL, NULL)) @@ -129,7 +129,7 @@ read_hostname_gentoo(const char *path) static char * read_hostname_slackware(const char *path) { - gs_free char * contents = NULL; + gs_free char *contents = NULL; gs_strfreev char **all_lines = NULL; guint i = 0; @@ -152,7 +152,7 @@ static gboolean hostname_is_dynamic(void) { GIOChannel *channel; - char * str = NULL; + char *str = NULL; gboolean dynamic = FALSE; channel = g_io_channel_new_file(CONF_DHCP, "r", NULL); @@ -178,39 +178,53 @@ hostname_is_dynamic(void) /*****************************************************************************/ const char * -nm_hostname_manager_get_hostname(NMHostnameManager *self) +nm_hostname_manager_get_static_hostname(NMHostnameManager *self) { g_return_val_if_fail(NM_IS_HOSTNAME_MANAGER(self), NULL); - return NM_HOSTNAME_MANAGER_GET_PRIVATE(self)->current_hostname; + + return NM_HOSTNAME_MANAGER_GET_PRIVATE(self)->static_hostname; } static void _set_hostname(NMHostnameManager *self, const char *hostname) { - NMHostnameManagerPrivate *priv = NM_HOSTNAME_MANAGER_GET_PRIVATE(self); - char * old_hostname; + NMHostnameManagerPrivate *priv = NM_HOSTNAME_MANAGER_GET_PRIVATE(self); + gs_free char *hostname_free = NULL; + char *old_hostname; hostname = nm_str_not_empty(hostname); - if (nm_streq0(hostname, priv->current_hostname)) + if (hostname) { + /* as we also read the file from disk, it might not be in UTF-8 encoding. + * + * A hostname in non-UTF-8 encoding would be odd and cause issues when we + * try to expose them on D-Bus via the NM_SETTINGS_STATIC_HOSTNAME property. + * + * Sanitize somewhat. It's wrong anyway. */ + hostname = nm_utils_str_utf8safe_escape(hostname, + NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL, + &hostname_free); + } + + if (nm_streq0(hostname, priv->static_hostname)) return; - _LOGI("hostname changed from %s%s%s to %s%s%s", - NM_PRINT_FMT_QUOTED(priv->current_hostname, "\"", priv->current_hostname, "\"", "(none)"), + _LOGI("static hostname changed from %s%s%s to %s%s%s", + NM_PRINT_FMT_QUOTED(priv->static_hostname, "\"", priv->static_hostname, "\"", "(none)"), NM_PRINT_FMT_QUOTED(hostname, "\"", hostname, "\"", "(none)")); - old_hostname = priv->current_hostname; - priv->current_hostname = g_strdup(hostname); + old_hostname = priv->static_hostname; + priv->static_hostname = g_strdup(hostname); g_free(old_hostname); - _notify(self, PROP_HOSTNAME); + _notify(self, PROP_STATIC_HOSTNAME); } static void _set_hostname_read_file(NMHostnameManager *self) { NMHostnameManagerPrivate *priv = NM_HOSTNAME_MANAGER_GET_PRIVATE(self); - gs_free char * hostname = NULL; + gs_free char *hostname = NULL; if (priv->hostnamed_proxy) { /* read-hostname returns the current hostname with hostnamed. */ @@ -239,10 +253,10 @@ _set_hostname_read_file(NMHostnameManager *self) static void set_transient_hostname_done(GObject *object, GAsyncResult *res, gpointer user_data) { - GDBusProxy * proxy = G_DBUS_PROXY(object); - gs_unref_variant GVariant *result = NULL; - gs_free_error GError * error = NULL; - gs_free char * hostname = NULL; + GDBusProxy *proxy = G_DBUS_PROXY(object); + gs_unref_variant GVariant *result = NULL; + gs_free_error GError *error = NULL; + gs_free char *hostname = NULL; NMHostnameManagerSetHostnameCb cb; gpointer cb_user_data; @@ -260,8 +274,8 @@ set_transient_hostname_done(GObject *object, GAsyncResult *res, gpointer user_da } void -nm_hostname_manager_set_transient_hostname(NMHostnameManager * self, - const char * hostname, +nm_hostname_manager_set_transient_hostname(NMHostnameManager *self, + const char *hostname, NMHostnameManagerSetHostnameCb cb, gpointer user_data) { @@ -290,7 +304,7 @@ gboolean nm_hostname_manager_get_transient_hostname(NMHostnameManager *self, char **hostname) { NMHostnameManagerPrivate *priv = NM_HOSTNAME_MANAGER_GET_PRIVATE(self); - GVariant * v_hostname; + GVariant *v_hostname; if (!priv->hostnamed_proxy) return FALSE; @@ -310,17 +324,17 @@ nm_hostname_manager_get_transient_hostname(NMHostnameManager *self, char **hostn gboolean nm_hostname_manager_write_hostname(NMHostnameManager *self, const char *hostname) { - NMHostnameManagerPrivate *priv; - char * hostname_eol; - gboolean ret; - gs_free_error GError *error = NULL; - const char * file = HOSTNAME_FILE; - gs_free char * link_path = NULL; - gs_unref_variant GVariant *var = NULL; + NMHostnameManagerPrivate *priv; + char *hostname_eol; + gboolean ret; + gs_free_error GError *error = NULL; + const char *file = HOSTNAME_FILE; + gs_free char *link_path = NULL; + gs_unref_variant GVariant *var = NULL; struct stat file_stat; #if HAVE_SELINUX gboolean fcon_was_set = FALSE; - char * fcon_prev = NULL; + char *fcon_prev = NULL; #endif g_return_val_if_fail(NM_IS_HOSTNAME_MANAGER(self), FALSE); @@ -365,7 +379,7 @@ nm_hostname_manager_write_hostname(NMHostnameManager *self, const char *hostname handle = selabel_open(SELABEL_CTX_FILE, NULL, 0); if (handle) { mode_t st_mode = 0; - char * fcon = NULL; + char *fcon = NULL; if (stat(file, &file_stat) == 0) st_mode = file_stat.st_mode; @@ -406,12 +420,12 @@ nm_hostname_manager_write_hostname(NMHostnameManager *self, const char *hostname static void hostnamed_properties_changed(GDBusProxy *proxy, - GVariant * changed_properties, - char ** invalidated_properties, + GVariant *changed_properties, + char **invalidated_properties, gpointer user_data) { - NMHostnameManager * self = user_data; - NMHostnameManagerPrivate *priv = NM_HOSTNAME_MANAGER_GET_PRIVATE(self); + NMHostnameManager *self = user_data; + NMHostnameManagerPrivate *priv = NM_HOSTNAME_MANAGER_GET_PRIVATE(self); gs_unref_variant GVariant *variant = NULL; variant = g_dbus_proxy_get_cached_property(priv->hostnamed_proxy, "StaticHostname"); @@ -422,9 +436,9 @@ hostnamed_properties_changed(GDBusProxy *proxy, /*****************************************************************************/ static void -_file_monitors_file_changed_cb(GFileMonitor * monitor, - GFile * file, - GFile * other_file, +_file_monitors_file_changed_cb(GFileMonitor *monitor, + GFile *file, + GFile *other_file, GFileMonitorEvent event_type, gpointer user_data) { @@ -453,9 +467,9 @@ static void _file_monitors_setup(NMHostnameManager *self) { NMHostnameManagerPrivate *priv = NM_HOSTNAME_MANAGER_GET_PRIVATE(self); - GFileMonitor * monitor; - const char * path = HOSTNAME_FILE; - gs_free char * link_path = NULL; + GFileMonitor *monitor; + const char *path = HOSTNAME_FILE; + gs_free char *link_path = NULL; struct stat file_stat; _file_monitors_clear(self); @@ -499,8 +513,8 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) NMHostnameManager *self = NM_HOSTNAME_MANAGER(object); switch (prop_id) { - case PROP_HOSTNAME: - g_value_set_string(value, nm_hostname_manager_get_hostname(self)); + case PROP_STATIC_HOSTNAME: + g_value_set_string(value, nm_hostname_manager_get_static_hostname(self)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); @@ -517,11 +531,11 @@ nm_hostname_manager_init(NMHostnameManager *self) static void constructed(GObject *object) { - NMHostnameManager * self = NM_HOSTNAME_MANAGER(object); + NMHostnameManager *self = NM_HOSTNAME_MANAGER(object); NMHostnameManagerPrivate *priv = NM_HOSTNAME_MANAGER_GET_PRIVATE(self); - GDBusProxy * proxy; - GVariant * variant; - gs_free_error GError *error = NULL; + GDBusProxy *proxy; + GVariant *variant; + gs_free_error GError *error = NULL; proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, 0, @@ -560,7 +574,7 @@ constructed(GObject *object) static void dispose(GObject *object) { - NMHostnameManager * self = NM_HOSTNAME_MANAGER(object); + NMHostnameManager *self = NM_HOSTNAME_MANAGER(object); NMHostnameManagerPrivate *priv = NM_HOSTNAME_MANAGER_GET_PRIVATE(self); if (priv->hostnamed_proxy) { @@ -572,7 +586,7 @@ dispose(GObject *object) _file_monitors_clear(self); - nm_clear_g_free(&priv->current_hostname); + nm_clear_g_free(&priv->static_hostname); G_OBJECT_CLASS(nm_hostname_manager_parent_class)->dispose(object); } @@ -586,11 +600,12 @@ nm_hostname_manager_class_init(NMHostnameManagerClass *class) object_class->get_property = get_property; object_class->dispose = dispose; - obj_properties[PROP_HOSTNAME] = g_param_spec_string(NM_HOSTNAME_MANAGER_HOSTNAME, - "", - "", - NULL, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + obj_properties[PROP_STATIC_HOSTNAME] = + g_param_spec_string(NM_HOSTNAME_MANAGER_STATIC_HOSTNAME, + "", + "", + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); } diff --git a/src/core/nm-hostname-manager.h b/src/core/nm-hostname-manager.h index ff109e7e..b871d177 100644 --- a/src/core/nm-hostname-manager.h +++ b/src/core/nm-hostname-manager.h @@ -21,7 +21,7 @@ #define NM_HOSTNAME_MANAGER_GET_CLASS(obj) \ (G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_HOSTNAME_MANAGER, NMHostnameManagerClass)) -#define NM_HOSTNAME_MANAGER_HOSTNAME "hostname" +#define NM_HOSTNAME_MANAGER_STATIC_HOSTNAME "static-hostname" typedef struct _NMHostnameManager NMHostnameManager; typedef struct _NMHostnameManagerClass NMHostnameManagerClass; @@ -34,12 +34,12 @@ GType nm_hostname_manager_get_type(void); NMHostnameManager *nm_hostname_manager_get(void); -const char *nm_hostname_manager_get_hostname(NMHostnameManager *self); +const char *nm_hostname_manager_get_static_hostname(NMHostnameManager *self); gboolean nm_hostname_manager_write_hostname(NMHostnameManager *self, const char *hostname); -void nm_hostname_manager_set_transient_hostname(NMHostnameManager * self, - const char * hostname, +void nm_hostname_manager_set_transient_hostname(NMHostnameManager *self, + const char *hostname, NMHostnameManagerSetHostnameCb cb, gpointer user_data); diff --git a/src/core/nm-iface-helper.c b/src/core/nm-iface-helper.c deleted file mode 100644 index 83ae1b54..00000000 --- a/src/core/nm-iface-helper.c +++ /dev/null @@ -1,857 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2014 Red Hat, Inc. - */ - -#include "src/core/nm-default-daemon.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "libnm-glib-aux/nm-c-list.h" - -#include "main-utils.h" -#include "NetworkManagerUtils.h" -#include "libnm-platform/nm-linux-platform.h" -#include "libnm-platform/nm-platform-utils.h" -#include "dhcp/nm-dhcp-manager.h" -#include "ndisc/nm-ndisc.h" -#include "ndisc/nm-lndp-ndisc.h" -#include "nm-utils.h" -#include "libnm-core-intern/nm-core-internal.h" -#include "nm-setting-ip6-config.h" -#include "libnm-systemd-core/nm-sd.h" - -#if !defined(NM_DIST_VERSION) -#define NM_DIST_VERSION VERSION -#endif - -#define NMIH_PID_FILE_FMT NMRUNDIR "/nm-iface-helper-%d.pid" - -/*****************************************************************************/ - -static struct { - GMainLoop *main_loop; - int ifindex; - gboolean is_vrf_device; - - guint dad_failed_id; - CList dad_failed_lst_head; -} gl /*obal*/ = { - .ifindex = -1, - .is_vrf_device = FALSE, -}; - -static struct { - gboolean slaac; - gboolean show_version; - gboolean become_daemon; - gboolean debug; - gboolean g_fatal_warnings; - gboolean slaac_required; - gboolean dhcp4_required; - int tempaddr; - char * ifname; - char * uuid; - char * stable_id; - char * dhcp4_address; - char * dhcp4_clientid; - char * dhcp4_hostname; - char * dhcp4_fqdn; - char * mud_url; - char * iid_str; - NMSettingIP6ConfigAddrGenMode addr_gen_mode; - char * logging_backend; - char * opt_log_level; - char * opt_log_domains; - guint32 priority_v4; - guint32 priority_v6; -} global_opt = { - .tempaddr = NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN, - .priority_v4 = NM_PLATFORM_ROUTE_METRIC_DEFAULT_IP4, - .priority_v6 = NM_PLATFORM_ROUTE_METRIC_DEFAULT_IP6, -}; - -/*****************************************************************************/ - -#define _NMLOG_PREFIX_NAME "nm-iface-helper" -#define _NMLOG(level, domain, ...) \ - nm_log((level), \ - (domain), \ - global_opt.ifname, \ - NULL, \ - "iface-helper: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__) _NM_UTILS_MACRO_REST(__VA_ARGS__)) - -/*****************************************************************************/ - -static void -_dhcp_client_notify_cb(NMDhcpClient * client, - const NMDhcpClientNotifyData *notify_data, - gpointer user_data) -{ - static NMIP4Config *last_config = NULL; - NMIP4Config * existing; - gs_unref_ptrarray GPtrArray *ip4_dev_route_blacklist = NULL; - gs_free_error GError *error = NULL; - NMIP4Config * ip4_config; - - if (!notify_data || notify_data->notify_type != NM_DHCP_CLIENT_NOTIFY_TYPE_STATE_CHANGED) - g_return_if_reached(); - - nm_assert(!notify_data->state_changed.ip_config - || NM_IS_IP4_CONFIG(notify_data->state_changed.ip_config)); - - _LOGD(LOGD_DHCP4, "new DHCPv4 client state %d", (int) notify_data->state_changed.dhcp_state); - - switch (notify_data->state_changed.dhcp_state) { - case NM_DHCP_STATE_BOUND: - case NM_DHCP_STATE_EXTENDED: - ip4_config = NM_IP4_CONFIG(notify_data->state_changed.ip_config); - - g_assert(ip4_config); - g_assert(nm_ip4_config_get_ifindex(ip4_config) == gl.ifindex); - - existing = nm_ip4_config_capture(nm_platform_get_multi_idx(NM_PLATFORM_GET), - NM_PLATFORM_GET, - gl.ifindex); - if (last_config) - nm_ip4_config_subtract(existing, last_config, 0); - - nm_ip4_config_merge(existing, ip4_config, NM_IP_CONFIG_MERGE_DEFAULT, 0); - nm_ip4_config_add_dependent_routes(existing, - RT_TABLE_MAIN, - global_opt.priority_v4, - gl.is_vrf_device, - &ip4_dev_route_blacklist); - if (!nm_ip4_config_commit(existing, NM_PLATFORM_GET, NM_IP_ROUTE_TABLE_SYNC_MODE_MAIN)) - _LOGW(LOGD_DHCP4, "failed to apply DHCPv4 config"); - - if (!last_config && !nm_dhcp_client_accept(client, &error)) - _LOGW(LOGD_DHCP4, "failed to accept lease: %s", error->message); - - nm_platform_ip4_dev_route_blacklist_set(NM_PLATFORM_GET, - gl.ifindex, - ip4_dev_route_blacklist); - - if (last_config) - g_object_unref(last_config); - last_config = nm_ip4_config_new(nm_platform_get_multi_idx(NM_PLATFORM_GET), - nm_dhcp_client_get_ifindex(client)); - 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 (global_opt.dhcp4_required) { - _LOGW(LOGD_DHCP4, "DHCPv4 timed out or failed, quitting..."); - g_main_loop_quit(gl.main_loop); - } else - _LOGW(LOGD_DHCP4, "DHCPv4 timed out or failed"); - break; - default: - break; - } -} - -static void -ndisc_config_changed(NMNDisc * ndisc, - const NMNDiscData *rdata, - guint changed_int, - gpointer user_data) -{ - NMNDiscConfigMap changed = changed_int; - static NMIP6Config *ndisc_config = NULL; - NMIP6Config * existing; - - existing = nm_ip6_config_capture(nm_platform_get_multi_idx(NM_PLATFORM_GET), - NM_PLATFORM_GET, - gl.ifindex, - global_opt.tempaddr); - if (ndisc_config) - nm_ip6_config_subtract(existing, ndisc_config, 0); - else { - ndisc_config = nm_ip6_config_new(nm_platform_get_multi_idx(NM_PLATFORM_GET), gl.ifindex); - } - - if (changed & NM_NDISC_CONFIG_ADDRESSES) { - guint32 ifa_flags; - - /* Check, whether kernel is 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. */ - ifa_flags = IFA_F_NOPREFIXROUTE; - if (NM_IN_SET(global_opt.tempaddr, - NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR, - NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR)) - ifa_flags |= IFA_F_MANAGETEMPADDR; - - nm_ip6_config_reset_addresses_ndisc(ndisc_config, - rdata->addresses, - rdata->addresses_n, - 64, - ifa_flags); - } - - if (NM_FLAGS_ANY(changed, NM_NDISC_CONFIG_ROUTES | NM_NDISC_CONFIG_GATEWAYS)) { - nm_ip6_config_reset_routes_ndisc(ndisc_config, - rdata->gateways, - rdata->gateways_n, - rdata->routes, - rdata->routes_n, - RT_TABLE_MAIN, - global_opt.priority_v6); - } - - if (changed & NM_NDISC_CONFIG_DHCP_LEVEL) { - /* Unsupported until systemd DHCPv6 is ready */ - } - - if (changed & NM_NDISC_CONFIG_HOP_LIMIT) - nm_platform_sysctl_ip_conf_set_ipv6_hop_limit_safe(NM_PLATFORM_GET, - global_opt.ifname, - rdata->hop_limit); - - if (changed & NM_NDISC_CONFIG_REACHABLE_TIME) { - nm_platform_sysctl_ip_neigh_set_ipv6_reachable_time(NM_PLATFORM_GET, - global_opt.ifname, - rdata->reachable_time_ms); - } - - if (changed & NM_NDISC_CONFIG_RETRANS_TIMER) { - nm_platform_sysctl_ip_neigh_set_ipv6_retrans_time(NM_PLATFORM_GET, - global_opt.ifname, - rdata->retrans_timer_ms); - } - - if (changed & NM_NDISC_CONFIG_MTU) { - nm_platform_sysctl_ip_conf_set_int64(NM_PLATFORM_GET, - AF_INET6, - global_opt.ifname, - "mtu", - rdata->mtu); - } - - nm_ip6_config_merge(existing, ndisc_config, NM_IP_CONFIG_MERGE_DEFAULT, 0); - nm_ip6_config_add_dependent_routes(existing, - RT_TABLE_MAIN, - global_opt.priority_v6, - gl.is_vrf_device); - if (!nm_ip6_config_commit(existing, NM_PLATFORM_GET, NM_IP_ROUTE_TABLE_SYNC_MODE_MAIN, NULL)) - _LOGW(LOGD_IP6, "failed to apply IPv6 config"); -} - -static void -ndisc_ra_timeout(NMNDisc *ndisc, gpointer user_data) -{ - if (global_opt.slaac_required) { - _LOGW(LOGD_IP6, "IPv6 timed out or failed, quitting..."); - g_main_loop_quit(gl.main_loop); - } else - _LOGW(LOGD_IP6, "IPv6 timed out or failed"); -} - -static gboolean -quit_handler(gpointer user_data) -{ - g_main_loop_quit(gl.main_loop); - return G_SOURCE_REMOVE; -} - -static void -setup_signals(void) -{ - signal(SIGPIPE, SIG_IGN); - g_unix_signal_add(SIGINT, quit_handler, NULL); - g_unix_signal_add(SIGTERM, quit_handler, NULL); -} - -static gboolean -do_early_setup(int *argc, char **argv[]) -{ - gint64 priority64_v4 = -1; - gint64 priority64_v6 = -1; - GOptionEntry options[] = { - /* Interface/IP config */ - {"ifname", - 'i', - 0, - G_OPTION_ARG_STRING, - &global_opt.ifname, - N_("The interface to manage"), - "eth0"}, - {"uuid", - 'u', - 0, - G_OPTION_ARG_STRING, - &global_opt.uuid, - N_("Connection UUID"), - "661e8cd0-b618-46b8-9dc9-31a52baaa16b"}, - {"stable-id", - '\0', - 0, - G_OPTION_ARG_STRING, - &global_opt.stable_id, - N_("Connection Token for Stable IDs"), - "eth"}, - {"slaac", - 's', - 0, - G_OPTION_ARG_NONE, - &global_opt.slaac, - N_("Whether to manage IPv6 SLAAC"), - NULL}, - {"slaac-required", - '6', - 0, - G_OPTION_ARG_NONE, - &global_opt.slaac_required, - N_("Whether SLAAC must be successful"), - NULL}, - {"slaac-tempaddr", - 't', - 0, - G_OPTION_ARG_INT, - &global_opt.tempaddr, - N_("Use an IPv6 temporary privacy address"), - NULL}, - {"dhcp4", - 'd', - 0, - G_OPTION_ARG_STRING, - &global_opt.dhcp4_address, - N_("Current DHCPv4 address"), - NULL}, - {"dhcp4-required", - '4', - 0, - G_OPTION_ARG_NONE, - &global_opt.dhcp4_required, - N_("Whether DHCPv4 must be successful"), - NULL}, - {"dhcp4-clientid", - 'c', - 0, - G_OPTION_ARG_STRING, - &global_opt.dhcp4_clientid, - N_("Hex-encoded DHCPv4 client ID"), - NULL}, - {"dhcp4-hostname", - 'h', - 0, - G_OPTION_ARG_STRING, - &global_opt.dhcp4_hostname, - N_("Hostname to send to DHCP server"), - N_("barbar")}, - {"dhcp4-fqdn", - 'F', - 0, - G_OPTION_ARG_STRING, - &global_opt.dhcp4_fqdn, - N_("FQDN to send to DHCP server"), - N_("host.domain.org")}, - {"priority4", - '\0', - 0, - G_OPTION_ARG_INT64, - &priority64_v4, - N_("Route priority for IPv4"), - N_("0")}, - {"priority6", - '\0', - 0, - G_OPTION_ARG_INT64, - &priority64_v6, - N_("Route priority for IPv6"), - N_("1024")}, - {"iid", - 'e', - 0, - G_OPTION_ARG_STRING, - &global_opt.iid_str, - N_("Hex-encoded Interface Identifier"), - ""}, - {"addr-gen-mode", - 'e', - 0, - G_OPTION_ARG_INT, - &global_opt.addr_gen_mode, - N_("IPv6 SLAAC address generation mode"), - "eui64"}, - {"logging-backend", - '\0', - 0, - G_OPTION_ARG_STRING, - &global_opt.logging_backend, - N_("The logging backend configuration value. See logging.backend in NetworkManager.conf"), - NULL}, - - /* Logging/debugging */ - {"version", - 'V', - 0, - G_OPTION_ARG_NONE, - &global_opt.show_version, - N_("Print NetworkManager version and exit"), - NULL}, - {"no-daemon", - 'n', - G_OPTION_FLAG_REVERSE, - G_OPTION_ARG_NONE, - &global_opt.become_daemon, - N_("Don't become a daemon"), - NULL}, - {"debug", - 'b', - 0, - G_OPTION_ARG_NONE, - &global_opt.debug, - N_("Don't become a daemon, and log to stderr"), - NULL}, - {"log-level", - 0, - 0, - G_OPTION_ARG_STRING, - &global_opt.opt_log_level, - N_("Log level: one of [%s]"), - "INFO"}, - {"log-domains", - 0, - 0, - G_OPTION_ARG_STRING, - &global_opt.opt_log_domains, - N_("Log domains separated by ',': any combination of [%s]"), - "PLATFORM,RFKILL,WIFI"}, - {"g-fatal-warnings", - 0, - 0, - G_OPTION_ARG_NONE, - &global_opt.g_fatal_warnings, - N_("Make all warnings fatal"), - NULL}, - {NULL}}; - - if (!nm_main_utils_early_setup("nm-iface-helper", - argc, - argv, - options, - NULL, - NULL, - _("nm-iface-helper is a small, standalone process that manages " - "a single network interface."))) - return FALSE; - - if (priority64_v4 >= 0 && priority64_v4 <= G_MAXUINT32) - global_opt.priority_v4 = (guint32) priority64_v4; - if (priority64_v6 >= 0 && priority64_v6 <= G_MAXUINT32) - global_opt.priority_v6 = (guint32) priority64_v6; - return TRUE; -} - -typedef struct { - NMPlatform *platform; - NMNDisc * ndisc; -} DadFailedHandleData; - -static gboolean -dad_failed_handle_idle(gpointer user_data) -{ - DadFailedHandleData *data = user_data; - NMCListElem * elem; - - while ((elem = c_list_first_entry(&gl.dad_failed_lst_head, NMCListElem, lst))) { - nm_auto_nmpobj const NMPObject *obj = elem->data; - - nm_c_list_elem_free(elem); - - if (nm_ndisc_dad_addr_is_fail_candidate(data->platform, obj)) { - nm_ndisc_dad_failed(data->ndisc, &NMP_OBJECT_CAST_IP6_ADDRESS(obj)->address, TRUE); - } - } - - gl.dad_failed_id = 0; - return G_SOURCE_REMOVE; -} - -static void -ip6_address_changed(NMPlatform * platform, - int obj_type_i, - int iface, - const NMPlatformIP6Address *addr, - int change_type_i, - NMNDisc * ndisc) -{ - const NMPlatformSignalChangeType change_type = change_type_i; - DadFailedHandleData * data; - - if (!nm_ndisc_dad_addr_is_fail_candidate_event(change_type, addr)) - return; - - c_list_link_tail( - &gl.dad_failed_lst_head, - &nm_c_list_elem_new_stale((gpointer) nmp_object_ref(NMP_OBJECT_UP_CAST(addr)))->lst); - if (gl.dad_failed_id) - return; - - data = g_slice_new(DadFailedHandleData); - data->platform = platform; - data->ndisc = ndisc; - gl.dad_failed_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, - dad_failed_handle_idle, - data, - nm_g_slice_free_fcn(DadFailedHandleData)); -} - -int -main(int argc, char *argv[]) -{ - char * bad_domains = NULL; - gs_free_error GError *error = NULL; - gboolean wrote_pidfile = FALSE; - gs_free char * pidfile = NULL; - gs_unref_object NMDhcpClient *dhcp4_client = NULL; - gs_unref_object NMNDisc *ndisc = NULL; - gs_unref_bytes GBytes *hwaddr = NULL; - gs_unref_bytes GBytes *bcast_hwaddr = NULL; - gs_unref_bytes GBytes *client_id = NULL; - gs_free NMUtilsIPv6IfaceId *iid = NULL; - const NMPlatformLink * pllink; - guint sd_id; - int errsv; - - c_list_init(&gl.dad_failed_lst_head); - - setpgid(getpid(), getpid()); - - if (!do_early_setup(&argc, &argv)) - return 1; - - nm_logging_init_pre("nm-iface-helper", - g_strdup_printf("%s[%ld] (%s): ", - _NMLOG_PREFIX_NAME, - (long) getpid(), - global_opt.ifname ?: "???")); - - if (global_opt.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); - } - - if (global_opt.show_version) { - fprintf(stdout, NM_DIST_VERSION "\n"); - return 0; - } - - nm_main_utils_ensure_root(); - - if (!global_opt.ifname || !global_opt.uuid) { - fprintf(stderr, _("An interface name and UUID are required\n")); - return 1; - } - - gl.ifindex = nmp_utils_if_nametoindex(global_opt.ifname); - if (gl.ifindex <= 0) { - errsv = errno; - fprintf(stderr, - _("Failed to find interface index for %s (%s)\n"), - global_opt.ifname, - nm_strerror_native(errsv)); - return 1; - } - pidfile = g_strdup_printf(NMIH_PID_FILE_FMT, gl.ifindex); - nm_main_utils_ensure_not_running_pidfile(pidfile); - - nm_main_utils_ensure_rundir(); - - if (!nm_logging_setup(global_opt.opt_log_level, - global_opt.opt_log_domains, - &bad_domains, - &error)) { - fprintf(stderr, - _("%s. Please use --help to see a list of valid options.\n"), - error->message); - return 1; - } else if (bad_domains) { - fprintf(stderr, - _("Ignoring unrecognized log domain(s) '%s' passed on command line.\n"), - bad_domains); - nm_clear_g_free(&bad_domains); - } - - if (global_opt.become_daemon && !global_opt.debug) { - if (daemon(0, 0) < 0) { - errsv = errno; - fprintf(stderr, - _("Could not daemonize: %s [error %u]\n"), - nm_strerror_native(errsv), - errsv); - return 1; - } - if (nm_main_utils_write_pidfile(pidfile)) - wrote_pidfile = TRUE; - } - - /* Set up unix signal handling - before creating threads, but after daemonizing! */ - gl.main_loop = g_main_loop_new(NULL, FALSE); - setup_signals(); - - nm_logging_init(global_opt.logging_backend, global_opt.debug); - - _LOGI(LOGD_CORE, "nm-iface-helper (version " NM_DIST_VERSION ") is starting..."); - - /* Set up platform interaction layer */ - nm_linux_platform_setup(); - - pllink = nm_platform_link_get(NM_PLATFORM_GET, gl.ifindex); - if (pllink) { - hwaddr = nmp_link_address_get_as_bytes(&pllink->l_address); - bcast_hwaddr = nmp_link_address_get_as_bytes(&pllink->l_broadcast); - - if (pllink->master > 0) { - gl.is_vrf_device = - nm_platform_link_get_type(NM_PLATFORM_GET, pllink->master) == NM_LINK_TYPE_VRF; - } - } - - if (global_opt.iid_str) { - GBytes *bytes; - gsize ignored = 0; - - bytes = nm_utils_hexstr2bin(global_opt.iid_str); - if (!bytes || g_bytes_get_size(bytes) != sizeof(*iid)) { - fprintf(stderr, _("(%s): Invalid IID %s\n"), global_opt.ifname, global_opt.iid_str); - return 1; - } - iid = g_bytes_unref_to_data(bytes, &ignored); - } - - if (global_opt.dhcp4_clientid) { - /* this string is just a plain hex-string. Unlike ipv4.dhcp-client-id, which - * is parsed via nm_dhcp_utils_client_id_string_to_bytes(). */ - client_id = nm_utils_hexstr2bin(global_opt.dhcp4_clientid); - if (!client_id || g_bytes_get_size(client_id) < 2) { - fprintf(stderr, - _("(%s): Invalid DHCP client-id %s\n"), - global_opt.ifname, - global_opt.dhcp4_clientid); - return 1; - } - } - - if (global_opt.dhcp4_address) { - nm_platform_sysctl_ip_conf_set(NM_PLATFORM_GET, - AF_INET, - global_opt.ifname, - "promote_secondaries", - "1"); - - dhcp4_client = nm_dhcp_manager_start_ip4(nm_dhcp_manager_get(), - nm_platform_get_multi_idx(NM_PLATFORM_GET), - global_opt.ifname, - gl.ifindex, - hwaddr, - bcast_hwaddr, - global_opt.uuid, - RT_TABLE_MAIN, - global_opt.priority_v4, - NM_DHCP_CLIENT_FLAGS_NONE, - !!global_opt.dhcp4_hostname, - global_opt.dhcp4_hostname, - global_opt.dhcp4_fqdn, - NM_DHCP_HOSTNAME_FLAGS_FQDN_DEFAULT_IP4, - global_opt.mud_url, - client_id, - NM_DHCP_TIMEOUT_DEFAULT, - NULL, - global_opt.dhcp4_address, - NULL, - NULL, - &error); - if (!dhcp4_client) - g_error("failure to start DHCP: %s", error->message); - - g_signal_connect(dhcp4_client, - NM_DHCP_CLIENT_NOTIFY, - G_CALLBACK(_dhcp_client_notify_cb), - NULL); - } - - if (global_opt.slaac) { - NMUtilsStableType stable_type = NM_UTILS_STABLE_TYPE_UUID; - const char * stable_id = global_opt.uuid; - int router_solicitation_interval; - int router_solicitations; - guint32 default_ra_timeout; - int max_addresses; - - nm_platform_link_set_inet6_addr_gen_mode(NM_PLATFORM_GET, - gl.ifindex, - NM_IN6_ADDR_GEN_MODE_NONE); - - if (global_opt.stable_id - && (global_opt.stable_id[0] >= '0' && global_opt.stable_id[0] <= '9') - && global_opt.stable_id[1] == ' ') { - /* strict parsing of --stable-id, which is the numeric stable-type - * and the ID, joined with one space. For now, only support stable-types - * from 0 to 9. */ - stable_type = (global_opt.stable_id[0] - '0'); - stable_id = &global_opt.stable_id[2]; - } - - nm_ndisc_get_sysctl(NM_PLATFORM_GET, - global_opt.ifname, - &max_addresses, - &router_solicitations, - &router_solicitation_interval, - &default_ra_timeout); - - ndisc = nm_lndp_ndisc_new(NM_PLATFORM_GET, - gl.ifindex, - global_opt.ifname, - stable_type, - stable_id, - global_opt.addr_gen_mode, - NM_NDISC_NODE_TYPE_HOST, - max_addresses, - router_solicitations, - router_solicitation_interval, - default_ra_timeout, - NULL); - g_assert(ndisc); - - if (iid) - nm_ndisc_set_iid(ndisc, *iid); - - nm_platform_sysctl_ip_conf_set(NM_PLATFORM_GET, - AF_INET6, - global_opt.ifname, - "accept_ra", - "0"); - - g_signal_connect(NM_PLATFORM_GET, - NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED, - G_CALLBACK(ip6_address_changed), - ndisc); - g_signal_connect(ndisc, NM_NDISC_CONFIG_RECEIVED, G_CALLBACK(ndisc_config_changed), NULL); - g_signal_connect(ndisc, NM_NDISC_RA_TIMEOUT_SIGNAL, G_CALLBACK(ndisc_ra_timeout), NULL); - nm_ndisc_start(ndisc); - } - - sd_id = nm_sd_event_attach_default(); - - g_main_loop_run(gl.main_loop); - - nm_clear_g_source(&gl.dad_failed_id); - nm_c_list_elem_free_all(&gl.dad_failed_lst_head, (GDestroyNotify) nmp_object_unref); - - if (pidfile && wrote_pidfile) - unlink(pidfile); - - _LOGI(LOGD_CORE, "exiting"); - - nm_clear_g_source(&sd_id); - nm_clear_pointer(&gl.main_loop, g_main_loop_unref); - return 0; -} - -/*****************************************************************************/ - -const NMDhcpClientFactory *const _nm_dhcp_manager_factories[6] = { - /* For nm-iface-helper there is no option to choose a DHCP plugin. - * It just uses the "internal" one. */ - &_nm_dhcp_client_factory_internal, -}; - -/*****************************************************************************/ -/* Stub functions */ - -#include "nm-config.h" -#include "devices/nm-device.h" -#include "nm-active-connection.h" -#include "nm-dbus-manager.h" - -void -nm_main_config_reload(int signal) -{ - _LOGI(LOGD_CORE, "reloading configuration not supported"); -} - -NMConfig * -nm_config_get(void) -{ - return GUINT_TO_POINTER(1); -} - -NMConfigData * -nm_config_get_data_orig(NMConfig *config) -{ - return GUINT_TO_POINTER(1); -} - -char * -nm_config_data_get_value(const NMConfigData * config_data, - const char * group, - const char * key, - NMConfigGetValueFlags flags) -{ - return NULL; -} - -NMConfigConfigureAndQuitType -nm_config_get_configure_and_quit(NMConfig *config) -{ - return NM_CONFIG_CONFIGURE_AND_QUIT_ENABLED; -} - -NMDBusManager * -nm_dbus_manager_get(void) -{ - return NULL; -} - -gboolean -nm_dbus_manager_is_stopping(NMDBusManager *self) -{ - return FALSE; -} - -void -_nm_dbus_manager_obj_export(NMDBusObject *obj) -{} - -void -_nm_dbus_manager_obj_unexport(NMDBusObject *obj) -{} - -void -_nm_dbus_manager_obj_notify(NMDBusObject *obj, guint n_pspecs, const GParamSpec *const *pspecs) -{} - -void -_nm_dbus_manager_obj_emit_signal(NMDBusObject * obj, - const NMDBusInterfaceInfoExtended *interface_info, - const GDBusSignalInfo * signal_info, - GVariant * args) -{} - -GType -nm_device_get_type(void) -{ - g_return_val_if_reached(0); -} - -GType -nm_active_connection_get_type(void) -{ - g_return_val_if_reached(0); -} diff --git a/src/core/nm-ip-config.c b/src/core/nm-ip-config.c index 2426eb49..b191b54b 100644 --- a/src/core/nm-ip-config.c +++ b/src/core/nm-ip-config.c @@ -8,31 +8,130 @@ #include "nm-ip-config.h" +#include + #include "nm-l3cfg.h" +#include "NetworkManagerUtils.h" + +/*****************************************************************************/ + +GType nm_ip4_config_get_type(void); +GType nm_ip6_config_get_type(void); + +/*****************************************************************************/ + +#define NM_IP_CONFIG_ADDRESS_DATA "address-data" +#define NM_IP_CONFIG_DNS_OPTIONS "dns-options" +#define NM_IP_CONFIG_DNS_PRIORITY "dns-priority" +#define NM_IP_CONFIG_DOMAINS "domains" +#define NM_IP_CONFIG_GATEWAY "gateway" +#define NM_IP_CONFIG_ROUTE_DATA "route-data" +#define NM_IP_CONFIG_SEARCHES "searches" /*****************************************************************************/ -NM_GOBJECT_PROPERTIES_DEFINE(NMIPConfig, PROP_L3CFG, PROP_IS_VPN, ); +typedef struct _NMIPConfigPrivate NMIPConfigPrivate; -typedef struct _NMIPConfigPrivate { - NML3Cfg *l3cfg; - bool is_vpn : 1; -} NMIPConfigPrivate; +NM_GOBJECT_PROPERTIES_DEFINE_FULL(_ip, + NMIPConfig, + PROP_IP_L3CFG, + PROP_IP_ADDRESS_DATA, + PROP_IP_GATEWAY, + PROP_IP_ROUTE_DATA, + PROP_IP_DOMAINS, + PROP_IP_SEARCHES, + PROP_IP_DNS_PRIORITY, + PROP_IP_DNS_OPTIONS, ); G_DEFINE_ABSTRACT_TYPE(NMIPConfig, nm_ip_config, NM_TYPE_DBUS_OBJECT) -#define NM_IP_CONFIG_GET_PRIVATE(self) _NM_GET_PRIVATE_PTR(self, NMIPConfig, NM_IS_IP_CONFIG) +#define NM_IP_CONFIG_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMIPConfig, NM_IS_IP_CONFIG) + +/*****************************************************************************/ + +static void _handle_platform_change(NMIPConfig *self, guint32 obj_type_flags, gboolean is_init); +static void _handle_l3cd_changed(NMIPConfig *self, const NML3ConfigData *l3cd); /*****************************************************************************/ static void -get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +_value_set_variant_as(GValue *value, const char *const *strv, guint len) { - NMIPConfig * self = NM_IP_CONFIG(object); - NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE(self); + if (len > 0) { + nm_assert(strv && strv[0]); + g_value_set_variant(value, g_variant_new_strv((const char *const *) strv, len)); + } else + g_value_set_variant(value, nm_g_variant_singleton_as()); +} + +/*****************************************************************************/ + +static void +_l3cfg_notify_cb(NML3Cfg *l3cfg, const NML3ConfigNotifyData *notify_data, NMIPConfig *self) +{ + switch (notify_data->notify_type) { + case NM_L3_CONFIG_NOTIFY_TYPE_L3CD_CHANGED: + if (notify_data->l3cd_changed.commited) + _handle_l3cd_changed(self, notify_data->l3cd_changed.l3cd_new); + break; + case NM_L3_CONFIG_NOTIFY_TYPE_PLATFORM_CHANGE_ON_IDLE: + _handle_platform_change(self, notify_data->platform_change_on_idle.obj_type_flags, FALSE); + break; + default: + break; + } +} + +/*****************************************************************************/ + +static void +get_property_ip(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +{ + NMIPConfig *self = NM_IP_CONFIG(object); + NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE(self); + const int addr_family = nm_ip_config_get_addr_family(self); + char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN]; + const char *const *strv; + guint len; + int v_i; - (void) priv; switch (prop_id) { + case PROP_IP_ADDRESS_DATA: + g_value_set_variant(value, priv->v_address_data); + break; + case PROP_IP_GATEWAY: + if (priv->v_gateway.best_default_route) { + const NMIPAddr *gateway; + + gateway = nm_platform_ip_route_get_gateway( + addr_family, + NMP_OBJECT_CAST_IP_ROUTE(priv->v_gateway.best_default_route)); + g_value_set_variant( + value, + g_variant_new_string(nm_utils_inet_ntop(addr_family, gateway, sbuf_addr))); + } else + g_value_set_variant(value, nm_g_variant_singleton_s_empty()); + break; + case PROP_IP_ROUTE_DATA: + g_value_set_variant(value, priv->v_route_data); + break; + case PROP_IP_DOMAINS: + strv = nm_l3_config_data_get_domains(priv->l3cd, addr_family, &len); + _value_set_variant_as(value, strv, len); + break; + case PROP_IP_SEARCHES: + strv = nm_l3_config_data_get_searches(priv->l3cd, addr_family, &len); + _value_set_variant_as(value, strv, len); + break; + case PROP_IP_DNS_PRIORITY: + v_i = nm_l3_config_data_get_dns_priority_or_default(priv->l3cd, addr_family); + g_value_set_variant(value, + (v_i == 0) ? nm_g_variant_singleton_i_0() : g_variant_new_int32(v_i)); + break; + case PROP_IP_DNS_OPTIONS: + strv = nm_l3_config_data_get_dns_options(priv->l3cd, addr_family, &len); + _value_set_variant_as(value, strv, len); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; @@ -42,18 +141,16 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - NMIPConfig * self = NM_IP_CONFIG(object); + NMIPConfig *self = NM_IP_CONFIG(object); NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE(self); + gpointer ptr; switch (prop_id) { - case PROP_L3CFG: - /* construct-only */ - priv->l3cfg = nm_g_object_ref(g_value_get_pointer(value)); - nm_assert(!priv->l3cfg || NM_IS_L3CFG(priv->l3cfg)); - break; - case PROP_IS_VPN: + case PROP_IP_L3CFG: /* construct-only */ - priv->is_vpn = g_value_get_boolean(value); + ptr = g_value_get_pointer(value); + nm_assert(NM_IS_L3CFG(ptr)); + priv->l3cfg = g_object_ref(ptr); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); @@ -65,16 +162,10 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps static void nm_ip_config_init(NMIPConfig *self) -{ - NMIPConfigPrivate *priv; - - priv = G_TYPE_INSTANCE_GET_PRIVATE(self, NM_TYPE_IP_CONFIG, NMIPConfigPrivate); - - self->_priv = priv; -} +{} NMIPConfig * -nm_ip_config_new(int addr_family, NML3Cfg *l3cfg, gboolean is_vpn) +nm_ip_config_new(int addr_family, NML3Cfg *l3cfg) { nm_assert_addr_family(addr_family); nm_assert(NM_L3CFG(l3cfg)); @@ -83,18 +174,50 @@ nm_ip_config_new(int addr_family, NML3Cfg *l3cfg, gboolean is_vpn) : nm_ip6_config_get_type(), NM_IP_CONFIG_L3CFG, l3cfg, - NM_IP_CONFIG_IS_VPN, - is_vpn, NULL); } +static void +constructed(GObject *object) +{ + NMIPConfig *self = NM_IP_CONFIG(object); + NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE(self); + + priv->l3cfg_notify_id = + g_signal_connect(priv->l3cfg, NM_L3CFG_SIGNAL_NOTIFY, G_CALLBACK(_l3cfg_notify_cb), self); + + priv->l3cd = nm_l3_config_data_ref(nm_l3cfg_get_combined_l3cd(priv->l3cfg, TRUE)); + + _handle_platform_change(self, ~((guint32) 0u), TRUE); + + G_OBJECT_CLASS(nm_ip_config_parent_class)->constructed(object); +} + +void +nm_ip_config_take_and_unexport_on_idle(NMIPConfig *self_take) +{ + if (self_take) + nm_dbus_object_unexport_on_idle(g_steal_pointer(&self_take)); +} + static void finalize(GObject *object) { - NMIPConfig * self = NM_IP_CONFIG(object); + NMIPConfig *self = NM_IP_CONFIG(object); NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE(self); - nm_g_object_unref(priv->l3cfg); + nm_clear_g_signal_handler(priv->l3cfg, &priv->l3cfg_notify_id); + + g_object_unref(priv->l3cfg); + + nm_g_variant_unref(priv->v_address_data); + nm_g_variant_unref(priv->v_addresses); + nm_g_variant_unref(priv->v_route_data); + nm_g_variant_unref(priv->v_routes); + + nmp_object_unref(priv->v_gateway.best_default_route); + + nm_l3_config_data_unref(priv->l3cd); G_OBJECT_CLASS(nm_ip_config_parent_class)->finalize(object); } @@ -102,26 +225,680 @@ finalize(GObject *object) static void nm_ip_config_class_init(NMIPConfigClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); + NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - g_type_class_add_private(object_class, sizeof(NMIPConfigPrivate)); - - object_class->get_property = get_property; + object_class->get_property = get_property_ip; object_class->set_property = set_property; + object_class->constructed = constructed; object_class->finalize = finalize; - obj_properties[PROP_L3CFG] = + dbus_object_class->export_on_construction = TRUE; + + obj_properties_ip[PROP_IP_L3CFG] = g_param_spec_pointer(NM_IP_CONFIG_L3CFG, "", "", G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_IS_VPN] = - g_param_spec_boolean(NM_IP_CONFIG_IS_VPN, + obj_properties_ip[PROP_IP_ADDRESS_DATA] = + g_param_spec_variant(NM_IP_CONFIG_ADDRESS_DATA, "", "", - FALSE, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + G_VARIANT_TYPE("aa{sv}"), + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + obj_properties_ip[PROP_IP_GATEWAY] = + g_param_spec_variant(NM_IP_CONFIG_GATEWAY, + "", + "", + G_VARIANT_TYPE("s"), + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + obj_properties_ip[PROP_IP_ROUTE_DATA] = + g_param_spec_variant(NM_IP_CONFIG_ROUTE_DATA, + "", + "", + G_VARIANT_TYPE("aa{sv}"), + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + obj_properties_ip[PROP_IP_DOMAINS] = + g_param_spec_variant(NM_IP_CONFIG_DOMAINS, + "", + "", + G_VARIANT_TYPE("as"), + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + obj_properties_ip[PROP_IP_SEARCHES] = + g_param_spec_variant(NM_IP_CONFIG_SEARCHES, + "", + "", + G_VARIANT_TYPE("as"), + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + obj_properties_ip[PROP_IP_DNS_PRIORITY] = + g_param_spec_variant(NM_IP_CONFIG_DNS_PRIORITY, + "", + "", + G_VARIANT_TYPE("i"), + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + obj_properties_ip[PROP_IP_DNS_OPTIONS] = + g_param_spec_variant(NM_IP_CONFIG_DNS_OPTIONS, + "", + "", + G_VARIANT_TYPE("as"), + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST_ip, obj_properties_ip); +} + +/*****************************************************************************/ + +/* public */ +#define NM_IP4_CONFIG_NAMESERVER_DATA "nameserver-data" +#define NM_IP4_CONFIG_WINS_SERVER_DATA "wins-server-data" + +/* deprecated */ +#define NM_IP4_CONFIG_ADDRESSES "addresses" +#define NM_IP4_CONFIG_NAMESERVERS "nameservers" +#define NM_IP4_CONFIG_ROUTES "routes" +#define NM_IP4_CONFIG_WINS_SERVERS "wins-servers" + +typedef struct _NMIP4Config NMIP4Config; +typedef struct _NMIP4ConfigClass NMIP4ConfigClass; + +NM_GOBJECT_PROPERTIES_DEFINE_FULL(_ip4, + NMIP4Config, + PROP_IP4_ADDRESSES, + PROP_IP4_NAMESERVERS, + PROP_IP4_NAMESERVER_DATA, + PROP_IP4_ROUTES, + PROP_IP4_WINS_SERVERS, + PROP_IP4_WINS_SERVER_DATA, ); + +struct _NMIP4Config { + NMIPConfig parent; +}; + +struct _NMIP4ConfigClass { + NMIPConfigClass parent; +}; + +G_DEFINE_TYPE(NMIP4Config, nm_ip4_config, NM_TYPE_IP_CONFIG) + +static void +get_property_ip4(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +{ + NMIPConfig *self = NM_IP_CONFIG(object); + NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE(self); + char addr_str[NM_UTILS_INET_ADDRSTRLEN]; + GVariantBuilder builder; + const in_addr_t *addrs; + guint len; + guint i; + + switch (prop_id) { + case PROP_IP4_ADDRESSES: + g_value_set_variant(value, priv->v_addresses); + break; + case PROP_IP4_ROUTES: + g_value_set_variant(value, priv->v_routes); + break; + case PROP_IP4_NAMESERVERS: + addrs = nm_l3_config_data_get_nameservers(priv->l3cd, AF_INET, &len); + g_value_set_variant(value, + (len == 0) ? nm_g_variant_singleton_au() + : nm_g_variant_new_au(addrs, len)); + break; + case PROP_IP4_NAMESERVER_DATA: + addrs = nm_l3_config_data_get_nameservers(priv->l3cd, AF_INET, &len); + if (len == 0) + g_value_set_variant(value, nm_g_variant_singleton_aaLsvI()); + else { + g_variant_builder_init(&builder, G_VARIANT_TYPE("aa{sv}")); + for (i = 0; i < len; i++) { + GVariantBuilder nested_builder; + + _nm_utils_inet4_ntop(addrs[i], addr_str); + + g_variant_builder_init(&nested_builder, G_VARIANT_TYPE("a{sv}")); + g_variant_builder_add(&nested_builder, + "{sv}", + "address", + g_variant_new_string(addr_str)); + g_variant_builder_add(&builder, "a{sv}", &nested_builder); + } + + g_value_take_variant(value, g_variant_builder_end(&builder)); + } + break; + case PROP_IP4_WINS_SERVERS: + addrs = nm_l3_config_data_get_wins(priv->l3cd, &len); + g_value_set_variant(value, + (len == 0) ? nm_g_variant_singleton_au() + : nm_g_variant_new_au(addrs, len)); + break; + case PROP_IP4_WINS_SERVER_DATA: + addrs = nm_l3_config_data_get_wins(priv->l3cd, &len); + if (len == 0) + g_value_set_variant(value, nm_g_variant_singleton_as()); + else { + g_variant_builder_init(&builder, G_VARIANT_TYPE("as")); + for (i = 0; i < len; i++) + g_variant_builder_add(&builder, "s", _nm_utils_inet4_ntop(addrs[i], addr_str)); + g_value_take_variant(value, g_variant_builder_end(&builder)); + } + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +static const NMDBusInterfaceInfoExtended interface_info_ip4_config = { + .parent = NM_DEFINE_GDBUS_INTERFACE_INFO_INIT( + NM_DBUS_INTERFACE_IP4_CONFIG, + .properties = NM_DEFINE_GDBUS_PROPERTY_INFOS( + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Addresses", + "aau", + NM_IP4_CONFIG_ADDRESSES), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("AddressData", + "aa{sv}", + NM_IP_CONFIG_ADDRESS_DATA), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Gateway", "s", NM_IP_CONFIG_GATEWAY), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Routes", "aau", NM_IP4_CONFIG_ROUTES), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("RouteData", + "aa{sv}", + NM_IP_CONFIG_ROUTE_DATA), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("NameserverData", + "aa{sv}", + NM_IP4_CONFIG_NAMESERVER_DATA), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Nameservers", + "au", + NM_IP4_CONFIG_NAMESERVERS), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Domains", "as", NM_IP_CONFIG_DOMAINS), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Searches", "as", NM_IP_CONFIG_SEARCHES), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("DnsOptions", + "as", + NM_IP_CONFIG_DNS_OPTIONS), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("DnsPriority", + "i", + NM_IP_CONFIG_DNS_PRIORITY), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("WinsServerData", + "as", + NM_IP4_CONFIG_WINS_SERVER_DATA), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("WinsServers", + "au", + NM_IP4_CONFIG_WINS_SERVERS), ), ), +}; + +static void +nm_ip4_config_init(NMIP4Config *self) +{} + +static void +nm_ip4_config_class_init(NMIP4ConfigClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS(klass); + NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); + NMIPConfigClass *ip_config_class = NM_IP_CONFIG_CLASS(klass); + + ip_config_class->addr_family = AF_INET; + + dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_NUMBERED(NM_DBUS_PATH "/IP4Config"); + dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS(&interface_info_ip4_config); + + object_class->get_property = get_property_ip4; + + obj_properties_ip4[PROP_IP4_ADDRESSES] = + g_param_spec_variant(NM_IP4_CONFIG_ADDRESSES, + "", + "", + G_VARIANT_TYPE("aau"), + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + obj_properties_ip4[PROP_IP4_ROUTES] = + g_param_spec_variant(NM_IP4_CONFIG_ROUTES, + "", + "", + G_VARIANT_TYPE("aau"), + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + obj_properties_ip4[PROP_IP4_NAMESERVER_DATA] = + g_param_spec_variant(NM_IP4_CONFIG_NAMESERVER_DATA, + "", + "", + G_VARIANT_TYPE("aa{sv}"), + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + obj_properties_ip4[PROP_IP4_NAMESERVERS] = + g_param_spec_variant(NM_IP4_CONFIG_NAMESERVERS, + "", + "", + G_VARIANT_TYPE("au"), + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + obj_properties_ip4[PROP_IP4_WINS_SERVER_DATA] = + g_param_spec_variant(NM_IP4_CONFIG_WINS_SERVER_DATA, + "", + "", + G_VARIANT_TYPE("as"), + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + obj_properties_ip4[PROP_IP4_WINS_SERVERS] = + g_param_spec_variant(NM_IP4_CONFIG_WINS_SERVERS, + "", + "", + G_VARIANT_TYPE("au"), + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST_ip4, obj_properties_ip4); +} + +void +nm_ip_config_dns_hash(const NML3ConfigData *l3cd, GChecksum *sum, int addr_family) +{ + guint i; + int val; + const char *const *nameservers; + const in_addr_t *wins; + const char *const *domains; + const char *const *searches; + const char *const *options; + guint num_nameservers; + guint num_wins; + guint num_domains; + guint num_searches; + guint num_options; + + g_return_if_fail(l3cd); + g_return_if_fail(sum); + + nameservers = nm_l3_config_data_get_nameservers(l3cd, addr_family, &num_nameservers); + for (i = 0; i < num_nameservers; i++) { + g_checksum_update(sum, + nm_ip_addr_from_packed_array(addr_family, nameservers, i), + nm_utils_addr_family_to_size(addr_family)); + } + + if (addr_family == AF_INET) { + wins = nm_l3_config_data_get_wins(l3cd, &num_wins); + for (i = 0; i < num_wins; i++) + g_checksum_update(sum, (guint8 *) &wins[i], 4); + } + + domains = nm_l3_config_data_get_domains(l3cd, addr_family, &num_domains); + for (i = 0; i < num_domains; i++) { + g_checksum_update(sum, (const guint8 *) domains[i], strlen(domains[i])); + } + + searches = nm_l3_config_data_get_searches(l3cd, addr_family, &num_searches); + for (i = 0; i < num_searches; i++) { + g_checksum_update(sum, (const guint8 *) searches[i], strlen(searches[i])); + } + + options = nm_l3_config_data_get_dns_options(l3cd, addr_family, &num_options); + for (i = 0; i < num_options; i++) { + g_checksum_update(sum, (const guint8 *) options[i], strlen(options[i])); + } + + val = nm_l3_config_data_get_mdns(l3cd); + if (val != NM_SETTING_CONNECTION_MDNS_DEFAULT) + g_checksum_update(sum, (const guint8 *) &val, sizeof(val)); + + val = nm_l3_config_data_get_llmnr(l3cd); + if (val != NM_SETTING_CONNECTION_LLMNR_DEFAULT) + g_checksum_update(sum, (const guint8 *) &val, sizeof(val)); + + val = nm_l3_config_data_get_dns_over_tls(l3cd); + if (val != NM_SETTING_CONNECTION_DNS_OVER_TLS_DEFAULT) + g_checksum_update(sum, (const guint8 *) &val, sizeof(val)); + + /* FIXME(ip-config-checksum): the DNS priority should be considered relevant + * and added into the checksum as well, but this can't be done right now + * because in the DNS manager we rely on the fact that an empty + * configuration (i.e. just created) has a zero checksum. This is needed to + * avoid rewriting resolv.conf when there is no change. + * + * The DNS priority initial value depends on the connection type (VPN or + * not), so it's a bit difficult to add it to checksum maintaining the + * assumption of checksum(empty)=0 + */ +} + +/*****************************************************************************/ + +/* public */ +#define NM_IP6_CONFIG_NAMESERVERS "nameservers" + +/* deprecated */ +#define NM_IP6_CONFIG_ADDRESSES "addresses" +#define NM_IP6_CONFIG_ROUTES "routes" + +typedef struct _NMIP6Config NMIP6Config; +typedef struct _NMIP6ConfigClass NMIP6ConfigClass; + +NM_GOBJECT_PROPERTIES_DEFINE_FULL(_ip6, + NMIP6Config, + PROP_IP6_NAMESERVERS, + PROP_IP6_ADDRESSES, + PROP_IP6_ROUTES, ); + +struct _NMIP6Config { + NMIPConfig parent; +}; + +struct _NMIP6ConfigClass { + NMIPConfigClass parent; +}; + +G_DEFINE_TYPE(NMIP6Config, nm_ip6_config, NM_TYPE_IP_CONFIG) + +static const NMDBusInterfaceInfoExtended interface_info_ip6_config = { + .parent = NM_DEFINE_GDBUS_INTERFACE_INFO_INIT( + NM_DBUS_INTERFACE_IP6_CONFIG, + .properties = NM_DEFINE_GDBUS_PROPERTY_INFOS( + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Addresses", + "a(ayuay)", + NM_IP6_CONFIG_ADDRESSES), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("AddressData", + "aa{sv}", + NM_IP_CONFIG_ADDRESS_DATA), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Gateway", "s", NM_IP_CONFIG_GATEWAY), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Routes", + "a(ayuayu)", + NM_IP6_CONFIG_ROUTES), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("RouteData", + "aa{sv}", + NM_IP_CONFIG_ROUTE_DATA), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Nameservers", + "aay", + NM_IP6_CONFIG_NAMESERVERS), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Domains", "as", NM_IP_CONFIG_DOMAINS), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Searches", "as", NM_IP_CONFIG_SEARCHES), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("DnsOptions", + "as", + NM_IP_CONFIG_DNS_OPTIONS), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("DnsPriority", + "i", + NM_IP_CONFIG_DNS_PRIORITY), ), ), +}; + +static void +get_property_ip6(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +{ + NMIPConfig *self = NM_IP_CONFIG(object); + NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE(self); + GVariantBuilder builder; + guint len; + guint i; + const struct in6_addr *addrs; + + switch (prop_id) { + case PROP_IP6_ADDRESSES: + g_value_set_variant(value, priv->v_addresses); + break; + case PROP_IP6_ROUTES: + g_value_set_variant(value, priv->v_routes); + break; + case PROP_IP6_NAMESERVERS: + addrs = nm_l3_config_data_get_nameservers(priv->l3cd, AF_INET6, &len); + if (len == 0) + g_value_set_variant(value, nm_g_variant_singleton_aay()); + else { + g_variant_builder_init(&builder, G_VARIANT_TYPE("aay")); + for (i = 0; i < len; i++) + g_variant_builder_add(&builder, "@ay", nm_g_variant_new_ay_in6addr(&addrs[i])); + g_value_take_variant(value, g_variant_builder_end(&builder)); + } + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +static void +nm_ip6_config_init(NMIP6Config *self) +{} + +static void +nm_ip6_config_class_init(NMIP6ConfigClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS(klass); + NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); + NMIPConfigClass *ip_config_class = NM_IP_CONFIG_CLASS(klass); + + ip_config_class->addr_family = AF_INET6; + + dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_NUMBERED(NM_DBUS_PATH "/IP6Config"); + dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS(&interface_info_ip6_config); + + object_class->get_property = get_property_ip6; + + obj_properties_ip6[PROP_IP6_ADDRESSES] = + g_param_spec_variant(NM_IP6_CONFIG_ADDRESSES, + "", + "", + G_VARIANT_TYPE("a(ayuay)"), + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + obj_properties_ip6[PROP_IP6_ROUTES] = + g_param_spec_variant(NM_IP6_CONFIG_ROUTES, + "", + "", + G_VARIANT_TYPE("a(ayuayu)"), + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + obj_properties_ip6[PROP_IP6_NAMESERVERS] = + g_param_spec_variant(NM_IP6_CONFIG_NAMESERVERS, + "", + "", + G_VARIANT_TYPE("aay"), + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST_ip6, obj_properties_ip6); +} + +/*****************************************************************************/ + +#define _notify_all(self, changed_params, n_changed_params) \ + G_STMT_START \ + { \ + NMIPConfig *const _self = (self); \ + const guint _n_changed_params = (n_changed_params); \ + GParamSpec *const *const _changed_params = (changed_params); \ + guint _i; \ + \ + if (_n_changed_params > 0) { \ + nm_assert(_n_changed_params <= G_N_ELEMENTS(changed_params)); \ + if (_n_changed_params > 1) \ + g_object_freeze_notify(G_OBJECT(_self)); \ + for (_i = 0; _i < _n_changed_params; _i++) \ + g_object_notify_by_pspec(G_OBJECT(_self), _changed_params[_i]); \ + if (_n_changed_params > 1) \ + g_object_thaw_notify(G_OBJECT(_self)); \ + } \ + } \ + G_STMT_END + +static void +_handle_l3cd_changed(NMIPConfig *self, const NML3ConfigData *l3cd) +{ + const int addr_family = nm_ip_config_get_addr_family(self); + const int IS_IPv4 = NM_IS_IPv4(addr_family); + NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE(self); + nm_auto_unref_l3cd const NML3ConfigData *l3cd_old = NULL; + GParamSpec *changed_params[8]; + guint n_changed_params = 0; + const char *const *strv; + const char *const *strv_old; + gconstpointer addrs; + gconstpointer addrs_old; + guint len; + guint len_old; + int v_i; + int v_i_old; + + l3cd_old = g_steal_pointer(&priv->l3cd); + priv->l3cd = nm_l3_config_data_ref(l3cd); + + addrs_old = nm_l3_config_data_get_nameservers(l3cd_old, addr_family, &len_old); + addrs = nm_l3_config_data_get_nameservers(priv->l3cd, addr_family, &len); + if (!nm_memeq_n(addrs_old, len_old, addrs, len, nm_utils_addr_family_to_size(addr_family))) { + if (IS_IPv4) { + changed_params[n_changed_params++] = obj_properties_ip4[PROP_IP4_NAMESERVER_DATA]; + changed_params[n_changed_params++] = obj_properties_ip4[PROP_IP4_NAMESERVERS]; + } else + changed_params[n_changed_params++] = obj_properties_ip6[PROP_IP6_NAMESERVERS]; + } + + strv_old = nm_l3_config_data_get_domains(l3cd_old, addr_family, &len_old); + strv = nm_l3_config_data_get_domains(priv->l3cd, addr_family, &len); + if (!nm_strv_equal_n(strv, len, strv_old, len_old)) + changed_params[n_changed_params++] = obj_properties_ip[PROP_IP_DOMAINS]; + + strv_old = nm_l3_config_data_get_searches(l3cd_old, addr_family, &len_old); + strv = nm_l3_config_data_get_searches(priv->l3cd, addr_family, &len); + if (!nm_strv_equal_n(strv, len, strv_old, len_old)) + changed_params[n_changed_params++] = obj_properties_ip[PROP_IP_SEARCHES]; + + v_i_old = nm_l3_config_data_get_dns_priority_or_default(l3cd_old, addr_family); + v_i = nm_l3_config_data_get_dns_priority_or_default(priv->l3cd, addr_family); + if (v_i != v_i_old) + changed_params[n_changed_params++] = obj_properties_ip[PROP_IP_DNS_PRIORITY]; + + strv_old = nm_l3_config_data_get_dns_options(l3cd_old, addr_family, &len); + strv = nm_l3_config_data_get_dns_options(priv->l3cd, addr_family, &len); + if (!nm_strv_equal_n(strv, len, strv_old, len_old)) + changed_params[n_changed_params++] = obj_properties_ip[PROP_IP_DNS_OPTIONS]; + + if (IS_IPv4) { + addrs_old = nm_l3_config_data_get_wins(l3cd_old, &len_old); + addrs = nm_l3_config_data_get_wins(priv->l3cd, &len); + if (!nm_memeq_n(addrs_old, len_old, addrs, len, sizeof(in_addr_t))) { + changed_params[n_changed_params++] = obj_properties_ip4[PROP_IP4_WINS_SERVER_DATA]; + changed_params[n_changed_params++] = obj_properties_ip4[PROP_IP4_WINS_SERVERS]; + } + } + + _notify_all(self, changed_params, n_changed_params); +} + +static void +_handle_platform_change(NMIPConfig *self, guint32 obj_type_flags, gboolean is_init) +{ + const int addr_family = nm_ip_config_get_addr_family(self); + const int IS_IPv4 = NM_IS_IPv4(addr_family); + NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE(self); + GParamSpec *changed_params[5]; + guint n_changed_params = 0; + const NMDedupMultiHeadEntry *head_entry_routes = NULL; + gboolean best_default_route_changed = FALSE; + + if (NM_FLAGS_ANY(obj_type_flags, + (nmp_object_type_to_flags(NMP_OBJECT_TYPE_IP_ADDRESS(IS_IPv4)) + | nmp_object_type_to_flags(NMP_OBJECT_TYPE_IP_ROUTE(IS_IPv4))))) { + const NMPObject *best_default_route = NULL; + + head_entry_routes = nm_platform_lookup_object(nm_l3cfg_get_platform(priv->l3cfg), + NMP_OBJECT_TYPE_IP_ROUTE(IS_IPv4), + nm_l3cfg_get_ifindex(priv->l3cfg)); + if (head_entry_routes) { + NMDedupMultiIter iter; + const NMPObject *obj; + + nm_dedup_multi_iter_init(&iter, head_entry_routes); + while (nm_platform_dedup_multi_iter_next_obj(&iter, + &obj, + NMP_OBJECT_TYPE_IP_ROUTE(IS_IPv4))) { + const NMPlatformIPXRoute *r = NMP_OBJECT_CAST_IPX_ROUTE(obj); + + /* Determine the gateway. That is the next hop of a route + * - 0.0.0.0/0 or ::/0 + * - type=unicast + * - table=main + */ + if (r->rx.plen != 0 + || r->rx.type_coerced != nm_platform_route_type_coerce(RTN_UNICAST) + || r->rx.table_coerced != nm_platform_route_table_coerce(RT_TABLE_MAIN) + || !nm_ip_addr_is_null(addr_family, r->rx.network_ptr)) + continue; + + if (!best_default_route + || NMP_OBJECT_CAST_IP_ROUTE(best_default_route)->metric > r->rx.metric) + best_default_route = obj; + } + } + + if (priv->v_gateway.best_default_route != best_default_route) { + if (!nm_ip_addr_equal( + addr_family, + nm_platform_ip_route_get_gateway( + addr_family, + NMP_OBJECT_CAST_IP_ROUTE(priv->v_gateway.best_default_route)), + nm_platform_ip_route_get_gateway(addr_family, + NMP_OBJECT_CAST_IP_ROUTE(best_default_route)))) + best_default_route_changed = TRUE; + + nmp_object_ref_set(&priv->v_gateway.best_default_route, best_default_route); + } + } + + if (best_default_route_changed + || NM_FLAGS_ANY(obj_type_flags, + nmp_object_type_to_flags(NMP_OBJECT_TYPE_IP_ADDRESS(IS_IPv4)))) { + gs_unref_variant GVariant *x_address_data = NULL; + gs_unref_variant GVariant *x_addresses = NULL; + + nm_utils_ip_addresses_to_dbus(addr_family, + nm_platform_lookup_object(nm_l3cfg_get_platform(priv->l3cfg), + NMP_OBJECT_TYPE_IP_ADDRESS(IS_IPv4), + nm_l3cfg_get_ifindex(priv->l3cfg)), + priv->v_gateway.best_default_route, + &x_address_data, + &x_addresses); + + if (!nm_g_variant_equal(priv->v_address_data, x_address_data)) { + changed_params[n_changed_params++] = obj_properties_ip[PROP_IP_ADDRESS_DATA]; + g_variant_ref_sink(x_address_data); + NM_SWAP(&priv->v_address_data, &x_address_data); + } + if (!nm_g_variant_equal(priv->v_addresses, x_addresses)) { + changed_params[n_changed_params++] = IS_IPv4 ? obj_properties_ip4[PROP_IP4_ADDRESSES] + : obj_properties_ip6[PROP_IP6_ADDRESSES]; + g_variant_ref_sink(x_addresses); + NM_SWAP(&priv->v_addresses, &x_addresses); + } + } + + if (best_default_route_changed) + changed_params[n_changed_params++] = obj_properties_ip[PROP_IP_GATEWAY]; + + if (NM_FLAGS_ANY(obj_type_flags, nmp_object_type_to_flags(NMP_OBJECT_TYPE_IP_ROUTE(IS_IPv4)))) { + gs_unref_variant GVariant *x_route_data = NULL; + gs_unref_variant GVariant *x_routes = NULL; + + nm_utils_ip_routes_to_dbus(addr_family, head_entry_routes, &x_route_data, &x_routes); + + if (!nm_g_variant_equal(priv->v_route_data, x_route_data)) { + changed_params[n_changed_params++] = obj_properties_ip[PROP_IP_ROUTE_DATA]; + g_variant_ref_sink(x_route_data); + NM_SWAP(&priv->v_route_data, &x_route_data); + } + if (!nm_g_variant_equal(priv->v_routes, x_routes)) { + changed_params[n_changed_params++] = + IS_IPv4 ? obj_properties_ip4[PROP_IP4_ROUTES] : obj_properties_ip6[PROP_IP6_ROUTES]; + g_variant_ref_sink(x_routes); + NM_SWAP(&priv->v_routes, &x_routes); + } + } - g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); + if (!is_init) + _notify_all(self, changed_params, n_changed_params); } diff --git a/src/core/nm-ip-config.h b/src/core/nm-ip-config.h index 8e1a5934..68103cf7 100644 --- a/src/core/nm-ip-config.h +++ b/src/core/nm-ip-config.h @@ -7,6 +7,7 @@ #define __NM_IP_CONFIG_H__ #include "nm-dbus-object.h" +#include "nm-l3cfg.h" /*****************************************************************************/ @@ -19,26 +20,67 @@ #define NM_IP_CONFIG_GET_CLASS(obj) \ (G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_IP_CONFIG, NMIPConfigClass)) -#define NM_IP_CONFIG_L3CFG "l3cfg" -#define NM_IP_CONFIG_IS_VPN "is-vpn" +#define NM_IP_CONFIG_L3CFG "l3cfg" -struct _NMIPConfigPrivate; +struct _NMIPConfigPrivate { + NML3Cfg *l3cfg; + const NML3ConfigData *l3cd; + GVariant *v_address_data; + GVariant *v_addresses; + GVariant *v_route_data; + GVariant *v_routes; + struct { + const NMPObject *best_default_route; + } v_gateway; + gulong l3cfg_notify_id; +}; struct _NMIPConfig { - NMDBusObject parent; - struct _NMIPConfigPrivate *_priv; + NMDBusObject parent; + struct _NMIPConfigPrivate _priv; }; typedef struct { NMDBusObjectClass parent; - gboolean is_ipv4; int addr_family; } NMIPConfigClass; GType nm_ip_config_get_type(void); -GType nm_ip4_config_get_type(void); -GType nm_ip6_config_get_type(void); -NMIPConfig *nm_ip_config_new(int addr_family, NML3Cfg *l3cfg, gboolean is_vpn); +NMIPConfig *nm_ip_config_new(int addr_family, NML3Cfg *l3cfg); + +void nm_ip_config_take_and_unexport_on_idle(NMIPConfig *self_take); + +void nm_ip_config_dns_hash(const NML3ConfigData *l3cd, GChecksum *sum, int addr_family); + +/*****************************************************************************/ + +static inline NML3Cfg * +nm_ip_config_get_l3cfg(NMIPConfig *self) +{ + g_return_val_if_fail(NM_IS_IP_CONFIG(self), NULL); + + return self->_priv.l3cfg; +} + +static inline struct _NMDedupMultiIndex * +nm_ip_config_get_multi_index(NMIPConfig *self) +{ + return nm_l3cfg_get_multi_idx(nm_ip_config_get_l3cfg(self)); +} + +static inline int +nm_ip_config_get_ifindex(NMIPConfig *self) +{ + return nm_l3cfg_get_ifindex(nm_ip_config_get_l3cfg(self)); +} + +static inline int +nm_ip_config_get_addr_family(NMIPConfig *self) +{ + g_return_val_if_fail(NM_IS_IP_CONFIG(self), AF_UNSPEC); + + return NM_IP_CONFIG_GET_CLASS(self)->addr_family; +} #endif /* __NM_IP_CONFIG_H__ */ diff --git a/src/core/nm-ip4-config.c b/src/core/nm-ip4-config.c deleted file mode 100644 index 90398dcc..00000000 --- a/src/core/nm-ip4-config.c +++ /dev/null @@ -1,3337 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2005 - 2017 Red Hat, Inc. - * Copyright (C) 2006 - 2008 Novell, Inc. - */ - -#include "src/core/nm-default-daemon.h" - -#include "nm-ip4-config.h" - -#include -#include -#include - -#include "libnm-glib-aux/nm-dedup-multi.h" - -#include "nm-utils.h" -#include "libnm-platform/nmp-object.h" -#include "libnm-platform/nm-platform.h" -#include "libnm-platform/nm-platform-utils.h" -#include "NetworkManagerUtils.h" -#include "libnm-core-intern/nm-core-internal.h" -#include "nm-dbus-object.h" - -/*****************************************************************************/ - -/* internal guint32 are assigned to gobject properties of type uint. Ensure, that uint is large enough */ -G_STATIC_ASSERT(sizeof(uint) >= sizeof(guint32)); -G_STATIC_ASSERT(G_MAXUINT >= 0xFFFFFFFF); - -/*****************************************************************************/ - -static gboolean -_route_valid(const NMPlatformIP4Route *r) -{ - return r && r->plen <= 32 - && r->network == nm_utils_ip4_address_clear_host_address(r->network, r->plen); -} - -/*****************************************************************************/ - -static void -_idx_obj_id_hash_update(const NMDedupMultiIdxType *idx_type, - const NMDedupMultiObj * obj, - NMHashState * h) -{ - nmp_object_id_hash_update((NMPObject *) obj, h); -} - -static gboolean -_idx_obj_id_equal(const NMDedupMultiIdxType *idx_type, - const NMDedupMultiObj * obj_a, - const NMDedupMultiObj * obj_b) -{ - return nmp_object_id_equal((NMPObject *) obj_a, (NMPObject *) obj_b); -} - -void -nm_ip_config_dedup_multi_idx_type_init(NMIPConfigDedupMultiIdxType *idx_type, - NMPObjectType obj_type) -{ - static const NMDedupMultiIdxTypeClass idx_type_class = { - .idx_obj_id_hash_update = _idx_obj_id_hash_update, - .idx_obj_id_equal = _idx_obj_id_equal, - }; - - nm_dedup_multi_idx_type_init((NMDedupMultiIdxType *) idx_type, &idx_type_class); - idx_type->obj_type = obj_type; -} - -/*****************************************************************************/ - -gboolean -_nm_ip_config_add_obj(NMDedupMultiIndex * multi_idx, - NMIPConfigDedupMultiIdxType *idx_type, - int ifindex, - const NMPObject * obj_new, - const NMPlatformObject * pl_new, - gboolean merge, - gboolean append_force, - const NMPObject ** out_obj_old /* returns a reference! */, - const NMPObject ** out_obj_new /* does not return a reference */) -{ - NMPObject obj_new_stackinit; - const NMDedupMultiEntry *entry_old; - const NMDedupMultiEntry *entry_new; - - nm_assert(multi_idx); - nm_assert(idx_type); - nm_assert(NM_IN_SET(idx_type->obj_type, - NMP_OBJECT_TYPE_IP4_ADDRESS, - NMP_OBJECT_TYPE_IP4_ROUTE, - NMP_OBJECT_TYPE_IP6_ADDRESS, - NMP_OBJECT_TYPE_IP6_ROUTE)); - nm_assert(ifindex > 0); - - /* we go through extra lengths to accept a full obj_new object. That one, - * can be reused by increasing the ref-count. */ - if (!obj_new) { - nm_assert(pl_new); - obj_new = nmp_object_stackinit(&obj_new_stackinit, idx_type->obj_type, pl_new); - NMP_OBJECT_CAST_OBJ_WITH_IFINDEX(&obj_new_stackinit)->ifindex = ifindex; - } else { - nm_assert(!pl_new); - nm_assert(NMP_OBJECT_GET_TYPE(obj_new) == idx_type->obj_type); - if (NMP_OBJECT_CAST_OBJ_WITH_IFINDEX(obj_new)->ifindex != ifindex) { - obj_new = nmp_object_stackinit_obj(&obj_new_stackinit, obj_new); - NMP_OBJECT_CAST_OBJ_WITH_IFINDEX(&obj_new_stackinit)->ifindex = ifindex; - } - } - nm_assert(NMP_OBJECT_GET_TYPE(obj_new) == idx_type->obj_type); - nm_assert(nmp_object_is_alive(obj_new)); - - entry_old = nm_dedup_multi_index_lookup_obj(multi_idx, &idx_type->parent, obj_new); - - if (entry_old) { - gboolean modified = FALSE; - const NMPObject *obj_old = entry_old->obj; - - if (nmp_object_equal(obj_new, obj_old)) { - nm_dedup_multi_entry_set_dirty(entry_old, FALSE); - goto append_force_and_out; - } - - /* if @merge, we merge the new object with the existing one. - * Otherwise, we replace it entirely. */ - if (merge) { - switch (idx_type->obj_type) { - case NMP_OBJECT_TYPE_IP4_ADDRESS: - case NMP_OBJECT_TYPE_IP6_ADDRESS: - /* for addresses that we read from the kernel, we keep the timestamps as defined - * by the previous source (item_old). The reason is, that the other source configured the lifetimes - * with "what should be" and the kernel values are "what turned out after configuring it". - * - * For other sources, the longer lifetime wins. */ - if ((obj_new->ip_address.addr_source == NM_IP_CONFIG_SOURCE_KERNEL - && obj_old->ip_address.addr_source != NM_IP_CONFIG_SOURCE_KERNEL) - || nm_platform_ip_address_cmp_expiry(NMP_OBJECT_CAST_IP_ADDRESS(obj_old), - NMP_OBJECT_CAST_IP_ADDRESS(obj_new)) - > 0) { - obj_new = nmp_object_stackinit_obj(&obj_new_stackinit, obj_new); - obj_new_stackinit.ip_address.timestamp = - NMP_OBJECT_CAST_IP_ADDRESS(obj_old)->timestamp; - obj_new_stackinit.ip_address.lifetime = - NMP_OBJECT_CAST_IP_ADDRESS(obj_old)->lifetime; - obj_new_stackinit.ip_address.preferred = - NMP_OBJECT_CAST_IP_ADDRESS(obj_old)->preferred; - modified = TRUE; - } - - /* keep the maximum addr_source. */ - if (obj_new->ip_address.addr_source < obj_old->ip_address.addr_source) { - obj_new = nmp_object_stackinit_obj(&obj_new_stackinit, obj_new); - obj_new_stackinit.ip_address.addr_source = obj_old->ip_address.addr_source; - modified = TRUE; - } - break; - case NMP_OBJECT_TYPE_IP4_ROUTE: - case NMP_OBJECT_TYPE_IP6_ROUTE: - /* keep the maximum rt_source. */ - if (obj_new->ip_route.rt_source < obj_old->ip_route.rt_source) { - obj_new = nmp_object_stackinit_obj(&obj_new_stackinit, obj_new); - obj_new_stackinit.ip_route.rt_source = obj_old->ip_route.rt_source; - modified = TRUE; - } - if (!obj_new->ip_route.is_external && obj_old->ip_route.is_external) { - obj_new = nmp_object_stackinit_obj(&obj_new_stackinit, obj_new); - obj_new_stackinit.ip_route.is_external = FALSE; - modified = TRUE; - } - break; - default: - nm_assert_not_reached(); - break; - } - - if (modified && nmp_object_equal(obj_new, obj_old)) { - nm_dedup_multi_entry_set_dirty(entry_old, FALSE); - goto append_force_and_out; - } - } - } - - if (!nm_dedup_multi_index_add_full(multi_idx, - &idx_type->parent, - obj_new, - append_force ? NM_DEDUP_MULTI_IDX_MODE_APPEND_FORCE - : NM_DEDUP_MULTI_IDX_MODE_APPEND, - NULL, - entry_old ?: NM_DEDUP_MULTI_ENTRY_MISSING, - NULL, - &entry_new, - out_obj_old)) { - nm_assert_not_reached(); - NM_SET_OUT(out_obj_new, NULL); - return FALSE; - } - - NM_SET_OUT(out_obj_new, entry_new->obj); - return TRUE; - -append_force_and_out: - NM_SET_OUT(out_obj_old, nmp_object_ref(entry_old->obj)); - NM_SET_OUT(out_obj_new, entry_old->obj); - if (append_force) { - if (nm_dedup_multi_entry_reorder(entry_old, NULL, TRUE)) - return TRUE; - } - return FALSE; -} - -/** - * _nm_ip_config_lookup_ip_route: - * @multi_idx: - * @idx_type: - * @needle: - * @cmp_type: after lookup, filter the result by comparing with @cmp_type. Only - * return the result, if it compares equal to @needle according to this @cmp_type. - * Note that the index uses %NM_PLATFORM_IP_ROUTE_CMP_TYPE_DST type, so passing - * that compare-type means not to filter any further. - * - * Returns: the found entry or %NULL. - */ -const NMDedupMultiEntry * -_nm_ip_config_lookup_ip_route(const NMDedupMultiIndex * multi_idx, - const NMIPConfigDedupMultiIdxType *idx_type, - const NMPObject * needle, - NMPlatformIPRouteCmpType cmp_type) -{ - const NMDedupMultiEntry *entry; - - nm_assert(multi_idx); - nm_assert(idx_type); - nm_assert(NM_IN_SET(idx_type->obj_type, NMP_OBJECT_TYPE_IP4_ROUTE, NMP_OBJECT_TYPE_IP6_ROUTE)); - nm_assert(NMP_OBJECT_GET_TYPE(needle) == idx_type->obj_type); - - entry = nm_dedup_multi_index_lookup_obj(multi_idx, &idx_type->parent, needle); - if (!entry) - return NULL; - - if (cmp_type == NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID) { - nm_assert((NMP_OBJECT_GET_TYPE(needle) == NMP_OBJECT_TYPE_IP4_ROUTE - && nm_platform_ip4_route_cmp(NMP_OBJECT_CAST_IP4_ROUTE(entry->obj), - NMP_OBJECT_CAST_IP4_ROUTE(needle), - cmp_type) - == 0) - || (NMP_OBJECT_GET_TYPE(needle) == NMP_OBJECT_TYPE_IP6_ROUTE - && nm_platform_ip6_route_cmp(NMP_OBJECT_CAST_IP6_ROUTE(entry->obj), - NMP_OBJECT_CAST_IP6_ROUTE(needle), - cmp_type) - == 0)); - } else { - if (NMP_OBJECT_GET_TYPE(needle) == NMP_OBJECT_TYPE_IP4_ROUTE) { - if (nm_platform_ip4_route_cmp(NMP_OBJECT_CAST_IP4_ROUTE(entry->obj), - NMP_OBJECT_CAST_IP4_ROUTE(needle), - cmp_type) - != 0) - return NULL; - } else { - if (nm_platform_ip6_route_cmp(NMP_OBJECT_CAST_IP6_ROUTE(entry->obj), - NMP_OBJECT_CAST_IP6_ROUTE(needle), - cmp_type) - != 0) - return NULL; - } - } - return entry; -} - -/*****************************************************************************/ - -NM_GOBJECT_PROPERTIES_DEFINE(NMIP4Config, - PROP_MULTI_IDX, - PROP_IFINDEX, - PROP_ADDRESS_DATA, - PROP_ADDRESSES, - PROP_ROUTE_DATA, - PROP_ROUTES, - PROP_GATEWAY, - PROP_NAMESERVER_DATA, - PROP_NAMESERVERS, - PROP_DOMAINS, - PROP_SEARCHES, - PROP_DNS_OPTIONS, - PROP_WINS_SERVER_DATA, - PROP_WINS_SERVERS, - PROP_DNS_PRIORITY, ); - -typedef struct { - bool metered : 1; - bool never_default : 1; - guint32 mtu; - int ifindex; - NMIPConfigSource mtu_source; - int dns_priority; - NMSettingConnectionMdns mdns; - NMSettingConnectionLlmnr llmnr; - NMSettingConnectionDnsOverTls dns_over_tls; - GArray * nameservers; - GPtrArray * domains; - GPtrArray * searches; - GPtrArray * dns_options; - GArray * nis; - char * nis_domain; - GArray * wins; - GVariant * address_data_variant; - GVariant * addresses_variant; - GVariant * route_data_variant; - GVariant * routes_variant; - NMDedupMultiIndex * multi_idx; - const NMPObject * best_default_route; - union { - NMIPConfigDedupMultiIdxType idx_ip4_addresses_; - NMDedupMultiIdxType idx_ip4_addresses; - }; - union { - NMIPConfigDedupMultiIdxType idx_ip4_routes_; - NMDedupMultiIdxType idx_ip4_routes; - }; - NMIPConfigFlags config_flags; -} NMIP4ConfigPrivate; - -struct _NMIP4Config { - NMIPConfig parent; - NMIP4ConfigPrivate _priv; -}; - -struct _NMIP4ConfigClass { - NMIPConfigClass parent; -}; - -G_DEFINE_TYPE(NMIP4Config, nm_ip4_config, NM_TYPE_IP_CONFIG) - -#define NM_IP4_CONFIG_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMIP4Config, NM_IS_IP4_CONFIG) - -/*****************************************************************************/ - -static void -_add_address(NMIP4Config *self, const NMPObject *obj_new, const NMPlatformIP4Address *new); -static void _add_route(NMIP4Config * self, - const NMPObject *obj_new, - const NMPlatformIP4Route *new, - const NMPObject **out_obj_new); -static const NMDedupMultiEntry * -_lookup_route(const NMIP4Config *self, const NMPObject *needle, NMPlatformIPRouteCmpType cmp_type); - -/*****************************************************************************/ - -int -nm_ip4_config_get_ifindex(const NMIP4Config *self) -{ - return NM_IP4_CONFIG_GET_PRIVATE(self)->ifindex; -} - -NMDedupMultiIndex * -nm_ip4_config_get_multi_idx(const NMIP4Config *self) -{ - return NM_IP4_CONFIG_GET_PRIVATE(self)->multi_idx; -} - -/*****************************************************************************/ - -const NMDedupMultiHeadEntry * -nm_ip4_config_lookup_addresses(const NMIP4Config *self) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - return nm_dedup_multi_index_lookup_head(priv->multi_idx, &priv->idx_ip4_addresses, NULL); -} - -void -nm_ip_config_iter_ip4_address_init(NMDedupMultiIter *ipconf_iter, const NMIP4Config *self) -{ - nm_assert(NM_IS_IP4_CONFIG(self)); - - nm_dedup_multi_iter_init(ipconf_iter, nm_ip4_config_lookup_addresses(self)); -} - -/*****************************************************************************/ - -const NMDedupMultiHeadEntry * -nm_ip4_config_lookup_routes(const NMIP4Config *self) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - return nm_dedup_multi_index_lookup_head(priv->multi_idx, &priv->idx_ip4_routes, NULL); -} - -void -nm_ip_config_iter_ip4_route_init(NMDedupMultiIter *ipconf_iter, const NMIP4Config *self) -{ - nm_assert(NM_IS_IP4_CONFIG(self)); - - nm_dedup_multi_iter_init(ipconf_iter, nm_ip4_config_lookup_routes(self)); -} - -/*****************************************************************************/ - -const NMPObject * -_nm_ip_config_best_default_route_find_better(const NMPObject *obj_cur, const NMPObject *obj_cmp) -{ - nm_assert(!obj_cur - || NM_IN_SET(NMP_OBJECT_GET_TYPE(obj_cur), - NMP_OBJECT_TYPE_IP4_ROUTE, - NMP_OBJECT_TYPE_IP6_ROUTE)); - nm_assert(!obj_cmp - || (!obj_cur - && NM_IN_SET(NMP_OBJECT_GET_TYPE(obj_cmp), - NMP_OBJECT_TYPE_IP4_ROUTE, - NMP_OBJECT_TYPE_IP6_ROUTE)) - || NMP_OBJECT_GET_TYPE(obj_cur) == NMP_OBJECT_GET_TYPE(obj_cmp)); - nm_assert(!obj_cur || nmp_object_ip_route_is_best_default_route(obj_cur)); - - /* assumes that @obj_cur is already the best default route (or NULL). It checks whether - * @obj_cmp is also a default route and returns the best of both. */ - if (obj_cmp && nmp_object_ip_route_is_best_default_route(obj_cmp)) { - guint32 metric_cur, metric_cmp; - - if (!obj_cur) - return obj_cmp; - - metric_cur = NMP_OBJECT_CAST_IP_ROUTE(obj_cur)->metric; - metric_cmp = NMP_OBJECT_CAST_IP_ROUTE(obj_cmp)->metric; - - if (metric_cmp < metric_cur) - return obj_cmp; - - if (metric_cmp == metric_cur) { - int c; - - /* Routes have the same metric. We still want to deterministically - * prefer one or the other. It's important to consistently choose one - * or the other, so that the order doesn't matter how routes are added - * (and merged). */ - c = nmp_object_cmp(obj_cur, obj_cmp); - if (c != 0) - return c < 0 ? obj_cur : obj_cmp; - - /* as last resort, compare pointers. */ - if (obj_cmp < obj_cur) - return obj_cmp; - } - } - return obj_cur; -} - -gboolean -_nm_ip_config_best_default_route_merge(const NMPObject **best_default_route, - const NMPObject * new_candidate) -{ - new_candidate = - _nm_ip_config_best_default_route_find_better(*best_default_route, new_candidate); - return nmp_object_ref_set(best_default_route, new_candidate); -} - -const NMPObject * -nm_ip4_config_best_default_route_get(const NMIP4Config *self) -{ - g_return_val_if_fail(NM_IS_IP4_CONFIG(self), NULL); - - return NM_IP4_CONFIG_GET_PRIVATE(self)->best_default_route; -} - -const NMPObject * -_nm_ip4_config_best_default_route_find(const NMIP4Config *self) -{ - NMDedupMultiIter ipconf_iter; - const NMPObject *new_best_default_route = NULL; - - nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, self, NULL) { - new_best_default_route = - _nm_ip_config_best_default_route_find_better(new_best_default_route, - ipconf_iter.current->obj); - } - return new_best_default_route; -} - -in_addr_t -nmtst_ip4_config_get_gateway(NMIP4Config *config) -{ - const NMPObject *rt; - - g_assert(NM_IS_IP4_CONFIG(config)); - - rt = nm_ip4_config_best_default_route_get(config); - if (!rt) - return 0; - return NMP_OBJECT_CAST_IP4_ROUTE(rt)->gateway; -} - -/*****************************************************************************/ - -static void -_notify_addresses(NMIP4Config *self) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - nm_clear_g_variant(&priv->address_data_variant); - nm_clear_g_variant(&priv->addresses_variant); - nm_gobject_notify_together(self, PROP_ADDRESS_DATA, PROP_ADDRESSES); -} - -static void -_notify_routes(NMIP4Config *self) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - nm_assert(priv->best_default_route == _nm_ip4_config_best_default_route_find(self)); - nm_clear_g_variant(&priv->route_data_variant); - nm_clear_g_variant(&priv->routes_variant); - nm_gobject_notify_together(self, PROP_ROUTE_DATA, PROP_ROUTES); -} - -/*****************************************************************************/ - -NMIP4Config * -nm_ip4_config_clone(const NMIP4Config *self) -{ - NMIP4Config *copy; - - copy = nm_ip4_config_new(nm_ip4_config_get_multi_idx(self), -1); - nm_ip4_config_replace(copy, self, NULL); - - return copy; -} - -NMIP4Config * -nm_ip4_config_capture(NMDedupMultiIndex *multi_idx, NMPlatform *platform, int ifindex) -{ - NMIP4Config * self; - NMIP4ConfigPrivate * priv; - const NMDedupMultiHeadEntry *head_entry; - NMDedupMultiIter iter; - const NMPObject * plobj = NULL; - - nm_assert(ifindex > 0); - - /* Slaves have no IP configuration */ - if (nm_platform_link_get_master(platform, ifindex) > 0) - return NULL; - - self = nm_ip4_config_new(multi_idx, ifindex); - priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - head_entry = nm_platform_lookup_object(platform, NMP_OBJECT_TYPE_IP4_ADDRESS, ifindex); - if (head_entry) { - nmp_cache_iter_for_each (&iter, head_entry, &plobj) { - if (!_nm_ip_config_add_obj(priv->multi_idx, - &priv->idx_ip4_addresses_, - ifindex, - plobj, - NULL, - FALSE, - TRUE, - NULL, - NULL)) - nm_assert_not_reached(); - } - _notify_addresses(self); - } - - head_entry = nm_platform_lookup_object(platform, NMP_OBJECT_TYPE_IP4_ROUTE, ifindex); - - /* Extract gateway from default route */ - nmp_cache_iter_for_each (&iter, head_entry, &plobj) - _add_route(self, plobj, NULL, NULL); - - return self; -} - -void -nm_ip4_config_update_routes_metric(NMIP4Config *self, gint64 metric) -{ - gs_free NMPlatformIP4Route *routes = NULL; - gboolean need_update = FALSE; - const NMPlatformIP4Route * r; - NMDedupMultiIter iter; - guint num = 0, i = 0; - - nm_ip_config_iter_ip4_route_for_each (&iter, self, &r) { - if (r->metric != metric) - need_update = TRUE; - num++; - } - if (!need_update) - return; - - routes = g_new(NMPlatformIP4Route, num); - nm_ip_config_iter_ip4_route_for_each (&iter, self, &r) { - routes[i] = *r; - routes[i].metric = metric; - i++; - } - - g_object_freeze_notify(G_OBJECT(self)); - nm_ip4_config_reset_routes(self); - for (i = 0; i < num; i++) - nm_ip4_config_add_route(self, &routes[i], NULL); - g_object_thaw_notify(G_OBJECT(self)); -} - -void -nm_ip4_config_add_dependent_routes(NMIP4Config *self, - guint32 route_table, - guint32 route_metric, - gboolean is_vrf, - GPtrArray ** out_ip4_dev_route_blacklist) -{ - GPtrArray * ip4_dev_route_blacklist = NULL; - const NMPlatformIP4Address *my_addr; - const NMPlatformIP4Route * my_route; - int ifindex; - NMDedupMultiIter iter; - - g_return_if_fail(NM_IS_IP4_CONFIG(self)); - - ifindex = nm_ip4_config_get_ifindex(self); - g_return_if_fail(ifindex > 0); - - /* For IPv6 slaac, we explicitly add the device-routes (onlink) to NMIP6Config. - * As we don't do that for IPv4 (and manual IPv6 addresses), add them explicitly. */ - - nm_ip_config_iter_ip4_address_for_each (&iter, self, &my_addr) { - nm_auto_nmpobj NMPObject *r = NULL; - NMPlatformIP4Route * route; - in_addr_t network; - - if (my_addr->plen == 0) - continue; - - nm_assert(my_addr->plen <= 32); - - /* The destination network depends on the peer-address. */ - network = nm_utils_ip4_address_clear_host_address(my_addr->peer_address, my_addr->plen); - - if (my_addr->external) - continue; - - if (nm_utils_ip4_address_is_zeronet(network)) { - /* Kernel doesn't add device-routes for destinations that - * start with 0.x.y.z. Skip them. */ - continue; - } - - if (my_addr->plen == 32 && my_addr->address == my_addr->peer_address) { - /* Kernel doesn't add device-routes for /32 addresses unless - * they have a peer. */ - continue; - } - - r = nmp_object_new(NMP_OBJECT_TYPE_IP4_ROUTE, NULL); - route = NMP_OBJECT_CAST_IP4_ROUTE(r); - - route->ifindex = ifindex; - route->rt_source = NM_IP_CONFIG_SOURCE_KERNEL; - route->network = network; - route->plen = my_addr->plen; - route->pref_src = my_addr->address; - route->table_coerced = nm_platform_route_table_coerce(route_table); - route->metric = route_metric; - route->scope_inv = nm_platform_route_scope_inv(NM_RT_SCOPE_LINK); - - nm_platform_ip_route_normalize(AF_INET, (NMPlatformIPRoute *) route); - - if (_lookup_route(self, r, NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID)) { - /* we already track this route. Don't add it again. */ - } else - _add_route(self, r, NULL, NULL); - - if (out_ip4_dev_route_blacklist - && (route_table != RT_TABLE_MAIN - || route_metric != NM_PLATFORM_ROUTE_METRIC_IP4_DEVICE_ROUTE)) { - nm_auto_nmpobj NMPObject *r_dev = NULL; - - r_dev = nmp_object_clone(r, FALSE); - route = NMP_OBJECT_CAST_IP4_ROUTE(r_dev); - route->table_coerced = nm_platform_route_table_coerce(RT_TABLE_MAIN); - route->metric = NM_PLATFORM_ROUTE_METRIC_IP4_DEVICE_ROUTE; - - nm_platform_ip_route_normalize(AF_INET, (NMPlatformIPRoute *) route); - - if (_lookup_route(self, r_dev, NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID)) { - /* we track such a route explicitly. Don't blacklist it. */ - } else { - if (!ip4_dev_route_blacklist) - ip4_dev_route_blacklist = - g_ptr_array_new_with_free_func((GDestroyNotify) nmp_object_unref); - - g_ptr_array_add(ip4_dev_route_blacklist, g_steal_pointer(&r_dev)); - } - } - } - -again: - nm_ip_config_iter_ip4_route_for_each (&iter, self, &my_route) { - NMPlatformIP4Route rt; - - if (!NM_PLATFORM_IP_ROUTE_IS_DEFAULT(my_route) || my_route->gateway == 0 - || NM_IS_IP_CONFIG_SOURCE_RTPROT(my_route->rt_source) - || nm_ip4_config_get_direct_route_for_host( - self, - my_route->gateway, - nm_platform_route_table_uncoerce(my_route->table_coerced, TRUE))) - continue; - - rt = *my_route; - rt.network = my_route->gateway; - rt.plen = 32; - rt.gateway = 0; - _add_route(self, NULL, &rt, NULL); - /* adding the route might have invalidated the iteration. Start again. */ - goto again; - } - - NM_SET_OUT(out_ip4_dev_route_blacklist, ip4_dev_route_blacklist); -} - -gboolean -nm_ip4_config_commit(const NMIP4Config * self, - NMPlatform * platform, - NMIPRouteTableSyncMode route_table_sync) -{ - gs_unref_ptrarray GPtrArray *addresses = NULL; - gs_unref_ptrarray GPtrArray *routes = NULL; - gs_unref_ptrarray GPtrArray *routes_prune = NULL; - int ifindex; - gboolean success = TRUE; - - g_return_val_if_fail(NM_IS_IP4_CONFIG(self), FALSE); - - ifindex = nm_ip4_config_get_ifindex(self); - g_return_val_if_fail(ifindex > 0, FALSE); - - addresses = - nm_dedup_multi_objs_to_ptr_array_head(nm_ip4_config_lookup_addresses(self), NULL, NULL); - - routes = nm_dedup_multi_objs_to_ptr_array_head(nm_ip4_config_lookup_routes(self), NULL, NULL); - - routes_prune = - nm_platform_ip_route_get_prune_list(platform, AF_INET, ifindex, route_table_sync); - - nm_platform_ip4_address_sync(platform, ifindex, addresses); - - if (!nm_platform_ip_route_sync(platform, AF_INET, ifindex, routes, routes_prune, NULL)) - success = FALSE; - - return success; -} - -void -nm_ip4_config_merge_setting(NMIP4Config * self, - NMSettingIPConfig * setting, - NMSettingConnectionMdns mdns, - NMSettingConnectionLlmnr llmnr, - NMSettingConnectionDnsOverTls dns_over_tls, - guint32 route_table, - guint32 route_metric) -{ - guint naddresses, nroutes, nnameservers, nsearches; - int i, priority; - const char *gateway_str; - guint32 gateway_bin; - - if (!setting) - return; - - g_return_if_fail(NM_IS_SETTING_IP4_CONFIG(setting)); - - g_object_freeze_notify(G_OBJECT(self)); - - 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_ip_config_get_never_default(setting) - && (gateway_str = nm_setting_ip_config_get_gateway(setting)) - && inet_pton(AF_INET, gateway_str, &gateway_bin) == 1 && gateway_bin) { - const NMPlatformIP4Route r = { - .rt_source = NM_IP_CONFIG_SOURCE_USER, - .gateway = gateway_bin, - .table_coerced = nm_platform_route_table_coerce(route_table), - .metric = route_metric, - }; - - _add_route(self, NULL, &r, NULL); - } - - /* Addresses */ - for (i = 0; i < naddresses; i++) { - NMIPAddress * s_addr = nm_setting_ip_config_get_address(setting, i); - GVariant * label; - NMPlatformIP4Address address; - - memset(&address, 0, sizeof(address)); - nm_ip_address_get_address_binary(s_addr, &address.address); - address.peer_address = address.address; - address.plen = nm_ip_address_get_prefix(s_addr); - nm_assert(address.plen <= 32); - address.lifetime = NM_PLATFORM_LIFETIME_PERMANENT; - address.preferred = NM_PLATFORM_LIFETIME_PERMANENT; - address.addr_source = NM_IP_CONFIG_SOURCE_USER; - - label = nm_ip_address_get_attribute(s_addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL); - if (label) - g_strlcpy(address.label, g_variant_get_string(label, NULL), sizeof(address.label)); - - _add_address(self, NULL, &address); - } - - /* Routes */ - for (i = 0; i < nroutes; i++) { - NMIPRoute * s_route = nm_setting_ip_config_get_route(setting, i); - NMPlatformIP4Route route; - gint64 m; - - if (nm_ip_route_get_family(s_route) != AF_INET) { - nm_assert_not_reached(); - continue; - } - - memset(&route, 0, sizeof(route)); - nm_ip_route_get_dest_binary(s_route, &route.network); - - route.plen = nm_ip_route_get_prefix(s_route); - nm_assert(route.plen <= 32); - - nm_ip_route_get_next_hop_binary(s_route, &route.gateway); - m = nm_ip_route_get_metric(s_route); - if (m < 0) - route.metric = route_metric; - else - route.metric = m; - route.rt_source = NM_IP_CONFIG_SOURCE_USER; - - route.network = nm_utils_ip4_address_clear_host_address(route.network, route.plen); - - nm_utils_ip_route_attribute_to_platform(AF_INET, - s_route, - NM_PLATFORM_IP_ROUTE_CAST(&route), - route_table); - _add_route(self, NULL, &route, NULL); - } - - /* DNS */ - if (nm_setting_ip_config_get_ignore_auto_dns(setting)) { - nm_ip4_config_reset_nameservers(self); - nm_ip4_config_reset_domains(self); - nm_ip4_config_reset_searches(self); - } - for (i = 0; i < nnameservers; i++) { - guint32 ip; - - if (inet_pton(AF_INET, nm_setting_ip_config_get_dns(setting, i), &ip) == 1) - nm_ip4_config_add_nameserver(self, ip); - } - for (i = 0; i < nsearches; i++) - nm_ip4_config_add_search(self, nm_setting_ip_config_get_dns_search(setting, i)); - - i = 0; - while ((i = nm_setting_ip_config_next_valid_dns_option(setting, i)) >= 0) { - nm_ip4_config_add_dns_option(self, nm_setting_ip_config_get_dns_option(setting, i)); - i++; - } - - priority = nm_setting_ip_config_get_dns_priority(setting); - if (priority) - nm_ip4_config_set_dns_priority(self, priority); - - nm_ip4_config_mdns_set(self, mdns); - nm_ip4_config_llmnr_set(self, llmnr); - nm_ip4_config_dns_over_tls_set(self, dns_over_tls); - - nm_ip4_config_set_never_default(self, nm_setting_ip_config_get_never_default(setting)); - - g_object_thaw_notify(G_OBJECT(self)); -} - -NMSetting * -nm_ip4_config_create_setting(const NMIP4Config *self) -{ - const NMIP4ConfigPrivate * priv; - NMSettingIPConfig * s_ip4; - guint nnameservers, nsearches, noptions; - const char * method = NULL; - int i; - NMDedupMultiIter ipconf_iter; - const NMPlatformIP4Address *address; - const NMPlatformIP4Route * route; - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; - - s_ip4 = NM_SETTING_IP_CONFIG(nm_setting_ip4_config_new()); - - if (!self) { - g_object_set(s_ip4, - NM_SETTING_IP_CONFIG_METHOD, - NM_SETTING_IP4_CONFIG_METHOD_DISABLED, - NULL); - return NM_SETTING(s_ip4); - } - - priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - nnameservers = nm_ip4_config_get_num_nameservers(self); - nsearches = nm_ip4_config_get_num_searches(self); - noptions = nm_ip4_config_get_num_dns_options(self); - - /* Addresses */ - nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, self, &address) { - NMIPAddress *s_addr; - - /* Detect dynamic address */ - if (address->lifetime != NM_PLATFORM_LIFETIME_PERMANENT) { - method = NM_SETTING_IP4_CONFIG_METHOD_AUTO; - continue; - } - - /* Static address found. */ - if (!method) - method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL; - - s_addr = nm_ip_address_new_binary(AF_INET, &address->address, address->plen, NULL); - if (*address->label) - nm_ip_address_set_attribute(s_addr, - NM_IP_ADDRESS_ATTRIBUTE_LABEL, - g_variant_new_string(address->label)); - - nm_setting_ip_config_add_address(s_ip4, s_addr); - nm_ip_address_unref(s_addr); - } - - /* Gateway */ - if (priv->best_default_route && nm_setting_ip_config_get_num_addresses(s_ip4) > 0) { - g_object_set( - s_ip4, - NM_SETTING_IP_CONFIG_GATEWAY, - _nm_utils_inet4_ntop(NMP_OBJECT_CAST_IP4_ROUTE(priv->best_default_route)->gateway, - sbuf), - 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_IP_CONFIG_METHOD, method, NULL); - - /* Routes */ - nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, self, &route) { - NMIPRoute *s_route; - - if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT(route)) - continue; - - /* Ignore routes provided by external sources */ - if (route->rt_source - != nmp_utils_ip_config_source_round_trip_rtprot(NM_IP_CONFIG_SOURCE_USER)) - continue; - - 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(self, i); - - nm_setting_ip_config_add_dns(s_ip4, _nm_utils_inet4_ntop(nameserver, sbuf)); - } - for (i = 0; i < nsearches; i++) { - const char *search = nm_ip4_config_get_search(self, i); - - nm_setting_ip_config_add_dns_search(s_ip4, search); - } - - for (i = 0; i < noptions; i++) { - const char *option = nm_ip4_config_get_dns_option(self, i); - - nm_setting_ip_config_add_dns_option(s_ip4, option); - } - - g_object_set(s_ip4, - NM_SETTING_IP_CONFIG_DNS_PRIORITY, - nm_ip4_config_get_dns_priority(self), - NULL); - - return NM_SETTING(s_ip4); -} - -/*****************************************************************************/ - -void -nm_ip4_config_merge(NMIP4Config * dst, - const NMIP4Config * src, - NMIPConfigMergeFlags merge_flags, - guint32 default_route_metric_penalty) -{ - NMIP4ConfigPrivate * dst_priv; - const NMIP4ConfigPrivate * src_priv; - guint32 i; - NMDedupMultiIter ipconf_iter; - const NMPlatformIP4Address *address = NULL; - - g_return_if_fail(src != NULL); - g_return_if_fail(dst != NULL); - - dst_priv = NM_IP4_CONFIG_GET_PRIVATE(dst); - src_priv = NM_IP4_CONFIG_GET_PRIVATE(src); - - g_object_freeze_notify(G_OBJECT(dst)); - - /* addresses */ - nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, src, &address) { - if (NM_FLAGS_HAS(merge_flags, NM_IP_CONFIG_MERGE_EXTERNAL) && !address->external) { - NMPlatformIP4Address a; - - a = *address; - a.external = TRUE; - _add_address(dst, NULL, &a); - } else - _add_address(dst, NMP_OBJECT_UP_CAST(address), NULL); - } - - /* nameservers */ - if (!NM_FLAGS_HAS(merge_flags, NM_IP_CONFIG_MERGE_NO_DNS)) { - for (i = 0; i < nm_ip4_config_get_num_nameservers(src); i++) - nm_ip4_config_add_nameserver(dst, nm_ip4_config_get_nameserver(src, i)); - } - - /* routes */ - if (!NM_FLAGS_HAS(merge_flags, NM_IP_CONFIG_MERGE_NO_ROUTES)) { - const NMPlatformIP4Route *r_src; - - nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, src, &r_src) { - if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT(r_src)) { - if (NM_FLAGS_HAS(merge_flags, NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES) - && !NM_FLAGS_HAS(src_priv->config_flags, - NM_IP_CONFIG_FLAGS_IGNORE_MERGE_NO_DEFAULT_ROUTES)) - continue; - if (default_route_metric_penalty) { - NMPlatformIP4Route r = *r_src; - - r.metric = - nm_utils_ip_route_metric_penalize(r.metric, default_route_metric_penalty); - _add_route(dst, NULL, &r, NULL); - continue; - } - } - _add_route(dst, ipconf_iter.current->obj, NULL, NULL); - } - } - - /* domains */ - if (!NM_FLAGS_HAS(merge_flags, NM_IP_CONFIG_MERGE_NO_DNS)) { - for (i = 0; i < nm_ip4_config_get_num_domains(src); i++) - nm_ip4_config_add_domain(dst, nm_ip4_config_get_domain(src, i)); - } - - /* dns searches */ - if (!NM_FLAGS_HAS(merge_flags, NM_IP_CONFIG_MERGE_NO_DNS)) { - for (i = 0; i < nm_ip4_config_get_num_searches(src); i++) - nm_ip4_config_add_search(dst, nm_ip4_config_get_search(src, i)); - } - - /* dns options */ - if (!NM_FLAGS_HAS(merge_flags, NM_IP_CONFIG_MERGE_NO_DNS)) { - for (i = 0; i < nm_ip4_config_get_num_dns_options(src); i++) - nm_ip4_config_add_dns_option(dst, nm_ip4_config_get_dns_option(src, i)); - } - - /* MTU */ - if (src_priv->mtu_source > dst_priv->mtu_source - || (src_priv->mtu_source == dst_priv->mtu_source - && ((!dst_priv->mtu && src_priv->mtu) - || (dst_priv->mtu && src_priv->mtu < dst_priv->mtu)))) - nm_ip4_config_set_mtu(dst, src_priv->mtu, src_priv->mtu_source); - - /* NIS */ - if (!NM_FLAGS_HAS(merge_flags, NM_IP_CONFIG_MERGE_NO_DNS)) { - for (i = 0; i < nm_ip4_config_get_num_nis_servers(src); i++) - nm_ip4_config_add_nis_server(dst, nm_ip4_config_get_nis_server(src, i)); - - if (nm_ip4_config_get_nis_domain(src)) - nm_ip4_config_set_nis_domain(dst, nm_ip4_config_get_nis_domain(src)); - } - - /* WINS */ - if (!NM_FLAGS_HAS(merge_flags, NM_IP_CONFIG_MERGE_NO_DNS)) { - for (i = 0; i < nm_ip4_config_get_num_wins(src); i++) - nm_ip4_config_add_wins(dst, nm_ip4_config_get_wins(src, i)); - } - - /* metered flag */ - nm_ip4_config_set_metered(dst, - nm_ip4_config_get_metered(dst) || nm_ip4_config_get_metered(src)); - - /* never default */ - nm_ip4_config_set_never_default(dst, - nm_ip4_config_get_never_default(dst) - || nm_ip4_config_get_never_default(src)); - - /* DNS priority */ - if (nm_ip4_config_get_dns_priority(src)) - nm_ip4_config_set_dns_priority(dst, nm_ip4_config_get_dns_priority(src)); - - /* mdns */ - nm_ip4_config_mdns_set(dst, NM_MAX(nm_ip4_config_mdns_get(src), nm_ip4_config_mdns_get(dst))); - /* LLMNR */ - nm_ip4_config_llmnr_set(dst, - NM_MAX(nm_ip4_config_llmnr_get(src), nm_ip4_config_llmnr_get(dst))); - /* dns_over_tls */ - nm_ip4_config_dns_over_tls_set( - dst, - NM_MAX(nm_ip4_config_dns_over_tls_get(src), nm_ip4_config_dns_over_tls_get(dst))); - - g_object_thaw_notify(G_OBJECT(dst)); -} - -/*****************************************************************************/ - -static int -_nameservers_get_index(const NMIP4Config *self, guint32 ns) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - guint i; - - for (i = 0; i < priv->nameservers->len; i++) { - guint32 n = g_array_index(priv->nameservers, guint32, i); - - if (ns == n) - return (int) i; - } - return -1; -} - -static int -_domains_get_index(const NMIP4Config *self, const char *domain) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - guint i; - - for (i = 0; i < priv->domains->len; i++) { - const char *d = g_ptr_array_index(priv->domains, i); - - if (g_strcmp0(domain, d) == 0) - return (int) i; - } - return -1; -} - -static int -_searches_get_index(const NMIP4Config *self, const char *search) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - guint i; - - for (i = 0; i < priv->searches->len; i++) { - const char *s = g_ptr_array_index(priv->searches, i); - - if (g_strcmp0(search, s) == 0) - return (int) i; - } - return -1; -} - -static int -_dns_options_get_index(const NMIP4Config *self, const char *option) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - guint i; - - for (i = 0; i < priv->dns_options->len; i++) { - const char *s = g_ptr_array_index(priv->dns_options, i); - - if (g_strcmp0(option, s) == 0) - return (int) i; - } - return -1; -} - -static int -_nis_servers_get_index(const NMIP4Config *self, guint32 nis_server) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - guint i; - - for (i = 0; i < priv->nis->len; i++) { - guint32 n = g_array_index(priv->nis, guint32, i); - - if (n == nis_server) - return (int) i; - } - return -1; -} - -static int -_wins_get_index(const NMIP4Config *self, guint32 wins_server) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - guint i; - - for (i = 0; i < priv->wins->len; i++) { - guint32 n = g_array_index(priv->wins, guint32, i); - - if (n == wins_server) - return (int) i; - } - return -1; -} - -/*****************************************************************************/ - -/** - * nm_ip4_config_subtract: - * @dst: config from which to remove everything in @src - * @src: config to remove from @dst - * @default_route_metric_penalty: pretend that on source we applied - * a route penalty on the default-route. It means, for default routes - * we don't remove routes that match exactly, but those with a lower - * metric (with the penalty removed). - * - * Removes everything in @src from @dst. - */ -void -nm_ip4_config_subtract(NMIP4Config * dst, - const NMIP4Config *src, - guint32 default_route_metric_penalty) -{ - NMIP4ConfigPrivate * dst_priv; - guint i; - int idx; - const NMPlatformIP4Address *a; - const NMPlatformIP4Route * r; - NMDedupMultiIter ipconf_iter; - gboolean changed; - gboolean changed_default_route; - - g_return_if_fail(src != NULL); - g_return_if_fail(dst != NULL); - - dst_priv = NM_IP4_CONFIG_GET_PRIVATE(dst); - - g_object_freeze_notify(G_OBJECT(dst)); - - /* addresses */ - changed = FALSE; - nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, src, &a) { - if (nm_dedup_multi_index_remove_obj(dst_priv->multi_idx, - &dst_priv->idx_ip4_addresses, - NMP_OBJECT_UP_CAST(a), - NULL)) - changed = TRUE; - } - if (changed) - _notify_addresses(dst); - - /* nameservers */ - for (i = 0; i < nm_ip4_config_get_num_nameservers(src); i++) { - idx = _nameservers_get_index(dst, nm_ip4_config_get_nameserver(src, i)); - if (idx >= 0) - nm_ip4_config_del_nameserver(dst, idx); - } - - /* routes */ - changed = FALSE; - changed_default_route = FALSE; - nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, src, &r) { - const NMPObject * o_src = NMP_OBJECT_UP_CAST(r); - NMPObject o_lookup_copy; - const NMPObject * o_lookup; - nm_auto_nmpobj const NMPObject *obj_old = NULL; - - if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT(r) && default_route_metric_penalty) { - NMPlatformIP4Route *rr; - - /* the default route was penalized when merging it to the combined ip-config. - * When subtracting the routes, we must re-do that process when comparing - * the routes. */ - o_lookup = nmp_object_stackinit_obj(&o_lookup_copy, o_src); - rr = NMP_OBJECT_CAST_IP4_ROUTE(&o_lookup_copy); - rr->metric = - nm_utils_ip_route_metric_penalize(rr->metric, default_route_metric_penalty); - } else - o_lookup = o_src; - - if (nm_dedup_multi_index_remove_obj(dst_priv->multi_idx, - &dst_priv->idx_ip4_routes, - o_lookup, - (gconstpointer *) &obj_old)) { - if (dst_priv->best_default_route == obj_old) { - nm_clear_nmp_object(&dst_priv->best_default_route); - changed_default_route = TRUE; - } - changed = TRUE; - } - } - if (changed_default_route) { - nmp_object_ref_set(&dst_priv->best_default_route, - _nm_ip4_config_best_default_route_find(dst)); - _notify(dst, PROP_GATEWAY); - } - if (changed) - _notify_routes(dst); - - /* domains */ - for (i = 0; i < nm_ip4_config_get_num_domains(src); i++) { - idx = _domains_get_index(dst, nm_ip4_config_get_domain(src, i)); - if (idx >= 0) - nm_ip4_config_del_domain(dst, idx); - } - - /* dns searches */ - for (i = 0; i < nm_ip4_config_get_num_searches(src); i++) { - idx = _searches_get_index(dst, nm_ip4_config_get_search(src, i)); - if (idx >= 0) - nm_ip4_config_del_search(dst, idx); - } - - /* dns options */ - for (i = 0; i < nm_ip4_config_get_num_dns_options(src); i++) { - idx = _dns_options_get_index(dst, nm_ip4_config_get_dns_option(src, i)); - if (idx >= 0) - nm_ip4_config_del_dns_option(dst, idx); - } - - /* MTU */ - if (nm_ip4_config_get_mtu(src) == nm_ip4_config_get_mtu(dst) - && nm_ip4_config_get_mtu_source(src) == nm_ip4_config_get_mtu_source(dst)) - nm_ip4_config_set_mtu(dst, 0, NM_IP_CONFIG_SOURCE_UNKNOWN); - - /* NIS */ - for (i = 0; i < nm_ip4_config_get_num_nis_servers(src); i++) { - idx = _nis_servers_get_index(dst, nm_ip4_config_get_nis_server(src, i)); - if (idx >= 0) - nm_ip4_config_del_nis_server(dst, idx); - } - - if (g_strcmp0(nm_ip4_config_get_nis_domain(src), nm_ip4_config_get_nis_domain(dst)) == 0) - nm_ip4_config_set_nis_domain(dst, NULL); - - /* WINS */ - for (i = 0; i < nm_ip4_config_get_num_wins(src); i++) { - idx = _wins_get_index(dst, nm_ip4_config_get_wins(src, i)); - if (idx >= 0) - nm_ip4_config_del_wins(dst, idx); - } - - /* DNS priority */ - if (nm_ip4_config_get_dns_priority(src) == nm_ip4_config_get_dns_priority(dst)) - nm_ip4_config_set_dns_priority(dst, 0); - - /* mdns */ - if (nm_ip4_config_mdns_get(src) == nm_ip4_config_mdns_get(dst)) - nm_ip4_config_mdns_set(dst, NM_SETTING_CONNECTION_MDNS_DEFAULT); - - /* LLMNR */ - if (nm_ip4_config_llmnr_get(src) == nm_ip4_config_llmnr_get(dst)) - nm_ip4_config_llmnr_set(dst, NM_SETTING_CONNECTION_LLMNR_DEFAULT); - - /* dns_over_tls */ - if (nm_ip4_config_dns_over_tls_get(src) == nm_ip4_config_dns_over_tls_get(dst)) - nm_ip4_config_dns_over_tls_set(dst, NM_SETTING_CONNECTION_DNS_OVER_TLS_DEFAULT); - - g_object_thaw_notify(G_OBJECT(dst)); -} - -static gboolean -_nm_ip4_config_intersect_helper(NMIP4Config * dst, - const NMIP4Config *src, - gboolean intersect_addresses, - gboolean intersect_routes, - guint32 default_route_metric_penalty, - gboolean update_dst) -{ - NMIP4ConfigPrivate * dst_priv; - const NMIP4ConfigPrivate * src_priv; - NMDedupMultiIter ipconf_iter; - const NMPlatformIP4Address *a; - const NMPlatformIP4Route * r; - const NMPObject * new_best_default_route; - gboolean changed, result = FALSE; - - g_return_val_if_fail(src, FALSE); - g_return_val_if_fail(dst, FALSE); - - dst_priv = NM_IP4_CONFIG_GET_PRIVATE(dst); - src_priv = NM_IP4_CONFIG_GET_PRIVATE(src); - - if (update_dst) - g_object_freeze_notify(G_OBJECT(dst)); - - /* addresses */ - if (intersect_addresses) { - changed = FALSE; - nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, dst, &a) { - if (nm_dedup_multi_index_lookup_obj(src_priv->multi_idx, - &src_priv->idx_ip4_addresses, - NMP_OBJECT_UP_CAST(a))) - continue; - - if (!update_dst) - return TRUE; - - if (nm_dedup_multi_index_remove_entry(dst_priv->multi_idx, ipconf_iter.current) != 1) - nm_assert_not_reached(); - changed = TRUE; - } - if (changed) { - _notify_addresses(dst); - result = TRUE; - } - } - - /* ignore nameservers */ - - /* routes */ - if (!intersect_routes) - goto skip_routes; - - changed = FALSE; - new_best_default_route = NULL; - nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, dst, &r) { - const NMPObject *o_dst = NMP_OBJECT_UP_CAST(r); - const NMPObject *o_lookup; - NMPObject o_lookup_copy; - - if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT(r) && default_route_metric_penalty) { - NMPlatformIP4Route *rr; - - /* the default route was penalized when merging it to the combined ip-config. - * When intersecting the routes, we must re-do that process when comparing - * the routes. */ - o_lookup = nmp_object_stackinit_obj(&o_lookup_copy, o_dst); - rr = NMP_OBJECT_CAST_IP4_ROUTE(&o_lookup_copy); - rr->metric = - nm_utils_ip_route_metric_penalize(rr->metric, default_route_metric_penalty); - } else - o_lookup = o_dst; - - if (nm_dedup_multi_index_lookup_obj(src_priv->multi_idx, - &src_priv->idx_ip4_routes, - o_lookup)) { - new_best_default_route = - _nm_ip_config_best_default_route_find_better(new_best_default_route, o_dst); - continue; - } - - if (!update_dst) - return TRUE; - - if (nm_dedup_multi_index_remove_entry(dst_priv->multi_idx, ipconf_iter.current) != 1) - nm_assert_not_reached(); - changed = TRUE; - } - if (nmp_object_ref_set(&dst_priv->best_default_route, new_best_default_route)) { - nm_assert(changed); - _notify(dst, PROP_GATEWAY); - } - - if (changed) { - _notify_routes(dst); - result = TRUE; - } - -skip_routes: - /* ignore domains */ - /* ignore dns searches */ - /* ignore dns options */ - /* ignore NIS */ - /* ignore WINS */ - /* ignore mdns */ - /* ignore LLMNR */ - /* ignore dns_over_tls */ - - if (update_dst) - g_object_thaw_notify(G_OBJECT(dst)); - return result; -} - -/** - * nm_ip4_config_intersect: - * @dst: a configuration to be updated - * @src: another configuration - * @intersect_addresses: whether addresses should be intersected - * @intersect_routes: whether routes should be intersected - * @default_route_metric_penalty: the default route metric penalty - * - * Computes the intersection between @src and @dst and updates @dst in place - * with the result. - */ -void -nm_ip4_config_intersect(NMIP4Config * dst, - const NMIP4Config *src, - gboolean intersect_addresses, - gboolean intersect_routes, - guint32 default_route_metric_penalty) -{ - _nm_ip4_config_intersect_helper(dst, - src, - intersect_addresses, - intersect_routes, - default_route_metric_penalty, - TRUE); -} - -/** - * nm_ip4_config_intersect_alloc: - * @a: a configuration - * @b: another configuration - * @intersect_addresses: whether addresses should be intersected - * @intersect_routes: whether routes should be intersected - * @default_route_metric_penalty: the default route metric penalty - * - * Computes the intersection between @a and @b and returns the result in a newly - * allocated configuration. As a special case, if @a and @b are identical (with - * respect to the only properties considered - addresses and routes) the - * functions returns NULL so that one of existing configuration can be reused - * without allocation. - * - * Returns: the intersection between @a and @b, or %NULL if the result is equal - * to @a and @b. - */ -NMIP4Config * -nm_ip4_config_intersect_alloc(const NMIP4Config *a, - const NMIP4Config *b, - gboolean intersect_addresses, - gboolean intersect_routes, - guint32 default_route_metric_penalty) -{ - NMIP4Config *a_copy; - - if (_nm_ip4_config_intersect_helper((NMIP4Config *) a, - b, - intersect_addresses, - intersect_routes, - default_route_metric_penalty, - FALSE)) { - a_copy = nm_ip4_config_clone(a); - _nm_ip4_config_intersect_helper(a_copy, - b, - intersect_addresses, - intersect_routes, - default_route_metric_penalty, - TRUE); - return a_copy; - } else - return NULL; -} - -/** - * nm_ip4_config_replace: - * @dst: config to replace with @src content - * @src: source config to copy - * @relevant_changes: return whether there are changes to the - * destination object that are relevant. This is equal to - * nm_ip4_config_equal() showing any difference. - * - * Replaces everything in @dst with @src so that the two configurations - * contain the same content -- with the exception of the dbus path. - * - * Returns: whether the @dst instance changed in any way (including minor changes, - * that are not signaled by the output parameter @relevant_changes). - */ -gboolean -nm_ip4_config_replace(NMIP4Config *dst, const NMIP4Config *src, gboolean *relevant_changes) -{ -#if NM_MORE_ASSERTS - gboolean config_equal; -#endif - gboolean has_minor_changes = FALSE, has_relevant_changes = FALSE, are_equal; - guint i, num; - NMIP4ConfigPrivate * dst_priv; - const NMIP4ConfigPrivate * src_priv; - NMDedupMultiIter ipconf_iter_src, ipconf_iter_dst; - const NMDedupMultiHeadEntry *head_entry_src; - const NMPObject * new_best_default_route; - - g_return_val_if_fail(src != NULL, FALSE); - g_return_val_if_fail(dst != NULL, FALSE); - g_return_val_if_fail(src != dst, FALSE); - -#if NM_MORE_ASSERTS - config_equal = nm_ip4_config_equal(dst, src); -#endif - - dst_priv = NM_IP4_CONFIG_GET_PRIVATE(dst); - src_priv = NM_IP4_CONFIG_GET_PRIVATE(src); - - g_object_freeze_notify(G_OBJECT(dst)); - - /* ifindex */ - if (src_priv->ifindex != dst_priv->ifindex) { - dst_priv->ifindex = src_priv->ifindex; - has_minor_changes = TRUE; - } - - /* addresses */ - head_entry_src = nm_ip4_config_lookup_addresses(src); - nm_dedup_multi_iter_init(&ipconf_iter_src, head_entry_src); - nm_ip_config_iter_ip4_address_init(&ipconf_iter_dst, dst); - are_equal = TRUE; - while (TRUE) { - gboolean has; - const NMPlatformIP4Address *r_src = NULL; - const NMPlatformIP4Address *r_dst = NULL; - - has = nm_platform_dedup_multi_iter_next_ip4_address(&ipconf_iter_src, &r_src); - if (has != nm_platform_dedup_multi_iter_next_ip4_address(&ipconf_iter_dst, &r_dst)) { - are_equal = FALSE; - has_relevant_changes = TRUE; - break; - } - if (!has) - break; - - if (nm_platform_ip4_address_cmp(r_src, r_dst) != 0) { - are_equal = FALSE; - if (r_src->address != r_dst->address || r_src->plen != r_dst->plen - || r_src->peer_address != r_dst->peer_address) { - has_relevant_changes = TRUE; - break; - } - } - } - if (!are_equal) { - has_minor_changes = TRUE; - nm_dedup_multi_index_dirty_set_idx(dst_priv->multi_idx, &dst_priv->idx_ip4_addresses); - nm_dedup_multi_iter_for_each (&ipconf_iter_src, head_entry_src) { - _nm_ip_config_add_obj(dst_priv->multi_idx, - &dst_priv->idx_ip4_addresses_, - dst_priv->ifindex, - ipconf_iter_src.current->obj, - NULL, - FALSE, - TRUE, - NULL, - NULL); - } - nm_dedup_multi_index_dirty_remove_idx(dst_priv->multi_idx, - &dst_priv->idx_ip4_addresses, - FALSE); - _notify_addresses(dst); - } - - /* routes */ - head_entry_src = nm_ip4_config_lookup_routes(src); - nm_dedup_multi_iter_init(&ipconf_iter_src, head_entry_src); - nm_ip_config_iter_ip4_route_init(&ipconf_iter_dst, dst); - are_equal = TRUE; - while (TRUE) { - gboolean has; - const NMPlatformIP4Route *r_src = NULL; - const NMPlatformIP4Route *r_dst = NULL; - - has = nm_platform_dedup_multi_iter_next_ip4_route(&ipconf_iter_src, &r_src); - if (has != nm_platform_dedup_multi_iter_next_ip4_route(&ipconf_iter_dst, &r_dst)) { - are_equal = FALSE; - has_relevant_changes = TRUE; - break; - } - if (!has) - break; - - if (nm_platform_ip4_route_cmp_full(r_src, r_dst) != 0) { - are_equal = FALSE; - if (r_src->plen != r_dst->plen - || !nm_utils_ip4_address_same_prefix(r_src->network, r_dst->network, r_src->plen) - || r_src->gateway != r_dst->gateway || r_src->metric != r_dst->metric) { - has_relevant_changes = TRUE; - break; - } - } - } - if (!are_equal) { - has_minor_changes = TRUE; - new_best_default_route = NULL; - nm_dedup_multi_index_dirty_set_idx(dst_priv->multi_idx, &dst_priv->idx_ip4_routes); - nm_dedup_multi_iter_for_each (&ipconf_iter_src, head_entry_src) { - const NMPObject *o = ipconf_iter_src.current->obj; - const NMPObject *obj_new; - - _nm_ip_config_add_obj(dst_priv->multi_idx, - &dst_priv->idx_ip4_routes_, - dst_priv->ifindex, - o, - NULL, - FALSE, - TRUE, - NULL, - &obj_new); - new_best_default_route = - _nm_ip_config_best_default_route_find_better(new_best_default_route, obj_new); - } - nm_dedup_multi_index_dirty_remove_idx(dst_priv->multi_idx, - &dst_priv->idx_ip4_routes, - FALSE); - if (nmp_object_ref_set(&dst_priv->best_default_route, new_best_default_route)) - _notify(dst, PROP_GATEWAY); - _notify_routes(dst); - } - - /* nameservers */ - num = nm_ip4_config_get_num_nameservers(src); - are_equal = num == nm_ip4_config_get_num_nameservers(dst); - if (are_equal) { - for (i = 0; i < num; i++) { - if (nm_ip4_config_get_nameserver(src, i) != nm_ip4_config_get_nameserver(dst, i)) { - are_equal = FALSE; - break; - } - } - } - if (!are_equal) { - nm_ip4_config_reset_nameservers(dst); - for (i = 0; i < num; i++) - nm_ip4_config_add_nameserver(dst, nm_ip4_config_get_nameserver(src, i)); - has_relevant_changes = TRUE; - } - - /* domains */ - num = nm_ip4_config_get_num_domains(src); - are_equal = num == nm_ip4_config_get_num_domains(dst); - if (are_equal) { - for (i = 0; i < num; i++) { - if (g_strcmp0(nm_ip4_config_get_domain(src, i), nm_ip4_config_get_domain(dst, i))) { - are_equal = FALSE; - break; - } - } - } - if (!are_equal) { - nm_ip4_config_reset_domains(dst); - for (i = 0; i < num; i++) - nm_ip4_config_add_domain(dst, nm_ip4_config_get_domain(src, i)); - has_relevant_changes = TRUE; - } - - /* dns searches */ - num = nm_ip4_config_get_num_searches(src); - are_equal = num == nm_ip4_config_get_num_searches(dst); - if (are_equal) { - for (i = 0; i < num; i++) { - if (g_strcmp0(nm_ip4_config_get_search(src, i), nm_ip4_config_get_search(dst, i))) { - are_equal = FALSE; - break; - } - } - } - if (!are_equal) { - nm_ip4_config_reset_searches(dst); - for (i = 0; i < num; i++) - nm_ip4_config_add_search(dst, nm_ip4_config_get_search(src, i)); - has_relevant_changes = TRUE; - } - - /* dns options */ - num = nm_ip4_config_get_num_dns_options(src); - are_equal = num == nm_ip4_config_get_num_dns_options(dst); - if (are_equal) { - for (i = 0; i < num; i++) { - if (g_strcmp0(nm_ip4_config_get_dns_option(src, i), - nm_ip4_config_get_dns_option(dst, i))) { - are_equal = FALSE; - break; - } - } - } - if (!are_equal) { - nm_ip4_config_reset_dns_options(dst); - for (i = 0; i < num; i++) - nm_ip4_config_add_dns_option(dst, nm_ip4_config_get_dns_option(src, i)); - has_relevant_changes = TRUE; - } - - if (src_priv->mdns != dst_priv->mdns) { - dst_priv->mdns = src_priv->mdns; - has_relevant_changes = TRUE; - } - - if (src_priv->llmnr != dst_priv->llmnr) { - dst_priv->llmnr = src_priv->llmnr; - has_relevant_changes = TRUE; - } - - if (src_priv->dns_over_tls != dst_priv->dns_over_tls) { - dst_priv->dns_over_tls = src_priv->dns_over_tls; - has_relevant_changes = TRUE; - } - - /* DNS priority */ - if (src_priv->dns_priority != dst_priv->dns_priority) { - nm_ip4_config_set_dns_priority(dst, src_priv->dns_priority); - has_minor_changes = TRUE; - } - - /* nis */ - num = nm_ip4_config_get_num_nis_servers(src); - are_equal = num == nm_ip4_config_get_num_nis_servers(dst); - if (are_equal) { - for (i = 0; i < num; i++) { - if (nm_ip4_config_get_nis_server(src, i) != nm_ip4_config_get_nis_server(dst, i)) { - are_equal = FALSE; - break; - } - } - } - if (!are_equal) { - nm_ip4_config_reset_nis_servers(dst); - for (i = 0; i < num; i++) - nm_ip4_config_add_nis_server(dst, nm_ip4_config_get_nis_server(src, i)); - has_relevant_changes = TRUE; - } - - /* nis_domain */ - if (g_strcmp0(src_priv->nis_domain, dst_priv->nis_domain)) { - nm_ip4_config_set_nis_domain(dst, src_priv->nis_domain); - has_relevant_changes = TRUE; - } - - /* wins */ - num = nm_ip4_config_get_num_wins(src); - are_equal = num == nm_ip4_config_get_num_wins(dst); - if (are_equal) { - for (i = 0; i < num; i++) { - if (nm_ip4_config_get_wins(src, i) != nm_ip4_config_get_wins(dst, i)) { - are_equal = FALSE; - break; - } - } - } - if (!are_equal) { - nm_ip4_config_reset_wins(dst); - for (i = 0; i < num; i++) - nm_ip4_config_add_wins(dst, nm_ip4_config_get_wins(src, i)); - has_relevant_changes = TRUE; - } - - /* mtu */ - if (src_priv->mtu != dst_priv->mtu || src_priv->mtu_source != dst_priv->mtu_source) { - nm_ip4_config_set_mtu(dst, src_priv->mtu, src_priv->mtu_source); - has_minor_changes = TRUE; - } - - /* metered */ - if (src_priv->metered != dst_priv->metered) { - dst_priv->metered = src_priv->metered; - has_minor_changes = TRUE; - } - - /* never default */ - if (src_priv->never_default != dst_priv->never_default) { - dst_priv->never_default = src_priv->never_default; - has_minor_changes = TRUE; - } - -#if NM_MORE_ASSERTS - /* config_equal does not compare *all* the fields, therefore, we might have has_minor_changes - * regardless of config_equal. But config_equal must correspond to has_relevant_changes. */ - nm_assert(config_equal == !has_relevant_changes); -#endif - - g_object_thaw_notify(G_OBJECT(dst)); - - if (relevant_changes) - *relevant_changes = has_relevant_changes; - - return has_relevant_changes || has_minor_changes; -} - -void -nm_ip_config_dump(const NMIPConfig *self, const char *detail, NMLogLevel level, NMLogDomain domain) -{ - NMDedupMultiIter ipconf_iter; - const NMPlatformIP4Address *addr4; - const NMPlatformIP6Address *addr6; - const NMPlatformIP4Route * route4; - const NMPlatformIP6Route * route6; - const NMIP4Config * ip4; - const NMIP6Config * ip6; - int addr_family = AF_UNSPEC; - char addr_family_char = '?'; - const char * path; - gconstpointer ptr; - guint i; - - if (self) { - addr_family = nm_ip_config_get_addr_family(self); - addr_family_char = nm_utils_addr_family_to_char(addr_family); - } - - nm_log(level, domain, NULL, NULL, "---- NMIP%cConfig %p (%s)", addr_family_char, self, detail); - - if (!self) - return; - - path = nm_dbus_object_get_path(NM_DBUS_OBJECT(self)); - if (path) - nm_log(level, domain, NULL, NULL, " path : %s", path); - - if (addr_family == AF_INET) { - ip4 = NM_IP4_CONFIG(self); - nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, ip4, &addr4) { - nm_log(level, - domain, - NULL, - NULL, - " address : %s", - nm_platform_ip4_address_to_string(addr4, NULL, 0)); - } - nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, ip4, &route4) { - nm_log(level, - domain, - NULL, - NULL, - " route : %s", - nm_platform_ip4_route_to_string(route4, NULL, 0)); - } - } else { - ip6 = NM_IP6_CONFIG(self); - nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, ip6, &addr6) { - nm_log(level, - domain, - NULL, - NULL, - " address : %s", - nm_platform_ip6_address_to_string(addr6, NULL, 0)); - } - nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, ip6, &route6) { - nm_log(level, - domain, - NULL, - NULL, - " route : %s", - nm_platform_ip6_route_to_string(route6, NULL, 0)); - } - } - - for (i = 0; i < nm_ip_config_get_num_nameservers(self); i++) { - char buf[NM_UTILS_INET_ADDRSTRLEN]; - - ptr = nm_ip_config_get_nameserver(self, i); - nm_log(level, - domain, - NULL, - NULL, - " dns : %s", - nm_utils_inet_ntop(addr_family, ptr, buf)); - } - - for (i = 0; i < nm_ip_config_get_num_domains(self); i++) - nm_log(level, domain, NULL, NULL, " domain : %s", nm_ip_config_get_domain(self, i)); - - for (i = 0; i < nm_ip_config_get_num_searches(self); i++) - nm_log(level, domain, NULL, NULL, " search : %s", nm_ip_config_get_search(self, i)); - - for (i = 0; i < nm_ip_config_get_num_dns_options(self); i++) - nm_log(level, domain, NULL, NULL, "dns-option: %s", nm_ip_config_get_dns_option(self, i)); - - nm_log(level, domain, NULL, NULL, " dns-prio : %d", nm_ip_config_get_dns_priority(self)); - - if (addr_family == AF_INET) { - ip4 = NM_IP4_CONFIG(self); - nm_log(level, - domain, - NULL, - NULL, - " mtu : %" G_GUINT32_FORMAT " (source: %d)", - nm_ip4_config_get_mtu(ip4), - (int) nm_ip4_config_get_mtu_source(ip4)); - nm_log(level, domain, NULL, NULL, " metered : %d", (int) nm_ip4_config_get_metered(ip4)); - } -} - -/*****************************************************************************/ - -gconstpointer -nm_ip_config_find_first_address(const NMIPConfig *self, NMPlatformMatchFlags match_flag) -{ - NMDedupMultiIter iter; - const NMPlatformIPAddress *address; - - g_return_val_if_fail(NM_IS_IP_CONFIG(self), NULL); - - nm_assert(!NM_FLAGS_ANY( - match_flag, - ~(NM_PLATFORM_MATCH_WITH_ADDRTYPE__ANY | NM_PLATFORM_MATCH_WITH_ADDRSTATE__ANY))); - - nm_ip_config_iter_ip_address_for_each (&iter, self, &address) { - if (nm_platform_ip_address_match(nm_ip_config_get_addr_family(self), address, match_flag)) - return address; - } - - return NULL; -} - -void -nm_ip4_config_reset_addresses(NMIP4Config *self) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - if (nm_dedup_multi_index_remove_idx(priv->multi_idx, &priv->idx_ip4_addresses) > 0) - _notify_addresses(self); -} - -static void -_add_address(NMIP4Config *self, const NMPObject *obj_new, const NMPlatformIP4Address *new) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - if (_nm_ip_config_add_obj(priv->multi_idx, - &priv->idx_ip4_addresses_, - priv->ifindex, - obj_new, - (const NMPlatformObject *) new, - TRUE, - FALSE, - NULL, - NULL)) - _notify_addresses(self); -} - -/** - * nm_ip4_config_add_address: - * @self: the #NMIP4Config - * @new: the new address to add to @self - * - * Adds the new address to @self. If an address with the same basic properties - * (address, prefix) already exists in @self, it is overwritten with the - * lifetime and preferred of @new. The source is also overwritten by the source - * from @new if that source is higher priority. - */ -void -nm_ip4_config_add_address(NMIP4Config *self, const NMPlatformIP4Address *new) -{ - g_return_if_fail(self); - g_return_if_fail(new); - g_return_if_fail(new->plen <= 32); - g_return_if_fail(NM_IP4_CONFIG_GET_PRIVATE(self)->ifindex > 0); - - _add_address(self, NULL, new); -} - -void -_nmtst_ip4_config_del_address(NMIP4Config *self, guint i) -{ - const NMPlatformIP4Address *a; - - a = _nmtst_ip4_config_get_address(self, i); - if (!nm_ip4_config_nmpobj_remove(self, NMP_OBJECT_UP_CAST(a))) - g_assert_not_reached(); -} - -guint -nm_ip4_config_get_num_addresses(const NMIP4Config *self) -{ - const NMDedupMultiHeadEntry *head_entry; - - head_entry = nm_ip4_config_lookup_addresses(self); - return head_entry ? head_entry->len : 0; -} - -const NMPlatformIP4Address * -nm_ip4_config_get_first_address(const NMIP4Config *self) -{ - NMDedupMultiIter iter; - const NMPlatformIP4Address *a = NULL; - - nm_ip_config_iter_ip4_address_for_each (&iter, self, &a) - return a; - return NULL; -} - -const NMPlatformIP4Address * -_nmtst_ip4_config_get_address(const NMIP4Config *self, guint i) -{ - NMDedupMultiIter iter = {}; - const NMPlatformIP4Address *a = NULL; - guint j; - - j = 0; - nm_ip_config_iter_ip4_address_for_each (&iter, self, &a) { - if (i == j) - return a; - j++; - } - g_return_val_if_reached(NULL); -} - -gboolean -nm_ip4_config_address_exists(const NMIP4Config *self, const NMPlatformIP4Address *needle) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - NMPObject obj_stack; - - nmp_object_stackinit_id_ip4_address(&obj_stack, - priv->ifindex, - needle->address, - needle->plen, - needle->peer_address); - return !!nm_dedup_multi_index_lookup_obj(priv->multi_idx, &priv->idx_ip4_addresses, &obj_stack); -} - -/*****************************************************************************/ - -static const NMDedupMultiEntry * -_lookup_route(const NMIP4Config *self, const NMPObject *needle, NMPlatformIPRouteCmpType cmp_type) -{ - const NMIP4ConfigPrivate *priv; - - nm_assert(NM_IS_IP4_CONFIG(self)); - nm_assert(NMP_OBJECT_GET_TYPE(needle) == NMP_OBJECT_TYPE_IP4_ROUTE); - - priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - return _nm_ip_config_lookup_ip_route(priv->multi_idx, &priv->idx_ip4_routes_, needle, cmp_type); -} - -void -nm_ip4_config_reset_routes(NMIP4Config *self) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - if (nm_dedup_multi_index_remove_idx(priv->multi_idx, &priv->idx_ip4_routes) > 0) { - if (nm_clear_nmp_object(&priv->best_default_route)) - _notify(self, PROP_GATEWAY); - _notify_routes(self); - } -} - -static void -_add_route(NMIP4Config * self, - const NMPObject *obj_new, - const NMPlatformIP4Route *new, - const NMPObject **out_obj_new) -{ - NMIP4ConfigPrivate * priv = NM_IP4_CONFIG_GET_PRIVATE(self); - nm_auto_nmpobj const NMPObject *obj_old = NULL; - const NMPObject * obj_new_2; - - nm_assert((!new) != (!obj_new)); - nm_assert(!new || _route_valid(new)); - nm_assert(!obj_new || _route_valid(NMP_OBJECT_CAST_IP4_ROUTE(obj_new))); - - if (_nm_ip_config_add_obj(priv->multi_idx, - &priv->idx_ip4_routes_, - priv->ifindex, - obj_new, - (const NMPlatformObject *) new, - TRUE, - FALSE, - &obj_old, - &obj_new_2)) { - gboolean changed_default_route = FALSE; - - if (priv->best_default_route == obj_old && obj_old != obj_new_2) { - changed_default_route = TRUE; - nm_clear_nmp_object(&priv->best_default_route); - } - NM_SET_OUT(out_obj_new, nmp_object_ref(obj_new_2)); - if (_nm_ip_config_best_default_route_merge(&priv->best_default_route, obj_new_2)) - changed_default_route = TRUE; - - if (changed_default_route) - _notify(self, PROP_GATEWAY); - _notify_routes(self); - } else - NM_SET_OUT(out_obj_new, nmp_object_ref(obj_new_2)); -} - -/** - * nm_ip4_config_add_route: - * @self: the #NMIP4Config - * @new: the new route to add to @self - * @out_obj_new: (allow-none) (out): the added route object. Must be unrefed - * by caller. - * - * Adds the new route to @self. If a route with the same basic properties - * (network, prefix) already exists in @self, it is overwritten including the - * gateway and metric of @new. The source is also overwritten by the source - * from @new if that source is higher priority. - */ -void -nm_ip4_config_add_route(NMIP4Config *self, - const NMPlatformIP4Route *new, - const NMPObject **out_obj_new) -{ - g_return_if_fail(self); - g_return_if_fail(new); - g_return_if_fail(new->plen <= 32); - g_return_if_fail(NM_IP4_CONFIG_GET_PRIVATE(self)->ifindex > 0); - - _add_route(self, NULL, new, out_obj_new); -} - -void -_nmtst_ip4_config_del_route(NMIP4Config *self, guint i) -{ - const NMPlatformIP4Route *r; - - r = _nmtst_ip4_config_get_route(self, i); - if (!nm_ip4_config_nmpobj_remove(self, NMP_OBJECT_UP_CAST(r))) - g_assert_not_reached(); -} - -guint -nm_ip4_config_get_num_routes(const NMIP4Config *self) -{ - const NMDedupMultiHeadEntry *head_entry; - - head_entry = nm_ip4_config_lookup_routes(self); - nm_assert(!head_entry || head_entry->len == c_list_length(&head_entry->lst_entries_head)); - return head_entry ? head_entry->len : 0; -} - -const NMPlatformIP4Route * -_nmtst_ip4_config_get_route(const NMIP4Config *self, guint i) -{ - NMDedupMultiIter iter; - const NMPlatformIP4Route *r = NULL; - guint j; - - j = 0; - nm_ip_config_iter_ip4_route_for_each (&iter, self, &r) { - if (i == j) - return r; - j++; - } - g_return_val_if_reached(NULL); -} - -const NMPlatformIP4Route * -nm_ip4_config_get_direct_route_for_host(const NMIP4Config *self, - in_addr_t host, - guint32 route_table) -{ - const NMPlatformIP4Route *best_route = NULL; - const NMPlatformIP4Route *item; - NMDedupMultiIter ipconf_iter; - - g_return_val_if_fail(host, NULL); - - nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, self, &item) { - if (item->gateway != 0) - continue; - - if (best_route && best_route->plen > item->plen) - continue; - - if (nm_platform_route_table_uncoerce(item->table_coerced, TRUE) != route_table) - continue; - - if (nm_utils_ip4_address_clear_host_address(host, item->plen) - != nm_utils_ip4_address_clear_host_address(item->network, item->plen)) - continue; - - if (best_route && best_route->metric <= item->metric) - continue; - - best_route = item; - } - return best_route; -} - -/*****************************************************************************/ - -void -nm_ip4_config_reset_nameservers(NMIP4Config *self) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - if (priv->nameservers->len != 0) { - g_array_set_size(priv->nameservers, 0); - nm_gobject_notify_together(self, PROP_NAMESERVER_DATA, PROP_NAMESERVERS); - } -} - -void -nm_ip4_config_add_nameserver(NMIP4Config *self, guint32 new) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - int i; - - g_return_if_fail(new != 0); - - for (i = 0; i < priv->nameservers->len; i++) - if (new == g_array_index(priv->nameservers, guint32, i)) - return; - - g_array_append_val(priv->nameservers, new); - nm_gobject_notify_together(self, PROP_NAMESERVER_DATA, PROP_NAMESERVERS); -} - -void -nm_ip4_config_del_nameserver(NMIP4Config *self, guint i) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - g_return_if_fail(i < priv->nameservers->len); - - g_array_remove_index(priv->nameservers, i); - nm_gobject_notify_together(self, PROP_NAMESERVER_DATA, PROP_NAMESERVERS); -} - -guint -nm_ip4_config_get_num_nameservers(const NMIP4Config *self) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - return priv->nameservers->len; -} - -guint32 -nm_ip4_config_get_nameserver(const NMIP4Config *self, guint i) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - return g_array_index(priv->nameservers, guint32, i); -} - -const in_addr_t * -_nm_ip4_config_get_nameserver(const NMIP4Config *self, guint i) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - return &g_array_index(priv->nameservers, guint32, i); -} - -/*****************************************************************************/ - -gboolean -_nm_ip_config_check_and_add_domain(GPtrArray *array, const char *domain) -{ - char * copy = NULL; - size_t len; - - g_return_val_if_fail(domain, FALSE); - g_return_val_if_fail(domain[0] != '\0', FALSE); - - if (domain[0] == '.' || strstr(domain, "..")) - return FALSE; - - len = strlen(domain); - if (domain[len - 1] == '.') - domain = copy = g_strndup(domain, len - 1); - - if (nm_strv_ptrarray_find_first(array, domain) >= 0) { - g_free(copy); - return FALSE; - } - - g_ptr_array_add(array, copy ?: g_strdup(domain)); - return TRUE; -} - -void -nm_ip4_config_reset_domains(NMIP4Config *self) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - if (priv->domains->len != 0) { - g_ptr_array_set_size(priv->domains, 0); - _notify(self, PROP_DOMAINS); - } -} - -void -nm_ip4_config_add_domain(NMIP4Config *self, const char *domain) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - if (_nm_ip_config_check_and_add_domain(priv->domains, domain)) - _notify(self, PROP_DOMAINS); -} - -void -nm_ip4_config_del_domain(NMIP4Config *self, guint i) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - g_return_if_fail(i < priv->domains->len); - - g_ptr_array_remove_index(priv->domains, i); - _notify(self, PROP_DOMAINS); -} - -guint -nm_ip4_config_get_num_domains(const NMIP4Config *self) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - return priv->domains->len; -} - -const char * -nm_ip4_config_get_domain(const NMIP4Config *self, guint i) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - return g_ptr_array_index(priv->domains, i); -} - -/*****************************************************************************/ - -void -nm_ip4_config_reset_searches(NMIP4Config *self) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - if (priv->searches->len != 0) { - g_ptr_array_set_size(priv->searches, 0); - _notify(self, PROP_SEARCHES); - } -} - -void -nm_ip4_config_add_search(NMIP4Config *self, const char *search) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - if (_nm_ip_config_check_and_add_domain(priv->searches, search)) - _notify(self, PROP_SEARCHES); -} - -void -nm_ip4_config_del_search(NMIP4Config *self, guint i) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - g_return_if_fail(i < priv->searches->len); - - g_ptr_array_remove_index(priv->searches, i); - _notify(self, PROP_SEARCHES); -} - -guint -nm_ip4_config_get_num_searches(const NMIP4Config *self) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - return priv->searches->len; -} - -const char * -nm_ip4_config_get_search(const NMIP4Config *self, guint i) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - return g_ptr_array_index(priv->searches, i); -} - -/*****************************************************************************/ - -void -nm_ip4_config_reset_dns_options(NMIP4Config *self) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - if (priv->dns_options->len != 0) { - g_ptr_array_set_size(priv->dns_options, 0); - _notify(self, PROP_DNS_OPTIONS); - } -} - -void -nm_ip4_config_add_dns_option(NMIP4Config *self, const char *new) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - int i; - - g_return_if_fail(new != NULL); - g_return_if_fail(new[0] != '\0'); - - for (i = 0; i < priv->dns_options->len; i++) - if (!g_strcmp0(g_ptr_array_index(priv->dns_options, i), new)) - return; - - g_ptr_array_add(priv->dns_options, g_strdup(new)); - _notify(self, PROP_DNS_OPTIONS); -} - -void -nm_ip4_config_del_dns_option(NMIP4Config *self, guint i) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - g_return_if_fail(i < priv->dns_options->len); - - g_ptr_array_remove_index(priv->dns_options, i); - _notify(self, PROP_DNS_OPTIONS); -} - -guint -nm_ip4_config_get_num_dns_options(const NMIP4Config *self) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - return priv->dns_options->len; -} - -const char * -nm_ip4_config_get_dns_option(const NMIP4Config *self, guint i) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - return g_ptr_array_index(priv->dns_options, i); -} - -/*****************************************************************************/ - -NMSettingConnectionMdns -nm_ip4_config_mdns_get(const NMIP4Config *self) -{ - return NM_IP4_CONFIG_GET_PRIVATE(self)->mdns; -} - -void -nm_ip4_config_mdns_set(NMIP4Config *self, NMSettingConnectionMdns mdns) -{ - NM_IP4_CONFIG_GET_PRIVATE(self)->mdns = mdns; -} - -NMSettingConnectionLlmnr -nm_ip4_config_llmnr_get(const NMIP4Config *self) -{ - return NM_IP4_CONFIG_GET_PRIVATE(self)->llmnr; -} - -void -nm_ip4_config_llmnr_set(NMIP4Config *self, NMSettingConnectionLlmnr llmnr) -{ - NM_IP4_CONFIG_GET_PRIVATE(self)->llmnr = llmnr; -} - -NMSettingConnectionDnsOverTls -nm_ip4_config_dns_over_tls_get(const NMIP4Config *self) -{ - return NM_IP4_CONFIG_GET_PRIVATE(self)->dns_over_tls; -} - -void -nm_ip4_config_dns_over_tls_set(NMIP4Config *self, NMSettingConnectionDnsOverTls dns_over_tls) -{ - NM_IP4_CONFIG_GET_PRIVATE(self)->dns_over_tls = dns_over_tls; -} - -/*****************************************************************************/ - -NMIPConfigFlags -nm_ip4_config_get_config_flags(const NMIP4Config *self) -{ - return NM_IP4_CONFIG_GET_PRIVATE(self)->config_flags; -} - -void -nm_ip4_config_set_config_flags(NMIP4Config *self, NMIPConfigFlags flags, NMIPConfigFlags mask) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - if (mask == 0) { - /* for convenience, accept 0 mask to set any flags. */ - mask = flags; - } - - nm_assert(!NM_FLAGS_ANY(flags, ~mask)); - priv->config_flags = (flags & mask) | (priv->config_flags & ~mask); -} - -/*****************************************************************************/ - -void -nm_ip4_config_set_dns_priority(NMIP4Config *self, int priority) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - if (priority != priv->dns_priority) { - priv->dns_priority = priority; - _notify(self, PROP_DNS_PRIORITY); - } -} - -int -nm_ip4_config_get_dns_priority(const NMIP4Config *self) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - return priv->dns_priority; -} - -/*****************************************************************************/ - -void -nm_ip4_config_reset_nis_servers(NMIP4Config *self) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - g_array_set_size(priv->nis, 0); -} - -void -nm_ip4_config_add_nis_server(NMIP4Config *self, guint32 nis) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - int i; - - for (i = 0; i < priv->nis->len; i++) - if (nis == g_array_index(priv->nis, guint32, i)) - return; - - g_array_append_val(priv->nis, nis); -} - -void -nm_ip4_config_del_nis_server(NMIP4Config *self, guint i) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - g_return_if_fail(i < priv->nis->len); - - g_array_remove_index(priv->nis, i); -} - -guint -nm_ip4_config_get_num_nis_servers(const NMIP4Config *self) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - return priv->nis->len; -} - -guint32 -nm_ip4_config_get_nis_server(const NMIP4Config *self, guint i) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - return g_array_index(priv->nis, guint32, i); -} - -void -nm_ip4_config_set_nis_domain(NMIP4Config *self, const char *domain) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - g_free(priv->nis_domain); - priv->nis_domain = g_strdup(domain); -} - -const char * -nm_ip4_config_get_nis_domain(const NMIP4Config *self) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - return priv->nis_domain; -} - -/*****************************************************************************/ - -void -nm_ip4_config_reset_wins(NMIP4Config *self) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - if (priv->wins->len != 0) { - g_array_set_size(priv->wins, 0); - nm_gobject_notify_together(self, PROP_WINS_SERVER_DATA, PROP_WINS_SERVERS); - } -} - -void -nm_ip4_config_add_wins(NMIP4Config *self, guint32 wins) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - int i; - - g_return_if_fail(wins != 0); - - for (i = 0; i < priv->wins->len; i++) - if (wins == g_array_index(priv->wins, guint32, i)) - return; - - g_array_append_val(priv->wins, wins); - nm_gobject_notify_together(self, PROP_WINS_SERVER_DATA, PROP_WINS_SERVERS); -} - -void -nm_ip4_config_del_wins(NMIP4Config *self, guint i) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - g_return_if_fail(i < priv->wins->len); - - g_array_remove_index(priv->wins, i); - nm_gobject_notify_together(self, PROP_WINS_SERVER_DATA, PROP_WINS_SERVERS); -} - -guint -nm_ip4_config_get_num_wins(const NMIP4Config *self) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - return priv->wins->len; -} - -guint32 -nm_ip4_config_get_wins(const NMIP4Config *self, guint i) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - return g_array_index(priv->wins, guint32, i); -} - -/*****************************************************************************/ - -void -nm_ip4_config_set_mtu(NMIP4Config *self, guint32 mtu, NMIPConfigSource source) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - if (!mtu) - source = NM_IP_CONFIG_SOURCE_UNKNOWN; - - priv->mtu = mtu; - priv->mtu_source = source; -} - -guint32 -nm_ip4_config_get_mtu(const NMIP4Config *self) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - return priv->mtu; -} - -NMIPConfigSource -nm_ip4_config_get_mtu_source(const NMIP4Config *self) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - return priv->mtu_source; -} - -/*****************************************************************************/ - -void -nm_ip4_config_set_metered(NMIP4Config *self, gboolean metered) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - priv->metered = metered; -} - -gboolean -nm_ip4_config_get_metered(const NMIP4Config *self) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - return priv->metered; -} - -/*****************************************************************************/ - -void -nm_ip4_config_set_never_default(NMIP4Config *self, gboolean never_default) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - priv->never_default = never_default; -} - -gboolean -nm_ip4_config_get_never_default(const NMIP4Config *self) -{ - const NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - return priv->never_default; -} - -/*****************************************************************************/ - -const NMPObject * -nm_ip4_config_nmpobj_lookup(const NMIP4Config *self, const NMPObject *needle) -{ - const NMIP4ConfigPrivate * priv; - const NMDedupMultiIdxType *idx_type; - - g_return_val_if_fail(NM_IS_IP4_CONFIG(self), NULL); - - priv = NM_IP4_CONFIG_GET_PRIVATE(self); - switch (NMP_OBJECT_GET_TYPE(needle)) { - case NMP_OBJECT_TYPE_IP4_ADDRESS: - idx_type = &priv->idx_ip4_addresses; - break; - case NMP_OBJECT_TYPE_IP4_ROUTE: - idx_type = &priv->idx_ip4_routes; - break; - default: - g_return_val_if_reached(NULL); - } - - return nm_dedup_multi_entry_get_obj( - nm_dedup_multi_index_lookup_obj(priv->multi_idx, idx_type, needle)); -} - -gboolean -nm_ip4_config_nmpobj_remove(NMIP4Config *self, const NMPObject *needle) -{ - NMIP4ConfigPrivate * priv; - NMDedupMultiIdxType *idx_type; - nm_auto_nmpobj const NMPObject *obj_old = NULL; - guint n; - - g_return_val_if_fail(NM_IS_IP4_CONFIG(self), FALSE); - - priv = NM_IP4_CONFIG_GET_PRIVATE(self); - switch (NMP_OBJECT_GET_TYPE(needle)) { - case NMP_OBJECT_TYPE_IP4_ADDRESS: - idx_type = &priv->idx_ip4_addresses; - break; - case NMP_OBJECT_TYPE_IP4_ROUTE: - idx_type = &priv->idx_ip4_routes; - break; - default: - g_return_val_if_reached(FALSE); - } - - n = nm_dedup_multi_index_remove_obj(priv->multi_idx, - idx_type, - needle, - (gconstpointer *) &obj_old); - if (n != 1) { - nm_assert(n == 0); - return FALSE; - } - - nm_assert(NMP_OBJECT_GET_TYPE(obj_old) == NMP_OBJECT_GET_TYPE(needle)); - - switch (NMP_OBJECT_GET_TYPE(obj_old)) { - case NMP_OBJECT_TYPE_IP4_ADDRESS: - _notify_addresses(self); - break; - case NMP_OBJECT_TYPE_IP4_ROUTE: - if (priv->best_default_route == obj_old) { - if (nmp_object_ref_set(&priv->best_default_route, - _nm_ip4_config_best_default_route_find(self))) - _notify(self, PROP_GATEWAY); - } - _notify_routes(self); - break; - default: - nm_assert_not_reached(); - } - return TRUE; -} - -/*****************************************************************************/ - -static void -hash_u32(GChecksum *sum, guint32 n) -{ - g_checksum_update(sum, (const guint8 *) &n, sizeof(n)); -} - -void -nm_ip4_config_hash(const NMIP4Config *self, GChecksum *sum, gboolean dns_only) -{ - guint i; - const char * s; - NMDedupMultiIter ipconf_iter; - const NMPlatformIP4Address *address; - const NMPlatformIP4Route * route; - int val; - - g_return_if_fail(self); - g_return_if_fail(sum); - - if (!dns_only) { - nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, self, &address) { - hash_u32(sum, address->address); - hash_u32(sum, address->plen); - hash_u32(sum, address->peer_address & _nm_utils_ip4_prefix_to_netmask(address->plen)); - } - - nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, self, &route) { - hash_u32(sum, route->network); - hash_u32(sum, route->plen); - hash_u32(sum, route->gateway); - hash_u32(sum, route->metric); - } - - for (i = 0; i < nm_ip4_config_get_num_nis_servers(self); i++) - hash_u32(sum, nm_ip4_config_get_nis_server(self, i)); - - s = nm_ip4_config_get_nis_domain(self); - if (s) - g_checksum_update(sum, (const guint8 *) s, strlen(s)); - } - - for (i = 0; i < nm_ip4_config_get_num_nameservers(self); i++) - hash_u32(sum, nm_ip4_config_get_nameserver(self, i)); - - for (i = 0; i < nm_ip4_config_get_num_wins(self); i++) - hash_u32(sum, nm_ip4_config_get_wins(self, i)); - - for (i = 0; i < nm_ip4_config_get_num_domains(self); i++) { - s = nm_ip4_config_get_domain(self, i); - g_checksum_update(sum, (const guint8 *) s, strlen(s)); - } - - for (i = 0; i < nm_ip4_config_get_num_searches(self); i++) { - s = nm_ip4_config_get_search(self, i); - g_checksum_update(sum, (const guint8 *) s, strlen(s)); - } - - for (i = 0; i < nm_ip4_config_get_num_dns_options(self); i++) { - s = nm_ip4_config_get_dns_option(self, i); - g_checksum_update(sum, (const guint8 *) s, strlen(s)); - } - - val = nm_ip4_config_mdns_get(self); - if (val != NM_SETTING_CONNECTION_MDNS_DEFAULT) - g_checksum_update(sum, (const guint8 *) &val, sizeof(val)); - - val = nm_ip4_config_llmnr_get(self); - if (val != NM_SETTING_CONNECTION_LLMNR_DEFAULT) - g_checksum_update(sum, (const guint8 *) &val, sizeof(val)); - - val = nm_ip4_config_dns_over_tls_get(self); - if (val != NM_SETTING_CONNECTION_DNS_OVER_TLS_DEFAULT) - g_checksum_update(sum, (const guint8 *) &val, sizeof(val)); - - /* FIXME(ip-config-checksum): the DNS priority should be considered relevant - * and added into the checksum as well, but this can't be done right now - * because in the DNS manager we rely on the fact that an empty - * configuration (i.e. just created) has a zero checksum. This is needed to - * avoid rewriting resolv.conf when there is no change. - * - * The DNS priority initial value depends on the connection type (VPN or - * not), so it's a bit difficult to add it to checksum maintaining the - * assumption of checksum(empty)=0 - */ -} - -/** - * nm_ip4_config_equal: - * @a: first config to compare - * @b: second config to compare - * - * Compares two #NMIP4Configs for basic equality. This means that all - * attributes must exist in the same order in both configs (addresses, routes, - * domains, DNS servers, etc) but some attributes (address lifetimes, and address - * and route sources) are ignored. - * - * Returns: %TRUE if the configurations are basically equal to each other, - * %FALSE if not - */ -gboolean -nm_ip4_config_equal(const NMIP4Config *a, const NMIP4Config *b) -{ - nm_auto_free_checksum GChecksum *a_checksum = g_checksum_new(G_CHECKSUM_SHA1); - nm_auto_free_checksum GChecksum *b_checksum = g_checksum_new(G_CHECKSUM_SHA1); - guint8 a_data[NM_UTILS_CHECKSUM_LENGTH_SHA1]; - guint8 b_data[NM_UTILS_CHECKSUM_LENGTH_SHA1]; - - if (a) - nm_ip4_config_hash(a, a_checksum, FALSE); - if (b) - nm_ip4_config_hash(b, b_checksum, FALSE); - - nm_utils_checksum_get_digest(a_checksum, a_data); - nm_utils_checksum_get_digest(b_checksum, b_data); - return !memcmp(a_data, b_data, sizeof(a_data)); -} - -/*****************************************************************************/ - -static void -get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - NMIP4Config * self = NM_IP4_CONFIG(object); - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - char addr_str[NM_UTILS_INET_ADDRSTRLEN]; - GVariantBuilder builder_data; - guint i; - - switch (prop_id) { - case PROP_IFINDEX: - g_value_set_int(value, priv->ifindex); - break; - case PROP_ADDRESS_DATA: - case PROP_ADDRESSES: - nm_assert(!!priv->address_data_variant == !!priv->addresses_variant); - - if (!priv->address_data_variant) { - nm_utils_ip_addresses_to_dbus(AF_INET, - nm_ip4_config_lookup_addresses(self), - priv->best_default_route, - NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN, - &priv->address_data_variant, - &priv->addresses_variant); - g_variant_ref_sink(priv->address_data_variant); - g_variant_ref_sink(priv->addresses_variant); - } - - g_value_set_variant(value, - prop_id == PROP_ADDRESS_DATA ? priv->address_data_variant - : priv->addresses_variant); - break; - case PROP_ROUTE_DATA: - case PROP_ROUTES: - nm_assert(!!priv->route_data_variant == !!priv->routes_variant); - - if (!priv->route_data_variant) { - nm_utils_ip_routes_to_dbus(AF_INET, - nm_ip4_config_lookup_routes(self), - &priv->route_data_variant, - &priv->routes_variant); - g_variant_ref_sink(priv->route_data_variant); - g_variant_ref_sink(priv->routes_variant); - } - - g_value_set_variant(value, - prop_id == PROP_ROUTE_DATA ? priv->route_data_variant - : priv->routes_variant); - break; - case PROP_GATEWAY: - if (priv->best_default_route) { - g_value_take_string(value, - nm_utils_inet4_ntop_dup( - NMP_OBJECT_CAST_IP4_ROUTE(priv->best_default_route)->gateway)); - } else - g_value_set_string(value, NULL); - break; - case PROP_NAMESERVER_DATA: - g_variant_builder_init(&builder_data, G_VARIANT_TYPE("aa{sv}")); - - for (i = 0; i < priv->nameservers->len; i++) { - GVariantBuilder nested_builder; - - _nm_utils_inet4_ntop(g_array_index(priv->nameservers, in_addr_t, i), addr_str); - - g_variant_builder_init(&nested_builder, G_VARIANT_TYPE("a{sv}")); - g_variant_builder_add(&nested_builder, - "{sv}", - "address", - g_variant_new_string(addr_str)); - g_variant_builder_add(&builder_data, "a{sv}", &nested_builder); - } - - g_value_take_variant(value, g_variant_builder_end(&builder_data)); - break; - case PROP_NAMESERVERS: - g_value_take_variant( - value, - nm_g_variant_new_au((const guint32 *) priv->nameservers->data, priv->nameservers->len)); - break; - case PROP_DOMAINS: - nm_utils_g_value_set_strv(value, priv->domains); - break; - case PROP_SEARCHES: - nm_utils_g_value_set_strv(value, priv->searches); - break; - case PROP_DNS_OPTIONS: - nm_utils_g_value_set_strv(value, priv->dns_options); - break; - case PROP_DNS_PRIORITY: - g_value_set_int(value, priv->dns_priority); - break; - case PROP_WINS_SERVER_DATA: - g_variant_builder_init(&builder_data, G_VARIANT_TYPE("as")); - for (i = 0; i < priv->wins->len; i++) { - g_variant_builder_add( - &builder_data, - "s", - _nm_utils_inet4_ntop(g_array_index(priv->wins, in_addr_t, i), addr_str)); - } - g_value_take_variant(value, g_variant_builder_end(&builder_data)); - break; - case PROP_WINS_SERVERS: - g_value_take_variant( - value, - nm_g_variant_new_au((const guint32 *) priv->wins->data, priv->wins->len)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } -} - -static void -set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) -{ - NMIP4Config * self = NM_IP4_CONFIG(object); - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - switch (prop_id) { - case PROP_MULTI_IDX: - /* construct-only */ - priv->multi_idx = g_value_get_pointer(value); - if (!priv->multi_idx) - g_return_if_reached(); - nm_dedup_multi_index_ref(priv->multi_idx); - break; - case PROP_IFINDEX: - /* construct-only */ - priv->ifindex = g_value_get_int(value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } -} - -/*****************************************************************************/ - -static void -nm_ip4_config_init(NMIP4Config *self) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - nm_ip_config_dedup_multi_idx_type_init((NMIPConfigDedupMultiIdxType *) &priv->idx_ip4_addresses, - NMP_OBJECT_TYPE_IP4_ADDRESS); - nm_ip_config_dedup_multi_idx_type_init((NMIPConfigDedupMultiIdxType *) &priv->idx_ip4_routes, - NMP_OBJECT_TYPE_IP4_ROUTE); - - priv->mdns = NM_SETTING_CONNECTION_MDNS_DEFAULT; - priv->llmnr = NM_SETTING_CONNECTION_LLMNR_DEFAULT; - priv->dns_over_tls = NM_SETTING_CONNECTION_DNS_OVER_TLS_DEFAULT; - priv->nameservers = g_array_new(FALSE, FALSE, sizeof(guint32)); - priv->domains = g_ptr_array_new_with_free_func(g_free); - priv->searches = g_ptr_array_new_with_free_func(g_free); - priv->dns_options = g_ptr_array_new_with_free_func(g_free); - priv->nis = g_array_new(FALSE, TRUE, sizeof(guint32)); - priv->wins = g_array_new(FALSE, TRUE, sizeof(guint32)); -} - -NMIP4Config * -nm_ip4_config_new(NMDedupMultiIndex *multi_idx, int ifindex) -{ - g_return_val_if_fail(ifindex >= -1, NULL); - return g_object_new(NM_TYPE_IP4_CONFIG, - NM_IP4_CONFIG_MULTI_IDX, - multi_idx, - NM_IP4_CONFIG_IFINDEX, - ifindex, - NULL); -} - -static void -finalize(GObject *object) -{ - NMIP4Config * self = NM_IP4_CONFIG(object); - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE(self); - - nm_clear_nmp_object(&priv->best_default_route); - - nm_dedup_multi_index_remove_idx(priv->multi_idx, &priv->idx_ip4_addresses); - nm_dedup_multi_index_remove_idx(priv->multi_idx, &priv->idx_ip4_routes); - - nm_clear_g_variant(&priv->address_data_variant); - nm_clear_g_variant(&priv->addresses_variant); - nm_clear_g_variant(&priv->route_data_variant); - nm_clear_g_variant(&priv->routes_variant); - - g_array_unref(priv->nameservers); - g_ptr_array_unref(priv->domains); - g_ptr_array_unref(priv->searches); - g_ptr_array_unref(priv->dns_options); - g_array_unref(priv->nis); - g_free(priv->nis_domain); - g_array_unref(priv->wins); - - G_OBJECT_CLASS(nm_ip4_config_parent_class)->finalize(object); - - nm_dedup_multi_index_unref(priv->multi_idx); -} - -static const NMDBusInterfaceInfoExtended interface_info_ip4_config = { - .parent = NM_DEFINE_GDBUS_INTERFACE_INFO_INIT( - NM_DBUS_INTERFACE_IP4_CONFIG, - .properties = NM_DEFINE_GDBUS_PROPERTY_INFOS( - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Addresses", - "aau", - NM_IP4_CONFIG_ADDRESSES), - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("AddressData", - "aa{sv}", - NM_IP4_CONFIG_ADDRESS_DATA), - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Gateway", "s", NM_IP4_CONFIG_GATEWAY), - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Routes", "aau", NM_IP4_CONFIG_ROUTES), - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("RouteData", - "aa{sv}", - NM_IP4_CONFIG_ROUTE_DATA), - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("NameserverData", - "aa{sv}", - NM_IP4_CONFIG_NAMESERVER_DATA), - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Nameservers", - "au", - NM_IP4_CONFIG_NAMESERVERS), - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Domains", "as", NM_IP4_CONFIG_DOMAINS), - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Searches", - "as", - NM_IP4_CONFIG_SEARCHES), - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("DnsOptions", - "as", - NM_IP4_CONFIG_DNS_OPTIONS), - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("DnsPriority", - "i", - NM_IP4_CONFIG_DNS_PRIORITY), - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("WinsServerData", - "as", - NM_IP4_CONFIG_WINS_SERVER_DATA), - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("WinsServers", - "au", - NM_IP4_CONFIG_WINS_SERVERS), ), ), -}; - -static void -nm_ip4_config_class_init(NMIP4ConfigClass *klass) -{ - GObjectClass * object_class = G_OBJECT_CLASS(klass); - NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMIPConfigClass * ip_config_class = NM_IP_CONFIG_CLASS(klass); - - ip_config_class->is_ipv4 = TRUE; - ip_config_class->addr_family = AF_INET; - - dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_NUMBERED(NM_DBUS_PATH "/IP4Config"); - dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS(&interface_info_ip4_config); - - object_class->get_property = get_property; - object_class->set_property = set_property; - object_class->finalize = finalize; - - obj_properties[PROP_MULTI_IDX] = - g_param_spec_pointer(NM_IP4_CONFIG_MULTI_IDX, - "", - "", - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_IFINDEX] = - g_param_spec_int(NM_IP4_CONFIG_IFINDEX, - "", - "", - -1, - G_MAXINT, - -1, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_ADDRESS_DATA] = - g_param_spec_variant(NM_IP4_CONFIG_ADDRESS_DATA, - "", - "", - G_VARIANT_TYPE("aa{sv}"), - NULL, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_ADDRESSES] = - g_param_spec_variant(NM_IP4_CONFIG_ADDRESSES, - "", - "", - G_VARIANT_TYPE("aau"), - NULL, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_ROUTE_DATA] = - g_param_spec_variant(NM_IP4_CONFIG_ROUTE_DATA, - "", - "", - G_VARIANT_TYPE("aa{sv}"), - NULL, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_ROUTES] = g_param_spec_variant(NM_IP4_CONFIG_ROUTES, - "", - "", - G_VARIANT_TYPE("aau"), - NULL, - 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_NAMESERVER_DATA] = - g_param_spec_variant(NM_IP4_CONFIG_NAMESERVER_DATA, - "", - "", - G_VARIANT_TYPE("aa{sv}"), - NULL, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_NAMESERVERS] = - g_param_spec_variant(NM_IP4_CONFIG_NAMESERVERS, - "", - "", - G_VARIANT_TYPE("au"), - NULL, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_DOMAINS] = g_param_spec_boxed(NM_IP4_CONFIG_DOMAINS, - "", - "", - G_TYPE_STRV, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_SEARCHES] = g_param_spec_boxed(NM_IP4_CONFIG_SEARCHES, - "", - "", - G_TYPE_STRV, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_DNS_OPTIONS] = - g_param_spec_boxed(NM_IP4_CONFIG_DNS_OPTIONS, - "", - "", - G_TYPE_STRV, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_DNS_PRIORITY] = g_param_spec_int(NM_IP4_CONFIG_DNS_PRIORITY, - "", - "", - G_MININT32, - G_MAXINT32, - 0, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_WINS_SERVER_DATA] = - g_param_spec_variant(NM_IP4_CONFIG_WINS_SERVER_DATA, - "", - "", - G_VARIANT_TYPE("as"), - NULL, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_WINS_SERVERS] = - g_param_spec_variant(NM_IP4_CONFIG_WINS_SERVERS, - "", - "", - G_VARIANT_TYPE("au"), - NULL, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); -} diff --git a/src/core/nm-ip4-config.h b/src/core/nm-ip4-config.h deleted file mode 100644 index 2eb193b2..00000000 --- a/src/core/nm-ip4-config.h +++ /dev/null @@ -1,673 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2008 - 2013 Red Hat, Inc. - */ - -#ifndef __NETWORKMANAGER_IP4_CONFIG_H__ -#define __NETWORKMANAGER_IP4_CONFIG_H__ - -#include "nm-setting-connection.h" - -#include "nm-setting-ip4-config.h" - -#include "libnm-glib-aux/nm-dedup-multi.h" -#include "libnm-platform/nmp-object.h" -#include "nm-ip-config.h" - -/*****************************************************************************/ - -typedef enum _NMIPConfigFlags { - NM_IP_CONFIG_FLAG_NONE = 0, - - /* if set, then the merge flag NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES gets - * ignored during merge. */ - NM_IP_CONFIG_FLAGS_IGNORE_MERGE_NO_DEFAULT_ROUTES = (1ull << 0), -} NMIPConfigFlags; - -typedef struct { - NMDedupMultiIdxType parent; - NMPObjectType obj_type; -} NMIPConfigDedupMultiIdxType; - -void nm_ip_config_dedup_multi_idx_type_init(NMIPConfigDedupMultiIdxType *idx_type, - NMPObjectType obj_type); - -/*****************************************************************************/ - -void nm_ip_config_iter_ip4_address_init(NMDedupMultiIter *iter, const NMIP4Config *self); -void nm_ip_config_iter_ip4_route_init(NMDedupMultiIter *iter, const NMIP4Config *self); - -#define nm_ip_config_iter_ip4_address_for_each(iter, self, address) \ - for (nm_ip_config_iter_ip4_address_init((iter), (self)); \ - nm_platform_dedup_multi_iter_next_ip4_address((iter), (address));) - -#define nm_ip_config_iter_ip4_route_for_each(iter, self, route) \ - for (nm_ip_config_iter_ip4_route_init((iter), (self)); \ - nm_platform_dedup_multi_iter_next_ip4_route((iter), (route));) - -/*****************************************************************************/ - -const NMPObject *_nm_ip_config_best_default_route_find_better(const NMPObject *obj_cur, - const NMPObject *obj_cmp); -gboolean _nm_ip_config_best_default_route_merge(const NMPObject **best_default_route, - const NMPObject * new_candidate); - -/*****************************************************************************/ - -gboolean _nm_ip_config_add_obj(NMDedupMultiIndex * multi_idx, - NMIPConfigDedupMultiIdxType *idx_type, - int ifindex, - const NMPObject * obj_new, - const NMPlatformObject * pl_new, - gboolean merge, - gboolean append_force, - const NMPObject ** out_obj_old, - const NMPObject ** out_obj_new); - -const NMDedupMultiEntry *_nm_ip_config_lookup_ip_route(const NMDedupMultiIndex * multi_idx, - const NMIPConfigDedupMultiIdxType *idx_type, - const NMPObject * needle, - NMPlatformIPRouteCmpType cmp_type); - -/*****************************************************************************/ - -#define NM_TYPE_IP4_CONFIG (nm_ip4_config_get_type()) -#define NM_IP4_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_IP4_CONFIG, NMIP4Config)) -#define NM_IP4_CONFIG_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), NM_TYPE_IP4_CONFIG, NMIP4ConfigClass)) -#define NM_IS_IP4_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NM_TYPE_IP4_CONFIG)) -#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)) - -typedef struct _NMIP4ConfigClass NMIP4ConfigClass; - -/* internal */ -#define NM_IP4_CONFIG_MULTI_IDX "multi-idx" -#define NM_IP4_CONFIG_IFINDEX "ifindex" - -/* public*/ -#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_NAMESERVER_DATA "nameserver-data" -#define NM_IP4_CONFIG_DOMAINS "domains" -#define NM_IP4_CONFIG_SEARCHES "searches" -#define NM_IP4_CONFIG_DNS_OPTIONS "dns-options" -#define NM_IP4_CONFIG_DNS_PRIORITY "dns-priority" -#define NM_IP4_CONFIG_WINS_SERVER_DATA "wins-server-data" - -/* deprecated */ -#define NM_IP4_CONFIG_ADDRESSES "addresses" -#define NM_IP4_CONFIG_ROUTES "routes" -#define NM_IP4_CONFIG_NAMESERVERS "nameservers" -#define NM_IP4_CONFIG_WINS_SERVERS "wins-servers" - -GType nm_ip4_config_get_type(void); - -NMIP4Config *nm_ip4_config_new(NMDedupMultiIndex *multi_idx, int ifindex); - -NMIP4Config *nm_ip4_config_clone(const NMIP4Config *self); -int nm_ip4_config_get_ifindex(const NMIP4Config *self); - -NMDedupMultiIndex *nm_ip4_config_get_multi_idx(const NMIP4Config *self); - -NMIP4Config *nm_ip4_config_capture(NMDedupMultiIndex *multi_idx, NMPlatform *platform, int ifindex); - -void nm_ip4_config_add_dependent_routes(NMIP4Config *self, - guint32 route_table, - guint32 route_metric, - gboolean is_vrf, - GPtrArray ** out_ip4_dev_route_blacklist); - -gboolean nm_ip4_config_commit(const NMIP4Config * self, - NMPlatform * platform, - NMIPRouteTableSyncMode route_table_sync); - -void nm_ip4_config_merge_setting(NMIP4Config * self, - NMSettingIPConfig * setting, - NMSettingConnectionMdns mdns, - NMSettingConnectionLlmnr llmnr, - NMSettingConnectionDnsOverTls dns_over_tls, - guint32 route_table, - guint32 route_metric); -NMSetting *nm_ip4_config_create_setting(const NMIP4Config *self); - -void nm_ip4_config_merge(NMIP4Config * dst, - const NMIP4Config * src, - NMIPConfigMergeFlags merge_flags, - guint32 default_route_metric_penalty); -void nm_ip4_config_subtract(NMIP4Config * dst, - const NMIP4Config *src, - guint32 default_route_metric_penalty); -void nm_ip4_config_intersect(NMIP4Config * dst, - const NMIP4Config *src, - gboolean intersect_addresses, - gboolean intersect_routes, - guint32 default_route_metric_penalty); -NMIP4Config *nm_ip4_config_intersect_alloc(const NMIP4Config *a, - const NMIP4Config *b, - gboolean intersect_addresses, - gboolean intersect_routes, - guint32 default_route_metric_penalty); -gboolean -nm_ip4_config_replace(NMIP4Config *dst, const NMIP4Config *src, gboolean *relevant_changes); - -const NMPObject *nm_ip4_config_best_default_route_get(const NMIP4Config *self); -const NMPObject *_nm_ip4_config_best_default_route_find(const NMIP4Config *self); - -in_addr_t nmtst_ip4_config_get_gateway(NMIP4Config *config); - -NMSettingConnectionMdns nm_ip4_config_mdns_get(const NMIP4Config *self); -void nm_ip4_config_mdns_set(NMIP4Config *self, NMSettingConnectionMdns mdns); -NMSettingConnectionLlmnr nm_ip4_config_llmnr_get(const NMIP4Config *self); -void nm_ip4_config_llmnr_set(NMIP4Config *self, NMSettingConnectionLlmnr llmnr); -NMSettingConnectionDnsOverTls nm_ip4_config_dns_over_tls_get(const NMIP4Config *self); -void nm_ip4_config_dns_over_tls_set(NMIP4Config *self, NMSettingConnectionDnsOverTls dns_over_tls); - -void nm_ip4_config_set_config_flags(NMIP4Config *self, NMIPConfigFlags flags, NMIPConfigFlags mask); -NMIPConfigFlags nm_ip4_config_get_config_flags(const NMIP4Config *self); - -const NMDedupMultiHeadEntry *nm_ip4_config_lookup_addresses(const NMIP4Config *self); -void nm_ip4_config_reset_addresses(NMIP4Config *self); -void nm_ip4_config_add_address(NMIP4Config *self, const NMPlatformIP4Address *address); -void _nmtst_ip4_config_del_address(NMIP4Config *self, guint i); -guint nm_ip4_config_get_num_addresses(const NMIP4Config *self); -const NMPlatformIP4Address *nm_ip4_config_get_first_address(const NMIP4Config *self); -const NMPlatformIP4Address *_nmtst_ip4_config_get_address(const NMIP4Config *self, guint i); -gboolean nm_ip4_config_address_exists(const NMIP4Config *self, const NMPlatformIP4Address *address); - -const NMDedupMultiHeadEntry *nm_ip4_config_lookup_routes(const NMIP4Config *self); -void nm_ip4_config_reset_routes(NMIP4Config *self); -void nm_ip4_config_add_route(NMIP4Config * self, - const NMPlatformIP4Route *route, - const NMPObject ** out_obj_new); -void _nmtst_ip4_config_del_route(NMIP4Config *self, guint i); -guint nm_ip4_config_get_num_routes(const NMIP4Config *self); -const NMPlatformIP4Route * _nmtst_ip4_config_get_route(const NMIP4Config *self, guint i); - -const NMPlatformIP4Route *nm_ip4_config_get_direct_route_for_host(const NMIP4Config *self, - in_addr_t host, - guint32 route_table); -void nm_ip4_config_update_routes_metric(NMIP4Config *self, gint64 metric); - -void nm_ip4_config_reset_nameservers(NMIP4Config *self); -void nm_ip4_config_add_nameserver(NMIP4Config *self, guint32 nameserver); - -static inline void -_nm_ip4_config_add_nameserver(NMIP4Config *self, const guint32 *nameserver) -{ - nm_ip4_config_add_nameserver(self, *nameserver); -} - -void nm_ip4_config_del_nameserver(NMIP4Config *self, guint i); -guint nm_ip4_config_get_num_nameservers(const NMIP4Config *self); -guint32 nm_ip4_config_get_nameserver(const NMIP4Config *self, guint i); -const in_addr_t *_nm_ip4_config_get_nameserver(const NMIP4Config *self, guint i); - -void nm_ip4_config_reset_domains(NMIP4Config *self); -void nm_ip4_config_add_domain(NMIP4Config *self, const char *domain); -void nm_ip4_config_del_domain(NMIP4Config *self, guint i); -guint nm_ip4_config_get_num_domains(const NMIP4Config *self); -const char *nm_ip4_config_get_domain(const NMIP4Config *self, guint i); - -void nm_ip4_config_reset_searches(NMIP4Config *self); -void nm_ip4_config_add_search(NMIP4Config *self, const char *search); -void nm_ip4_config_del_search(NMIP4Config *self, guint i); -guint nm_ip4_config_get_num_searches(const NMIP4Config *self); -const char *nm_ip4_config_get_search(const NMIP4Config *self, guint i); - -void nm_ip4_config_reset_dns_options(NMIP4Config *self); -void nm_ip4_config_add_dns_option(NMIP4Config *self, const char *option); -void nm_ip4_config_del_dns_option(NMIP4Config *self, guint i); -guint nm_ip4_config_get_num_dns_options(const NMIP4Config *self); -const char *nm_ip4_config_get_dns_option(const NMIP4Config *self, guint i); - -void nm_ip4_config_set_dns_priority(NMIP4Config *self, int priority); -int nm_ip4_config_get_dns_priority(const NMIP4Config *self); - -void nm_ip4_config_reset_nis_servers(NMIP4Config *self); -void nm_ip4_config_add_nis_server(NMIP4Config *self, guint32 nis); -void nm_ip4_config_del_nis_server(NMIP4Config *self, guint i); -guint nm_ip4_config_get_num_nis_servers(const NMIP4Config *self); -guint32 nm_ip4_config_get_nis_server(const NMIP4Config *self, guint i); -void nm_ip4_config_set_nis_domain(NMIP4Config *self, const char *domain); -const char *nm_ip4_config_get_nis_domain(const NMIP4Config *self); - -void nm_ip4_config_reset_wins(NMIP4Config *self); -void nm_ip4_config_add_wins(NMIP4Config *self, guint32 wins); -void nm_ip4_config_del_wins(NMIP4Config *self, guint i); -guint nm_ip4_config_get_num_wins(const NMIP4Config *self); -guint32 nm_ip4_config_get_wins(const NMIP4Config *self, guint i); - -void nm_ip4_config_set_mtu(NMIP4Config *self, guint32 mtu, NMIPConfigSource source); -guint32 nm_ip4_config_get_mtu(const NMIP4Config *self); -NMIPConfigSource nm_ip4_config_get_mtu_source(const NMIP4Config *self); - -void nm_ip4_config_set_metered(NMIP4Config *self, gboolean metered); -gboolean nm_ip4_config_get_metered(const NMIP4Config *self); - -void nm_ip4_config_set_never_default(NMIP4Config *self, gboolean never_default); -gboolean nm_ip4_config_get_never_default(const NMIP4Config *self); - -const NMPObject *nm_ip4_config_nmpobj_lookup(const NMIP4Config *self, const NMPObject *needle); -gboolean nm_ip4_config_nmpobj_remove(NMIP4Config *self, const NMPObject *needle); - -void nm_ip4_config_hash(const NMIP4Config *self, GChecksum *sum, gboolean dns_only); -gboolean nm_ip4_config_equal(const NMIP4Config *a, const NMIP4Config *b); - -gboolean _nm_ip_config_check_and_add_domain(GPtrArray *array, const char *domain); - -void -nm_ip_config_dump(const NMIPConfig *self, const char *detail, NMLogLevel level, NMLogDomain domain); - -/*****************************************************************************/ - -#include "nm-ip6-config.h" - -static inline gboolean -NM_IS_IP_CONFIG_ADDR_FAMILY(gconstpointer config, int addr_family) -{ - if (addr_family == AF_UNSPEC) - return NM_IS_IP4_CONFIG(config) || NM_IS_IP6_CONFIG(config); - if (addr_family == AF_INET) - return NM_IS_IP4_CONFIG(config); - if (addr_family == AF_INET6) - return NM_IS_IP6_CONFIG(config); - g_return_val_if_reached(FALSE); -} - -#if _NM_CC_SUPPORT_GENERIC -/* _NM_IS_IP_CONFIG() is a bit unusual. If _Generic() is supported, - * it checks whether @config is either NM_IS_IP4_CONFIG() or NM_IS_IP6_CONFIG(), - * depending on the pointer type of @config. - * - * For example, with _Generic() support, the following assertions would fail: - * NMIP6Config *ptr = (NMIP6Config *) nm_ip4_config_new(...); - * g_assert (_NM_IS_IP_CONFIG (ptr, ptr)); - * but the following would pass: - * NMIP4Config *ptr = nm_ip4_config_new(...); - * g_assert (_NM_IS_IP_CONFIG (ptr, ptr)); - */ -#define _NM_IS_IP_CONFIG(typeexpr, config) \ - ({ \ - const void *const _config = (config); \ - _Generic ((typeexpr), \ - const void *const: (NM_IS_IP4_CONFIG (_config) || NM_IS_IP6_CONFIG (_config)), \ - const void * : (NM_IS_IP4_CONFIG (_config) || NM_IS_IP6_CONFIG (_config)), \ - void *const: (NM_IS_IP4_CONFIG (_config) || NM_IS_IP6_CONFIG (_config)), \ - void * : (NM_IS_IP4_CONFIG (_config) || NM_IS_IP6_CONFIG (_config)), \ - const NMIPConfig *const: (NM_IS_IP4_CONFIG (_config) || NM_IS_IP6_CONFIG (_config)), \ - const NMIPConfig * : (NM_IS_IP4_CONFIG (_config) || NM_IS_IP6_CONFIG (_config)), \ - NMIPConfig *const: (NM_IS_IP4_CONFIG (_config) || NM_IS_IP6_CONFIG (_config)), \ - NMIPConfig * : (NM_IS_IP4_CONFIG (_config) || NM_IS_IP6_CONFIG (_config)), \ - const NMIP4Config *const: (NM_IS_IP4_CONFIG (_config)), \ - const NMIP4Config * : (NM_IS_IP4_CONFIG (_config)), \ - NMIP4Config *const: (NM_IS_IP4_CONFIG (_config)), \ - NMIP4Config * : (NM_IS_IP4_CONFIG (_config)), \ - const NMIP6Config *const: (NM_IS_IP6_CONFIG (_config)), \ - const NMIP6Config * : (NM_IS_IP6_CONFIG (_config)), \ - NMIP6Config *const: (NM_IS_IP6_CONFIG (_config)), \ - NMIP6Config * : (NM_IS_IP6_CONFIG (_config))); \ - }) -#else -#define _NM_IS_IP_CONFIG(typeexpr, config) NM_IS_IP_CONFIG(config) -#endif - -#define NM_IP_CONFIG_CAST(config) \ - ({ \ - const void *const _configx = (config); \ - \ - nm_assert(!_configx || _NM_IS_IP_CONFIG((config), _configx)); \ - NM_CONSTCAST_FULL(NMIPConfig, (config), _configx, NMIP4Config, NMIP6Config); \ - }) - -static inline gboolean -nm_ip_config_is_ipv4(const NMIPConfig *config) -{ - if (NM_IP_CONFIG_GET_CLASS(config)->is_ipv4) { - nm_assert(NM_IS_IP4_CONFIG(config)); - return TRUE; - } - nm_assert(NM_IS_IP6_CONFIG(config)); - return FALSE; -} - -static inline int -nm_ip_config_get_addr_family(const NMIPConfig *config) -{ - return nm_ip_config_is_ipv4(config) ? AF_INET : AF_INET6; -} - -#define _NM_IP_CONFIG_DISPATCH(config, v4_func, v6_func, ...) \ - G_STMT_START \ - { \ - gconstpointer _config = (config); \ - \ - if (nm_ip_config_is_ipv4(_config)) { \ - return v4_func((NMIP4Config *) _config, ##__VA_ARGS__); \ - } else { \ - return v6_func((NMIP6Config *) _config, ##__VA_ARGS__); \ - } \ - } \ - G_STMT_END - -#define _NM_IP_CONFIG_DISPATCH_VOID(config, v4_func, v6_func, ...) \ - G_STMT_START \ - { \ - gconstpointer _config = (config); \ - \ - if (nm_ip_config_is_ipv4(_config)) { \ - v4_func((NMIP4Config *) _config, ##__VA_ARGS__); \ - } else { \ - v6_func((NMIP6Config *) _config, ##__VA_ARGS__); \ - } \ - } \ - G_STMT_END - -static inline int -nm_ip_config_get_ifindex(const NMIPConfig *self) -{ - _NM_IP_CONFIG_DISPATCH(self, nm_ip4_config_get_ifindex, nm_ip6_config_get_ifindex); -} - -static inline void -nm_ip_config_hash(const NMIPConfig *self, GChecksum *sum, gboolean dns_only) -{ - _NM_IP_CONFIG_DISPATCH_VOID(self, nm_ip4_config_hash, nm_ip6_config_hash, sum, dns_only); -} - -static inline gconstpointer -nm_ip_config_get_first_address(NMIPConfig *self) -{ - _NM_IP_CONFIG_DISPATCH(self, nm_ip4_config_get_first_address, nm_ip6_config_get_first_address); -} - -static inline void -nm_ip_config_iter_ip_address_init(NMDedupMultiIter *iter, const NMIPConfig *self) -{ - if (nm_ip_config_is_ipv4(self)) - nm_ip_config_iter_ip4_address_init(iter, (const NMIP4Config *) self); - else - nm_ip_config_iter_ip6_address_init(iter, (const NMIP6Config *) self); -} - -#define nm_ip_config_iter_ip_address_for_each(iter, self, address) \ - for (nm_ip_config_iter_ip_address_init((iter), (self)); \ - nm_platform_dedup_multi_iter_next_ip_address((iter), (address));) - -static inline void -nm_ip_config_iter_ip_route_init(NMDedupMultiIter *iter, const NMIPConfig *self) -{ - if (nm_ip_config_is_ipv4(self)) - nm_ip_config_iter_ip4_route_init(iter, (const NMIP4Config *) self); - else - nm_ip_config_iter_ip6_route_init(iter, (const NMIP6Config *) self); -} - -#define nm_ip_config_iter_ip_route_for_each(iter, self, route) \ - for (nm_ip_config_iter_ip_route_init((iter), (self)); \ - nm_platform_dedup_multi_iter_next_ip_route((iter), (route));) - -static inline void -nm_ip_config_add_address(NMIPConfig *self, const NMPlatformIPAddress *address) -{ - _NM_IP_CONFIG_DISPATCH_VOID(self, - nm_ip4_config_add_address, - nm_ip6_config_add_address, - (gconstpointer) address); -} - -static inline void -nm_ip_config_reset_addresses(NMIPConfig *self) -{ - _NM_IP_CONFIG_DISPATCH_VOID(self, nm_ip4_config_reset_addresses, nm_ip6_config_reset_addresses); -} - -static inline void -nm_ip_config_add_route(NMIPConfig *self, - const NMPlatformIPRoute *new, - const NMPObject **out_obj_new) -{ - _NM_IP_CONFIG_DISPATCH_VOID(self, - nm_ip4_config_add_route, - nm_ip6_config_add_route, - (gpointer) new, - out_obj_new); -} - -static inline void -nm_ip_config_reset_routes(NMIPConfig *self) -{ - _NM_IP_CONFIG_DISPATCH_VOID(self, nm_ip4_config_reset_routes, nm_ip6_config_reset_routes); -} - -static inline int -nm_ip_config_get_dns_priority(const NMIPConfig *self) -{ - _NM_IP_CONFIG_DISPATCH(self, nm_ip4_config_get_dns_priority, nm_ip6_config_get_dns_priority); -} - -static inline void -nm_ip_config_set_dns_priority(NMIPConfig *self, int priority) -{ - _NM_IP_CONFIG_DISPATCH_VOID(self, - nm_ip4_config_set_dns_priority, - nm_ip6_config_set_dns_priority, - priority); -} - -static inline void -nm_ip_config_add_nameserver(NMIPConfig *self, const NMIPAddr *ns) -{ - _NM_IP_CONFIG_DISPATCH_VOID(self, - _nm_ip4_config_add_nameserver, - nm_ip6_config_add_nameserver, - (gconstpointer) ns); -} - -static inline void -nm_ip_config_reset_nameservers(const NMIPConfig *self) -{ - _NM_IP_CONFIG_DISPATCH_VOID(self, - nm_ip4_config_reset_nameservers, - nm_ip6_config_reset_nameservers); -} - -static inline guint -nm_ip_config_get_num_nameservers(const NMIPConfig *self) -{ - _NM_IP_CONFIG_DISPATCH(self, - nm_ip4_config_get_num_nameservers, - nm_ip6_config_get_num_nameservers); -} - -static inline gconstpointer -nm_ip_config_get_nameserver(const NMIPConfig *self, guint i) -{ - _NM_IP_CONFIG_DISPATCH(self, _nm_ip4_config_get_nameserver, nm_ip6_config_get_nameserver, i); -} - -static inline guint -nm_ip_config_get_num_domains(const NMIPConfig *self) -{ - _NM_IP_CONFIG_DISPATCH(self, nm_ip4_config_get_num_domains, nm_ip6_config_get_num_domains); -} - -static inline const char * -nm_ip_config_get_domain(const NMIPConfig *self, guint i) -{ - _NM_IP_CONFIG_DISPATCH(self, nm_ip4_config_get_domain, nm_ip6_config_get_domain, i); -} - -static inline void -nm_ip_config_reset_searches(const NMIPConfig *self) -{ - _NM_IP_CONFIG_DISPATCH_VOID(self, nm_ip4_config_reset_searches, nm_ip6_config_reset_searches); -} - -static inline void -nm_ip_config_add_search(const NMIPConfig *self, const char *new) -{ - _NM_IP_CONFIG_DISPATCH_VOID(self, nm_ip4_config_add_search, nm_ip6_config_add_search, new); -} - -static inline guint -nm_ip_config_get_num_searches(const NMIPConfig *self) -{ - _NM_IP_CONFIG_DISPATCH(self, nm_ip4_config_get_num_searches, nm_ip6_config_get_num_searches); -} - -static inline const char * -nm_ip_config_get_search(const NMIPConfig *self, guint i) -{ - _NM_IP_CONFIG_DISPATCH(self, nm_ip4_config_get_search, nm_ip6_config_get_search, i); -} - -static inline guint -nm_ip_config_get_num_dns_options(const NMIPConfig *self) -{ - _NM_IP_CONFIG_DISPATCH(self, - nm_ip4_config_get_num_dns_options, - nm_ip6_config_get_num_dns_options); -} - -static inline const char * -nm_ip_config_get_dns_option(const NMIPConfig *self, guint i) -{ - _NM_IP_CONFIG_DISPATCH(self, nm_ip4_config_get_dns_option, nm_ip6_config_get_dns_option, i); -} - -static inline const NMPObject * -nm_ip_config_best_default_route_get(const NMIPConfig *self) -{ - _NM_IP_CONFIG_DISPATCH(self, - nm_ip4_config_best_default_route_get, - nm_ip6_config_best_default_route_get); -} - -static inline NMIPConfigFlags -nm_ip_config_get_config_flags(const NMIPConfig *self) -{ - _NM_IP_CONFIG_DISPATCH(self, nm_ip4_config_get_config_flags, nm_ip6_config_get_config_flags); -} - -static inline void -nm_ip_config_set_config_flags(NMIPConfig *self, NMIPConfigFlags flags, NMIPConfigFlags mask) -{ - _NM_IP_CONFIG_DISPATCH_VOID(self, - nm_ip4_config_set_config_flags, - nm_ip6_config_set_config_flags, - flags, - mask); -} - -static inline gboolean -nm_ip_config_get_never_default(const NMIPConfig *self) -{ - _NM_IP_CONFIG_DISPATCH(self, nm_ip4_config_get_never_default, nm_ip6_config_get_never_default); -} - -static inline void -nm_ip_config_set_never_default(NMIPConfig *self, gboolean never_default) -{ - _NM_IP_CONFIG_DISPATCH_VOID(self, - nm_ip4_config_set_never_default, - nm_ip6_config_set_never_default, - never_default); -} - -#define _NM_IP_CONFIG_DISPATCH_SET_OP(_return, dst, src, v4_func, v6_func, ...) \ - G_STMT_START \ - { \ - gpointer _dst = (dst); \ - gconstpointer _src = (src); \ - \ - if (nm_ip_config_is_ipv4(_dst)) { \ - _return v4_func((NMIP4Config *) _dst, (const NMIP4Config *) _src, ##__VA_ARGS__); \ - } else { \ - _return v6_func((NMIP6Config *) _dst, (const NMIP6Config *) _src, ##__VA_ARGS__); \ - } \ - } \ - G_STMT_END - -static inline void -nm_ip_config_intersect(NMIPConfig * dst, - const NMIPConfig *src, - gboolean intersect_addresses, - gboolean intersect_routes, - guint32 default_route_metric_penalty) -{ - _NM_IP_CONFIG_DISPATCH_SET_OP(, - dst, - src, - nm_ip4_config_intersect, - nm_ip6_config_intersect, - intersect_addresses, - intersect_routes, - default_route_metric_penalty); -} - -static inline void -nm_ip_config_subtract(NMIPConfig *dst, const NMIPConfig *src, guint32 default_route_metric_penalty) -{ - _NM_IP_CONFIG_DISPATCH_SET_OP(, - dst, - src, - nm_ip4_config_subtract, - nm_ip6_config_subtract, - default_route_metric_penalty); -} - -static inline void -nm_ip_config_merge(NMIPConfig * dst, - const NMIPConfig * src, - NMIPConfigMergeFlags merge_flags, - guint32 default_route_metric_penalty) -{ - _NM_IP_CONFIG_DISPATCH_SET_OP(, - dst, - src, - nm_ip4_config_merge, - nm_ip6_config_merge, - merge_flags, - default_route_metric_penalty); -} - -static inline gboolean -nm_ip_config_replace(NMIPConfig *dst, const NMIPConfig *src, gboolean *relevant_changes) -{ - _NM_IP_CONFIG_DISPATCH_SET_OP( - return, dst, src, nm_ip4_config_replace, nm_ip6_config_replace, relevant_changes); -} - -static inline NMIPConfig * -nm_ip_config_intersect_alloc(const NMIPConfig *a, - const NMIPConfig *b, - gboolean intersect_addresses, - gboolean intersect_routes, - guint32 default_route_metric_penalty) -{ - if (nm_ip_config_is_ipv4(a)) { - nm_assert(NM_IS_IP4_CONFIG(a)); - nm_assert(NM_IS_IP4_CONFIG(b)); - return (NMIPConfig *) nm_ip4_config_intersect_alloc((const NMIP4Config *) a, - (const NMIP4Config *) b, - intersect_addresses, - intersect_routes, - default_route_metric_penalty); - } else { - nm_assert(NM_IS_IP6_CONFIG(a)); - nm_assert(NM_IS_IP6_CONFIG(b)); - return (NMIPConfig *) nm_ip6_config_intersect_alloc((const NMIP6Config *) a, - (const NMIP6Config *) b, - intersect_addresses, - intersect_routes, - default_route_metric_penalty); - } -} - -gconstpointer nm_ip_config_find_first_address(const NMIPConfig * self, - NMPlatformMatchFlags match_flag); - -#endif /* __NETWORKMANAGER_IP4_CONFIG_H__ */ diff --git a/src/core/nm-ip6-config.c b/src/core/nm-ip6-config.c deleted file mode 100644 index 5ec68bd2..00000000 --- a/src/core/nm-ip6-config.c +++ /dev/null @@ -1,2675 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2005 - 2017 Red Hat, Inc. - * Copyright (C) 2006 - 2008 Novell, Inc. - */ - -#include "src/core/nm-default-daemon.h" - -#include "nm-ip6-config.h" - -#include -#include -#include -#include - -#include "libnm-glib-aux/nm-dedup-multi.h" - -#include "nm-utils.h" -#include "libnm-platform/nmp-object.h" -#include "libnm-platform/nm-platform.h" -#include "libnm-platform/nm-platform-utils.h" -#include "libnm-core-intern/nm-core-internal.h" -#include "NetworkManagerUtils.h" -#include "nm-ip4-config.h" -#include "ndisc/nm-ndisc.h" -#include "nm-dbus-object.h" - -/*****************************************************************************/ - -static gboolean -_route_valid(const NMPlatformIP6Route *r) -{ - struct in6_addr n; - - return r && r->plen <= 128 - && (memcmp(&r->network, - nm_utils_ip6_address_clear_host_address(&n, &r->network, r->plen), - sizeof(n)) - == 0); -} - -/*****************************************************************************/ - -typedef struct { - int ifindex; - int dns_priority; - NMSettingIP6ConfigPrivacy privacy; - GArray * nameservers; - GPtrArray * domains; - GPtrArray * searches; - GPtrArray * dns_options; - GVariant * address_data_variant; - GVariant * addresses_variant; - GVariant * route_data_variant; - GVariant * routes_variant; - NMDedupMultiIndex * multi_idx; - const NMPObject * best_default_route; - union { - NMIPConfigDedupMultiIdxType idx_ip6_addresses_; - NMDedupMultiIdxType idx_ip6_addresses; - }; - union { - NMIPConfigDedupMultiIdxType idx_ip6_routes_; - NMDedupMultiIdxType idx_ip6_routes; - }; - NMIPConfigFlags config_flags; - bool never_default : 1; -} NMIP6ConfigPrivate; - -struct _NMIP6Config { - NMIPConfig parent; - NMIP6ConfigPrivate _priv; -}; - -struct _NMIP6ConfigClass { - NMIPConfigClass parent; -}; - -G_DEFINE_TYPE(NMIP6Config, nm_ip6_config, NM_TYPE_IP_CONFIG) - -#define NM_IP6_CONFIG_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMIP6Config, NM_IS_IP6_CONFIG) - -NM_GOBJECT_PROPERTIES_DEFINE(NMIP6Config, - PROP_MULTI_IDX, - PROP_IFINDEX, - PROP_ADDRESS_DATA, - PROP_ADDRESSES, - PROP_ROUTE_DATA, - PROP_ROUTES, - PROP_GATEWAY, - PROP_NAMESERVERS, - PROP_DOMAINS, - PROP_SEARCHES, - PROP_DNS_OPTIONS, - PROP_DNS_PRIORITY, ); - -/*****************************************************************************/ - -static void -_add_address(NMIP6Config *self, const NMPObject *obj_new, const NMPlatformIP6Address *new); -static void _add_route(NMIP6Config * self, - const NMPObject *obj_new, - const NMPlatformIP6Route *new, - const NMPObject **out_obj_new); -static const NMDedupMultiEntry * -_lookup_route(const NMIP6Config *self, const NMPObject *needle, NMPlatformIPRouteCmpType cmp_type); - -/*****************************************************************************/ - -int -nm_ip6_config_get_ifindex(const NMIP6Config *self) -{ - return NM_IP6_CONFIG_GET_PRIVATE(self)->ifindex; -} - -NMDedupMultiIndex * -nm_ip6_config_get_multi_idx(const NMIP6Config *self) -{ - return NM_IP6_CONFIG_GET_PRIVATE(self)->multi_idx; -} - -void -nm_ip6_config_set_privacy(NMIP6Config *self, NMSettingIP6ConfigPrivacy privacy) -{ - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - priv->privacy = privacy; -} - -/*****************************************************************************/ - -void -nm_ip6_config_set_never_default(NMIP6Config *self, gboolean never_default) -{ - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - priv->never_default = never_default; -} - -gboolean -nm_ip6_config_get_never_default(const NMIP6Config *self) -{ - const NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - return priv->never_default; -} - -/*****************************************************************************/ - -const NMDedupMultiHeadEntry * -nm_ip6_config_lookup_addresses(const NMIP6Config *self) -{ - const NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - return nm_dedup_multi_index_lookup_head(priv->multi_idx, &priv->idx_ip6_addresses, NULL); -} - -void -nm_ip_config_iter_ip6_address_init(NMDedupMultiIter *ipconf_iter, const NMIP6Config *self) -{ - nm_assert(NM_IS_IP6_CONFIG(self)); - - nm_dedup_multi_iter_init(ipconf_iter, nm_ip6_config_lookup_addresses(self)); -} - -/*****************************************************************************/ - -const NMDedupMultiHeadEntry * -nm_ip6_config_lookup_routes(const NMIP6Config *self) -{ - const NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - return nm_dedup_multi_index_lookup_head(priv->multi_idx, &priv->idx_ip6_routes, NULL); -} - -void -nm_ip_config_iter_ip6_route_init(NMDedupMultiIter *ipconf_iter, const NMIP6Config *self) -{ - nm_assert(NM_IS_IP6_CONFIG(self)); - - nm_dedup_multi_iter_init(ipconf_iter, nm_ip6_config_lookup_routes(self)); -} - -/*****************************************************************************/ - -const NMPObject * -nm_ip6_config_best_default_route_get(const NMIP6Config *self) -{ - g_return_val_if_fail(NM_IS_IP6_CONFIG(self), NULL); - - return NM_IP6_CONFIG_GET_PRIVATE(self)->best_default_route; -} - -const NMPObject * -_nm_ip6_config_best_default_route_find(const NMIP6Config *self) -{ - NMDedupMultiIter ipconf_iter; - const NMPObject *new_best_default_route = NULL; - - nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, self, NULL) { - new_best_default_route = - _nm_ip_config_best_default_route_find_better(new_best_default_route, - ipconf_iter.current->obj); - } - return new_best_default_route; -} - -/*****************************************************************************/ - -static void -_notify_addresses(NMIP6Config *self) -{ - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - nm_clear_g_variant(&priv->address_data_variant); - nm_clear_g_variant(&priv->addresses_variant); - nm_gobject_notify_together(self, PROP_ADDRESS_DATA, PROP_ADDRESSES); -} - -static void -_notify_routes(NMIP6Config *self) -{ - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - nm_assert(priv->best_default_route == _nm_ip6_config_best_default_route_find(self)); - nm_clear_g_variant(&priv->route_data_variant); - nm_clear_g_variant(&priv->routes_variant); - nm_gobject_notify_together(self, PROP_ROUTE_DATA, PROP_ROUTES); -} - -/*****************************************************************************/ - -static int -sort_captured_addresses(const CList *lst_a, const CList *lst_b, gconstpointer user_data) -{ - return nm_platform_ip6_address_pretty_sort_cmp( - NMP_OBJECT_CAST_IP6_ADDRESS(c_list_entry(lst_a, NMDedupMultiEntry, lst_entries)->obj), - NMP_OBJECT_CAST_IP6_ADDRESS(c_list_entry(lst_b, NMDedupMultiEntry, lst_entries)->obj), - (((NMSettingIP6ConfigPrivacy) GPOINTER_TO_INT(user_data)) - == NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR)); -} - -gboolean -_nmtst_ip6_config_addresses_sort(NMIP6Config *self) -{ - NMIP6ConfigPrivate * priv; - const NMDedupMultiHeadEntry *head_entry; - - g_return_val_if_fail(NM_IS_IP6_CONFIG(self), FALSE); - - head_entry = nm_ip6_config_lookup_addresses(self); - if (head_entry && head_entry->len > 1) { - gboolean changed; - gs_free gconstpointer *addresses_old = NULL; - guint naddr, j; - NMDedupMultiIter iter; - - priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - addresses_old = nm_dedup_multi_objs_to_array_head(head_entry, NULL, NULL, &naddr); - nm_assert(addresses_old); - nm_assert(naddr > 0 && naddr == head_entry->len); - - nm_dedup_multi_head_entry_sort(head_entry, - sort_captured_addresses, - GINT_TO_POINTER(priv->privacy)); - - changed = FALSE; - j = 0; - nm_dedup_multi_iter_for_each (&iter, head_entry) { - nm_assert(j < naddr); - if (iter.current->obj != addresses_old[j++]) - changed = TRUE; - } - nm_assert(j == naddr); - - if (changed) { - _notify_addresses(self); - return TRUE; - } - } - return FALSE; -} - -NMIP6Config * -nm_ip6_config_clone(const NMIP6Config *self) -{ - NMIP6Config *copy; - - copy = nm_ip6_config_new(nm_ip6_config_get_multi_idx(self), -1); - nm_ip6_config_replace(copy, self, NULL); - - return copy; -} - -NMIP6Config * -nm_ip6_config_capture(NMDedupMultiIndex * multi_idx, - NMPlatform * platform, - int ifindex, - NMSettingIP6ConfigPrivacy use_temporary) -{ - NMIP6Config * self; - NMIP6ConfigPrivate * priv; - const NMDedupMultiHeadEntry *head_entry; - NMDedupMultiIter iter; - const NMPObject * plobj = NULL; - - nm_assert(ifindex > 0); - - /* Slaves have no IP configuration */ - if (nm_platform_link_get_master(platform, ifindex) > 0) - return NULL; - - self = nm_ip6_config_new(multi_idx, ifindex); - priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - head_entry = nm_platform_lookup_object(platform, NMP_OBJECT_TYPE_IP6_ADDRESS, ifindex); - if (head_entry) { - nmp_cache_iter_for_each_reverse (&iter, head_entry, &plobj) { - if (!_nm_ip_config_add_obj(priv->multi_idx, - &priv->idx_ip6_addresses_, - ifindex, - plobj, - NULL, - FALSE, - TRUE, - NULL, - NULL)) - nm_assert_not_reached(); - } - _notify_addresses(self); - } - - head_entry = nm_platform_lookup_object(platform, NMP_OBJECT_TYPE_IP6_ROUTE, ifindex); - - nmp_cache_iter_for_each (&iter, head_entry, &plobj) - _add_route(self, plobj, NULL, NULL); - - return self; -} - -void -nm_ip6_config_update_routes_metric(NMIP6Config *self, gint64 metric) -{ - gs_free NMPlatformIP6Route *routes = NULL; - gboolean need_update = FALSE; - const NMPlatformIP6Route * r; - NMDedupMultiIter iter; - guint num = 0, i = 0; - - nm_ip_config_iter_ip6_route_for_each (&iter, self, &r) { - if (r->metric != metric) - need_update = TRUE; - num++; - } - if (!need_update) - return; - - routes = g_new(NMPlatformIP6Route, num); - nm_ip_config_iter_ip6_route_for_each (&iter, self, &r) { - routes[i] = *r; - routes[i].metric = metric; - i++; - } - - g_object_freeze_notify(G_OBJECT(self)); - nm_ip6_config_reset_routes(self); - for (i = 0; i < num; i++) - nm_ip6_config_add_route(self, &routes[i], NULL); - g_object_thaw_notify(G_OBJECT(self)); -} - -void -nm_ip6_config_add_dependent_routes(NMIP6Config *self, - guint32 route_table, - guint32 route_metric, - gboolean is_vrf) -{ - const NMPlatformIP6Address *my_addr; - const NMPlatformIP6Route * my_route; - int ifindex; - NMDedupMultiIter iter; - - g_return_if_fail(NM_IS_IP6_CONFIG(self)); - - ifindex = nm_ip6_config_get_ifindex(self); - g_return_if_fail(ifindex > 0); - - /* For IPv6 addresses received via SLAAC/autoconf, we explicitly add the - * device-routes (onlink) to NMIP6Config. - * - * For manually added IPv6 routes, add the device routes explicitly. */ - - nm_ip_config_iter_ip6_address_for_each (&iter, self, &my_addr) { - NMPlatformIP6Route *route; - gboolean has_peer; - int routes_n, routes_i; - - if (my_addr->external) - continue; - - if (NM_FLAGS_HAS(my_addr->n_ifa_flags, IFA_F_NOPREFIXROUTE)) - continue; - if (my_addr->plen == 0) - continue; - - has_peer = !IN6_IS_ADDR_UNSPECIFIED(&my_addr->peer_address); - - /* If we have an IPv6 peer, we add two /128 routes - * (unless, both addresses are identical). */ - routes_n = - (has_peer && !IN6_ARE_ADDR_EQUAL(&my_addr->address, &my_addr->peer_address)) ? 2 : 1; - - for (routes_i = 0; routes_i < routes_n; routes_i++) { - nm_auto_nmpobj NMPObject *r = NULL; - - r = nmp_object_new(NMP_OBJECT_TYPE_IP6_ROUTE, NULL); - route = NMP_OBJECT_CAST_IP6_ROUTE(r); - - route->ifindex = ifindex; - route->rt_source = NM_IP_CONFIG_SOURCE_KERNEL; - route->table_coerced = nm_platform_route_table_coerce(route_table); - route->metric = route_metric; - - if (has_peer) { - if (routes_i == 0) - route->network = my_addr->address; - else - route->network = my_addr->peer_address; - route->plen = 128; - } else { - nm_utils_ip6_address_clear_host_address(&route->network, - &my_addr->address, - my_addr->plen); - route->plen = my_addr->plen; - } - - nm_platform_ip_route_normalize(AF_INET6, (NMPlatformIPRoute *) route); - - if (_lookup_route(self, r, NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID)) { - /* we already track this route. Don't add it again. */ - } else - _add_route(self, r, NULL, NULL); - } - } - -again: - nm_ip_config_iter_ip6_route_for_each (&iter, self, &my_route) { - NMPlatformIP6Route rt; - - if (!NM_PLATFORM_IP_ROUTE_IS_DEFAULT(my_route) - || IN6_IS_ADDR_UNSPECIFIED(&my_route->gateway) - || NM_IS_IP_CONFIG_SOURCE_RTPROT(my_route->rt_source) - || nm_ip6_config_get_direct_route_for_host( - self, - &my_route->gateway, - nm_platform_route_table_uncoerce(my_route->table_coerced, TRUE))) - continue; - - rt = *my_route; - rt.network = my_route->gateway; - rt.plen = 128; - rt.gateway = in6addr_any; - _add_route(self, NULL, &rt, NULL); - /* adding the route might have invalidated the iteration. Start again. */ - goto again; - } -} - -gboolean -nm_ip6_config_commit(const NMIP6Config * self, - NMPlatform * platform, - NMIPRouteTableSyncMode route_table_sync, - GPtrArray ** out_temporary_not_available) -{ - gs_unref_ptrarray GPtrArray *addresses = NULL; - gs_unref_ptrarray GPtrArray *routes = NULL; - gs_unref_ptrarray GPtrArray *routes_prune = NULL; - int ifindex; - gboolean success = TRUE; - - g_return_val_if_fail(NM_IS_IP6_CONFIG(self), FALSE); - - ifindex = nm_ip6_config_get_ifindex(self); - g_return_val_if_fail(ifindex > 0, FALSE); - - addresses = - nm_dedup_multi_objs_to_ptr_array_head(nm_ip6_config_lookup_addresses(self), NULL, NULL); - - routes = nm_dedup_multi_objs_to_ptr_array_head(nm_ip6_config_lookup_routes(self), NULL, NULL); - - routes_prune = - nm_platform_ip_route_get_prune_list(platform, AF_INET6, ifindex, route_table_sync); - - nm_platform_ip6_address_sync(platform, ifindex, addresses, FALSE); - - if (!nm_platform_ip_route_sync(platform, - AF_INET6, - ifindex, - routes, - routes_prune, - out_temporary_not_available)) - success = FALSE; - - return success; -} - -void -nm_ip6_config_merge_setting(NMIP6Config * self, - NMSettingIPConfig *setting, - guint32 route_table, - guint32 route_metric) -{ - guint naddresses, nroutes, nnameservers, nsearches; - const char * gateway_str; - struct in6_addr gateway_bin; - int i, priority; - - if (!setting) - return; - - 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(self)); - - /* Gateway */ - if (!nm_setting_ip_config_get_never_default(setting) - && (gateway_str = nm_setting_ip_config_get_gateway(setting)) - && inet_pton(AF_INET6, gateway_str, &gateway_bin) == 1 - && !IN6_IS_ADDR_UNSPECIFIED(&gateway_bin)) { - const NMPlatformIP6Route r = { - .rt_source = NM_IP_CONFIG_SOURCE_USER, - .gateway = gateway_bin, - .table_coerced = nm_platform_route_table_coerce(route_table), - .metric = route_metric, - }; - - _add_route(self, NULL, &r, NULL); - } - - /* Addresses */ - for (i = 0; i < naddresses; i++) { - NMIPAddress * s_addr = nm_setting_ip_config_get_address(setting, i); - NMPlatformIP6Address address; - - memset(&address, 0, sizeof(address)); - nm_ip_address_get_address_binary(s_addr, &address.address); - address.plen = nm_ip_address_get_prefix(s_addr); - nm_assert(address.plen <= 128); - address.lifetime = NM_PLATFORM_LIFETIME_PERMANENT; - address.preferred = NM_PLATFORM_LIFETIME_PERMANENT; - address.addr_source = NM_IP_CONFIG_SOURCE_USER; - - _add_address(self, NULL, &address); - } - - /* Routes */ - for (i = 0; i < nroutes; i++) { - NMIPRoute * s_route = nm_setting_ip_config_get_route(setting, i); - NMPlatformIP6Route route; - gint64 m; - - if (nm_ip_route_get_family(s_route) != AF_INET6) { - nm_assert_not_reached(); - continue; - } - - memset(&route, 0, sizeof(route)); - nm_ip_route_get_dest_binary(s_route, &route.network); - - route.plen = nm_ip_route_get_prefix(s_route); - nm_assert(route.plen <= 128); - - nm_ip_route_get_next_hop_binary(s_route, &route.gateway); - m = nm_ip_route_get_metric(s_route); - if (m < 0) - route.metric = route_metric; - else - route.metric = nm_utils_ip6_route_metric_normalize(m); - route.rt_source = NM_IP_CONFIG_SOURCE_USER; - - nm_utils_ip6_address_clear_host_address(&route.network, &route.network, route.plen); - - nm_utils_ip_route_attribute_to_platform(AF_INET6, - s_route, - NM_PLATFORM_IP_ROUTE_CAST(&route), - route_table); - _add_route(self, NULL, &route, NULL); - } - - /* DNS */ - if (nm_setting_ip_config_get_ignore_auto_dns(setting)) { - nm_ip6_config_reset_nameservers(self); - nm_ip6_config_reset_domains(self); - nm_ip6_config_reset_searches(self); - } - for (i = 0; i < nnameservers; i++) { - struct in6_addr ip; - - if (inet_pton(AF_INET6, nm_setting_ip_config_get_dns(setting, i), &ip) == 1) - nm_ip6_config_add_nameserver(self, &ip); - } - for (i = 0; i < nsearches; i++) - nm_ip6_config_add_search(self, nm_setting_ip_config_get_dns_search(setting, i)); - - i = 0; - while ((i = nm_setting_ip_config_next_valid_dns_option(setting, i)) >= 0) { - nm_ip6_config_add_dns_option(self, nm_setting_ip_config_get_dns_option(setting, i)); - i++; - } - - priority = nm_setting_ip_config_get_dns_priority(setting); - if (priority) - nm_ip6_config_set_dns_priority(self, priority); - - nm_ip6_config_set_never_default(self, nm_setting_ip_config_get_never_default(setting)); - - g_object_thaw_notify(G_OBJECT(self)); -} - -NMSetting * -nm_ip6_config_create_setting(const NMIP6Config *self, gboolean maybe_ipv6_disabled) -{ - const NMIP6ConfigPrivate * priv; - NMSettingIPConfig * s_ip6; - guint nnameservers, nsearches, noptions; - const char * method = NULL; - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; - int i; - NMDedupMultiIter ipconf_iter; - const NMPlatformIP6Address *address; - const NMPlatformIP6Route * route; - - s_ip6 = NM_SETTING_IP_CONFIG(nm_setting_ip6_config_new()); - - if (!self) { - g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); - return NM_SETTING(s_ip6); - } - - priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - nnameservers = nm_ip6_config_get_num_nameservers(self); - nsearches = nm_ip6_config_get_num_searches(self); - noptions = nm_ip6_config_get_num_dns_options(self); - - /* Addresses */ - nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, self, &address) { - NMIPAddress *s_addr; - - /* Ignore link-local address. */ - if (IN6_IS_ADDR_LINKLOCAL(&address->address)) { - if (!method) - method = NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL; - continue; - } - - /* Detect dynamic address */ - if (address->lifetime != NM_PLATFORM_LIFETIME_PERMANENT) { - method = NM_SETTING_IP6_CONFIG_METHOD_AUTO; - continue; - } - - /* Static address found. */ - if (!method || strcmp(method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL) == 0) - method = NM_SETTING_IP6_CONFIG_METHOD_MANUAL; - - 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); - } - - /* Gateway */ - if (priv->best_default_route && nm_setting_ip_config_get_num_addresses(s_ip6) > 0) { - g_object_set( - s_ip6, - NM_SETTING_IP_CONFIG_GATEWAY, - _nm_utils_inet6_ntop(&NMP_OBJECT_CAST_IP6_ROUTE(priv->best_default_route)->gateway, - sbuf), - NULL); - } - - /* Use 'ignore' if the method wasn't previously set */ - if (!method) { - method = maybe_ipv6_disabled ? NM_SETTING_IP6_CONFIG_METHOD_DISABLED - : NM_SETTING_IP6_CONFIG_METHOD_IGNORE; - } - - g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, method, NULL); - - /* Routes */ - nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, self, &route) { - NMIPRoute *s_route; - - /* Ignore link-local route. */ - if (IN6_IS_ADDR_LINKLOCAL(&route->network)) - continue; - - if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT(route)) - continue; - - /* Ignore routes provided by external sources */ - if (route->rt_source - != nmp_utils_ip_config_source_round_trip_rtprot(NM_IP_CONFIG_SOURCE_USER)) - continue; - - 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(self, i); - - nm_setting_ip_config_add_dns(s_ip6, _nm_utils_inet6_ntop(nameserver, sbuf)); - } - for (i = 0; i < nsearches; i++) { - const char *search = nm_ip6_config_get_search(self, i); - - nm_setting_ip_config_add_dns_search(s_ip6, search); - } - for (i = 0; i < noptions; i++) { - const char *option = nm_ip6_config_get_dns_option(self, i); - - nm_setting_ip_config_add_dns_option(s_ip6, option); - } - - g_object_set(s_ip6, - NM_SETTING_IP_CONFIG_DNS_PRIORITY, - nm_ip6_config_get_dns_priority(self), - NULL); - - return NM_SETTING(s_ip6); -} - -/*****************************************************************************/ - -void -nm_ip6_config_merge(NMIP6Config * dst, - const NMIP6Config * src, - NMIPConfigMergeFlags merge_flags, - guint32 default_route_metric_penalty) -{ - guint32 i; - NMDedupMultiIter ipconf_iter; - const NMPlatformIP6Address *address = NULL; - const NMIP6ConfigPrivate * src_priv; - - g_return_if_fail(src != NULL); - g_return_if_fail(dst != NULL); - - src_priv = NM_IP6_CONFIG_GET_PRIVATE(src); - - g_object_freeze_notify(G_OBJECT(dst)); - - /* addresses */ - nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, src, &address) { - if (NM_FLAGS_HAS(merge_flags, NM_IP_CONFIG_MERGE_EXTERNAL) && !address->external) { - NMPlatformIP6Address a; - - a = *address; - a.external = TRUE; - _add_address(dst, NULL, &a); - } else - _add_address(dst, NMP_OBJECT_UP_CAST(address), NULL); - } - - /* nameservers */ - if (!NM_FLAGS_HAS(merge_flags, NM_IP_CONFIG_MERGE_NO_DNS)) { - for (i = 0; i < nm_ip6_config_get_num_nameservers(src); i++) - nm_ip6_config_add_nameserver(dst, nm_ip6_config_get_nameserver(src, i)); - } - - /* routes */ - if (!NM_FLAGS_HAS(merge_flags, NM_IP_CONFIG_MERGE_NO_ROUTES)) { - const NMPlatformIP6Route *r_src; - - nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, src, &r_src) { - if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT(r_src)) { - if (NM_FLAGS_HAS(merge_flags, NM_IP_CONFIG_MERGE_NO_DEFAULT_ROUTES) - && !NM_FLAGS_HAS(src_priv->config_flags, - NM_IP_CONFIG_FLAGS_IGNORE_MERGE_NO_DEFAULT_ROUTES)) - continue; - if (default_route_metric_penalty) { - NMPlatformIP6Route r = *r_src; - - r.metric = - nm_utils_ip_route_metric_penalize(r.metric, default_route_metric_penalty); - _add_route(dst, NULL, &r, NULL); - continue; - } - } - _add_route(dst, ipconf_iter.current->obj, NULL, NULL); - } - } - - /* domains */ - if (!NM_FLAGS_HAS(merge_flags, NM_IP_CONFIG_MERGE_NO_DNS)) { - for (i = 0; i < nm_ip6_config_get_num_domains(src); i++) - nm_ip6_config_add_domain(dst, nm_ip6_config_get_domain(src, i)); - } - - /* dns searches */ - if (!NM_FLAGS_HAS(merge_flags, NM_IP_CONFIG_MERGE_NO_DNS)) { - for (i = 0; i < nm_ip6_config_get_num_searches(src); i++) - nm_ip6_config_add_search(dst, nm_ip6_config_get_search(src, i)); - } - - /* dns options */ - if (!NM_FLAGS_HAS(merge_flags, NM_IP_CONFIG_MERGE_NO_DNS)) { - for (i = 0; i < nm_ip6_config_get_num_dns_options(src); i++) - nm_ip6_config_add_dns_option(dst, nm_ip6_config_get_dns_option(src, i)); - } - - /* DNS priority */ - if (nm_ip6_config_get_dns_priority(src)) - nm_ip6_config_set_dns_priority(dst, nm_ip6_config_get_dns_priority(src)); - - g_object_thaw_notify(G_OBJECT(dst)); -} - -/*****************************************************************************/ - -static int -_nameservers_get_index(const NMIP6Config *self, const struct in6_addr *ns) -{ - const NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - guint i; - - for (i = 0; i < priv->nameservers->len; i++) { - const struct in6_addr *n = &g_array_index(priv->nameservers, struct in6_addr, i); - - if (IN6_ARE_ADDR_EQUAL(ns, n)) - return (int) i; - } - return -1; -} - -static int -_domains_get_index(const NMIP6Config *self, const char *domain) -{ - const NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - guint i; - - for (i = 0; i < priv->domains->len; i++) { - const char *d = g_ptr_array_index(priv->domains, i); - - if (g_strcmp0(domain, d) == 0) - return (int) i; - } - return -1; -} - -static int -_searches_get_index(const NMIP6Config *self, const char *search) -{ - const NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - guint i; - - for (i = 0; i < priv->searches->len; i++) { - const char *s = g_ptr_array_index(priv->searches, i); - - if (g_strcmp0(search, s) == 0) - return (int) i; - } - return -1; -} - -static int -_dns_options_get_index(const NMIP6Config *self, const char *option) -{ - const NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - guint i; - - for (i = 0; i < priv->dns_options->len; i++) { - const char *s = g_ptr_array_index(priv->dns_options, i); - - if (g_strcmp0(option, s) == 0) - return (int) i; - } - return -1; -} - -/*****************************************************************************/ - -/** - * nm_ip6_config_subtract: - * @dst: config from which to remove everything in @src - * @src: config to remove from @dst - * @default_route_metric_penalty: pretend that on source we applied - * a route penalty on the default-route. It means, for default routes - * we don't remove routes that match exactly, but those with a lower - * metric (with the penalty removed). -* - * Removes everything in @src from @dst. - */ -void -nm_ip6_config_subtract(NMIP6Config * dst, - const NMIP6Config *src, - guint32 default_route_metric_penalty) -{ - NMIP6ConfigPrivate * dst_priv; - guint i; - int idx; - const NMPlatformIP6Address *a; - const NMPlatformIP6Route * r; - NMDedupMultiIter ipconf_iter; - gboolean changed; - gboolean changed_default_route; - - g_return_if_fail(src != NULL); - g_return_if_fail(dst != NULL); - - dst_priv = NM_IP6_CONFIG_GET_PRIVATE(dst); - - g_object_freeze_notify(G_OBJECT(dst)); - - /* addresses */ - changed = FALSE; - nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, src, &a) { - if (nm_dedup_multi_index_remove_obj(dst_priv->multi_idx, - &dst_priv->idx_ip6_addresses, - NMP_OBJECT_UP_CAST(a), - NULL)) - changed = TRUE; - } - if (changed) - _notify_addresses(dst); - - /* nameservers */ - for (i = 0; i < nm_ip6_config_get_num_nameservers(src); i++) { - idx = _nameservers_get_index(dst, nm_ip6_config_get_nameserver(src, i)); - if (idx >= 0) - nm_ip6_config_del_nameserver(dst, idx); - } - - /* routes */ - changed = FALSE; - changed_default_route = FALSE; - nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, src, &r) { - const NMPObject * o_src = NMP_OBJECT_UP_CAST(r); - NMPObject o_lookup_copy; - const NMPObject * o_lookup; - nm_auto_nmpobj const NMPObject *obj_old = NULL; - - if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT(r) && default_route_metric_penalty) { - NMPlatformIP6Route *rr; - - /* the default route was penalized when merging it to the combined ip-config. - * When subtracting the routes, we must re-do that process when comparing - * the routes. */ - o_lookup = nmp_object_stackinit_obj(&o_lookup_copy, o_src); - rr = NMP_OBJECT_CAST_IP6_ROUTE(&o_lookup_copy); - rr->metric = - nm_utils_ip_route_metric_penalize(rr->metric, default_route_metric_penalty); - } else - o_lookup = o_src; - - if (nm_dedup_multi_index_remove_obj(dst_priv->multi_idx, - &dst_priv->idx_ip6_routes, - o_lookup, - (gconstpointer *) &obj_old)) { - if (dst_priv->best_default_route == obj_old) { - nm_clear_nmp_object(&dst_priv->best_default_route); - changed_default_route = TRUE; - } - changed = TRUE; - } - } - if (changed_default_route) { - nmp_object_ref_set(&dst_priv->best_default_route, - _nm_ip6_config_best_default_route_find(dst)); - _notify(dst, PROP_GATEWAY); - } - if (changed) - _notify_routes(dst); - - /* domains */ - for (i = 0; i < nm_ip6_config_get_num_domains(src); i++) { - idx = _domains_get_index(dst, nm_ip6_config_get_domain(src, i)); - if (idx >= 0) - nm_ip6_config_del_domain(dst, idx); - } - - /* dns searches */ - for (i = 0; i < nm_ip6_config_get_num_searches(src); i++) { - idx = _searches_get_index(dst, nm_ip6_config_get_search(src, i)); - if (idx >= 0) - nm_ip6_config_del_search(dst, idx); - } - - /* dns options */ - for (i = 0; i < nm_ip6_config_get_num_dns_options(src); i++) { - idx = _dns_options_get_index(dst, nm_ip6_config_get_dns_option(src, i)); - if (idx >= 0) - nm_ip6_config_del_dns_option(dst, idx); - } - - /* DNS priority */ - if (nm_ip6_config_get_dns_priority(src) == nm_ip6_config_get_dns_priority(dst)) - nm_ip6_config_set_dns_priority(dst, 0); - - g_object_thaw_notify(G_OBJECT(dst)); -} - -static gboolean -_nm_ip6_config_intersect_helper(NMIP6Config * dst, - const NMIP6Config *src, - gboolean intersect_addresses, - gboolean intersect_routes, - guint32 default_route_metric_penalty, - gboolean update_dst) -{ - NMIP6ConfigPrivate * dst_priv; - const NMIP6ConfigPrivate * src_priv; - NMDedupMultiIter ipconf_iter; - const NMPlatformIP6Address *a; - const NMPlatformIP6Route * r; - gboolean changed, result = FALSE; - const NMPObject * new_best_default_route; - - g_return_val_if_fail(src, FALSE); - g_return_val_if_fail(dst, FALSE); - - dst_priv = NM_IP6_CONFIG_GET_PRIVATE(dst); - src_priv = NM_IP6_CONFIG_GET_PRIVATE(src); - - if (update_dst) - g_object_freeze_notify(G_OBJECT(dst)); - - /* addresses */ - if (intersect_addresses) { - changed = FALSE; - nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, dst, &a) { - if (nm_dedup_multi_index_lookup_obj(src_priv->multi_idx, - &src_priv->idx_ip6_addresses, - NMP_OBJECT_UP_CAST(a))) - continue; - - if (!update_dst) - return TRUE; - - if (nm_dedup_multi_index_remove_entry(dst_priv->multi_idx, ipconf_iter.current) != 1) - nm_assert_not_reached(); - changed = TRUE; - } - if (changed) { - _notify_addresses(dst); - result = TRUE; - } - } - - /* ignore nameservers */ - - /* routes */ - if (!intersect_routes) - goto skip_routes; - - changed = FALSE; - new_best_default_route = NULL; - nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, dst, &r) { - const NMPObject *o_dst = NMP_OBJECT_UP_CAST(r); - const NMPObject *o_lookup; - NMPObject o_lookup_copy; - - if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT(r) && default_route_metric_penalty) { - NMPlatformIP6Route *rr; - - /* the default route was penalized when merging it to the combined ip-config. - * When intersecting the routes, we must re-do that process when comparing - * the routes. */ - o_lookup = nmp_object_stackinit_obj(&o_lookup_copy, o_dst); - rr = NMP_OBJECT_CAST_IP6_ROUTE(&o_lookup_copy); - rr->metric = - nm_utils_ip_route_metric_penalize(rr->metric, default_route_metric_penalty); - } else - o_lookup = o_dst; - - if (nm_dedup_multi_index_lookup_obj(src_priv->multi_idx, - &src_priv->idx_ip6_routes, - o_lookup)) { - new_best_default_route = - _nm_ip_config_best_default_route_find_better(new_best_default_route, o_dst); - continue; - } - - if (!update_dst) - return TRUE; - - if (nm_dedup_multi_index_remove_entry(dst_priv->multi_idx, ipconf_iter.current) != 1) - nm_assert_not_reached(); - changed = TRUE; - } - if (nmp_object_ref_set(&dst_priv->best_default_route, new_best_default_route)) { - nm_assert(changed); - _notify(dst, PROP_GATEWAY); - } - if (changed) { - _notify_routes(dst); - result = TRUE; - } - -skip_routes: - /* ignore domains */ - /* ignore dns searches */ - /* ignore dns options */ - - if (update_dst) - g_object_thaw_notify(G_OBJECT(dst)); - - return result; -} - -/** - * nm_ip6_config_intersect: - * @dst: a configuration to be updated - * @src: another configuration - * @intersect_addresses: whether addresses should be intersected - * @intersect_routes: whether routes should be intersected - * @default_route_metric_penalty: the default route metric penalty - * - * Computes the intersection between @src and @dst and updates @dst in place - * with the result. - */ -void -nm_ip6_config_intersect(NMIP6Config * dst, - const NMIP6Config *src, - gboolean intersect_addresses, - gboolean intersect_routes, - guint32 default_route_metric_penalty) -{ - _nm_ip6_config_intersect_helper(dst, - src, - intersect_addresses, - intersect_routes, - default_route_metric_penalty, - TRUE); -} - -/** - * nm_ip6_config_intersect_alloc: - * @a: a configuration - * @b: another configuration - * @intersect_addresses: whether addresses should be intersected - * @intersect_routes: whether routes should be intersected - * @default_route_metric_penalty: the default route metric penalty - * - * Computes the intersection between @a and @b and returns the result in a newly - * allocated configuration. As a special case, if @a and @b are identical (with - * respect to the only properties considered - addresses and routes) the - * functions returns NULL so that one of existing configuration can be reused - * without allocation. - * - * Returns: the intersection between @a and @b, or %NULL if the result is equal - * to @a and @b. - */ -NMIP6Config * -nm_ip6_config_intersect_alloc(const NMIP6Config *a, - const NMIP6Config *b, - gboolean intersect_addresses, - gboolean intersect_routes, - guint32 default_route_metric_penalty) -{ - NMIP6Config *a_copy; - - if (_nm_ip6_config_intersect_helper((NMIP6Config *) a, - b, - intersect_addresses, - intersect_routes, - default_route_metric_penalty, - FALSE)) { - a_copy = nm_ip6_config_clone(a); - _nm_ip6_config_intersect_helper(a_copy, - b, - intersect_addresses, - intersect_routes, - default_route_metric_penalty, - TRUE); - return a_copy; - } else - return NULL; -} - -/** - * nm_ip6_config_replace: - * @dst: config which will be replaced with everything in @src - * @src: config to copy over to @dst - * @relevant_changes: return whether there are changes to the - * destination object that are relevant. This is equal to - * nm_ip6_config_equal() showing any difference. - * - * Replaces everything in @dst with @src so that the two configurations - * contain the same content -- with the exception of the dbus path. - * - * Returns: whether the @dst instance changed in any way (including minor changes, - * that are not signaled by the output parameter @relevant_changes). - */ -gboolean -nm_ip6_config_replace(NMIP6Config *dst, const NMIP6Config *src, gboolean *relevant_changes) -{ -#if NM_MORE_ASSERTS - gboolean config_equal; -#endif - gboolean has_minor_changes = FALSE, has_relevant_changes = FALSE, are_equal; - guint i, num; - NMIP6ConfigPrivate * dst_priv; - const NMIP6ConfigPrivate * src_priv; - NMDedupMultiIter ipconf_iter_src, ipconf_iter_dst; - const NMDedupMultiHeadEntry *head_entry_src; - const NMPObject * new_best_default_route; - - g_return_val_if_fail(NM_IS_IP6_CONFIG(src), FALSE); - g_return_val_if_fail(NM_IS_IP6_CONFIG(dst), FALSE); - g_return_val_if_fail(src != dst, FALSE); - -#if NM_MORE_ASSERTS - config_equal = nm_ip6_config_equal(dst, src); -#endif - - dst_priv = NM_IP6_CONFIG_GET_PRIVATE(dst); - src_priv = NM_IP6_CONFIG_GET_PRIVATE(src); - - g_return_val_if_fail(src_priv->ifindex > 0, FALSE); - - g_object_freeze_notify(G_OBJECT(dst)); - - /* ifindex */ - if (src_priv->ifindex != dst_priv->ifindex) { - dst_priv->ifindex = src_priv->ifindex; - has_minor_changes = TRUE; - } - - /* addresses */ - head_entry_src = nm_ip6_config_lookup_addresses(src); - nm_dedup_multi_iter_init(&ipconf_iter_src, head_entry_src); - nm_ip_config_iter_ip6_address_init(&ipconf_iter_dst, dst); - are_equal = TRUE; - while (TRUE) { - gboolean has; - const NMPlatformIP6Address *r_src = NULL; - const NMPlatformIP6Address *r_dst = NULL; - - has = nm_platform_dedup_multi_iter_next_ip6_address(&ipconf_iter_src, &r_src); - if (has != nm_platform_dedup_multi_iter_next_ip6_address(&ipconf_iter_dst, &r_dst)) { - are_equal = FALSE; - has_relevant_changes = TRUE; - break; - } - if (!has) - break; - - if (nm_platform_ip6_address_cmp(r_src, r_dst) != 0) { - are_equal = FALSE; - if (!IN6_ARE_ADDR_EQUAL(&r_src->address, &r_dst->address) || r_src->plen != r_dst->plen - || !IN6_ARE_ADDR_EQUAL(nm_platform_ip6_address_get_peer(r_src), - nm_platform_ip6_address_get_peer(r_dst))) { - has_relevant_changes = TRUE; - break; - } - } - } - if (!are_equal) { - has_minor_changes = TRUE; - nm_dedup_multi_index_dirty_set_idx(dst_priv->multi_idx, &dst_priv->idx_ip6_addresses); - nm_dedup_multi_iter_for_each (&ipconf_iter_src, head_entry_src) { - _nm_ip_config_add_obj(dst_priv->multi_idx, - &dst_priv->idx_ip6_addresses_, - dst_priv->ifindex, - ipconf_iter_src.current->obj, - NULL, - FALSE, - TRUE, - NULL, - NULL); - } - nm_dedup_multi_index_dirty_remove_idx(dst_priv->multi_idx, - &dst_priv->idx_ip6_addresses, - FALSE); - _notify_addresses(dst); - } - - /* routes */ - head_entry_src = nm_ip6_config_lookup_routes(src); - nm_dedup_multi_iter_init(&ipconf_iter_src, head_entry_src); - nm_ip_config_iter_ip6_route_init(&ipconf_iter_dst, dst); - are_equal = TRUE; - while (TRUE) { - gboolean has; - const NMPlatformIP6Route *r_src = NULL; - const NMPlatformIP6Route *r_dst = NULL; - - has = nm_platform_dedup_multi_iter_next_ip6_route(&ipconf_iter_src, &r_src); - if (has != nm_platform_dedup_multi_iter_next_ip6_route(&ipconf_iter_dst, &r_dst)) { - are_equal = FALSE; - has_relevant_changes = TRUE; - break; - } - if (!has) - break; - - if (nm_platform_ip6_route_cmp_full(r_src, r_dst) != 0) { - are_equal = FALSE; - if (r_src->plen != r_dst->plen - || !nm_utils_ip6_address_same_prefix(&r_src->network, &r_dst->network, r_src->plen) - || r_src->metric != r_dst->metric - || !IN6_ARE_ADDR_EQUAL(&r_src->gateway, &r_dst->gateway)) { - has_relevant_changes = TRUE; - break; - } - } - } - if (!are_equal) { - has_minor_changes = TRUE; - new_best_default_route = NULL; - nm_dedup_multi_index_dirty_set_idx(dst_priv->multi_idx, &dst_priv->idx_ip6_routes); - nm_dedup_multi_iter_for_each (&ipconf_iter_src, head_entry_src) { - const NMPObject *o = ipconf_iter_src.current->obj; - const NMPObject *obj_new; - - _nm_ip_config_add_obj(dst_priv->multi_idx, - &dst_priv->idx_ip6_routes_, - dst_priv->ifindex, - o, - NULL, - FALSE, - TRUE, - NULL, - &obj_new); - new_best_default_route = - _nm_ip_config_best_default_route_find_better(new_best_default_route, obj_new); - } - nm_dedup_multi_index_dirty_remove_idx(dst_priv->multi_idx, - &dst_priv->idx_ip6_routes, - FALSE); - if (nmp_object_ref_set(&dst_priv->best_default_route, new_best_default_route)) - _notify(dst, PROP_GATEWAY); - _notify_routes(dst); - } - - /* nameservers */ - num = nm_ip6_config_get_num_nameservers(src); - are_equal = num == nm_ip6_config_get_num_nameservers(dst); - if (are_equal) { - for (i = 0; i < num; i++) { - if (!IN6_ARE_ADDR_EQUAL(nm_ip6_config_get_nameserver(src, i), - nm_ip6_config_get_nameserver(dst, i))) { - are_equal = FALSE; - break; - } - } - } - if (!are_equal) { - nm_ip6_config_reset_nameservers(dst); - for (i = 0; i < num; i++) - nm_ip6_config_add_nameserver(dst, nm_ip6_config_get_nameserver(src, i)); - has_relevant_changes = TRUE; - } - - /* domains */ - num = nm_ip6_config_get_num_domains(src); - are_equal = num == nm_ip6_config_get_num_domains(dst); - if (are_equal) { - for (i = 0; i < num; i++) { - if (g_strcmp0(nm_ip6_config_get_domain(src, i), nm_ip6_config_get_domain(dst, i))) { - are_equal = FALSE; - break; - } - } - } - if (!are_equal) { - nm_ip6_config_reset_domains(dst); - for (i = 0; i < num; i++) - nm_ip6_config_add_domain(dst, nm_ip6_config_get_domain(src, i)); - has_relevant_changes = TRUE; - } - - /* dns searches */ - num = nm_ip6_config_get_num_searches(src); - are_equal = num == nm_ip6_config_get_num_searches(dst); - if (are_equal) { - for (i = 0; i < num; i++) { - if (g_strcmp0(nm_ip6_config_get_search(src, i), nm_ip6_config_get_search(dst, i))) { - are_equal = FALSE; - break; - } - } - } - if (!are_equal) { - nm_ip6_config_reset_searches(dst); - for (i = 0; i < num; i++) - nm_ip6_config_add_search(dst, nm_ip6_config_get_search(src, i)); - has_relevant_changes = TRUE; - } - - /* dns options */ - num = nm_ip6_config_get_num_dns_options(src); - are_equal = num == nm_ip6_config_get_num_dns_options(dst); - if (are_equal) { - for (i = 0; i < num; i++) { - if (g_strcmp0(nm_ip6_config_get_dns_option(src, i), - nm_ip6_config_get_dns_option(dst, i))) { - are_equal = FALSE; - break; - } - } - } - if (!are_equal) { - nm_ip6_config_reset_dns_options(dst); - for (i = 0; i < num; i++) - nm_ip6_config_add_dns_option(dst, nm_ip6_config_get_dns_option(src, i)); - has_relevant_changes = TRUE; - } - - /* DNS priority */ - if (src_priv->dns_priority != dst_priv->dns_priority) { - nm_ip6_config_set_dns_priority(dst, src_priv->dns_priority); - has_minor_changes = TRUE; - } - - if (src_priv->privacy != dst_priv->privacy) { - nm_ip6_config_set_privacy(dst, src_priv->privacy); - has_minor_changes = TRUE; - } - -#if NM_MORE_ASSERTS - /* config_equal does not compare *all* the fields, therefore, we might have has_minor_changes - * regardless of config_equal. But config_equal must correspond to has_relevant_changes. */ - nm_assert(config_equal == !has_relevant_changes); -#endif - - g_object_thaw_notify(G_OBJECT(dst)); - - if (relevant_changes) - *relevant_changes = has_relevant_changes; - - return has_relevant_changes || has_minor_changes; -} - -/*****************************************************************************/ - -void -nm_ip6_config_reset_addresses_ndisc(NMIP6Config * self, - const NMNDiscAddress *addresses, - guint addresses_n, - guint8 plen, - guint32 ifa_flags) -{ - NMIP6ConfigPrivate *priv; - guint i; - gboolean changed = FALSE; - gint32 base_time_sec; - - g_return_if_fail(NM_IS_IP6_CONFIG(self)); - - priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - g_return_if_fail(priv->ifindex > 0); - - /* the base-timestamp doesn't matter it's only an anchor for the - * expiry. However, try to re-use the same base-time for a while - * by rounding it to 10000 seconds. - * - * That is because we deduplicate and NMPlatformIP6Address instances - * so using the same timestamps is preferable. */ - base_time_sec = nm_utils_get_monotonic_timestamp_sec(); - base_time_sec = (base_time_sec / 10000) * 10000; - base_time_sec = NM_MAX(1, base_time_sec); - - nm_dedup_multi_index_dirty_set_idx(priv->multi_idx, &priv->idx_ip6_addresses); - - for (i = 0; i < addresses_n; i++) { - const NMNDiscAddress *ndisc_addr = &addresses[i]; - NMPObject obj; - NMPlatformIP6Address *a; - - nmp_object_stackinit(&obj, NMP_OBJECT_TYPE_IP6_ADDRESS, NULL); - a = NMP_OBJECT_CAST_IP6_ADDRESS(&obj); - a->ifindex = priv->ifindex; - a->address = ndisc_addr->address; - a->plen = plen; - a->timestamp = base_time_sec, - a->lifetime = _nm_ndisc_lifetime_from_expiry(((gint64) base_time_sec) * 1000, - ndisc_addr->expiry_msec, - TRUE), - a->preferred = _nm_ndisc_lifetime_from_expiry(((gint64) base_time_sec) * 1000, - ndisc_addr->expiry_preferred_msec, - TRUE), - a->addr_source = NM_IP_CONFIG_SOURCE_NDISC; - a->n_ifa_flags = ifa_flags; - - if (_nm_ip_config_add_obj(priv->multi_idx, - &priv->idx_ip6_addresses_, - priv->ifindex, - &obj, - NULL, - FALSE, - TRUE, - NULL, - NULL)) - changed = TRUE; - } - - if (nm_dedup_multi_index_dirty_remove_idx(priv->multi_idx, &priv->idx_ip6_addresses, FALSE) > 0) - changed = TRUE; - - if (changed) - _notify_addresses(self); -} - -void -nm_ip6_config_reset_addresses(NMIP6Config *self) -{ - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - if (nm_dedup_multi_index_remove_idx(priv->multi_idx, &priv->idx_ip6_addresses) > 0) - _notify_addresses(self); -} - -static void -_add_address(NMIP6Config *self, const NMPObject *obj_new, const NMPlatformIP6Address *new) -{ - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - if (_nm_ip_config_add_obj(priv->multi_idx, - &priv->idx_ip6_addresses_, - priv->ifindex, - obj_new, - (const NMPlatformObject *) new, - TRUE, - FALSE, - NULL, - NULL)) - _notify_addresses(self); -} - -/** - * nm_ip6_config_add_address: - * @self: the #NMIP6Config - * @new: the new address to add to @self - * - * Adds the new address to @self. If an address with the same basic properties - * (address, prefix) already exists in @self, it is overwritten with the - * lifetime and preferred of @new. The source is also overwritten by the source - * from @new if that source is higher priority. - */ -void -nm_ip6_config_add_address(NMIP6Config *self, const NMPlatformIP6Address *new) -{ - g_return_if_fail(self); - g_return_if_fail(new); - g_return_if_fail(new->plen <= 128); - g_return_if_fail(NM_IP6_CONFIG_GET_PRIVATE(self)->ifindex > 0); - - _add_address(self, NULL, new); -} - -void -_nmtst_ip6_config_del_address(NMIP6Config *self, guint i) -{ - const NMPlatformIP6Address *a; - - a = _nmtst_ip6_config_get_address(self, i); - if (!nm_ip6_config_nmpobj_remove(self, NMP_OBJECT_UP_CAST(a))) - g_assert_not_reached(); -} - -guint -nm_ip6_config_get_num_addresses(const NMIP6Config *self) -{ - const NMDedupMultiHeadEntry *head_entry; - - head_entry = nm_ip6_config_lookup_addresses(self); - return head_entry ? head_entry->len : 0; -} - -const NMPlatformIP6Address * -nm_ip6_config_get_first_address(const NMIP6Config *self) -{ - NMDedupMultiIter iter; - const NMPlatformIP6Address *a = NULL; - - nm_ip_config_iter_ip6_address_for_each (&iter, self, &a) - return a; - return NULL; -} - -const NMPlatformIP6Address * -_nmtst_ip6_config_get_address(const NMIP6Config *self, guint i) -{ - NMDedupMultiIter iter; - const NMPlatformIP6Address *a = NULL; - guint j; - - j = 0; - nm_ip_config_iter_ip6_address_for_each (&iter, self, &a) { - if (i == j) - return a; - j++; - } - g_return_val_if_reached(NULL); -} - -const NMPlatformIP6Address * -nm_ip6_config_lookup_address(const NMIP6Config *self, const struct in6_addr *addr) -{ - const NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - NMPObject obj_stack; - const NMDedupMultiEntry * entry; - - nmp_object_stackinit_id_ip6_address(&obj_stack, priv->ifindex, addr); - entry = nm_dedup_multi_index_lookup_obj(priv->multi_idx, &priv->idx_ip6_addresses, &obj_stack); - return entry ? NMP_OBJECT_CAST_IP6_ADDRESS(entry->obj) : NULL; -} - -/** - * nm_ip6_config_has_dad_pending_addresses - * @self: configuration containing the addresses to check - * @candidates: configuration with the list of addresses we are - * interested in - * - * Check whether there are addresses with DAD pending in @self, that - * are also contained in @candidates. - * - * Returns: %TRUE if at least one matching address was found, %FALSE - * otherwise - */ -gboolean -nm_ip6_config_has_any_dad_pending(const NMIP6Config *self, const NMIP6Config *candidates) -{ - NMDedupMultiIter ipconf_iter; - const NMPlatformIP6Address *addr, *addr_c; - - nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, self, &addr) { - if (NM_FLAGS_HAS(addr->n_ifa_flags, IFA_F_TENTATIVE) - && !NM_FLAGS_HAS(addr->n_ifa_flags, IFA_F_DADFAILED) - && !NM_FLAGS_HAS(addr->n_ifa_flags, IFA_F_OPTIMISTIC)) { - addr_c = nm_ip6_config_lookup_address(candidates, &addr->address); - if (addr_c) { - if (addr->plen == addr_c->plen) - return TRUE; - } - } - } - - return FALSE; -} - -/*****************************************************************************/ - -static const NMDedupMultiEntry * -_lookup_route(const NMIP6Config *self, const NMPObject *needle, NMPlatformIPRouteCmpType cmp_type) -{ - const NMIP6ConfigPrivate *priv; - - nm_assert(NM_IS_IP6_CONFIG(self)); - nm_assert(NMP_OBJECT_GET_TYPE(needle) == NMP_OBJECT_TYPE_IP6_ROUTE); - - priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - return _nm_ip_config_lookup_ip_route(priv->multi_idx, &priv->idx_ip6_routes_, needle, cmp_type); -} - -void -nm_ip6_config_reset_routes_ndisc(NMIP6Config * self, - const NMNDiscGateway *gateways, - guint gateways_n, - const NMNDiscRoute * routes, - guint routes_n, - guint32 route_table, - guint32 route_metric) -{ - NMIP6ConfigPrivate *priv; - guint i; - gboolean changed = FALSE; - const NMPObject * new_best_default_route; - - g_return_if_fail(NM_IS_IP6_CONFIG(self)); - - priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - g_return_if_fail(priv->ifindex > 0); - - nm_dedup_multi_index_dirty_set_idx(priv->multi_idx, &priv->idx_ip6_routes); - - new_best_default_route = NULL; - for (i = 0; i < routes_n; i++) { - const NMNDiscRoute *ndisc_route = &routes[i]; - NMPObject obj; - const NMPObject * obj_new; - NMPlatformIP6Route *r; - - nmp_object_stackinit(&obj, NMP_OBJECT_TYPE_IP6_ROUTE, NULL); - r = NMP_OBJECT_CAST_IP6_ROUTE(&obj); - r->ifindex = priv->ifindex; - r->network = ndisc_route->network; - r->plen = ndisc_route->plen; - r->gateway = ndisc_route->gateway; - r->rt_source = NM_IP_CONFIG_SOURCE_NDISC; - r->table_coerced = nm_platform_route_table_coerce(route_table); - r->metric = route_metric; - r->rt_pref = ndisc_route->preference; - nm_assert((NMIcmpv6RouterPref) r->rt_pref == ndisc_route->preference); - - if (_nm_ip_config_add_obj(priv->multi_idx, - &priv->idx_ip6_routes_, - priv->ifindex, - &obj, - NULL, - FALSE, - TRUE, - NULL, - &obj_new)) - changed = TRUE; - new_best_default_route = - _nm_ip_config_best_default_route_find_better(new_best_default_route, obj_new); - } - - if (gateways_n) { - const NMPObject * obj_new; - NMPlatformIP6Route r = { - .rt_source = NM_IP_CONFIG_SOURCE_NDISC, - .ifindex = priv->ifindex, - .table_coerced = nm_platform_route_table_coerce(route_table), - .metric = route_metric, - }; - - for (i = 0; i < gateways_n; i++) { - r.gateway = gateways[i].address; - r.rt_pref = gateways[i].preference; - nm_assert((NMIcmpv6RouterPref) r.rt_pref == gateways[i].preference); - if (_nm_ip_config_add_obj(priv->multi_idx, - &priv->idx_ip6_routes_, - priv->ifindex, - NULL, - (const NMPlatformObject *) &r, - FALSE, - TRUE, - NULL, - &obj_new)) - changed = TRUE; - new_best_default_route = - _nm_ip_config_best_default_route_find_better(new_best_default_route, obj_new); - } - } - - if (nm_dedup_multi_index_dirty_remove_idx(priv->multi_idx, &priv->idx_ip6_routes, FALSE) > 0) - changed = TRUE; - - if (nmp_object_ref_set(&priv->best_default_route, new_best_default_route)) { - changed = TRUE; - _notify(self, PROP_GATEWAY); - } - - if (changed) - _notify_routes(self); -} - -void -nm_ip6_config_reset_routes(NMIP6Config *self) -{ - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - if (nm_dedup_multi_index_remove_idx(priv->multi_idx, &priv->idx_ip6_routes) > 0) { - if (nm_clear_nmp_object(&priv->best_default_route)) - _notify(self, PROP_GATEWAY); - _notify_routes(self); - } -} - -static void -_add_route(NMIP6Config * self, - const NMPObject *obj_new, - const NMPlatformIP6Route *new, - const NMPObject **out_obj_new) -{ - NMIP6ConfigPrivate * priv = NM_IP6_CONFIG_GET_PRIVATE(self); - nm_auto_nmpobj const NMPObject *obj_old = NULL; - const NMPObject * obj_new_2; - - nm_assert((!new) != (!obj_new)); - nm_assert(!new || _route_valid(new)); - nm_assert(!obj_new || _route_valid(NMP_OBJECT_CAST_IP6_ROUTE(obj_new))); - - if (_nm_ip_config_add_obj(priv->multi_idx, - &priv->idx_ip6_routes_, - priv->ifindex, - obj_new, - (const NMPlatformObject *) new, - TRUE, - FALSE, - &obj_old, - &obj_new_2)) { - gboolean changed_default_route = FALSE; - - if (priv->best_default_route == obj_old && obj_old != obj_new_2) { - changed_default_route = TRUE; - nm_clear_nmp_object(&priv->best_default_route); - } - NM_SET_OUT(out_obj_new, nmp_object_ref(obj_new_2)); - if (_nm_ip_config_best_default_route_merge(&priv->best_default_route, obj_new_2)) - changed_default_route = TRUE; - - if (changed_default_route) - _notify(self, PROP_GATEWAY); - _notify_routes(self); - } else - NM_SET_OUT(out_obj_new, nmp_object_ref(obj_new_2)); -} - -/** - * nm_ip6_config_add_route: - * @self: the #NMIP6Config - * @new: the new route to add to @self - * @out_obj_new: (allow-none) (out): the added route object. Must be unrefed - * by caller. - * - * Adds the new route to @self. If a route with the same basic properties - * (network, prefix) already exists in @self, it is overwritten including the - * gateway and metric of @new. The source is also overwritten by the source - * from @new if that source is higher priority. - */ -void -nm_ip6_config_add_route(NMIP6Config *self, - const NMPlatformIP6Route *new, - const NMPObject **out_obj_new) -{ - g_return_if_fail(self); - g_return_if_fail(new); - g_return_if_fail(new->plen <= 128); - g_return_if_fail(NM_IP6_CONFIG_GET_PRIVATE(self)->ifindex > 0); - - _add_route(self, NULL, new, out_obj_new); -} - -void -_nmtst_ip6_config_del_route(NMIP6Config *self, guint i) -{ - const NMPlatformIP6Route *r; - - r = _nmtst_ip6_config_get_route(self, i); - if (!nm_ip6_config_nmpobj_remove(self, NMP_OBJECT_UP_CAST(r))) - g_assert_not_reached(); -} - -guint -nm_ip6_config_get_num_routes(const NMIP6Config *self) -{ - const NMDedupMultiHeadEntry *head_entry; - - head_entry = nm_ip6_config_lookup_routes(self); - nm_assert(!head_entry || head_entry->len == c_list_length(&head_entry->lst_entries_head)); - return head_entry ? head_entry->len : 0; -} - -const NMPlatformIP6Route * -_nmtst_ip6_config_get_route(const NMIP6Config *self, guint i) -{ - NMDedupMultiIter iter; - const NMPlatformIP6Route *r = NULL; - guint j; - - j = 0; - nm_ip_config_iter_ip6_route_for_each (&iter, self, &r) { - if (i == j) - return r; - j++; - } - g_return_val_if_reached(NULL); -} - -const NMPlatformIP6Route * -nm_ip6_config_get_direct_route_for_host(const NMIP6Config * self, - const struct in6_addr *host, - guint32 route_table) -{ - const NMPlatformIP6Route *best_route = NULL; - const NMPlatformIP6Route *item; - NMDedupMultiIter ipconf_iter; - - g_return_val_if_fail(host && !IN6_IS_ADDR_UNSPECIFIED(host), NULL); - - nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, self, &item) { - if (!IN6_IS_ADDR_UNSPECIFIED(&item->gateway)) - continue; - - if (best_route && best_route->plen > item->plen) - continue; - - if (nm_platform_route_table_uncoerce(item->table_coerced, TRUE) != route_table) - continue; - - if (!nm_utils_ip6_address_same_prefix(host, &item->network, item->plen)) - continue; - - if (best_route && best_route->metric <= item->metric) - continue; - - best_route = item; - } - return best_route; -} - -const NMPlatformIP6Address * -nm_ip6_config_get_subnet_for_host(const NMIP6Config *self, const struct in6_addr *host) -{ - NMDedupMultiIter iter; - const NMPlatformIP6Address *item; - const NMPlatformIP6Address *subnet = NULL; - struct in6_addr subnet2, host2; - - g_return_val_if_fail(host && !IN6_IS_ADDR_UNSPECIFIED(host), NULL); - - nm_ip_config_iter_ip6_address_for_each (&iter, self, &item) { - 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 -nm_ip6_config_reset_nameservers(NMIP6Config *self) -{ - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - if (priv->nameservers->len != 0) { - g_array_set_size(priv->nameservers, 0); - _notify(self, PROP_NAMESERVERS); - } -} - -void -nm_ip6_config_add_nameserver(NMIP6Config *self, const struct in6_addr *new) -{ - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - int i; - - g_return_if_fail(new != NULL); - - for (i = 0; i < priv->nameservers->len; i++) - if (IN6_ARE_ADDR_EQUAL(new, &g_array_index(priv->nameservers, struct in6_addr, i))) - return; - - g_array_append_val(priv->nameservers, *new); - _notify(self, PROP_NAMESERVERS); -} - -void -nm_ip6_config_del_nameserver(NMIP6Config *self, guint i) -{ - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - g_return_if_fail(i < priv->nameservers->len); - - g_array_remove_index(priv->nameservers, i); - _notify(self, PROP_NAMESERVERS); -} - -guint -nm_ip6_config_get_num_nameservers(const NMIP6Config *self) -{ - const NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - return priv->nameservers->len; -} - -const struct in6_addr * -nm_ip6_config_get_nameserver(const NMIP6Config *self, guint i) -{ - const NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - return &g_array_index(priv->nameservers, struct in6_addr, i); -} - -/*****************************************************************************/ - -void -nm_ip6_config_reset_domains(NMIP6Config *self) -{ - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - if (priv->domains->len != 0) { - g_ptr_array_set_size(priv->domains, 0); - _notify(self, PROP_DOMAINS); - } -} - -void -nm_ip6_config_add_domain(NMIP6Config *self, const char *domain) -{ - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - if (_nm_ip_config_check_and_add_domain(priv->domains, domain)) - _notify(self, PROP_DOMAINS); -} - -void -nm_ip6_config_del_domain(NMIP6Config *self, guint i) -{ - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - g_return_if_fail(i < priv->domains->len); - - g_ptr_array_remove_index(priv->domains, i); - _notify(self, PROP_DOMAINS); -} - -guint -nm_ip6_config_get_num_domains(const NMIP6Config *self) -{ - const NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - return priv->domains->len; -} - -const char * -nm_ip6_config_get_domain(const NMIP6Config *self, guint i) -{ - const NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - return g_ptr_array_index(priv->domains, i); -} - -/*****************************************************************************/ - -void -nm_ip6_config_reset_searches(NMIP6Config *self) -{ - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - if (priv->searches->len != 0) { - g_ptr_array_set_size(priv->searches, 0); - _notify(self, PROP_SEARCHES); - } -} - -void -nm_ip6_config_add_search(NMIP6Config *self, const char *search) -{ - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - if (_nm_ip_config_check_and_add_domain(priv->searches, search)) - _notify(self, PROP_SEARCHES); -} - -void -nm_ip6_config_del_search(NMIP6Config *self, guint i) -{ - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - g_return_if_fail(i < priv->searches->len); - - g_ptr_array_remove_index(priv->searches, i); - _notify(self, PROP_SEARCHES); -} - -guint -nm_ip6_config_get_num_searches(const NMIP6Config *self) -{ - const NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - return priv->searches->len; -} - -const char * -nm_ip6_config_get_search(const NMIP6Config *self, guint i) -{ - const NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - return g_ptr_array_index(priv->searches, i); -} - -/*****************************************************************************/ - -void -nm_ip6_config_reset_dns_options(NMIP6Config *self) -{ - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - if (priv->dns_options->len != 0) { - g_ptr_array_set_size(priv->dns_options, 0); - _notify(self, PROP_DNS_OPTIONS); - } -} - -void -nm_ip6_config_add_dns_option(NMIP6Config *self, const char *new) -{ - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - int i; - - g_return_if_fail(new != NULL); - g_return_if_fail(new[0] != '\0'); - - for (i = 0; i < priv->dns_options->len; i++) - if (!g_strcmp0(g_ptr_array_index(priv->dns_options, i), new)) - return; - - g_ptr_array_add(priv->dns_options, g_strdup(new)); - _notify(self, PROP_DNS_OPTIONS); -} - -void -nm_ip6_config_del_dns_option(NMIP6Config *self, guint i) -{ - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - g_return_if_fail(i < priv->dns_options->len); - - g_ptr_array_remove_index(priv->dns_options, i); - _notify(self, PROP_DNS_OPTIONS); -} - -guint -nm_ip6_config_get_num_dns_options(const NMIP6Config *self) -{ - const NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - return priv->dns_options->len; -} - -const char * -nm_ip6_config_get_dns_option(const NMIP6Config *self, guint i) -{ - const NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - return g_ptr_array_index(priv->dns_options, i); -} - -/*****************************************************************************/ - -NMIPConfigFlags -nm_ip6_config_get_config_flags(const NMIP6Config *self) -{ - return NM_IP6_CONFIG_GET_PRIVATE(self)->config_flags; -} - -void -nm_ip6_config_set_config_flags(NMIP6Config *self, NMIPConfigFlags flags, NMIPConfigFlags mask) -{ - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - if (mask == 0) { - /* for convenience, accept 0 mask to set any flags. */ - mask = flags; - } - - nm_assert(!NM_FLAGS_ANY(flags, ~mask)); - priv->config_flags = (flags & mask) | (priv->config_flags & ~mask); -} - -/*****************************************************************************/ - -void -nm_ip6_config_set_dns_priority(NMIP6Config *self, int priority) -{ - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - if (priority != priv->dns_priority) { - priv->dns_priority = priority; - _notify(self, PROP_DNS_PRIORITY); - } -} - -int -nm_ip6_config_get_dns_priority(const NMIP6Config *self) -{ - const NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - return priv->dns_priority; -} - -/*****************************************************************************/ - -const NMPObject * -nm_ip6_config_nmpobj_lookup(const NMIP6Config *self, const NMPObject *needle) -{ - const NMIP6ConfigPrivate * priv; - const NMDedupMultiIdxType *idx_type; - - g_return_val_if_fail(NM_IS_IP6_CONFIG(self), NULL); - - priv = NM_IP6_CONFIG_GET_PRIVATE(self); - switch (NMP_OBJECT_GET_TYPE(needle)) { - case NMP_OBJECT_TYPE_IP6_ADDRESS: - idx_type = &priv->idx_ip6_addresses; - break; - case NMP_OBJECT_TYPE_IP6_ROUTE: - idx_type = &priv->idx_ip6_routes; - break; - default: - g_return_val_if_reached(NULL); - } - - return nm_dedup_multi_entry_get_obj( - nm_dedup_multi_index_lookup_obj(priv->multi_idx, idx_type, needle)); -} - -gboolean -nm_ip6_config_nmpobj_remove(NMIP6Config *self, const NMPObject *needle) -{ - NMIP6ConfigPrivate * priv; - NMDedupMultiIdxType *idx_type; - nm_auto_nmpobj const NMPObject *obj_old = NULL; - guint n; - - g_return_val_if_fail(NM_IS_IP6_CONFIG(self), FALSE); - - priv = NM_IP6_CONFIG_GET_PRIVATE(self); - switch (NMP_OBJECT_GET_TYPE(needle)) { - case NMP_OBJECT_TYPE_IP6_ADDRESS: - idx_type = &priv->idx_ip6_addresses; - break; - case NMP_OBJECT_TYPE_IP6_ROUTE: - idx_type = &priv->idx_ip6_routes; - break; - default: - g_return_val_if_reached(FALSE); - } - - n = nm_dedup_multi_index_remove_obj(priv->multi_idx, - idx_type, - needle, - (gconstpointer *) &obj_old); - if (n != 1) { - nm_assert(n == 0); - return FALSE; - } - - nm_assert(NMP_OBJECT_GET_TYPE(obj_old) == NMP_OBJECT_GET_TYPE(needle)); - - switch (NMP_OBJECT_GET_TYPE(obj_old)) { - case NMP_OBJECT_TYPE_IP6_ADDRESS: - _notify_addresses(self); - break; - case NMP_OBJECT_TYPE_IP6_ROUTE: - if (priv->best_default_route == obj_old) { - if (nmp_object_ref_set(&priv->best_default_route, - _nm_ip6_config_best_default_route_find(self))) - _notify(self, PROP_GATEWAY); - } - _notify_routes(self); - break; - default: - nm_assert_not_reached(); - } - return TRUE; -} - -/*****************************************************************************/ - -static void -hash_u32(GChecksum *sum, guint32 n) -{ - g_checksum_update(sum, (const guint8 *) &n, sizeof(n)); -} - -static void -hash_in6addr(GChecksum *sum, const struct in6_addr *a) -{ - if (a) - g_checksum_update(sum, (const guint8 *) a, sizeof(*a)); - else - g_checksum_update(sum, (const guint8 *) &in6addr_any, sizeof(in6addr_any)); -} - -void -nm_ip6_config_hash(const NMIP6Config *self, GChecksum *sum, gboolean dns_only) -{ - guint32 i; - const char * s; - NMDedupMultiIter ipconf_iter; - const NMPlatformIP6Address *address; - const NMPlatformIP6Route * route; - - g_return_if_fail(self); - g_return_if_fail(sum); - - if (dns_only == FALSE) { - nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, self, &address) { - hash_in6addr(sum, &address->address); - hash_u32(sum, address->plen); - } - - nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, self, &route) { - hash_in6addr(sum, &route->network); - hash_u32(sum, route->plen); - hash_in6addr(sum, &route->gateway); - hash_u32(sum, route->metric); - } - } - - for (i = 0; i < nm_ip6_config_get_num_nameservers(self); i++) - hash_in6addr(sum, nm_ip6_config_get_nameserver(self, i)); - - for (i = 0; i < nm_ip6_config_get_num_domains(self); i++) { - s = nm_ip6_config_get_domain(self, i); - g_checksum_update(sum, (const guint8 *) s, strlen(s)); - } - - for (i = 0; i < nm_ip6_config_get_num_searches(self); i++) { - s = nm_ip6_config_get_search(self, i); - g_checksum_update(sum, (const guint8 *) s, strlen(s)); - } - - for (i = 0; i < nm_ip6_config_get_num_dns_options(self); i++) { - s = nm_ip6_config_get_dns_option(self, i); - g_checksum_update(sum, (const guint8 *) s, strlen(s)); - } -} - -/** - * nm_ip6_config_equal: - * @a: first config to compare - * @b: second config to compare - * - * Compares two #NMIP6Configs for basic equality. This means that all - * attributes must exist in the same order in both configs (addresses, routes, - * domains, DNS servers, etc) but some attributes (address lifetimes, and address - * and route sources) are ignored. - * - * Returns: %TRUE if the configurations are basically equal to each other, - * %FALSE if not - */ -gboolean -nm_ip6_config_equal(const NMIP6Config *a, const NMIP6Config *b) -{ - nm_auto_free_checksum GChecksum *a_checksum = g_checksum_new(G_CHECKSUM_SHA1); - nm_auto_free_checksum GChecksum *b_checksum = g_checksum_new(G_CHECKSUM_SHA1); - guint8 a_data[NM_UTILS_CHECKSUM_LENGTH_SHA1]; - guint8 b_data[NM_UTILS_CHECKSUM_LENGTH_SHA1]; - - if (a) - nm_ip6_config_hash(a, a_checksum, FALSE); - if (b) - nm_ip6_config_hash(b, b_checksum, FALSE); - - nm_utils_checksum_get_digest(a_checksum, a_data); - nm_utils_checksum_get_digest(b_checksum, b_data); - return !memcmp(a_data, b_data, sizeof(a_data)); -} - -/*****************************************************************************/ - -static void -nameservers_to_gvalue(GArray *array, GValue *value) -{ - GVariantBuilder builder; - guint i = 0; - - g_variant_builder_init(&builder, G_VARIANT_TYPE("aay")); - - while (array && (i < array->len)) { - struct in6_addr *addr; - - addr = &g_array_index(array, struct in6_addr, i++); - g_variant_builder_add(&builder, "@ay", nm_g_variant_new_ay_in6addr(addr)); - } - - g_value_take_variant(value, g_variant_builder_end(&builder)); -} - -static void -get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - NMIP6Config * self = NM_IP6_CONFIG(object); - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - switch (prop_id) { - case PROP_IFINDEX: - g_value_set_int(value, priv->ifindex); - break; - case PROP_ADDRESS_DATA: - case PROP_ADDRESSES: - nm_assert(!!priv->address_data_variant == !!priv->addresses_variant); - - if (!priv->address_data_variant) { - nm_utils_ip_addresses_to_dbus(AF_INET6, - nm_ip6_config_lookup_addresses(self), - priv->best_default_route, - priv->privacy, - &priv->address_data_variant, - &priv->addresses_variant); - g_variant_ref_sink(priv->address_data_variant); - g_variant_ref_sink(priv->addresses_variant); - } - g_value_set_variant(value, - prop_id == PROP_ADDRESS_DATA ? priv->address_data_variant - : priv->addresses_variant); - break; - - case PROP_ROUTE_DATA: - case PROP_ROUTES: - nm_assert(!!priv->route_data_variant == !!priv->routes_variant); - - if (!priv->route_data_variant) { - nm_utils_ip_routes_to_dbus(AF_INET6, - nm_ip6_config_lookup_routes(self), - &priv->route_data_variant, - &priv->routes_variant); - g_variant_ref_sink(priv->route_data_variant); - g_variant_ref_sink(priv->routes_variant); - } - - g_value_set_variant(value, - prop_id == PROP_ROUTE_DATA ? priv->route_data_variant - : priv->routes_variant); - break; - case PROP_GATEWAY: - if (priv->best_default_route) { - g_value_take_string(value, - nm_utils_inet6_ntop_dup( - &NMP_OBJECT_CAST_IP6_ROUTE(priv->best_default_route)->gateway)); - } else - g_value_set_string(value, NULL); - break; - case PROP_NAMESERVERS: - nameservers_to_gvalue(priv->nameservers, value); - break; - case PROP_DOMAINS: - nm_utils_g_value_set_strv(value, priv->domains); - break; - case PROP_SEARCHES: - nm_utils_g_value_set_strv(value, priv->searches); - break; - case PROP_DNS_OPTIONS: - nm_utils_g_value_set_strv(value, priv->dns_options); - break; - case PROP_DNS_PRIORITY: - g_value_set_int(value, priv->dns_priority); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } -} - -static void -set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) -{ - NMIP6Config * self = NM_IP6_CONFIG(object); - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - switch (prop_id) { - case PROP_MULTI_IDX: - /* construct-only */ - priv->multi_idx = g_value_get_pointer(value); - if (!priv->multi_idx) - g_return_if_reached(); - nm_dedup_multi_index_ref(priv->multi_idx); - break; - case PROP_IFINDEX: - /* construct-only */ - priv->ifindex = g_value_get_int(value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } -} - -/*****************************************************************************/ - -static void -nm_ip6_config_init(NMIP6Config *self) -{ - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - nm_ip_config_dedup_multi_idx_type_init((NMIPConfigDedupMultiIdxType *) &priv->idx_ip6_addresses, - NMP_OBJECT_TYPE_IP6_ADDRESS); - nm_ip_config_dedup_multi_idx_type_init((NMIPConfigDedupMultiIdxType *) &priv->idx_ip6_routes, - NMP_OBJECT_TYPE_IP6_ROUTE); - - priv->nameservers = g_array_new(FALSE, TRUE, sizeof(struct in6_addr)); - priv->domains = g_ptr_array_new_with_free_func(g_free); - priv->searches = g_ptr_array_new_with_free_func(g_free); - priv->dns_options = g_ptr_array_new_with_free_func(g_free); -} - -NMIP6Config * -nm_ip6_config_new(NMDedupMultiIndex *multi_idx, int ifindex) -{ - g_return_val_if_fail(ifindex >= -1, NULL); - return g_object_new(NM_TYPE_IP6_CONFIG, - NM_IP6_CONFIG_MULTI_IDX, - multi_idx, - NM_IP6_CONFIG_IFINDEX, - ifindex, - NULL); -} - -NMIP6Config * -nm_ip6_config_new_cloned(const NMIP6Config *src) -{ - NMIP6Config *new; - - g_return_val_if_fail(NM_IS_IP6_CONFIG(src), NULL); - - new = nm_ip6_config_new(nm_ip6_config_get_multi_idx(src), nm_ip6_config_get_ifindex(src)); - nm_ip6_config_replace(new, src, NULL); - return new; -} - -static void -finalize(GObject *object) -{ - NMIP6Config * self = NM_IP6_CONFIG(object); - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE(self); - - nm_clear_nmp_object(&priv->best_default_route); - - nm_dedup_multi_index_remove_idx(priv->multi_idx, &priv->idx_ip6_addresses); - nm_dedup_multi_index_remove_idx(priv->multi_idx, &priv->idx_ip6_routes); - - nm_clear_g_variant(&priv->address_data_variant); - nm_clear_g_variant(&priv->addresses_variant); - nm_clear_g_variant(&priv->route_data_variant); - nm_clear_g_variant(&priv->routes_variant); - - g_array_unref(priv->nameservers); - g_ptr_array_unref(priv->domains); - g_ptr_array_unref(priv->searches); - g_ptr_array_unref(priv->dns_options); - - G_OBJECT_CLASS(nm_ip6_config_parent_class)->finalize(object); - - nm_dedup_multi_index_unref(priv->multi_idx); -} - -static const NMDBusInterfaceInfoExtended interface_info_ip6_config = { - .parent = NM_DEFINE_GDBUS_INTERFACE_INFO_INIT( - NM_DBUS_INTERFACE_IP6_CONFIG, - .properties = NM_DEFINE_GDBUS_PROPERTY_INFOS( - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Addresses", - "a(ayuay)", - NM_IP6_CONFIG_ADDRESSES), - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("AddressData", - "aa{sv}", - NM_IP6_CONFIG_ADDRESS_DATA), - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Gateway", "s", NM_IP6_CONFIG_GATEWAY), - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Routes", - "a(ayuayu)", - NM_IP6_CONFIG_ROUTES), - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("RouteData", - "aa{sv}", - NM_IP6_CONFIG_ROUTE_DATA), - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Nameservers", - "aay", - NM_IP6_CONFIG_NAMESERVERS), - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Domains", "as", NM_IP6_CONFIG_DOMAINS), - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Searches", - "as", - NM_IP6_CONFIG_SEARCHES), - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("DnsOptions", - "as", - NM_IP6_CONFIG_DNS_OPTIONS), - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("DnsPriority", - "i", - NM_IP6_CONFIG_DNS_PRIORITY), ), ), -}; - -static void -nm_ip6_config_class_init(NMIP6ConfigClass *klass) -{ - GObjectClass * object_class = G_OBJECT_CLASS(klass); - NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); - NMIPConfigClass * ip_config_class = NM_IP_CONFIG_CLASS(klass); - - ip_config_class->is_ipv4 = FALSE; - ip_config_class->addr_family = AF_INET6; - - dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_NUMBERED(NM_DBUS_PATH "/IP6Config"); - dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS(&interface_info_ip6_config); - - object_class->get_property = get_property; - object_class->set_property = set_property; - object_class->finalize = finalize; - - obj_properties[PROP_MULTI_IDX] = - g_param_spec_pointer(NM_IP6_CONFIG_MULTI_IDX, - "", - "", - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_IFINDEX] = - g_param_spec_int(NM_IP6_CONFIG_IFINDEX, - "", - "", - -1, - G_MAXINT, - -1, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_ADDRESS_DATA] = - g_param_spec_variant(NM_IP6_CONFIG_ADDRESS_DATA, - "", - "", - G_VARIANT_TYPE("aa{sv}"), - NULL, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_ADDRESSES] = - g_param_spec_variant(NM_IP6_CONFIG_ADDRESSES, - "", - "", - G_VARIANT_TYPE("a(ayuay)"), - NULL, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_ROUTE_DATA] = - g_param_spec_variant(NM_IP6_CONFIG_ROUTE_DATA, - "", - "", - G_VARIANT_TYPE("aa{sv}"), - NULL, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_ROUTES] = g_param_spec_variant(NM_IP6_CONFIG_ROUTES, - "", - "", - G_VARIANT_TYPE("a(ayuayu)"), - NULL, - 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_variant(NM_IP6_CONFIG_NAMESERVERS, - "", - "", - G_VARIANT_TYPE("aay"), - NULL, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_DOMAINS] = g_param_spec_boxed(NM_IP6_CONFIG_DOMAINS, - "", - "", - G_TYPE_STRV, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_SEARCHES] = g_param_spec_boxed(NM_IP6_CONFIG_SEARCHES, - "", - "", - G_TYPE_STRV, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_DNS_OPTIONS] = - g_param_spec_boxed(NM_IP6_CONFIG_DNS_OPTIONS, - "", - "", - G_TYPE_STRV, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_DNS_PRIORITY] = g_param_spec_int(NM_IP6_CONFIG_DNS_PRIORITY, - "", - "", - G_MININT32, - G_MAXINT32, - 0, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); -} diff --git a/src/core/nm-ip6-config.h b/src/core/nm-ip6-config.h deleted file mode 100644 index a54040fc..00000000 --- a/src/core/nm-ip6-config.h +++ /dev/null @@ -1,205 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2008 - 2013 Red Hat, Inc. - */ - -#ifndef __NETWORKMANAGER_IP6_CONFIG_H__ -#define __NETWORKMANAGER_IP6_CONFIG_H__ - -#include - -#include "nm-setting-ip6-config.h" - -#include "libnm-glib-aux/nm-dedup-multi.h" -#include "libnm-platform/nmp-object.h" -#include "nm-ip-config.h" - -/*****************************************************************************/ - -void nm_ip_config_iter_ip6_address_init(NMDedupMultiIter *iter, const NMIP6Config *self); -void nm_ip_config_iter_ip6_route_init(NMDedupMultiIter *iter, const NMIP6Config *self); - -#define nm_ip_config_iter_ip6_address_for_each(iter, self, address) \ - for (nm_ip_config_iter_ip6_address_init((iter), (self)); \ - nm_platform_dedup_multi_iter_next_ip6_address((iter), (address));) - -#define nm_ip_config_iter_ip6_route_for_each(iter, self, route) \ - for (nm_ip_config_iter_ip6_route_init((iter), (self)); \ - nm_platform_dedup_multi_iter_next_ip6_route((iter), (route));) - -/*****************************************************************************/ - -#define NM_TYPE_IP6_CONFIG (nm_ip6_config_get_type()) -#define NM_IP6_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_IP6_CONFIG, NMIP6Config)) -#define NM_IP6_CONFIG_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), NM_TYPE_IP6_CONFIG, NMIP6ConfigClass)) -#define NM_IS_IP6_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NM_TYPE_IP6_CONFIG)) -#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)) - -typedef struct _NMIP6ConfigClass NMIP6ConfigClass; - -/* internal */ -#define NM_IP6_CONFIG_MULTI_IDX "multi-idx" -#define NM_IP6_CONFIG_IFINDEX "ifindex" - -/* public */ -#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_NAMESERVERS "nameservers" -#define NM_IP6_CONFIG_DOMAINS "domains" -#define NM_IP6_CONFIG_SEARCHES "searches" -#define NM_IP6_CONFIG_DNS_OPTIONS "dns-options" -#define NM_IP6_CONFIG_DNS_PRIORITY "dns-priority" - -/* deprecated */ -#define NM_IP6_CONFIG_ADDRESSES "addresses" -#define NM_IP6_CONFIG_ROUTES "routes" - -GType nm_ip6_config_get_type(void); - -NMIP6Config *nm_ip6_config_new(struct _NMDedupMultiIndex *multi_idx, int ifindex); -NMIP6Config *nm_ip6_config_new_cloned(const NMIP6Config *src); - -NMIP6Config *nm_ip6_config_clone(const NMIP6Config *self); -int nm_ip6_config_get_ifindex(const NMIP6Config *self); - -struct _NMDedupMultiIndex *nm_ip6_config_get_multi_idx(const NMIP6Config *self); - -NMIP6Config *nm_ip6_config_capture(struct _NMDedupMultiIndex *multi_idx, - NMPlatform * platform, - int ifindex, - NMSettingIP6ConfigPrivacy use_temporary); - -void nm_ip6_config_add_dependent_routes(NMIP6Config *self, - guint32 route_table, - guint32 route_metric, - gboolean is_vrf); - -gboolean nm_ip6_config_commit(const NMIP6Config * self, - NMPlatform * platform, - NMIPRouteTableSyncMode route_table_sync, - GPtrArray ** out_temporary_not_available); -void nm_ip6_config_merge_setting(NMIP6Config * self, - NMSettingIPConfig *setting, - guint32 route_table, - guint32 route_metric); -NMSetting *nm_ip6_config_create_setting(const NMIP6Config *self, gboolean maybe_ipv6_disabled); - -void nm_ip6_config_merge(NMIP6Config * dst, - const NMIP6Config * src, - NMIPConfigMergeFlags merge_flags, - guint32 default_route_metric_penalty); -void nm_ip6_config_subtract(NMIP6Config * dst, - const NMIP6Config *src, - guint32 default_route_metric_penalty); -void nm_ip6_config_intersect(NMIP6Config * dst, - const NMIP6Config *src, - gboolean intersect_addresses, - gboolean intersect_routes, - guint32 default_route_metric_penalty); -NMIP6Config *nm_ip6_config_intersect_alloc(const NMIP6Config *a, - const NMIP6Config *b, - gboolean intersect_addresses, - gboolean intersect_routes, - guint32 default_route_metric_penalty); -gboolean -nm_ip6_config_replace(NMIP6Config *dst, const NMIP6Config *src, gboolean *relevant_changes); - -const NMPObject *nm_ip6_config_best_default_route_get(const NMIP6Config *self); -const NMPObject *_nm_ip6_config_best_default_route_find(const NMIP6Config *self); - -enum _NMIPConfigFlags; - -void nm_ip6_config_set_config_flags(NMIP6Config * self, - enum _NMIPConfigFlags flags, - enum _NMIPConfigFlags mask); -enum _NMIPConfigFlags nm_ip6_config_get_config_flags(const NMIP6Config *self); - -const NMDedupMultiHeadEntry *nm_ip6_config_lookup_addresses(const NMIP6Config *self); -void nm_ip6_config_reset_addresses(NMIP6Config *self); -void nm_ip6_config_add_address(NMIP6Config *self, const NMPlatformIP6Address *address); -void _nmtst_ip6_config_del_address(NMIP6Config *self, guint i); -guint nm_ip6_config_get_num_addresses(const NMIP6Config *self); -const NMPlatformIP6Address *nm_ip6_config_get_first_address(const NMIP6Config *self); -const NMPlatformIP6Address *_nmtst_ip6_config_get_address(const NMIP6Config *self, guint i); -gboolean nm_ip6_config_address_exists(const NMIP6Config *self, const NMPlatformIP6Address *address); -const NMPlatformIP6Address *nm_ip6_config_lookup_address(const NMIP6Config * self, - const struct in6_addr *addr); -gboolean _nmtst_ip6_config_addresses_sort(NMIP6Config *self); -gboolean nm_ip6_config_has_any_dad_pending(const NMIP6Config *self, const NMIP6Config *candidates); - -const NMDedupMultiHeadEntry *nm_ip6_config_lookup_routes(const NMIP6Config *self); -void nm_ip6_config_reset_routes(NMIP6Config *self); -void nm_ip6_config_add_route(NMIP6Config * self, - const NMPlatformIP6Route *route, - const NMPObject ** out_obj_new); -void _nmtst_ip6_config_del_route(NMIP6Config *self, guint i); -guint nm_ip6_config_get_num_routes(const NMIP6Config *self); -const NMPlatformIP6Route * _nmtst_ip6_config_get_route(const NMIP6Config *self, guint i); - -const NMPlatformIP6Route * nm_ip6_config_get_direct_route_for_host(const NMIP6Config * self, - const struct in6_addr *host, - guint32 route_table); -const NMPlatformIP6Address *nm_ip6_config_get_subnet_for_host(const NMIP6Config * self, - const struct in6_addr *host); - -void nm_ip6_config_reset_nameservers(NMIP6Config *self); -void nm_ip6_config_add_nameserver(NMIP6Config *self, const struct in6_addr *nameserver); -void nm_ip6_config_del_nameserver(NMIP6Config *self, guint i); -guint nm_ip6_config_get_num_nameservers(const NMIP6Config *self); -const struct in6_addr *nm_ip6_config_get_nameserver(const NMIP6Config *self, guint i); - -void nm_ip6_config_reset_domains(NMIP6Config *self); -void nm_ip6_config_add_domain(NMIP6Config *self, const char *domain); -void nm_ip6_config_del_domain(NMIP6Config *self, guint i); -guint nm_ip6_config_get_num_domains(const NMIP6Config *self); -const char *nm_ip6_config_get_domain(const NMIP6Config *self, guint i); - -void nm_ip6_config_reset_searches(NMIP6Config *self); -void nm_ip6_config_add_search(NMIP6Config *self, const char *search); -void nm_ip6_config_del_search(NMIP6Config *self, guint i); -guint nm_ip6_config_get_num_searches(const NMIP6Config *self); -const char *nm_ip6_config_get_search(const NMIP6Config *self, guint i); - -void nm_ip6_config_reset_dns_options(NMIP6Config *self); -void nm_ip6_config_add_dns_option(NMIP6Config *self, const char *option); -void nm_ip6_config_del_dns_option(NMIP6Config *self, guint i); -guint nm_ip6_config_get_num_dns_options(const NMIP6Config *self); -const char *nm_ip6_config_get_dns_option(const NMIP6Config *self, guint i); - -void nm_ip6_config_set_dns_priority(NMIP6Config *self, int priority); -int nm_ip6_config_get_dns_priority(const NMIP6Config *self); - -void nm_ip6_config_set_never_default(NMIP6Config *self, gboolean never_default); -gboolean nm_ip6_config_get_never_default(const NMIP6Config *self); - -const NMPObject *nm_ip6_config_nmpobj_lookup(const NMIP6Config *self, const NMPObject *needle); -gboolean nm_ip6_config_nmpobj_remove(NMIP6Config *self, const NMPObject *needle); - -void nm_ip6_config_hash(const NMIP6Config *self, GChecksum *sum, gboolean dns_only); -gboolean nm_ip6_config_equal(const NMIP6Config *a, const NMIP6Config *b); - -void nm_ip6_config_set_privacy(NMIP6Config *self, NMSettingIP6ConfigPrivacy privacy); - -struct _NMNDiscAddress; -void nm_ip6_config_reset_addresses_ndisc(NMIP6Config * self, - const struct _NMNDiscAddress *addresses, - guint addresses_n, - guint8 plen, - guint32 ifa_flags); -struct _NMNDiscRoute; -struct _NMNDiscGateway; -void nm_ip6_config_reset_routes_ndisc(NMIP6Config * self, - const struct _NMNDiscGateway *gateways, - guint gateways_n, - const struct _NMNDiscRoute * routes, - guint routes_n, - guint32 route_table, - guint32 route_metric); - -void nm_ip6_config_update_routes_metric(NMIP6Config *self, gint64 metric); - -#endif /* __NETWORKMANAGER_IP6_CONFIG_H__ */ diff --git a/src/core/nm-keep-alive.c b/src/core/nm-keep-alive.c index 6275544c..e147163c 100644 --- a/src/core/nm-keep-alive.c +++ b/src/core/nm-keep-alive.c @@ -18,8 +18,8 @@ typedef struct { GObject *owner; NMSettingsConnection *connection; - GDBusConnection * dbus_connection; - char * dbus_client; + GDBusConnection *dbus_connection; + char *dbus_client; GCancellable *dbus_client_confirm_cancellable; guint subscription_id; @@ -150,11 +150,11 @@ connection_flags_changed(NMSettingsConnection *connection, NMKeepAlive *self) } static void -_set_settings_connection_watch_visible(NMKeepAlive * self, +_set_settings_connection_watch_visible(NMKeepAlive *self, NMSettingsConnection *connection, gboolean emit_signal) { - NMKeepAlivePrivate *priv = NM_KEEP_ALIVE_GET_PRIVATE(self); + NMKeepAlivePrivate *priv = NM_KEEP_ALIVE_GET_PRIVATE(self); gs_unref_object NMSettingsConnection *old_connection = NULL; if (priv->connection == connection) @@ -183,7 +183,7 @@ _set_settings_connection_watch_visible(NMKeepAlive * self, } void -nm_keep_alive_set_settings_connection_watch_visible(NMKeepAlive * self, +nm_keep_alive_set_settings_connection_watch_visible(NMKeepAlive *self, NMSettingsConnection *connection) { _set_settings_connection_watch_visible(self, connection, TRUE); @@ -194,7 +194,7 @@ nm_keep_alive_set_settings_connection_watch_visible(NMKeepAlive * self, static void get_name_owner_cb(const char *name_owner, GError *error, gpointer user_data) { - NMKeepAlive * self; + NMKeepAlive *self; NMKeepAlivePrivate *priv; if (!name_owner && g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) @@ -259,16 +259,16 @@ cleanup_dbus_watch(NMKeepAlive *self) static void name_owner_changed_cb(GDBusConnection *connection, - const char * sender_name, - const char * object_path, - const char * interface_name, - const char * signal_name, - GVariant * parameters, + const char *sender_name, + const char *object_path, + const char *interface_name, + const char *signal_name, + GVariant *parameters, gpointer user_data) { NMKeepAlive *self = NM_KEEP_ALIVE(user_data); - const char * old_owner; - const char * new_owner; + const char *old_owner; + const char *new_owner; g_variant_get(parameters, "(&s&s&s)", NULL, &old_owner, &new_owner); @@ -281,9 +281,9 @@ name_owner_changed_cb(GDBusConnection *connection, } void -nm_keep_alive_set_dbus_client_watch(NMKeepAlive * self, +nm_keep_alive_set_dbus_client_watch(NMKeepAlive *self, GDBusConnection *connection, - const char * client_address) + const char *client_address) { NMKeepAlivePrivate *priv = NM_KEEP_ALIVE_GET_PRIVATE(self); diff --git a/src/core/nm-keep-alive.h b/src/core/nm-keep-alive.h index 2c2b4faa..7737c17a 100644 --- a/src/core/nm-keep-alive.h +++ b/src/core/nm-keep-alive.h @@ -29,12 +29,12 @@ void nm_keep_alive_disarm(NMKeepAlive *self); void nm_keep_alive_destroy(NMKeepAlive *self); -void nm_keep_alive_set_settings_connection_watch_visible(NMKeepAlive * self, +void nm_keep_alive_set_settings_connection_watch_visible(NMKeepAlive *self, NMSettingsConnection *connection); -void nm_keep_alive_set_dbus_client_watch(NMKeepAlive * self, +void nm_keep_alive_set_dbus_client_watch(NMKeepAlive *self, GDBusConnection *connection, - const char * client_address); + const char *client_address); gpointer /* GObject * */ nm_keep_alive_get_owner(NMKeepAlive *self); diff --git a/src/core/nm-l3-config-data.c b/src/core/nm-l3-config-data.c index 033c8942..03593ea2 100644 --- a/src/core/nm-l3-config-data.c +++ b/src/core/nm-l3-config-data.c @@ -117,8 +117,10 @@ struct _NML3ConfigData { NMIPRouteTableSyncMode route_table_sync_x[2]; }; - NMSettingConnectionMdns mdns; - NMSettingConnectionLlmnr llmnr; + NMSettingConnectionMdns mdns; + NMSettingConnectionLlmnr llmnr; + NMSettingConnectionDnsOverTls dns_over_tls; + NMUtilsIPv6IfaceId ip6_token; NML3ConfigDatFlags flags; @@ -177,7 +179,7 @@ static GArray * _garray_inaddr_clone(const GArray *src, int addr_family) { const gsize elt_size = nm_utils_addr_family_to_size(addr_family); - GArray * dst; + GArray *dst; nm_assert_addr_family(addr_family); @@ -226,7 +228,7 @@ next:; } static gssize -_garray_inaddr_find(GArray * arr, +_garray_inaddr_find(GArray *arr, int addr_family, gconstpointer needle, /* (const NMIPAddr **) */ gpointer out_addr) @@ -342,8 +344,8 @@ _strv_ptrarray_merge(GPtrArray **p_dst, const GPtrArray *src) void nm_l3_config_data_log(const NML3ConfigData *self, - const char * title, - const char * prefix, + const char *title, + const char *prefix, NMLogLevel log_level, NMLogDomain log_domain) { @@ -443,7 +445,7 @@ nm_l3_config_data_log(const NML3ConfigData *self, if (self->ndisc_hop_limit_set || self->ndisc_reachable_time_msec_set || self->ndisc_retrans_timer_msec_set) { gsize l = sizeof(sbuf); - char * p = sbuf; + char *p = sbuf; const char *s_prefix = "ndisc: "; if (self->ndisc_hop_limit_set) { @@ -524,7 +526,7 @@ nm_l3_config_data_log(const NML3ConfigData *self, if (self->dhcp_lease_x[IS_IPv4]) { gs_free NMUtilsNamedValue *options_free = NULL; NMUtilsNamedValue options_buffer[30]; - NMUtilsNamedValue * options; + NMUtilsNamedValue *options; guint options_len; options = nm_utils_named_values_from_strdict( @@ -570,6 +572,21 @@ nm_l3_config_data_log(const NML3ConfigData *self, NULL))); } + if (self->dns_over_tls != NM_SETTING_CONNECTION_DNS_OVER_TLS_DEFAULT) { + gs_free char *s = NULL; + + _L("dns-over-tls: %s", + (s = _nm_utils_enum_to_str_full(nm_setting_connection_dns_over_tls_get_type(), + self->dns_over_tls, + " ", + NULL))); + } + + if (self->ip6_token.id != 0) { + _L("ipv6-token: %s", + nm_utils_inet6_interface_identifier_to_token(&self->ip6_token, sbuf_addr)); + } + if (self->metered != NM_TERNARY_DEFAULT) _L("metered: %s", self->metered ? "yes" : "no"); @@ -617,22 +634,22 @@ _route_valid(int addr_family, gconstpointer r) static gboolean _NM_IS_L3_CONFIG_DATA(const NML3ConfigData *self, gboolean allow_sealed) { - nm_assert(!self || (self->ifindex > 0 && self->multi_idx && self->ref_count > 0)); + nm_assert(!self || (self->ifindex >= 0 && self->multi_idx && self->ref_count > 0)); return self && self->ref_count > 0 && (allow_sealed || !self->is_sealed); } static void _idx_obj_id_hash_update(const NMDedupMultiIdxType *idx_type, - const NMDedupMultiObj * obj, - NMHashState * h) + const NMDedupMultiObj *obj, + NMHashState *h) { nmp_object_id_hash_update((NMPObject *) obj, h); } static gboolean _idx_obj_id_equal(const NMDedupMultiIdxType *idx_type, - const NMDedupMultiObj * obj_a, - const NMDedupMultiObj * obj_b) + const NMDedupMultiObj *obj_a, + const NMDedupMultiObj *obj_b) { return nmp_object_id_equal((NMPObject *) obj_a, (NMPObject *) obj_b); } @@ -666,6 +683,7 @@ nm_l3_config_data_new(NMDedupMultiIndex *multi_idx, int ifindex, NMIPConfigSourc .multi_idx = nm_dedup_multi_index_ref(multi_idx), .mdns = NM_SETTING_CONNECTION_MDNS_DEFAULT, .llmnr = NM_SETTING_CONNECTION_LLMNR_DEFAULT, + .dns_over_tls = NM_SETTING_CONNECTION_DNS_OVER_TLS_DEFAULT, .flags = NM_L3_CONFIG_DAT_FLAGS_NONE, .metered = NM_TERNARY_DEFAULT, .proxy_browser_only = NM_TERNARY_DEFAULT, @@ -788,7 +806,7 @@ nm_l3_config_data_unref(const NML3ConfigData *self) static const NMDedupMultiEntry * _lookup_route(const NMDedupMultiIndex *multi_idx, const DedupMultiIdxType *idx_type, - const NMPObject * needle) + const NMPObject *needle) { const NMDedupMultiEntry *entry; @@ -828,7 +846,7 @@ nm_l3_config_data_lookup_route_obj(const NML3ConfigData *self, const NMPObject * } const NMDedupMultiEntry * -nm_l3_config_data_lookup_route(const NML3ConfigData * self, +nm_l3_config_data_lookup_route(const NML3ConfigData *self, int addr_family, const NMPlatformIPRoute *needle) { @@ -952,7 +970,7 @@ gboolean nm_l3_config_data_has_routes_with_type_local(const NML3ConfigData *self, int addr_family) { const int IS_IPv4 = NM_IS_IPv4(addr_family); - NML3ConfigData * self_mutable; + NML3ConfigData *self_mutable; NMDedupMultiIter iter; const NMPObject *obj; gboolean val; @@ -1020,7 +1038,7 @@ nm_l3_config_data_get_flags(const NML3ConfigData *self) } void -nm_l3_config_data_set_flags_full(NML3ConfigData * self, +nm_l3_config_data_set_flags_full(NML3ConfigData *self, NML3ConfigDatFlags flags, NML3ConfigDatFlags mask) { @@ -1053,14 +1071,14 @@ nm_l3_config_data_get_first_obj(const NML3ConfigData *self, /*****************************************************************************/ static gboolean -_l3_config_data_add_obj(NMDedupMultiIndex * multi_idx, - DedupMultiIdxType * idx_type, +_l3_config_data_add_obj(NMDedupMultiIndex *multi_idx, + DedupMultiIdxType *idx_type, int ifindex, - const NMPObject * obj_new, + const NMPObject *obj_new, const NMPlatformObject *pl_new, NML3ConfigAddFlags add_flags, - const NMPObject ** out_obj_old /* returns a reference! */, - const NMPObject ** out_obj_new /* does not return a reference */) + const NMPObject **out_obj_old /* returns a reference! */, + const NMPObject **out_obj_new /* does not return a reference */) { NMPObject obj_new_stackinit; const NMDedupMultiEntry *entry_old; @@ -1076,8 +1094,22 @@ _l3_config_data_add_obj(NMDedupMultiIndex * multi_idx, NMP_OBJECT_TYPE_IP4_ROUTE, NMP_OBJECT_TYPE_IP6_ADDRESS, NMP_OBJECT_TYPE_IP6_ROUTE)); + nm_assert((!!obj_new) != (!!pl_new)); + + if (NM_IN_SET(idx_type->obj_type, NMP_OBJECT_TYPE_IP4_ROUTE, NMP_OBJECT_TYPE_IP6_ROUTE)) { + const NMPlatformIPRoute *r; + + r = obj_new ? NMP_OBJECT_CAST_IP_ROUTE(obj_new) : (NMPlatformIPRoute *) pl_new; + + if (nm_platform_route_type_is_nodev(nm_platform_route_type_uncoerce(r->type_coerced))) { + /* such routes don't have a device/next-hop. We track them without ifindex. */ + ifindex = 0; + } + } + /* we go through extra lengths to accept a full obj_new object. That one, - * can be reused by increasing the ref-count. */ + * can be reused by increasing the ref-count. We thus accept any ifindex, and + * set it here. */ if (!obj_new) { nm_assert(pl_new); obj_new = nmp_object_stackinit(&obj_new_stackinit, idx_type->obj_type, pl_new); @@ -1258,12 +1290,12 @@ _l3_config_best_default_route_find_better(const NMPObject *obj_cur, const NMPObj } gboolean -nm_l3_config_data_add_address_full(NML3ConfigData * self, +nm_l3_config_data_add_address_full(NML3ConfigData *self, int addr_family, - const NMPObject * obj_new, + const NMPObject *obj_new, const NMPlatformIPAddress *pl_new, NML3ConfigAddFlags add_flags, - const NMPObject ** out_obj_new) + const NMPObject **out_obj_new) { const NMPObject *new; gboolean changed; @@ -1287,24 +1319,24 @@ nm_l3_config_data_add_address_full(NML3ConfigData * self, static gboolean _l3_config_best_default_route_merge(const NMPObject **best_default_route, - const NMPObject * new_candidate) + const NMPObject *new_candidate) { new_candidate = _l3_config_best_default_route_find_better(*best_default_route, new_candidate); return nmp_object_ref_set(best_default_route, new_candidate); } gboolean -nm_l3_config_data_add_route_full(NML3ConfigData * self, +nm_l3_config_data_add_route_full(NML3ConfigData *self, int addr_family, - const NMPObject * obj_new, + const NMPObject *obj_new, const NMPlatformIPRoute *pl_new, NML3ConfigAddFlags add_flags, - const NMPObject ** out_obj_new, - gboolean * out_changed_best_default_route) + const NMPObject **out_obj_new, + gboolean *out_changed_best_default_route) { - const int IS_IPv4 = NM_IS_IPv4(addr_family); + const int IS_IPv4 = NM_IS_IPv4(addr_family); nm_auto_nmpobj const NMPObject *obj_old = NULL; - const NMPObject * obj_new_2; + const NMPObject *obj_new_2; gboolean changed = FALSE; gboolean changed_best_default_route = FALSE; @@ -1407,7 +1439,7 @@ nm_l3_config_data_get_nameservers(const NML3ConfigData *self, int addr_family, g } gboolean -nm_l3_config_data_add_nameserver(NML3ConfigData * self, +nm_l3_config_data_add_nameserver(NML3ConfigData *self, int addr_family, gconstpointer /* (const NMIPAddr *) */ nameserver) { @@ -1679,6 +1711,26 @@ nm_l3_config_data_set_llmnr(NML3ConfigData *self, NMSettingConnectionLlmnr llmnr return TRUE; } +NMSettingConnectionDnsOverTls +nm_l3_config_data_get_dns_over_tls(const NML3ConfigData *self) +{ + nm_assert(_NM_IS_L3_CONFIG_DATA(self, TRUE)); + + return self->dns_over_tls; +} + +gboolean +nm_l3_config_data_set_dns_over_tls(NML3ConfigData *self, NMSettingConnectionDnsOverTls dns_over_tls) +{ + nm_assert(_NM_IS_L3_CONFIG_DATA(self, FALSE)); + + if (self->dns_over_tls == dns_over_tls) + return FALSE; + + self->dns_over_tls = dns_over_tls; + return TRUE; +} + NMIPRouteTableSyncMode nm_l3_config_data_get_route_table_sync(const NML3ConfigData *self, int addr_family) { @@ -1689,7 +1741,7 @@ nm_l3_config_data_get_route_table_sync(const NML3ConfigData *self, int addr_fami } gboolean -nm_l3_config_data_set_route_table_sync(NML3ConfigData * self, +nm_l3_config_data_set_route_table_sync(NML3ConfigData *self, int addr_family, NMIPRouteTableSyncMode route_table_sync) { @@ -1817,6 +1869,26 @@ nm_l3_config_data_set_ip6_privacy(NML3ConfigData *self, NMSettingIP6ConfigPrivac return TRUE; } +NMUtilsIPv6IfaceId +nm_l3_config_data_get_ip6_token(const NML3ConfigData *self) +{ + nm_assert(_NM_IS_L3_CONFIG_DATA(self, TRUE)); + + return self->ip6_token; +} + +gboolean +nm_l3_config_data_set_ip6_token(NML3ConfigData *self, NMUtilsIPv6IfaceId ipv6_token) +{ + nm_assert(_NM_IS_L3_CONFIG_DATA(self, FALSE)); + + if (self->ip6_token.id == ipv6_token.id) + return FALSE; + + self->ip6_token.id = ipv6_token.id; + return TRUE; +} + NMProxyConfigMethod nm_l3_config_data_get_proxy_method(const NML3ConfigData *self) { @@ -1977,7 +2049,7 @@ gboolean nm_l3_config_data_set_dhcp_lease(NML3ConfigData *self, int addr_family, NMDhcpLease *lease) { nm_auto_unref_dhcplease NMDhcpLease *lease_old = NULL; - NMDhcpLease ** p_lease; + NMDhcpLease **p_lease; nm_assert(_NM_IS_L3_CONFIG_DATA(self, FALSE)); @@ -1996,11 +2068,11 @@ nm_l3_config_data_set_dhcp_lease(NML3ConfigData *self, int addr_family, NMDhcpLe gboolean nm_l3_config_data_set_dhcp_lease_from_options(NML3ConfigData *self, int addr_family, - GHashTable * options_take) + GHashTable *options_take) { nm_auto_unref_dhcplease NMDhcpLease *lease = NULL; nm_auto_unref_dhcplease NMDhcpLease *lease_old = NULL; - NMDhcpLease ** p_lease; + NMDhcpLease **p_lease; nm_assert(_NM_IS_L3_CONFIG_DATA(self, FALSE)); @@ -2023,7 +2095,8 @@ static int _dedup_multi_index_cmp(const NML3ConfigData *a, const NML3ConfigData *b, NMPObjectType obj_type, - gboolean ignore_ifindex) + gboolean cmp_ifindex, + gboolean cmp_full) { const NMDedupMultiHeadEntry *h_a = nm_l3_config_data_lookup_objs(a, obj_type); const NMDedupMultiHeadEntry *h_b = nm_l3_config_data_lookup_objs(b, obj_type); @@ -2062,91 +2135,221 @@ _dedup_multi_index_cmp(const NML3ConfigData *a, have_b = nm_platform_dedup_multi_iter_next_obj(&iter_b, &obj_b, obj_type); nm_assert(have_b); - NM_CMP_RETURN(nmp_object_cmp_full(obj_a, - obj_b, - ignore_ifindex ? NMP_OBJECT_CMP_FLAGS_IGNORE_IFINDEX - : NMP_OBJECT_CMP_FLAGS_NONE)); + if (cmp_full) { + NM_CMP_RETURN(nmp_object_cmp_full(obj_a, + obj_b, + cmp_ifindex ? NMP_OBJECT_CMP_FLAGS_NONE + : NMP_OBJECT_CMP_FLAGS_IGNORE_IFINDEX)); + } else { + if (cmp_ifindex) { + NM_CMP_DIRECT(obj_a->obj_with_ifindex.ifindex, obj_b->obj_with_ifindex.ifindex); + } + + switch (obj_type) { + case NMP_OBJECT_TYPE_IP4_ADDRESS: + NM_CMP_DIRECT(obj_a->ip4_address.plen, obj_b->ip4_address.plen); + NM_CMP_DIRECT(obj_b->ip4_address.address, obj_b->ip4_address.address); + NM_CMP_DIRECT(obj_b->ip4_address.peer_address, obj_b->ip4_address.peer_address); + break; + case NMP_OBJECT_TYPE_IP6_ADDRESS: + NM_CMP_DIRECT(obj_a->ip6_address.plen, obj_b->ip6_address.plen); + NM_CMP_DIRECT_IN6ADDR(&obj_a->ip6_address.address, &obj_b->ip6_address.address); + break; + case NMP_OBJECT_TYPE_IP4_ROUTE: + { + NMPlatformIP4Route ra = obj_a->ip4_route; + NMPlatformIP4Route rb = obj_b->ip4_route; + + NM_CMP_DIRECT(ra.metric, rb.metric); + NM_CMP_DIRECT(ra.plen, rb.plen); + NM_CMP_RETURN_DIRECT( + nm_utils_ip4_address_same_prefix_cmp(ra.network, rb.network, ra.plen)); + break; + } + case NMP_OBJECT_TYPE_IP6_ROUTE: + { + NMPlatformIP6Route ra = obj_a->ip6_route; + NMPlatformIP6Route rb = obj_b->ip6_route; + + NM_CMP_DIRECT(ra.metric, rb.metric); + NM_CMP_DIRECT(ra.plen, rb.plen); + NM_CMP_RETURN_DIRECT( + nm_utils_ip6_address_same_prefix_cmp(&ra.network, &rb.network, ra.plen)); + break; + } + default: + nm_assert_not_reached(); + } + } + } +} + +static const NML3ConfigData * +get_empty_l3cd(void) +{ + static NML3ConfigData *empty_l3cd; + + if (!empty_l3cd) { + empty_l3cd = + nm_l3_config_data_new(nm_dedup_multi_index_new(), 1, NM_IP_CONFIG_SOURCE_UNKNOWN); + empty_l3cd->ifindex = 0; } + + return empty_l3cd; } int nm_l3_config_data_cmp_full(const NML3ConfigData *a, const NML3ConfigData *b, - NML3ConfigCmpFlags cmp_flags) + NML3ConfigCmpFlags flags) { - int IS_IPv4; - gboolean ignore_ifindex; + int IS_IPv4; + + if (a == b) + return 0; - NM_CMP_SELF(a, b); + if (NM_FLAGS_HAS(flags, NM_L3_CONFIG_CMP_FLAGS_ADDRESSES)) + flags |= NM_L3_CONFIG_CMP_FLAGS_ADDRESSES_ID; + if (NM_FLAGS_HAS(flags, NM_L3_CONFIG_CMP_FLAGS_ROUTES)) + flags |= NM_L3_CONFIG_CMP_FLAGS_ROUTES_ID; - ignore_ifindex = NM_FLAGS_HAS(cmp_flags, NM_L3_CONFIG_CMP_FLAGS_IGNORE_IFINDEX); + if (!a) + a = get_empty_l3cd(); + if (!b) + b = get_empty_l3cd(); - if (!ignore_ifindex) + if (NM_FLAGS_HAS(flags, NM_L3_CONFIG_CMP_FLAGS_IFINDEX)) NM_CMP_DIRECT(a->ifindex, b->ifindex); - NM_CMP_DIRECT(a->flags, b->flags); + if (NM_FLAGS_ANY(flags, + NM_L3_CONFIG_CMP_FLAGS_ADDRESSES | NM_L3_CONFIG_CMP_FLAGS_ADDRESSES_ID)) { + NM_CMP_RETURN( + _dedup_multi_index_cmp(a, + b, + NMP_OBJECT_TYPE_IP4_ADDRESS, + NM_FLAGS_HAS(flags, NM_L3_CONFIG_CMP_FLAGS_IFINDEX), + NM_FLAGS_HAS(flags, NM_L3_CONFIG_CMP_FLAGS_ADDRESSES))); + NM_CMP_RETURN( + _dedup_multi_index_cmp(a, + b, + NMP_OBJECT_TYPE_IP6_ADDRESS, + NM_FLAGS_HAS(flags, NM_L3_CONFIG_CMP_FLAGS_IFINDEX), + NM_FLAGS_HAS(flags, NM_L3_CONFIG_CMP_FLAGS_ADDRESSES))); + } - NM_CMP_RETURN(_dedup_multi_index_cmp(a, b, NMP_OBJECT_TYPE_IP4_ADDRESS, ignore_ifindex)); - NM_CMP_RETURN(_dedup_multi_index_cmp(a, b, NMP_OBJECT_TYPE_IP6_ADDRESS, ignore_ifindex)); - NM_CMP_RETURN(_dedup_multi_index_cmp(a, b, NMP_OBJECT_TYPE_IP4_ROUTE, ignore_ifindex)); - NM_CMP_RETURN(_dedup_multi_index_cmp(a, b, NMP_OBJECT_TYPE_IP6_ROUTE, ignore_ifindex)); + if (NM_FLAGS_ANY(flags, NM_L3_CONFIG_CMP_FLAGS_ROUTES | NM_L3_CONFIG_CMP_FLAGS_ROUTES_ID)) { + NM_CMP_RETURN(_dedup_multi_index_cmp(a, + b, + NMP_OBJECT_TYPE_IP4_ROUTE, + NM_FLAGS_HAS(flags, NM_L3_CONFIG_CMP_FLAGS_IFINDEX), + NM_FLAGS_HAS(flags, NM_L3_CONFIG_CMP_FLAGS_ROUTES))); + NM_CMP_RETURN(_dedup_multi_index_cmp(a, + b, + NMP_OBJECT_TYPE_IP6_ROUTE, + NM_FLAGS_HAS(flags, NM_L3_CONFIG_CMP_FLAGS_IFINDEX), + NM_FLAGS_HAS(flags, NM_L3_CONFIG_CMP_FLAGS_ROUTES))); + } for (IS_IPv4 = 1; IS_IPv4 >= 0; IS_IPv4--) { - const int addr_family = IS_IPv4 ? AF_INET : AF_INET6; + const int addr_family = IS_IPv4 ? AF_INET : AF_INET6; + const NMPObject *def_route_a = a->best_default_route_x[IS_IPv4]; + const NMPObject *def_route_b = b->best_default_route_x[IS_IPv4]; + + NM_CMP_SELF(def_route_a, def_route_b); + + if (NM_FLAGS_HAS(flags, NM_L3_CONFIG_CMP_FLAGS_ROUTES)) { + NM_CMP_RETURN(nmp_object_cmp_full(def_route_a, + def_route_b, + NM_FLAGS_HAS(flags, NM_L3_CONFIG_CMP_FLAGS_IFINDEX) + ? NMP_OBJECT_CMP_FLAGS_NONE + : NMP_OBJECT_CMP_FLAGS_IGNORE_IFINDEX)); + } else if (NM_FLAGS_HAS(flags, NM_L3_CONFIG_CMP_FLAGS_ROUTES_ID)) { + if (NM_FLAGS_HAS(flags, NM_L3_CONFIG_CMP_FLAGS_IFINDEX)) { + NM_CMP_DIRECT(def_route_a->obj_with_ifindex.ifindex, + def_route_b->obj_with_ifindex.ifindex); + } - NM_CMP_RETURN(nmp_object_cmp_full(a->best_default_route_x[IS_IPv4], - b->best_default_route_x[IS_IPv4], - ignore_ifindex ? NMP_OBJECT_CMP_FLAGS_IGNORE_IFINDEX - : NMP_OBJECT_CMP_FLAGS_NONE)); + if (IS_IPv4) { + NMPlatformIP4Route ra = def_route_a->ip4_route; + NMPlatformIP4Route rb = def_route_b->ip4_route; + + NM_CMP_DIRECT(ra.metric, rb.metric); + NM_CMP_DIRECT(ra.plen, rb.plen); + NM_CMP_RETURN_DIRECT( + nm_utils_ip4_address_same_prefix_cmp(ra.network, rb.network, ra.plen)); + } else { + NMPlatformIP6Route ra = def_route_a->ip6_route; + NMPlatformIP6Route rb = def_route_b->ip6_route; + + NM_CMP_DIRECT(ra.metric, rb.metric); + NM_CMP_DIRECT(ra.plen, rb.plen); + NM_CMP_RETURN_DIRECT( + nm_utils_ip6_address_same_prefix_cmp(&ra.network, &rb.network, ra.plen)); + } + } - NM_CMP_RETURN( - _garray_inaddr_cmp(a->nameservers_x[IS_IPv4], b->nameservers_x[IS_IPv4], addr_family)); - - NM_CMP_RETURN(nm_utils_hashtable_cmp(nm_dhcp_lease_get_options(a->dhcp_lease_x[IS_IPv4]), - nm_dhcp_lease_get_options(b->dhcp_lease_x[IS_IPv4]), - TRUE, - nm_strcmp_with_data, - nm_strcmp_with_data, - NULL)); - - NM_CMP_RETURN(nm_strv_ptrarray_cmp(a->domains_x[IS_IPv4], b->domains_x[IS_IPv4])); - NM_CMP_RETURN(nm_strv_ptrarray_cmp(a->searches_x[IS_IPv4], b->searches_x[IS_IPv4])); - NM_CMP_RETURN(nm_strv_ptrarray_cmp(a->dns_options_x[IS_IPv4], b->dns_options_x[IS_IPv4])); - - if (NM_FLAGS_ANY(a->flags, NM_L3_CONFIG_DAT_FLAGS_HAS_DNS_PRIORITY(IS_IPv4))) - NM_CMP_DIRECT(a->dns_priority_x[IS_IPv4], b->dns_priority_x[IS_IPv4]); - - NM_CMP_DIRECT(a->route_table_sync_x[IS_IPv4], b->route_table_sync_x[IS_IPv4]); - NM_CMP_DIRECT(a->never_default_x[IS_IPv4], b->never_default_x[IS_IPv4]); - } - - NM_CMP_RETURN(_garray_inaddr_cmp(a->wins, b->wins, AF_INET)); - NM_CMP_RETURN(_garray_inaddr_cmp(a->nis_servers, b->nis_servers, AF_INET)); - NM_CMP_DIRECT_REF_STRING(a->nis_domain, b->nis_domain); - NM_CMP_DIRECT(a->mdns, b->mdns); - NM_CMP_DIRECT(a->llmnr, b->llmnr); - NM_CMP_DIRECT(a->mtu, b->mtu); - NM_CMP_DIRECT(a->ip6_mtu, b->ip6_mtu); - NM_CMP_DIRECT_UNSAFE(a->metered, b->metered); - NM_CMP_DIRECT_UNSAFE(a->proxy_browser_only, b->proxy_browser_only); - NM_CMP_DIRECT_UNSAFE(a->proxy_method, b->proxy_method); - NM_CMP_DIRECT_REF_STRING(a->proxy_pac_url, b->proxy_pac_url); - NM_CMP_DIRECT_REF_STRING(a->proxy_pac_script, b->proxy_pac_script); - NM_CMP_DIRECT_UNSAFE(a->ip6_privacy, b->ip6_privacy); - - NM_CMP_DIRECT_UNSAFE(a->ndisc_hop_limit_set, b->ndisc_hop_limit_set); - if (a->ndisc_hop_limit_set) - NM_CMP_DIRECT(a->ndisc_hop_limit_val, b->ndisc_hop_limit_val); - - NM_CMP_DIRECT_UNSAFE(a->ndisc_reachable_time_msec_set, b->ndisc_reachable_time_msec_set); - if (a->ndisc_reachable_time_msec_set) - NM_CMP_DIRECT(a->ndisc_reachable_time_msec_val, b->ndisc_reachable_time_msec_val); - - NM_CMP_DIRECT_UNSAFE(a->ndisc_retrans_timer_msec_set, b->ndisc_retrans_timer_msec_set); - if (a->ndisc_retrans_timer_msec_set) - NM_CMP_DIRECT(a->ndisc_retrans_timer_msec_val, b->ndisc_retrans_timer_msec_val); - - NM_CMP_FIELD(a, b, source); + if (NM_FLAGS_HAS(flags, NM_L3_CONFIG_CMP_FLAGS_DNS)) { + NM_CMP_RETURN(_garray_inaddr_cmp(a->nameservers_x[IS_IPv4], + b->nameservers_x[IS_IPv4], + addr_family)); + NM_CMP_RETURN(nm_strv_ptrarray_cmp(a->domains_x[IS_IPv4], b->domains_x[IS_IPv4])); + NM_CMP_RETURN(nm_strv_ptrarray_cmp(a->searches_x[IS_IPv4], b->searches_x[IS_IPv4])); + NM_CMP_RETURN( + nm_strv_ptrarray_cmp(a->dns_options_x[IS_IPv4], b->dns_options_x[IS_IPv4])); + + if (NM_FLAGS_ANY(a->flags, NM_L3_CONFIG_DAT_FLAGS_HAS_DNS_PRIORITY(IS_IPv4))) + NM_CMP_DIRECT(a->dns_priority_x[IS_IPv4], b->dns_priority_x[IS_IPv4]); + } + + if (NM_FLAGS_HAS(flags, NM_L3_CONFIG_CMP_FLAGS_OTHER)) { + NM_CMP_RETURN( + nm_utils_hashtable_cmp(nm_dhcp_lease_get_options(a->dhcp_lease_x[IS_IPv4]), + nm_dhcp_lease_get_options(b->dhcp_lease_x[IS_IPv4]), + TRUE, + nm_strcmp_with_data, + nm_strcmp_with_data, + NULL)); + + NM_CMP_DIRECT(a->route_table_sync_x[IS_IPv4], b->route_table_sync_x[IS_IPv4]); + NM_CMP_DIRECT(a->never_default_x[IS_IPv4], b->never_default_x[IS_IPv4]); + } + } + + if (NM_FLAGS_HAS(flags, NM_L3_CONFIG_CMP_FLAGS_DNS)) { + NM_CMP_RETURN(_garray_inaddr_cmp(a->wins, b->wins, AF_INET)); + NM_CMP_RETURN(_garray_inaddr_cmp(a->nis_servers, b->nis_servers, AF_INET)); + NM_CMP_DIRECT_REF_STRING(a->nis_domain, b->nis_domain); + NM_CMP_DIRECT(a->mdns, b->mdns); + NM_CMP_DIRECT(a->llmnr, b->llmnr); + NM_CMP_DIRECT(a->dns_over_tls, b->dns_over_tls); + } + + if (NM_FLAGS_HAS(flags, NM_L3_CONFIG_CMP_FLAGS_OTHER)) { + NM_CMP_DIRECT(a->flags, b->flags); + NM_CMP_DIRECT(a->ip6_token.id, b->ip6_token.id); + NM_CMP_DIRECT(a->mtu, b->mtu); + NM_CMP_DIRECT(a->ip6_mtu, b->ip6_mtu); + NM_CMP_DIRECT_UNSAFE(a->metered, b->metered); + NM_CMP_DIRECT_UNSAFE(a->proxy_browser_only, b->proxy_browser_only); + NM_CMP_DIRECT_UNSAFE(a->proxy_method, b->proxy_method); + NM_CMP_DIRECT_REF_STRING(a->proxy_pac_url, b->proxy_pac_url); + NM_CMP_DIRECT_REF_STRING(a->proxy_pac_script, b->proxy_pac_script); + NM_CMP_DIRECT_UNSAFE(a->ip6_privacy, b->ip6_privacy); + + NM_CMP_DIRECT_UNSAFE(a->ndisc_hop_limit_set, b->ndisc_hop_limit_set); + if (a->ndisc_hop_limit_set) + NM_CMP_DIRECT(a->ndisc_hop_limit_val, b->ndisc_hop_limit_val); + + NM_CMP_DIRECT_UNSAFE(a->ndisc_reachable_time_msec_set, b->ndisc_reachable_time_msec_set); + if (a->ndisc_reachable_time_msec_set) + NM_CMP_DIRECT(a->ndisc_reachable_time_msec_val, b->ndisc_reachable_time_msec_val); + + NM_CMP_DIRECT_UNSAFE(a->ndisc_retrans_timer_msec_set, b->ndisc_retrans_timer_msec_set); + if (a->ndisc_retrans_timer_msec_set) + NM_CMP_DIRECT(a->ndisc_retrans_timer_msec_val, b->ndisc_retrans_timer_msec_val); + + NM_CMP_FIELD(a, b, source); + } /* these fields are not considered by cmp(): * @@ -2167,9 +2370,9 @@ _data_get_direct_route_for_host(const NML3ConfigData *self, guint32 route_table) { const int IS_IPv4 = NM_IS_IPv4(addr_family); - const NMPObject * best_route_obj = NULL; + const NMPObject *best_route_obj = NULL; const NMPlatformIPXRoute *best_route = NULL; - const NMPObject * item_obj; + const NMPObject *item_obj; NMDedupMultiIter ipconf_iter; nm_assert(_NM_IS_L3_CONFIG_DATA(self, TRUE)); @@ -2230,7 +2433,7 @@ GPtrArray * nm_l3_config_data_get_blacklisted_ip4_routes(const NML3ConfigData *self, gboolean is_vrf) { gs_unref_ptrarray GPtrArray *ip4_dev_route_blacklist = NULL; - const NMPObject * my_addr_obj; + const NMPObject *my_addr_obj; NMDedupMultiIter iter; nm_assert(_NM_IS_L3_CONFIG_DATA(self, TRUE)); @@ -2295,7 +2498,7 @@ void nm_l3_config_data_add_dependent_onlink_routes(NML3ConfigData *self, int addr_family) { gs_unref_ptrarray GPtrArray *extra_onlink_routes = NULL; - const NMPObject * obj_src; + const NMPObject *obj_src; NMDedupMultiIter iter; int IS_IPv4; guint i; @@ -2316,16 +2519,17 @@ nm_l3_config_data_add_dependent_onlink_routes(NML3ConfigData *self, int addr_fam nm_l3_config_data_iter_obj_for_each (&iter, self, &obj_src, NMP_OBJECT_TYPE_IP_ROUTE(IS_IPv4)) { const NMPlatformIPXRoute *route_src = NMP_OBJECT_CAST_IPX_ROUTE(obj_src); - NMPObject * new_route; - NMPlatformIPXRoute * new_r; - const NMIPAddr * p_gateway; + NMPObject *new_route; + NMPlatformIPXRoute *new_r; + const NMIPAddr *p_gateway; p_gateway = nm_platform_ip_route_get_gateway(addr_family, &route_src->rx); if (nm_ip_addr_is_null(addr_family, p_gateway)) continue; - if (_data_get_direct_route_for_host( + if (!NM_PLATFORM_IP_ROUTE_IS_DEFAULT(route_src) + || _data_get_direct_route_for_host( self, addr_family, p_gateway, @@ -2363,14 +2567,15 @@ nm_l3_config_data_add_dependent_onlink_routes(NML3ConfigData *self, int addr_fam } void -nm_l3_config_data_add_dependent_device_routes(NML3ConfigData * self, +nm_l3_config_data_add_dependent_device_routes(NML3ConfigData *self, int addr_family, guint32 route_table, guint32 route_metric, + gboolean force_commit, const NML3ConfigData *source) { const int IS_IPv4 = NM_IS_IPv4(addr_family); - const NMPObject * obj_src; + const NMPObject *obj_src; NMPlatformIPXRoute rx; NMDedupMultiIter iter; @@ -2393,7 +2598,7 @@ nm_l3_config_data_add_dependent_device_routes(NML3ConfigData * self, &obj_src, NMP_OBJECT_TYPE_IP_ADDRESS(IS_IPv4)) { const NMPlatformIPXAddress *const addr_src = NMP_OBJECT_CAST_IPX_ADDRESS(obj_src); - const NMPlatformIPXAddress * addr_dst; + const NMPlatformIPXAddress *addr_dst; addr_dst = NMP_OBJECT_CAST_IPX_ADDRESS( nm_dedup_multi_entry_get_obj(nm_l3_config_data_lookup_obj(self, obj_src))); @@ -2411,6 +2616,7 @@ nm_l3_config_data_add_dependent_device_routes(NML3ConfigData * self, self->ifindex, route_table, route_metric, + force_commit, &r_stack.r4); if (r) nm_l3_config_data_add_route(self, addr_family, NULL, r); @@ -2449,13 +2655,15 @@ nm_l3_config_data_add_dependent_device_routes(NML3ConfigData * self, } rx.r6 = (NMPlatformIP6Route){ - .ifindex = self->ifindex, - .rt_source = NM_IP_CONFIG_SOURCE_KERNEL, - .table_coerced = nm_platform_route_table_coerce(route_table), - .metric = route_metric, - .network = *a6, - .plen = plen, + .ifindex = self->ifindex, + .rt_source = NM_IP_CONFIG_SOURCE_KERNEL, + .table_coerced = nm_platform_route_table_coerce(route_table), + .metric = route_metric, + .network = *a6, + .plen = plen, + .r_force_commit = force_commit, }; + nm_platform_ip_route_normalize(addr_family, &rx.rx); nm_l3_config_data_add_route(self, addr_family, NULL, &rx.rx); } @@ -2475,7 +2683,7 @@ _init_from_connection_ip(NML3ConfigData *self, int addr_family, NMConnection *co guint nroutes; guint nnameservers; guint nsearches; - const char * gateway_str; + const char *gateway_str; NMIPAddr gateway_bin; guint i; int idx; @@ -2521,10 +2729,10 @@ _init_from_connection_ip(NML3ConfigData *self, int addr_family, NMConnection *co naddresses = nm_setting_ip_config_get_num_addresses(s_ip); for (i = 0; i < naddresses; i++) { - NMIPAddress * s_addr = nm_setting_ip_config_get_address(s_ip, i); + NMIPAddress *s_addr = nm_setting_ip_config_get_address(s_ip, i); NMPlatformIPXAddress a; NMIPAddr addr_bin; - GVariant * label; + GVariant *label; nm_assert(nm_ip_address_get_family(s_addr) == addr_family); @@ -2561,7 +2769,7 @@ _init_from_connection_ip(NML3ConfigData *self, int addr_family, NMConnection *co nroutes = nm_setting_ip_config_get_num_routes(s_ip); for (i = 0; i < nroutes; i++) { - NMIPRoute * s_route = nm_setting_ip_config_get_route(s_ip, i); + NMIPRoute *s_route = nm_setting_ip_config_get_route(s_ip, i); NMPlatformIPXRoute r; NMIPAddr network_bin; NMIPAddr next_hop_bin; @@ -2656,7 +2864,7 @@ _init_from_connection_ip(NML3ConfigData *self, int addr_family, NMConnection *co NML3ConfigData * nm_l3_config_data_new_from_connection(NMDedupMultiIndex *multi_idx, int ifindex, - NMConnection * connection) + NMConnection *connection) { NML3ConfigData *self; NMSettingProxy *s_proxy; @@ -2716,14 +2924,14 @@ sort_captured_addresses_6(const CList *lst_a, const CList *lst_b, gconstpointer } static void -_init_from_platform(NML3ConfigData * self, +_init_from_platform(NML3ConfigData *self, int addr_family, - NMPlatform * platform, + NMPlatform *platform, NMSettingIP6ConfigPrivacy ipv6_privacy_rfc4941) { const int IS_IPv4 = NM_IS_IPv4(addr_family); const NMDedupMultiHeadEntry *head_entry; - const NMPObject * plobj = NULL; + const NMPObject *plobj = NULL; NMDedupMultiIter iter; nm_assert(_NM_IS_L3_CONFIG_DATA(self, FALSE)); @@ -2766,9 +2974,9 @@ _init_from_platform(NML3ConfigData * self, } NML3ConfigData * -nm_l3_config_data_new_from_platform(NMDedupMultiIndex * multi_idx, +nm_l3_config_data_new_from_platform(NMDedupMultiIndex *multi_idx, int ifindex, - NMPlatform * platform, + NMPlatform *platform, NMSettingIP6ConfigPrivacy ipv6_privacy_rfc4941) { NML3ConfigData *self; @@ -2791,31 +2999,39 @@ nm_l3_config_data_new_from_platform(NMDedupMultiIndex * multi_idx, /*****************************************************************************/ void -nm_l3_config_data_merge(NML3ConfigData * self, +nm_l3_config_data_merge(NML3ConfigData *self, const NML3ConfigData *src, NML3ConfigMergeFlags merge_flags, - const guint32 * default_route_table_x /* length 2, for IS_IPv4 */, - const guint32 * default_route_metric_x /* length 2, for IS_IPv4 */, - const guint32 * default_route_penalty_x /* length 2, for IS_IPv4 */, - const int * default_dns_priority_x /* length 2, for IS_IPv4 */, + const guint32 *default_route_table_x /* length 2, for IS_IPv4 */, + const guint32 *default_route_metric_x /* length 2, for IS_IPv4 */, + const guint32 *default_route_penalty_x /* length 2, for IS_IPv4 */, + const int *default_dns_priority_x /* length 2, for IS_IPv4 */, NML3ConfigMergeHookAddObj hook_add_obj, gpointer hook_user_data) { - static const guint32 x_default_route_table_x[2] = {RT_TABLE_MAIN, RT_TABLE_MAIN}; static const guint32 x_default_route_metric_x[2] = {NM_PLATFORM_ROUTE_METRIC_DEFAULT_IP6, NM_PLATFORM_ROUTE_METRIC_DEFAULT_IP4}; static const guint32 x_default_route_penalty_x[2] = {0, 0}; static const int x_default_dns_priority_x[2] = {NM_DNS_PRIORITY_DEFAULT_NORMAL, NM_DNS_PRIORITY_DEFAULT_NORMAL}; + guint32 default_route_table_coerced_x[2]; NMDedupMultiIter iter; - const NMPObject * obj; + const NMPObject *obj; int IS_IPv4; nm_assert(_NM_IS_L3_CONFIG_DATA(self, FALSE)); nm_assert(_NM_IS_L3_CONFIG_DATA(src, TRUE)); - if (!default_route_table_x) - default_route_table_x = x_default_route_table_x; + if (default_route_table_x) { + default_route_table_coerced_x[0] = nm_platform_route_table_coerce(default_route_table_x[0]); + default_route_table_coerced_x[1] = nm_platform_route_table_coerce(default_route_table_x[1]); + } else { + default_route_table_coerced_x[0] = nm_platform_route_table_coerce(RT_TABLE_MAIN); + default_route_table_coerced_x[1] = nm_platform_route_table_coerce(RT_TABLE_MAIN); + } + nm_assert(nm_platform_route_table_uncoerce(default_route_table_coerced_x[0], FALSE) != 0); + nm_assert(nm_platform_route_table_uncoerce(default_route_table_coerced_x[1], FALSE) != 0); + if (!default_route_metric_x) default_route_metric_x = x_default_route_metric_x; if (!default_route_penalty_x) @@ -2823,8 +3039,6 @@ nm_l3_config_data_merge(NML3ConfigData * self, if (!default_dns_priority_x) default_dns_priority_x = x_default_dns_priority_x; - nm_assert(default_route_table_x[0] != 0); - nm_assert(default_route_table_x[1] != 0); nm_assert(default_route_metric_x[0] != 0); /* IPv6 route metric cannot be zero. */ nm_assert(!NM_FLAGS_HAS(merge_flags, NM_L3_CONFIG_MERGE_FLAGS_CLONE) @@ -2842,8 +3056,9 @@ nm_l3_config_data_merge(NML3ConfigData * self, const NMPlatformIPAddress *a_src = NMP_OBJECT_CAST_IP_ADDRESS(obj); NMPlatformIPXAddress a; NML3ConfigMergeHookResult hook_result = { - .ip4acd_not_ready = NM_OPTION_BOOL_DEFAULT, - .assume_config_once = NM_OPTION_BOOL_DEFAULT, + .ip4acd_not_ready = NM_OPTION_BOOL_DEFAULT, + .assume_config_once = NM_OPTION_BOOL_DEFAULT, + .force_commit = NM_OPTION_BOOL_DEFAULT, }; #define _ensure_a() \ @@ -2882,6 +3097,12 @@ nm_l3_config_data_merge(NML3ConfigData * self, a.ax.a_assume_config_once = (!!hook_result.assume_config_once); } + if (hook_result.force_commit != NM_OPTION_BOOL_DEFAULT + && (!!hook_result.force_commit) != a_src->a_force_commit) { + _ensure_a(); + a.ax.a_force_commit = (!!hook_result.force_commit); + } + nm_l3_config_data_add_address_full(self, addr_family, a_src == &a.ax ? NULL : obj, @@ -2897,11 +3118,12 @@ nm_l3_config_data_merge(NML3ConfigData * self, src, &obj, NMP_OBJECT_TYPE_IP_ROUTE(IS_IPv4)) { - const NMPlatformIPRoute * r_src = NMP_OBJECT_CAST_IP_ROUTE(obj); + const NMPlatformIPRoute *r_src = NMP_OBJECT_CAST_IP_ROUTE(obj); NMPlatformIPXRoute r; NML3ConfigMergeHookResult hook_result = { .ip4acd_not_ready = NM_OPTION_BOOL_DEFAULT, .assume_config_once = NM_OPTION_BOOL_DEFAULT, + .force_commit = NM_OPTION_BOOL_DEFAULT, }; #define _ensure_r() \ @@ -2933,11 +3155,17 @@ nm_l3_config_data_merge(NML3ConfigData * self, r.rx.r_assume_config_once = (!!hook_result.assume_config_once); } + if (hook_result.force_commit != NM_OPTION_BOOL_DEFAULT + && (!!hook_result.force_commit) != r_src->r_force_commit) { + _ensure_r(); + r.rx.r_force_commit = (!!hook_result.force_commit); + } + if (!NM_FLAGS_HAS(merge_flags, NM_L3_CONFIG_MERGE_FLAGS_CLONE)) { if (r_src->table_any) { _ensure_r(); r.rx.table_any = FALSE; - r.rx.table_coerced = default_route_table_x[IS_IPv4]; + r.rx.table_coerced = default_route_table_coerced_x[IS_IPv4]; } if (r_src->metric_any) { @@ -3019,6 +3247,12 @@ nm_l3_config_data_merge(NML3ConfigData * self, if (self->llmnr == NM_SETTING_CONNECTION_LLMNR_DEFAULT) self->llmnr = src->llmnr; + if (self->dns_over_tls == NM_SETTING_CONNECTION_DNS_OVER_TLS_DEFAULT) + self->dns_over_tls = src->dns_over_tls; + + if (self->ip6_token.id == 0) + self->ip6_token.id = src->ip6_token.id; + self->metered = NM_MAX((NMTernary) self->metered, (NMTernary) src->metered); if (self->proxy_method == NM_PROXY_CONFIG_METHOD_UNKNOWN) @@ -3095,9 +3329,10 @@ nm_l3_config_data_new_clone(const NML3ConfigData *src, int ifindex) nm_assert(nm_l3_config_data_cmp_full(src, self, - src->ifindex != ifindex - ? NM_L3_CONFIG_CMP_FLAGS_IGNORE_IFINDEX - : NM_L3_CONFIG_CMP_FLAGS_NONE) + src->ifindex == ifindex + ? NM_L3_CONFIG_CMP_FLAGS_ALL + : NM_L3_CONFIG_CMP_FLAGS_ALL + & ~(NM_L3_CONFIG_CMP_FLAGS_IFINDEX)) == 0); nm_assert(nm_l3_config_data_get_ifindex(self) == ifindex); diff --git a/src/core/nm-l3-config-data.h b/src/core/nm-l3-config-data.h index 1ad23c32..b7a1bb32 100644 --- a/src/core/nm-l3-config-data.h +++ b/src/core/nm-l3-config-data.h @@ -128,30 +128,31 @@ NML3ConfigData *nm_l3_config_data_new_clone(const NML3ConfigData *src, int ifind NML3ConfigData *nm_l3_config_data_new_from_connection(NMDedupMultiIndex *multi_idx, int ifindex, - NMConnection * connection); + NMConnection *connection); -NML3ConfigData *nm_l3_config_data_new_from_platform(NMDedupMultiIndex * multi_idx, +NML3ConfigData *nm_l3_config_data_new_from_platform(NMDedupMultiIndex *multi_idx, int ifindex, - NMPlatform * platform, + NMPlatform *platform, NMSettingIP6ConfigPrivacy ipv6_privacy_rfc4941); typedef struct { NMOptionBool ip4acd_not_ready; NMOptionBool assume_config_once; + NMOptionBool force_commit; } NML3ConfigMergeHookResult; -typedef gboolean (*NML3ConfigMergeHookAddObj)(const NML3ConfigData * l3cd, - const NMPObject * obj, +typedef gboolean (*NML3ConfigMergeHookAddObj)(const NML3ConfigData *l3cd, + const NMPObject *obj, NML3ConfigMergeHookResult *result, gpointer user_data); -void nm_l3_config_data_merge(NML3ConfigData * self, +void nm_l3_config_data_merge(NML3ConfigData *self, const NML3ConfigData *src, NML3ConfigMergeFlags merge_flags, const guint32 *default_route_table_x /* length 2, for IS_IPv4 */, const guint32 *default_route_metric_x /* length 2, for IS_IPv4 */, const guint32 *default_route_penalty_x /* length 2, for IS_IPv4 */, - const int * default_dns_priority_x /* length 2, for IS_IPv4 */, + const int *default_dns_priority_x /* length 2, for IS_IPv4 */, NML3ConfigMergeHookAddObj hook_add_obj, gpointer hook_user_data); @@ -160,17 +161,18 @@ GPtrArray *nm_l3_config_data_get_blacklisted_ip4_routes(const NML3ConfigData *se void nm_l3_config_data_add_dependent_onlink_routes(NML3ConfigData *self, int addr_family); -void nm_l3_config_data_add_dependent_device_routes(NML3ConfigData * self, +void nm_l3_config_data_add_dependent_device_routes(NML3ConfigData *self, int addr_family, guint32 route_table, guint32 route_metric, + gboolean force_commit, const NML3ConfigData *source); /*****************************************************************************/ void nm_l3_config_data_log(const NML3ConfigData *self, - const char * title, - const char * prefix, + const char *title, + const char *prefix, NMLogLevel log_level, NMLogDomain log_domain); @@ -196,18 +198,25 @@ NMDedupMultiIndex *nm_l3_config_data_get_multi_idx(const NML3ConfigData *self); /*****************************************************************************/ typedef enum { - NM_L3_CONFIG_CMP_FLAGS_NONE, - NM_L3_CONFIG_CMP_FLAGS_IGNORE_IFINDEX = (1LL << 0), + NM_L3_CONFIG_CMP_FLAGS_NONE = 0, + NM_L3_CONFIG_CMP_FLAGS_IFINDEX = (1LL << 0), + NM_L3_CONFIG_CMP_FLAGS_ADDRESSES_ID = (1LL << 1), + NM_L3_CONFIG_CMP_FLAGS_ADDRESSES = (1LL << 2), + NM_L3_CONFIG_CMP_FLAGS_ROUTES_ID = (1LL << 3), + NM_L3_CONFIG_CMP_FLAGS_ROUTES = (1LL << 4), + NM_L3_CONFIG_CMP_FLAGS_DNS = (1LL << 5), + NM_L3_CONFIG_CMP_FLAGS_OTHER = (1LL << 6), + NM_L3_CONFIG_CMP_FLAGS_ALL = (1LL << 7) - 1, } NML3ConfigCmpFlags; int nm_l3_config_data_cmp_full(const NML3ConfigData *a, const NML3ConfigData *b, - NML3ConfigCmpFlags cmp_flags); + NML3ConfigCmpFlags flags); static inline int nm_l3_config_data_cmp(const NML3ConfigData *a, const NML3ConfigData *b) { - return nm_l3_config_data_cmp_full(a, b, NM_L3_CONFIG_CMP_FLAGS_NONE); + return nm_l3_config_data_cmp_full(a, b, NM_L3_CONFIG_CMP_FLAGS_ALL); } static inline gboolean @@ -222,20 +231,20 @@ const NMDedupMultiIdxType *nm_l3_config_data_lookup_index(const NML3ConfigData * NMPObjectType obj_type); const NMDedupMultiEntry *nm_l3_config_data_lookup_obj(const NML3ConfigData *self, - const NMPObject * obj); + const NMPObject *obj); const NMPlatformIP4Address *nm_l3_config_data_lookup_address_4(const NML3ConfigData *self, in_addr_t addr, guint8 plen, in_addr_t peer_addr); -const NMPlatformIP6Address *nm_l3_config_data_lookup_address_6(const NML3ConfigData * self, +const NMPlatformIP6Address *nm_l3_config_data_lookup_address_6(const NML3ConfigData *self, const struct in6_addr *addr); const NMDedupMultiEntry *nm_l3_config_data_lookup_route_obj(const NML3ConfigData *self, - const NMPObject * needle); + const NMPObject *needle); -const NMDedupMultiEntry *nm_l3_config_data_lookup_route(const NML3ConfigData * self, +const NMDedupMultiEntry *nm_l3_config_data_lookup_route(const NML3ConfigData *self, int addr_family, const NMPlatformIPRoute *needle); @@ -345,7 +354,7 @@ nmtst_l3_config_data_get_route_at_6(const NML3ConfigData *self, guint i) NML3ConfigDatFlags nm_l3_config_data_get_flags(const NML3ConfigData *self); -void nm_l3_config_data_set_flags_full(NML3ConfigData * self, +void nm_l3_config_data_set_flags_full(NML3ConfigData *self, NML3ConfigDatFlags flags, NML3ConfigDatFlags mask); @@ -367,17 +376,17 @@ const NMPObject *nm_l3_config_data_get_first_obj(const NML3ConfigData *self, NMPObjectType obj_type, gboolean (*predicate)(const NMPObject *obj)); -gboolean nm_l3_config_data_add_address_full(NML3ConfigData * self, +gboolean nm_l3_config_data_add_address_full(NML3ConfigData *self, int addr_family, - const NMPObject * obj_new, + const NMPObject *obj_new, const NMPlatformIPAddress *pl_new, NML3ConfigAddFlags add_flags, - const NMPObject ** out_obj_new); + const NMPObject **out_obj_new); static inline gboolean -nm_l3_config_data_add_address(NML3ConfigData * self, +nm_l3_config_data_add_address(NML3ConfigData *self, int addr_family, - const NMPObject * obj_new, + const NMPObject *obj_new, const NMPlatformIPAddress *pl_new) { return nm_l3_config_data_add_address_full(self, @@ -400,18 +409,18 @@ nm_l3_config_data_add_address_6(NML3ConfigData *self, const NMPlatformIP6Address return nm_l3_config_data_add_address(self, AF_INET6, NULL, NM_PLATFORM_IP_ADDRESS_CAST(addr)); } -gboolean nm_l3_config_data_add_route_full(NML3ConfigData * self, +gboolean nm_l3_config_data_add_route_full(NML3ConfigData *self, int addr_family, - const NMPObject * obj_new, + const NMPObject *obj_new, const NMPlatformIPRoute *pl_new, NML3ConfigAddFlags add_flags, - const NMPObject ** out_obj_new, - gboolean * out_changed_best_default_route); + const NMPObject **out_obj_new, + gboolean *out_changed_best_default_route); static inline gboolean -nm_l3_config_data_add_route(NML3ConfigData * self, +nm_l3_config_data_add_route(NML3ConfigData *self, int addr_family, - const NMPObject * obj_new, + const NMPObject *obj_new, const NMPlatformIPRoute *pl_new) { return nm_l3_config_data_add_route_full(self, @@ -446,10 +455,15 @@ NMSettingConnectionLlmnr nm_l3_config_data_get_llmnr(const NML3ConfigData *self) gboolean nm_l3_config_data_set_llmnr(NML3ConfigData *self, NMSettingConnectionLlmnr llmnr); +NMSettingConnectionDnsOverTls nm_l3_config_data_get_dns_over_tls(const NML3ConfigData *self); + +gboolean nm_l3_config_data_set_dns_over_tls(NML3ConfigData *self, + NMSettingConnectionDnsOverTls dns_over_tls); + NMIPRouteTableSyncMode nm_l3_config_data_get_route_table_sync(const NML3ConfigData *self, int addr_family); -gboolean nm_l3_config_data_set_route_table_sync(NML3ConfigData * self, +gboolean nm_l3_config_data_set_route_table_sync(NML3ConfigData *self, int addr_family, NMIPRouteTableSyncMode route_table_sync); @@ -470,6 +484,10 @@ guint32 nm_l3_config_data_get_ip6_mtu(const NML3ConfigData *self); gboolean nm_l3_config_data_set_ip6_mtu(NML3ConfigData *self, guint32 ip6_mtu); +NMUtilsIPv6IfaceId nm_l3_config_data_get_ip6_token(const NML3ConfigData *self); + +gboolean nm_l3_config_data_set_ip6_token(NML3ConfigData *self, NMUtilsIPv6IfaceId ipv6_token); + const in_addr_t *nm_l3_config_data_get_wins(const NML3ConfigData *self, guint *out_len); gboolean nm_l3_config_data_add_wins(NML3ConfigData *self, in_addr_t wins); @@ -477,7 +495,7 @@ gboolean nm_l3_config_data_add_wins(NML3ConfigData *self, in_addr_t wins); gconstpointer nm_l3_config_data_get_nameservers(const NML3ConfigData *self, int addr_family, guint *out_len); -gboolean nm_l3_config_data_add_nameserver(NML3ConfigData * self, +gboolean nm_l3_config_data_add_nameserver(NML3ConfigData *self, int addr_family, gconstpointer /* (const NMIPAddr *) */ nameserver); @@ -528,7 +546,7 @@ nm_l3_config_data_set_dns_priority(NML3ConfigData *self, int addr_family, int dn NMSettingIP6ConfigPrivacy nm_l3_config_data_get_ip6_privacy(const NML3ConfigData *self); -gboolean nm_l3_config_data_set_ip6_privacy(NML3ConfigData * self, +gboolean nm_l3_config_data_set_ip6_privacy(NML3ConfigData *self, NMSettingIP6ConfigPrivacy ip6_privacy); NMProxyConfigMethod nm_l3_config_data_get_proxy_method(const NML3ConfigData *self); @@ -551,11 +569,11 @@ gboolean nm_l3_config_data_get_ndisc_hop_limit(const NML3ConfigData *self, int * gboolean nm_l3_config_data_set_ndisc_hop_limit(NML3ConfigData *self, int val); gboolean nm_l3_config_data_get_ndisc_reachable_time_msec(const NML3ConfigData *self, - guint32 * out_val); + guint32 *out_val); gboolean nm_l3_config_data_set_ndisc_reachable_time_msec(NML3ConfigData *self, guint32 val); gboolean nm_l3_config_data_get_ndisc_retrans_timer_msec(const NML3ConfigData *self, - guint32 * out_val); + guint32 *out_val); gboolean nm_l3_config_data_set_ndisc_retrans_timer_msec(NML3ConfigData *self, guint32 val); struct _NMDhcpLease *nm_l3_config_data_get_dhcp_lease(const NML3ConfigData *self, int addr_family); @@ -565,7 +583,7 @@ nm_l3_config_data_set_dhcp_lease(NML3ConfigData *self, int addr_family, struct _ gboolean nm_l3_config_data_set_dhcp_lease_from_options(NML3ConfigData *self, int addr_family, - GHashTable * options_take); + GHashTable *options_take); static inline const NMIPAddr * nmtst_l3_config_data_get_best_gateway(const NML3ConfigData *self, int addr_family) diff --git a/src/core/nm-l3-ipv4ll.c b/src/core/nm-l3-ipv4ll.c index eb9ceb9b..68cb17fb 100644 --- a/src/core/nm-l3-ipv4ll.c +++ b/src/core/nm-l3-ipv4ll.c @@ -31,16 +31,16 @@ struct _NML3IPv4LLRegistration { G_STATIC_ASSERT(G_STRUCT_OFFSET(NML3IPv4LLRegistration, self) == 0); struct _NML3IPv4LL { - NML3Cfg * l3cfg; + NML3Cfg *l3cfg; int ref_count; in_addr_t addr; guint reg_timeout_msec; CList reg_lst_head; NML3CfgCommitTypeHandle *l3cfg_commit_handle; - GSource * state_change_on_idle_source; - GSource * timed_out_source; - const NML3ConfigData * l3cd; - const NMPObject * plobj; + GSource *state_change_on_idle_source; + GSource *timed_out_source; + const NML3ConfigData *l3cd; + const NMPObject *plobj; struct { nm_le64_t value; nm_le64_t generation; @@ -202,7 +202,7 @@ _ipv4ll_emit_signal_notify(NML3IPv4LL *self) /*****************************************************************************/ static NML3IPv4LLRegistration * -_registration_update(NML3IPv4LL * self, +_registration_update(NML3IPv4LL *self, NML3IPv4LLRegistration *reg, gboolean add, guint timeout_msec) @@ -305,8 +305,8 @@ _acd_info_is_good(const NML3AcdAddrInfo *acd_info) case NM_L3_ACD_ADDR_STATE_PROBING: case NM_L3_ACD_ADDR_STATE_READY: case NM_L3_ACD_ADDR_STATE_DEFENDING: - case NM_L3_ACD_ADDR_STATE_EXTERNAL_REMOVED: return TRUE; + case NM_L3_ACD_ADDR_STATE_EXTERNAL_REMOVED: case NM_L3_ACD_ADDR_STATE_USED: case NM_L3_ACD_ADDR_STATE_CONFLICT: return FALSE; @@ -503,9 +503,9 @@ gen_addr: static void _ipv4ll_update_link(NML3IPv4LL *self, const NMPObject *plobj) { - char sbuf[ETH_ALEN * 3]; + char sbuf[ETH_ALEN * 3]; nm_auto_nmpobj const NMPObject *pllink_old = NULL; - const NMEtherAddr * mac_new; + const NMEtherAddr *mac_new; gboolean changed; if (self->plobj == plobj) @@ -668,8 +668,8 @@ _ipv4ll_platform_find_addr(NML3IPv4LL *self, const NML3AcdAddrInfo **out_acd_inf const NMPlatformIP4Address *addr_without_acd_info = NULL; NMDedupMultiIter iter; NMPLookup lookup; - const NMPObject * obj; - const NML3AcdAddrInfo * acd_info; + const NMPObject *obj; + const NML3AcdAddrInfo *acd_info; const NMPlatformIP4Address *addr; nmp_lookup_init_object(&lookup, NMP_OBJECT_TYPE_IP4_ADDRESS, nm_l3_ipv4ll_get_ifindex(self)); @@ -785,12 +785,12 @@ static void _ipv4ll_state_change(NML3IPv4LL *self, gboolean is_on_idle_handler) { nm_auto_unref_l3ipv4ll NML3IPv4LL *self_keep_alive = NULL; - const NMPlatformIP4Address * pladdr; - const NML3AcdAddrInfo * acd_info; + const NMPlatformIP4Address *pladdr; + const NML3AcdAddrInfo *acd_info; gboolean generate_new_addr; NML3IPv4LLState new_state; in_addr_t addr0; - NML3IPv4LLRegistration * reg; + NML3IPv4LLRegistration *reg; _ASSERT(self); diff --git a/src/core/nm-l3-ipv6ll.c b/src/core/nm-l3-ipv6ll.c index 14387321..60da4ee8 100644 --- a/src/core/nm-l3-ipv6ll.c +++ b/src/core/nm-l3-ipv6ll.c @@ -29,13 +29,13 @@ NM_UTILS_LOOKUP_STR_DEFINE(nm_l3_ipv6ll_state_to_string, /*****************************************************************************/ struct _NML3IPv6LL { - NML3Cfg * l3cfg; + NML3Cfg *l3cfg; NML3CfgCommitTypeHandle *l3cfg_commit_handle; NML3IPv6LLNotifyFcn notify_fcn; gpointer user_data; - GSource * starting_on_idle_source; - GSource * wait_for_addr_source; - GSource * emit_changed_idle_source; + GSource *starting_on_idle_source; + GSource *wait_for_addr_source; + GSource *emit_changed_idle_source; gulong l3cfg_signal_notify_id; NML3IPv6LLState state; @@ -51,6 +51,8 @@ struct _NML3IPv6LL { * with the configuration. */ const NML3ConfigData *l3cd; + guint32 route_table; + /* "assume" means that we first look whether there is any suitable * IPv6 address on the device, and in that case, try to use that * instead of generating a new one. Otherwise, we always try to @@ -202,7 +204,7 @@ nm_l3_ipv6ll_get_l3cd(NML3IPv6LL *self) static gboolean _emit_changed_on_idle_cb(gpointer user_data) { - NML3IPv6LL * self = user_data; + NML3IPv6LL *self = user_data; const struct in6_addr *lladdr; NML3IPv6LLState state; char sbuf[INET6_ADDRSTRLEN]; @@ -284,7 +286,7 @@ _pladdr_find_ll(NML3IPv6LL *self, gboolean *out_cur_addr_failed) NMDedupMultiIter iter; NMPLookup lookup; const NMPlatformIP6Address *pladdr1 = NULL; - const NMPObject * obj; + const NMPObject *obj; const NMPlatformIP6Address *pladdr_ready = NULL; const NMPlatformIP6Address *pladdr_tentative = NULL; gboolean cur_addr_check = TRUE; @@ -410,7 +412,7 @@ _lladdr_handle_changed(NML3IPv6LL *self) l3cd, NM_L3CFG_CONFIG_PRIORITY_IPV6LL, 0, - 0, + self->route_table, NM_PLATFORM_ROUTE_METRIC_DEFAULT_IP4, NM_PLATFORM_ROUTE_METRIC_DEFAULT_IP6, 0, @@ -618,12 +620,13 @@ _starting_on_idle_cb(gpointer user_data) /*****************************************************************************/ NML3IPv6LL * -_nm_l3_ipv6ll_new(NML3Cfg * l3cfg, +_nm_l3_ipv6ll_new(NML3Cfg *l3cfg, gboolean assume, NMUtilsStableType stable_type, - const char * ifname, - const char * network_id, + const char *ifname, + const char *network_id, const NMUtilsIPv6IfaceId *token_iid, + guint32 route_table, NML3IPv6LLNotifyFcn notify_fcn, gpointer user_data) { @@ -647,6 +650,7 @@ _nm_l3_ipv6ll_new(NML3Cfg * l3cfg, .cur_lladdr_obj = NULL, .cur_lladdr = IN6ADDR_ANY_INIT, .assume = assume, + .route_table = route_table, .addrgen = { .stable_type = stable_type, diff --git a/src/core/nm-l3-ipv6ll.h b/src/core/nm-l3-ipv6ll.h index 770a4268..c81757ed 100644 --- a/src/core/nm-l3-ipv6ll.h +++ b/src/core/nm-l3-ipv6ll.h @@ -30,7 +30,7 @@ typedef enum _nm_packed { const char *nm_l3_ipv6ll_state_to_string(NML3IPv6LLState state); -typedef void (*NML3IPv6LLNotifyFcn)(NML3IPv6LL * ipv6ll, +typedef void (*NML3IPv6LLNotifyFcn)(NML3IPv6LL *ipv6ll, NML3IPv6LLState state, const struct in6_addr *lladdr, gpointer user_data); @@ -42,21 +42,23 @@ NM_IS_L3_IPV6LL(const NML3IPv6LL *self) return !!self; } -NML3IPv6LL *_nm_l3_ipv6ll_new(NML3Cfg * l3cfg, +NML3IPv6LL *_nm_l3_ipv6ll_new(NML3Cfg *l3cfg, gboolean assume, NMUtilsStableType stable_type, - const char * ifname, - const char * network_id, + const char *ifname, + const char *network_id, const NMUtilsIPv6IfaceId *token_iid, + guint32 route_table, NML3IPv6LLNotifyFcn notify_fcn, gpointer user_data); static inline NML3IPv6LL * -nm_l3_ipv6ll_new_stable_privacy(NML3Cfg * l3cfg, +nm_l3_ipv6ll_new_stable_privacy(NML3Cfg *l3cfg, gboolean assume, NMUtilsStableType stable_type, - const char * ifname, - const char * network_id, + const char *ifname, + const char *network_id, + guint32 route_table, NML3IPv6LLNotifyFcn notify_fcn, gpointer user_data) { @@ -67,14 +69,16 @@ nm_l3_ipv6ll_new_stable_privacy(NML3Cfg * l3cfg, ifname, network_id, NULL, + route_table, notify_fcn, user_data); } static inline NML3IPv6LL * -nm_l3_ipv6ll_new_token(NML3Cfg * l3cfg, +nm_l3_ipv6ll_new_token(NML3Cfg *l3cfg, gboolean assume, const NMUtilsIPv6IfaceId *token_iid, + guint32 route_table, NML3IPv6LLNotifyFcn notify_fcn, gpointer user_data) { @@ -84,6 +88,7 @@ nm_l3_ipv6ll_new_token(NML3Cfg * l3cfg, NULL, NULL, token_iid, + route_table, notify_fcn, user_data); } diff --git a/src/core/nm-l3cfg.c b/src/core/nm-l3cfg.c index aa56c13f..9258decf 100644 --- a/src/core/nm-l3cfg.c +++ b/src/core/nm-l3cfg.c @@ -12,9 +12,11 @@ #include "libnm-glib-aux/nm-time-utils.h" #include "libnm-platform/nm-platform.h" #include "libnm-platform/nmp-object.h" +#include "libnm-platform/nmp-route-manager.h" #include "nm-netns.h" #include "n-acd/src/n-acd.h" #include "nm-l3-ipv4ll.h" +#include "nm-ip-config.h" /*****************************************************************************/ @@ -203,6 +205,7 @@ typedef struct { guint32 acd_timeout_msec_confdata; NML3AcdDefendType acd_defend_type_confdata : 3; bool dirty_confdata : 1; + gboolean force_commit_once : 1; } L3ConfigData; /*****************************************************************************/ @@ -240,12 +243,20 @@ typedef struct _NML3CfgPrivate { CList acd_event_notify_lst_head; - NAcd * nacd; + NAcd *nacd; GSource *nacd_source; GSource *nacd_event_down_source; gint64 nacd_event_down_ratelimited_until_msec; + union { + struct { + NMIPConfig *ipconfig_6; + NMIPConfig *ipconfig_4; + }; + NMIPConfig *ipconfig_x[2]; + }; + /* This is for rate-limiting the creation of nacd instance. */ GSource *nacd_instance_ensure_retry; @@ -332,17 +343,17 @@ static void _l3_commit(NML3Cfg *self, NML3CfgCommitType commit_type, gboolean is static void _nm_l3cfg_emit_signal_notify_acd_event_all(NML3Cfg *self); static gboolean _acd_has_valid_link(const NMPObject *obj, - const guint8 ** out_addr_bin, - gboolean * out_acd_not_supported); + const guint8 **out_addr_bin, + gboolean *out_acd_not_supported); static void _l3_acd_nacd_instance_reset(NML3Cfg *self, NMTernary start_timer, gboolean acd_data_notify); -static void _l3_acd_data_state_change(NML3Cfg * self, - AcdData * acd_data, +static void _l3_acd_data_state_change(NML3Cfg *self, + AcdData *acd_data, AcdStateChangeMode mode, const NMEtherAddr *sender, - gint64 * p_now_msec); + gint64 *p_now_msec); static AcdData *_l3_acd_data_find(NML3Cfg *self, in_addr_t addr); @@ -400,6 +411,92 @@ static NM_UTILS_LOOKUP_DEFINE(_l3_acd_addr_state_to_string, "external-removed"), NM_UTILS_LOOKUP_ITEM(NM_L3_ACD_ADDR_STATE_USED, "used"), ); +static gboolean +_obj_is_route_nodev(const NMPObject *obj) +{ + gboolean has_ifindex; + + nm_assert(obj); + + has_ifindex = (NMP_OBJECT_CAST_OBJ_WITH_IFINDEX(obj)->ifindex > 0); + + nm_assert(has_ifindex + == !(NM_IN_SET(NMP_OBJECT_GET_TYPE(obj), + NMP_OBJECT_TYPE_IP4_ROUTE, + NMP_OBJECT_TYPE_IP6_ROUTE) + && nm_platform_route_type_is_nodev(nm_platform_route_type_uncoerce( + NMP_OBJECT_CAST_IP_ROUTE(obj)->type_coerced)))); + + return !has_ifindex; +} + +/*****************************************************************************/ + +NMIPConfig * +nm_l3cfg_ipconfig_get(NML3Cfg *self, int addr_family) +{ + g_return_val_if_fail(NM_IS_L3CFG(self), NULL); + nm_assert_addr_family(addr_family); + + return self->priv.p->ipconfig_x[NM_IS_IPv4(addr_family)]; +} + +static void +_ipconfig_toggle_notify(gpointer data, GObject *object, gboolean is_last_ref) +{ + NML3Cfg *self = NM_L3CFG(data); + NMIPConfig *ipconfig = NM_IP_CONFIG(object); + + if (!is_last_ref) { + /* This happens while we take another ref below. Ignore the signal. */ + nm_assert(!NM_IN_SET(ipconfig, self->priv.p->ipconfig_4, self->priv.p->ipconfig_6)); + return; + } + + if (ipconfig == self->priv.p->ipconfig_4) + self->priv.p->ipconfig_4 = NULL; + else { + nm_assert(ipconfig == self->priv.p->ipconfig_6); + self->priv.p->ipconfig_6 = NULL; + } + + /* We take a second reference to keep the instance alive, while also removing the + * toggle ref. This will notify the function again, but we will ignore that. */ + g_object_ref(ipconfig); + + g_object_remove_toggle_ref(G_OBJECT(ipconfig), _ipconfig_toggle_notify, self); + + /* pass on the reference, and unexport on idle. */ + nm_ip_config_take_and_unexport_on_idle(g_steal_pointer(&ipconfig)); +} + +NMIPConfig * +nm_l3cfg_ipconfig_acquire(NML3Cfg *self, int addr_family) +{ + NMIPConfig *ipconfig; + + g_return_val_if_fail(NM_IS_L3CFG(self), NULL); + nm_assert_addr_family(addr_family); + + ipconfig = self->priv.p->ipconfig_x[NM_IS_IPv4(addr_family)]; + + if (ipconfig) + return g_object_ref(ipconfig); + + ipconfig = nm_ip_config_new(addr_family, self); + + self->priv.p->ipconfig_x[NM_IS_IPv4(addr_family)] = ipconfig; + + /* The ipconfig keeps self alive. We use a toggle reference + * to avoid a cycle. But we anyway wouldn't want a strong reference, + * because the user releases the instance by unrefing it, and we + * notice that via the weak reference. */ + g_object_add_toggle_ref(G_OBJECT(ipconfig), _ipconfig_toggle_notify, self); + + /* We keep the toggle reference, and return the other reference to the caller. */ + return g_steal_pointer(&ipconfig); +} + /*****************************************************************************/ gboolean @@ -415,13 +512,13 @@ nm_l3cfg_is_vrf(const NML3Cfg *self) static const char * _l3_config_notify_data_to_string(const NML3ConfigNotifyData *notify_data, - char * sbuf, + char *sbuf, gsize sbuf_size) { char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN]; char sbuf100[100]; char sbufobf[NM_HASH_OBFUSCATE_PTR_STR_BUF_SIZE]; - char * s = sbuf; + char *s = sbuf; gsize l = sbuf_size; in_addr_t addr4; @@ -509,7 +606,7 @@ _nm_l3cfg_emit_signal_notify_simple(NML3Cfg *self, NML3ConfigNotifyType notify_t } static void -_nm_l3cfg_emit_signal_notify_l3cd_changed(NML3Cfg * self, +_nm_l3cfg_emit_signal_notify_l3cd_changed(NML3Cfg *self, const NML3ConfigData *l3cd_old, const NML3ConfigData *l3cd_new, gboolean commited) @@ -538,7 +635,7 @@ _l3_changed_configs_set_dirty(NML3Cfg *self) /*****************************************************************************/ static void -_l3_acd_ipv4_addresses_on_link_update(NML3Cfg * self, +_l3_acd_ipv4_addresses_on_link_update(NML3Cfg *self, in_addr_t addr, gboolean add /* or else remove */) { @@ -596,7 +693,7 @@ static NAcdProbe * _nm_n_acd_data_probe_new(NML3Cfg *self, in_addr_t addr, guint32 timeout_msec, gpointer user_data) { nm_auto(n_acd_probe_config_freep) NAcdProbeConfig *probe_config = NULL; - NAcdProbe * probe; + NAcdProbe *probe; int r; nm_assert(self); @@ -628,7 +725,7 @@ _nm_n_acd_data_probe_new(NML3Cfg *self, in_addr_t addr, guint32 timeout_msec, gp G_STMT_START \ { \ if (NM_MORE_ASSERTS > 0) { \ - const NML3Cfg * _self = (self); \ + const NML3Cfg *_self = (self); \ const ObjStateData *_obj_state = (obj_state); \ \ nm_assert(_obj_state); \ @@ -866,7 +963,7 @@ _obj_states_update_all(NML3Cfg *self) for (i = 0; i < (int) G_N_ELEMENTS(obj_types); i++) { const NMPObjectType obj_type = obj_types[i]; NMDedupMultiIter o_iter; - const NMPObject * obj; + const NMPObject *obj; if (!self->priv.p->combined_l3cd_commited) continue; @@ -875,6 +972,11 @@ _obj_states_update_all(NML3Cfg *self) self->priv.p->combined_l3cd_commited, &obj, obj_type) { + if (_obj_is_route_nodev(obj)) { + /* this is a nodev route. We don't track an obj-state for this. */ + continue; + } + obj_state = g_hash_table_lookup(self->priv.p->obj_state_hash, &obj); if (!obj_state) { obj_state = @@ -926,21 +1028,16 @@ _obj_states_update_all(NML3Cfg *self) } typedef struct { - NML3Cfg * self; + NML3Cfg *self; NML3CfgCommitType commit_type; } ObjStatesSyncFilterData; static gboolean -_obj_states_sync_filter(/* const NMDedupMultiObj * */ gconstpointer o, gpointer user_data) +_obj_states_sync_filter(NML3Cfg *self, const NMPObject *obj, NML3CfgCommitType commit_type) { - char sbuf[sizeof(_nm_utils_to_string_buffer)]; - const NMPObject * obj = o; - const ObjStatesSyncFilterData *sync_filter_data = user_data; - NMPObjectType obj_type; - ObjStateData * obj_state; - - nm_assert(sync_filter_data); - nm_assert(NM_IS_L3CFG(sync_filter_data->self)); + char sbuf[sizeof(_nm_utils_to_string_buffer)]; + NMPObjectType obj_type; + ObjStateData *obj_state; obj_type = NMP_OBJECT_GET_TYPE(obj); @@ -948,22 +1045,19 @@ _obj_states_sync_filter(/* const NMDedupMultiObj * */ gconstpointer o, gpointer && NMP_OBJECT_CAST_IP4_ADDRESS(obj)->a_acd_not_ready) return FALSE; - obj_state = g_hash_table_lookup(sync_filter_data->self->priv.p->obj_state_hash, &obj); + obj_state = g_hash_table_lookup(self->priv.p->obj_state_hash, &obj); - nm_assert_obj_state(sync_filter_data->self, obj_state); + nm_assert_obj_state(self, obj_state); nm_assert(obj_state->obj == obj); nm_assert(c_list_is_empty(&obj_state->os_zombie_lst)); if (!obj_state->os_nm_configured) { - NML3Cfg *self; - - if (sync_filter_data->commit_type == NM_L3_CFG_COMMIT_TYPE_ASSUME + if (commit_type == NM_L3_CFG_COMMIT_TYPE_ASSUME && !_obj_state_data_get_assume_config_once(obj_state)) return FALSE; obj_state->os_nm_configured = TRUE; - self = sync_filter_data->self; _LOGD("obj-state: configure-first-time: %s", _obj_state_data_to_string(obj_state, sbuf, sizeof(sbuf))); return TRUE; @@ -975,14 +1069,80 @@ _obj_states_sync_filter(/* const NMDedupMultiObj * */ gconstpointer o, gpointer return TRUE; } - if (!obj_state->os_plobj && sync_filter_data->commit_type != NM_L3_CFG_COMMIT_TYPE_REAPPLY) + if (!obj_state->os_plobj && commit_type != NM_L3_CFG_COMMIT_TYPE_REAPPLY + && !nmp_object_get_force_commit(obj)) return FALSE; return TRUE; } +static gboolean +_obj_states_sync_filter_predicate(gconstpointer o, gpointer user_data) +{ + const NMPObject *obj = o; + const ObjStatesSyncFilterData *sync_filter_data = user_data; + + return _obj_states_sync_filter(sync_filter_data->self, obj, sync_filter_data->commit_type); +} + +static GPtrArray * +_commit_collect_addresses(NML3Cfg *self, int addr_family, NML3CfgCommitType commit_type) +{ + const int IS_IPv4 = NM_IS_IPv4(addr_family); + const NMDedupMultiHeadEntry *head_entry; + const ObjStatesSyncFilterData sync_filter_data = { + .self = self, + .commit_type = commit_type, + }; + + head_entry = nm_l3_config_data_lookup_objs(self->priv.p->combined_l3cd_commited, + NMP_OBJECT_TYPE_IP_ADDRESS(IS_IPv4)); + return nm_dedup_multi_objs_to_ptr_array_head(head_entry, + _obj_states_sync_filter_predicate, + (gpointer) &sync_filter_data); +} + +static void +_commit_collect_routes(NML3Cfg *self, + int addr_family, + NML3CfgCommitType commit_type, + GPtrArray **routes, + GPtrArray **routes_nodev) +{ + const int IS_IPv4 = NM_IS_IPv4(addr_family); + const NMDedupMultiHeadEntry *head_entry; + const NMDedupMultiEntry *entry; + + nm_assert(routes && !*routes); + nm_assert(routes_nodev && !*routes_nodev); + + head_entry = nm_l3_config_data_lookup_objs(self->priv.p->combined_l3cd_commited, + NMP_OBJECT_TYPE_IP_ROUTE(IS_IPv4)); + + if (!head_entry) + return; + + c_list_for_each_entry (entry, &head_entry->lst_entries_head, lst_entries) { + const NMPObject *obj = entry->obj; + GPtrArray **r; + + if (_obj_is_route_nodev(obj)) + r = routes_nodev; + else { + if (!_obj_states_sync_filter(self, obj, commit_type)) + continue; + r = routes; + } + + if (!*r) + *r = g_ptr_array_new_full(head_entry->len, (GDestroyNotify) nm_dedup_multi_obj_unref); + + g_ptr_array_add(*r, (gpointer) nmp_object_ref(obj)); + } +} + static void -_obj_state_zombie_lst_get_prune_lists(NML3Cfg * self, +_obj_state_zombie_lst_get_prune_lists(NML3Cfg *self, int addr_family, GPtrArray **out_addresses_prune, GPtrArray **out_routes_prune) @@ -991,8 +1151,8 @@ _obj_state_zombie_lst_get_prune_lists(NML3Cfg * self, const NMPObjectType obj_type_route = NMP_OBJECT_TYPE_IP_ROUTE(IS_IPv4); const NMPObjectType obj_type_address = NMP_OBJECT_TYPE_IP_ADDRESS(IS_IPv4); char sbuf[sizeof(_nm_utils_to_string_buffer)]; - ObjStateData * obj_state; - ObjStateData * obj_state_safe; + ObjStateData *obj_state; + ObjStateData *obj_state_safe; nm_assert(NM_IS_L3CFG(self)); nm_assert(out_addresses_prune && !*out_addresses_prune); @@ -1003,7 +1163,7 @@ _obj_state_zombie_lst_get_prune_lists(NML3Cfg * self, &self->priv.p->obj_state_zombie_lst_head, os_zombie_lst) { NMPObjectType obj_type; - GPtrArray ** p_a; + GPtrArray **p_a; nm_assert_obj_state(self, obj_state); nm_assert(obj_state->os_zombie_count > 0); @@ -1073,16 +1233,16 @@ static void _load_link(NML3Cfg *self, gboolean initial) { nm_auto_nmpobj const NMPObject *obj_old = NULL; - const NMPObject * obj; - const char * ifname; - const char * ifname_old; + const NMPObject *obj; + const char *ifname; + const char *ifname_old; gboolean nacd_changed; gboolean nacd_new_valid; gboolean nacd_old_valid; - const guint8 * nacd_old_addr = NULL; - const guint8 * nacd_new_addr = NULL; + const guint8 *nacd_old_addr = NULL; + const guint8 *nacd_new_addr = NULL; gboolean nacd_link_now_up; - AcdData * acd_data; + AcdData *acd_data; if (initial) { obj = nm_platform_link_get_obj(self->priv.platform, self->priv.ifindex, TRUE); @@ -1172,9 +1332,9 @@ _nm_l3cfg_notify_platform_change_on_idle(NML3Cfg *self, guint32 obj_type_flags) } void -_nm_l3cfg_notify_platform_change(NML3Cfg * self, +_nm_l3cfg_notify_platform_change(NML3Cfg *self, NMPlatformSignalChangeType change_type, - const NMPObject * obj) + const NMPObject *obj) { NML3ConfigNotifyData notify_data; NMPObjectType obj_type; @@ -1247,9 +1407,9 @@ _acd_data_free(AcdData *acd_data) } static guint -_acd_data_collect_tracks_data(const AcdData * acd_data, +_acd_data_collect_tracks_data(const AcdData *acd_data, NMTernary dirty_selector, - guint32 * out_best_acd_timeout_msec, + guint32 *out_best_acd_timeout_msec, NML3AcdDefendType *out_best_acd_defend_type) { NML3AcdDefendType best_acd_defend_type = _NM_L3_ACD_DEFEND_TYPE_NONE; @@ -1257,6 +1417,15 @@ _acd_data_collect_tracks_data(const AcdData * acd_data, guint n = 0; guint i; + /* We do a simple search over all track-infos for the best, which determines + * our ACD state. That is, we prefer ACD disabled, and otherwise the + * shortest configured timeout. + * + * This linear search is probably fast enough, because we expect that each + * address/acd_data has few trackers. + * The alternative would be caching the best result, but that is more complicated, + * so not done. */ + for (i = 0; i < acd_data->info.n_track_infos; i++) { const NML3AcdAddrTrackInfo *acd_track = &acd_data->info.track_infos[i]; @@ -1280,9 +1449,9 @@ _acd_data_collect_tracks_data(const AcdData * acd_data, } static NML3AcdAddrTrackInfo * -_acd_data_find_track(const AcdData * acd_data, +_acd_data_find_track(const AcdData *acd_data, const NML3ConfigData *l3cd, - const NMPObject * obj, + const NMPObject *obj, gconstpointer tag) { guint i; @@ -1301,11 +1470,11 @@ _acd_data_find_track(const AcdData * acd_data, static gboolean _acd_has_valid_link(const NMPObject *obj, - const guint8 ** out_addr_bin, - gboolean * out_acd_not_supported) + const guint8 **out_addr_bin, + gboolean *out_acd_not_supported) { const NMPlatformLink *link; - const guint8 * addr_bin; + const guint8 *addr_bin; gsize addr_len; if (!obj) { @@ -1360,8 +1529,8 @@ _l3_acd_nacd_event(int fd, GIOCondition condition, gpointer user_data) while (TRUE) { NMEtherAddr sender_addr_data; const NMEtherAddr *sender_addr; - AcdData * acd_data; - NAcdEvent * event; + AcdData *acd_data; + NAcdEvent *event; if (!self->priv.p->nacd) { /* In the loop we emit signals, where *anything* might happen. @@ -1440,12 +1609,7 @@ _l3_acd_nacd_event(int fd, GIOCondition condition, gpointer user_data) "in %u msec)", timeout_msec); self->priv.p->nacd_event_down_source = - nm_g_timeout_source_new(timeout_msec, - G_PRIORITY_DEFAULT, - _l3_acd_nacd_event_down_timeout_cb, - self, - NULL); - g_source_attach(self->priv.p->nacd_event_down_source, NULL); + nm_g_timeout_add_source(timeout_msec, _l3_acd_nacd_event_down_timeout_cb, self); } break; default: @@ -1494,6 +1658,7 @@ _l3_acd_nacd_instance_reset(NML3Cfg *self, NMTernary start_timer, gboolean acd_d } nm_clear_g_source_inst(&self->priv.p->nacd_source); nm_clear_g_source_inst(&self->priv.p->nacd_instance_ensure_retry); + nm_clear_g_source_inst(&self->priv.p->nacd_event_down_source); if (c_list_is_empty(&self->priv.p->acd_lst_head)) start_timer = NM_TERNARY_DEFAULT; @@ -1505,12 +1670,9 @@ _l3_acd_nacd_instance_reset(NML3Cfg *self, NMTernary start_timer, gboolean acd_d break; case NM_TERNARY_TRUE: self->priv.p->nacd_instance_ensure_retry = - nm_g_timeout_source_new_seconds(ACD_ENSURE_RATELIMIT_MSEC / 1000u, - G_PRIORITY_DEFAULT, + nm_g_timeout_add_seconds_source(ACD_ENSURE_RATELIMIT_MSEC / 1000u, _l3_acd_nacd_instance_ensure_retry_cb, - self, - NULL); - g_source_attach(self->priv.p->nacd_instance_ensure_retry, NULL); + self); break; case NM_TERNARY_DEFAULT: break; @@ -1534,8 +1696,8 @@ static NAcd * _l3_acd_nacd_instance_ensure(NML3Cfg *self, gboolean *out_acd_not_supported) { nm_auto(n_acd_config_freep) NAcdConfig *config = NULL; - nm_auto(n_acd_unrefp) NAcd * nacd = NULL; - const guint8 * addr_bin; + nm_auto(n_acd_unrefp) NAcd *nacd = NULL; + const guint8 *addr_bin; gboolean acd_not_supported; gboolean valid; int fd; @@ -1599,11 +1761,11 @@ failed_create_acd: } static NAcdProbe * -_l3_acd_nacd_instance_create_probe(NML3Cfg * self, +_l3_acd_nacd_instance_create_probe(NML3Cfg *self, in_addr_t addr, guint32 timeout_msec, gpointer user_data, - gboolean * out_acd_not_supported, + gboolean *out_acd_not_supported, const char **out_failure_reason) { gboolean acd_not_supported; @@ -1699,17 +1861,17 @@ _l3_acd_data_defendconflict_warning_ratelimited(AcdData *acd_data, gint64 *p_now } static void -_l3_acd_data_add(NML3Cfg * self, +_l3_acd_data_add(NML3Cfg *self, const NML3ConfigData *l3cd, - const NMPObject * obj, + const NMPObject *obj, gconstpointer tag, NML3AcdDefendType acd_defend_type, guint32 acd_timeout_msec) { in_addr_t addr = NMP_OBJECT_CAST_IP4_ADDRESS(obj)->address; NML3AcdAddrTrackInfo *acd_track; - AcdData * acd_data; - const char * track_mode; + AcdData *acd_data; + const char *track_mode; char sbuf100[100]; if (ACD_ADDR_SKIP(addr)) @@ -1795,7 +1957,7 @@ _l3_acd_data_add(NML3Cfg * self, } static void -_l3_acd_data_add_all(NML3Cfg * self, +_l3_acd_data_add_all(NML3Cfg *self, const L3ConfigData *const *infos, guint infos_len, gboolean reapply) @@ -1817,7 +1979,7 @@ _l3_acd_data_add_all(NML3Cfg * self, for (i_info = 0; i_info < infos_len; i_info++) { const L3ConfigData *info = infos[i_info]; NMDedupMultiIter iter; - const NMPObject * obj; + const NMPObject *obj; nm_l3_config_data_iter_obj_for_each (&iter, info->l3cd, &obj, NMP_OBJECT_TYPE_IP4_ADDRESS) { _l3_acd_data_add(self, @@ -1859,14 +2021,24 @@ _l3_acd_data_timeout_cb(gpointer user_data) static void _l3_acd_data_timeout_schedule(AcdData *acd_data, gint64 timeout_msec) { + /* in _l3_acd_data_state_set_full() we clear the timer. At the same time, + * in _l3_acd_data_state_change(ACD_STATE_CHANGE_MODE_TIMEOUT) we only + * expect timeouts in certain states. + * + * That means, scheduling a timeout is only correct if we are in a certain + * state, which allows to handle timeouts. This assert checks for that to + * ensure we don't call a timeout in an unexpected state. */ + nm_assert(NM_IN_SET(acd_data->info.state, + NM_L3_ACD_ADDR_STATE_PROBING, + NM_L3_ACD_ADDR_STATE_USED, + NM_L3_ACD_ADDR_STATE_DEFENDING, + NM_L3_ACD_ADDR_STATE_CONFLICT)); + nm_clear_g_source_inst(&acd_data->acd_data_timeout_source); acd_data->acd_data_timeout_source = - nm_g_timeout_source_new(NM_CLAMP((gint64) 0, timeout_msec, (gint64) G_MAXUINT), - G_PRIORITY_DEFAULT, + nm_g_timeout_add_source(NM_CLAMP((gint64) 0, timeout_msec, (gint64) G_MAXUINT), _l3_acd_data_timeout_cb, - acd_data, - NULL); - g_source_attach(acd_data->acd_data_timeout_source, NULL); + acd_data); } static void @@ -1899,7 +2071,7 @@ _nm_l3cfg_emit_signal_notify_acd_event(NML3Cfg *self, AcdData *acd_data) { gs_free NML3AcdAddrTrackInfo *track_infos_clone = NULL; NML3ConfigNotifyData notify_data; - NML3AcdAddrInfo * info; + NML3AcdAddrInfo *info; guint i; nm_assert(acd_data); @@ -1908,7 +2080,7 @@ _nm_l3cfg_emit_signal_notify_acd_event(NML3Cfg *self, AcdData *acd_data) notify_data.notify_type = NM_L3_CONFIG_NOTIFY_TYPE_ACD_EVENT; notify_data.acd_event = (typeof(notify_data.acd_event)){ - .info = acd_data->info, + .info = acd_data->info, }; /* we need to clone the track-data, because the callee is allowed to add/remove @@ -1952,7 +2124,7 @@ static void _nm_l3cfg_emit_signal_notify_acd_event_all(NML3Cfg *self) { gs_unref_object NML3Cfg *self_keep_alive = NULL; - AcdData * acd_data; + AcdData *acd_data; while ((acd_data = c_list_first_entry(&self->priv.p->acd_event_notify_lst_head, AcdData, @@ -1964,11 +2136,11 @@ _nm_l3cfg_emit_signal_notify_acd_event_all(NML3Cfg *self) } } -_nm_printf(5, 6) static void _l3_acd_data_state_set_full(NML3Cfg * self, - AcdData * acd_data, +_nm_printf(5, 6) static void _l3_acd_data_state_set_full(NML3Cfg *self, + AcdData *acd_data, NML3AcdAddrState state, gboolean allow_commit, - const char * format, + const char *format, ...) { NML3AcdAddrState old_state; @@ -1993,17 +2165,19 @@ _nm_printf(5, 6) static void _l3_acd_data_state_set_full(NML3Cfg * self, else changed = FALSE; - if (format) { - gs_free char *msg = NULL; - va_list args; + if (_LOGT_ENABLED()) { + if (format) { + gs_free char *msg = NULL; + va_list args; - va_start(args, format); - msg = g_strdup_vprintf(format, args); - va_end(args); + va_start(args, format); + msg = g_strdup_vprintf(format, args); + va_end(args); - _LOGT_acd(acd_data, "set state to %s (%s)", _l3_acd_addr_state_to_string(state), msg); - } else - _LOGT_acd(acd_data, "set state to %s", _l3_acd_addr_state_to_string(state)); + _LOGT_acd(acd_data, "set state to %s (%s)", _l3_acd_addr_state_to_string(state), msg); + } else + _LOGT_acd(acd_data, "set state to %s", _l3_acd_addr_state_to_string(state)); + } if (changed && allow_commit) { /* The availability of an address just changed (and we are instructed to @@ -2014,8 +2188,8 @@ _nm_printf(5, 6) static void _l3_acd_data_state_set_full(NML3Cfg * self, } static void -_l3_acd_data_state_set(NML3Cfg * self, - AcdData * acd_data, +_l3_acd_data_state_set(NML3Cfg *self, + AcdData *acd_data, NML3AcdAddrState state, gboolean allow_commit) { @@ -2023,17 +2197,17 @@ _l3_acd_data_state_set(NML3Cfg * self, } static void -_l3_acd_data_state_change(NML3Cfg * self, - AcdData * acd_data, +_l3_acd_data_state_change(NML3Cfg *self, + AcdData *acd_data, AcdStateChangeMode state_change_mode, const NMEtherAddr *sender_addr, - gint64 * p_now_msec) + gint64 *p_now_msec) { guint32 acd_timeout_msec; NML3AcdDefendType acd_defend_type; gint64 now_msec; - const char * log_reason; + const char *log_reason; char sbuf256[256]; char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN]; @@ -2260,22 +2434,7 @@ handle_init: /* we are already probing. There is nothing to do for this timeout. */ return; } - - nm_utils_get_monotonic_timestamp_msec_cached(p_now_msec); - - if (acd_data->probing_timestamp_msec + ACD_WAIT_PROBING_EXTRA_TIME_MSEC - + ACD_WAIT_PROBING_EXTRA_TIME2_MSEC - >= (*p_now_msec)) { - /* hm. We failed to create a new probe too long. Something is really wrong - * internally, but let's ignore the issue and assume the address is good. What - * else would we do? Assume the address is USED? */ - _LOGT_acd(acd_data, - "probe-good (waiting for creating probe timed out. Assume good)"); - goto handle_start_defending; - } - - log_reason = "retry probing on timeout"; - goto handle_start_probing; + /* fall-through */ case NM_L3_ACD_ADDR_STATE_USED: case NM_L3_ACD_ADDR_STATE_CONFLICT: @@ -2295,7 +2454,10 @@ handle_init: acd_data->acd_defend_type_desired = acd_defend_type; if (acd_timeout_msec <= 0) { - log_reason = "acd disabled by configuration (restart after previous conflict)"; + if (acd_data->info.state == NM_L3_ACD_ADDR_STATE_PROBING) + log_reason = "acd disabled by configuration (timeout during probing)"; + else + log_reason = "acd disabled by configuration (restart after previous conflict)"; goto handle_probing_done; } @@ -2305,6 +2467,23 @@ handle_init: } nm_utils_get_monotonic_timestamp_msec_cached(p_now_msec); + + if (acd_data->info.state == NM_L3_ACD_ADDR_STATE_PROBING) { + if ((*p_now_msec) > acd_data->probing_timestamp_msec + + ACD_WAIT_PROBING_EXTRA_TIME_MSEC + + ACD_WAIT_PROBING_EXTRA_TIME2_MSEC) { + /* hm. We failed to create a new probe too long. Something is really wrong + * internally, but let's ignore the issue and assume the address is good. What + * else would we do? Assume the address is USED? */ + _LOGT_acd(acd_data, + "probe-good (waiting for creating probe timed out. Assume good)"); + goto handle_start_defending; + } + + log_reason = "retry probing on timeout"; + goto handle_start_probing; + } + acd_data->probing_timestamp_msec = (*p_now_msec); acd_data->probing_timeout_msec = acd_timeout_msec; if (acd_data->info.state == NM_L3_ACD_ADDR_STATE_USED) @@ -2525,40 +2704,23 @@ handle_init: return; case ACD_STATE_CHANGE_MODE_INSTANCE_RESET: + nm_assert(NM_IN_SET(acd_data->info.state, + NM_L3_ACD_ADDR_STATE_PROBING, + NM_L3_ACD_ADDR_STATE_DEFENDING, + NM_L3_ACD_ADDR_STATE_READY, + NM_L3_ACD_ADDR_STATE_USED, + NM_L3_ACD_ADDR_STATE_CONFLICT, + NM_L3_ACD_ADDR_STATE_EXTERNAL_REMOVED)); - switch (acd_data->info.state) { - case NM_L3_ACD_ADDR_STATE_INIT: - nm_assert_not_reached(); - return; - case NM_L3_ACD_ADDR_STATE_PROBING: - case NM_L3_ACD_ADDR_STATE_DEFENDING: - - if (!acd_data->nacd_probe) { - /* we failed starting to probe before and have a timer running to - * restart. We don't do anything now, but let the timer handle it. - * This also implements some rate limiting for us. */ - _LOGT_acd(acd_data, - "n-acd instance reset. Ignore event while restarting %s", - (acd_data->info.state == NM_L3_ACD_ADDR_STATE_PROBING) ? "probing" - : "defending"); - return; - } - - _LOGT_acd(acd_data, - "n-acd instance reset. Trigger a restart of the %s", - (acd_data->info.state == NM_L3_ACD_ADDR_STATE_PROBING) ? "probing" - : "defending"); - acd_data->nacd_probe = n_acd_probe_free(acd_data->nacd_probe); - _l3_acd_data_timeout_schedule(acd_data, 0); - return; - case NM_L3_ACD_ADDR_STATE_READY: - case NM_L3_ACD_ADDR_STATE_USED: - case NM_L3_ACD_ADDR_STATE_CONFLICT: - case NM_L3_ACD_ADDR_STATE_EXTERNAL_REMOVED: - nm_assert(!acd_data->nacd_probe); - return; - } - nm_assert_not_reached(); + /* an instance-reset is a dramatic event. We start over with probing. */ + _LOGT_acd(acd_data, + "n-acd instance reset. Reset to probing while in state %s", + _l3_acd_addr_state_to_string(acd_data->info.state)); + acd_data->nacd_probe = n_acd_probe_free(acd_data->nacd_probe); + acd_data->last_defendconflict_timestamp_msec = 0; + acd_data->probing_timestamp_msec = nm_utils_get_monotonic_timestamp_msec_cached(p_now_msec); + _l3_acd_data_state_set(self, acd_data, NM_L3_ACD_ADDR_STATE_PROBING, FALSE); + _l3_acd_data_timeout_schedule(acd_data, 0); return; } @@ -2569,7 +2731,7 @@ handle_start_probing: if (TRUE) { const NML3AcdAddrState orig_state = acd_data->info.state; nm_auto(n_acd_probe_freep) NAcdProbe *probe = NULL; - const char * failure_reason; + const char *failure_reason; gboolean acd_not_supported; nm_assert(NM_IN_SET(acd_data->info.state, @@ -2646,10 +2808,10 @@ handle_probing_done: goto handle_start_defending; case NM_L3_ACD_ADDR_STATE_READY: case NM_L3_ACD_ADDR_STATE_DEFENDING: + case NM_L3_ACD_ADDR_STATE_EXTERNAL_REMOVED: goto handle_start_defending; case NM_L3_ACD_ADDR_STATE_CONFLICT: return; - case NM_L3_ACD_ADDR_STATE_EXTERNAL_REMOVED: nm_assert_not_reached(); return; } @@ -2689,7 +2851,7 @@ handle_start_defending: if (!acd_data->nacd_probe) { const char *failure_reason; - NAcdProbe * probe; + NAcdProbe *probe; if (acd_data->acd_data_timeout_source) { /* we already failed to create a probe. We are ratelimited to retry, but @@ -2786,11 +2948,11 @@ nm_l3cfg_get_acd_addr_info(NML3Cfg *self, in_addr_t addr) /*****************************************************************************/ gboolean -nm_l3cfg_check_ready(NML3Cfg * self, - const NML3ConfigData * l3cd, +nm_l3cfg_check_ready(NML3Cfg *self, + const NML3ConfigData *l3cd, int addr_family, NML3CfgCheckReadyFlags flags, - gboolean * acd_used) + gboolean *acd_used) { NMDedupMultiIter iter; const NMPObject *obj; @@ -2869,7 +3031,7 @@ static gboolean _l3_commit_on_idle_cb(gpointer user_data) { _nm_unused gs_unref_object NML3Cfg *self_keep_alive = NULL; - NML3Cfg * self = user_data; + NML3Cfg *self = user_data; NML3CfgCommitType commit_type; commit_type = self->priv.p->commit_on_idle_type; @@ -2948,7 +3110,7 @@ nm_l3cfg_commit_on_idle_is_scheduled(NML3Cfg *self) (&g_array_index((l3_config_datas), L3ConfigData, (idx))) static gssize -_l3_config_datas_find_next(GArray * l3_config_datas, +_l3_config_datas_find_next(GArray *l3_config_datas, guint start_idx, gconstpointer needle_tag, const NML3ConfigData *needle_l3cd) @@ -2978,9 +3140,9 @@ _l3_config_datas_get_sorted_cmp(gconstpointer p_a, gconstpointer p_b, gpointer u nm_assert(b); nm_assert(nm_l3_config_data_get_ifindex(a->l3cd) == nm_l3_config_data_get_ifindex(b->l3cd)); - /* we sort the entries with higher priority (more important, lower numerical value) + /* we sort the entries with higher priority (higher numerical value, more important) * first. */ - NM_CMP_FIELD(a, b, priority_confdata); + NM_CMP_FIELD(b, a, priority_confdata); /* if the priority is not unique, we sort them in the order they were added, * with the oldest first (lower numerical value). */ @@ -3028,8 +3190,16 @@ nm_l3cfg_mark_config_dirty(NML3Cfg *self, gconstpointer tag, gboolean dirty) } } +/* + * nm_l3cfg_add_config: + * @priority: all l3cd get merged/combined. This merging requires that some + * l3cd are more important than others. For example, coming from static IP + * configuration needs to take precedence over DHCP. The @priority determines + * the order in which l3cds get merged (and thus the outcome). Higher numbers + * mean more important!! + */ gboolean -nm_l3cfg_add_config(NML3Cfg * self, +nm_l3cfg_add_config(NML3Cfg *self, gconstpointer tag, gboolean replace_same_tag, const NML3ConfigData *l3cd, @@ -3123,7 +3293,8 @@ nm_l3cfg_add_config(NML3Cfg * self, .acd_timeout_msec_confdata = acd_timeout_msec, .priority_confdata = priority, .pseudo_timestamp_confdata = ++self->priv.p->pseudo_timestamp_counter, - .dirty_confdata = FALSE, + .force_commit_once = NM_FLAGS_HAS(config_flags, NM_L3CFG_CONFIG_FLAGS_FORCE_ONCE), + .dirty_confdata = FALSE, }; changed = TRUE; } else { @@ -3194,7 +3365,7 @@ nm_l3cfg_add_config(NML3Cfg * self, } static gboolean -_l3cfg_remove_config(NML3Cfg * self, +_l3cfg_remove_config(NML3Cfg *self, gconstpointer tag, gboolean only_dirty, const NML3ConfigData *l3cd) @@ -3263,22 +3434,70 @@ nm_l3cfg_remove_config_all_dirty(NML3Cfg *self, gconstpointer tag) /*****************************************************************************/ +#define _NODEV_ROUTES_TAG(self, IS_IPv4) ((gconstpointer) (&(&(self)->priv.route_manager)[IS_IPv4])) + +static gboolean +_nodev_routes_untrack(NML3Cfg *self, int addr_family) +{ + return nmp_route_manager_untrack_all(self->priv.route_manager, + _NODEV_ROUTES_TAG(self, NM_IS_IPv4(addr_family)), + FALSE, + TRUE); +} + +static void +_nodev_routes_sync(NML3Cfg *self, + int addr_family, + NML3CfgCommitType commit_type, + GPtrArray *routes_nodev) +{ + const int IS_IPv4 = NM_IS_IPv4(addr_family); + const NMPObjectType obj_type = NMP_OBJECT_TYPE_IP_ROUTE(IS_IPv4); + guint i; + gboolean changed = FALSE; + + if (!routes_nodev) + goto out_clear; + + for (i = 0; i < routes_nodev->len; i++) { + const NMPObject *obj = routes_nodev->pdata[i]; + + if (nmp_route_manager_track(self->priv.route_manager, + obj_type, + NMP_OBJECT_CAST_IP_ROUTE(obj), + 1, + _NODEV_ROUTES_TAG(self, IS_IPv4), + NULL)) + changed = TRUE; + } + +out_clear: + if (_nodev_routes_untrack(self, addr_family)) + changed = TRUE; + + if (changed || commit_type >= NM_L3_CFG_COMMIT_TYPE_REAPPLY) + nmp_route_manager_sync(self->priv.route_manager, NMP_OBJECT_TYPE_IP_ROUTE(IS_IPv4), FALSE); +} + +/*****************************************************************************/ + typedef struct { - NML3Cfg * self; + NML3Cfg *self; gconstpointer tag; bool assume_config_once; bool to_commit; + bool force_commit_once; } L3ConfigMergeHookAddObjData; static gboolean -_l3_hook_add_obj_cb(const NML3ConfigData * l3cd, - const NMPObject * obj, +_l3_hook_add_obj_cb(const NML3ConfigData *l3cd, + const NMPObject *obj, NML3ConfigMergeHookResult *hook_result, gpointer user_data) { const L3ConfigMergeHookAddObjData *hook_data = user_data; - NML3Cfg * self = hook_data->self; - AcdData * acd_data; + NML3Cfg *self = hook_data->self; + AcdData *acd_data; in_addr_t addr; gboolean acd_bad = FALSE; @@ -3286,8 +3505,10 @@ _l3_hook_add_obj_cb(const NML3ConfigData * l3cd, nm_assert(hook_result); nm_assert(hook_result->ip4acd_not_ready == NM_OPTION_BOOL_DEFAULT); nm_assert(hook_result->assume_config_once == NM_OPTION_BOOL_DEFAULT); + nm_assert(hook_result->force_commit == NM_OPTION_BOOL_DEFAULT); hook_result->assume_config_once = hook_data->assume_config_once; + hook_result->force_commit = hook_data->force_commit_once; switch (NMP_OBJECT_GET_TYPE(obj)) { case NMP_OBJECT_TYPE_IP4_ADDRESS: @@ -3327,7 +3548,8 @@ _l3_hook_add_obj_cb(const NML3ConfigData * l3cd, if (!NM_IN_SET(acd_data->info.state, NM_L3_ACD_ADDR_STATE_READY, - NM_L3_ACD_ADDR_STATE_DEFENDING)) { + NM_L3_ACD_ADDR_STATE_DEFENDING, + NM_L3_ACD_ADDR_STATE_EXTERNAL_REMOVED)) { acd_bad = TRUE; goto out_ip4_address; } @@ -3347,21 +3569,21 @@ out_ip4_address: } static void -_l3cfg_update_combined_config(NML3Cfg * self, +_l3cfg_update_combined_config(NML3Cfg *self, gboolean to_commit, gboolean reapply, const NML3ConfigData **out_old /* transfer reference */, - gboolean * out_changed_combined_l3cd) + gboolean *out_changed_combined_l3cd) { - nm_auto_unref_l3cd const NML3ConfigData *l3cd_commited_old = NULL; - nm_auto_unref_l3cd const NML3ConfigData *l3cd_old = NULL; - nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; - gs_free const L3ConfigData **l3_config_datas_free = NULL; - const L3ConfigData ** l3_config_datas_arr; - guint l3_config_datas_len; - guint i; - gboolean merged_changed = FALSE; - gboolean commited_changed = FALSE; + nm_auto_unref_l3cd const NML3ConfigData *l3cd_commited_old = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd_old = NULL; + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + gs_free const L3ConfigData **l3_config_datas_free = NULL; + const L3ConfigData **l3_config_datas_arr; + guint l3_config_datas_len; + guint i; + gboolean merged_changed = FALSE; + gboolean commited_changed = FALSE; nm_assert(NM_IS_L3CFG(self)); nm_assert(!out_old || !*out_old); @@ -3388,6 +3610,20 @@ _l3cfg_update_combined_config(NML3Cfg * self, l3_config_datas_arr[i] = _l3_config_datas_at(self->priv.p->l3_config_datas, i); if (l3_config_datas_len > 1) { + /* We are about to merge the l3cds. The order in which we do that matters. + * + * Below, we iterate over the l3cds and merge them into a new one. nm_l3_config_data_merge() + * uses "NM_L3_CONFIG_ADD_FLAGS_EXCLUSIVE" flag, which means to keep the first entry. + * + * Consider for example addresses/routes, which have a set of ID attributes (based on + * which no duplicates can be accepted) and additional attributes. For example, trying + * to add the same address twice ("same" according to their ID), only one can be added. + * If they differ in their lifetimes, we need to make a choice. + * We could merge the attributes in a sensible way. Instead, NM_L3_CONFIG_ADD_FLAGS_EXCLUSIVE + * takes care to only take the first one. + * + * So we want to sort the more important entries *first*, and this is based on + * the priority_confdata. */ g_qsort_with_data(l3_config_datas_arr, l3_config_datas_len, sizeof(l3_config_datas_arr[0]), @@ -3417,12 +3653,21 @@ _l3cfg_update_combined_config(NML3Cfg * self, for (i = 0; i < l3_config_datas_len; i++) { const L3ConfigData *l3cd_data = l3_config_datas_arr[i]; + /* more important entries must be sorted *first*. */ + nm_assert( + i == 0 + || (l3_config_datas_arr[i - 1]->priority_confdata > l3cd_data->priority_confdata) + || (l3_config_datas_arr[i - 1]->priority_confdata == l3cd_data->priority_confdata + && l3_config_datas_arr[i - 1]->pseudo_timestamp_confdata + < l3cd_data->pseudo_timestamp_confdata)); + if (NM_FLAGS_HAS(l3cd_data->config_flags, NM_L3CFG_CONFIG_FLAGS_ONLY_FOR_ACD)) continue; hook_data.tag = l3cd_data->tag_confdata; hook_data.assume_config_once = NM_FLAGS_HAS(l3cd_data->config_flags, NM_L3CFG_CONFIG_FLAGS_ASSUME_CONFIG_ONCE); + hook_data.force_commit_once = l3cd_data->force_commit_once; nm_l3_config_data_merge(l3cd, l3cd_data->l3cd, @@ -3448,6 +3693,7 @@ _l3cfg_update_combined_config(NML3Cfg * self, IS_IPv4 ? AF_INET : AF_INET6, l3cd_data->default_route_table_x[IS_IPv4], l3cd_data->default_route_metric_x[IS_IPv4], + l3cd_data->force_commit_once, l3cd_data->l3cd); } } @@ -3524,7 +3770,7 @@ out: static gboolean _routes_temporary_not_available_timeout(gpointer user_data) { - NML3Cfg * self = NM_L3CFG(user_data); + NML3Cfg *self = NM_L3CFG(user_data); ObjStateData *obj_state; gint64 now_msec; gint64 expiry_msec; @@ -3563,12 +3809,12 @@ _routes_temporary_not_available_timeout(gpointer user_data) } static gboolean -_routes_temporary_not_available_update(NML3Cfg * self, +_routes_temporary_not_available_update(NML3Cfg *self, int addr_family, GPtrArray *routes_temporary_not_available_arr) { - ObjStateData * obj_state; - ObjStateData * obj_state_safe; + ObjStateData *obj_state; + ObjStateData *obj_state_safe; gint64 now_msec; gboolean prune_all = FALSE; gboolean success = TRUE; @@ -3673,6 +3919,7 @@ out_prune: } /*****************************************************************************/ + static const char * ip6_privacy_to_str(NMSettingIP6ConfigPrivacy ip6_privacy) { @@ -3699,7 +3946,7 @@ _l3_commit_ndisc_params(NML3Cfg *self, NML3CfgCommitType commit_type) guint32 reachable = 0; guint32 retrans = 0; int hop_limit = 0; - const char * ifname; + const char *ifname; if (commit_type < NM_L3_CFG_COMMIT_TYPE_UPDATE) { self->priv.p->ndisc_reachable_time_msec_set = FALSE; @@ -3757,7 +4004,7 @@ _l3_commit_ip6_privacy(NML3Cfg *self, NML3CfgCommitType commit_type) { NMSettingIP6ConfigPrivacy ip6_privacy; NMSettingIP6ConfigPrivacy ip6_privacy_set_before; - const char * ifname; + const char *ifname; if (commit_type < NM_L3_CFG_COMMIT_TYPE_UPDATE) ip6_privacy = NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN; @@ -3861,16 +4108,79 @@ set: ip6_privacy_to_str(ip6_privacy)); } +static void +_l3_commit_ip6_token(NML3Cfg *self, NML3CfgCommitType commit_type) +{ + NMUtilsIPv6IfaceId token; + const NMPlatformLink *pllink; + int val; + + if (commit_type < NM_L3_CFG_COMMIT_TYPE_UPDATE || !self->priv.p->combined_l3cd_commited) + token.id = 0; + else + token = nm_l3_config_data_get_ip6_token(self->priv.p->combined_l3cd_commited); + + pllink = nm_l3cfg_get_pllink(self, TRUE); + if (!pllink || pllink->inet6_token.id == token.id) + return; + + if (_LOGT_ENABLED()) { + struct in6_addr addr = {}; + struct in6_addr addr_old = {}; + char addr_str[INET6_ADDRSTRLEN]; + char addr_str_old[INET6_ADDRSTRLEN]; + + nm_utils_ipv6_addr_set_interface_identifier(&addr, &token); + nm_utils_ipv6_addr_set_interface_identifier(&addr_old, &pllink->inet6_token); + + _LOGT("commit-ip6-token: set value %s (was %s)", + inet_ntop(AF_INET6, &addr, addr_str, INET6_ADDRSTRLEN), + inet_ntop(AF_INET6, &addr_old, addr_str_old, INET6_ADDRSTRLEN)); + } + + /* The kernel allows setting a token only when 'accept_ra' + * is 1: temporarily flip it if necessary; unfortunately + * this will also generate an additional Router Solicitation + * from kernel. */ + val = nm_platform_sysctl_ip_conf_get_int_checked(self->priv.platform, + AF_INET6, + pllink->name, + "accept_ra", + 10, + G_MININT32, + G_MAXINT32, + 1); + + if (val != 1) { + nm_platform_sysctl_ip_conf_set(self->priv.platform, + AF_INET6, + pllink->name, + "accept_ra", + "1"); + } + + nm_platform_link_set_ipv6_token(self->priv.platform, self->priv.ifindex, &token); + + if (val != 1) { + nm_platform_sysctl_ip_conf_set_int64(self->priv.platform, + AF_INET6, + pllink->name, + "accept_ra", + val); + } +} + static gboolean -_l3_commit_one(NML3Cfg * self, +_l3_commit_one(NML3Cfg *self, int addr_family, NML3CfgCommitType commit_type, gboolean changed_combined_l3cd, const NML3ConfigData *l3cd_old) { - const int IS_IPv4 = NM_IS_IPv4(addr_family); + const int IS_IPv4 = NM_IS_IPv4(addr_family); gs_unref_ptrarray GPtrArray *addresses = NULL; gs_unref_ptrarray GPtrArray *routes = NULL; + gs_unref_ptrarray GPtrArray *routes_nodev = NULL; gs_unref_ptrarray GPtrArray *addresses_prune = NULL; gs_unref_ptrarray GPtrArray *routes_prune = NULL; gs_unref_ptrarray GPtrArray *routes_temporary_not_available_arr = NULL; @@ -3892,23 +4202,9 @@ _l3_commit_one(NML3Cfg * self, _l3_cfg_commit_type_to_string(commit_type, sbuf_commit_type, sizeof(sbuf_commit_type))); if (self->priv.p->combined_l3cd_commited) { - const NMDedupMultiHeadEntry * head_entry; - const ObjStatesSyncFilterData sync_filter_data = { - .self = self, - .commit_type = commit_type, - }; - - head_entry = nm_l3_config_data_lookup_objs(self->priv.p->combined_l3cd_commited, - NMP_OBJECT_TYPE_IP_ADDRESS(IS_IPv4)); - addresses = nm_dedup_multi_objs_to_ptr_array_head(head_entry, - _obj_states_sync_filter, - (gpointer) &sync_filter_data); + addresses = _commit_collect_addresses(self, addr_family, commit_type); - head_entry = nm_l3_config_data_lookup_objs(self->priv.p->combined_l3cd_commited, - NMP_OBJECT_TYPE_IP_ROUTE(IS_IPv4)); - routes = nm_dedup_multi_objs_to_ptr_array_head(head_entry, - _obj_states_sync_filter, - (gpointer) &sync_filter_data); + _commit_collect_routes(self, addr_family, commit_type, &routes, &routes_nodev); route_table_sync = nm_l3_config_data_get_route_table_sync(self->priv.p->combined_l3cd_commited, @@ -3918,10 +4214,11 @@ _l3_commit_one(NML3Cfg * self, if (!IS_IPv4) { _l3_commit_ip6_privacy(self, commit_type); _l3_commit_ndisc_params(self, commit_type); + _l3_commit_ip6_token(self, commit_type); } if (route_table_sync == NM_IP_ROUTE_TABLE_SYNC_MODE_NONE) - route_table_sync = NM_IP_ROUTE_TABLE_SYNC_MODE_ALL; + route_table_sync = NM_IP_ROUTE_TABLE_SYNC_MODE_MAIN; if (commit_type == NM_L3_CFG_COMMIT_TYPE_REAPPLY) { addresses_prune = nm_platform_ip_address_get_prune_list(self->priv.platform, @@ -3945,6 +4242,8 @@ _l3_commit_one(NML3Cfg * self, addresses, addresses_prune); + _nodev_routes_sync(self, addr_family, commit_type, routes_nodev); + if (!nm_platform_ip_route_sync(self->priv.platform, addr_family, self->priv.ifindex, @@ -3968,13 +4267,14 @@ _l3_commit_one(NML3Cfg * self, static void _l3_commit(NML3Cfg *self, NML3CfgCommitType commit_type, gboolean is_idle) { - _nm_unused gs_unref_object NML3Cfg *self_keep_alive = NULL; - nm_auto_unref_l3cd const NML3ConfigData *l3cd_old = NULL; + _nm_unused gs_unref_object NML3Cfg *self_keep_alive = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd_old = NULL; NML3CfgCommitType commit_type_auto; gboolean commit_type_from_auto = FALSE; gboolean is_sticky_update = FALSE; char sbuf_ct[30]; gboolean changed_combined_l3cd; + guint i; g_return_if_fail(NM_IS_L3CFG(self)); nm_assert(NM_IN_SET(commit_type, @@ -4038,6 +4338,15 @@ _l3_commit(NML3Cfg *self, NML3CfgCommitType commit_type, gboolean is_idle) _l3_acd_data_process_changes(self); + if (self->priv.p->l3_config_datas) { + for (i = 0; i < self->priv.p->l3_config_datas->len; i++) { + L3ConfigData *l3_config_data = _l3_config_datas_at(self->priv.p->l3_config_datas, i); + + if (l3_config_data->force_commit_once) + l3_config_data->force_commit_once = FALSE; + } + } + nm_assert(self->priv.p->commit_reentrant_count == 1); self->priv.p->commit_reentrant_count--; @@ -4083,10 +4392,10 @@ nm_l3cfg_commit_type_get(NML3Cfg *self) * is %NM_L3_CFG_COMMIT_TYPE_NONE. */ NML3CfgCommitTypeHandle * -nm_l3cfg_commit_type_register(NML3Cfg * self, +nm_l3cfg_commit_type_register(NML3Cfg *self, NML3CfgCommitType commit_type, NML3CfgCommitTypeHandle *existing_handle, - const char * source) + const char *source) { NML3CfgCommitTypeHandle *handle; NML3CfgCommitTypeHandle *h; @@ -4170,6 +4479,20 @@ nm_l3cfg_commit_type_unregister(NML3Cfg *self, NML3CfgCommitTypeHandle *handle) nm_g_slice_free(handle); } +void +nm_l3cfg_commit_type_reset_update(NML3Cfg *self) +{ + NML3CfgCommitTypeHandle *h; + + c_list_for_each_entry (h, &self->priv.p->commit_type_lst_head, commit_type_lst) { + if (h->commit_type >= NM_L3_CFG_COMMIT_TYPE_UPDATE) { + return; + } + } + + self->priv.p->commit_type_update_sticky = FALSE; +} + /*****************************************************************************/ const NML3ConfigData * @@ -4202,7 +4525,7 @@ gboolean nm_l3cfg_has_commited_ip6_addresses_pending_dad(NML3Cfg *self) { const NML3ConfigData *l3cd; - const NMPObject * plat_obj; + const NMPObject *plat_obj; NMPLookup plat_lookup; NMDedupMultiIter iter; @@ -4224,7 +4547,7 @@ nm_l3cfg_has_commited_ip6_addresses_pending_dad(NML3Cfg *self) nm_platform_iter_obj_for_each (&iter, self->priv.platform, &plat_lookup, &plat_obj) { const NMPlatformIP6Address *plat_addr = NMP_OBJECT_CAST_IP6_ADDRESS(plat_obj); - const NMDedupMultiEntry * l3cd_entry; + const NMDedupMultiEntry *l3cd_entry; if (!NM_FLAGS_HAS(plat_addr->n_ifa_flags, IFA_F_TENTATIVE) || NM_FLAGS_ANY(plat_addr->n_ifa_flags, IFA_F_DADFAILED | IFA_F_OPTIMISTIC)) @@ -4355,6 +4678,8 @@ constructed(GObject *object) self->priv.platform = g_object_ref(nm_netns_get_platform(self->priv.netns)); nm_assert(NM_IS_PLATFORM(self->priv.platform)); + self->priv.route_manager = nmp_route_manager_ref(nm_netns_get_route_manager(self->priv.netns)); + _LOGT("created (netns=" NM_HASH_OBFUSCATE_PTR_FMT ")", NM_HASH_OBFUSCATE_PTR(self->priv.netns)); G_OBJECT_CLASS(nm_l3cfg_parent_class)->constructed(object); @@ -4376,6 +4701,9 @@ finalize(GObject *object) { NML3Cfg *self = NM_L3CFG(object); + nm_assert(!self->priv.p->ipconfig_4); + nm_assert(!self->priv.p->ipconfig_6); + nm_assert(!self->priv.p->l3_config_datas); nm_assert(!self->priv.p->ipv4ll); @@ -4393,6 +4721,7 @@ finalize(GObject *object) nm_clear_pointer(&self->priv.p->nacd, n_acd_unref); nm_clear_g_source_inst(&self->priv.p->nacd_source); nm_clear_g_source_inst(&self->priv.p->nacd_instance_ensure_retry); + nm_clear_g_source_inst(&self->priv.p->nacd_event_down_source); nm_clear_g_source_inst(&self->priv.p->obj_state_temporary_not_available_timeout_source); @@ -4401,8 +4730,14 @@ finalize(GObject *object) nm_assert(c_list_is_empty(&self->priv.p->obj_state_temporary_not_available_lst_head)); nm_assert(c_list_is_empty(&self->priv.p->obj_state_zombie_lst_head)); + if (_nodev_routes_untrack(self, AF_INET)) + nmp_route_manager_sync(self->priv.route_manager, NMP_OBJECT_TYPE_IP4_ROUTE, FALSE); + if (_nodev_routes_untrack(self, AF_INET6)) + nmp_route_manager_sync(self->priv.route_manager, NMP_OBJECT_TYPE_IP6_ROUTE, FALSE); + g_clear_object(&self->priv.netns); g_clear_object(&self->priv.platform); + nm_clear_pointer(&self->priv.route_manager, nmp_route_manager_unref); nm_clear_l3cd(&self->priv.p->combined_l3cd_merged); nm_clear_l3cd(&self->priv.p->combined_l3cd_commited); diff --git a/src/core/nm-l3cfg.h b/src/core/nm-l3cfg.h index 19dec118..7dc9facc 100644 --- a/src/core/nm-l3cfg.h +++ b/src/core/nm-l3cfg.h @@ -7,7 +7,8 @@ #include "nm-l3-config-data.h" #define NM_L3CFG_CONFIG_PRIORITY_IPV4LL 0 -#define NM_L3CFG_CONFIG_PRIORITY_IPV6LL 0 +#define NM_L3CFG_CONFIG_PRIORITY_IPV6LL 1 +#define NM_L3CFG_CONFIG_PRIORITY_VPN 9 #define NM_ACD_TIMEOUT_RFC5227_MSEC 9000u #define NM_TYPE_L3CFG (nm_l3cfg_get_type()) @@ -53,11 +54,15 @@ typedef enum _nm_packed { * "don't change" behavior. At least once. If the address/route * is still not (no longer) configured on the subsequent * commit, it's not getting added again. + * @NM_L3CFG_CONFIG_FLAGS_FORCE_ONCE: if set, objects in the + * NML3ConfigData are committed to platform even if they were + * removed externally. */ typedef enum _nm_packed { NM_L3CFG_CONFIG_FLAGS_NONE = 0, NM_L3CFG_CONFIG_FLAGS_ONLY_FOR_ACD = (1LL << 0), NM_L3CFG_CONFIG_FLAGS_ASSUME_CONFIG_ONCE = (1LL << 1), + NM_L3CFG_CONFIG_FLAGS_FORCE_ONCE = (1LL << 2), } NML3CfgConfigFlags; typedef enum _nm_packed { @@ -71,7 +76,7 @@ typedef enum _nm_packed { } NML3AcdAddrState; typedef struct { - const NMPObject * obj; + const NMPObject *obj; const NML3ConfigData *l3cd; gconstpointer tag; @@ -88,15 +93,15 @@ typedef struct { in_addr_t addr; guint n_track_infos; NML3AcdAddrState state; - NML3Cfg * l3cfg; + NML3Cfg *l3cfg; const NML3AcdAddrTrackInfo *track_infos; } NML3AcdAddrInfo; static inline const NML3AcdAddrTrackInfo * nm_l3_acd_addr_info_find_track_info(const NML3AcdAddrInfo *addr_info, gconstpointer tag, - const NML3ConfigData * l3cd, - const NMPObject * obj) + const NML3ConfigData *l3cd, + const NMPObject *obj) { guint i; const NML3AcdAddrTrackInfo *ti; @@ -175,7 +180,7 @@ typedef struct { } acd_event; struct { - const NMPObject * obj; + const NMPObject *obj; NMPlatformSignalChangeType change_type; } platform_change; @@ -190,16 +195,18 @@ typedef struct { } NML3ConfigNotifyData; struct _NML3CfgPrivate; +struct _NMPRouteManager; struct _NML3Cfg { GObject parent; struct { - struct _NML3CfgPrivate *p; - NMNetns * netns; - NMPlatform * platform; - const NMPObject * plobj; - const NMPObject * plobj_next; - int ifindex; + struct _NML3CfgPrivate *p; + NMNetns *netns; + NMPlatform *platform; + struct _NMPRouteManager *route_manager; + const NMPObject *plobj; + const NMPObject *plobj_next; + int ifindex; } priv; }; @@ -215,9 +222,9 @@ gboolean nm_l3cfg_is_ready(NML3Cfg *self); void _nm_l3cfg_notify_platform_change_on_idle(NML3Cfg *self, guint32 obj_type_flags); -void _nm_l3cfg_notify_platform_change(NML3Cfg * self, +void _nm_l3cfg_notify_platform_change(NML3Cfg *self, NMPlatformSignalChangeType change_type, - const NMPObject * obj); + const NMPObject *obj); /*****************************************************************************/ @@ -301,7 +308,7 @@ void _nm_l3cfg_emit_signal_notify(NML3Cfg *self, const NML3ConfigNotifyData *not void nm_l3cfg_mark_config_dirty(NML3Cfg *self, gconstpointer tag, gboolean dirty); -gboolean nm_l3cfg_add_config(NML3Cfg * self, +gboolean nm_l3cfg_add_config(NML3Cfg *self, gconstpointer tag, gboolean replace_same_tag, const NML3ConfigData *l3cd, @@ -397,11 +404,11 @@ typedef enum { NM_L3CFG_CHECK_READY_FLAGS_IP6_DAD_READY = (1ull << 1), } NML3CfgCheckReadyFlags; -gboolean nm_l3cfg_check_ready(NML3Cfg * self, - const NML3ConfigData * l3cd, +gboolean nm_l3cfg_check_ready(NML3Cfg *self, + const NML3ConfigData *l3cd, int addr_family, NML3CfgCheckReadyFlags flags, - gboolean * acd_used); + gboolean *acd_used); /*****************************************************************************/ @@ -409,10 +416,10 @@ NML3CfgCommitType nm_l3cfg_commit_type_get(NML3Cfg *self); typedef struct _NML3CfgCommitTypeHandle NML3CfgCommitTypeHandle; -NML3CfgCommitTypeHandle *nm_l3cfg_commit_type_register(NML3Cfg * self, +NML3CfgCommitTypeHandle *nm_l3cfg_commit_type_register(NML3Cfg *self, NML3CfgCommitType commit_type, NML3CfgCommitTypeHandle *existing_handle, - const char * source); + const char *source); void nm_l3cfg_commit_type_unregister(NML3Cfg *self, NML3CfgCommitTypeHandle *handle); @@ -426,6 +433,8 @@ nm_l3cfg_commit_type_clear(NML3Cfg *self, NML3CfgCommitTypeHandle **handle) return TRUE; } +void nm_l3cfg_commit_type_reset_update(NML3Cfg *self); + /*****************************************************************************/ const NML3ConfigData *nm_l3cfg_get_combined_l3cd(NML3Cfg *self, gboolean get_commited); @@ -447,4 +456,10 @@ void _nm_l3cfg_unregister_ipv4ll(NML3Cfg *self); /*****************************************************************************/ +struct _NMIPConfig; +struct _NMIPConfig *nm_l3cfg_ipconfig_get(NML3Cfg *self, int addr_family); +struct _NMIPConfig *nm_l3cfg_ipconfig_acquire(NML3Cfg *self, int addr_family); + +/*****************************************************************************/ + #endif /* __NM_L3CFG_H__ */ diff --git a/src/core/nm-manager.c b/src/core/nm-manager.c index 3c9660c7..b440b224 100644 --- a/src/core/nm-manager.c +++ b/src/core/nm-manager.c @@ -59,9 +59,9 @@ typedef struct { gboolean hw_enabled; RfKillType rtype; NMConfigRunStatePropertyType key; - const char * desc; - const char * prop; - const char * hw_prop; + const char *desc; + const char *prop; + const char *hw_prop; } RadioState; typedef enum { @@ -73,7 +73,7 @@ typedef enum { typedef struct { CList async_op_lst; - NMManager * self; + NMManager *self; AsyncOpType async_op_type; union { struct { @@ -83,8 +83,8 @@ typedef struct { GDBusMethodInvocation *invocation; } activate_user; struct { - GDBusMethodInvocation * invocation; - NMConnection * connection; + GDBusMethodInvocation *invocation; + NMConnection *connection; NMSettingsConnectionPersistMode persist_mode; bool is_volatile : 1; } add_and_activate; @@ -152,9 +152,9 @@ typedef struct { CList devices_lst_head; NMState state; - NMConfig * config; - NMConnectivity * concheck_mgr; - NMPolicy * policy; + NMConfig *config; + NMConnectivity *concheck_mgr; + NMPolicy *policy; NMHostnameManager *hostname_manager; struct { @@ -324,28 +324,28 @@ static gboolean add_device(NMManager *self, NMDevice *device, GError **error); static void _emit_device_added_removed(NMManager *self, NMDevice *device, gboolean is_added); -static NMActiveConnection *_new_active_connection(NMManager * self, +static NMActiveConnection *_new_active_connection(NMManager *self, gboolean is_vpn, - NMSettingsConnection * sett_conn, - NMConnection * incompl_conn, - NMConnection * applied, - const char * specific_object, - NMDevice * device, - NMAuthSubject * subject, + NMSettingsConnection *sett_conn, + NMConnection *incompl_conn, + NMConnection *applied, + const char *specific_object, + NMDevice *device, + NMAuthSubject *subject, NMActivationType activation_type, NMActivationReason activation_reason, NMActivationStateFlags initial_state_flags, - GError ** error); + GError **error); static void policy_activating_ac_changed(GObject *object, GParamSpec *pspec, gpointer user_data); -static gboolean find_master(NMManager * self, - NMConnection * connection, - NMDevice * device, +static gboolean find_master(NMManager *self, + NMConnection *connection, + NMDevice *device, NMSettingsConnection **out_master_connection, - NMDevice ** out_master_device, - NMActiveConnection ** out_master_ac, - GError ** error); + NMDevice **out_master_device, + NMActiveConnection **out_master_ac, + GError **error); static void nm_manager_update_state(NMManager *manager); @@ -363,35 +363,35 @@ static void active_connection_default_changed(NMActiveConnection *active, GParamSpec *pspec, NMManager *self); static void active_connection_parent_active(NMActiveConnection *active, NMActiveConnection *parent_ac, - NMManager * self); + NMManager *self); -static NMActiveConnection *active_connection_find(NMManager * self, - NMSettingsConnection * sett_conn, - const char * uuid, +static NMActiveConnection *active_connection_find(NMManager *self, + NMSettingsConnection *sett_conn, + const char *uuid, NMActiveConnectionState max_state, gboolean also_waiting_auth, - GPtrArray ** out_all_matching); + GPtrArray **out_all_matching); static NMConnectivity *concheck_get_mgr(NMManager *self); -static void _internal_activation_auth_done(NMManager * self, +static void _internal_activation_auth_done(NMManager *self, NMActiveConnection *active, gboolean success, - const char * error_desc); -static void _add_and_activate_auth_done(NMManager * self, + const char *error_desc); +static void _add_and_activate_auth_done(NMManager *self, AsyncOpType async_op_type, - NMActiveConnection * active, - NMConnection * connection, - GDBusMethodInvocation * invocation, + NMActiveConnection *active, + NMConnection *connection, + GDBusMethodInvocation *invocation, NMSettingsConnectionPersistMode persist_mode, gboolean is_volatile, gboolean success, - const char * error_desc); -static void _activation_auth_done(NMManager * self, - NMActiveConnection * active, + const char *error_desc); +static void _activation_auth_done(NMManager *self, + NMActiveConnection *active, GDBusMethodInvocation *invocation, gboolean success, - const char * error_desc); + const char *error_desc); /*****************************************************************************/ @@ -436,7 +436,7 @@ static void concheck_config_changed_cb(NMConnectivity *connectivity, NMManager *self) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMDevice * device; + NMDevice *device; gboolean changed; concheck_enabled(self, &changed); @@ -479,8 +479,8 @@ _async_op_data_new_authorize_activate_internal(NMManager *self, NMActiveConnecti } static AsyncOpData * -_async_op_data_new_ac_auth_activate_user(NMManager * self, - NMActiveConnection * active_take, +_async_op_data_new_ac_auth_activate_user(NMManager *self, + NMActiveConnection *active_take, GDBusMethodInvocation *invocation_take) { AsyncOpData *async_op_data; @@ -496,11 +496,11 @@ _async_op_data_new_ac_auth_activate_user(NMManager * self, } static AsyncOpData * -_async_op_data_new_ac_auth_add_and_activate(NMManager * self, +_async_op_data_new_ac_auth_add_and_activate(NMManager *self, AsyncOpType async_op_type, - NMActiveConnection * active_take, - GDBusMethodInvocation * invocation_take, - NMConnection * connection_take, + NMActiveConnection *active_take, + GDBusMethodInvocation *invocation_take, + NMConnection *connection_take, NMSettingsConnectionPersistMode persist_mode, gboolean is_volatile) { @@ -526,7 +526,7 @@ _async_op_data_new_ac_auth_add_and_activate(NMManager * self static void _async_op_complete_ac_auth_cb(NMActiveConnection *active, gboolean success, - const char * error_desc, + const char *error_desc, gpointer user_data) { AsyncOpData *async_op_data = user_data; @@ -629,15 +629,15 @@ _device_route_metric_data_by_ifindex_equal(gconstpointer pa, gconstpointer pb) } static guint32 -_device_route_metric_get(NMManager * self, +_device_route_metric_get(NMManager *self, int ifindex, NMDeviceType device_type, gboolean lookup_only, - guint32 * out_aspired_metric) + guint32 *out_aspired_metric) { - NMManagerPrivate * priv; + NMManagerPrivate *priv; const DeviceRouteMetricData *d2; - DeviceRouteMetricData * data; + DeviceRouteMetricData *data; DeviceRouteMetricData data_lookup; const NMDedupMultiHeadEntry *all_links_head; NMPObject links_needle; @@ -664,7 +664,7 @@ _device_route_metric_get(NMManager * self, return 0; if (G_UNLIKELY(!priv->device_route_metrics)) { - const GHashTable * h; + const GHashTable *h; const NMConfigDeviceStateData *device_state; priv->device_route_metrics = @@ -810,7 +810,7 @@ nm_manager_device_route_metric_reserve(NMManager *self, int ifindex, NMDeviceTyp void nm_manager_device_route_metric_clear(NMManager *self, int ifindex) { - NMManagerPrivate * priv; + NMManagerPrivate *priv; DeviceRouteMetricData data_lookup; priv = NM_MANAGER_GET_PRIVATE(self); @@ -855,7 +855,7 @@ _delete_volatile_connection_do(NMManager *self, NMSettingsConnection *connection static gboolean active_connection_remove(NMManager *self, NMActiveConnection *active) { - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); gs_unref_object NMSettingsConnection *connection = NULL; gboolean notify; @@ -883,8 +883,8 @@ active_connection_remove(NMManager *self, NMActiveConnection *active) static gboolean _active_connection_cleanup(gpointer user_data) { - NMManager * self = NM_MANAGER(user_data); - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); + NMManager *self = NM_MANAGER(user_data); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); NMActiveConnection *ac, *ac_safe; priv->ac_cleanup_id = 0; @@ -907,9 +907,9 @@ _active_connection_cleanup(gpointer user_data) static void active_connection_state_changed(NMActiveConnection *active, GParamSpec *pspec, NMManager *self) { - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); NMActiveConnectionState state; - NMSettingsConnection * con; + NMSettingsConnection *con; state = nm_active_connection_get_state(active); if (state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) { @@ -982,17 +982,17 @@ nm_manager_get_active_connections(NMManager *manager) static NMActiveConnection * active_connection_find( - NMManager * self, - NMSettingsConnection * sett_conn, - const char * uuid, + NMManager *self, + NMSettingsConnection *sett_conn, + const char *uuid, NMActiveConnectionState max_state /* candidates in state @max_state will be found */, gboolean also_waiting_auth /* return also ACs waiting authorization */, - GPtrArray ** out_all_matching) + GPtrArray **out_all_matching) { - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); NMActiveConnection *ac; NMActiveConnection *best_ac = NULL; - GPtrArray * all = NULL; + GPtrArray *all = NULL; nm_assert(!sett_conn || NM_IS_SETTINGS_CONNECTION(sett_conn)); nm_assert(!out_all_matching || !*out_all_matching); @@ -1071,11 +1071,11 @@ active_connection_find( } static NMActiveConnection * -active_connection_find_by_connection(NMManager * self, - NMSettingsConnection * sett_conn, - NMConnection * connection, +active_connection_find_by_connection(NMManager *self, + NMSettingsConnection *sett_conn, + NMConnection *connection, NMActiveConnectionState max_state, - GPtrArray ** out_all_matching) + GPtrArray **out_all_matching) { nm_assert(NM_IS_MANAGER(self)); nm_assert(!sett_conn || NM_IS_SETTINGS_CONNECTION(sett_conn)); @@ -1100,7 +1100,7 @@ typedef struct { } GetActivatableConnectionsFilterData; static gboolean -_get_activatable_connections_filter(NMSettings * settings, +_get_activatable_connections_filter(NMSettings *settings, NMSettingsConnection *sett_conn, gpointer user_data) { @@ -1133,12 +1133,12 @@ NMSettingsConnection ** nm_manager_get_activatable_connections(NMManager *manager, gboolean for_auto_activation, gboolean sort, - guint * out_len) + guint *out_len) { - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(manager); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(manager); const GetActivatableConnectionsFilterData d = { - .self = manager, - .for_auto_activation = for_auto_activation, + .self = manager, + .for_auto_activation = for_auto_activation, }; return nm_settings_get_connections_clone( @@ -1153,7 +1153,7 @@ nm_manager_get_activatable_connections(NMManager *manager, static NMActiveConnection * active_connection_get_by_path(NMManager *self, const char *path) { - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); NMActiveConnection *ac; ac = nm_dbus_manager_lookup_object(nm_dbus_object_get_manager(NM_DBUS_OBJECT(self)), path); @@ -1167,11 +1167,11 @@ active_connection_get_by_path(NMManager *self, const char *path) /*****************************************************************************/ static void -_config_changed_cb(NMConfig * config, - NMConfigData * config_data, +_config_changed_cb(NMConfig *config, + NMConfigData *config_data, NMConfigChangeFlags changes, - NMConfigData * old_data, - NMManager * self) + NMConfigData *old_data, + NMManager *self) { g_object_freeze_notify(G_OBJECT(self)); @@ -1192,12 +1192,12 @@ _config_changed_cb(NMConfig * config, static void _reload_auth_cb(NMAuthChain *chain, GDBusMethodInvocation *context, gpointer user_data) { - NMManager * self = NM_MANAGER(user_data); - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); - GError * ret_error = NULL; + NMManager *self = NM_MANAGER(user_data); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); + GError *ret_error = NULL; NMAuthCallResult result; guint32 flags; - NMAuthSubject * subject; + NMAuthSubject *subject; char s_buf[60]; NMConfigChangeFlags reload_type = NM_CONFIG_CHANGE_NONE; @@ -1250,17 +1250,17 @@ _reload_auth_cb(NMAuthChain *chain, GDBusMethodInvocation *context, gpointer use } static void -impl_manager_reload(NMDBusObject * obj, +impl_manager_reload(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMManager * self = NM_MANAGER(obj); + NMManager *self = NM_MANAGER(obj); NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMAuthChain * chain; + NMAuthChain *chain; guint32 flags; g_variant_get(parameters, "(u)", &flags); @@ -1285,7 +1285,7 @@ NMDevice * nm_manager_get_device_by_path(NMManager *self, const char *path) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMDevice * device; + NMDevice *device; g_return_val_if_fail(path, NULL); @@ -1301,7 +1301,7 @@ NMDevice * nm_manager_get_device_by_ifindex(NMManager *self, int ifindex) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMDevice * device; + NMDevice *device; if (ifindex > 0) { c_list_for_each_entry (device, &priv->devices_lst_head, devices_lst) { @@ -1317,8 +1317,8 @@ static NMDevice * find_device_by_permanent_hw_addr(NMManager *self, const char *hwaddr) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMDevice * device; - const char * device_addr; + NMDevice *device; + const char *device_addr; guint8 hwaddr_bin[_NM_UTILS_HWADDR_LEN_MAX]; gsize hwaddr_len; @@ -1339,7 +1339,7 @@ static NMDevice * find_device_by_ip_iface(NMManager *self, const char *iface) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMDevice * device; + NMDevice *device; g_return_val_if_fail(iface, NULL); @@ -1366,14 +1366,14 @@ find_device_by_ip_iface(NMManager *self, const char *iface) * Returns: the matching #NMDevice */ static NMDevice * -find_device_by_iface(NMManager * self, - const char * iface, +find_device_by_iface(NMManager *self, + const char *iface, NMConnection *connection, NMConnection *slave) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMDevice * fallback = NULL; - NMDevice * candidate; + NMDevice *fallback = NULL; + NMDevice *candidate; g_return_val_if_fail(iface != NULL, NULL); @@ -1434,7 +1434,7 @@ _nm_state_to_string(NMState state) static NMState find_best_device_state(NMManager *manager) { - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(manager); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(manager); NMState best_state = NM_STATE_DISCONNECTED; NMActiveConnection *ac; @@ -1481,7 +1481,7 @@ static void nm_manager_update_metered(NMManager *self) { NMManagerPrivate *priv; - NMDevice * device; + NMDevice *device; NMMetered value = NM_METERED_UNKNOWN; g_return_if_fail(NM_IS_MANAGER(self)); @@ -1543,13 +1543,13 @@ nm_manager_update_state(NMManager *self) } static void -manager_device_state_changed(NMDevice * device, +manager_device_state_changed(NMDevice *device, NMDeviceState new_state, NMDeviceState old_state, NMDeviceStateReason reason, gpointer user_data) { - NMManager * self = NM_MANAGER(user_data); + NMManager *self = NM_MANAGER(user_data); NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); if (old_state == NM_DEVICE_STATE_UNMANAGED && new_state > NM_DEVICE_STATE_UNMANAGED) @@ -1593,8 +1593,8 @@ static void check_if_startup_complete(NMManager *self) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMDevice * device; - const char * reason; + NMDevice *device; + const char *reason; if (!priv->startup) return; @@ -1674,7 +1674,7 @@ static void _parent_notify_changed(NMManager *self, NMDevice *device, gboolean device_removed) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMDevice * candidate; + NMDevice *candidate; nm_assert(NM_IS_DEVICE(device)); @@ -1733,10 +1733,6 @@ remove_device(NMManager *self, NMDevice *device, gboolean quitting) TRUE, NM_DEVICE_STATE_REASON_REMOVED); } - } else if (quitting - && nm_config_get_configure_and_quit(priv->config) - == NM_CONFIG_CONFIGURE_AND_QUIT_ENABLED) { - nm_device_spawn_iface_helper(device); } } @@ -1796,17 +1792,17 @@ nm_manager_get_state(NMManager *manager) /*****************************************************************************/ static NMDevice * -find_parent_device_for_connection(NMManager * self, - NMConnection * connection, +find_parent_device_for_connection(NMManager *self, + NMConnection *connection, NMDeviceFactory *cached_factory, - const char ** out_parent_spec) + const char **out_parent_spec) { - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); - NMDeviceFactory * factory; - const char * parent_name = NULL; + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); + NMDeviceFactory *factory; + const char *parent_name = NULL; NMSettingsConnection *parent_connection; - NMDevice * parent, *first_compatible = NULL; - NMDevice * candidate; + NMDevice *parent, *first_compatible = NULL; + NMDevice *candidate; g_return_val_if_fail(NM_IS_CONNECTION(connection), NULL); NM_SET_OUT(out_parent_spec, NULL); @@ -1879,15 +1875,15 @@ find_parent_device_for_connection(NMManager * self, * Returns: the expected interface name (caller takes ownership), or %NULL */ char * -nm_manager_get_connection_iface(NMManager * self, +nm_manager_get_connection_iface(NMManager *self, NMConnection *connection, - NMDevice ** out_parent, - const char ** out_parent_spec, - GError ** error) + NMDevice **out_parent, + const char **out_parent_spec, + GError **error) { NMDeviceFactory *factory; - char * iface = NULL; - NMDevice * parent = NULL; + char *iface = NULL; + NMDevice *parent = NULL; NM_SET_OUT(out_parent, NULL); NM_SET_OUT(out_parent_spec, NULL); @@ -1951,7 +1947,7 @@ return_ifname_fom_connection: const char * nm_manager_iface_for_uuid(NMManager *self, const char *uuid) { - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); NMSettingsConnection *sett_conn; sett_conn = nm_settings_get_connection_by_uuid(priv->settings, uuid); @@ -1965,7 +1961,7 @@ NMDevice * nm_manager_get_device(NMManager *self, const char *ifname, NMDeviceType device_type) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMDevice * device; + NMDevice *device; g_return_val_if_fail(ifname, NULL); g_return_val_if_fail(device_type != NM_DEVICE_TYPE_UNKNOWN, NULL); @@ -2005,15 +2001,15 @@ nm_manager_remove_device(NMManager *self, const char *ifname, NMDeviceType devic static NMDevice * system_create_virtual_device(NMManager *self, NMConnection *connection) { - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); - NMDeviceFactory * factory; + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); + NMDeviceFactory *factory; NMSettingsConnection *const *connections; guint i; - gs_free char * iface = NULL; - const char * parent_spec; - NMDevice * device = NULL, *parent = NULL; - NMDevice * dev_candidate; - GError * error = NULL; + gs_free char *iface = NULL; + const char *parent_spec; + NMDevice *device = NULL, *parent = NULL; + NMDevice *dev_candidate; + GError *error = NULL; NMLogLevel log_level; g_return_val_if_fail(NM_IS_MANAGER(self), NULL); @@ -2099,7 +2095,7 @@ system_create_virtual_device(NMManager *self, NMConnection *connection) /* Create backing resources if the device has any autoconnect connections */ connections = nm_settings_get_connections_sorted_by_autoconnect_priority(priv->settings, NULL); for (i = 0; connections[i]; i++) { - NMConnection * candidate = nm_settings_connection_get_connection(connections[i]); + NMConnection *candidate = nm_settings_connection_get_connection(connections[i]); NMSettingConnection *s_con; if (!nm_device_check_connection_compatible(device, candidate, NULL)) @@ -2136,7 +2132,7 @@ system_create_virtual_device(NMManager *self, NMConnection *connection) static void retry_connections_for_parent_device(NMManager *self, NMDevice *device) { - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); NMSettingsConnection *const *connections; guint i; @@ -2145,10 +2141,10 @@ retry_connections_for_parent_device(NMManager *self, NMDevice *device) connections = nm_settings_get_connections_sorted_by_autoconnect_priority(priv->settings, NULL); for (i = 0; connections[i]; i++) { NMSettingsConnection *sett_conn = connections[i]; - NMConnection * connection = nm_settings_connection_get_connection(sett_conn); + NMConnection *connection = nm_settings_connection_get_connection(sett_conn); gs_free_error GError *error = NULL; - gs_free char * ifname = NULL; - NMDevice * parent; + gs_free char *ifname = NULL; + NMDevice *parent; parent = find_parent_device_for_connection(self, connection, NULL, NULL); if (parent == device) { @@ -2166,7 +2162,7 @@ static void connection_changed(NMManager *self, NMSettingsConnection *sett_conn) { NMConnection *connection; - NMDevice * device; + NMDevice *device; if (NM_FLAGS_ANY(nm_settings_connection_get_flags(sett_conn), NM_SETTINGS_CONNECTION_INT_FLAGS_VOLATILE @@ -2195,10 +2191,10 @@ connection_added_cb(NMSettings *settings, NMSettingsConnection *sett_conn, NMMan } static void -connection_updated_cb(NMSettings * settings, +connection_updated_cb(NMSettings *settings, NMSettingsConnection *sett_conn, guint update_reason_u, - NMManager * self) + NMManager *self) { connection_changed(self, sett_conn); } @@ -2209,7 +2205,7 @@ static void _delete_volatile_connection_all(NMManager *self, gboolean do_delete) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMCListElem * elem; + NMCListElem *elem; while ( (elem = c_list_first_entry(&priv->delete_volatile_connection_lst_head, NMCListElem, lst))) { @@ -2224,7 +2220,7 @@ _delete_volatile_connection_all(NMManager *self, gboolean do_delete) static gboolean _delete_volatile_connection_cb(gpointer user_data) { - NMManager * self = user_data; + NMManager *self = user_data; NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); priv->delete_volatile_connection_idle_id = 0; @@ -2235,7 +2231,7 @@ _delete_volatile_connection_cb(gpointer user_data) static void connection_flags_changed(NMSettings *settings, NMSettingsConnection *connection, gpointer user_data) { - NMManager * self = user_data; + NMManager *self = user_data; NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); if (!NM_FLAGS_ANY(nm_settings_connection_get_flags(connection), @@ -2265,24 +2261,18 @@ connection_flags_changed(NMSettings *settings, NMSettingsConnection *connection, static void system_unmanaged_devices_changed_cb(NMSettings *settings, GParamSpec *pspec, gpointer user_data) { - NMManager * self = NM_MANAGER(user_data); + NMManager *self = NM_MANAGER(user_data); NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMDevice * device; + NMDevice *device; c_list_for_each_entry (device, &priv->devices_lst_head, devices_lst) - nm_device_set_unmanaged_by_user_settings(device); + nm_device_set_unmanaged_by_user_settings(device, TRUE); } static void -hostname_changed_cb(NMHostnameManager *hostname_manager, GParamSpec *pspec, NMManager *self) +_static_hostname_changed_cb(NMHostnameManager *hostname_manager, GParamSpec *pspec, NMManager *self) { - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - const char * hostname; - - hostname = nm_hostname_manager_get_hostname(priv->hostname_manager); - nm_dispatcher_call_hostname(NULL, NULL, NULL); - nm_dhcp_manager_set_default_hostname(nm_dhcp_manager_get(), hostname); } /*****************************************************************************/ @@ -2312,7 +2302,7 @@ static void manager_update_radio_enabled(NMManager *self, RadioState *rstate, gboolean enabled) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMDevice * device; + NMDevice *device; /* Do nothing for radio types not yet implemented */ if (!rstate->prop) @@ -2423,14 +2413,14 @@ nm_manager_rfkill_update(NMManager *self, RfKillType rtype) static void device_auth_done_cb(NMAuthChain *chain, GDBusMethodInvocation *context, gpointer user_data) { - NMManager * self = NM_MANAGER(user_data); - gs_free_error GError * error = NULL; + NMManager *self = NM_MANAGER(user_data); + gs_free_error GError *error = NULL; NMAuthCallResult result; - NMDevice * device; - GCancellable * cancellable; - const char * permission; + NMDevice *device; + GCancellable *cancellable; + const char *permission; NMManagerDeviceAuthRequestFunc callback; - NMAuthSubject * subject; + NMAuthSubject *subject; nm_assert(G_IS_DBUS_METHOD_INVOCATION(context)); @@ -2469,14 +2459,14 @@ device_auth_done_cb(NMAuthChain *chain, GDBusMethodInvocation *context, gpointer static void _device_auth_done_fail_on_idle(gpointer user_data, GCancellable *cancellable) { - gs_unref_object NMManager *self = NULL; - gs_unref_object NMDevice *device = NULL; - gs_unref_object GDBusMethodInvocation *context = NULL; - gs_unref_object NMAuthSubject *subject = NULL; - gs_free_error GError *error_original = NULL; - gs_free_error GError * error_cancelled = NULL; - NMManagerDeviceAuthRequestFunc callback; - gpointer callback_user_data; + gs_unref_object NMManager *self = NULL; + gs_unref_object NMDevice *device = NULL; + gs_unref_object GDBusMethodInvocation *context = NULL; + gs_unref_object NMAuthSubject *subject = NULL; + gs_free_error GError *error_original = NULL; + gs_free_error GError *error_cancelled = NULL; + NMManagerDeviceAuthRequestFunc callback; + gpointer callback_user_data; nm_utils_user_data_unpack(user_data, &self, @@ -2493,21 +2483,21 @@ _device_auth_done_fail_on_idle(gpointer user_data, GCancellable *cancellable) } void -nm_manager_device_auth_request(NMManager * self, - NMDevice * device, - GDBusMethodInvocation * context, - NMConnection * connection, - const char * permission, +nm_manager_device_auth_request(NMManager *self, + NMDevice *device, + GDBusMethodInvocation *context, + NMConnection *connection, + const char *permission, gboolean allow_interaction, - GCancellable * cancellable, + GCancellable *cancellable, NMManagerDeviceAuthRequestFunc callback, gpointer user_data) { - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - gs_free_error GError *error = NULL; + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); + gs_free_error GError *error = NULL; gs_unref_object NMAuthSubject *subject = NULL; - NMAuthChain * chain; - char * permission_dup; + NMAuthChain *chain; + char *permission_dup; /* Validate the caller */ subject = nm_dbus_manager_new_auth_subject_from_context(context); @@ -2583,24 +2573,22 @@ new_activation_allowed_for_connection(NMManager *self, NMSettingsConnection *con static NMSettingsConnection * get_existing_connection(NMManager *self, NMDevice *device, gboolean *out_generated) { - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); gs_unref_object NMConnection *connection = NULL; - NMSettingsConnection * added; - GError * error = NULL; - gs_free_error GError *gen_error = NULL; - NMDevice * master = NULL; - int ifindex = nm_device_get_ifindex(device); - NMSettingsConnection *matched = NULL; - NMSettingsConnection *connection_checked = NULL; - gboolean assume_state_guess_assume = FALSE; - const char * assume_state_connection_uuid = NULL; - gboolean maybe_later, only_by_uuid = FALSE; + NMSettingsConnection *added; + GError *error = NULL; + gs_free_error GError *gen_error = NULL; + NMDevice *master = NULL; + int ifindex = nm_device_get_ifindex(device); + NMSettingsConnection *matched = NULL; + NMSettingsConnection *connection_checked = NULL; + gboolean assume_state_guess_assume = FALSE; + const char *assume_state_connection_uuid = NULL; + gboolean maybe_later, only_by_uuid = FALSE; if (out_generated) *out_generated = FALSE; - nm_device_capture_initial_config(device); - if (!nm_device_can_assume_connections(device)) { nm_device_assume_state_reset(device); _LOG2D(LOGD_DEVICE, device, "assume: device cannot assume connection"); @@ -2731,7 +2719,7 @@ get_existing_connection(NMManager *self, NMDevice *device, gboolean *out_generat len = j; if (len > 0) { gs_free NMConnection **conns = NULL; - NMConnection * con; + NMConnection *con; g_qsort_with_data(sett_conns, len, @@ -2950,10 +2938,10 @@ recheck_assume_connection(NMManager *self, NMDevice *device) g_return_val_if_fail(nm_device_get_state(device) >= NM_DEVICE_STATE_DISCONNECTED, FALSE); { - gs_unref_object NMActiveConnection *active = NULL; - gs_unref_object NMAuthSubject *subject = NULL; - NMActiveConnection * master_ac; - GError * error = NULL; + gs_unref_object NMActiveConnection *active = NULL; + gs_unref_object NMAuthSubject *subject = NULL; + NMActiveConnection *master_ac; + GError *error = NULL; subject = nm_auth_subject_new_internal(); @@ -3042,9 +3030,9 @@ static void device_ip_iface_changed(NMDevice *device, GParamSpec *pspec, NMManager *self) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - const char * ip_iface = nm_device_get_ip_iface(device); + const char *ip_iface = nm_device_get_ip_iface(device); NMDeviceType device_type = nm_device_get_device_type(device); - NMDevice * candidate; + NMDevice *candidate; /* Remove NMDevice objects that are actually child devices of others, * when the other device finally knows its IP interface name. For example, @@ -3091,9 +3079,9 @@ device_realized(NMDevice *device, GParamSpec *pspec, NMManager *self) static NMConnectivityState _get_best_connectivity(NMManager *self, int addr_family) { - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); NMConnectivityState best_state; - NMDevice * dev; + NMDevice *dev; gint64 best_metric; if (addr_family == AF_UNSPEC) { @@ -3113,7 +3101,7 @@ _get_best_connectivity(NMManager *self, int addr_family) best_state = NM_CONNECTIVITY_UNKNOWN; best_metric = G_MAXINT64; c_list_for_each_entry (dev, &priv->devices_lst_head, devices_lst) { - const NMPObject * r; + const NMPObject *r; NMConnectivityState state; gint64 metric; @@ -3159,7 +3147,7 @@ device_connectivity_changed(NMDevice *device, GParamSpec *pspec, NMManager *self static void update_connectivity_value(NMManager *self) { - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); NMConnectivityState best_state; best_state = _get_best_connectivity(self, AF_UNSPEC); @@ -3218,12 +3206,12 @@ static gboolean add_device(NMManager *self, NMDevice *device, GError **error) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - const char * iface, *type_desc; + const char *iface, *type_desc; RfKillType rtype; - GSList * iter, *remove = NULL; + GSList *iter, *remove = NULL; int ifindex; - const char * dbus_path; - NMDevice * candidate; + const char *dbus_path; + NMDevice *candidate; /* No duplicates */ ifindex = nm_device_get_ifindex(device); @@ -3316,7 +3304,7 @@ add_device(NMManager *self, NMDevice *device, GError **error) type_desc = nm_device_get_type_desc(device); g_assert(type_desc); - nm_device_set_unmanaged_by_user_settings(device); + nm_device_set_unmanaged_by_user_settings(device, TRUE); nm_device_set_unmanaged_flags(device, NM_UNMANAGED_SLEEPING, manager_sleeping(self)); @@ -3338,7 +3326,7 @@ static void factory_device_added_cb(NMDeviceFactory *factory, NMDevice *device, gpointer user_data) { NMManager *self = user_data; - GError * error = NULL; + GError *error = NULL; g_return_if_fail(NM_IS_MANAGER(self)); @@ -3376,7 +3364,7 @@ void nm_manager_notify_device_availability_maybe_changed(NMManager *self) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMDevice * device; + NMDevice *device; c_list_for_each_entry (device, &priv->devices_lst_head, devices_lst) nm_device_notify_availability_maybe_changed(device); @@ -3385,16 +3373,16 @@ nm_manager_notify_device_availability_maybe_changed(NMManager *self) /*****************************************************************************/ static void -platform_link_added(NMManager * self, +platform_link_added(NMManager *self, int ifindex, - const NMPlatformLink * plink, + const NMPlatformLink *plink, gboolean guess_assume, const NMConfigDeviceStateData *dev_state) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMDeviceFactory * factory; - NMDevice * device = NULL; - NMDevice * candidate; + NMDeviceFactory *factory; + NMDevice *device = NULL; + NMDevice *candidate; g_return_if_fail(ifindex > 0); @@ -3403,8 +3391,8 @@ platform_link_added(NMManager * self, /* Let unrealized devices try to realize themselves with the link */ c_list_for_each_entry (candidate, &priv->devices_lst_head, devices_lst) { - gboolean compatible = TRUE; - gs_free_error GError *error = NULL; + gboolean compatible = TRUE; + gs_free_error GError *error = NULL; if (nm_device_get_link_type(candidate) != plink->type) continue; @@ -3454,8 +3442,8 @@ add: /* Try registered device factories */ factory = nm_device_factory_manager_find_factory_for_link_type(plink->type); if (factory) { - gboolean ignore = FALSE; - gs_free_error GError *error = NULL; + gboolean ignore = FALSE; + gs_free_error GError *error = NULL; device = nm_device_factory_create_device(factory, plink->name, plink, NULL, &ignore, &error); @@ -3541,9 +3529,9 @@ typedef struct { static gboolean _check_remove_dev_on_link_deleted(NMManager *self, NMDevice *device) { - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); NMSettingsConnection *const *scons = NULL; - NMConnection * con; + NMConnection *con; guint i; nm_assert(nm_device_is_software(device)); @@ -3581,8 +3569,8 @@ static gboolean _platform_link_cb_idle(PlatformLinkCbData *data) { int ifindex = data->ifindex; - NMManager * self = data->self; - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); + NMManager *self = data->self; + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); const NMPlatformLink *plink; c_list_unlink_stale(&data->lst); @@ -3596,7 +3584,7 @@ _platform_link_cb_idle(PlatformLinkCbData *data) nmp_object_unref(plink_keep_alive); } else { NMDevice *device; - GError * error = NULL; + GError *error = NULL; device = nm_manager_get_device_by_ifindex(self, ifindex); if (device) { @@ -3623,17 +3611,17 @@ _platform_link_cb_idle(PlatformLinkCbData *data) } static void -platform_link_cb(NMPlatform * platform, +platform_link_cb(NMPlatform *platform, int obj_type_i, int ifindex, NMPlatformLink *plink, int change_type_i, gpointer user_data) { - NMManager * self; - NMManagerPrivate * priv; + NMManager *self; + NMManagerPrivate *priv; const NMPlatformSignalChangeType change_type = change_type_i; - PlatformLinkCbData * data; + PlatformLinkCbData *data; switch (change_type) { case NM_PLATFORM_SIGNAL_ADDED: @@ -3655,11 +3643,11 @@ platform_link_cb(NMPlatform * platform, static void platform_query_devices(NMManager *self) { - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); gs_unref_ptrarray GPtrArray *links = NULL; int i; gboolean guess_assume; - gs_free char * order = NULL; + gs_free char *order = NULL; guess_assume = nm_config_get_first_start(nm_config_get()); order = nm_config_data_get_value(NM_CONFIG_GET_DATA, @@ -3670,7 +3658,7 @@ platform_query_devices(NMManager *self) if (!links) return; for (i = 0; i < links->len; i++) { - const NMPlatformLink * link = NMP_OBJECT_CAST_LINK(links->pdata[i]); + const NMPlatformLink *link = NMP_OBJECT_CAST_LINK(links->pdata[i]); const NMConfigDeviceStateData *dev_state; dev_state = nm_config_device_state_get(priv->config, link->ifindex); @@ -3743,29 +3731,29 @@ _device_get_activation_prio(NMDevice *device) } static NMDevice * -nm_manager_get_best_device_for_connection(NMManager * self, +nm_manager_get_best_device_for_connection(NMManager *self, NMSettingsConnection *sett_conn, - NMConnection * connection, + NMConnection *connection, gboolean for_user_request, - GHashTable * unavailable_devices, - GError ** error) + GHashTable *unavailable_devices, + GError **error) { - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); NMActiveConnectionState ac_state; - NMActiveConnection * ac; - NMDevice * ac_device; - NMDevice * device; + NMActiveConnection *ac; + NMDevice *ac_device; + NMDevice *device; struct { - NMDevice * device; + NMDevice *device; DeviceActivationPrio prio; } best = { .device = NULL, .prio = DEVICE_ACTIVATION_PRIO_NONE, }; NMDeviceCheckConAvailableFlags flags; - gs_unref_ptrarray GPtrArray *all_ac_arr = NULL; - gs_free_error GError * local_best = NULL; - NMConnectionMultiConnect multi_connect; + gs_unref_ptrarray GPtrArray *all_ac_arr = NULL; + gs_free_error GError *local_best = NULL; + NMConnectionMultiConnect multi_connect; nm_assert(!sett_conn || NM_IS_SETTINGS_CONNECTION(sett_conn)); nm_assert(!connection || NM_IS_CONNECTION(connection)); @@ -3842,8 +3830,8 @@ nm_manager_get_best_device_for_connection(NMManager * self, /* we found several active connections. See which one is the most suitable... */ nm_assert(ac == all_ac_arr->pdata[0]); for (i = 1; i < all_ac_arr->len; i++) { - NMActiveConnection * ac2 = all_ac_arr->pdata[i]; - NMDevice * ac_device2 = nm_active_connection_get_device(ac2); + NMActiveConnection *ac2 = all_ac_arr->pdata[i]; + NMDevice *ac_device2 = nm_active_connection_get_device(ac2); NMActiveConnectionState ac_state2; if (!ac_device2 @@ -3906,7 +3894,7 @@ found_better: /* Pick the first device that's compatible with the connection. */ c_list_for_each_entry (device, &priv->devices_lst_head, devices_lst) { - GError * local = NULL; + GError *local = NULL; DeviceActivationPrio prio; if (unavailable_devices && g_hash_table_contains(unavailable_devices, device)) @@ -3989,9 +3977,9 @@ static const char ** _get_devices_paths(NMManager *self, gboolean all_devices) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - const char ** paths = NULL; + const char **paths = NULL; guint i; - NMDevice * device; + NMDevice *device; paths = g_new(const char *, c_list_length(&priv->devices_lst_head) + 1); @@ -4014,15 +4002,15 @@ _get_devices_paths(NMManager *self, gboolean all_devices) } static void -impl_manager_get_devices(NMDBusObject * obj, +impl_manager_get_devices(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMManager * self = NM_MANAGER(obj); + NMManager *self = NM_MANAGER(obj); gs_free const char **paths = NULL; paths = _get_devices_paths(self, FALSE); @@ -4030,15 +4018,15 @@ impl_manager_get_devices(NMDBusObject * obj, } static void -impl_manager_get_all_devices(NMDBusObject * obj, +impl_manager_get_all_devices(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMManager * self = NM_MANAGER(obj); + NMManager *self = NM_MANAGER(obj); gs_free const char **paths = NULL; paths = _get_devices_paths(self, TRUE); @@ -4046,16 +4034,16 @@ impl_manager_get_all_devices(NMDBusObject * obj, } static void -impl_manager_get_device_by_ip_iface(NMDBusObject * obj, +impl_manager_get_device_by_ip_iface(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) -{ - NMManager * self = NM_MANAGER(obj); - NMDevice * device; + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) +{ + NMManager *self = NM_MANAGER(obj); + NMDevice *device; const char *path = NULL; const char *iface; @@ -4133,18 +4121,18 @@ is_compatible_with_slave(NMConnection *master, NMConnection *slave) * the connection did not require a master, %FALSE otherwise **/ static gboolean -find_master(NMManager * self, - NMConnection * connection, - NMDevice * device, +find_master(NMManager *self, + NMConnection *connection, + NMDevice *device, NMSettingsConnection **out_master_connection, - NMDevice ** out_master_device, - NMActiveConnection ** out_master_ac, - GError ** error) -{ - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); - NMSettingConnection * s_con; - const char * master; - NMDevice * master_device = NULL; + NMDevice **out_master_device, + NMActiveConnection **out_master_ac, + GError **error) +{ + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); + NMSettingConnection *s_con; + const char *master; + NMDevice *master_device = NULL; NMSettingsConnection *master_connection; s_con = nm_connection_get_setting_connection(connection); @@ -4249,16 +4237,16 @@ find_master(NMManager * self, * %NULL if an error occurred */ static NMActiveConnection * -ensure_master_active_connection(NMManager * self, - NMAuthSubject * subject, - NMConnection * connection, - NMDevice * device, +ensure_master_active_connection(NMManager *self, + NMAuthSubject *subject, + NMConnection *connection, + NMDevice *device, NMSettingsConnection *master_connection, - NMDevice * master_device, + NMDevice *master_device, NMActivationReason activation_reason, - GError ** error) + GError **error) { - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); NMActiveConnection *ac; NMActiveConnection *master_ac = NULL; NMDeviceState master_state; @@ -4321,7 +4309,7 @@ ensure_master_active_connection(NMManager * self, connections = nm_manager_get_activatable_connections(self, FALSE, TRUE, NULL); for (i = 0; connections[i]; i++) { NMSettingsConnection *candidate = connections[i]; - NMConnection * cand_conn = nm_settings_connection_get_connection(candidate); + NMConnection *cand_conn = nm_settings_connection_get_connection(candidate); /* Ensure eg bond/team slave and the candidate master is a * bond/team master @@ -4416,7 +4404,7 @@ ensure_master_active_connection(NMManager * self, typedef struct { NMSettingsConnection *connection; - NMDevice * device; + NMDevice *device; } SlaveConnectionInfo; /** @@ -4432,19 +4420,19 @@ typedef struct { * Returns: an array of #SlaveConnectionInfo for given master @sett_conn, or %NULL **/ static SlaveConnectionInfo * -find_slaves(NMManager * manager, +find_slaves(NMManager *manager, NMSettingsConnection *sett_conn, - NMDevice * device, - guint * out_n_slaves, + NMDevice *device, + guint *out_n_slaves, gboolean for_user_request) { - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(manager); - NMSettingsConnection *const *all_connections = NULL; - guint n_all_connections; - guint i; - SlaveConnectionInfo * slaves = NULL; - guint n_slaves = 0; - NMSettingConnection * s_con; + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(manager); + NMSettingsConnection *const *all_connections = NULL; + guint n_all_connections; + guint i; + SlaveConnectionInfo *slaves = NULL; + guint n_slaves = 0; + NMSettingConnection *s_con; gs_unref_hashtable GHashTable *devices = NULL; nm_assert(out_n_slaves); @@ -4463,7 +4451,7 @@ find_slaves(NMManager * manager, &n_all_connections); for (i = 0; i < n_all_connections; i++) { NMSettingsConnection *master_connection = NULL; - NMDevice * master_device = NULL, *slave_device; + NMDevice *master_device = NULL, *slave_device; NMSettingsConnection *candidate = all_connections[i]; find_master(manager, @@ -4506,7 +4494,7 @@ find_slaves(NMManager * manager, static gboolean should_connect_slaves(NMConnection *connection, NMDevice *device) { - NMSettingConnection * s_con; + NMSettingConnection *s_con; NMSettingConnectionAutoconnectSlaves val; s_con = nm_connection_get_setting_connection(connection); @@ -4552,10 +4540,10 @@ compare_slaves(gconstpointer a, gconstpointer b, gpointer sort_by_name) } static void -autoconnect_slaves(NMManager * self, +autoconnect_slaves(NMManager *self, NMSettingsConnection *master_connection, - NMDevice * master_device, - NMAuthSubject * subject, + NMDevice *master_device, + NMAuthSubject *subject, gboolean for_user_request) { GError *local_err = NULL; @@ -4588,7 +4576,7 @@ autoconnect_slaves(NMManager * self, for (i = 0; i < n_slaves; i++) { SlaveConnectionInfo *slave = &slaves[i]; - const char * uuid; + const char *uuid; /* To avoid loops when autoconnecting slaves, we propagate * the UUID of the initial connection down to slaves until @@ -4752,12 +4740,12 @@ _activation_bind_lifetime_to_profile_visibility(NMAuthSubject *subject) static void active_connection_parent_active(NMActiveConnection *active, NMActiveConnection *parent_ac, - NMManager * self) + NMManager *self) { - NMDevice * device = nm_active_connection_get_device(active); - GError * error = NULL; + NMDevice *device = nm_active_connection_get_device(active); + GError *error = NULL; NMSettingsConnection *sett_conn; - NMDevice * parent; + NMDevice *parent; g_signal_handlers_disconnect_by_func(active, G_CALLBACK(active_connection_parent_active), self); @@ -4795,16 +4783,16 @@ active_connection_parent_active(NMActiveConnection *active, static gboolean _internal_activate_device(NMManager *self, NMActiveConnection *active, GError **error) { - NMDevice * device, *master_device = NULL; - NMConnection * applied; - NMSettingsConnection * sett_conn; - NMSettingsConnection * master_connection = NULL; - NMConnection * existing_connection = NULL; - NMActiveConnection * master_ac = NULL; - NMAuthSubject * subject; - GError * local = NULL; + NMDevice *device, *master_device = NULL; + NMConnection *applied; + NMSettingsConnection *sett_conn; + NMSettingsConnection *master_connection = NULL; + NMConnection *existing_connection = NULL; + NMActiveConnection *master_ac = NULL; + NMAuthSubject *subject; + GError *local = NULL; NMConnectionMultiConnect multi_connect; - const char * parent_spec; + const char *parent_spec; g_return_val_if_fail(NM_IS_MANAGER(self), FALSE); g_return_val_if_fail(NM_IS_ACTIVE_CONNECTION(active), FALSE); @@ -4891,7 +4879,7 @@ _internal_activate_device(NMManager *self, NMActiveConnection *active, GError ** if (parent && !nm_device_is_real(parent)) { NMSettingsConnection *parent_con; - NMActiveConnection * parent_ac; + NMActiveConnection *parent_ac; parent_con = nm_device_get_best_connection(parent, NULL, error); if (!parent_con) { @@ -5043,7 +5031,7 @@ _internal_activate_device(NMManager *self, NMActiveConnection *active, GError ** /* the profile can be activated multiple times. Proceed. */ } else { gs_unref_ptrarray GPtrArray *all_ac_arr = NULL; - NMActiveConnection * ac; + NMActiveConnection *ac; guint i, n_all; /* Disconnect the connection if already connected or queued for activation. @@ -5122,21 +5110,21 @@ _internal_activate_generic(NMManager *self, NMActiveConnection *active, GError * } static NMActiveConnection * -_new_active_connection(NMManager * self, +_new_active_connection(NMManager *self, gboolean is_vpn, - NMSettingsConnection * sett_conn, - NMConnection * incompl_conn, - NMConnection * applied, - const char * specific_object, - NMDevice * device, - NMAuthSubject * subject, + NMSettingsConnection *sett_conn, + NMConnection *incompl_conn, + NMConnection *applied, + const char *specific_object, + NMDevice *device, + NMAuthSubject *subject, NMActivationType activation_type, NMActivationReason activation_reason, NMActivationStateFlags initial_state_flags, - GError ** error) + GError **error) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMDevice * parent_device; + NMDevice *parent_device; nm_assert(!sett_conn || NM_IS_SETTINGS_CONNECTION(sett_conn)); nm_assert(!incompl_conn || NM_IS_CONNECTION(incompl_conn)); @@ -5231,13 +5219,13 @@ _new_active_connection(NMManager * self, } static void -_internal_activation_auth_done(NMManager * self, +_internal_activation_auth_done(NMManager *self, NMActiveConnection *active, gboolean success, - const char * error_desc) + const char *error_desc) { - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); - NMActiveConnection *ac; + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); + NMActiveConnection *ac; gs_free_error GError *error = NULL; nm_assert(NM_IS_ACTIVE_CONNECTION(active)); @@ -5305,20 +5293,20 @@ fail: * activation of @sett_conn on @device */ NMActiveConnection * -nm_manager_activate_connection(NMManager * self, - NMSettingsConnection * sett_conn, - NMConnection * applied, - const char * specific_object, - NMDevice * device, - NMAuthSubject * subject, +nm_manager_activate_connection(NMManager *self, + NMSettingsConnection *sett_conn, + NMConnection *applied, + const char *specific_object, + NMDevice *device, + NMAuthSubject *subject, NMActivationType activation_type, NMActivationReason activation_reason, NMActivationStateFlags initial_state_flags, - GError ** error) + GError **error) { - NMManagerPrivate * priv; + NMManagerPrivate *priv; NMActiveConnection *active; - AsyncOpData * async_op_data; + AsyncOpData *async_op_data; gboolean is_vpn; g_return_val_if_fail(NM_IS_MANAGER(self), NULL); @@ -5402,17 +5390,17 @@ nm_manager_activate_connection(NMManager * self, * %NULL on error */ static NMAuthSubject * -validate_activation_request(NMManager * self, +validate_activation_request(NMManager *self, GDBusMethodInvocation *context, - NMSettingsConnection * sett_conn, - NMConnection * connection, - const char * device_path, - NMDevice ** out_device, - gboolean * out_is_vpn, - GError ** error) -{ - NMDevice * device = NULL; - gboolean is_vpn = FALSE; + NMSettingsConnection *sett_conn, + NMConnection *connection, + const char *device_path, + NMDevice **out_device, + gboolean *out_is_vpn, + GError **error) +{ + NMDevice *device = NULL; + gboolean is_vpn = FALSE; gs_unref_object NMAuthSubject *subject = NULL; nm_assert(!sett_conn || NM_IS_SETTINGS_CONNECTION(sett_conn)); @@ -5509,14 +5497,14 @@ validate_activation_request(NMManager * self, /*****************************************************************************/ static void -_activation_auth_done(NMManager * self, - NMActiveConnection * active, +_activation_auth_done(NMManager *self, + NMActiveConnection *active, GDBusMethodInvocation *invocation, gboolean success, - const char * error_desc) + const char *error_desc) { - GError * error = NULL; - NMAuthSubject * subject; + GError *error = NULL; + NMAuthSubject *subject; NMSettingsConnection *connection; subject = nm_active_connection_get_subject(active); @@ -5558,25 +5546,25 @@ fail: } static void -impl_manager_activate_connection(NMDBusObject * obj, +impl_manager_activate_connection(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * dbus_connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) -{ - NMManager * self = NM_MANAGER(obj); - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - gs_unref_object NMActiveConnection *active = NULL; - gs_unref_object NMAuthSubject *subject = NULL; - NMSettingsConnection * sett_conn = NULL; - NMDevice * device = NULL; - gboolean is_vpn = FALSE; - GError * error = NULL; - const char * connection_path; - const char * device_path; - const char * specific_object_path; + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *dbus_connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) +{ + NMManager *self = NM_MANAGER(obj); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); + gs_unref_object NMActiveConnection *active = NULL; + gs_unref_object NMAuthSubject *subject = NULL; + NMSettingsConnection *sett_conn = NULL; + NMDevice *device = NULL; + gboolean is_vpn = FALSE; + GError *error = NULL; + const char *connection_path; + const char *device_path; + const char *specific_object_path; g_variant_get(parameters, "(&o&o&o)", &connection_path, &device_path, &specific_object_path); @@ -5672,19 +5660,19 @@ error: /*****************************************************************************/ static void -activation_add_done(NMSettings * settings, - NMSettingsConnection * new_connection, - GError * error, +activation_add_done(NMSettings *settings, + NMSettingsConnection *new_connection, + GError *error, GDBusMethodInvocation *context, - NMAuthSubject * subject, + NMAuthSubject *subject, gpointer user_data) { - NMManager * self; + NMManager *self; gs_unref_object NMActiveConnection *active = NULL; - gs_free_error GError *local = NULL; - gpointer async_op_type_ptr; - AsyncOpType async_op_type; - GVariant * result_floating; + gs_free_error GError *local = NULL; + gpointer async_op_type_ptr; + AsyncOpType async_op_type; + GVariant *result_floating; nm_utils_user_data_unpack(user_data, &self, &active, &async_op_type_ptr); async_op_type = GPOINTER_TO_INT(async_op_type_ptr); @@ -5739,18 +5727,18 @@ fail: } static void -_add_and_activate_auth_done(NMManager * self, +_add_and_activate_auth_done(NMManager *self, AsyncOpType async_op_type, - NMActiveConnection * active, - NMConnection * connection, - GDBusMethodInvocation * invocation, + NMActiveConnection *active, + NMConnection *connection, + GDBusMethodInvocation *invocation, NMSettingsConnectionPersistMode persist_mode, gboolean is_volatile, gboolean success, - const char * error_desc) + const char *error_desc) { NMManagerPrivate *priv; - GError * error = NULL; + GError *error = NULL; if (!success) { error = @@ -5784,31 +5772,31 @@ _add_and_activate_auth_done(NMManager * self, } static void -impl_manager_add_and_activate_connection(NMDBusObject * obj, +impl_manager_add_and_activate_connection(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * dbus_connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) -{ - NMManager * self = NM_MANAGER(obj); - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - gs_unref_object NMConnection *incompl_conn = NULL; - gs_unref_object NMActiveConnection *active = NULL; - gs_unref_object NMAuthSubject *subject = NULL; - GError * error = NULL; - NMDevice * device = NULL; - gboolean is_vpn = FALSE; - gs_unref_variant GVariant *settings = NULL; - gs_unref_variant GVariant *options = NULL; - const char * device_path; - const char * specific_object_path; - gs_free NMConnection ** conns = NULL; - NMSettingsConnectionPersistMode persist_mode = NM_SETTINGS_CONNECTION_PERSIST_MODE_TO_DISK; - gboolean is_volatile = FALSE; - gboolean bind_dbus_client = FALSE; - AsyncOpType async_op_type; + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *dbus_connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) +{ + NMManager *self = NM_MANAGER(obj); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); + gs_unref_object NMConnection *incompl_conn = NULL; + gs_unref_object NMActiveConnection *active = NULL; + gs_unref_object NMAuthSubject *subject = NULL; + GError *error = NULL; + NMDevice *device = NULL; + gboolean is_vpn = FALSE; + gs_unref_variant GVariant *settings = NULL; + gs_unref_variant GVariant *options = NULL; + const char *device_path; + const char *specific_object_path; + gs_free NMConnection **conns = NULL; + NMSettingsConnectionPersistMode persist_mode = NM_SETTINGS_CONNECTION_PERSIST_MODE_TO_DISK; + gboolean is_volatile = FALSE; + gboolean bind_dbus_client = FALSE; + AsyncOpType async_op_type; if (nm_streq(method_info->parent.name, "AddAndActivateConnection2")) { async_op_type = ASYNC_OP_TYPE_AC_AUTH_ADD_AND_ACTIVATE2; @@ -5830,13 +5818,13 @@ impl_manager_add_and_activate_connection(NMDBusObject * obj, if (options) { GVariantIter iter; - const char * option_name; - GVariant * option_value; + const char *option_name; + GVariant *option_value; g_variant_iter_init(&iter, options); while (g_variant_iter_next(&iter, "{&sv}", &option_name, &option_value)) { gs_unref_variant GVariant *option_value_free = NULL; - const char * s; + const char *s; option_value_free = option_value; @@ -6003,10 +5991,10 @@ error: /*****************************************************************************/ gboolean -nm_manager_deactivate_connection(NMManager * manager, +nm_manager_deactivate_connection(NMManager *manager, NMActiveConnection *active, NMDeviceStateReason reason, - GError ** error) + GError **error) { if (NM_IS_VPN_CONNECTION(active)) { NMActiveConnectionStateReason vpn_reason = @@ -6036,11 +6024,11 @@ nm_manager_deactivate_connection(NMManager * manager, static void deactivate_net_auth_done_cb(NMAuthChain *chain, GDBusMethodInvocation *context, gpointer user_data) { - NMManager * self = NM_MANAGER(user_data); - GError * error = NULL; + NMManager *self = NM_MANAGER(user_data); + GError *error = NULL; NMAuthCallResult result; NMActiveConnection *active; - char * path; + char *path; nm_assert(G_IS_DBUS_METHOD_INVOCATION(context)); @@ -6083,22 +6071,22 @@ deactivate_net_auth_done_cb(NMAuthChain *chain, GDBusMethodInvocation *context, } static void -impl_manager_deactivate_connection(NMDBusObject * obj, +impl_manager_deactivate_connection(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * dbus_connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) -{ - NMManager * self = NM_MANAGER(obj); - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); - NMActiveConnection * ac; + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *dbus_connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) +{ + NMManager *self = NM_MANAGER(obj); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); + NMActiveConnection *ac; NMSettingsConnection *sett_conn = NULL; - GError * error = NULL; - NMAuthSubject * subject = NULL; - NMAuthChain * chain; - const char * active_path; + GError *error = NULL; + NMAuthSubject *subject = NULL; + NMAuthChain *chain; + const char *active_path; g_variant_get(parameters, "(&o)", &active_path); @@ -6153,7 +6141,7 @@ done: static gboolean sleep_devices_add(NMManager *self, NMDevice *device, gboolean suspending) { - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); NMSleepMonitorInhibitorHandle *handle = NULL; if (g_hash_table_lookup_extended(priv->sleep_devices, device, NULL, (gpointer *) &handle)) { @@ -6179,7 +6167,7 @@ sleep_devices_add(NMManager *self, NMDevice *device, gboolean suspending) static gboolean sleep_devices_remove(NMManager *self, NMDevice *device) { - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); NMSleepMonitorInhibitorHandle *handle; if (!g_hash_table_lookup_extended(priv->sleep_devices, device, NULL, (gpointer *) &handle)) @@ -6198,8 +6186,8 @@ sleep_devices_remove(NMManager *self, NMDevice *device) static void sleep_devices_clear(NMManager *self) { - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); - NMDevice * device; + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); + NMDevice *device; NMSleepMonitorInhibitorHandle *handle; GHashTableIter iter; @@ -6244,7 +6232,7 @@ do_sleep_wake(NMManager *self, gboolean sleeping_changed) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); gboolean suspending, waking_from_suspend; - NMDevice * device; + NMDevice *device; suspending = sleeping_changed && priv->sleeping; waking_from_suspend = sleeping_changed && !priv->sleeping; @@ -6395,17 +6383,17 @@ _internal_sleep(NMManager *self, gboolean do_sleep) } static void -impl_manager_sleep(NMDBusObject * obj, +impl_manager_sleep(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) -{ - NMManager * self = NM_MANAGER(obj); - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - GError * error = NULL; + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) +{ + NMManager *self = NM_MANAGER(obj); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); + GError *error = NULL; gs_unref_object NMAuthSubject *subject = NULL; gboolean do_sleep; @@ -6481,10 +6469,10 @@ _internal_enable(NMManager *self, gboolean enable) static void enable_net_done_cb(NMAuthChain *chain, GDBusMethodInvocation *context, gpointer user_data) { - NMManager * self = NM_MANAGER(user_data); + NMManager *self = NM_MANAGER(user_data); NMAuthCallResult result; gboolean enable; - NMAuthSubject * subject; + NMAuthSubject *subject; nm_assert(G_IS_DBUS_METHOD_INVOCATION(context)); @@ -6514,18 +6502,18 @@ enable_net_done_cb(NMAuthChain *chain, GDBusMethodInvocation *context, gpointer } static void -impl_manager_enable(NMDBusObject * obj, +impl_manager_enable(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMManager * self = NM_MANAGER(obj); + NMManager *self = NM_MANAGER(obj); NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMAuthChain * chain; - GError * error = NULL; + NMAuthChain *chain; + GError *error = NULL; gboolean enable; g_variant_get(parameters, "(b)", &enable); @@ -6572,7 +6560,7 @@ get_permissions_done_cb(NMAuthChain *chain, GDBusMethodInvocation *context, gpoi for (i = 0; i < (int) G_N_ELEMENTS(nm_auth_permission_sorted); i++) { const char *permission = nm_auth_permission_names_by_idx[nm_auth_permission_sorted[i] - 1]; NMAuthCallResult result; - const char * result_str; + const char *result_str; result = nm_auth_chain_get_result(chain, permission); result_str = nm_client_permission_result_to_string(nm_auth_call_result_to_client(result)); @@ -6583,17 +6571,17 @@ get_permissions_done_cb(NMAuthChain *chain, GDBusMethodInvocation *context, gpoi } static void -impl_manager_get_permissions(NMDBusObject * obj, +impl_manager_get_permissions(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMManager * self = NM_MANAGER(obj); + NMManager *self = NM_MANAGER(obj); NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMAuthChain * chain; + NMAuthChain *chain; int i; chain = nm_auth_chain_new_context(invocation, get_permissions_done_cb, self); @@ -6615,13 +6603,13 @@ impl_manager_get_permissions(NMDBusObject * obj, } static void -impl_manager_state(NMDBusObject * obj, +impl_manager_state(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { NMManager *self = NM_MANAGER(obj); @@ -6632,16 +6620,16 @@ impl_manager_state(NMDBusObject * obj, } static void -impl_manager_set_logging(NMDBusObject * obj, +impl_manager_set_logging(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) -{ - NMManager * self = NM_MANAGER(obj); - GError * error = NULL; + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) +{ + NMManager *self = NM_MANAGER(obj); + GError *error = NULL; const char *level; const char *domains; @@ -6672,13 +6660,13 @@ impl_manager_set_logging(NMDBusObject * obj, } static void -impl_manager_get_logging(NMDBusObject * obj, +impl_manager_get_logging(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { g_dbus_method_invocation_return_value( invocation, @@ -6686,21 +6674,21 @@ impl_manager_get_logging(NMDBusObject * obj, } typedef struct { - NMManager * self; + NMManager *self; GDBusMethodInvocation *context; guint remaining; } ConnectivityCheckData; static void -device_connectivity_done(NMDevice * device, +device_connectivity_done(NMDevice *device, NMDeviceConnectivityHandle *handle, NMConnectivityState state, - GError * error, + GError *error, gpointer user_data) { ConnectivityCheckData *data = user_data; - NMManager * self; - NMManagerPrivate * priv; + NMManager *self; + NMManagerPrivate *priv; nm_assert(data); nm_assert(data->remaining > 0); @@ -6737,16 +6725,16 @@ device_connectivity_done(NMDevice * device, } static void -check_connectivity_auth_done_cb(NMAuthChain * chain, +check_connectivity_auth_done_cb(NMAuthChain *chain, GDBusMethodInvocation *context, gpointer user_data) { - NMManager * self = NM_MANAGER(user_data); - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); - GError * error = NULL; + NMManager *self = NM_MANAGER(user_data); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); + GError *error = NULL; NMAuthCallResult result; ConnectivityCheckData *data; - NMDevice * device; + NMDevice *device; c_list_unlink(nm_auth_chain_parent_lst_list(chain)); @@ -6783,17 +6771,17 @@ check_connectivity_auth_done_cb(NMAuthChain * chain, } static void -impl_manager_check_connectivity(NMDBusObject * obj, +impl_manager_check_connectivity(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMManager * self = NM_MANAGER(obj); + NMManager *self = NM_MANAGER(obj); NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMAuthChain * chain; + NMAuthChain *chain; chain = nm_auth_chain_new_context(invocation, check_connectivity_auth_done_cb, self); if (!chain) { @@ -6817,20 +6805,20 @@ start_factory(NMDeviceFactory *factory, gpointer user_data) gboolean nm_manager_write_device_state(NMManager *self, NMDevice *device, int *out_ifindex) { - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); int ifindex; gboolean managed; NMConfigDeviceStateManagedType managed_type; - const char * uuid = NULL; - const char * perm_hw_addr_fake = NULL; + const char *uuid = NULL; + const char *perm_hw_addr_fake = NULL; gboolean perm_hw_addr_is_fake; guint32 route_metric_default_aspired; guint32 route_metric_default_effective; NMTernary nm_owned; - NMDhcpConfig * dhcp_config; - const char * next_server = NULL; - const char * root_path = NULL; - const char * dhcp_bootfile = NULL; + NMDhcpConfig *dhcp_config; + const char *next_server = NULL; + const char *root_path = NULL; + const char *dhcp_bootfile = NULL; NM_SET_OUT(out_ifindex, 0); @@ -6900,9 +6888,9 @@ nm_manager_write_device_state(NMManager *self, NMDevice *device, int *out_ifinde void nm_manager_write_device_state_all(NMManager *self) { - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); gs_unref_hashtable GHashTable *preserve_ifindexes = NULL; - NMDevice * device; + NMDevice *device; preserve_ifindexes = g_hash_table_new(nm_direct_hash, NULL); @@ -6920,7 +6908,7 @@ nm_manager_write_device_state_all(NMManager *self) static gboolean devices_inited_cb(gpointer user_data) { - NMManager * self = user_data; + NMManager *self = user_data; NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); priv->devices_inited_id = 0; @@ -6932,7 +6920,7 @@ devices_inited_cb(gpointer user_data) gboolean nm_manager_start(NMManager *self, GError **error) { - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); NMSettingsConnection *const *connections; guint i; @@ -6966,7 +6954,7 @@ nm_manager_start(NMManager *self, GError **error) system_unmanaged_devices_changed_cb(priv->settings, NULL, self); - hostname_changed_cb(priv->hostname_manager, NULL, self); + _static_hostname_changed_cb(priv->hostname_manager, NULL, self); if (!nm_settings_start(priv->settings, error)) return FALSE; @@ -7006,7 +6994,7 @@ void nm_manager_stop(NMManager *self) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMDevice * device; + NMDevice *device; /* FIXME(shutdown): we don't do a proper shutdown yet: * - need to ensure that all pending async operations are cancelled @@ -7034,9 +7022,9 @@ nm_manager_stop(NMManager *self) static gboolean handle_firmware_changed(gpointer user_data) { - NMManager * self = NM_MANAGER(user_data); + NMManager *self = NM_MANAGER(user_data); NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMDevice * device; + NMDevice *device; priv->fw_changed_id = 0; @@ -7058,13 +7046,13 @@ handle_firmware_changed(gpointer user_data) } static void -firmware_dir_changed(GFileMonitor * monitor, - GFile * file, - GFile * other_file, +firmware_dir_changed(GFileMonitor *monitor, + GFile *file, + GFile *other_file, GFileMonitorEvent event_type, gpointer user_data) { - NMManager * self = NM_MANAGER(user_data); + NMManager *self = NM_MANAGER(user_data); NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); switch (event_type) { @@ -7092,8 +7080,8 @@ connection_metered_changed(GObject *object, NMMetered metered, gpointer user_dat static void policy_default_ac_changed(GObject *object, GParamSpec *pspec, gpointer user_data) { - NMManager * self = NM_MANAGER(user_data); - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); + NMManager *self = NM_MANAGER(user_data); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); NMActiveConnection *ac; /* Note: this assumes that it's not possible for the IP4 default @@ -7132,8 +7120,8 @@ policy_default_ac_changed(GObject *object, GParamSpec *pspec, gpointer user_data static void policy_activating_ac_changed(GObject *object, GParamSpec *pspec, gpointer user_data) { - NMManager * self = NM_MANAGER(user_data); - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); + NMManager *self = NM_MANAGER(user_data); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); NMActiveConnection *activating, *best; /* We only look at activating-ip6-ac if activating-ip4-ac @@ -7159,11 +7147,11 @@ policy_activating_ac_changed(GObject *object, GParamSpec *pspec, gpointer user_d /*****************************************************************************/ typedef struct { - NMManager * self; - NMDBusObject * obj; + NMManager *self; + NMDBusObject *obj; const NMDBusInterfaceInfoExtended *interface_info; - const NMDBusPropertyInfoExtended * property_info; - GVariant * value; + const NMDBusPropertyInfoExtended *property_info; + GVariant *value; guint64 export_version_id; } DBusSetPropertyHandle; @@ -7171,9 +7159,9 @@ typedef struct { static const char * _dbus_set_property_audit_log_get_args(NMDBusObject *obj, - const char * property_name, - GVariant * value, - char ** str_to_free) + const char *property_name, + GVariant *value, + char **str_to_free) { nm_assert(str_to_free && !*str_to_free); @@ -7223,7 +7211,7 @@ _dbus_set_property_audit_log_get_args(NMDBusObject *obj, const char *const _property_name = (property_name); \ GVariant *const _value = (value); \ const char *const _error_message = (error_message); \ - gs_free char * _args_to_free = NULL; \ + gs_free char *_args_to_free = NULL; \ \ if (NM_IS_DEVICE(_obj)) { \ nm_audit_log_device_op(_audit_op, \ @@ -7249,23 +7237,23 @@ _dbus_set_property_audit_log_get_args(NMDBusObject *obj, G_STMT_END static void -_dbus_set_property_auth_cb(NMAuthChain * chain, +_dbus_set_property_auth_cb(NMAuthChain *chain, GDBusMethodInvocation *invocation, gpointer user_data) { - DBusSetPropertyHandle *handle_data = user_data; - gs_unref_object NMDBusObject * obj = handle_data->obj; - const NMDBusInterfaceInfoExtended *interface_info = handle_data->interface_info; - const NMDBusPropertyInfoExtended * property_info = handle_data->property_info; - gs_unref_variant GVariant *value = handle_data->value; - guint64 export_version_id = handle_data->export_version_id; - gs_unref_object NMManager *self = handle_data->self; - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); - NMAuthCallResult result; - gs_free_error GError *local = NULL; - const char * error_name = NULL; - const char * error_message = NULL; - GValue gvalue; + DBusSetPropertyHandle *handle_data = user_data; + gs_unref_object NMDBusObject *obj = handle_data->obj; + const NMDBusInterfaceInfoExtended *interface_info = handle_data->interface_info; + const NMDBusPropertyInfoExtended *property_info = handle_data->property_info; + gs_unref_variant GVariant *value = handle_data->value; + guint64 export_version_id = handle_data->export_version_id; + gs_unref_object NMManager *self = handle_data->self; + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); + NMAuthCallResult result; + gs_free_error GError *local = NULL; + const char *error_name = NULL; + const char *error_message = NULL; + GValue gvalue; g_slice_free(DBusSetPropertyHandle, handle_data); @@ -7319,21 +7307,21 @@ out: } void -nm_manager_dbus_set_property_handle(NMDBusObject * obj, +nm_manager_dbus_set_property_handle(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusPropertyInfoExtended * property_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * value, + const NMDBusPropertyInfoExtended *property_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *value, gpointer user_data) { - NMManager * self = user_data; - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMAuthChain * chain; - const char * error_message = NULL; - gs_unref_object NMAuthSubject *subject = NULL; - DBusSetPropertyHandle * handle_data; + NMManager *self = user_data; + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); + NMAuthChain *chain; + const char *error_message = NULL; + gs_unref_object NMAuthSubject *subject = NULL; + DBusSetPropertyHandle *handle_data; /* we only have writable properties on Device or Manager. In the future, * we probably should not add new API with writable properties. Add @@ -7386,16 +7374,16 @@ _checkpoint_mgr_get(NMManager *self, gboolean create_as_needed) static void checkpoint_auth_done_cb(NMAuthChain *chain, GDBusMethodInvocation *context, gpointer user_data) { - NMManager * self = NM_MANAGER(user_data); - char * op; - char * checkpoint_path = NULL; - char ** devices; - NMCheckpoint * checkpoint; + NMManager *self = NM_MANAGER(user_data); + char *op; + char *checkpoint_path = NULL; + char **devices; + NMCheckpoint *checkpoint; NMAuthCallResult result; guint32 timeout, flags; - GVariant * variant = NULL; - GError * error = NULL; - const char * arg = NULL; + GVariant *variant = NULL; + GError *error = NULL; + const char *arg = NULL; guint32 add_timeout; op = nm_auth_chain_get_data(chain, "audit-op"); @@ -7457,18 +7445,18 @@ checkpoint_auth_done_cb(NMAuthChain *chain, GDBusMethodInvocation *context, gpoi } static void -impl_manager_checkpoint_create(NMDBusObject * obj, +impl_manager_checkpoint_create(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMManager * self = NM_MANAGER(obj); + NMManager *self = NM_MANAGER(obj); NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMAuthChain * chain; - char ** devices; + NMAuthChain *chain; + char **devices; guint32 rollback_timeout; guint32 flags; @@ -7494,18 +7482,18 @@ impl_manager_checkpoint_create(NMDBusObject * obj, } static void -impl_manager_checkpoint_destroy(NMDBusObject * obj, +impl_manager_checkpoint_destroy(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMManager * self = NM_MANAGER(obj); + NMManager *self = NM_MANAGER(obj); NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMAuthChain * chain; - const char * checkpoint_path; + NMAuthChain *chain; + const char *checkpoint_path; chain = nm_auth_chain_new_context(invocation, checkpoint_auth_done_cb, self); if (!chain) { @@ -7525,18 +7513,18 @@ impl_manager_checkpoint_destroy(NMDBusObject * obj, } static void -impl_manager_checkpoint_rollback(NMDBusObject * obj, +impl_manager_checkpoint_rollback(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMManager * self = NM_MANAGER(obj); + NMManager *self = NM_MANAGER(obj); NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMAuthChain * chain; - const char * checkpoint_path; + NMAuthChain *chain; + const char *checkpoint_path; chain = nm_auth_chain_new_context(invocation, checkpoint_auth_done_cb, self); if (!chain) { @@ -7556,18 +7544,18 @@ impl_manager_checkpoint_rollback(NMDBusObject * obj, } static void -impl_manager_checkpoint_adjust_rollback_timeout(NMDBusObject * obj, +impl_manager_checkpoint_adjust_rollback_timeout(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMManager * self = NM_MANAGER(obj); + NMManager *self = NM_MANAGER(obj); NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - NMAuthChain * chain; - const char * checkpoint_path; + NMAuthChain *chain; + const char *checkpoint_path; guint32 add_timeout; chain = nm_auth_chain_new_context(invocation, checkpoint_auth_done_cb, self); @@ -7716,8 +7704,8 @@ manager_radio_user_toggled(NMManager *self, RadioState *rstate, gboolean enabled static gboolean periodic_update_active_connection_timestamps(gpointer user_data) { - NMManager * manager = NM_MANAGER(user_data); - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(manager); + NMManager *manager = NM_MANAGER(user_data); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(manager); NMActiveConnection *ac; gboolean has_time = FALSE; guint64 t = 0; @@ -7825,8 +7813,8 @@ nm_manager_setup(void) static void constructed(GObject *object) { - NMManager * self = NM_MANAGER(object); - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); + NMManager *self = NM_MANAGER(object); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); const NMConfigState *state; G_OBJECT_CLASS(nm_manager_parent_class)->constructed(object); @@ -7850,8 +7838,8 @@ constructed(GObject *object) priv->hostname_manager = g_object_ref(nm_hostname_manager_get()); g_signal_connect(priv->hostname_manager, - "notify::" NM_HOSTNAME_MANAGER_HOSTNAME, - G_CALLBACK(hostname_changed_cb), + "notify::" NM_HOSTNAME_MANAGER_STATIC_HOSTNAME, + G_CALLBACK(_static_hostname_changed_cb), self); /* @@ -7917,7 +7905,7 @@ nm_manager_init(NMManager *self) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); guint i; - GFile * file; + GFile *file; c_list_init(&priv->auth_lst_head); c_list_init(&priv->link_cb_lst); @@ -7992,14 +7980,14 @@ nm_manager_init(NMManager *self) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMManager * self = NM_MANAGER(object); - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); - NMConfigData * config_data; + NMManager *self = NM_MANAGER(object); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); + NMConfigData *config_data; const NMGlobalDnsConfig *dns_config; - const char * type; - const char * path; - NMActiveConnection * ac; - GPtrArray * ptrarr; + const char *type; + const char *path; + NMActiveConnection *ac; + GPtrArray *ptrarr; switch (prop_id) { case PROP_VERSION: @@ -8113,10 +8101,10 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - NMManager * self = NM_MANAGER(object); - NMManagerPrivate * priv = NM_MANAGER_GET_PRIVATE(self); + NMManager *self = NM_MANAGER(object); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); NMGlobalDnsConfig *dns_config; - GError * error = NULL; + GError *error = NULL; switch (prop_id) { case PROP_WIRELESS_ENABLED: @@ -8168,9 +8156,9 @@ _deinit_device_factory(NMDeviceFactory *factory, gpointer user_data) static void dispose(GObject *object) { - NMManager * self = NM_MANAGER(object); + NMManager *self = NM_MANAGER(object); NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); - CList * iter; + CList *iter; nm_assert(c_list_is_empty(&priv->async_op_lst_head)); @@ -8239,7 +8227,9 @@ dispose(GObject *object) } if (priv->hostname_manager) { - g_signal_handlers_disconnect_by_func(priv->hostname_manager, hostname_changed_cb, self); + g_signal_handlers_disconnect_by_func(priv->hostname_manager, + _static_hostname_changed_cb, + self); g_clear_object(&priv->hostname_manager); } @@ -8535,7 +8525,7 @@ static const NMDBusInterfaceInfoExtended interface_info_manager = { static void nm_manager_class_init(NMManagerClass *manager_class) { - GObjectClass * object_class = G_OBJECT_CLASS(manager_class); + GObjectClass *object_class = G_OBJECT_CLASS(manager_class); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(manager_class); #if WITH_OPENVSWITCH diff --git a/src/core/nm-manager.h b/src/core/nm-manager.h index 7a8b3a1e..385cdfe0 100644 --- a/src/core/nm-manager.h +++ b/src/core/nm-manager.h @@ -117,7 +117,7 @@ const CList *nm_manager_get_active_connections(NMManager *manager); NMSettingsConnection **nm_manager_get_activatable_connections(NMManager *manager, gboolean for_auto_activation, gboolean sort, - guint * out_len); + guint *out_len); void nm_manager_write_device_state_all(NMManager *manager); gboolean nm_manager_write_device_state(NMManager *manager, NMDevice *device, int *out_ifindex); @@ -156,29 +156,29 @@ nm_manager_device_route_metric_reserve(NMManager *self, int ifindex, NMDeviceTyp void nm_manager_device_route_metric_clear(NMManager *self, int ifindex); -char *nm_manager_get_connection_iface(NMManager * self, +char *nm_manager_get_connection_iface(NMManager *self, NMConnection *connection, - NMDevice ** out_parent, - const char ** out_parent_spec, - GError ** error); + NMDevice **out_parent, + const char **out_parent_spec, + GError **error); const char *nm_manager_iface_for_uuid(NMManager *self, const char *uuid); -NMActiveConnection *nm_manager_activate_connection(NMManager * manager, - NMSettingsConnection * connection, - NMConnection * applied_connection, - const char * specific_object, - NMDevice * device, - NMAuthSubject * subject, +NMActiveConnection *nm_manager_activate_connection(NMManager *manager, + NMSettingsConnection *connection, + NMConnection *applied_connection, + const char *specific_object, + NMDevice *device, + NMAuthSubject *subject, NMActivationType activation_type, NMActivationReason activation_reason, NMActivationStateFlags initial_state_flags, - GError ** error); + GError **error); -gboolean nm_manager_deactivate_connection(NMManager * manager, +gboolean nm_manager_deactivate_connection(NMManager *manager, NMActiveConnection *active, NMDeviceStateReason reason, - GError ** error); + GError **error); void nm_manager_set_capability(NMManager *self, NMCapability cap); void nm_manager_emit_device_ifindex_changed(NMManager *self, NMDevice *device); @@ -186,13 +186,13 @@ void nm_manager_emit_device_ifindex_changed(NMManager *self, NMDevice *device); NMDevice *nm_manager_get_device(NMManager *self, const char *ifname, NMDeviceType device_type); gboolean nm_manager_remove_device(NMManager *self, const char *ifname, NMDeviceType device_type); -void nm_manager_dbus_set_property_handle(NMDBusObject * obj, +void nm_manager_dbus_set_property_handle(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusPropertyInfoExtended * property_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * value, + const NMDBusPropertyInfoExtended *property_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *value, gpointer user_data); NMMetered nm_manager_get_metered(NMManager *self); @@ -201,13 +201,13 @@ void nm_manager_notify_device_availability_maybe_changed(NMManager *self); /*****************************************************************************/ -void nm_manager_device_auth_request(NMManager * self, - NMDevice * device, - GDBusMethodInvocation * context, - NMConnection * connection, - const char * permission, +void nm_manager_device_auth_request(NMManager *self, + NMDevice *device, + GDBusMethodInvocation *context, + NMConnection *connection, + const char *permission, gboolean allow_interaction, - GCancellable * cancellable, + GCancellable *cancellable, NMManagerDeviceAuthRequestFunc callback, gpointer user_data); diff --git a/src/core/nm-netns.c b/src/core/nm-netns.c index 224070be..f120e43d 100644 --- a/src/core/nm-netns.c +++ b/src/core/nm-netns.c @@ -15,21 +15,21 @@ #include "nm-l3cfg.h" #include "libnm-platform/nm-platform.h" #include "libnm-platform/nmp-netns.h" -#include "libnm-platform/nmp-rules-manager.h" +#include "libnm-platform/nmp-route-manager.h" /*****************************************************************************/ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_PLATFORM, ); typedef struct { - NMNetns * _self_signal_user_data; - NMPlatform * platform; - NMPNetns * platform_netns; - NMPRulesManager *rules_manager; - GHashTable * l3cfgs; - GHashTable * shared_ips; + NMNetns *_self_signal_user_data; + NMPlatform *platform; + NMPNetns *platform_netns; + NMPRouteManager *route_manager; + GHashTable *l3cfgs; + GHashTable *shared_ips; CList l3cfg_signal_pending_lst_head; - GSource * signal_pending_idle_source; + GSource *signal_pending_idle_source; } NMNetnsPrivate; struct _NMNetns { @@ -79,10 +79,10 @@ nm_netns_get_platform(NMNetns *self) return NM_NETNS_GET_PRIVATE(self)->platform; } -NMPRulesManager * -nm_netns_get_rules_manager(NMNetns *self) +NMPRouteManager * +nm_netns_get_route_manager(NMNetns *self) { - return NM_NETNS_GET_PRIVATE(self)->rules_manager; + return NM_NETNS_GET_PRIVATE(self)->route_manager; } NMDedupMultiIndex * @@ -113,9 +113,9 @@ _l3cfg_data_free(gpointer ptr) static void _l3cfg_weak_notify(gpointer data, GObject *where_the_object_was) { - NMNetns * self = NM_NETNS(data); + NMNetns *self = NM_NETNS(data); NMNetnsPrivate *priv = NM_NETNS_GET_PRIVATE(data); - NML3Cfg * l3cfg = NM_L3CFG(where_the_object_was); + NML3Cfg *l3cfg = NM_L3CFG(where_the_object_was); int ifindex = nm_l3cfg_get_ifindex(l3cfg); if (!g_hash_table_remove(priv->l3cfgs, &ifindex)) @@ -126,7 +126,7 @@ _l3cfg_weak_notify(gpointer data, GObject *where_the_object_was) } NML3Cfg * -nm_netns_get_l3cfg(NMNetns *self, int ifindex) +nm_netns_l3cfg_get(NMNetns *self, int ifindex) { NMNetnsPrivate *priv; @@ -139,10 +139,10 @@ nm_netns_get_l3cfg(NMNetns *self, int ifindex) } NML3Cfg * -nm_netns_access_l3cfg(NMNetns *self, int ifindex) +nm_netns_l3cfg_acquire(NMNetns *self, int ifindex) { NMNetnsPrivate *priv; - L3CfgData * l3cfg_data; + L3CfgData *l3cfg_data; g_return_val_if_fail(NM_IS_NETNS(self), NULL); g_return_val_if_fail(ifindex > 0, NULL); @@ -185,8 +185,8 @@ static gboolean _platform_signal_on_idle_cb(gpointer user_data) { gs_unref_object NMNetns *self = g_object_ref(NM_NETNS(user_data)); - NMNetnsPrivate * priv = NM_NETNS_GET_PRIVATE(self); - L3CfgData * l3cfg_data; + NMNetnsPrivate *priv = NM_NETNS_GET_PRIVATE(self); + L3CfgData *l3cfg_data; CList work_list; nm_clear_g_source_inst(&priv->signal_pending_idle_source); @@ -214,18 +214,18 @@ _platform_signal_on_idle_cb(gpointer user_data) } static void -_platform_signal_cb(NMPlatform * platform, +_platform_signal_cb(NMPlatform *platform, int obj_type_i, int ifindex, gconstpointer platform_object, int change_type_i, - NMNetns ** p_self) + NMNetns **p_self) { - NMNetns * self = NM_NETNS(*p_self); - NMNetnsPrivate * priv = NM_NETNS_GET_PRIVATE(self); + NMNetns *self = NM_NETNS(*p_self); + NMNetnsPrivate *priv = NM_NETNS_GET_PRIVATE(self); const NMPObjectType obj_type = obj_type_i; const NMPlatformSignalChangeType change_type = change_type_i; - L3CfgData * l3cfg_data; + L3CfgData *l3cfg_data; l3cfg_data = g_hash_table_lookup(priv->l3cfgs, &ifindex); if (!l3cfg_data) @@ -250,7 +250,7 @@ _platform_signal_cb(NMPlatform * platform, NMNetnsSharedIPHandle * nm_netns_shared_ip_reserve(NMNetns *self) { - NMNetnsPrivate * priv; + NMNetnsPrivate *priv; NMNetnsSharedIPHandle *handle; const in_addr_t addr_start = ntohl(0x0a2a0001u); /* 10.42.0.1 */ in_addr_t addr; @@ -312,7 +312,7 @@ nm_netns_shared_ip_reserve(NMNetns *self) void nm_netns_shared_ip_release(NMNetnsSharedIPHandle *handle) { - NMNetns * self; + NMNetns *self; NMNetnsPrivate *priv; char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN]; @@ -356,7 +356,7 @@ nm_netns_shared_ip_release(NMNetnsSharedIPHandle *handle) static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - NMNetns * self = NM_NETNS(object); + NMNetns *self = NM_NETNS(object); NMNetnsPrivate *priv = NM_NETNS_GET_PRIVATE(self); switch (prop_id) { @@ -387,7 +387,7 @@ nm_netns_init(NMNetns *self) static void constructed(GObject *object) { - NMNetns * self = NM_NETNS(object); + NMNetns *self = NM_NETNS(object); NMNetnsPrivate *priv = NM_NETNS_GET_PRIVATE(self); if (!priv->platform) @@ -397,14 +397,14 @@ constructed(GObject *object) priv->platform_netns = nm_platform_netns_get(priv->platform); - priv->rules_manager = nmp_rules_manager_new(priv->platform); + priv->route_manager = nmp_route_manager_new(priv->platform); /* Weakly track the default rules with a dummy user-tag. These * rules are always weekly tracked... */ - nmp_rules_manager_track_default(priv->rules_manager, - AF_UNSPEC, - 0, - nm_netns_parent_class /* static dummy user-tag */); + nmp_route_manager_track_rule_default(priv->route_manager, + AF_UNSPEC, + 0, + nm_netns_parent_class /* static dummy user-tag */); /* Also weakly track all existing rules. These were added before NetworkManager * starts, so they are probably none of NetworkManager's business. @@ -414,12 +414,12 @@ constructed(GObject *object) * of NetworkManager, we just don't know. * * For that reason, whenever we will touch such rules later one, we make them - * fully owned and no longer weekly tracked. See %NMP_RULES_MANAGER_EXTERN_WEAKLY_TRACKED_USER_TAG. */ - nmp_rules_manager_track_from_platform(priv->rules_manager, - NULL, - AF_UNSPEC, - 0, - NMP_RULES_MANAGER_EXTERN_WEAKLY_TRACKED_USER_TAG); + * fully owned and no longer weekly tracked. See %NMP_ROUTE_MANAGER_EXTERN_WEAKLY_TRACKED_USER_TAG. */ + nmp_route_manager_track_rule_from_platform(priv->route_manager, + NULL, + AF_UNSPEC, + 0, + NMP_ROUTE_MANAGER_EXTERN_WEAKLY_TRACKED_USER_TAG); G_OBJECT_CLASS(nm_netns_parent_class)->constructed(object); @@ -454,7 +454,7 @@ nm_netns_new(NMPlatform *platform) static void dispose(GObject *object) { - NMNetns * self = NM_NETNS(object); + NMNetns *self = NM_NETNS(object); NMNetnsPrivate *priv = NM_NETNS_GET_PRIVATE(self); nm_assert(nm_g_hash_table_size(priv->l3cfgs) == 0); @@ -469,7 +469,7 @@ dispose(GObject *object) g_clear_object(&priv->platform); nm_clear_pointer(&priv->l3cfgs, g_hash_table_unref); - nm_clear_pointer(&priv->rules_manager, nmp_rules_manager_unref); + nm_clear_pointer(&priv->route_manager, nmp_route_manager_unref); G_OBJECT_CLASS(nm_netns_parent_class)->dispose(object); } diff --git a/src/core/nm-netns.h b/src/core/nm-netns.h index 78a9121a..deb1d1f0 100644 --- a/src/core/nm-netns.h +++ b/src/core/nm-netns.h @@ -27,24 +27,24 @@ NMNetns *nm_netns_get(void); NMNetns *nm_netns_new(struct _NMPlatform *platform); struct _NMPlatform *nm_netns_get_platform(NMNetns *self); -NMPNetns * nm_netns_get_platform_netns(NMNetns *self); +NMPNetns *nm_netns_get_platform_netns(NMNetns *self); -struct _NMPRulesManager *nm_netns_get_rules_manager(NMNetns *self); +struct _NMPRouteManager *nm_netns_get_route_manager(NMNetns *self); struct _NMDedupMultiIndex *nm_netns_get_multi_idx(NMNetns *self); #define NM_NETNS_GET (nm_netns_get()) -NML3Cfg *nm_netns_get_l3cfg(NMNetns *self, int ifindex); +NML3Cfg *nm_netns_l3cfg_get(NMNetns *self, int ifindex); -NML3Cfg *nm_netns_access_l3cfg(NMNetns *netns, int ifindex); +NML3Cfg *nm_netns_l3cfg_acquire(NMNetns *netns, int ifindex); /*****************************************************************************/ typedef struct { in_addr_t addr; int _ref_count; - NMNetns * _self; + NMNetns *_self; } NMNetnsSharedIPHandle; NMNetnsSharedIPHandle *nm_netns_shared_ip_reserve(NMNetns *self); diff --git a/src/core/nm-pacrunner-manager.c b/src/core/nm-pacrunner-manager.c index 67930dba..5ef425bb 100644 --- a/src/core/nm-pacrunner-manager.c +++ b/src/core/nm-pacrunner-manager.c @@ -7,15 +7,14 @@ #include "nm-pacrunner-manager.h" -#include "nm-utils.h" -#include "NetworkManagerUtils.h" -#include "libnm-platform/nm-platform.h" -#include "nm-dbus-manager.h" -#include "nm-proxy-config.h" -#include "nm-ip4-config.h" -#include "nm-ip6-config.h" #include "c-list/src/c-list.h" #include "libnm-glib-aux/nm-dbus-aux.h" +#include "libnm-platform/nm-platform.h" + +#include "NetworkManagerUtils.h" +#include "nm-dbus-manager.h" +#include "nm-l3-config-data.h" +#include "nm-utils.h" #define PACRUNNER_DBUS_SERVICE "org.pacrunner" #define PACRUNNER_DBUS_INTERFACE "org.pacrunner.Manager" @@ -30,14 +29,14 @@ struct _NMPacrunnerConfId { GVariant *parameters; - char * path; + char *path; guint64 log_id; guint refcount; }; typedef struct { GDBusConnection *dbus_connection; - GCancellable * cancellable; + GCancellable *cancellable; CList conf_id_lst_head; guint64 log_id_counter; guint name_owner_changed_id; @@ -86,8 +85,8 @@ NM_DEFINE_SINGLETON_GETTER(NMPacrunnerManager, nm_pacrunner_manager_get, NM_TYPE /*****************************************************************************/ static void _call_destroy_proxy_configuration(NMPacrunnerManager *self, - NMPacrunnerConfId * conf_id, - const char * path, + NMPacrunnerConfId *conf_id, + const char *path, gboolean verbose_log); /*****************************************************************************/ @@ -124,58 +123,48 @@ NM_AUTO_DEFINE_FCN0(NMPacrunnerConfId *, _nm_auto_unref_conf_id, conf_id_unref); /*****************************************************************************/ static void -get_ip_domains(GPtrArray *domains, NMIPConfig *ip_config) +get_ip_domains(GPtrArray *domains, const NML3ConfigData *l3cd, int addr_family) { NMDedupMultiIter ipconf_iter; - char * cidr; - guint i, num; + char *cidr; + guint num; + guint i; char sbuf[NM_UTILS_INET_ADDRSTRLEN]; - int addr_family; const NMPlatformIPAddress *address; - const NMPlatformIPRoute * routes; - - if (!ip_config) - return; - - addr_family = nm_ip_config_get_addr_family(ip_config); + const NMPlatformIPRoute *route; + const char *const *strv; - num = nm_ip_config_get_num_searches(ip_config); + strv = nm_l3_config_data_get_searches(l3cd, addr_family, &num); for (i = 0; i < num; i++) - g_ptr_array_add(domains, g_strdup(nm_ip_config_get_search(ip_config, i))); + g_ptr_array_add(domains, g_strdup(strv[i])); - num = nm_ip_config_get_num_domains(ip_config); + strv = nm_l3_config_data_get_domains(l3cd, addr_family, &num); for (i = 0; i < num; i++) - g_ptr_array_add(domains, g_strdup(nm_ip_config_get_domain(ip_config, i))); + g_ptr_array_add(domains, g_strdup(strv[i])); - nm_ip_config_iter_ip_address_for_each (&ipconf_iter, ip_config, &address) { + nm_l3_config_data_iter_ip_address_for_each (&ipconf_iter, l3cd, addr_family, &address) { cidr = g_strdup_printf("%s/%u", nm_utils_inet_ntop(addr_family, address->address_ptr, sbuf), address->plen); g_ptr_array_add(domains, cidr); } - nm_ip_config_iter_ip_route_for_each (&ipconf_iter, ip_config, &routes) { - if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT(routes)) + nm_l3_config_data_iter_ip_route_for_each (&ipconf_iter, l3cd, addr_family, &route) { + if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT(route)) continue; cidr = g_strdup_printf("%s/%u", - nm_utils_inet_ntop(addr_family, routes->network_ptr, sbuf), - routes->plen); + nm_utils_inet_ntop(addr_family, route->network_ptr, sbuf), + route->plen); g_ptr_array_add(domains, cidr); } } static GVariant * -_make_request_create_proxy_configuration(NMProxyConfig *proxy_config, - const char * iface, - NMIP4Config * ip4_config, - NMIP6Config * ip6_config) +_make_request_create_proxy_configuration(const char *iface, const NML3ConfigData *l3cd) { GVariantBuilder builder; NMProxyConfigMethod method; - const char * pac_url; - const char * pac_script; - - nm_assert(NM_IS_PROXY_CONFIG(proxy_config)); + const char *s; g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT); @@ -183,20 +172,19 @@ _make_request_create_proxy_configuration(NMProxyConfig *proxy_config, g_variant_builder_add(&builder, "{sv}", "Interface", g_variant_new_string(iface)); } - method = nm_proxy_config_get_method(proxy_config); + method = l3cd ? nm_l3_config_data_get_proxy_method(l3cd) : NM_PROXY_CONFIG_METHOD_UNKNOWN; + switch (method) { case NM_PROXY_CONFIG_METHOD_AUTO: g_variant_builder_add(&builder, "{sv}", "Method", g_variant_new_string("auto")); - pac_url = nm_proxy_config_get_pac_url(proxy_config); - if (pac_url) { - g_variant_builder_add(&builder, "{sv}", "URL", g_variant_new_string(pac_url)); - } + s = nm_l3_config_data_get_proxy_pac_url(l3cd); + if (s) + g_variant_builder_add(&builder, "{sv}", "URL", g_variant_new_string(s)); - pac_script = nm_proxy_config_get_pac_script(proxy_config); - if (pac_script) { - g_variant_builder_add(&builder, "{sv}", "Script", g_variant_new_string(pac_script)); - } + s = nm_l3_config_data_get_proxy_pac_script(l3cd); + if (s) + g_variant_builder_add(&builder, "{sv}", "Script", g_variant_new_string(s)); break; case NM_PROXY_CONFIG_METHOD_UNKNOWN: case NM_PROXY_CONFIG_METHOD_NONE: @@ -204,18 +192,19 @@ _make_request_create_proxy_configuration(NMProxyConfig *proxy_config, break; } - g_variant_builder_add(&builder, - "{sv}", - "BrowserOnly", - g_variant_new_boolean(nm_proxy_config_get_browser_only(proxy_config))); + g_variant_builder_add( + &builder, + "{sv}", + "BrowserOnly", + g_variant_new_boolean(l3cd ? !!nm_l3_config_data_get_proxy_browser_only(l3cd) : FALSE)); - if (ip4_config || ip6_config) { + if (l3cd) { gs_unref_ptrarray GPtrArray *domains = NULL; domains = g_ptr_array_new_with_free_func(g_free); - get_ip_domains(domains, NM_IP_CONFIG_CAST(ip4_config)); - get_ip_domains(domains, NM_IP_CONFIG_CAST(ip6_config)); + get_ip_domains(domains, l3cd, AF_INET); + get_ip_domains(domains, l3cd, AF_INET6); if (domains->len > 0) { g_variant_builder_add( @@ -235,8 +224,8 @@ static void _call_destroy_proxy_configuration_cb(GObject *source, GAsyncResult *res, gpointer user_data) { nm_auto_unref_conf_id NMPacrunnerConfId *conf_id = user_data; - gs_free_error GError *error = NULL; - gs_unref_variant GVariant *ret = NULL; + gs_free_error GError *error = NULL; + gs_unref_variant GVariant *ret = NULL; ret = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), res, &error); if (!ret) { @@ -253,10 +242,10 @@ static void _call_create_proxy_configuration_cb(GObject *source, GAsyncResult *res, gpointer user_data) { nm_auto_unref_conf_id NMPacrunnerConfId *conf_id = user_data; - NMPacrunnerManager * self = NM_PACRUNNER_MANAGER(conf_id->self); - gs_free_error GError *error = NULL; - gs_unref_variant GVariant *variant = NULL; - const char * path = NULL; + NMPacrunnerManager *self = NM_PACRUNNER_MANAGER(conf_id->self); + gs_free_error GError *error = NULL; + gs_unref_variant GVariant *variant = NULL; + const char *path = NULL; nm_assert(!conf_id->path); @@ -285,8 +274,8 @@ _call_create_proxy_configuration_cb(GObject *source, GAsyncResult *res, gpointer static void _call_destroy_proxy_configuration(NMPacrunnerManager *self, - NMPacrunnerConfId * conf_id, - const char * path, + NMPacrunnerConfId *conf_id, + const char *path, gboolean verbose_log) { NMPacrunnerManagerPrivate *priv = NM_PACRUNNER_MANAGER_GET_PRIVATE(self); @@ -310,7 +299,7 @@ _call_destroy_proxy_configuration(NMPacrunnerManager *self, static void _call_create_proxy_configuration(NMPacrunnerManager *self, - NMPacrunnerConfId * conf_id, + NMPacrunnerConfId *conf_id, gboolean verbose_log) { NMPacrunnerManagerPrivate *priv = NM_PACRUNNER_MANAGER_GET_PRIVATE(self); @@ -356,10 +345,8 @@ _try_start_service_by_name(NMPacrunnerManager *self) /** * nm_pacrunner_manager_add: * @self: the #NMPacrunnerManager - * @proxy_config: proxy config of the connection * @iface: the iface for the connection or %NULL - * @ip4_config: IP4 config of the connection to extract domain info from - * @ip6_config: IP6 config of the connection to extract domain info from + * @l3cd: the #NML3ConfigData of the connection to extract domain info from * * Returns: a #NMPacrunnerConfId id. The function cannot * fail and always returns a non NULL pointer. The conf-id may @@ -367,18 +354,13 @@ _try_start_service_by_name(NMPacrunnerManager *self) * Note that the conf-id keeps the @self instance alive. */ NMPacrunnerConfId * -nm_pacrunner_manager_add(NMPacrunnerManager *self, - NMProxyConfig * proxy_config, - const char * iface, - NMIP4Config * ip4_config, - NMIP6Config * ip6_config) +nm_pacrunner_manager_add(NMPacrunnerManager *self, const char *iface, const NML3ConfigData *l3cd) { NMPacrunnerManagerPrivate *priv; - NMPacrunnerConfId * conf_id; - gs_free char * log_msg = NULL; + NMPacrunnerConfId *conf_id; + gs_free char *log_msg = NULL; g_return_val_if_fail(NM_IS_PACRUNNER_MANAGER(self), NULL); - g_return_val_if_fail(proxy_config, NULL); priv = NM_PACRUNNER_MANAGER_GET_PRIVATE(self); @@ -387,8 +369,7 @@ nm_pacrunner_manager_add(NMPacrunnerManager *self, .log_id = ++priv->log_id_counter, .refcount = 1, .self = g_object_ref(self), - .parameters = g_variant_ref_sink( - _make_request_create_proxy_configuration(proxy_config, iface, ip4_config, ip6_config)), + .parameters = g_variant_ref_sink(_make_request_create_proxy_configuration(iface, l3cd)), }; c_list_link_tail(&priv->conf_id_lst_head, &conf_id->conf_id_lst); @@ -417,8 +398,8 @@ void nm_pacrunner_manager_remove(NMPacrunnerConfId *conf_id) { _nm_unused nm_auto_unref_conf_id NMPacrunnerConfId *conf_id_free = conf_id; - NMPacrunnerManager * self; - NMPacrunnerManagerPrivate * priv; + NMPacrunnerManager *self; + NMPacrunnerManagerPrivate *priv; g_return_if_fail(conf_id); @@ -470,7 +451,7 @@ static void name_owner_changed(NMPacrunnerManager *self, const char *name_owner) { NMPacrunnerManagerPrivate *priv = NM_PACRUNNER_MANAGER_GET_PRIVATE(self); - NMPacrunnerConfId * conf_id; + NMPacrunnerConfId *conf_id; gboolean has_name_owner; has_name_owner = (name_owner && name_owner[0]); @@ -506,11 +487,11 @@ name_owner_changed(NMPacrunnerManager *self, const char *name_owner) static void name_owner_changed_cb(GDBusConnection *connection, - const char * sender_name, - const char * object_path, - const char * interface_name, - const char * signal_name, - GVariant * parameters, + const char *sender_name, + const char *object_path, + const char *interface_name, + const char *signal_name, + GVariant *parameters, gpointer user_data) { const char *new_owner; diff --git a/src/core/nm-pacrunner-manager.h b/src/core/nm-pacrunner-manager.h index fd40f120..3f16908f 100644 --- a/src/core/nm-pacrunner-manager.h +++ b/src/core/nm-pacrunner-manager.h @@ -26,11 +26,8 @@ GType nm_pacrunner_manager_get_type(void); NMPacrunnerManager *nm_pacrunner_manager_get(void); -NMPacrunnerConfId *nm_pacrunner_manager_add(NMPacrunnerManager *self, - NMProxyConfig * proxy_config, - const char * iface, - NMIP4Config * ip4_config, - NMIP6Config * ip6_config); +NMPacrunnerConfId * +nm_pacrunner_manager_add(NMPacrunnerManager *self, const char *iface, const NML3ConfigData *l3cd); void nm_pacrunner_manager_remove(NMPacrunnerConfId *conf_id); diff --git a/src/core/nm-policy.c b/src/core/nm-policy.c index 03e082f1..cb5b543e 100644 --- a/src/core/nm-policy.c +++ b/src/core/nm-policy.c @@ -11,28 +11,31 @@ #include #include +#include "libnm-core-intern/nm-core-internal.h" +#include "libnm-platform/nm-platform.h" +#include "libnm-platform/nmp-object.h" + #include "NetworkManagerUtils.h" -#include "nm-act-request.h" -#include "nm-keep-alive.h" #include "devices/nm-device.h" -#include "nm-setting-ip4-config.h" -#include "nm-setting-connection.h" -#include "libnm-platform/nm-platform.h" #include "dns/nm-dns-manager.h" -#include "vpn/nm-vpn-manager.h" +#include "nm-act-request.h" #include "nm-auth-utils.h" -#include "nm-firewalld-manager.h" +#include "nm-config.h" +#include "nm-dhcp-config.h" #include "nm-dispatcher.h" -#include "nm-utils.h" -#include "libnm-core-intern/nm-core-internal.h" +#include "nm-firewalld-manager.h" +#include "nm-hostname-manager.h" +#include "nm-keep-alive.h" +#include "nm-l3-config-data.h" #include "nm-manager.h" -#include "settings/nm-settings.h" -#include "settings/nm-settings-connection.h" -#include "settings/nm-agent-manager.h" -#include "nm-dhcp-config.h" -#include "nm-config.h" #include "nm-netns.h" -#include "nm-hostname-manager.h" +#include "nm-setting-connection.h" +#include "nm-setting-ip4-config.h" +#include "nm-utils.h" +#include "settings/nm-agent-manager.h" +#include "settings/nm-settings-connection.h" +#include "settings/nm-settings.h" +#include "vpn/nm-vpn-manager.h" /*****************************************************************************/ @@ -45,8 +48,8 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMPolicy, PROP_ACTIVATING_IP6_AC, ); typedef struct { - NMManager * manager; - NMNetns * netns; + NMManager *manager; + NMNetns *netns; NMFirewalldManager *firewalld_manager; CList pending_activation_checks; @@ -72,8 +75,8 @@ typedef struct { guint schedule_activate_all_id; /* idle handler for schedule_activate_all(). */ NMPolicyHostnameMode hostname_mode; - char * orig_hostname; /* hostname at NM start time */ - char * cur_hostname; /* hostname we want to assign */ + char *orig_hostname; /* hostname at NM start time */ + char *cur_hostname; /* hostname we want to assign */ char * last_hostname; /* last hostname NM set (to detect if someone else changed it in the meanwhile) */ @@ -136,36 +139,12 @@ static NMDevice *get_default_device(NMPolicy *self, int addr_family); /*****************************************************************************/ -static void -_dns_manager_set_ip_config(NMDnsManager * dns_manager, - NMIPConfig * ip_config, - NMDnsIPConfigType ip_config_type, - NMDevice * device) -{ - if (device && nm_device_sys_iface_state_is_external(device)) { - nm_dns_manager_set_ip_config(dns_manager, ip_config, NM_DNS_IP_CONFIG_TYPE_REMOVED); - return; - } - - if (NM_IN_SET(ip_config_type, NM_DNS_IP_CONFIG_TYPE_DEFAULT, NM_DNS_IP_CONFIG_TYPE_BEST_DEVICE) - && device - && nm_device_get_route_metric_default(nm_device_get_device_type(device)) - == NM_VPN_ROUTE_METRIC_DEFAULT) { - /* some device types are inherently VPN. */ - ip_config_type = NM_DNS_IP_CONFIG_TYPE_VPN; - } - - nm_dns_manager_set_ip_config(dns_manager, ip_config, ip_config_type); -} - -/*****************************************************************************/ - typedef struct { NMPlatformIP6Address prefix; - NMDevice * device; /* The requesting ("uplink") device */ + NMDevice *device; /* The requesting ("uplink") device */ guint64 next_subnet; /* Cache of the next subnet number to be * assigned from this prefix */ - GHashTable * subnets; /* ifindex -> NMPlatformIP6Address */ + GHashTable *subnets; /* ifindex -> NMPlatformIP6Address */ } IP6PrefixDelegation; static void @@ -201,7 +180,7 @@ clear_ip6_prefix_delegation(gpointer data) static void expire_ip6_delegations(NMPolicy *self) { - NMPolicyPrivate * priv = NM_POLICY_GET_PRIVATE(self); + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); guint32 now = nm_utils_get_monotonic_timestamp_sec(); IP6PrefixDelegation *delegation = NULL; guint i; @@ -278,7 +257,7 @@ ip6_subnet_from_delegation(IP6PrefixDelegation *delegation, NMDevice *device) static void ip6_subnet_from_device(NMPolicy *self, NMDevice *from_device, NMDevice *device) { - NMPolicyPrivate * priv = NM_POLICY_GET_PRIVATE(self); + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); IP6PrefixDelegation *delegation = NULL; gboolean got_subnet = FALSE; guint have_prefixes = 0; @@ -310,7 +289,7 @@ ip6_subnet_from_device(NMPolicy *self, NMDevice *from_device, NMDevice *device) static void ip6_remove_device_prefix_delegations(NMPolicy *self, NMDevice *device) { - NMPolicyPrivate * priv = NM_POLICY_GET_PRIVATE(self); + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); IP6PrefixDelegation *delegation = NULL; guint i; @@ -322,16 +301,16 @@ ip6_remove_device_prefix_delegations(NMPolicy *self, NMDevice *device) } static void -device_ip6_prefix_delegated(NMDevice * device, +device_ip6_prefix_delegated(NMDevice *device, const NMPlatformIP6Address *prefix, gpointer user_data) { - NMPolicyPrivate * priv = user_data; - NMPolicy * self = _PRIV_TO_SELF(priv); + NMPolicyPrivate *priv = user_data; + NMPolicy *self = _PRIV_TO_SELF(priv); IP6PrefixDelegation *delegation = NULL; guint i; - const CList * tmp_list; - NMActiveConnection * ac; + const CList *tmp_list; + NMActiveConnection *ac; char sbuf[NM_UTILS_INET_ADDRSTRLEN]; _LOGI(LOGD_IP6, @@ -377,7 +356,7 @@ static void device_ip6_subnet_needed(NMDevice *device, gpointer user_data) { NMPolicyPrivate *priv = user_data; - NMPolicy * self = _PRIV_TO_SELF(priv); + NMPolicy *self = _PRIV_TO_SELF(priv); _LOGD(LOGD_IP6, "ipv6-pd: %s needs a subnet", nm_device_get_iface(device)); @@ -397,7 +376,7 @@ device_ip6_subnet_needed(NMDevice *device, gpointer user_data) static NMDevice * get_default_device(NMPolicy *self, int addr_family) { - NMPolicyPrivate * priv = NM_POLICY_GET_PRIVATE(self); + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); NMActiveConnection *ac; nm_assert_addr_family(addr_family); @@ -410,9 +389,9 @@ get_default_device(NMPolicy *self, int addr_family) static NMActiveConnection * get_best_active_connection(NMPolicy *self, int addr_family, gboolean fully_activated) { - NMPolicyPrivate * priv = NM_POLICY_GET_PRIVATE(self); - const CList * tmp_lst; - NMDevice * device; + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); + const CList *tmp_lst; + NMDevice *device; guint32 best_metric = G_MAXUINT32; gboolean best_is_fully_activated = FALSE; NMActiveConnection *best_ac, *prev_ac; @@ -427,9 +406,9 @@ get_best_active_connection(NMPolicy *self, int addr_family, gboolean fully_activ nm_manager_for_each_device (priv->manager, device, tmp_lst) { NMDeviceState state; - const NMPObject * r; + const NMPObject *r; NMActiveConnection *ac; - NMConnection * connection; + NMConnection *connection; guint32 metric; gboolean is_fully_activated; @@ -481,8 +460,8 @@ static gboolean all_devices_not_active(NMPolicy *self) { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); - const CList * tmp_lst; - NMDevice * device; + const CList *tmp_lst; + NMDevice *device; nm_manager_for_each_device (priv->manager, device, tmp_lst) { NMDeviceState state; @@ -501,7 +480,7 @@ all_devices_not_active(NMPolicy *self) static void settings_set_hostname_cb(const char *hostname, gboolean result, gpointer user_data) { - NMPolicy * self = NM_POLICY(user_data); + NMPolicy *self = NM_POLICY(user_data); NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); int ret = 0; int errsv; @@ -535,7 +514,7 @@ static char * _get_hostname(NMPolicy *self) { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); - char * hostname = NULL; + char *hostname = NULL; int errsv; /* If there is an in-progress hostname change, return @@ -580,8 +559,8 @@ static void _set_hostname(NMPolicy *self, const char *new_hostname, const char *msg) { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); - gs_free char * old_hostname = NULL; - const char * name; + gs_free char *old_hostname = NULL; + const char *name; /* The incoming hostname *can* be NULL, which will get translated to * 'localhost.localdomain' or such in the hostname policy code, but we @@ -721,14 +700,14 @@ device_get_hostname_priority(NMDevice *device) static GArray * build_device_hostname_infos(NMPolicy *self) { - NMPolicyPrivate * priv = NM_POLICY_GET_PRIVATE(self); - const CList * tmp_clist; + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); + const CList *tmp_clist; NMActiveConnection *ac; - GArray * array = NULL; + GArray *array = NULL; nm_manager_for_each_active_connection (priv->manager, ac, tmp_clist) { DeviceHostnameInfo *info; - NMDevice * device; + NMDevice *device; gboolean only_from_default; gboolean is_default; int IS_IPv4; @@ -798,14 +777,14 @@ device_dns_lookup_done(NMDevice *device, gpointer user_data) static void update_system_hostname(NMPolicy *self, const char *msg) { - NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); - const char * configured_hostname; - gs_free char * temp_hostname = NULL; - const char * dhcp_hostname, *p; - gboolean external_hostname = FALSE; - NMDhcpConfig * dhcp_config; + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); + const char *configured_hostname; + gs_free char *temp_hostname = NULL; + const char *dhcp_hostname, *p; + gboolean external_hostname = FALSE; + NMDhcpConfig *dhcp_config; gs_unref_array GArray *infos = NULL; - DeviceHostnameInfo * info; + DeviceHostnameInfo *info; guint i; int addr_family; @@ -851,7 +830,7 @@ update_system_hostname(NMPolicy *self, const char *msg) */ /* Try a persistent hostname first */ - configured_hostname = nm_hostname_manager_get_hostname(priv->hostname_manager); + configured_hostname = nm_hostname_manager_get_static_hostname(priv->hostname_manager); if (configured_hostname && nm_utils_is_specific_hostname(configured_hostname)) { _set_hostname(self, configured_hostname, "from system configuration"); priv->dhcp_hostname = FALSE; @@ -956,8 +935,8 @@ update_system_hostname(NMPolicy *self, const char *msg) static void update_default_ac(NMPolicy *self, int addr_family, NMActiveConnection *best) { - NMPolicyPrivate * priv = NM_POLICY_GET_PRIVATE(self); - const CList * tmp_list; + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); + const CList *tmp_list; NMActiveConnection *ac; /* Clear the 'default[6]' flag on all active connections that aren't the new @@ -974,28 +953,29 @@ update_default_ac(NMPolicy *self, int addr_family, NMActiveConnection *best) nm_active_connection_set_default(best, addr_family, TRUE); } -static gpointer -get_best_ip_config(NMPolicy * self, +static const NML3ConfigData * +get_best_ip_config(NMPolicy *self, int addr_family, - const char ** out_ip_iface, + const char **out_ip_iface, NMActiveConnection **out_ac, - NMDevice ** out_device, - NMVpnConnection ** out_vpn) + NMDevice **out_device, + NMVpnConnection **out_vpn) { - NMPolicyPrivate * priv = NM_POLICY_GET_PRIVATE(self); - gpointer conf, best_conf = NULL; - const CList * tmp_list; - NMActiveConnection *ac; - guint64 best_metric = G_MAXUINT64; - NMVpnConnection * best_vpn = NULL; + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); + const NML3ConfigData *l3cd_best = NULL; + const CList *tmp_list; + NMActiveConnection *ac; + guint64 best_metric = G_MAXUINT64; + NMVpnConnection *best_vpn = NULL; nm_assert(NM_IN_SET(addr_family, AF_INET, AF_INET6)); nm_manager_for_each_active_connection (priv->manager, ac, tmp_list) { - NMVpnConnection * candidate; - NMVpnConnectionState vpn_state; - const NMPObject * obj; - guint32 metric; + const NML3ConfigData *l3cd; + NMVpnConnection *candidate; + NMVpnConnectionState vpn_state; + const NMPObject *obj; + guint32 metric; if (!NM_IS_VPN_CONNECTION(ac)) continue; @@ -1006,24 +986,18 @@ get_best_ip_config(NMPolicy * self, if (vpn_state != NM_VPN_CONNECTION_STATE_ACTIVATED) continue; - if (addr_family == AF_INET) - conf = nm_vpn_connection_get_ip4_config(candidate); - else - conf = nm_vpn_connection_get_ip6_config(candidate); - if (!conf) + l3cd = nm_vpn_connection_get_l3cd(candidate); + if (!l3cd) continue; - if (addr_family == AF_INET) - obj = nm_ip4_config_best_default_route_get(conf); - else - obj = nm_ip6_config_best_default_route_get(conf); + obj = nm_l3_config_data_get_best_default_route(l3cd, addr_family); if (!obj) continue; metric = NMP_OBJECT_CAST_IPX_ROUTE(obj)->rx.metric; if (metric <= best_metric) { best_metric = metric; - best_conf = conf; + l3cd_best = l3cd; best_vpn = candidate; } } @@ -1033,25 +1007,20 @@ get_best_ip_config(NMPolicy * self, NM_SET_OUT(out_vpn, best_vpn); NM_SET_OUT(out_ac, NM_ACTIVE_CONNECTION(best_vpn)); NM_SET_OUT(out_ip_iface, nm_vpn_connection_get_ip_iface(best_vpn, TRUE)); - return best_conf; + return l3cd_best; } ac = get_best_active_connection(self, addr_family, TRUE); if (ac) { NMDevice *device = nm_active_connection_get_device(ac); - nm_assert(device); - - if (addr_family == AF_INET) - conf = nm_device_get_ip4_config(device); - else - conf = nm_device_get_ip6_config(device); + nm_assert(NM_IS_DEVICE(device)); NM_SET_OUT(out_device, device); NM_SET_OUT(out_vpn, NULL); NM_SET_OUT(out_ac, ac); NM_SET_OUT(out_ip_iface, nm_device_get_ip_iface(device)); - return conf; + return nm_device_get_l3cd(device, TRUE); } NM_SET_OUT(out_device, NULL); @@ -1064,13 +1033,11 @@ get_best_ip_config(NMPolicy * self, static void update_ip4_routing(NMPolicy *self, gboolean force_update) { - NMPolicyPrivate * priv = NM_POLICY_GET_PRIVATE(self); - NMDevice * best = NULL; - NMVpnConnection * vpn = NULL; + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); + NMDevice *best = NULL; + NMVpnConnection *vpn = NULL; NMActiveConnection *best_ac = NULL; - const char * ip_iface = NULL; - const CList * tmp_list; - NMActiveConnection *ac; + const char *ip_iface = NULL; /* Note that we might have an IPv4 VPN tunneled over an IPv6-only device, * so we can get (vpn != NULL && best == NULL). @@ -1088,9 +1055,11 @@ update_ip4_routing(NMPolicy *self, gboolean force_update) return; if (best) { + const CList *tmp_list; + NMActiveConnection *ac; + nm_manager_for_each_active_connection (priv->manager, ac, tmp_list) { - if (NM_IS_VPN_CONNECTION(ac) && nm_vpn_connection_get_ip4_config(NM_VPN_CONNECTION(ac)) - && !nm_active_connection_get_device(ac)) + if (NM_IS_VPN_CONNECTION(ac) && !nm_active_connection_get_device(ac)) nm_active_connection_set_device(ac, best); } } @@ -1111,10 +1080,10 @@ update_ip4_routing(NMPolicy *self, gboolean force_update) static void update_ip6_prefix_delegation(NMPolicy *self) { - NMPolicyPrivate * priv = NM_POLICY_GET_PRIVATE(self); - NMDevice * device; + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); + NMDevice *device; NMActiveConnection *ac; - const CList * tmp_list; + const CList *tmp_list; /* There's new default IPv6 connection, try to get a prefix for everyone. */ nm_manager_for_each_active_connection (priv->manager, ac, tmp_list) { @@ -1127,13 +1096,11 @@ update_ip6_prefix_delegation(NMPolicy *self) static void update_ip6_routing(NMPolicy *self, gboolean force_update) { - NMPolicyPrivate * priv = NM_POLICY_GET_PRIVATE(self); - NMDevice * best = NULL; - NMVpnConnection * vpn = NULL; + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); + NMDevice *best = NULL; + NMVpnConnection *vpn = NULL; NMActiveConnection *best_ac = NULL; - const char * ip_iface = NULL; - NMActiveConnection *ac; - const CList * tmp_list; + const char *ip_iface = NULL; /* Note that we might have an IPv6 VPN tunneled over an IPv4-only device, * so we can get (vpn != NULL && best == NULL). @@ -1151,9 +1118,11 @@ update_ip6_routing(NMPolicy *self, gboolean force_update) return; if (best) { + const CList *tmp_list; + NMActiveConnection *ac; + nm_manager_for_each_active_connection (priv->manager, ac, tmp_list) { - if (NM_IS_VPN_CONNECTION(ac) && nm_vpn_connection_get_ip6_config(NM_VPN_CONNECTION(ac)) - && !nm_active_connection_get_device(ac)) + if (NM_IS_VPN_CONNECTION(ac) && !nm_active_connection_get_device(ac)) nm_active_connection_set_device(ac, best); } } @@ -1176,30 +1145,43 @@ update_ip6_routing(NMPolicy *self, gboolean force_update) static void update_ip_dns(NMPolicy *self, int addr_family, NMDevice *changed_device) { - NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); - gpointer ip_config; - const char * ip_iface = NULL; - NMVpnConnection *vpn = NULL; - NMDevice * device = NULL; + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); + const NML3ConfigData *l3cd; + const char *ip_iface = NULL; + NMVpnConnection *vpn = NULL; + NMDevice *device = NULL; nm_assert_addr_family(addr_family); - ip_config = get_best_ip_config(self, addr_family, &ip_iface, NULL, &device, &vpn); - if (ip_config) { + l3cd = get_best_ip_config(self, addr_family, &ip_iface, NULL, &device, &vpn); + if (l3cd) { + NMDnsIPConfigType ip_config_type; + + nm_assert(!device || NM_IS_DEVICE(device)); + nm_assert(!vpn || NM_IS_VPN_CONNECTION(vpn)); + nm_assert((!!device) != (!!vpn)); + /* Tell the DNS manager this config is preferred by re-adding it with * a different IP config type. */ - _dns_manager_set_ip_config(NM_POLICY_GET_PRIVATE(self)->dns_manager, - ip_config, - (vpn || (device && nm_device_is_vpn(device))) - ? NM_DNS_IP_CONFIG_TYPE_VPN - : NM_DNS_IP_CONFIG_TYPE_BEST_DEVICE, - device); + if (device && nm_device_sys_iface_state_is_external(device)) + ip_config_type = NM_DNS_IP_CONFIG_TYPE_REMOVED; + else if (vpn || (device && nm_device_is_vpn(device))) + ip_config_type = NM_DNS_IP_CONFIG_TYPE_VPN; + else + ip_config_type = NM_DNS_IP_CONFIG_TYPE_BEST_DEVICE; + + nm_dns_manager_set_ip_config(NM_POLICY_GET_PRIVATE(self)->dns_manager, + addr_family, + ((gconstpointer) device) ?: ((gconstpointer) vpn), + l3cd, + ip_config_type, + TRUE); } if (addr_family == AF_INET6) { NMActiveConnection *ac; - const CList * tmp_list; + const CList *tmp_list; /* Tell devices needing a subnet about the new DNS configuration */ nm_manager_for_each_active_connection (priv->manager, ac, tmp_list) { @@ -1232,7 +1214,7 @@ update_routing_and_dns(NMPolicy *self, gboolean force_update, NMDevice *changed_ static void check_activating_active_connections(NMPolicy *self) { - NMPolicyPrivate * priv = NM_POLICY_GET_PRIVATE(self); + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); NMActiveConnection *best4, *best6 = NULL; best4 = get_best_active_connection(self, AF_INET, FALSE); @@ -1272,7 +1254,7 @@ activate_data_free(ActivateData *data) static void pending_ac_gone(gpointer data, GObject *where_the_object_was) { - NMPolicy * self = NM_POLICY(data); + NMPolicy *self = NM_POLICY(data); NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); /* Active connections should reach the DEACTIVATED state @@ -1286,7 +1268,7 @@ pending_ac_gone(gpointer data, GObject *where_the_object_was) static void pending_ac_state_changed(NMActiveConnection *ac, guint state, guint reason, NMPolicy *self) { - NMPolicyPrivate * priv = NM_POLICY_GET_PRIVATE(self); + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); NMSettingsConnection *con; if (state >= NM_ACTIVE_CONNECTION_STATE_DEACTIVATING) { @@ -1316,14 +1298,14 @@ pending_ac_state_changed(NMActiveConnection *ac, guint state, guint reason, NMPo static void auto_activate_device(NMPolicy *self, NMDevice *device) { - NMPolicyPrivate * priv; - NMSettingsConnection *best_connection; - gs_free char * specific_object = NULL; - gs_free NMSettingsConnection **connections = NULL; + NMPolicyPrivate *priv; + NMSettingsConnection *best_connection; + gs_free char *specific_object = NULL; + gs_free NMSettingsConnection **connections = NULL; guint i, len; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; gs_unref_object NMAuthSubject *subject = NULL; - NMActiveConnection * ac; + NMActiveConnection *ac; nm_assert(NM_IS_POLICY(self)); nm_assert(NM_IS_DEVICE(device)); @@ -1348,9 +1330,9 @@ auto_activate_device(NMPolicy *self, NMDevice *device) best_connection = NULL; for (i = 0; i < len; i++) { NMSettingsConnection *candidate = connections[i]; - NMConnection * cand_conn; - NMSettingConnection * s_con; - const char * permission; + NMConnection *cand_conn; + NMSettingConnection *s_con; + const char *permission; if (nm_settings_connection_autoconnect_is_blocked(candidate)) continue; @@ -1436,7 +1418,7 @@ static ActivateData * find_pending_activation(NMPolicy *self, NMDevice *device) { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); - ActivateData * data; + ActivateData *data; c_list_for_each_entry (data, &priv->pending_activation_checks, pending_lst) { if (data->device == device) @@ -1449,7 +1431,7 @@ find_pending_activation(NMPolicy *self, NMDevice *device) typedef struct { NMDevice *device; - GSList * secondaries; + GSList *secondaries; } PendingSecondaryData; static PendingSecondaryData * @@ -1475,12 +1457,12 @@ static void process_secondaries(NMPolicy *self, NMActiveConnection *active, gboolean connected) { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); - GSList * iter, *iter2, *next, *next2; + GSList *iter, *iter2, *next, *next2; /* Loop through devices waiting for secondary connections to activate */ for (iter = priv->pending_secondaries; iter; iter = next) { PendingSecondaryData *secondary_data = (PendingSecondaryData *) iter->data; - NMDevice * item_device = secondary_data->device; + NMDevice *item_device = secondary_data->device; next = g_slist_next(iter); @@ -1536,10 +1518,12 @@ process_secondaries(NMPolicy *self, NMActiveConnection *active, gboolean connect } static void -hostname_changed(NMHostnameManager *hostname_manager, GParamSpec *pspec, gpointer user_data) +_static_hostname_changed_cb(NMHostnameManager *hostname_manager, + GParamSpec *pspec, + gpointer user_data) { NMPolicyPrivate *priv = user_data; - NMPolicy * self = _PRIV_TO_SELF(priv); + NMPolicy *self = _PRIV_TO_SELF(priv); update_system_hostname(self, "hostname changed"); } @@ -1547,7 +1531,7 @@ hostname_changed(NMHostnameManager *hostname_manager, GParamSpec *pspec, gpointe void nm_policy_unblock_failed_ovs_interfaces(NMPolicy *self) { - NMPolicyPrivate * priv = NM_POLICY_GET_PRIVATE(self); + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); NMSettingsConnection *const *connections = NULL; guint i; @@ -1556,7 +1540,7 @@ nm_policy_unblock_failed_ovs_interfaces(NMPolicy *self) connections = nm_settings_get_connections(priv->settings, NULL); for (i = 0; connections[i]; i++) { NMSettingsConnection *sett_conn = connections[i]; - NMConnection * connection = nm_settings_connection_get_connection(sett_conn); + NMConnection *connection = nm_settings_connection_get_connection(sett_conn); if (nm_connection_get_setting_ovs_interface(connection)) { nm_settings_connection_autoconnect_retries_reset(sett_conn); @@ -1574,7 +1558,7 @@ reset_autoconnect_all( NMDevice *device, /* if present, only reset connections compatible with @device */ gboolean only_no_secrets) { - NMPolicyPrivate * priv = NM_POLICY_GET_PRIVATE(self); + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); NMSettingsConnection *const *connections = NULL; guint i; gboolean changed = FALSE; @@ -1631,7 +1615,7 @@ static void sleeping_changed(NMManager *manager, GParamSpec *pspec, gpointer user_data) { NMPolicyPrivate *priv = user_data; - NMPolicy * self = _PRIV_TO_SELF(priv); + NMPolicy *self = _PRIV_TO_SELF(priv); gboolean sleeping = FALSE, enabled = FALSE; g_object_get(G_OBJECT(manager), NM_MANAGER_SLEEPING, &sleeping, NULL); @@ -1645,10 +1629,10 @@ sleeping_changed(NMManager *manager, GParamSpec *pspec, gpointer user_data) static void schedule_activate_check(NMPolicy *self, NMDevice *device) { - NMPolicyPrivate * priv = NM_POLICY_GET_PRIVATE(self); - ActivateData * data; + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); + ActivateData *data; NMActiveConnection *ac; - const CList * tmp_list; + const CList *tmp_list; if (nm_manager_get_state(priv->manager) == NM_STATE_ASLEEP) return; @@ -1676,8 +1660,8 @@ schedule_activate_check(NMPolicy *self, NMDevice *device) static gboolean reset_connections_retries(gpointer user_data) { - NMPolicy * self = (NMPolicy *) user_data; - NMPolicyPrivate * priv = NM_POLICY_GET_PRIVATE(self); + NMPolicy *self = (NMPolicy *) user_data; + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); NMSettingsConnection *const *connections = NULL; guint i; gint32 con_stamp, min_stamp, now; @@ -1742,12 +1726,12 @@ _connection_autoconnect_retries_set(NMPolicy *self, NMSettingsConnection *connec static void activate_slave_connections(NMPolicy *self, NMDevice *device) { - NMPolicyPrivate * priv = NM_POLICY_GET_PRIVATE(self); - const char * master_device; - const char * master_uuid_settings = NULL; - const char * master_uuid_applied = NULL; + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); + const char *master_device; + const char *master_uuid_settings = NULL; + const char *master_uuid_applied = NULL; guint i; - NMActRequest * req; + NMActRequest *req; gboolean internal_activation = FALSE; NMSettingsConnection *const *connections; gboolean changed; @@ -1757,9 +1741,9 @@ activate_slave_connections(NMPolicy *self, NMDevice *device) req = nm_device_get_act_request(device); if (req) { - NMConnection * connection; + NMConnection *connection; NMSettingsConnection *sett_conn; - NMAuthSubject * subject; + NMAuthSubject *subject; connection = nm_active_connection_get_applied_connection(NM_ACTIVE_CONNECTION(req)); if (connection) @@ -1781,8 +1765,8 @@ activate_slave_connections(NMPolicy *self, NMDevice *device) connections = nm_settings_get_connections(priv->settings, NULL); for (i = 0; connections[i]; i++) { NMSettingsConnection *sett_conn = connections[i]; - NMSettingConnection * s_slave_con; - const char * slave_master; + NMSettingConnection *s_slave_con; + const char *slave_master; s_slave_con = nm_connection_get_setting_connection(nm_settings_connection_get_connection(sett_conn)); @@ -1813,12 +1797,12 @@ activate_slave_connections(NMPolicy *self, NMDevice *device) static gboolean activate_secondary_connections(NMPolicy *self, NMConnection *connection, NMDevice *device) { - NMPolicyPrivate * priv = NM_POLICY_GET_PRIVATE(self); - NMSettingConnection * s_con; - NMActiveConnection * ac; - PendingSecondaryData * secondary_data; - GSList * secondary_ac_list = NULL; - GError * error = NULL; + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); + NMSettingConnection *s_con; + NMActiveConnection *ac; + PendingSecondaryData *secondary_data; + GSList *secondary_ac_list = NULL; + GError *error = NULL; guint32 i; gboolean success = TRUE; NMActivationStateFlags initial_state_flags; @@ -1832,8 +1816,8 @@ activate_secondary_connections(NMPolicy *self, NMConnection *connection, NMDevic for (i = 0; i < nm_setting_connection_get_num_secondaries(s_con); i++) { NMSettingsConnection *sett_conn; - const char * sec_uuid = nm_setting_connection_get_secondary(s_con, i); - NMActRequest * req; + const char *sec_uuid = nm_setting_connection_get_secondary(s_con, i); + NMActRequest *req; sett_conn = nm_settings_get_connection_by_uuid(priv->settings, sec_uuid); if (!sett_conn) { @@ -1899,19 +1883,17 @@ activate_secondary_connections(NMPolicy *self, NMConnection *connection, NMDevic } static void -device_state_changed(NMDevice * device, +device_state_changed(NMDevice *device, NMDeviceState new_state, NMDeviceState old_state, NMDeviceStateReason reason, gpointer user_data) { - NMPolicyPrivate * priv = user_data; - NMPolicy * self = _PRIV_TO_SELF(priv); - NMActiveConnection * ac; + NMPolicyPrivate *priv = user_data; + NMPolicy *self = _PRIV_TO_SELF(priv); + NMActiveConnection *ac; NMSettingsConnection *sett_conn = nm_device_get_settings_connection(device); - NMIP4Config * ip4_config; - NMIP6Config * ip6_config; - NMSettingConnection * s_con = NULL; + NMSettingConnection *s_con = NULL; switch (nm_device_state_reason_check(reason)) { case NM_DEVICE_STATE_REASON_GSM_SIM_PIN_REQUIRED: @@ -2014,26 +1996,25 @@ device_state_changed(NMDevice * device, nm_settings_connection_autoconnect_retries_reset(sett_conn); } - /* Add device's new IPv4 and IPv6 configs to DNS */ - + /* Since there is no guarantee that device_l3cd_changed() is called + * again when the device becomes ACTIVATED, we need also to update + * routing and DNS here. */ nm_dns_manager_begin_updates(priv->dns_manager, __func__); - - ip4_config = nm_device_get_ip4_config(device); - if (ip4_config) - _dns_manager_set_ip_config(priv->dns_manager, - NM_IP_CONFIG_CAST(ip4_config), - NM_DNS_IP_CONFIG_TYPE_DEFAULT, - device); - ip6_config = nm_device_get_ip6_config(device); - if (ip6_config) - _dns_manager_set_ip_config(priv->dns_manager, - NM_IP_CONFIG_CAST(ip6_config), - NM_DNS_IP_CONFIG_TYPE_DEFAULT, - device); - - update_routing_and_dns(self, FALSE, device); - + if (!nm_device_sys_iface_state_is_external(device)) { + nm_dns_manager_set_ip_config(priv->dns_manager, + AF_UNSPEC, + device, + nm_device_get_l3cd(device, TRUE), + NM_DNS_IP_CONFIG_TYPE_DEFAULT, + TRUE); + } + update_ip_dns(self, AF_INET, device); + update_ip_dns(self, AF_INET6, device); + update_ip4_routing(self, TRUE); + update_ip6_routing(self, TRUE); + update_system_hostname(self, "routing and dns"); nm_dns_manager_end_updates(priv->dns_manager, __func__); + break; case NM_DEVICE_STATE_UNMANAGED: case NM_DEVICE_STATE_UNAVAILABLE: @@ -2135,70 +2116,78 @@ device_state_changed(NMDevice * device, } static void -device_ip_config_changed(NMDevice * device, - NMIPConfig *new_config, - NMIPConfig *old_config, - gpointer user_data) +device_l3cd_changed(NMDevice *device, + const NML3ConfigData *l3cd_old, + const NML3ConfigData *l3cd_new, + gpointer user_data) { NMPolicyPrivate *priv = user_data; - NMPolicy * self = _PRIV_TO_SELF(priv); - int addr_family; + NMPolicy *self = _PRIV_TO_SELF(priv); NMDeviceState state; - nm_assert(new_config || old_config); - nm_assert(!new_config || NM_IS_IP_CONFIG(new_config)); - nm_assert(!old_config || NM_IS_IP_CONFIG(old_config)); - - if (new_config) { - addr_family = nm_ip_config_get_addr_family(new_config); - nm_assert(!old_config || addr_family == nm_ip_config_get_addr_family(old_config)); - } else - addr_family = nm_ip_config_get_addr_family(old_config); + nm_assert(!l3cd_new || NM_IS_L3_CONFIG_DATA(l3cd_new)); + nm_assert(!l3cd_old || NM_IS_L3_CONFIG_DATA(l3cd_old)); nm_dns_manager_begin_updates(priv->dns_manager, __func__); /* We catch already all the IP events registering on the device state changes but - * the ones where the IP changes but the device state keep stable (i.e., activated): + * the ones where the IP changes with a stable state (i.e., activated): * ignore IP config changes but when the device is in activated state. * Prevents unnecessary changes to DNS information. + * FIXME(l3cfg): check why ^^^ this is needed and implement it. Note that + * this function is not always called when the device becomes ACTIVATED. + * Previously, we would also update the DNS manager's IP config in + * device_state_change(ACTIVATED). There we would also special-case + * pseudo-VPNs like wireguard. I don't see the code where this is handled + * now. */ state = nm_device_get_state(device); - if (state > NM_DEVICE_STATE_IP_CONFIG && state <= NM_DEVICE_STATE_ACTIVATED) { - if (old_config != new_config) { - if (new_config) - _dns_manager_set_ip_config(priv->dns_manager, - new_config, - NM_DNS_IP_CONFIG_TYPE_DEFAULT, - device); - if (old_config) - nm_dns_manager_set_ip_config(priv->dns_manager, - old_config, - NM_DNS_IP_CONFIG_TYPE_REMOVED); - } - update_ip_dns(self, addr_family, device); - if (addr_family == AF_INET) - update_ip4_routing(self, TRUE); - else - update_ip6_routing(self, TRUE); - update_system_hostname(self, addr_family == AF_INET ? "ip4 conf" : "ip6 conf"); + if (l3cd_new && state > NM_DEVICE_STATE_IP_CONFIG && state < NM_DEVICE_STATE_DEACTIVATING) { + nm_dns_manager_set_ip_config(priv->dns_manager, + AF_UNSPEC, + device, + l3cd_new, + NM_DNS_IP_CONFIG_TYPE_DEFAULT, + TRUE); + update_ip_dns(self, AF_INET, device); + update_ip_dns(self, AF_INET6, device); + update_ip4_routing(self, TRUE); + update_ip6_routing(self, TRUE); + /* FIXME: since we already monitor platform addresses changes, + * this is probably no longer necessary? */ + update_system_hostname(self, "ip conf"); } else { - /* Old configs get removed immediately */ - if (old_config) - nm_dns_manager_set_ip_config(priv->dns_manager, - old_config, - NM_DNS_IP_CONFIG_TYPE_REMOVED); + nm_dns_manager_set_ip_config(priv->dns_manager, + AF_UNSPEC, + device, + l3cd_old, + NM_DNS_IP_CONFIG_TYPE_REMOVED, + TRUE); } nm_dns_manager_end_updates(priv->dns_manager, __func__); } +static void +device_platform_address_changed(NMDevice *device, gpointer user_data) +{ + NMPolicyPrivate *priv = user_data; + NMPolicy *self = _PRIV_TO_SELF(priv); + NMDeviceState state; + + state = nm_device_get_state(device); + if (state > NM_DEVICE_STATE_DISCONNECTED && state < NM_DEVICE_STATE_DEACTIVATING) { + update_system_hostname(self, "address changed"); + } +} + /*****************************************************************************/ static void device_autoconnect_changed(NMDevice *device, GParamSpec *pspec, gpointer user_data) { NMPolicyPrivate *priv = user_data; - NMPolicy * self = _PRIV_TO_SELF(priv); + NMPolicy *self = _PRIV_TO_SELF(priv); schedule_activate_check(self, device); } @@ -2207,7 +2196,7 @@ static void device_recheck_auto_activate(NMDevice *device, gpointer user_data) { NMPolicyPrivate *priv = user_data; - NMPolicy * self = _PRIV_TO_SELF(priv); + NMPolicy *self = _PRIV_TO_SELF(priv); schedule_activate_check(self, device); } @@ -2227,13 +2216,10 @@ devices_list_register(NMPolicy *self, NMDevice *device) /* Connect state-changed with _after, so that the handler is invoked after other handlers. */ g_signal_connect_after(device, NM_DEVICE_STATE_CHANGED, G_CALLBACK(device_state_changed), priv); + g_signal_connect(device, NM_DEVICE_L3CD_CHANGED, G_CALLBACK(device_l3cd_changed), priv); g_signal_connect(device, - NM_DEVICE_IP4_CONFIG_CHANGED, - G_CALLBACK(device_ip_config_changed), - priv); - g_signal_connect(device, - NM_DEVICE_IP6_CONFIG_CHANGED, - G_CALLBACK(device_ip_config_changed), + NM_DEVICE_PLATFORM_ADDRESS_CHANGED, + G_CALLBACK(device_platform_address_changed), priv); g_signal_connect(device, NM_DEVICE_IP6_PREFIX_DELEGATED, @@ -2257,7 +2243,7 @@ static void device_added(NMManager *manager, NMDevice *device, gpointer user_data) { NMPolicyPrivate *priv = user_data; - NMPolicy * self = _PRIV_TO_SELF(priv); + NMPolicy *self = _PRIV_TO_SELF(priv); g_return_if_fail(NM_IS_POLICY(self)); @@ -2273,8 +2259,8 @@ static void device_removed(NMManager *manager, NMDevice *device, gpointer user_data) { NMPolicyPrivate *priv = user_data; - NMPolicy * self = _PRIV_TO_SELF(priv); - ActivateData * data; + NMPolicy *self = _PRIV_TO_SELF(priv); + ActivateData *data; /* TODO: is this needed? The delegations are cleaned up * on transition to deactivated too. */ @@ -2296,51 +2282,26 @@ device_removed(NMManager *manager, NMDevice *device, gpointer user_data) /*****************************************************************************/ static void -vpn_connection_activated(NMPolicy *self, NMVpnConnection *vpn) +vpn_connection_update_dns(NMPolicy *self, NMVpnConnection *vpn, gboolean remove) { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); - NMIP4Config * ip4_config; - NMIP6Config * ip6_config; + int IS_IPv4; nm_dns_manager_begin_updates(priv->dns_manager, __func__); - ip4_config = nm_vpn_connection_get_ip4_config(vpn); - if (ip4_config) - nm_dns_manager_set_ip_config(priv->dns_manager, - NM_IP_CONFIG_CAST(ip4_config), - NM_DNS_IP_CONFIG_TYPE_VPN); + for (IS_IPv4 = 1; IS_IPv4 >= 0; IS_IPv4--) { + int addr_family = IS_IPv4 ? AF_INET : AF_INET6; + const NML3ConfigData *l3cd; - ip6_config = nm_vpn_connection_get_ip6_config(vpn); - if (ip6_config) + l3cd = nm_vpn_connection_get_l3cd(vpn); nm_dns_manager_set_ip_config(priv->dns_manager, - NM_IP_CONFIG_CAST(ip6_config), - NM_DNS_IP_CONFIG_TYPE_VPN); - - update_routing_and_dns(self, TRUE, NULL); - - nm_dns_manager_end_updates(priv->dns_manager, __func__); -} - -static void -vpn_connection_deactivated(NMPolicy *self, NMVpnConnection *vpn) -{ - NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); - NMIP4Config * ip4_config; - NMIP6Config * ip6_config; - - nm_dns_manager_begin_updates(priv->dns_manager, __func__); - - ip4_config = nm_vpn_connection_get_ip4_config(vpn); - if (ip4_config) - nm_dns_manager_set_ip_config(priv->dns_manager, - NM_IP_CONFIG_CAST(ip4_config), - NM_DNS_IP_CONFIG_TYPE_REMOVED); - - ip6_config = nm_vpn_connection_get_ip6_config(vpn); - if (ip6_config) - nm_dns_manager_set_ip_config(priv->dns_manager, - NM_IP_CONFIG_CAST(ip6_config), - NM_DNS_IP_CONFIG_TYPE_REMOVED); + addr_family, + vpn, + l3cd, + remove ? NM_DNS_IP_CONFIG_TYPE_REMOVED + : NM_DNS_IP_CONFIG_TYPE_VPN, + TRUE); + } update_routing_and_dns(self, TRUE, NULL); @@ -2348,29 +2309,30 @@ vpn_connection_deactivated(NMPolicy *self, NMVpnConnection *vpn) } static void -vpn_connection_state_changed(NMVpnConnection * vpn, +vpn_connection_state_changed(NMVpnConnection *vpn, NMVpnConnectionState new_state, NMVpnConnectionState old_state, NMActiveConnectionStateReason reason, - NMPolicy * self) + NMPolicy *self) { + /* FIXME(l3cfg): we need to track changes to nm_vpn_connection_get_l3cd(). */ if (new_state == NM_VPN_CONNECTION_STATE_ACTIVATED) - vpn_connection_activated(self, vpn); + vpn_connection_update_dns(self, vpn, FALSE); else if (new_state >= NM_VPN_CONNECTION_STATE_FAILED) { /* Only clean up IP/DNS if the connection ever got past IP_CONFIG */ if (old_state >= NM_VPN_CONNECTION_STATE_IP_CONFIG_GET && old_state <= NM_VPN_CONNECTION_STATE_ACTIVATED) - vpn_connection_deactivated(self, vpn); + vpn_connection_update_dns(self, vpn, TRUE); } } static void vpn_connection_retry_after_failure(NMVpnConnection *vpn, NMPolicy *self) { - NMPolicyPrivate * priv = NM_POLICY_GET_PRIVATE(self); - NMActiveConnection * ac = NM_ACTIVE_CONNECTION(vpn); + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); + NMActiveConnection *ac = NM_ACTIVE_CONNECTION(vpn); NMSettingsConnection *connection = nm_active_connection_get_settings_connection(ac); - GError * error = NULL; + GError *error = NULL; /* Attempt to reconnect VPN connections that failed after being connected */ if (!nm_manager_activate_connection( @@ -2407,9 +2369,9 @@ active_connection_state_changed(NMActiveConnection *active, GParamSpec *pspec, N static void active_connection_keep_alive_changed(NMKeepAlive *keep_alive, GParamSpec *pspec, NMPolicy *self) { - NMPolicyPrivate * priv; + NMPolicyPrivate *priv; NMActiveConnection *ac; - GError * error = NULL; + GError *error = NULL; nm_assert(NM_IS_POLICY(self)); nm_assert(NM_IS_KEEP_ALIVE(keep_alive)); @@ -2441,8 +2403,8 @@ static void active_connection_added(NMManager *manager, NMActiveConnection *active, gpointer user_data) { NMPolicyPrivate *priv = user_data; - NMPolicy * self = _PRIV_TO_SELF(priv); - NMKeepAlive * keep_alive; + NMPolicy *self = _PRIV_TO_SELF(priv); + NMKeepAlive *keep_alive; if (NM_IS_VPN_CONNECTION(active)) { g_signal_connect(active, @@ -2474,7 +2436,7 @@ static void active_connection_removed(NMManager *manager, NMActiveConnection *active, gpointer user_data) { NMPolicyPrivate *priv = user_data; - NMPolicy * self = _PRIV_TO_SELF(priv); + NMPolicy *self = _PRIV_TO_SELF(priv); g_signal_handlers_disconnect_by_func(active, vpn_connection_state_changed, self); g_signal_handlers_disconnect_by_func(active, vpn_connection_retry_after_failure, self); @@ -2489,10 +2451,10 @@ active_connection_removed(NMManager *manager, NMActiveConnection *active, gpoint static gboolean schedule_activate_all_cb(gpointer user_data) { - NMPolicy * self = user_data; + NMPolicy *self = user_data; NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); - const CList * tmp_lst; - NMDevice * device; + const CList *tmp_lst; + NMDevice *device; priv->schedule_activate_all_id = 0; @@ -2517,7 +2479,7 @@ static void connection_added(NMSettings *settings, NMSettingsConnection *connection, gpointer user_data) { NMPolicyPrivate *priv = user_data; - NMPolicy * self = _PRIV_TO_SELF(priv); + NMPolicy *self = _PRIV_TO_SELF(priv); schedule_activate_all(self); } @@ -2526,10 +2488,10 @@ static void firewall_state_changed(NMFirewalldManager *manager, int signal_type_i, gpointer user_data) { const NMFirewalldManagerStateChangedType signal_type = signal_type_i; - NMPolicy * self = user_data; - NMPolicyPrivate * priv = NM_POLICY_GET_PRIVATE(self); - const CList * tmp_lst; - NMDevice * device; + NMPolicy *self = user_data; + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); + const CList *tmp_lst; + NMDevice *device; if (signal_type == NM_FIREWALLD_MANAGER_STATE_CHANGED_TYPE_INITIALIZED) { /* the firewall manager was initializing, but all requests @@ -2549,10 +2511,10 @@ firewall_state_changed(NMFirewalldManager *manager, int signal_type_i, gpointer static void dns_config_changed(NMDnsManager *dns_manager, gpointer user_data) { - NMPolicy * self = (NMPolicy *) user_data; + NMPolicy *self = (NMPolicy *) user_data; NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); - NMDevice * device; - const CList * tmp_lst; + NMDevice *device; + const CList *tmp_lst; /* We are currently updating the hostname in the DNS manager. * This doesn't warrant a new DNS lookup.*/ @@ -2567,18 +2529,18 @@ dns_config_changed(NMDnsManager *dns_manager, gpointer user_data) } static void -connection_updated(NMSettings * settings, +connection_updated(NMSettings *settings, NMSettingsConnection *connection, guint update_reason_u, gpointer user_data) { - NMPolicyPrivate * priv = user_data; - NMPolicy * self = _PRIV_TO_SELF(priv); + NMPolicyPrivate *priv = user_data; + NMPolicy *self = _PRIV_TO_SELF(priv); NMSettingsConnectionUpdateReason update_reason = update_reason_u; if (NM_FLAGS_HAS(update_reason, NM_SETTINGS_CONNECTION_UPDATE_REASON_REAPPLY_PARTIAL)) { const CList *tmp_lst; - NMDevice * device; + NMDevice *device; /* find device with given connection */ nm_manager_for_each_device (priv->manager, device, tmp_lst) { @@ -2593,10 +2555,10 @@ connection_updated(NMSettings * settings, static void _deactivate_if_active(NMPolicy *self, NMSettingsConnection *connection) { - NMPolicyPrivate * priv = NM_POLICY_GET_PRIVATE(self); + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); NMActiveConnection *ac; - const CList * tmp_list, *tmp_safe; - GError * error = NULL; + const CList *tmp_list, *tmp_safe; + GError *error = NULL; nm_assert(NM_IS_SETTINGS_CONNECTION(connection)); @@ -2622,7 +2584,7 @@ static void connection_removed(NMSettings *settings, NMSettingsConnection *connection, gpointer user_data) { NMPolicyPrivate *priv = user_data; - NMPolicy * self = _PRIV_TO_SELF(priv); + NMPolicy *self = _PRIV_TO_SELF(priv); _deactivate_if_active(self, connection); } @@ -2631,7 +2593,7 @@ static void connection_flags_changed(NMSettings *settings, NMSettingsConnection *connection, gpointer user_data) { NMPolicyPrivate *priv = user_data; - NMPolicy * self = _PRIV_TO_SELF(priv); + NMPolicy *self = _PRIV_TO_SELF(priv); if (NM_FLAGS_HAS(nm_settings_connection_get_flags(connection), NM_SETTINGS_CONNECTION_INT_FLAGS_VISIBLE)) { @@ -2691,7 +2653,7 @@ static NM_UTILS_LOOKUP_STR_DEFINE(_hostname_mode_to_string, static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMPolicy * self = NM_POLICY(object); + NMPolicy *self = NM_POLICY(object); NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); switch (prop_id) { @@ -2716,7 +2678,7 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - NMPolicy * self = NM_POLICY(object); + NMPolicy *self = NM_POLICY(object); NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); switch (prop_id) { @@ -2742,7 +2704,7 @@ static void nm_policy_init(NMPolicy *self) { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); - gs_free char * hostname_mode = NULL; + gs_free char *hostname_mode = NULL; c_list_init(&priv->pending_activation_checks); @@ -2771,9 +2733,9 @@ nm_policy_init(NMPolicy *self) static void constructed(GObject *object) { - NMPolicy * self = NM_POLICY(object); + NMPolicy *self = NM_POLICY(object); NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); - char * hostname = NULL; + char *hostname = NULL; /* Grab hostname on startup and use that if nothing provides one */ if ((hostname = _get_hostname(self))) { @@ -2804,8 +2766,8 @@ constructed(GObject *object) self); g_signal_connect(priv->hostname_manager, - "notify::" NM_HOSTNAME_MANAGER_HOSTNAME, - G_CALLBACK(hostname_changed), + "notify::" NM_HOSTNAME_MANAGER_STATIC_HOSTNAME, + G_CALLBACK(_static_hostname_changed_cb), priv); g_signal_connect(priv->manager, @@ -2858,6 +2820,7 @@ constructed(GObject *object) G_OBJECT_CLASS(nm_policy_parent_class)->constructed(object); _LOGD(LOGD_DNS, "hostname-mode: %s", _hostname_mode_to_string(priv->hostname_mode)); + update_system_hostname(self, "initial hostname"); } NMPolicy * @@ -2877,11 +2840,11 @@ nm_policy_new(NMManager *manager, NMSettings *settings) static void dispose(GObject *object) { - NMPolicy * self = NM_POLICY(object); + NMPolicy *self = NM_POLICY(object); NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); GHashTableIter h_iter; - NMDevice * device; - ActivateData * data, *data_safe; + NMDevice *device; + ActivateData *data, *data_safe; nm_clear_g_object(&priv->default_ac4); nm_clear_g_object(&priv->default_ac6); @@ -2959,7 +2922,7 @@ dispose(GObject *object) static void finalize(GObject *object) { - NMPolicy * self = NM_POLICY(object); + NMPolicy *self = NM_POLICY(object); NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); g_hash_table_unref(priv->devices); diff --git a/src/core/nm-priv-helper-call.c b/src/core/nm-priv-helper-call.c index 06249ece..4f07481d 100644 --- a/src/core/nm-priv-helper-call.c +++ b/src/core/nm-priv-helper-call.c @@ -15,10 +15,10 @@ _nm_priv_helper_call_get_fd_cb(GObject *source, GAsyncResult *res, gpointer user { NMPrivHelperCallGetFDCallback callback; gpointer callback_data; - gs_unref_variant GVariant *ret = NULL; - gs_free_error GError *error = NULL; - gs_unref_object GUnixFDList *fd_list = NULL; - gs_free int * fd_arr = NULL; + gs_unref_variant GVariant *ret = NULL; + gs_free_error GError *error = NULL; + gs_unref_object GUnixFDList *fd_list = NULL; + gs_free int *fd_arr = NULL; nm_utils_user_data_unpack(user_data, &callback, &callback_data); @@ -52,7 +52,7 @@ _nm_priv_helper_call_get_fd_fail_on_idle(gpointer user_data) gs_unref_object GCancellable *cancellable = NULL; NMPrivHelperCallGetFDCallback callback; gpointer callback_data; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; nm_utils_user_data_unpack(user_data, &cancellable, &callback, &callback_data); @@ -67,7 +67,7 @@ _nm_priv_helper_call_get_fd_fail_on_idle(gpointer user_data) void nm_priv_helper_call_get_fd(NMPrivHelperGetFDType fd_type, - GCancellable * cancellable, + GCancellable *cancellable, NMPrivHelperCallGetFDCallback callback, gpointer user_data) { diff --git a/src/core/nm-priv-helper-call.h b/src/core/nm-priv-helper-call.h index 1915c5b3..334daa77 100644 --- a/src/core/nm-priv-helper-call.h +++ b/src/core/nm-priv-helper-call.h @@ -8,7 +8,7 @@ typedef void (*NMPrivHelperCallGetFDCallback)(int fd_take, GError *error, gpointer user_data); void nm_priv_helper_call_get_fd(NMPrivHelperGetFDType fd_type, - GCancellable * cancellable, + GCancellable *cancellable, NMPrivHelperCallGetFDCallback callback, gpointer user_data); diff --git a/src/core/nm-proxy-config.c b/src/core/nm-proxy-config.c deleted file mode 100644 index 49156dfa..00000000 --- a/src/core/nm-proxy-config.c +++ /dev/null @@ -1,172 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2016 Atul Anand . - */ - -#include "src/core/nm-default-daemon.h" - -#include "nm-proxy-config.h" - -#include - -#include "libnm-core-intern/nm-core-internal.h" - -/*****************************************************************************/ - -typedef struct { - NMProxyConfigMethod method; - gboolean browser_only; - char * pac_url; - char * pac_script; -} NMProxyConfigPrivate; - -struct _NMProxyConfig { - GObject parent; - NMProxyConfigPrivate _priv; -}; - -struct _NMProxyConfigClass { - GObjectClass parent; -}; - -G_DEFINE_TYPE(NMProxyConfig, nm_proxy_config, G_TYPE_OBJECT) - -#define NM_PROXY_CONFIG_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMProxyConfig, NM_IS_PROXY_CONFIG) - -/*****************************************************************************/ - -void -nm_proxy_config_set_method(NMProxyConfig *config, NMProxyConfigMethod method) -{ - NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE(config); - - priv->method = method; -} - -NMProxyConfigMethod -nm_proxy_config_get_method(const NMProxyConfig *config) -{ - const NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE(config); - - return priv->method; -} - -void -nm_proxy_config_merge_setting(NMProxyConfig *config, NMSettingProxy *setting) -{ - const char * tmp = NULL; - NMProxyConfigPrivate *priv; - NMSettingProxyMethod method; - - if (!setting) - return; - - g_return_if_fail(NM_IS_SETTING_PROXY(setting)); - - priv = NM_PROXY_CONFIG_GET_PRIVATE(config); - - nm_clear_g_free(&priv->pac_script); - - method = nm_setting_proxy_get_method(setting); - switch (method) { - case NM_SETTING_PROXY_METHOD_AUTO: - priv->method = NM_PROXY_CONFIG_METHOD_AUTO; - - /* Free DHCP Obtained PAC Url (i.e Option 252) - * only when libnm overrides it. - */ - tmp = nm_setting_proxy_get_pac_url(setting); - if (tmp) { - g_free(priv->pac_url); - priv->pac_url = g_strdup(tmp); - } - - tmp = nm_setting_proxy_get_pac_script(setting); - priv->pac_script = g_strdup(tmp); - - break; - case NM_SETTING_PROXY_METHOD_NONE: - priv->method = NM_PROXY_CONFIG_METHOD_NONE; - break; - } - - priv->browser_only = nm_setting_proxy_get_browser_only(setting); -} - -gboolean -nm_proxy_config_get_browser_only(const NMProxyConfig *config) -{ - const NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE(config); - - return priv->browser_only; -} - -void -nm_proxy_config_set_pac_url(NMProxyConfig *config, const char *url) -{ - NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE(config); - - g_free(priv->pac_url); - priv->pac_url = g_strdup(url); -} - -const char * -nm_proxy_config_get_pac_url(const NMProxyConfig *config) -{ - const NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE(config); - - return priv->pac_url; -} - -void -nm_proxy_config_set_pac_script(NMProxyConfig *config, const char *script) -{ - NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE(config); - - g_free(priv->pac_script); - priv->pac_script = g_strdup(script); -} - -const char * -nm_proxy_config_get_pac_script(const NMProxyConfig *config) -{ - const NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE(config); - - return priv->pac_script; -} - -/*****************************************************************************/ - -static void -nm_proxy_config_init(NMProxyConfig *config) -{ - NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE(config); - - priv->method = NM_PROXY_CONFIG_METHOD_NONE; -} - -NMProxyConfig * -nm_proxy_config_new(void) -{ - return g_object_new(NM_TYPE_PROXY_CONFIG, NULL); -} - -static void -finalize(GObject *object) -{ - NMProxyConfig * self = NM_PROXY_CONFIG(object); - NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE(self); - - g_free(priv->pac_url); - g_free(priv->pac_script); - - G_OBJECT_CLASS(nm_proxy_config_parent_class)->finalize(object); -} - -static void -nm_proxy_config_class_init(NMProxyConfigClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS(klass); - - object_class->finalize = finalize; -} diff --git a/src/core/nm-proxy-config.h b/src/core/nm-proxy-config.h deleted file mode 100644 index 7b6241f8..00000000 --- a/src/core/nm-proxy-config.h +++ /dev/null @@ -1,41 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2016 Atul Anand . - */ - -#ifndef __NETWORKMANAGER_PROXY_CONFIG_H__ -#define __NETWORKMANAGER_PROXY_CONFIG_H__ - -#include "nm-setting-proxy.h" -#include "nm-l3-config-data.h" - -#define NM_TYPE_PROXY_CONFIG (nm_proxy_config_get_type()) -#define NM_PROXY_CONFIG(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_PROXY_CONFIG, NMProxyConfig)) -#define NM_PROXY_CONFIG_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), NM_TYPE_PROXY_CONFIG, NMProxyConfigClass)) -#define NM_IS_PROXY_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NM_TYPE_PROXY_CONFIG)) -#define NM_IS_PROXY_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NM_TYPE_PROXY_CONFIG)) -#define NM_PROXY_CONFIG_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_PROXY_CONFIG, NMProxyConfigClass)) - -typedef struct _NMProxyConfigClass NMProxyConfigClass; - -GType nm_proxy_config_get_type(void); - -NMProxyConfig *nm_proxy_config_new(void); - -void nm_proxy_config_set_method(NMProxyConfig *config, NMProxyConfigMethod method); -NMProxyConfigMethod nm_proxy_config_get_method(const NMProxyConfig *config); - -void nm_proxy_config_merge_setting(NMProxyConfig *config, NMSettingProxy *setting); - -gboolean nm_proxy_config_get_browser_only(const NMProxyConfig *config); - -void nm_proxy_config_set_pac_url(NMProxyConfig *config, const char *url); -const char *nm_proxy_config_get_pac_url(const NMProxyConfig *config); - -void nm_proxy_config_set_pac_script(NMProxyConfig *config, const char *script); -const char *nm_proxy_config_get_pac_script(const NMProxyConfig *config); - -#endif /* __NETWORKMANAGER_PROXY_CONFIG_H__ */ diff --git a/src/core/nm-rfkill-manager.c b/src/core/nm-rfkill-manager.c index 7f0b7726..f3851e5c 100644 --- a/src/core/nm-rfkill-manager.c +++ b/src/core/nm-rfkill-manager.c @@ -25,7 +25,7 @@ typedef struct { /* Authoritative rfkill state (RFKILL_* enum) */ RfKillState rfkill_states[RFKILL_TYPE_MAX]; - GSList * killswitches; + GSList *killswitches; } NMRfkillManagerPrivate; struct _NMRfkillManager { @@ -45,10 +45,10 @@ G_DEFINE_TYPE(NMRfkillManager, nm_rfkill_manager, G_TYPE_OBJECT) /*****************************************************************************/ typedef struct { - char * name; + char *name; guint64 seqnum; - char * path; - char * driver; + char *path; + char *driver; RfKillType rtype; int state; gboolean platform; @@ -90,9 +90,9 @@ rfkill_state_to_desc(RfKillState rstate) static Killswitch * killswitch_new(struct udev_device *device, RfKillType rtype) { - Killswitch * ks; + Killswitch *ks; struct udev_device *parent = NULL, *grandparent = NULL; - const char * driver, *subsys, *parent_subsys = NULL; + const char *driver, *subsys, *parent_subsys = NULL; ks = g_malloc0(sizeof(Killswitch)); ks->name = g_strdup(udev_device_get_sysname(device)); @@ -161,7 +161,7 @@ static void recheck_killswitches(NMRfkillManager *self) { NMRfkillManagerPrivate *priv = NM_RFKILL_MANAGER_GET_PRIVATE(self); - GSList * iter; + GSList *iter; RfKillState poll_states[RFKILL_TYPE_MAX]; RfKillState platform_states[RFKILL_TYPE_MAX]; gboolean platform_checked[RFKILL_TYPE_MAX]; @@ -176,7 +176,7 @@ recheck_killswitches(NMRfkillManager *self) /* Poll the states of all killswitches */ for (iter = priv->killswitches; iter; iter = g_slist_next(iter)) { - Killswitch * ks = iter->data; + Killswitch *ks = iter->data; struct udev_device *device; RfKillState dev_state; int sysfs_state; @@ -239,7 +239,7 @@ static Killswitch * killswitch_find_by_name(NMRfkillManager *self, const char *name) { NMRfkillManagerPrivate *priv = NM_RFKILL_MANAGER_GET_PRIVATE(self); - GSList * iter; + GSList *iter; g_return_val_if_fail(name != NULL, NULL); @@ -269,9 +269,9 @@ static void add_one_killswitch(NMRfkillManager *self, struct udev_device *device) { NMRfkillManagerPrivate *priv = NM_RFKILL_MANAGER_GET_PRIVATE(self); - const char * str_type; + const char *str_type; RfKillType rtype; - Killswitch * ks; + Killswitch *ks; str_type = udev_device_get_property_value(device, "RFKILL_TYPE"); rtype = rfkill_type_to_enum(str_type); @@ -307,8 +307,8 @@ static void rfkill_remove(NMRfkillManager *self, struct udev_device *device) { NMRfkillManagerPrivate *priv = NM_RFKILL_MANAGER_GET_PRIVATE(self); - GSList * iter; - const char * name; + GSList *iter; + const char *name; g_return_if_fail(device != NULL); name = udev_device_get_sysname(device); @@ -330,8 +330,8 @@ static void handle_uevent(NMUdevClient *client, struct udev_device *device, gpointer user_data) { NMRfkillManager *self = NM_RFKILL_MANAGER(user_data); - const char * subsys; - const char * action; + const char *subsys; + const char *action; action = udev_device_get_action(device); @@ -360,7 +360,7 @@ static void nm_rfkill_manager_init(NMRfkillManager *self) { NMRfkillManagerPrivate *priv = NM_RFKILL_MANAGER_GET_PRIVATE(self); - struct udev_enumerate * enumerate; + struct udev_enumerate *enumerate; struct udev_list_entry *iter; guint i; @@ -397,7 +397,7 @@ nm_rfkill_manager_new(void) static void dispose(GObject *object) { - NMRfkillManager * self = NM_RFKILL_MANAGER(object); + NMRfkillManager *self = NM_RFKILL_MANAGER(object); NMRfkillManagerPrivate *priv = NM_RFKILL_MANAGER_GET_PRIVATE(self); if (priv->killswitches) { diff --git a/src/core/nm-session-monitor.c b/src/core/nm-session-monitor.c index 2cc99ab3..08bfedca 100644 --- a/src/core/nm-session-monitor.c +++ b/src/core/nm-session-monitor.c @@ -48,14 +48,14 @@ struct _NMSessionMonitor { #if SESSION_TRACKING_XLOGIND struct { sd_login_monitor *monitor; - GSource * watch; + GSource *watch; } sd; #endif #if SESSION_TRACKING_CONSOLEKIT struct { GFileMonitor *monitor; - GHashTable * cache; + GHashTable *cache; time_t timestamp; } ck; #endif @@ -145,8 +145,8 @@ static gboolean ck_load_cache(GHashTable *cache) { GKeyFile *keyfile = g_key_file_new(); - char ** groups = NULL; - GError * error = NULL; + char **groups = NULL; + GError *error = NULL; gsize i, len; gboolean finished = FALSE; @@ -235,9 +235,9 @@ ck_session_exists(NMSessionMonitor *monitor, uid_t uid, gboolean active) } static void -ck_changed(GFileMonitor * file_monitor, - GFile * file, - GFile * other_file, +ck_changed(GFileMonitor *file_monitor, + GFile *file, + GFile *other_file, GFileMonitorEvent event_type, gpointer user_data) { @@ -247,7 +247,7 @@ ck_changed(GFileMonitor * file_monitor, static void ck_init(NMSessionMonitor *monitor) { - GFile * file = g_file_new_for_path(CKDB_PATH); + GFile *file = g_file_new_for_path(CKDB_PATH); GError *error = NULL; if (g_file_query_exists(file, NULL)) { diff --git a/src/core/nm-sleep-monitor.c b/src/core/nm-sleep-monitor.c index 76f13203..a7ea496d 100644 --- a/src/core/nm-sleep-monitor.c +++ b/src/core/nm-sleep-monitor.c @@ -133,10 +133,10 @@ drop_inhibitor(NMSleepMonitor *self, gboolean force) static void inhibit_done(GObject *source, GAsyncResult *result, gpointer user_data) { - GDBusProxy * proxy = G_DBUS_PROXY(source); - NMSleepMonitor *self = user_data; - gs_free_error GError *error = NULL; - gs_unref_variant GVariant *res = NULL; + GDBusProxy *proxy = G_DBUS_PROXY(source); + NMSleepMonitor *self = user_data; + gs_free_error GError *error = NULL; + gs_unref_variant GVariant *res = NULL; gs_unref_object GUnixFDList *fd_list = NULL; res = g_dbus_proxy_call_with_unix_fd_list_finish(proxy, &fd_list, result, &error); @@ -193,9 +193,9 @@ prepare_for_sleep_cb(GDBusProxy *proxy, gboolean is_about_to_suspend, gpointer d static void name_owner_cb(GObject *object, GParamSpec *pspec, gpointer user_data) { - GDBusProxy * proxy = G_DBUS_PROXY(object); + GDBusProxy *proxy = G_DBUS_PROXY(object); NMSleepMonitor *self = NM_SLEEP_MONITOR(user_data); - char * owner; + char *owner; g_assert(proxy == self->proxy); @@ -280,7 +280,7 @@ nm_sleep_monitor_inhibit_release(NMSleepMonitor *self, NMSleepMonitorInhibitorHa static void on_proxy_acquired(GObject *object, GAsyncResult *res, NMSleepMonitor *self) { - GError * error = NULL; + GError *error = NULL; GDBusProxy *proxy; proxy = g_dbus_proxy_new_for_bus_finish(res, &error); diff --git a/src/core/nm-test-utils-core.h b/src/core/nm-test-utils-core.h index e037ba92..6f571972 100644 --- a/src/core/nm-test-utils-core.h +++ b/src/core/nm-test-utils-core.h @@ -36,8 +36,8 @@ nmtst_platform_ip4_address(const char *address, const char *peer_address, guint } static inline NMPlatformIP4Address * -nmtst_platform_ip4_address_full(const char * address, - const char * peer_address, +nmtst_platform_ip4_address_full(const char *address, + const char *peer_address, guint plen, int ifindex, NMIPConfigSource source, @@ -45,7 +45,7 @@ nmtst_platform_ip4_address_full(const char * address, guint32 lifetime, guint32 preferred, guint32 flags, - const char * label) + const char *label) { NMPlatformIP4Address *addr = nmtst_platform_ip4_address(address, peer_address, plen); @@ -80,8 +80,8 @@ nmtst_platform_ip6_address(const char *address, const char *peer_address, guint } static inline NMPlatformIP6Address * -nmtst_platform_ip6_address_full(const char * address, - const char * peer_address, +nmtst_platform_ip6_address_full(const char *address, + const char *peer_address, guint plen, int ifindex, NMIPConfigSource source, @@ -118,15 +118,15 @@ nmtst_platform_ip4_route(const char *network, guint plen, const char *gateway) } static inline NMPlatformIP4Route * -nmtst_platform_ip4_route_full(const char * network, +nmtst_platform_ip4_route_full(const char *network, guint plen, - const char * gateway, + const char *gateway, int ifindex, NMIPConfigSource source, guint metric, guint mss, guint8 scope, - const char * pref_src) + const char *pref_src) { NMPlatformIP4Route *route = nmtst_platform_ip4_route(network, plen, gateway); @@ -157,9 +157,9 @@ nmtst_platform_ip6_route(const char *network, guint plen, const char *gateway, c } static inline NMPlatformIP6Route * -nmtst_platform_ip6_route_full(const char * network, +nmtst_platform_ip6_route_full(const char *network, guint plen, - const char * gateway, + const char *gateway, int ifindex, NMIPConfigSource source, guint metric, @@ -188,7 +188,7 @@ nmtst_platform_ip4_routes_equal(const NMPlatformIP4Route *a, gsize len, gboolean ignore_order) { - gsize i; + gsize i; gs_free const NMPlatformIP4Route *c_a = NULL, *c_b = NULL; g_assert(a); @@ -225,12 +225,12 @@ nmtst_platform_ip4_routes_equal(const NMPlatformIP4Route *a, #ifdef __NMP_OBJECT_H__ static inline void -nmtst_platform_ip4_routes_equal_aptr(const NMPObject *const * a, +nmtst_platform_ip4_routes_equal_aptr(const NMPObject *const *a, const NMPlatformIP4Route *b, gsize len, gboolean ignore_order) { - gsize i; + gsize i; gs_free NMPlatformIP4Route *c_a = NULL; g_assert(len > 0); @@ -257,7 +257,7 @@ nmtst_platform_ip6_routes_equal(const NMPlatformIP6Route *a, gsize len, gboolean ignore_order) { - gsize i; + gsize i; gs_free const NMPlatformIP6Route *c_a = NULL, *c_b = NULL; g_assert(a); @@ -294,12 +294,12 @@ nmtst_platform_ip6_routes_equal(const NMPlatformIP6Route *a, #ifdef __NMP_OBJECT_H__ static inline void -nmtst_platform_ip6_routes_equal_aptr(const NMPObject *const * a, +nmtst_platform_ip6_routes_equal_aptr(const NMPObject *const *a, const NMPlatformIP6Route *b, gsize len, gboolean ignore_order) { - gsize i; + gsize i; gs_free NMPlatformIP6Route *c_a = NULL; g_assert(len > 0); diff --git a/src/core/nm-types.h b/src/core/nm-types.h index 294cf409..18f44ca9 100644 --- a/src/core/nm-types.h +++ b/src/core/nm-types.h @@ -25,10 +25,7 @@ typedef struct _NML3Cfg NML3Cfg; typedef struct _NML3ConfigData NML3ConfigData; typedef struct _NMDevice NMDevice; typedef struct _NMDhcpConfig NMDhcpConfig; -typedef struct _NMProxyConfig NMProxyConfig; typedef struct _NMIPConfig NMIPConfig; -typedef struct _NMIP4Config NMIP4Config; -typedef struct _NMIP6Config NMIP6Config; typedef struct _NMManager NMManager; typedef struct _NMNetns NMNetns; typedef struct _NMPolicy NMPolicy; @@ -40,10 +37,10 @@ typedef struct _NMSleepMonitor NMSleepMonitor; typedef struct _NMLldpListener NMLldpListener; typedef struct _NMConfigDeviceStateData NMConfigDeviceStateData; -typedef void (*NMManagerDeviceAuthRequestFunc)(NMDevice * device, +typedef void (*NMManagerDeviceAuthRequestFunc)(NMDevice *device, GDBusMethodInvocation *context, - NMAuthSubject * subject, - GError * error, + NMAuthSubject *subject, + GError *error, gpointer user_data); struct _NMDedupMultiIndex; diff --git a/src/core/platform/nm-fake-platform.c b/src/core/platform/nm-fake-platform.c index b773df9a..7d8986d7 100644 --- a/src/core/platform/nm-fake-platform.c +++ b/src/core/platform/nm-fake-platform.c @@ -23,13 +23,13 @@ typedef struct { const NMPObject *obj; - char * udi; + char *udi; struct in6_addr ip6_lladdr; } NMFakePlatformLink; typedef struct { GHashTable *options; - GArray * links; + GArray *links; } NMFakePlatformPrivate; struct _NMFakePlatform { @@ -60,7 +60,7 @@ G_DEFINE_TYPE(NMFakePlatform, nm_fake_platform, NM_TYPE_PLATFORM) \ if (nm_logging_enabled(__level, __domain)) { \ char __prefix[32]; \ - const char * __p_prefix = _NMLOG_PREFIX_NAME; \ + const char *__p_prefix = _NMLOG_PREFIX_NAME; \ NMPlatform *const __self = (self); \ \ if (__self && nm_platform_get_log_with_ptr(self)) { \ @@ -80,12 +80,12 @@ G_DEFINE_TYPE(NMFakePlatform, nm_fake_platform, NM_TYPE_PLATFORM) /*****************************************************************************/ -static void link_changed(NMPlatform * platform, +static void link_changed(NMPlatform *platform, NMFakePlatformLink *device, NMPCacheOpsType cache_op, - const NMPObject * obj_old); + const NMPObject *obj_old); -static gboolean ipx_address_delete(NMPlatform * platform, +static gboolean ipx_address_delete(NMPlatform *platform, int addr_family, int ifindex, gconstpointer addr, @@ -95,7 +95,7 @@ static gboolean ipx_address_delete(NMPlatform * platform, static gboolean ipx_route_delete(NMPlatform *platform, int addr_family, int ifindex, const NMPObject *obj); -static gboolean ip6_address_add(NMPlatform * platform, +static gboolean ip6_address_add(NMPlatform *platform, int ifindex, struct in6_addr addr, guint8 plen, @@ -143,7 +143,7 @@ static char * sysctl_get(NMPlatform *platform, const char *pathid, int dirfd, const char *path) { NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE(platform); - const char * v; + const char *v; ASSERT_SYSCTL_ARGS(pathid, dirfd, path); @@ -160,7 +160,7 @@ static NMFakePlatformLink * link_get(NMPlatform *platform, int ifindex) { NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE(platform); - NMFakePlatformLink * device; + NMFakePlatformLink *device; int idx; if (ifindex <= 0) @@ -226,11 +226,11 @@ link_add_pre(NMPlatform *platform, guint32 mtu) { NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE(platform); - NMFakePlatformLink * device; + NMFakePlatformLink *device; int ifindex; - NMPObject * o; - NMPlatformLink * link; - gs_free char * ip6_lladdr = NULL; + NMPObject *o; + NMPlatformLink *link; + gs_free char *ip6_lladdr = NULL; g_assert(!name || strlen(name) < IFNAMSIZ); @@ -278,27 +278,27 @@ link_add_pre(NMPlatform *platform, } static int -link_add(NMPlatform * platform, +link_add(NMPlatform *platform, NMLinkType type, - const char * name, + const char *name, int parent, - const void * address, + const void *address, size_t address_len, guint32 mtu, gconstpointer extra_data, const NMPlatformLink **out_link) { - NMFakePlatformLink * device; - NMFakePlatformLink * device_veth = NULL; + NMFakePlatformLink *device; + NMFakePlatformLink *device_veth = NULL; nm_auto_nmpobj const NMPObject *obj_old = NULL; nm_auto_nmpobj const NMPObject *obj_new = NULL; nm_auto_nmpobj const NMPObject *obj_old_veth = NULL; nm_auto_nmpobj const NMPObject *obj_new_veth = NULL; NMPCacheOpsType cache_op; NMPCacheOpsType cache_op_veth = NMP_CACHE_OPS_UNCHANGED; - const char * veth_peer = NULL; - NMPObject * dev_obj; - NMPObject * dev_lnk = NULL; + const char *veth_peer = NULL; + NMPObject *dev_obj; + NMPObject *dev_lnk = NULL; device = link_add_pre(platform, name, type, address, address_len, mtu); @@ -389,13 +389,13 @@ static NMFakePlatformLink * link_add_one(NMPlatform *platform, const char *name, NMLinkType link_type, - void (*prepare_fcn)(NMPlatform * platform, + void (*prepare_fcn)(NMPlatform *platform, NMFakePlatformLink *device, gconstpointer user_data), gconstpointer user_data, const NMPlatformLink **out_link) { - NMFakePlatformLink * device; + NMFakePlatformLink *device; nm_auto_nmpobj const NMPObject *obj_old = NULL; nm_auto_nmpobj const NMPObject *obj_new = NULL; NMPCacheOpsType cache_op; @@ -431,7 +431,7 @@ link_add_one(NMPlatform *platform, static gboolean link_delete(NMPlatform *platform, int ifindex) { - NMFakePlatformLink * device = link_get(platform, ifindex); + NMFakePlatformLink *device = link_get(platform, ifindex); nm_auto_nmpobj const NMPObject *obj_old = NULL; nm_auto_nmpobj const NMPObject *obj_old2 = NULL; NMPCacheOpsType cache_op; @@ -459,10 +459,10 @@ link_delete(NMPlatform *platform, int ifindex) static void link_set_obj(NMPlatform *platform, NMFakePlatformLink *device, NMPObject *obj_tmp) { - nm_auto_nmpobj const NMPObject *obj_new = NULL; - nm_auto_nmpobj const NMPObject *obj_old = NULL; - nm_auto_nmpobj NMPObject *obj_tmp_tmp = NULL; - NMPCacheOpsType cache_op; + nm_auto_nmpobj const NMPObject *obj_new = NULL; + nm_auto_nmpobj const NMPObject *obj_old = NULL; + nm_auto_nmpobj NMPObject *obj_tmp_tmp = NULL; + NMPCacheOpsType cache_op; g_assert(device); g_assert(NMP_OBJECT_GET_TYPE(device->obj) == NMP_OBJECT_TYPE_LINK); @@ -519,10 +519,10 @@ link_change_flags(NMPlatform *platform, int ifindex, unsigned flags_mask, unsign } static void -link_changed(NMPlatform * platform, +link_changed(NMPlatform *platform, NMFakePlatformLink *device, NMPCacheOpsType cache_op, - const NMPObject * obj_old) + const NMPObject *obj_old) { g_assert(device->obj); @@ -558,7 +558,7 @@ link_changed(NMPlatform * platform, static int link_set_address(NMPlatform *platform, int ifindex, gconstpointer addr, size_t len) { - NMFakePlatformLink *device = link_get(platform, ifindex); + NMFakePlatformLink *device = link_get(platform, ifindex); nm_auto_nmpobj NMPObject *obj_tmp = NULL; if (len == 0 || len > _NM_UTILS_HWADDR_LEN_MAX || !addr) @@ -579,7 +579,7 @@ link_set_address(NMPlatform *platform, int ifindex, gconstpointer addr, size_t l static int link_set_mtu(NMPlatform *platform, int ifindex, guint32 mtu) { - NMFakePlatformLink *device = link_get(platform, ifindex); + NMFakePlatformLink *device = link_get(platform, ifindex); nm_auto_nmpobj NMPObject *obj_tmp = NULL; if (!device) { @@ -596,9 +596,9 @@ link_set_mtu(NMPlatform *platform, int ifindex, guint32 mtu) static gboolean link_get_driver_info(NMPlatform *platform, int ifindex, - char ** out_driver_name, - char ** out_driver_version, - char ** out_fw_version) + char **out_driver_name, + char **out_driver_version, + char **out_fw_version) { if (out_driver_name) *out_driver_name = NULL; @@ -683,8 +683,8 @@ link_enslave(NMPlatform *platform, int master, int slave) static gboolean link_release(NMPlatform *platform, int master_idx, int slave_idx) { - NMFakePlatformLink *master = link_get(platform, master_idx); - NMFakePlatformLink *slave = link_get(platform, slave_idx); + NMFakePlatformLink *master = link_get(platform, master_idx); + NMFakePlatformLink *slave = link_get(platform, slave_idx); nm_auto_nmpobj NMPObject *obj_tmp = NULL; g_return_val_if_fail(master, FALSE); @@ -700,7 +700,7 @@ link_release(NMPlatform *platform, int master_idx, int slave_idx) } static gboolean -link_vlan_change(NMPlatform * platform, +link_vlan_change(NMPlatform *platform, int ifindex, _NMVlanFlags flags_mask, _NMVlanFlags flags_set, @@ -723,8 +723,8 @@ static void _infiniband_add_prepare(NMPlatform *platform, NMFakePlatformLink *device, gconstpointer user_data) { const struct infiniband_add_data *d = user_data; - NMPObject * obj_tmp; - NMPObject * lnk; + NMPObject *obj_tmp; + NMPObject *lnk; obj_tmp = (NMPObject *) device->obj; @@ -737,12 +737,12 @@ _infiniband_add_prepare(NMPlatform *platform, NMFakePlatformLink *device, gconst } static gboolean -infiniband_partition_add(NMPlatform * platform, +infiniband_partition_add(NMPlatform *platform, int parent, int p_key, const NMPlatformLink **out_link) { - NMFakePlatformLink * parent_device; + NMFakePlatformLink *parent_device; char name[IFNAMSIZ]; const struct infiniband_add_data d = { .parent = parent, @@ -762,7 +762,7 @@ static gboolean infiniband_partition_delete(NMPlatform *platform, int parent, int p_key) { NMFakePlatformLink *parent_device; - gs_free char * name = NULL; + gs_free char *name = NULL; parent_device = link_get(platform, parent); g_return_val_if_fail(parent_device != NULL, FALSE); @@ -859,11 +859,11 @@ mesh_set_ssid(NMPlatform *platform, int ifindex, const guint8 *ssid, gsize len) static gboolean ipx_address_add(NMPlatform *platform, int addr_family, const NMPlatformObject *address) { - nm_auto_nmpobj NMPObject *obj = NULL; - NMPCacheOpsType cache_op; + nm_auto_nmpobj NMPObject *obj = NULL; + NMPCacheOpsType cache_op; nm_auto_nmpobj const NMPObject *obj_old = NULL; nm_auto_nmpobj const NMPObject *obj_new = NULL; - NMPCache * cache = nm_platform_get_cache(platform); + NMPCache *cache = nm_platform_get_cache(platform); g_assert(NM_IN_SET(addr_family, AF_INET, AF_INET6)); @@ -910,7 +910,7 @@ ip4_address_add(NMPlatform *platform, } static gboolean -ip6_address_add(NMPlatform * platform, +ip6_address_add(NMPlatform *platform, int ifindex, struct in6_addr addr, guint8 plen, @@ -938,7 +938,7 @@ ip6_address_add(NMPlatform * platform, } static gboolean -ipx_address_delete(NMPlatform * platform, +ipx_address_delete(NMPlatform *platform, int addr_family, int ifindex, gconstpointer addr, @@ -957,11 +957,10 @@ ipx_address_delete(NMPlatform * platform, peer_addr_i = peer_addr ? *((guint32 *) peer_addr) : 0; nmp_cache_iter_for_each (&iter, - nm_platform_lookup_object(platform, - addr_family == AF_INET - ? NMP_OBJECT_TYPE_IP4_ADDRESS - : NMP_OBJECT_TYPE_IP6_ADDRESS, - 0), + nm_platform_lookup_obj_type(platform, + addr_family == AF_INET + ? NMP_OBJECT_TYPE_IP4_ADDRESS + : NMP_OBJECT_TYPE_IP6_ADDRESS), &o) { const NMPObject *obj_old = NULL; @@ -1085,23 +1084,23 @@ object_delete(NMPlatform *platform, const NMPObject *obj) } static int -ip_route_add(NMPlatform * platform, +ip_route_add(NMPlatform *platform, NMPNlmFlags flags, int addr_family, const NMPlatformIPRoute *route) { - NMDedupMultiIter iter; - nm_auto_nmpobj NMPObject *obj = NULL; - NMPCacheOpsType cache_op; - const NMPObject * o = NULL; + NMDedupMultiIter iter; + nm_auto_nmpobj NMPObject *obj = NULL; + NMPCacheOpsType cache_op; + const NMPObject *o = NULL; nm_auto_nmpobj const NMPObject *obj_old = NULL; nm_auto_nmpobj const NMPObject *obj_new = NULL; nm_auto_nmpobj const NMPObject *obj_replace = NULL; - NMPCache * cache = nm_platform_get_cache(platform); + NMPCache *cache = nm_platform_get_cache(platform); gboolean has_gateway = FALSE; - NMPlatformIPRoute * r = NULL; - NMPlatformIP4Route * r4 = NULL; - NMPlatformIP6Route * r6 = NULL; + NMPlatformIPRoute *r = NULL; + NMPlatformIP4Route *r4 = NULL; + NMPlatformIP6Route *r6 = NULL; gboolean has_same_weak_id; gboolean only_dirty; guint16 nlmsgflags; @@ -1118,8 +1117,6 @@ ip_route_add(NMPlatform * platform, (const NMPlatformObject *) route); r = NMP_OBJECT_CAST_IP_ROUTE(obj); - r->is_external = TRUE; - nm_platform_ip_route_normalize(addr_family, r); switch (addr_family) { @@ -1141,7 +1138,7 @@ ip_route_add(NMPlatform * platform, gboolean has_route_to_gw = FALSE; nmp_cache_iter_for_each (&iter, - nm_platform_lookup_object(platform, NMP_OBJECT_GET_TYPE(obj), 0), + nm_platform_lookup_obj_type(platform, NMP_OBJECT_GET_TYPE(obj)), &o) { if (addr_family == AF_INET) { const NMPlatformIP4Route *item = NMP_OBJECT_CAST_IP4_ROUTE(o); @@ -1298,8 +1295,8 @@ finalize(GObject *object) static void nm_fake_platform_class_init(NMFakePlatformClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); - NMPlatformClass * platform_class = NM_PLATFORM_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); + NMPlatformClass *platform_class = NM_PLATFORM_CLASS(klass); NMPlatformKernelSupportType kernel_support; for (kernel_support = 0; kernel_support < _NM_PLATFORM_KERNEL_SUPPORT_NUM; kernel_support++) diff --git a/src/core/platform/tests/test-address.c b/src/core/platform/tests/test-address.c index 4e1d1d6e..700891e8 100644 --- a/src/core/platform/tests/test-address.c +++ b/src/core/platform/tests/test-address.c @@ -20,12 +20,12 @@ /*****************************************************************************/ static void -ip4_address_callback(NMPlatform * platform, +ip4_address_callback(NMPlatform *platform, NMPObjectType obj_type, int ifindex, - NMPlatformIP4Address * received, + NMPlatformIP4Address *received, NMPlatformSignalChangeType change_type, - SignalData * data) + SignalData *data) { g_assert(received); g_assert_cmpint(received->ifindex, ==, ifindex); @@ -45,12 +45,12 @@ ip4_address_callback(NMPlatform * platform, } static void -ip6_address_callback(NMPlatform * platform, +ip6_address_callback(NMPlatform *platform, NMPObjectType obj_type, int ifindex, - NMPlatformIP6Address * received, + NMPlatformIP6Address *received, NMPlatformSignalChangeType change_type, - SignalData * data) + SignalData *data) { g_assert(received); g_assert_cmpint(received->ifindex, ==, ifindex); @@ -87,7 +87,7 @@ test_ip4_address_general(void) NM_PLATFORM_SIGNAL_REMOVED, ip4_address_callback, ifindex); - GArray * addresses; + GArray *addresses; NMPlatformIP4Address *address; in_addr_t addr; guint32 lifetime = 2000; @@ -154,7 +154,7 @@ test_ip6_address_general(void) NM_PLATFORM_SIGNAL_REMOVED, ip6_address_callback, ifindex); - GArray * addresses; + GArray *addresses; NMPlatformIP6Address *address; struct in6_addr addr; guint32 lifetime = 2000; @@ -258,10 +258,10 @@ static void test_ip6_address_general_2(void) { const int ifindex = DEVICE_IFINDEX; - SignalData * address_added = add_signal(NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED, + SignalData *address_added = add_signal(NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED, NM_PLATFORM_SIGNAL_ADDED, ip6_address_callback); - SignalData * address_removed = add_signal(NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED, + SignalData *address_removed = add_signal(NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED, NM_PLATFORM_SIGNAL_REMOVED, ip6_address_callback); struct in6_addr addr; @@ -307,10 +307,10 @@ static void test_ip4_address_peer(void) { const int ifindex = DEVICE_IFINDEX; - SignalData * address_added = add_signal(NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED, + SignalData *address_added = add_signal(NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED, NM_PLATFORM_SIGNAL_ADDED, ip4_address_callback); - SignalData * address_removed = add_signal(NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED, + SignalData *address_removed = add_signal(NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED, NM_PLATFORM_SIGNAL_REMOVED, ip4_address_callback); in_addr_t addr, addr_peer, addr_peer2; @@ -387,7 +387,7 @@ test_ip4_address_peer_zero(void) const char *label = NULL; in_addr_t peers[3], r_peers[3]; int i; - GArray * addrs; + GArray *addrs; g_assert(ifindex > 0); diff --git a/src/core/platform/tests/test-cleanup.c b/src/core/platform/tests/test-cleanup.c index e13bb8c8..2198e921 100644 --- a/src/core/platform/tests/test-cleanup.c +++ b/src/core/platform/tests/test-cleanup.c @@ -10,15 +10,15 @@ static void test_cleanup_internal(void) { - SignalData * link_added = add_signal_ifname(NM_PLATFORM_SIGNAL_LINK_CHANGED, + SignalData *link_added = add_signal_ifname(NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_ADDED, link_callback, DEVICE_NAME); int ifindex; - GArray * addresses4; - GArray * addresses6; - GPtrArray * routes4; - GPtrArray * routes6; + GArray *addresses4; + GArray *addresses6; + GPtrArray *routes4; + GPtrArray *routes6; in_addr_t addr4; in_addr_t network4; int plen4 = 24; @@ -55,7 +55,7 @@ test_cleanup_internal(void) /* wait for kernel to add the IPv6 link local address... it takes a bit. */ NMTST_WAIT_ASSERT(300, { - gs_unref_array GArray * addrs = NULL; + gs_unref_array GArray *addrs = NULL; const NMPlatformIP6Address *a; if (nmtst_wait_iteration > 0) { diff --git a/src/core/platform/tests/test-common.c b/src/core/platform/tests/test-common.c index 4f56a3a7..9053d351 100644 --- a/src/core/platform/tests/test-common.c +++ b/src/core/platform/tests/test-common.c @@ -94,7 +94,7 @@ nmtstp_platform_ip_address_find(NMPlatform *self, int ifindex, int addr_family, const int IS_IPv4 = NM_IS_IPv4(addr_family); const NMPlatformIPAddress *found = NULL; NMDedupMultiIter iter; - const NMPObject * obj; + const NMPObject *obj; NMPLookup lookup; g_assert(NM_IS_PLATFORM(self)); @@ -102,7 +102,11 @@ nmtstp_platform_ip_address_find(NMPlatform *self, int ifindex, int addr_family, nm_assert_addr_family(addr_family); nm_assert(addr); - nmp_lookup_init_object(&lookup, NMP_OBJECT_TYPE_IP_ADDRESS(IS_IPv4), ifindex); + if (ifindex > 0) + nmp_lookup_init_object(&lookup, NMP_OBJECT_TYPE_IP_ADDRESS(IS_IPv4), ifindex); + else + nmp_lookup_init_obj_type(&lookup, NMP_OBJECT_TYPE_IP_ADDRESS(IS_IPv4)); + nm_platform_iter_obj_for_each (&iter, self, &lookup, &obj) { const NMPlatformIPAddress *a = NMP_OBJECT_CAST_IP_ADDRESS(obj); @@ -132,9 +136,9 @@ typedef struct { } IPAddressesAssertData; void -_nmtstp_platform_ip_addresses_assert(const char * filename, +_nmtstp_platform_ip_addresses_assert(const char *filename, int lineno, - NMPlatform * self, + NMPlatform *self, int ifindex, gboolean force_exact_4, gboolean force_exact_6, @@ -176,8 +180,8 @@ _nmtstp_platform_ip_addresses_assert(const char * filename, } for (IS_IPv4 = 1; IS_IPv4 >= 0; IS_IPv4--) { - const int addr_family = IS_IPv4 ? AF_INET : AF_INET6; - gs_unref_ptrarray GPtrArray *plat_addrs = NULL; + const int addr_family = IS_IPv4 ? AF_INET : AF_INET6; + gs_unref_ptrarray GPtrArray *plat_addrs = NULL; NMPLookup lookup; guint j; @@ -282,7 +286,7 @@ nmtstp_platform_ip4_route_delete(NMPlatform *platform, } gboolean -nmtstp_platform_ip6_route_delete(NMPlatform * platform, +nmtstp_platform_ip6_route_delete(NMPlatform *platform, int ifindex, struct in6_addr network, guint8 plen, @@ -311,11 +315,11 @@ nmtstp_platform_ip6_route_delete(NMPlatform * platform, /*****************************************************************************/ SignalData * -add_signal_full(const char * name, +add_signal_full(const char *name, NMPlatformSignalChangeType change_type, GCallback callback, int ifindex, - const char * ifname) + const char *ifname) { SignalData *data = g_new0(SignalData, 1); @@ -448,18 +452,18 @@ _free_signal(const char *file, int line, const char *func, SignalData *data) } void -link_callback(NMPlatform * platform, +link_callback(NMPlatform *platform, int obj_type_i, int ifindex, NMPlatformLink *received, int change_type_i, - SignalData * data) + SignalData *data) { const NMPObjectType obj_type = obj_type_i; const NMPlatformSignalChangeType change_type = change_type_i; NMPLookup lookup; NMDedupMultiIter iter; - const NMPlatformLink * cached; + const NMPlatformLink *cached; g_assert_cmpint(obj_type, ==, NMP_OBJECT_TYPE_LINK); g_assert(received); @@ -522,11 +526,11 @@ _ip4_route_get(NMPlatform *platform, int plen, guint32 metric, guint8 tos, - guint * out_c_exists) + guint *out_c_exists) { NMDedupMultiIter iter; NMPLookup lookup; - const NMPObject * o = NULL; + const NMPObject *o = NULL; guint c; const NMPlatformIP4Route *r = NULL; @@ -606,18 +610,18 @@ nmtstp_ip4_route_get(NMPlatform *platform, /*****************************************************************************/ static const NMPlatformIP6Route * -_ip6_route_get(NMPlatform * platform, +_ip6_route_get(NMPlatform *platform, int ifindex, const struct in6_addr *network, guint plen, guint32 metric, const struct in6_addr *src, guint8 src_plen, - guint * out_c_exists) + guint *out_c_exists) { NMDedupMultiIter iter; NMPLookup lookup; - const NMPObject * o = NULL; + const NMPObject *o = NULL; guint c; const NMPlatformIP6Route *r = NULL; @@ -639,12 +643,12 @@ _ip6_route_get(NMPlatform * platform, } const NMPlatformIP6Route * -_nmtstp_assert_ip6_route_exists(const char * file, +_nmtstp_assert_ip6_route_exists(const char *file, guint line, - const char * func, - NMPlatform * platform, + const char *func, + NMPlatform *platform, int c_exists, - const char * ifname, + const char *ifname, const struct in6_addr *network, guint plen, guint32 metric, @@ -687,7 +691,7 @@ _nmtstp_assert_ip6_route_exists(const char * file, } const NMPlatformIP6Route * -nmtstp_ip6_route_get(NMPlatform * platform, +nmtstp_ip6_route_get(NMPlatform *platform, int ifindex, const struct in6_addr *network, guint plen, @@ -727,7 +731,7 @@ typedef struct { } WaitForSignalData; static void -_wait_for_signal_cb(NMPlatform * platform, +_wait_for_signal_cb(NMPlatform *platform, int obj_type_i, int ifindex, NMPlatformLink *plink, @@ -1016,7 +1020,7 @@ nmtstp_ip_address_assert_lifetime(const NMPlatformIPAddress *addr, /*****************************************************************************/ static void -_ip_address_add(NMPlatform * platform, +_ip_address_add(NMPlatform *platform, gboolean external_command, gboolean is_v4, int ifindex, @@ -1026,7 +1030,7 @@ _ip_address_add(NMPlatform * platform, guint32 lifetime, guint32 preferred, guint32 flags, - const char * label) + const char *label) { gint64 end_time; @@ -1035,7 +1039,7 @@ _ip_address_add(NMPlatform * platform, _init_platform(&platform, external_command); if (external_command) { - const char * ifname; + const char *ifname; gs_free char *s_valid = NULL; gs_free char *s_preferred = NULL; gs_free char *s_label = NULL; @@ -1193,7 +1197,7 @@ nmtstp_ip4_address_add(NMPlatform *platform, } void -nmtstp_ip6_address_add(NMPlatform * platform, +nmtstp_ip6_address_add(NMPlatform *platform, gboolean external_command, int ifindex, struct in6_addr address, @@ -1217,7 +1221,7 @@ nmtstp_ip6_address_add(NMPlatform * platform, } void -nmtstp_ip4_route_add(NMPlatform * platform, +nmtstp_ip4_route_add(NMPlatform *platform, int ifindex, NMIPConfigSource source, in_addr_t network, @@ -1243,7 +1247,7 @@ nmtstp_ip4_route_add(NMPlatform * platform, } void -nmtstp_ip6_route_add(NMPlatform * platform, +nmtstp_ip6_route_add(NMPlatform *platform, int ifindex, NMIPConfigSource source, struct in6_addr network, @@ -1271,7 +1275,7 @@ nmtstp_ip6_route_add(NMPlatform * platform, /*****************************************************************************/ static void -_ip_address_del(NMPlatform * platform, +_ip_address_del(NMPlatform *platform, gboolean external_command, gboolean is_v4, int ifindex, @@ -1388,7 +1392,7 @@ nmtstp_ip4_address_del(NMPlatform *platform, } void -nmtstp_ip6_address_del(NMPlatform * platform, +nmtstp_ip6_address_del(NMPlatform *platform, gboolean external_command, int ifindex, struct in6_addr address, @@ -1427,7 +1431,7 @@ nmtstp_ip6_address_del(NMPlatform * platform, const NMPlatformLnkBridge * nmtstp_link_bridge_normalize_jiffies_time(const NMPlatformLnkBridge *requested, const NMPlatformLnkBridge *kernel, - NMPlatformLnkBridge * dst) + NMPlatformLnkBridge *dst) { g_assert(requested); g_assert(dst); @@ -1458,12 +1462,12 @@ nmtstp_link_bridge_normalize_jiffies_time(const NMPlatformLnkBridge *requested, } const NMPlatformLink * -nmtstp_link_bridge_add(NMPlatform * platform, +nmtstp_link_bridge_add(NMPlatform *platform, gboolean external_command, - const char * name, + const char *name, const NMPlatformLnkBridge *lnk) { - const NMPlatformLink * pllink = NULL; + const NMPlatformLink *pllink = NULL; const NMPlatformLnkBridge *ll = NULL; NMPlatformLnkBridge lnk_normalized; int r = 0; @@ -1686,9 +1690,9 @@ nmtstp_link_dummy_add(NMPlatform *platform, gboolean external_command, const cha } const NMPlatformLink * -nmtstp_link_gre_add(NMPlatform * platform, +nmtstp_link_gre_add(NMPlatform *platform, gboolean external_command, - const char * name, + const char *name, const NMPlatformLnkGre *lnk) { const NMPlatformLink *pllink = NULL; @@ -1706,7 +1710,7 @@ nmtstp_link_gre_add(NMPlatform * platform, if (external_command) { gs_free char *dev = NULL; - char * obj, *type; + char *obj, *type; if (lnk->parent_ifindex) dev = @@ -1737,9 +1741,9 @@ nmtstp_link_gre_add(NMPlatform * platform, } const NMPlatformLink * -nmtstp_link_ip6tnl_add(NMPlatform * platform, +nmtstp_link_ip6tnl_add(NMPlatform *platform, gboolean external_command, - const char * name, + const char *name, const NMPlatformLnkIp6Tnl *lnk) { const NMPlatformLink *pllink = NULL; @@ -1760,7 +1764,7 @@ nmtstp_link_ip6tnl_add(NMPlatform * platform, if (external_command) { gs_free char *dev = NULL; - const char * mode; + const char *mode; if (lnk->parent_ifindex) dev = @@ -1803,9 +1807,9 @@ nmtstp_link_ip6tnl_add(NMPlatform * platform, } const NMPlatformLink * -nmtstp_link_ip6gre_add(NMPlatform * platform, +nmtstp_link_ip6gre_add(NMPlatform *platform, gboolean external_command, - const char * name, + const char *name, const NMPlatformLnkIp6Tnl *lnk) { const NMPlatformLink *pllink = NULL; @@ -1862,9 +1866,9 @@ nmtstp_link_ip6gre_add(NMPlatform * platform, } const NMPlatformLink * -nmtstp_link_ipip_add(NMPlatform * platform, +nmtstp_link_ipip_add(NMPlatform *platform, gboolean external_command, - const char * name, + const char *name, const NMPlatformLnkIpIp *lnk) { const NMPlatformLink *pllink = NULL; @@ -1905,9 +1909,9 @@ nmtstp_link_ipip_add(NMPlatform * platform, } const NMPlatformLink * -nmtstp_link_macvlan_add(NMPlatform * platform, +nmtstp_link_macvlan_add(NMPlatform *platform, gboolean external_command, - const char * name, + const char *name, int parent, const NMPlatformLnkMacvlan *lnk) { @@ -1925,7 +1929,7 @@ nmtstp_link_macvlan_add(NMPlatform * platform, if (external_command) { const char *dev; - char * modes[] = { + char *modes[] = { [MACVLAN_MODE_BRIDGE] = "bridge", [MACVLAN_MODE_VEPA] = "vepa", [MACVLAN_MODE_PRIVATE] = "private", @@ -1954,9 +1958,9 @@ nmtstp_link_macvlan_add(NMPlatform * platform, } const NMPlatformLink * -nmtstp_link_sit_add(NMPlatform * platform, +nmtstp_link_sit_add(NMPlatform *platform, gboolean external_command, - const char * name, + const char *name, const NMPlatformLnkSit *lnk) { const NMPlatformLink *pllink = NULL; @@ -2001,11 +2005,11 @@ nmtstp_link_sit_add(NMPlatform * platform, } const NMPlatformLink * -nmtstp_link_tun_add(NMPlatform * platform, +nmtstp_link_tun_add(NMPlatform *platform, gboolean external_command, - const char * name, + const char *name, const NMPlatformLnkTun *lnk, - int * out_fd) + int *out_fd) { const NMPlatformLink *pllink = NULL; int err; @@ -2066,11 +2070,11 @@ nmtstp_link_tun_add(NMPlatform * platform, } const NMPlatformLink * -nmtstp_link_vrf_add(NMPlatform * platform, +nmtstp_link_vrf_add(NMPlatform *platform, gboolean external_command, - const char * name, + const char *name, const NMPlatformLnkVrf *lnk, - gboolean * out_not_supported) + gboolean *out_not_supported) { const NMPlatformLink *pllink = NULL; int r = 0; @@ -2103,9 +2107,9 @@ nmtstp_link_vrf_add(NMPlatform * platform, } const NMPlatformLink * -nmtstp_link_vxlan_add(NMPlatform * platform, +nmtstp_link_vxlan_add(NMPlatform *platform, gboolean external_command, - const char * name, + const char *name, const NMPlatformLnkVxlan *lnk) { const NMPlatformLink *pllink = NULL; @@ -2228,7 +2232,7 @@ nmtstp_link_delete(NMPlatform *platform, gint64 end_time; const NMPlatformLink *pllink; gboolean success; - gs_free char * name_copy = NULL; + gs_free char *name_copy = NULL; external_command = nmtstp_run_command_check_external(external_command); @@ -2653,9 +2657,9 @@ main(int argc, char **argv) struct _NMTstpAcdDefender { int ifindex; in_addr_t ip_addr; - NAcd * nacd; + NAcd *nacd; NAcdProbe *probe; - GSource * source; + GSource *source; gint8 announce_started; }; @@ -2713,11 +2717,11 @@ _l3_acd_nacd_event(int fd, GIOCondition condition, gpointer user_data) NMTstpAcdDefender * nmtstp_acd_defender_new(int ifindex, in_addr_t ip_addr, const NMEtherAddr *mac_addr) { - NMTstpAcdDefender * defender; - nm_auto(n_acd_config_freep) NAcdConfig * config = NULL; - nm_auto(n_acd_unrefp) NAcd * nacd = NULL; + NMTstpAcdDefender *defender; + nm_auto(n_acd_config_freep) NAcdConfig *config = NULL; + nm_auto(n_acd_unrefp) NAcd *nacd = NULL; nm_auto(n_acd_probe_config_freep) NAcdProbeConfig *probe_config = NULL; - NAcdProbe * probe = NULL; + NAcdProbe *probe = NULL; int fd; int r; char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN]; diff --git a/src/core/platform/tests/test-common.h b/src/core/platform/tests/test-common.h index fc4149f0..77f2c50d 100644 --- a/src/core/platform/tests/test-common.h +++ b/src/core/platform/tests/test-common.h @@ -90,19 +90,19 @@ void nmtstp_netns_select_random(NMPlatform **platforms, gsize n_platforms, NMPNe typedef struct { gulong handler_id; - const char * name; + const char *name; NMPlatformSignalChangeType change_type; int received_count; - GMainLoop * loop; + GMainLoop *loop; int ifindex; - const char * ifname; + const char *ifname; } SignalData; -SignalData *add_signal_full(const char * name, +SignalData *add_signal_full(const char *name, NMPlatformSignalChangeType change_type, GCallback callback, int ifindex, - const char * ifname); + const char *ifname); #define add_signal(name, change_type, callback) \ add_signal_full(name, change_type, G_CALLBACK(callback), 0, NULL) #define add_signal_ifindex(name, change_type, callback, ifindex) \ @@ -124,12 +124,12 @@ void _free_signal(const char *file, int line, const char *func, SignalData *data #define ensure_no_signal(data) _ensure_no_signal(__FILE__, __LINE__, G_STRFUNC, data) #define free_signal(data) _free_signal(__FILE__, __LINE__, G_STRFUNC, data) -void link_callback(NMPlatform * platform, +void link_callback(NMPlatform *platform, int obj_type_i, int ifindex, NMPlatformLink *received, int change_type_i, - SignalData * data); + SignalData *data); /*****************************************************************************/ @@ -210,12 +210,12 @@ const NMPlatformIP4Route *nmtstp_ip4_route_get(NMPlatform *platform, guint32 metric, guint8 tos); -const NMPlatformIP6Route *_nmtstp_assert_ip6_route_exists(const char * file, +const NMPlatformIP6Route *_nmtstp_assert_ip6_route_exists(const char *file, guint line, - const char * func, - NMPlatform * platform, + const char *func, + NMPlatform *platform, int c_exists, - const char * ifname, + const char *ifname, const struct in6_addr *network, guint plen, guint32 metric, @@ -241,7 +241,7 @@ const NMPlatformIP6Route *_nmtstp_assert_ip6_route_exists(const char * src, \ src_plen) -const NMPlatformIP6Route *nmtstp_ip6_route_get(NMPlatform * platform, +const NMPlatformIP6Route *nmtstp_ip6_route_get(NMPlatform *platform, int ifindex, const struct in6_addr *network, guint plen, @@ -270,7 +270,7 @@ void nmtstp_ip4_address_add(NMPlatform *platform, guint32 preferred, guint32 flags, const char *label); -void nmtstp_ip6_address_add(NMPlatform * platform, +void nmtstp_ip6_address_add(NMPlatform *platform, gboolean external_command, int ifindex, struct in6_addr address, @@ -285,13 +285,13 @@ void nmtstp_ip4_address_del(NMPlatform *platform, in_addr_t address, int plen, in_addr_t peer_address); -void nmtstp_ip6_address_del(NMPlatform * platform, +void nmtstp_ip6_address_del(NMPlatform *platform, gboolean external_command, int ifindex, struct in6_addr address, int plen); -void nmtstp_ip4_route_add(NMPlatform * platform, +void nmtstp_ip4_route_add(NMPlatform *platform, int ifindex, NMIPConfigSource source, in_addr_t network, @@ -301,7 +301,7 @@ void nmtstp_ip4_route_add(NMPlatform * platform, guint32 metric, guint32 mss); -void nmtstp_ip6_route_add(NMPlatform * platform, +void nmtstp_ip6_route_add(NMPlatform *platform, int ifindex, NMIPConfigSource source, struct in6_addr network, @@ -357,9 +357,9 @@ nmtstp_platform_ip6_address_find(NMPlatform *self, int ifindex, const struct in6 nmtstp_platform_ip_address_find(self, ifindex, AF_INET6, addr); } -void _nmtstp_platform_ip_addresses_assert(const char * filename, +void _nmtstp_platform_ip_addresses_assert(const char *filename, int lineno, - NMPlatform * self, + NMPlatform *self, int ifindex, gboolean force_exact_4, gboolean force_exact_6, @@ -417,7 +417,7 @@ nmtstp_platform_routing_rules_get_count(NMPlatform *platform, int addr_family) { const NMDedupMultiHeadEntry *head_entry; NMDedupMultiIter iter; - const NMPObject * obj; + const NMPObject *obj; NMPLookup lookup; guint n; @@ -440,7 +440,7 @@ gboolean nmtstp_platform_ip4_route_delete(NMPlatform *platform, in_addr_t network, guint8 plen, guint32 metric); -gboolean nmtstp_platform_ip6_route_delete(NMPlatform * platform, +gboolean nmtstp_platform_ip6_route_delete(NMPlatform *platform, int ifindex, struct in6_addr network, guint8 plen, @@ -458,11 +458,11 @@ nmtstp_link_set_updown(NMPlatform *platform, gboolean external_command, int ifin const NMPlatformLnkBridge * nmtstp_link_bridge_normalize_jiffies_time(const NMPlatformLnkBridge *requested, const NMPlatformLnkBridge *kernel, - NMPlatformLnkBridge * dst); + NMPlatformLnkBridge *dst); -const NMPlatformLink *nmtstp_link_bridge_add(NMPlatform * platform, +const NMPlatformLink *nmtstp_link_bridge_add(NMPlatform *platform, gboolean external_command, - const char * name, + const char *name, const NMPlatformLnkBridge *lnk); const NMPlatformLink *nmtstp_link_veth_add(NMPlatform *platform, gboolean external_command, @@ -470,44 +470,44 @@ const NMPlatformLink *nmtstp_link_veth_add(NMPlatform *platform, const char *peer); const NMPlatformLink * nmtstp_link_dummy_add(NMPlatform *platform, gboolean external_command, const char *name); -const NMPlatformLink *nmtstp_link_gre_add(NMPlatform * platform, +const NMPlatformLink *nmtstp_link_gre_add(NMPlatform *platform, gboolean external_command, - const char * name, + const char *name, const NMPlatformLnkGre *lnk); -const NMPlatformLink *nmtstp_link_ip6tnl_add(NMPlatform * platform, +const NMPlatformLink *nmtstp_link_ip6tnl_add(NMPlatform *platform, gboolean external_command, - const char * name, + const char *name, const NMPlatformLnkIp6Tnl *lnk); -const NMPlatformLink *nmtstp_link_ip6gre_add(NMPlatform * platform, +const NMPlatformLink *nmtstp_link_ip6gre_add(NMPlatform *platform, gboolean external_command, - const char * name, + const char *name, const NMPlatformLnkIp6Tnl *lnk); -const NMPlatformLink *nmtstp_link_ipip_add(NMPlatform * platform, +const NMPlatformLink *nmtstp_link_ipip_add(NMPlatform *platform, gboolean external_command, - const char * name, + const char *name, const NMPlatformLnkIpIp *lnk); -const NMPlatformLink *nmtstp_link_macvlan_add(NMPlatform * platform, +const NMPlatformLink *nmtstp_link_macvlan_add(NMPlatform *platform, gboolean external_command, - const char * name, + const char *name, int parent, const NMPlatformLnkMacvlan *lnk); -const NMPlatformLink *nmtstp_link_sit_add(NMPlatform * platform, +const NMPlatformLink *nmtstp_link_sit_add(NMPlatform *platform, gboolean external_command, - const char * name, + const char *name, const NMPlatformLnkSit *lnk); -const NMPlatformLink *nmtstp_link_tun_add(NMPlatform * platform, +const NMPlatformLink *nmtstp_link_tun_add(NMPlatform *platform, gboolean external_command, - const char * name, + const char *name, const NMPlatformLnkTun *lnk, - int * out_fd); -const NMPlatformLink *nmtstp_link_vrf_add(NMPlatform * platform, + int *out_fd); +const NMPlatformLink *nmtstp_link_vrf_add(NMPlatform *platform, gboolean external_command, - const char * name, + const char *name, const NMPlatformLnkVrf *lnk, - gboolean * out_not_supported); -const NMPlatformLink *nmtstp_link_vxlan_add(NMPlatform * platform, + gboolean *out_not_supported); +const NMPlatformLink *nmtstp_link_vxlan_add(NMPlatform *platform, gboolean external_command, - const char * name, + const char *name, const NMPlatformLnkVxlan *lnk); void nmtstp_link_delete(NMPlatform *platform, @@ -524,7 +524,7 @@ extern int NMTSTP_ENV1_EX; static inline void _nmtstp_env1_wrapper_setup(const NmtstTestData *test_data) { - int * p_ifindex; + int *p_ifindex; gpointer p_ifup; nmtst_test_data_unpack(test_data, &p_ifindex, NULL, NULL, NULL, &p_ifup); diff --git a/src/core/platform/tests/test-link.c b/src/core/platform/tests/test-link.c index 24e3fd99..48b321d2 100644 --- a/src/core/platform/tests/test-link.c +++ b/src/core/platform/tests/test-link.c @@ -169,12 +169,12 @@ software_add(NMLinkType link_type, const char *name) } static void -test_link_changed_signal_cb(NMPlatform * platform, +test_link_changed_signal_cb(NMPlatform *platform, int obj_type_i, int ifindex, const NMPlatformIP4Route *route, int change_type_i, - gboolean * p_test_link_changed_signal_arg) + gboolean *p_test_link_changed_signal_arg) { const NMPObjectType obj_type = obj_type_i; const NMPlatformSignalChangeType change_type = change_type_i; @@ -211,7 +211,7 @@ test_slave(int master, int type, SignalData *master_changed) link_callback, SLAVE_NAME); SignalData *link_changed, *link_removed; - char * value; + char *value; NMLinkType link_type = nm_platform_link_get_type(NM_PLATFORM_GET, master); gboolean test_link_changed_signal_arg1; gboolean test_link_changed_signal_arg2; @@ -422,7 +422,7 @@ test_software(NMLinkType link_type, const char *link_typename) link_callback, ifindex); if (link_type == NM_LINK_TYPE_VLAN) { - const NMPlatformLink * plink; + const NMPlatformLink *plink; const NMPlatformLnkVlan *plnk; plnk = nm_platform_link_get_lnk_vlan(NM_PLATFORM_GET, ifindex, &plink); @@ -754,7 +754,7 @@ test_external(void) { const NMPlatformLink *pllink; NMPLinkAddress hw_perm_addr; - SignalData * link_added, *link_changed, *link_removed; + SignalData *link_added, *link_changed, *link_removed; int ifindex; link_added = add_signal_ifname(NM_PLATFORM_SIGNAL_LINK_CHANGED, @@ -1157,10 +1157,10 @@ _test_wireguard_change(NMPlatform *platform, int ifindex, int test_mode) "wmjW2wDT2EzFkyaGui7YWNLTRu8Q4eD/GVKM2utZkEs="}, }; gs_unref_ptrarray GPtrArray *allowed_ips_keep_alive = NULL; - gs_unref_array GArray *peers = NULL; - NMPlatformLnkWireGuard lnk_wireguard; - int r; - guint i; + gs_unref_array GArray *peers = NULL; + NMPlatformLnkWireGuard lnk_wireguard; + int r; + guint i; allowed_ips_keep_alive = g_ptr_array_new_with_free_func(g_free); @@ -1270,8 +1270,8 @@ test_software_detect(gconstpointer user_data) { const TestAddSoftwareDetectData *test_data = user_data; int ifindex, ifindex_parent; - const NMPlatformLink * plink; - const NMPObject * lnk; + const NMPlatformLink *plink; + const NMPObject *lnk; int r; guint i_step; const gboolean ext = test_data->external_command; @@ -1991,7 +1991,7 @@ static void test_software_detect_add(const char *testpath, NMLinkType link_type, int test_mode) { TestAddSoftwareDetectData *test_data; - char * path; + char *path; test_data = g_new0(TestAddSoftwareDetectData, 1); test_data->link_type = link_type; @@ -2026,8 +2026,8 @@ test_software_detect_add(const char *testpath, NMLinkType link_type, int test_mo static void _assert_xgress_qos_mappings_impl(int ifindex, gboolean is_ingress_map, int n_entries, int n, ...) { - const NMPlatformLink * plink; - const NMPObject * lnk; + const NMPlatformLink *plink; + const NMPObject *lnk; guint n_map; const NMVlanQosMapping *map; va_list ap; @@ -2460,10 +2460,10 @@ test_vlan_set_xgress(void) static void test_create_many_links_do(guint n_devices) { - gint64 time, start_time = nm_utils_get_monotonic_timestamp_nsec(); - guint i; - char name[64]; - const NMPlatformLink *pllink; + gint64 time, start_time = nm_utils_get_monotonic_timestamp_nsec(); + guint i; + char name[64]; + const NMPlatformLink *pllink; gs_unref_array GArray *ifindexes = g_array_sized_new(FALSE, FALSE, sizeof(int), n_devices); const int EX = ((int) (nmtst_get_rand_uint32() % 4)) - 1; @@ -2540,12 +2540,12 @@ test_create_many_links(gconstpointer user_data) static void test_nl_bugs_veth(void) { - const char * IFACE_VETH0 = "nm-test-veth0"; - const char * IFACE_VETH1 = "nm-test-veth1"; - int ifindex_veth0, ifindex_veth1; - int i; - const NMPlatformLink *pllink_veth0, *pllink_veth1; - gs_free_error GError * error = NULL; + const char *IFACE_VETH0 = "nm-test-veth0"; + const char *IFACE_VETH1 = "nm-test-veth1"; + int ifindex_veth0, ifindex_veth1; + int i; + const NMPlatformLink *pllink_veth0, *pllink_veth1; + gs_free_error GError *error = NULL; NMTstpNamespaceHandle *ns_handle = NULL; NMPLinkAddress hw_perm_addr; @@ -2612,8 +2612,8 @@ out: static void test_nl_bugs_spuroius_newlink(void) { - const char * IFACE_BOND0 = "nm-test-bond0"; - const char * IFACE_DUMMY0 = "nm-test-dummy0"; + const char *IFACE_BOND0 = "nm-test-bond0"; + const char *IFACE_DUMMY0 = "nm-test-dummy0"; int ifindex_bond0, ifindex_dummy0; const NMPlatformLink *pllink; NMPLinkAddress hw_perm_addr; @@ -2668,8 +2668,8 @@ again: static void test_nl_bugs_spuroius_dellink(void) { - const char * IFACE_BRIDGE0 = "nm-test-bridge0"; - const char * IFACE_DUMMY0 = "nm-test-dummy0"; + const char *IFACE_BRIDGE0 = "nm-test-bridge0"; + const char *IFACE_DUMMY0 = "nm-test-dummy0"; int ifindex_bridge0, ifindex_dummy0; const NMPlatformLink *pllink; NMPLinkAddress hw_perm_addr; @@ -2745,7 +2745,7 @@ _test_netns_teardown(gpointer fixture, gconstpointer test_data) static NMPlatform * _test_netns_create_platform(void) { - NMPNetns * netns; + NMPNetns *netns; NMPlatform *platform; netns = nmp_netns_new(); @@ -2763,9 +2763,9 @@ _test_netns_create_platform(void) static gboolean _test_netns_check_skip(void) { - static int support = -1; - static int support_errsv = 0; - NMPNetns * netns; + static int support = -1; + static int support_errsv = 0; + NMPNetns *netns; gs_unref_object NMPNetns *netns2 = NULL; netns = nmp_netns_get_current(); @@ -2828,7 +2828,7 @@ test_netns_general(gpointer fixture, gconstpointer test_data) { gs_unref_object NMPlatform *platform_1 = NULL; gs_unref_object NMPlatform *platform_2 = NULL; - NMPNetns * netns_tmp; + NMPNetns *netns_tmp; char sbuf[100]; int i, j, k; gboolean ethtool_support; @@ -2959,7 +2959,7 @@ test_netns_general(gpointer fixture, gconstpointer test_data) static void test_netns_set_netns(gpointer fixture, gconstpointer test_data) { - NMPlatform * platforms[3]; + NMPlatform *platforms[3]; gs_unref_object NMPlatform *platform_0 = NULL; gs_unref_object NMPlatform *platform_1 = NULL; gs_unref_object NMPlatform *platform_2 = NULL; @@ -2997,8 +2997,8 @@ static char * _get_current_namespace_id(int ns_type) { const char *p; - GError * error = NULL; - char * id; + GError *error = NULL; + char *id; switch (ns_type) { case CLONE_NEWNET: @@ -3020,7 +3020,7 @@ _get_current_namespace_id(int ns_type) static char * _get_sysctl_value(const char *path) { - char * data = NULL; + char *data = NULL; gs_free_error GError *error = NULL; if (!g_file_get_contents(path, &data, NULL, &error)) { @@ -3037,10 +3037,10 @@ _get_sysctl_value(const char *path) static void test_netns_push(gpointer fixture, gconstpointer test_data) { - gs_unref_object NMPlatform *platform_0 = NULL; - gs_unref_object NMPlatform *platform_1 = NULL; - gs_unref_object NMPlatform *platform_2 = NULL; - nm_auto_pop_netns NMPNetns *netns_pop = NULL; + gs_unref_object NMPlatform *platform_0 = NULL; + gs_unref_object NMPlatform *platform_1 = NULL; + gs_unref_object NMPlatform *platform_2 = NULL; + nm_auto_pop_netns NMPNetns *netns_pop = NULL; gs_unref_ptrarray GPtrArray *device_names = g_ptr_array_new_with_free_func(g_free); int i, j; const int ns_types_list[] = {CLONE_NEWNET, CLONE_NEWNS, CLONE_NEWNET | CLONE_NEWNS}; @@ -3080,7 +3080,7 @@ test_netns_push(gpointer fixture, gconstpointer test_data) for (i = 0; i < G_N_ELEMENTS(pl); i++) { nm_auto_pop_netns NMPNetns *netns_free = NULL; - char * tmp; + char *tmp; g_assert(nm_platform_netns_push(pl[i].platform, &netns_free)); @@ -3207,8 +3207,8 @@ test_netns_bind_to_path(gpointer fixture, gconstpointer test_data) gs_unref_object NMPlatform *platform_1 = NULL; gs_unref_object NMPlatform *platform_2 = NULL; nm_auto_pop_netns NMPNetns *netns_pop = NULL; - NMPlatform * platforms[3]; - NMPNetns * netns; + NMPlatform *platforms[3]; + NMPNetns *netns; int i; if (_test_netns_check_skip()) @@ -3270,7 +3270,7 @@ test_sysctl_rename(void) nm_auto_close int dirfd = -1; int i; char ifname_buf[IFNAMSIZ]; - char * s; + char *s; const NMPlatformLink *pllink; ifindex[0] = nmtstp_link_dummy_add(PL, -1, IFNAME[0])->ifindex; @@ -3362,19 +3362,19 @@ test_sysctl_rename(void) static void test_sysctl_netns_switch(void) { - const char *const IFNAME = "nm-dummy-0"; - int ifindex, ifindex_tmp; - nm_auto_close int dirfd = -1; - char ifname_buf[IFNAMSIZ]; - char * s; + const char *const IFNAME = "nm-dummy-0"; + int ifindex, ifindex_tmp; + nm_auto_close int dirfd = -1; + char ifname_buf[IFNAMSIZ]; + char *s; gs_unref_object NMPlatform *platform_0 = NULL; gs_unref_object NMPlatform *platform_1 = NULL; gs_unref_object NMPlatform *platform_2 = NULL; nm_auto_pop_netns NMPNetns *netns_pop_1 = NULL; nm_auto_pop_netns NMPNetns *netns_pop_2 = NULL; nm_auto_pop_netns NMPNetns *netns_pop_3 = NULL; - NMPlatform * PL; - NMPlatform * platforms[3]; + NMPlatform *PL; + NMPlatform *platforms[3]; if (_test_netns_check_skip()) return; @@ -3432,7 +3432,7 @@ test_sysctl_netns_switch(void) { gint64 i64; int errsv; - char * v; + char *v; errno = ESRCH; v = nm_platform_sysctl_get( @@ -3501,7 +3501,7 @@ test_sysctl_netns_switch(void) } typedef struct { - GMainLoop * loop; + GMainLoop *loop; const char *path; gboolean expected_success; gint32 expected_value; @@ -3528,10 +3528,10 @@ sysctl_set_async_cb(GError *error, gpointer user_data) static void test_sysctl_set_async(void) { - NMPlatform *const PL = NM_PLATFORM_GET; - const char *const IFNAME = "nm-dummy-0"; - const char *const PATH = "/proc/sys/net/ipv4/conf/nm-dummy-0/rp_filter"; - GMainLoop * loop; + NMPlatform *const PL = NM_PLATFORM_GET; + const char *const IFNAME = "nm-dummy-0"; + const char *const PATH = "/proc/sys/net/ipv4/conf/nm-dummy-0/rp_filter"; + GMainLoop *loop; gs_unref_object GCancellable *cancellable = NULL; gboolean proc_writable; SetAsyncData data; @@ -3583,10 +3583,10 @@ test_sysctl_set_async(void) static void test_sysctl_set_async_fail(void) { - NMPlatform *const PL = NM_PLATFORM_GET; - const char *const IFNAME = "nm-dummy-0"; - const char *const PATH = "/proc/sys/net/ipv4/conf/nm-dummy-0/does-not-exist"; - GMainLoop * loop; + NMPlatform *const PL = NM_PLATFORM_GET; + const char *const IFNAME = "nm-dummy-0"; + const char *const PATH = "/proc/sys/net/ipv4/conf/nm-dummy-0/does-not-exist"; + GMainLoop *loop; gs_unref_object GCancellable *cancellable = NULL; SetAsyncData data; int ifindex; @@ -3620,10 +3620,10 @@ test_sysctl_set_async_fail(void) static gpointer _test_netns_mt_thread(gpointer data) { - NMPNetns * netns1 = data; + NMPNetns *netns1 = data; gs_unref_object NMPNetns *netns2 = NULL; - NMPNetns * netns_bottom; - NMPNetns * initial; + NMPNetns *netns_bottom; + NMPNetns *initial; netns_bottom = nmp_netns_get_initial(); g_assert(netns_bottom); @@ -3654,8 +3654,8 @@ static void test_netns_mt(void) { gs_unref_object NMPNetns *netns1 = NULL; - NMPNetns * initial_from_other_thread; - GThread * th; + NMPNetns *initial_from_other_thread; + GThread *th; if (_test_netns_check_skip()) return; @@ -3732,7 +3732,7 @@ test_ethtool_features_get(void) for (i_run = 0; i_run < 5; i_run++) { NMEthtoolFeatureStates *features; - NMOptionBool * requested; + NMOptionBool *requested; gboolean do_set = TRUE; requested = g_new(NMOptionBool, _NM_ETHTOOL_ID_FEATURE_NUM); diff --git a/src/core/platform/tests/test-nmp-object.c b/src/core/platform/tests/test-nmp-object.c index 6d2236ec..ddd5aa93 100644 --- a/src/core/platform/tests/test-nmp-object.c +++ b/src/core/platform/tests/test-nmp-object.c @@ -30,14 +30,14 @@ test_obj_base(void) GTypeClass k; NMPClass c; } l = {}; - static const GObject * g = &x.g; + static const GObject *g = &x.g; static const GTypeClass *k = &l.k; - static const NMPObject * o = &x.k; - static const NMPClass * c = &l.c; + static const NMPObject *o = &x.k; + static const NMPClass *c = &l.c; - NMObjBaseInst * obj; + NMObjBaseInst *obj; gs_unref_object GCancellable *obj_cancellable = g_cancellable_new(); - nm_auto_nmpobj NMPObject *obj_link = nmp_object_new_link(10); + nm_auto_nmpobj NMPObject *obj_link = nmp_object_new_link(10); g_assert(&g->g_type_instance == (void *) &o->_class); g_assert(&g->g_type_instance.g_class == (void *) &o->_class); @@ -88,9 +88,9 @@ _nmp_object_equal(const NMPObject *a, const NMPObject *b) /*****************************************************************************/ static void -_assert_cache_multi_lookup_contains(const NMPCache * cache, +_assert_cache_multi_lookup_contains(const NMPCache *cache, const NMDedupMultiHeadEntry *head_entry, - const NMPObject * obj, + const NMPObject *obj, gboolean visible_only, gboolean contains) { @@ -126,7 +126,7 @@ _assert_cache_multi_lookup_contains(const NMPCache * cache, } static void -_assert_cache_multi_lookup_contains_link(const NMPCache * cache, +_assert_cache_multi_lookup_contains_link(const NMPCache *cache, gboolean visible_only, const NMPObject *obj, gboolean contains) @@ -144,7 +144,7 @@ _assert_cache_multi_lookup_contains_link(const NMPCache * cache, /*****************************************************************************/ static void -ops_post_check(NMPCache * cache, +ops_post_check(NMPCache *cache, NMPCacheOpsType ops_type, const NMPObject *obj_old, const NMPObject *obj_new, @@ -199,16 +199,16 @@ ops_post_check(NMPCache * cache, } static void -_nmp_cache_update_netlink(NMPCache * cache, - NMPObject * obj, +_nmp_cache_update_netlink(NMPCache *cache, + NMPObject *obj, const NMPObject **out_obj_old, const NMPObject **out_obj_new, NMPCacheOpsType expected_ops_type) { - NMPCacheOpsType ops_type; - const NMPObject *obj_prev; - const NMPObject *obj_old; - const NMPObject *obj_new; + NMPCacheOpsType ops_type; + const NMPObject *obj_prev; + const NMPObject *obj_old; + const NMPObject *obj_new; nm_auto_nmpobj NMPObject *obj_new_expected = NULL; g_assert(cache); @@ -253,13 +253,13 @@ static const NMPlatformLink pl_link_3 = { static void test_cache_link(void) { - NMPCache * cache; - NMPObject * objm1; - const NMPObject * obj_old, *obj_new; - NMPObject objs1; - struct udev_device * udev_device_2 = g_list_nth_data(global.udev_devices, 0); - struct udev_device * udev_device_3 = g_list_nth_data(global.udev_devices, 0); - NMPCacheOpsType ops_type; + NMPCache *cache; + NMPObject *objm1; + const NMPObject *obj_old, *obj_new; + NMPObject objs1; + struct udev_device *udev_device_2 = g_list_nth_data(global.udev_devices, 0); + struct udev_device *udev_device_3 = g_list_nth_data(global.udev_devices, 0); + NMPCacheOpsType ops_type; nm_auto_unref_dedup_multi_index NMDedupMultiIndex *multi_idx = NULL; gboolean use_udev = nmtst_get_rand_uint32() % 2; @@ -512,11 +512,11 @@ static const NMPlatformQdisc pl_qdisc_2 = { static void test_cache_qdisc(void) { - NMPCache * cache; + NMPCache *cache; nm_auto_unref_dedup_multi_index NMDedupMultiIndex *multi_idx = NULL; NMPLookup lookup; - const NMDedupMultiHeadEntry * head_entry; - nm_auto_nmpobj NMPObject *obj1a = + const NMDedupMultiHeadEntry *head_entry; + nm_auto_nmpobj NMPObject *obj1a = nmp_object_new(NMP_OBJECT_TYPE_QDISC, (NMPlatformObject *) &pl_qdisc_1a); nm_auto_nmpobj NMPObject *obj1b = nmp_object_new(NMP_OBJECT_TYPE_QDISC, (NMPlatformObject *) &pl_qdisc_1b); @@ -571,7 +571,7 @@ main(int argc, char **argv) udev_client = nm_udev_client_new(NM_MAKE_STRV("net"), NULL, NULL); { - struct udev_enumerate * enumerator; + struct udev_enumerate *enumerator; struct udev_list_entry *devices, *l; enumerator = nm_udev_client_enumerate_new(udev_client); diff --git a/src/core/platform/tests/test-platform-general.c b/src/core/platform/tests/test-platform-general.c index 8ffd92b5..9629326a 100644 --- a/src/core/platform/tests/test-platform-general.c +++ b/src/core/platform/tests/test-platform-general.c @@ -39,8 +39,8 @@ test_init_linux_platform(void) static void test_link_get_all(void) { - gs_unref_object NMPlatform *platform = NULL; - gs_unref_ptrarray GPtrArray *links = NULL; + gs_unref_object NMPlatform *platform = NULL; + gs_unref_ptrarray GPtrArray *links = NULL; platform = nm_linux_platform_new(TRUE, NM_PLATFORM_NETNS_SUPPORT_DEFAULT, TRUE); @@ -548,11 +548,11 @@ test_platform_ip_address_pretty_sort_cmp(gconstpointer test_data) const guint N_ADDRESSES = 100; const gsize ELM_SIZE = addr_family == AF_INET ? sizeof(NMPlatformIP4Address) : sizeof(NMPlatformIP6Address); - const gboolean DO_REGENERATE = FALSE; - const gboolean PRINT_RESULT = DO_REGENERATE; - const gboolean CHECK_RESULT = !DO_REGENERATE; - gs_free guint8 *addresses = NULL; - gs_free guint64 *rand_map = NULL; + const gboolean DO_REGENERATE = FALSE; + const gboolean PRINT_RESULT = DO_REGENERATE; + const gboolean CHECK_RESULT = !DO_REGENERATE; + gs_free guint8 *addresses = NULL; + gs_free guint64 *rand_map = NULL; gsize i, j; #if !defined(__amd64__) @@ -586,7 +586,7 @@ test_platform_ip_address_pretty_sort_cmp(gconstpointer test_data) for (i = 0; i < N_ADDRESSES; i++) { NMPlatformIPXAddress *a = (gpointer) (&addresses[i * ELM_SIZE]); guint64 r = rand_map[i]; - struct in6_addr * a6; + struct in6_addr *a6; #define CONSUME_BITS(r, nbits) \ ({ \ @@ -748,6 +748,31 @@ test_platform_ip_address_pretty_sort_cmp(gconstpointer test_data) /*****************************************************************************/ +static void +test_route_type_is_nodev(void) +{ + int i; + + for (i = -1; i <= 257; i++) { + gboolean is_nodev; + + switch ((guint8) i) { + case RTN_BLACKHOLE: + case RTN_UNREACHABLE: + case RTN_PROHIBIT: + is_nodev = TRUE; + break; + default: + is_nodev = FALSE; + break; + } + + g_assert_cmpint(is_nodev, ==, nm_platform_route_type_is_nodev(i)); + } +} + +/*****************************************************************************/ + NMTST_DEFINE(); int @@ -767,6 +792,7 @@ main(int argc, char **argv) g_test_add_data_func("/general/platform_ip_address_pretty_sort_cmp/6/2", GINT_TO_POINTER(2), test_platform_ip_address_pretty_sort_cmp); + g_test_add_func("/general/test_route_type_is_nodev", test_route_type_is_nodev); return g_test_run(); } diff --git a/src/core/platform/tests/test-route.c b/src/core/platform/tests/test-route.c index 4b1db7fa..cf0236e0 100644 --- a/src/core/platform/tests/test-route.c +++ b/src/core/platform/tests/test-route.c @@ -10,7 +10,7 @@ #include "nm-core-utils.h" #include "libnm-platform/nm-platform-utils.h" -#include "libnm-platform/nmp-rules-manager.h" +#include "libnm-platform/nmp-route-manager.h" #include "test-common.h" @@ -51,7 +51,7 @@ _wait_for_ipv4_addr_device_route(NMPlatform *platform, } static void -_wait_for_ipv6_addr_non_tentative(NMPlatform * platform, +_wait_for_ipv6_addr_non_tentative(NMPlatform *platform, gint64 timeout_msec, int ifindex, guint addr_n, @@ -83,17 +83,17 @@ _wait_for_ipv6_addr_non_tentative(NMPlatform * platform, } static void -ip4_route_callback(NMPlatform * platform, +ip4_route_callback(NMPlatform *platform, int obj_type_i, int ifindex, const NMPlatformIP4Route *received, int change_type_i, - SignalData * data) + SignalData *data) { const NMPObjectType obj_type = obj_type_i; const NMPlatformSignalChangeType change_type = change_type_i; NMPObject o_id; - nm_auto_nmpobj NMPObject *o_id_p = nmp_object_new(NMP_OBJECT_TYPE_IP4_ROUTE, NULL); + nm_auto_nmpobj NMPObject *o_id_p = nmp_object_new(NMP_OBJECT_TYPE_IP4_ROUTE, NULL); g_assert_cmpint(obj_type, ==, NMP_OBJECT_TYPE_IP4_ROUTE); g_assert(received); @@ -119,17 +119,17 @@ ip4_route_callback(NMPlatform * platform, } static void -ip6_route_callback(NMPlatform * platform, +ip6_route_callback(NMPlatform *platform, int obj_type_i, int ifindex, const NMPlatformIP6Route *received, int change_type_i, - SignalData * data) + SignalData *data) { const NMPObjectType obj_type = obj_type_i; const NMPlatformSignalChangeType change_type = change_type_i; NMPObject o_id; - nm_auto_nmpobj NMPObject *o_id_p = nmp_object_new(NMP_OBJECT_TYPE_IP6_ROUTE, NULL); + nm_auto_nmpobj NMPObject *o_id_p = nmp_object_new(NMP_OBJECT_TYPE_IP6_ROUTE, NULL); g_assert_cmpint(obj_type, ==, NMP_OBJECT_TYPE_IP6_ROUTE); g_assert(received); @@ -244,16 +244,16 @@ static void test_ip4_route(void) { int ifindex = nm_platform_link_get_ifindex(NM_PLATFORM_GET, DEVICE_NAME); - SignalData * route_added = add_signal(NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, + SignalData *route_added = add_signal(NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, NM_PLATFORM_SIGNAL_ADDED, ip4_route_callback); - SignalData * route_changed = add_signal(NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, + SignalData *route_changed = add_signal(NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, NM_PLATFORM_SIGNAL_CHANGED, ip4_route_callback); - SignalData * route_removed = add_signal(NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, + SignalData *route_removed = add_signal(NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, NM_PLATFORM_SIGNAL_REMOVED, ip4_route_callback); - GPtrArray * routes; + GPtrArray *routes; NMPlatformIP4Route rts[3]; in_addr_t network; guint8 plen = 24; @@ -332,33 +332,30 @@ test_ip4_route(void) /* Test route listing */ routes = nmtstp_ip4_route_get_all(NM_PLATFORM_GET, ifindex); memset(rts, 0, sizeof(rts)); - rts[0].rt_source = nmp_utils_ip_config_source_round_trip_rtprot(NM_IP_CONFIG_SOURCE_USER); - rts[0].network = gateway; - rts[0].plen = 32; - rts[0].ifindex = ifindex; - rts[0].gateway = INADDR_ANY; - rts[0].metric = metric; - rts[0].mss = mss; - rts[0].is_external = TRUE; - rts[0].scope_inv = nm_platform_route_scope_inv(RT_SCOPE_LINK); - rts[1].rt_source = nmp_utils_ip_config_source_round_trip_rtprot(NM_IP_CONFIG_SOURCE_USER); - rts[1].network = network; - rts[1].plen = plen; - rts[1].ifindex = ifindex; - rts[1].gateway = gateway; - rts[1].metric = metric; - rts[1].mss = mss; - rts[1].scope_inv = nm_platform_route_scope_inv(RT_SCOPE_UNIVERSE); - rts[1].is_external = TRUE; - rts[2].rt_source = nmp_utils_ip_config_source_round_trip_rtprot(NM_IP_CONFIG_SOURCE_USER); - rts[2].network = 0; - rts[2].plen = 0; - rts[2].ifindex = ifindex; - rts[2].gateway = gateway; - rts[2].metric = metric; - rts[2].mss = mss; - rts[2].scope_inv = nm_platform_route_scope_inv(RT_SCOPE_UNIVERSE); - rts[2].is_external = TRUE; + rts[0].rt_source = nmp_utils_ip_config_source_round_trip_rtprot(NM_IP_CONFIG_SOURCE_USER); + rts[0].network = gateway; + rts[0].plen = 32; + rts[0].ifindex = ifindex; + rts[0].gateway = INADDR_ANY; + rts[0].metric = metric; + rts[0].mss = mss; + rts[0].scope_inv = nm_platform_route_scope_inv(RT_SCOPE_LINK); + rts[1].rt_source = nmp_utils_ip_config_source_round_trip_rtprot(NM_IP_CONFIG_SOURCE_USER); + rts[1].network = network; + rts[1].plen = plen; + rts[1].ifindex = ifindex; + rts[1].gateway = gateway; + rts[1].metric = metric; + rts[1].mss = mss; + rts[1].scope_inv = nm_platform_route_scope_inv(RT_SCOPE_UNIVERSE); + rts[2].rt_source = nmp_utils_ip_config_source_round_trip_rtprot(NM_IP_CONFIG_SOURCE_USER); + rts[2].network = 0; + rts[2].plen = 0; + rts[2].ifindex = ifindex; + rts[2].gateway = gateway; + rts[2].metric = metric; + rts[2].mss = mss; + rts[2].scope_inv = nm_platform_route_scope_inv(RT_SCOPE_UNIVERSE); g_assert_cmpint(routes->len, ==, 3); nmtst_platform_ip4_routes_equal_aptr((const NMPObject *const *) routes->pdata, rts, @@ -391,16 +388,16 @@ static void test_ip6_route(void) { int ifindex = nm_platform_link_get_ifindex(NM_PLATFORM_GET, DEVICE_NAME); - SignalData * route_added = add_signal(NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, + SignalData *route_added = add_signal(NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, NM_PLATFORM_SIGNAL_ADDED, ip6_route_callback); - SignalData * route_changed = add_signal(NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, + SignalData *route_changed = add_signal(NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, NM_PLATFORM_SIGNAL_CHANGED, ip6_route_callback); - SignalData * route_removed = add_signal(NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, + SignalData *route_removed = add_signal(NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, NM_PLATFORM_SIGNAL_REMOVED, ip6_route_callback); - GPtrArray * routes; + GPtrArray *routes; NMPlatformIP6Route rts[3]; struct in6_addr network; guint8 plen = 64; @@ -492,33 +489,30 @@ test_ip6_route(void) /* Test route listing */ routes = nmtstp_ip6_route_get_all(NM_PLATFORM_GET, ifindex); memset(rts, 0, sizeof(rts)); - rts[0].rt_source = nmp_utils_ip_config_source_round_trip_rtprot(NM_IP_CONFIG_SOURCE_USER); - rts[0].network = gateway; - rts[0].plen = 128; - rts[0].ifindex = ifindex; - rts[0].gateway = in6addr_any; - rts[0].pref_src = in6addr_any; - rts[0].metric = metric; - rts[0].mss = mss; - rts[0].is_external = TRUE; - rts[1].rt_source = nmp_utils_ip_config_source_round_trip_rtprot(NM_IP_CONFIG_SOURCE_USER); - rts[1].network = network; - rts[1].plen = plen; - rts[1].ifindex = ifindex; - rts[1].gateway = gateway; - rts[1].pref_src = pref_src; - rts[1].metric = metric; - rts[1].mss = mss; - rts[1].is_external = TRUE; - rts[2].rt_source = nmp_utils_ip_config_source_round_trip_rtprot(NM_IP_CONFIG_SOURCE_USER); - rts[2].network = in6addr_any; - rts[2].plen = 0; - rts[2].ifindex = ifindex; - rts[2].gateway = gateway; - rts[2].pref_src = in6addr_any; - rts[2].metric = metric; - rts[2].mss = mss; - rts[2].is_external = TRUE; + rts[0].rt_source = nmp_utils_ip_config_source_round_trip_rtprot(NM_IP_CONFIG_SOURCE_USER); + rts[0].network = gateway; + rts[0].plen = 128; + rts[0].ifindex = ifindex; + rts[0].gateway = in6addr_any; + rts[0].pref_src = in6addr_any; + rts[0].metric = metric; + rts[0].mss = mss; + rts[1].rt_source = nmp_utils_ip_config_source_round_trip_rtprot(NM_IP_CONFIG_SOURCE_USER); + rts[1].network = network; + rts[1].plen = plen; + rts[1].ifindex = ifindex; + rts[1].gateway = gateway; + rts[1].pref_src = pref_src; + rts[1].metric = metric; + rts[1].mss = mss; + rts[2].rt_source = nmp_utils_ip_config_source_round_trip_rtprot(NM_IP_CONFIG_SOURCE_USER); + rts[2].network = in6addr_any; + rts[2].plen = 0; + rts[2].ifindex = ifindex; + rts[2].gateway = gateway; + rts[2].pref_src = in6addr_any; + rts[2].metric = metric; + rts[2].mss = mss; g_assert_cmpint(routes->len, ==, 3); nmtst_platform_ip6_routes_equal_aptr((const NMPObject *const *) routes->pdata, rts, @@ -552,9 +546,9 @@ test_ip6_route(void) static void test_ip4_route_get(void) { - int ifindex = nm_platform_link_get_ifindex(NM_PLATFORM_GET, DEVICE_NAME); - in_addr_t a; - int result; + int ifindex = nm_platform_link_get_ifindex(NM_PLATFORM_GET, DEVICE_NAME); + in_addr_t a; + int result; nm_auto_nmpobj NMPObject *route = NULL; const NMPlatformIP4Route *r; @@ -626,8 +620,8 @@ test_ip4_zero_gateway(void) static void test_ip4_route_options(gconstpointer test_data) { - const int TEST_IDX = GPOINTER_TO_INT(test_data); - const int IFINDEX = nm_platform_link_get_ifindex(NM_PLATFORM_GET, DEVICE_NAME); + const int TEST_IDX = GPOINTER_TO_INT(test_data); + const int IFINDEX = nm_platform_link_get_ifindex(NM_PLATFORM_GET, DEVICE_NAME); gs_unref_ptrarray GPtrArray *routes = NULL; #define RTS_MAX 3 NMPlatformIP4Route rts_add[RTS_MAX] = {}; @@ -656,13 +650,13 @@ test_ip4_route_options(gconstpointer test_data) break; case 2: addr[addr_n++] = ((NMPlatformIP4Address){ - .ifindex = IFINDEX, - .address = nmtst_inet4_from_string("172.16.1.5"), - .peer_address = nmtst_inet4_from_string("172.16.1.5"), - .plen = 24, - .lifetime = NM_PLATFORM_LIFETIME_PERMANENT, - .preferred = NM_PLATFORM_LIFETIME_PERMANENT, - .n_ifa_flags = 0, + .ifindex = IFINDEX, + .address = nmtst_inet4_from_string("172.16.1.5"), + .peer_address = nmtst_inet4_from_string("172.16.1.5"), + .plen = 24, + .lifetime = NM_PLATFORM_LIFETIME_PERMANENT, + .preferred = NM_PLATFORM_LIFETIME_PERMANENT, + .n_ifa_flags = 0, }); rts_add[rts_n++] = ((NMPlatformIP4Route){ .ifindex = IFINDEX, @@ -715,7 +709,6 @@ test_ip4_route_options(gconstpointer test_data) for (i = 0; i < rts_n; i++) { rts_cmp[i] = rts_add[i]; nm_platform_ip_route_normalize(AF_INET, NM_PLATFORM_IP_ROUTE_CAST(&rts_cmp[i])); - rts_cmp[i].is_external = TRUE; } routes = nmtstp_ip4_route_get_all(NM_PLATFORM_GET, IFINDEX); @@ -738,9 +731,9 @@ test_ip4_route_options(gconstpointer test_data) static void test_ip6_route_get(void) { - int ifindex = nm_platform_link_get_ifindex(NM_PLATFORM_GET, DEVICE_NAME); - const struct in6_addr *a; - int result; + int ifindex = nm_platform_link_get_ifindex(NM_PLATFORM_GET, DEVICE_NAME); + const struct in6_addr *a; + int result; nm_auto_nmpobj NMPObject *route = NULL; const NMPlatformIP6Route *r; @@ -783,8 +776,8 @@ test_ip6_route_get(void) static void test_ip6_route_options(gconstpointer test_data) { - const int TEST_IDX = GPOINTER_TO_INT(test_data); - const int IFINDEX = nm_platform_link_get_ifindex(NM_PLATFORM_GET, DEVICE_NAME); + const int TEST_IDX = GPOINTER_TO_INT(test_data); + const int IFINDEX = nm_platform_link_get_ifindex(NM_PLATFORM_GET, DEVICE_NAME); gs_unref_ptrarray GPtrArray *routes = NULL; #define RTS_MAX 3 NMPlatformIP6Route rts_add[RTS_MAX] = {}; @@ -814,13 +807,13 @@ test_ip6_route_options(gconstpointer test_data) break; case 2: addr[addr_n++] = ((NMPlatformIP6Address){ - .ifindex = IFINDEX, - .address = *nmtst_inet6_from_string("2000::2"), - .plen = 128, - .peer_address = in6addr_any, - .lifetime = NM_PLATFORM_LIFETIME_PERMANENT, - .preferred = NM_PLATFORM_LIFETIME_PERMANENT, - .n_ifa_flags = 0, + .ifindex = IFINDEX, + .address = *nmtst_inet6_from_string("2000::2"), + .plen = 128, + .peer_address = in6addr_any, + .lifetime = NM_PLATFORM_LIFETIME_PERMANENT, + .preferred = NM_PLATFORM_LIFETIME_PERMANENT, + .n_ifa_flags = 0, }); rts_add[rts_n++] = ((NMPlatformIP6Route){ .ifindex = IFINDEX, @@ -834,13 +827,13 @@ test_ip6_route_options(gconstpointer test_data) break; case 3: addr[addr_n++] = ((NMPlatformIP6Address){ - .ifindex = IFINDEX, - .address = *nmtst_inet6_from_string("2001:db8:8086::5"), - .plen = 128, - .peer_address = in6addr_any, - .lifetime = NM_PLATFORM_LIFETIME_PERMANENT, - .preferred = NM_PLATFORM_LIFETIME_PERMANENT, - .n_ifa_flags = 0, + .ifindex = IFINDEX, + .address = *nmtst_inet6_from_string("2001:db8:8086::5"), + .plen = 128, + .peer_address = in6addr_any, + .lifetime = NM_PLATFORM_LIFETIME_PERMANENT, + .preferred = NM_PLATFORM_LIFETIME_PERMANENT, + .n_ifa_flags = 0, }); rts_add[rts_n++] = ((NMPlatformIP6Route){ .ifindex = IFINDEX, @@ -887,7 +880,6 @@ test_ip6_route_options(gconstpointer test_data) for (i = 0; i < rts_n; i++) { rts_cmp[i] = rts_add[i]; nm_platform_ip_route_normalize(AF_INET6, NM_PLATFORM_IP_ROUTE_CAST(&rts_cmp[i])); - rts_cmp[i].is_external = TRUE; } routes = nmtstp_ip6_route_get_all(NM_PLATFORM_GET, IFINDEX); @@ -923,7 +915,7 @@ test_ip(gconstpointer test_data) char ifname[IFNAMSIZ]; char ifname2[IFNAMSIZ]; char s1[NM_UTILS_INET_ADDRSTRLEN]; - NMPlatform * platform = NM_PLATFORM_GET; + NMPlatform *platform = NM_PLATFORM_GET; const int EX_ = -1; struct { int ifindex; @@ -965,7 +957,7 @@ test_ip(gconstpointer test_data) order_len = 0; for (try = 0; try < 5 * G_N_ELEMENTS(order_idx); try++) { NMPObject o; - NMPlatformIP4Route * r; + NMPlatformIP4Route *r; guint idx; const NMDedupMultiHeadEntry *head_entry; NMPLookup lookup; @@ -1052,8 +1044,8 @@ _rule_find_by_priority(NMPlatform *platform, guint32 priority) { const NMDedupMultiHeadEntry *head_entry; NMDedupMultiIter iter; - const NMPObject * o; - const NMPObject * obj = NULL; + const NMPObject *o; + const NMPObject *obj = NULL; NMPLookup lookup; nmp_lookup_init_obj_type(&lookup, NMP_OBJECT_TYPE_ROUTING_RULE); @@ -1128,9 +1120,9 @@ _rule_check_kernel_support(NMPlatform *platform, int attribute) { nm_auto_nmpobj const NMPObject *obj = NULL; const NMPlatformRoutingRule rr = { - .addr_family = AF_INET, - .priority = PROBE_PRORITY, - .suppress_ifgroup_inverse = ~((guint32) 1245), + .addr_family = AF_INET, + .priority = PROBE_PRORITY, + .suppress_ifgroup_inverse = ~((guint32) 1245), }; obj = _rule_check_kernel_support_one(platform, &rr); @@ -1143,9 +1135,9 @@ _rule_check_kernel_support(NMPlatform *platform, int attribute) { nm_auto_nmpobj const NMPObject *obj = NULL; const NMPlatformRoutingRule rr = { - .addr_family = AF_INET, - .priority = PROBE_PRORITY, - .suppress_prefixlen_inverse = ~((guint32) 1245), + .addr_family = AF_INET, + .priority = PROBE_PRORITY, + .suppress_prefixlen_inverse = ~((guint32) 1245), }; obj = _rule_check_kernel_support_one(platform, &rr); @@ -1158,9 +1150,9 @@ _rule_check_kernel_support(NMPlatform *platform, int attribute) { nm_auto_nmpobj const NMPObject *obj = NULL; const NMPlatformRoutingRule rr = { - .addr_family = AF_INET, - .priority = PROBE_PRORITY, - .l3mdev = TRUE, + .addr_family = AF_INET, + .priority = PROBE_PRORITY, + .l3mdev = TRUE, }; obj = _rule_check_kernel_support_one(platform, &rr); @@ -1172,14 +1164,14 @@ _rule_check_kernel_support(NMPlatform *platform, int attribute) { nm_auto_nmpobj const NMPObject *obj = NULL; const NMPlatformRoutingRule rr = { - .addr_family = AF_INET, - .priority = PROBE_PRORITY, - .uid_range = + .addr_family = AF_INET, + .priority = PROBE_PRORITY, + .uid_range = { - .start = 0, - .end = 0, + .start = 0, + .end = 0, }, - .uid_range_has = TRUE, + .uid_range_has = TRUE, }; obj = _rule_check_kernel_support_one(platform, &rr); @@ -1191,9 +1183,9 @@ _rule_check_kernel_support(NMPlatform *platform, int attribute) { nm_auto_nmpobj const NMPObject *obj = NULL; const NMPlatformRoutingRule rr = { - .addr_family = AF_INET, - .priority = PROBE_PRORITY, - .protocol = 30, + .addr_family = AF_INET, + .priority = PROBE_PRORITY, + .protocol = 30, }; obj = _rule_check_kernel_support_one(platform, &rr); @@ -1205,9 +1197,9 @@ _rule_check_kernel_support(NMPlatform *platform, int attribute) { nm_auto_nmpobj const NMPObject *obj = NULL; const NMPlatformRoutingRule rr = { - .addr_family = AF_INET, - .priority = PROBE_PRORITY, - .ip_proto = 30, + .addr_family = AF_INET, + .priority = PROBE_PRORITY, + .ip_proto = 30, }; obj = _rule_check_kernel_support_one(platform, &rr); @@ -1277,7 +1269,7 @@ _rr_rand_choose_u32(guint32 p) static const NMPObject * _rule_create_random(NMPlatform *platform) { - NMPObject * obj; + NMPObject *obj; NMPlatformRoutingRule *rr; guint32 p; int addr_size; @@ -1320,7 +1312,7 @@ _rule_create_random(NMPlatform *platform) for (i = 0; i < 2; i++) { NMIPAddr *p_addr = i ? &rr->src : &rr->dst; - guint8 * p_len = i ? &rr->src_len : &rr->dst_len; + guint8 *p_len = i ? &rr->src_len : &rr->dst_len; p = nmtst_get_rand_uint32(); if ((p % 1000u) < 100) { @@ -1543,11 +1535,11 @@ _rule_fuzzy_equal(const NMPObject *obj, const NMPObject *obj_comp, int op_type) static void test_rule(gconstpointer test_data) { - const int TEST_IDX = GPOINTER_TO_INT(test_data); - const gboolean TEST_SYNC = (TEST_IDX == 4); + const int TEST_IDX = GPOINTER_TO_INT(test_data); + const gboolean TEST_SYNC = (TEST_IDX == 4); gs_unref_ptrarray GPtrArray *objs = NULL; gs_unref_ptrarray GPtrArray *objs_initial = NULL; - NMPlatform * platform = NM_PLATFORM_GET; + NMPlatform *platform = NM_PLATFORM_GET; guint i, j, n; int r; gboolean had_an_issue_exist = FALSE; @@ -1563,7 +1555,7 @@ test_rule(gconstpointer test_data) for (i = 6; i > 0; i--) { gs_unref_ptrarray GPtrArray *objs_extern = NULL; - const NMPObject * obj; + const NMPObject *obj; objs_extern = nmtstp_platform_routing_rules_get_all(platform, AF_UNSPEC); @@ -1645,8 +1637,8 @@ again: if (TEST_SYNC) { gs_unref_hashtable GHashTable *unique_priorities = g_hash_table_new(NULL, NULL); - nm_auto_unref_rules_manager NMPRulesManager *rules_manager = - nmp_rules_manager_new(platform); + nm_auto_unref_route_manager NMPRouteManager *route_manager = + nmp_route_manager_new(platform); gs_unref_ptrarray GPtrArray *objs_sync = NULL; gconstpointer USER_TAG_1 = &platform; gconstpointer USER_TAG_2 = &unique_priorities; @@ -1668,29 +1660,29 @@ again: } for (i = 0; i < objs_sync->len; i++) { - nmp_rules_manager_track(rules_manager, - NMP_OBJECT_CAST_ROUTING_RULE(objs_sync->pdata[i]), - 1, - USER_TAG_1, - NULL); + nmp_route_manager_track_rule(route_manager, + NMP_OBJECT_CAST_ROUTING_RULE(objs_sync->pdata[i]), + 1, + USER_TAG_1, + NULL); if (nmtst_get_rand_bool()) { /* this has no effect, because a negative priority (of same absolute value) * has lower priority than the positive priority above. */ - nmp_rules_manager_track(rules_manager, - NMP_OBJECT_CAST_ROUTING_RULE(objs_sync->pdata[i]), - -1, - USER_TAG_2, - NULL); + nmp_route_manager_track_rule(route_manager, + NMP_OBJECT_CAST_ROUTING_RULE(objs_sync->pdata[i]), + -1, + USER_TAG_2, + NULL); } if (nmtst_get_rand_uint32() % objs_sync->len == 0) { - nmp_rules_manager_sync(rules_manager, FALSE); + nmp_route_manager_sync(route_manager, NMP_OBJECT_TYPE_ROUTING_RULE, FALSE); g_assert_cmpint(nmtstp_platform_routing_rules_get_count(platform, AF_UNSPEC), ==, i + 1); } } - nmp_rules_manager_sync(rules_manager, FALSE); + nmp_route_manager_sync(route_manager, NMP_OBJECT_TYPE_ROUTING_RULE, FALSE); g_assert_cmpint(nmtstp_platform_routing_rules_get_count(platform, AF_UNSPEC), ==, objs_sync->len); @@ -1698,37 +1690,37 @@ again: for (i = 0; i < objs_sync->len; i++) { switch (nmtst_get_rand_uint32() % 3) { case 0: - nmp_rules_manager_untrack(rules_manager, - NMP_OBJECT_CAST_ROUTING_RULE(objs_sync->pdata[i]), - USER_TAG_1); - nmp_rules_manager_untrack(rules_manager, - NMP_OBJECT_CAST_ROUTING_RULE(objs_sync->pdata[i]), - USER_TAG_1); + nmp_route_manager_untrack_rule(route_manager, + NMP_OBJECT_CAST_ROUTING_RULE(objs_sync->pdata[i]), + USER_TAG_1); + nmp_route_manager_untrack_rule(route_manager, + NMP_OBJECT_CAST_ROUTING_RULE(objs_sync->pdata[i]), + USER_TAG_1); break; case 1: - nmp_rules_manager_track(rules_manager, - NMP_OBJECT_CAST_ROUTING_RULE(objs_sync->pdata[i]), - -1, - USER_TAG_1, - NULL); + nmp_route_manager_track_rule(route_manager, + NMP_OBJECT_CAST_ROUTING_RULE(objs_sync->pdata[i]), + -1, + USER_TAG_1, + NULL); break; case 2: - nmp_rules_manager_track(rules_manager, - NMP_OBJECT_CAST_ROUTING_RULE(objs_sync->pdata[i]), - -2, - USER_TAG_2, - NULL); + nmp_route_manager_track_rule(route_manager, + NMP_OBJECT_CAST_ROUTING_RULE(objs_sync->pdata[i]), + -2, + USER_TAG_2, + NULL); break; } if (nmtst_get_rand_uint32() % objs_sync->len == 0) { - nmp_rules_manager_sync(rules_manager, FALSE); + nmp_route_manager_sync(route_manager, NMP_OBJECT_TYPE_ROUTING_RULE, FALSE); g_assert_cmpint(nmtstp_platform_routing_rules_get_count(platform, AF_UNSPEC), ==, objs_sync->len - i - 1); } } - nmp_rules_manager_sync(rules_manager, FALSE); + nmp_route_manager_sync(route_manager, NMP_OBJECT_TYPE_ROUTING_RULE, FALSE); } else { for (i = 0; i < objs->len;) { @@ -1767,7 +1759,7 @@ again: NMPLookup lookup; const NMDedupMultiHeadEntry *head_entry; NMDedupMultiIter iter; - const NMPObject * o; + const NMPObject *o; g_print(">>> failing... errno=%d, rule=%s\n", r, @@ -1894,6 +1886,64 @@ again: /*****************************************************************************/ +static void +test_blackhole(gconstpointer test_data) +{ + int TEST_IDX = GPOINTER_TO_INT(test_data); + const int addr_family = (TEST_IDX == 1) ? AF_INET : AF_INET6; + const int IS_IPv4 = NM_IS_IPv4(addr_family); + const NMDedupMultiHeadEntry *head_entry; + NMDedupMultiIter iter; + const NMPObject *obj; + NMPObject obj_stack; + NMPlatformIPXRoute rr = {}; + int r = -1; + int i; + + if (IS_IPv4) { + rr.r4 = (const NMPlatformIP4Route){ + .type_coerced = nmtst_rand_select(RTN_BLACKHOLE, RTN_UNREACHABLE, RTN_PROHIBIT), + }; + } else { + rr.r6 = (const NMPlatformIP6Route){ + .type_coerced = nmtst_rand_select(RTN_BLACKHOLE, RTN_UNREACHABLE, RTN_PROHIBIT), + .metric = 1000, + }; + } + + nm_platform_ip_route_normalize(addr_family, &rr.rx); + + if (IS_IPv4) + r = nm_platform_ip4_route_add(NM_PLATFORM_GET, NMP_NLM_FLAG_APPEND, &rr.r4); + else + r = nm_platform_ip6_route_add(NM_PLATFORM_GET, NMP_NLM_FLAG_APPEND, &rr.r6); + + g_assert_cmpint(r, ==, 0); + + nmp_object_stackinit(&obj_stack, NMP_OBJECT_TYPE_IP_ROUTE(IS_IPv4), &rr); + + obj = nm_platform_lookup_obj(NM_PLATFORM_GET, NMP_CACHE_ID_TYPE_OBJECT_TYPE, &obj_stack); + + _LOGT(">>> adding %s", + nmp_object_to_string(&obj_stack, NMP_OBJECT_TO_STRING_ALL, g_alloca(1000), 1000)); + _LOGT(">>> found %s", + nmp_object_to_string(obj, NMP_OBJECT_TO_STRING_ALL, g_alloca(1000), 1000)); + + g_assert(obj); + + head_entry = nm_platform_lookup_object(NM_PLATFORM_GET, NMP_OBJECT_TYPE_IP_ROUTE(IS_IPv4), 0); + g_assert(head_entry); + g_assert_cmpint(head_entry->len, ==, 1); + i = 0; + nm_dedup_multi_iter_for_each (&iter, head_entry) { + i++; + g_assert(iter.current->obj == obj); + } + g_assert_cmpint(i, ==, 1); +} + +/*****************************************************************************/ + NMTstpSetupFunc const _nmtstp_setup_platform_func = SETUP; void @@ -1931,4 +1981,8 @@ _nmtstp_setup_tests(void) add_test_func_data("/route/rule/3", test_rule, GINT_TO_POINTER(3)); add_test_func_data("/route/rule/4", test_rule, GINT_TO_POINTER(4)); } + if (nmtstp_is_root_test()) { + add_test_func_data("/route/blackhole/1", test_blackhole, GINT_TO_POINTER(1)); + add_test_func_data("/route/blackhole/2", test_blackhole, GINT_TO_POINTER(2)); + } } diff --git a/src/core/platform/tests/test-tc.c b/src/core/platform/tests/test-tc.c index ee7b861e..db23a932 100644 --- a/src/core/platform/tests/test-tc.c +++ b/src/core/platform/tests/test-tc.c @@ -39,11 +39,11 @@ qdiscs_lookup(int ifindex) static void test_qdisc1(void) { - int ifindex; + int ifindex; gs_unref_ptrarray GPtrArray *known = NULL; gs_unref_ptrarray GPtrArray *plat = NULL; - NMPObject * obj; - NMPlatformQdisc * qdisc; + NMPObject *obj; + NMPlatformQdisc *qdisc; ifindex = nm_platform_link_get_ifindex(NM_PLATFORM_GET, DEVICE_NAME); g_assert_cmpint(ifindex, >, 0); @@ -76,11 +76,11 @@ test_qdisc1(void) static void test_qdisc_fq_codel(void) { - int ifindex; + int ifindex; gs_unref_ptrarray GPtrArray *known = NULL; gs_unref_ptrarray GPtrArray *plat = NULL; - NMPObject * obj; - NMPlatformQdisc * qdisc; + NMPObject *obj; + NMPlatformQdisc *qdisc; ifindex = nm_platform_link_get_ifindex(NM_PLATFORM_GET, DEVICE_NAME); g_assert_cmpint(ifindex, >, 0); @@ -115,11 +115,11 @@ test_qdisc_fq_codel(void) static void test_qdisc_sfq(void) { - int ifindex; + int ifindex; gs_unref_ptrarray GPtrArray *known = NULL; gs_unref_ptrarray GPtrArray *plat = NULL; - NMPObject * obj; - NMPlatformQdisc * qdisc; + NMPObject *obj; + NMPlatformQdisc *qdisc; ifindex = nm_platform_link_get_ifindex(NM_PLATFORM_GET, DEVICE_NAME); g_assert_cmpint(ifindex, >, 0); @@ -154,11 +154,11 @@ test_qdisc_sfq(void) static void test_qdisc_tbf(void) { - int ifindex; + int ifindex; gs_unref_ptrarray GPtrArray *known = NULL; gs_unref_ptrarray GPtrArray *plat = NULL; - NMPObject * obj; - NMPlatformQdisc * qdisc; + NMPObject *obj; + NMPlatformQdisc *qdisc; ifindex = nm_platform_link_get_ifindex(NM_PLATFORM_GET, DEVICE_NAME); g_assert_cmpint(ifindex, >, 0); diff --git a/src/core/ppp/nm-ppp-manager-call.c b/src/core/ppp/nm-ppp-manager-call.c index 5e84f596..8c788fad 100644 --- a/src/core/ppp/nm-ppp-manager-call.c +++ b/src/core/ppp/nm-ppp-manager-call.c @@ -25,9 +25,9 @@ static const NMPPPOps *_ppp_ops = NULL; NMPPPManager * nm_ppp_manager_create(const char *iface, GError **error) { - NMPPPManager * ret; - GModule * plugin; - GError * error_local = NULL; + NMPPPManager *ret; + GModule *plugin; + GError *error_local = NULL; struct stat st; const NMPPPOps *ppp_ops; @@ -94,31 +94,13 @@ again: return ret; } -void -nm_ppp_manager_set_route_parameters(NMPPPManager *self, - guint32 ip4_route_table, - guint32 ip4_route_metric, - guint32 ip6_route_table, - guint32 ip6_route_metric) -{ - const NMPPPOps *ppp_ops = ppp_ops_get(); - - g_return_if_fail(ppp_ops); - - ppp_ops->set_route_parameters(self, - ip4_route_table, - ip4_route_metric, - ip6_route_table, - ip6_route_metric); -} - gboolean nm_ppp_manager_start(NMPPPManager *self, NMActRequest *req, - const char * ppp_name, + const char *ppp_name, guint32 timeout_secs, guint baud_override, - GError ** err) + GError **err) { const NMPPPOps *ppp_ops = ppp_ops_get(); @@ -128,8 +110,8 @@ nm_ppp_manager_start(NMPPPManager *self, } NMPPPManagerStopHandle * -nm_ppp_manager_stop(NMPPPManager * self, - GCancellable * cancellable, +nm_ppp_manager_stop(NMPPPManager *self, + GCancellable *cancellable, NMPPPManagerStopCallback callback, gpointer user_data) { diff --git a/src/core/ppp/nm-ppp-manager-call.h b/src/core/ppp/nm-ppp-manager-call.h index c831cf0d..ef081200 100644 --- a/src/core/ppp/nm-ppp-manager-call.h +++ b/src/core/ppp/nm-ppp-manager-call.h @@ -10,21 +10,15 @@ NMPPPManager *nm_ppp_manager_create(const char *iface, GError **error); -void nm_ppp_manager_set_route_parameters(NMPPPManager *ppp_manager, - guint32 ip4_route_table, - guint32 ip4_route_metric, - guint32 ip6_route_table, - guint32 ip6_route_metric); - gboolean nm_ppp_manager_start(NMPPPManager *self, NMActRequest *req, - const char * ppp_name, + const char *ppp_name, guint32 timeout_secs, guint baud_override, - GError ** error); + GError **error); -NMPPPManagerStopHandle *nm_ppp_manager_stop(NMPPPManager * self, - GCancellable * cancellable, +NMPPPManagerStopHandle *nm_ppp_manager_stop(NMPPPManager *self, + GCancellable *cancellable, NMPPPManagerStopCallback callback, gpointer user_data); diff --git a/src/core/ppp/nm-ppp-manager.c b/src/core/ppp/nm-ppp-manager.c index e6790f22..f1f10305 100644 --- a/src/core/ppp/nm-ppp-manager.c +++ b/src/core/ppp/nm-ppp-manager.c @@ -32,8 +32,7 @@ #include "libnm-platform/nm-platform-utils.h" #include "libnm-core-intern/nm-core-internal.h" #include "nm-act-request.h" -#include "nm-ip4-config.h" -#include "nm-ip6-config.h" +#include "nm-l3-config-data.h" #include "nm-dbus-object.h" #include "nm-pppd-plugin.h" @@ -46,6 +45,26 @@ static NM_CACHED_QUARK_FCN("ppp-manager-secret-tries", ppp_manager_secret_tries_ /*****************************************************************************/ +/* FIXME(l3cfg:ppp): I think NMPPPManager's API should be improved to be easier + * usable (by the higher layers). That means to make the class more complex, to + * provide a simpler API. + * + * For example: + * + * - NM_PPP_MANAGER_SIGNAL_STATE_CHANGED just gets re-emitted when we receive + * the D-Bus call from the plugin. The emitted state is like NM_PPP_STATUS_SERIALCONN, + * but none of the users cares about this (what would it mean anyway)? The + * class should itself consume the state, and emit something more consumable + * (like: interface is ready (with ifindex), IPvX configuration done (with l3cd). + * + * - currently signals can be emitted in any order, and it's not clear which + * signals we can expect. For example, when we activate a device, we may want to wait + * for IPv4 and IPv6 configuration, but it's not clear whether this configuration + * is still to be received or whether we can stop waiting. + **/ + +/*****************************************************************************/ + #define NM_TYPE_PPP_MANAGER (nm_ppp_manager_get_type()) #define NM_PPP_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_PPP_MANAGER, NMPPPManager)) #define NM_PPP_MANAGER_CLASS(klass) \ @@ -62,8 +81,7 @@ GType nm_ppp_manager_get_type(void); enum { STATE_CHANGED, IFINDEX_SET, - IP4_CONFIG, - IP6_CONFIG, + NEW_CONFIG, STATS, LAST_SIGNAL @@ -80,10 +98,10 @@ typedef struct { char *ip_iface; int ifindex; - NMActRequest * act_req; - GDBusMethodInvocation * pending_secrets_context; + NMActRequest *act_req; + GDBusMethodInvocation *pending_secrets_context; NMActRequestGetSecretsCallId *secrets_id; - const char * secrets_setting_name; + const char *secrets_setting_name; guint ppp_watch_id; guint ppp_timeout_handler; @@ -91,11 +109,6 @@ typedef struct { /* Monitoring */ int monitor_fd; guint monitor_id; - - guint32 ip4_route_table; - guint32 ip4_route_metric; - guint32 ip6_route_table; - guint32 ip6_route_metric; } NMPPPManagerPrivate; struct _NMPPPManager { @@ -121,8 +134,8 @@ G_DEFINE_TYPE(NMPPPManager, nm_ppp_manager, NM_TYPE_DBUS_OBJECT) static void _ppp_cleanup(NMPPPManager *self); -static NMPPPManagerStopHandle *_ppp_manager_stop(NMPPPManager * self, - GCancellable * cancellable, +static NMPPPManagerStopHandle *_ppp_manager_stop(NMPPPManager *self, + GCancellable *cancellable, NMPPPManagerStopCallback callback, gpointer user_data); @@ -131,30 +144,19 @@ static void _ppp_manager_stop_cancel(NMPPPManagerStopHandle *handle); /*****************************************************************************/ static void -_ppp_manager_set_route_parameters(NMPPPManager *self, - guint32 ip4_route_table, - guint32 ip4_route_metric, - guint32 ip6_route_table, - guint32 ip6_route_metric) +_emit_signal_new_config(NMPPPManager *self, + int addr_family, + const NML3ConfigData *l3cd, + const NMUtilsIPv6IfaceId *iid) { - NMPPPManagerPrivate *priv; + nm_assert(NM_IS_PPP_MANAGER(self)); + nm_assert_addr_family(addr_family); + nm_assert(NM_IS_L3_CONFIG_DATA(l3cd)); + nm_assert((!!iid) == (addr_family == AF_INET6)); - g_return_if_fail(NM_IS_PPP_MANAGER(self)); + nm_l3_config_data_seal(l3cd); - priv = NM_PPP_MANAGER_GET_PRIVATE(self); - if (priv->ip4_route_table != ip4_route_table || priv->ip4_route_metric != ip4_route_metric - || priv->ip6_route_table != ip6_route_table || priv->ip6_route_metric != ip6_route_metric) { - priv->ip4_route_table = ip4_route_table; - priv->ip4_route_metric = ip4_route_metric; - priv->ip6_route_table = ip6_route_table; - priv->ip6_route_metric = ip6_route_metric; - - _LOGT("route-parameters: table-v4: %u, metric-v4: %u, table-v6: %u, metric-v6: %u", - priv->ip4_route_table, - priv->ip4_route_metric, - priv->ip6_route_table, - priv->ip6_route_metric); - } + g_signal_emit(self, signals[NEW_CONFIG], 0, addr_family, l3cd, iid); } /*****************************************************************************/ @@ -162,9 +164,9 @@ _ppp_manager_set_route_parameters(NMPPPManager *self, static gboolean monitor_cb(gpointer user_data) { - NMPPPManager * self = NM_PPP_MANAGER(user_data); + NMPPPManager *self = NM_PPP_MANAGER(user_data); NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE(self); - const char * ifname; + const char *ifname; int errsv; ifname = nm_platform_link_get_name(NM_PLATFORM_GET, priv->ifindex); @@ -172,7 +174,7 @@ monitor_cb(gpointer user_data) if (ifname) { struct ppp_stats stats = {}; struct ifreq req = { - .ifr_data = (caddr_t) &stats, + .ifr_data = (caddr_t) &stats, }; nm_utils_ifname_cpy(req.ifr_name, ifname); @@ -230,14 +232,14 @@ cancel_get_secrets(NMPPPManager *self) static gboolean extract_details_from_connection(NMConnection *connection, - const char * secrets_setting_name, - const char ** username, - const char ** password, - GError ** error) + const char *secrets_setting_name, + const char **username, + const char **password, + GError **error) { NMSettingConnection *s_con; - NMSetting * setting; - const char * setting_name; + NMSetting *setting; + const char *setting_name; g_return_val_if_fail(connection != NULL, FALSE); g_return_val_if_fail(username != NULL, FALSE); @@ -290,18 +292,18 @@ extract_details_from_connection(NMConnection *connection, } static void -ppp_secrets_cb(NMActRequest * req, +ppp_secrets_cb(NMActRequest *req, NMActRequestGetSecretsCallId *call_id, - NMSettingsConnection * settings_connection, /* unused (we pass NULL here) */ - GError * error, + NMSettingsConnection *settings_connection, /* unused (we pass NULL here) */ + GError *error, gpointer user_data) { - NMPPPManager * self = NM_PPP_MANAGER(user_data); + NMPPPManager *self = NM_PPP_MANAGER(user_data); NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE(self); - const char * username = NULL; - const char * password = NULL; - GError * local = NULL; - NMConnection * applied_connection; + const char *username = NULL; + const char *password = NULL; + GError *local = NULL; + NMConnection *applied_connection; g_return_if_fail(priv->pending_secrets_context != NULL); g_return_if_fail(req == priv->act_req); @@ -344,22 +346,22 @@ out: } static void -impl_ppp_manager_need_secrets(NMDBusObject * obj, +impl_ppp_manager_need_secrets(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMPPPManager * self = NM_PPP_MANAGER(obj); - NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE(self); - NMConnection * applied_connection; - const char * username = NULL; - const char * password = NULL; - guint32 tries; + NMPPPManager *self = NM_PPP_MANAGER(obj); + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE(self); + NMConnection *applied_connection; + const char *username = NULL; + const char *password = NULL; + guint32 tries; gs_unref_ptrarray GPtrArray *hints = NULL; - GError * error = NULL; + GError *error = NULL; NMSecretAgentGetSecretsFlags flags = NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION; nm_active_connection_clear_secrets(NM_ACTIVE_CONNECTION(priv->act_req)); @@ -410,35 +412,42 @@ impl_ppp_manager_need_secrets(NMDBusObject * obj, } static void -impl_ppp_manager_set_state(NMDBusObject * obj, +impl_ppp_manager_set_state(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { NMPPPManager *self = NM_PPP_MANAGER(obj); - guint32 state; + guint32 ppp_state; - g_variant_get(parameters, "(u)", &state); - g_signal_emit(self, signals[STATE_CHANGED], 0, (guint) state); + g_variant_get(parameters, "(u)", &ppp_state); + + if (ppp_state >= NM_PPP_STATUS_INTERN_DEAD) { + /* we don't expect an intern state to be reported by the plugin. */ + ppp_state = NM_PPP_STATUS_UNKNOWN; + } + + g_signal_emit(self, signals[STATE_CHANGED], 0, (guint) ppp_state); g_dbus_method_invocation_return_value(invocation, NULL); } static void -impl_ppp_manager_set_ifindex(NMDBusObject * obj, +impl_ppp_manager_set_ifindex(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMPPPManager * self = NM_PPP_MANAGER(obj); - NMPPPManagerPrivate * priv = NM_PPP_MANAGER_GET_PRIVATE(self); - const NMPlatformLink *plink = NULL; - nm_auto_nmpobj const NMPObject *obj_keep_alive = NULL; + NMPPPManager *self = NM_PPP_MANAGER(obj); + gs_unref_object NMPPPManager *self_keep_alive = NULL; + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE(self); + const NMPlatformLink *plink = NULL; + nm_auto_nmpobj const NMPObject *obj_keep_alive = NULL; gint32 ifindex; g_variant_get(parameters, "(i)", &ifindex); @@ -456,6 +465,10 @@ impl_ppp_manager_set_ifindex(NMDBusObject * obj, if (ifindex > 0) { plink = nm_platform_link_get(NM_PLATFORM_GET, ifindex); if (!plink) { + /* processing events has side-effects. We need to keep self alive + * during that.*/ + self_keep_alive = g_object_ref(self); + nm_platform_process_events(NM_PLATFORM_GET); plink = nm_platform_link_get(NM_PLATFORM_GET, ifindex); } @@ -481,8 +494,8 @@ static gboolean set_ip_config_common(NMPPPManager *self, GVariant *config_dict, guint32 *out_mtu) { NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE(self); - NMConnection * applied_connection; - NMSettingPpp * s_ppp; + NMConnection *applied_connection; + NMSettingPpp *s_ppp; if (priv->ifindex <= 0) return FALSE; @@ -502,21 +515,21 @@ set_ip_config_common(NMPPPManager *self, GVariant *config_dict, guint32 *out_mtu } static void -impl_ppp_manager_set_ip4_config(NMDBusObject * obj, +impl_ppp_manager_set_ip4_config(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMPPPManager * self = NM_PPP_MANAGER(obj); - NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE(self); - gs_unref_object NMIP4Config *config = NULL; - NMPlatformIP4Address address; - guint32 u32, mtu; - GVariantIter * iter; - gs_unref_variant GVariant *config_dict = NULL; + NMPPPManager *self = NM_PPP_MANAGER(obj); + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE(self); + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + NMPlatformIP4Address address; + guint32 u32, mtu; + GVariantIter *iter; + gs_unref_variant GVariant *config_dict = NULL; _LOGI("(IPv4 Config Get) reply received."); @@ -527,37 +540,41 @@ impl_ppp_manager_set_ip4_config(NMDBusObject * obj, if (!set_ip_config_common(self, config_dict, &mtu)) goto out; - config = nm_ip4_config_new(nm_platform_get_multi_idx(NM_PLATFORM_GET), priv->ifindex); + l3cd = nm_l3_config_data_new(nm_platform_get_multi_idx(NM_PLATFORM_GET), + priv->ifindex, + NM_IP_CONFIG_SOURCE_PPP); - if (mtu) - nm_ip4_config_set_mtu(config, mtu, NM_IP_CONFIG_SOURCE_PPP); + nm_l3_config_data_set_mtu(l3cd, mtu); - memset(&address, 0, sizeof(address)); - address.plen = 32; + address = (NMPlatformIP4Address){ + .plen = 32, + }; if (g_variant_lookup(config_dict, NM_PPP_IP4_CONFIG_ADDRESS, "u", &u32)) address.address = u32; + if (g_variant_lookup(config_dict, NM_PPP_IP4_CONFIG_PREFIX, "u", &u32)) + address.plen = u32; + if (g_variant_lookup(config_dict, NM_PPP_IP4_CONFIG_GATEWAY, "u", &u32)) { const NMPlatformIP4Route r = { .ifindex = priv->ifindex, .rt_source = NM_IP_CONFIG_SOURCE_PPP, .gateway = u32, - .table_coerced = nm_platform_route_table_coerce(priv->ip4_route_table), - .metric = priv->ip4_route_metric, + .table_any = TRUE, + .table_coerced = 0, + .metric_any = TRUE, + .metric = 0, }; - nm_ip4_config_add_route(config, &r, NULL); + nm_l3_config_data_add_route_4(l3cd, &r); address.peer_address = u32; } else address.peer_address = address.address; - if (g_variant_lookup(config_dict, NM_PPP_IP4_CONFIG_PREFIX, "u", &u32)) - address.plen = u32; - - if (address.address && address.plen && address.plen <= 32) { + if (address.address && address.plen > 0 && address.plen <= 32) { address.addr_source = NM_IP_CONFIG_SOURCE_PPP; - nm_ip4_config_add_address(config, &address); + nm_l3_config_data_add_address_4(l3cd, &address); } else { _LOGE("invalid IPv4 address received!"); goto out; @@ -565,18 +582,17 @@ impl_ppp_manager_set_ip4_config(NMDBusObject * obj, if (g_variant_lookup(config_dict, NM_PPP_IP4_CONFIG_DNS, "au", &iter)) { while (g_variant_iter_next(iter, "u", &u32)) - nm_ip4_config_add_nameserver(config, u32); + nm_l3_config_data_add_nameserver(l3cd, AF_INET, &u32); g_variant_iter_free(iter); } if (g_variant_lookup(config_dict, NM_PPP_IP4_CONFIG_WINS, "au", &iter)) { while (g_variant_iter_next(iter, "u", &u32)) - nm_ip4_config_add_wins(config, u32); + nm_l3_config_data_add_wins(l3cd, u32); g_variant_iter_free(iter); } - /* Push the IP4 config up to the device */ - g_signal_emit(self, signals[IP4_CONFIG], 0, config); + _emit_signal_new_config(self, AF_INET, l3cd, NULL); out: g_dbus_method_invocation_return_value(invocation, NULL); @@ -586,9 +602,9 @@ out: * returns the IID. */ static gboolean -iid_value_to_ll6_addr(GVariant * dict, - const char * prop, - struct in6_addr * out_addr, +iid_value_to_ll6_addr(GVariant *dict, + const char *prop, + struct in6_addr *out_addr, NMUtilsIPv6IfaceId *out_iid) { guint64 iid; @@ -612,22 +628,22 @@ iid_value_to_ll6_addr(GVariant * dict, } static void -impl_ppp_manager_set_ip6_config(NMDBusObject * obj, +impl_ppp_manager_set_ip6_config(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMPPPManager * self = NM_PPP_MANAGER(obj); - NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE(self); - gs_unref_object NMIP6Config *config = NULL; - NMPlatformIP6Address addr; - struct in6_addr a; - NMUtilsIPv6IfaceId iid = NM_UTILS_IPV6_IFACE_ID_INIT; - gboolean has_peer = FALSE; - gs_unref_variant GVariant *config_dict = NULL; + NMPPPManager *self = NM_PPP_MANAGER(obj); + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE(self); + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + NMPlatformIP6Address address; + struct in6_addr a; + NMUtilsIPv6IfaceId iid = NM_UTILS_IPV6_IFACE_ID_INIT; + gboolean has_peer = FALSE; + gs_unref_variant GVariant *config_dict = NULL; _LOGI("(IPv6 Config Get) reply received."); @@ -638,32 +654,37 @@ impl_ppp_manager_set_ip6_config(NMDBusObject * obj, if (!set_ip_config_common(self, config_dict, NULL)) goto out; - config = nm_ip6_config_new(nm_platform_get_multi_idx(NM_PLATFORM_GET), priv->ifindex); + l3cd = nm_l3_config_data_new(nm_platform_get_multi_idx(NM_PLATFORM_GET), + priv->ifindex, + NM_IP_CONFIG_SOURCE_PPP); - memset(&addr, 0, sizeof(addr)); - addr.plen = 64; + address = (NMPlatformIP6Address){ + .plen = 64, + .addr_source = NM_IP_CONFIG_SOURCE_PPP, + }; if (iid_value_to_ll6_addr(config_dict, NM_PPP_IP6_CONFIG_PEER_IID, &a, NULL)) { const NMPlatformIP6Route r = { .ifindex = priv->ifindex, .rt_source = NM_IP_CONFIG_SOURCE_PPP, .gateway = a, - .table_coerced = nm_platform_route_table_coerce(priv->ip6_route_table), - .metric = priv->ip6_route_metric, + .table_any = TRUE, + .table_coerced = 0, + .metric_any = TRUE, + .metric = 0, }; - nm_ip6_config_add_route(config, &r, NULL); - addr.peer_address = a; - has_peer = TRUE; + nm_l3_config_data_add_route_6(l3cd, &r); + address.peer_address = a; + has_peer = TRUE; } - if (iid_value_to_ll6_addr(config_dict, NM_PPP_IP6_CONFIG_OUR_IID, &addr.address, &iid)) { + if (iid_value_to_ll6_addr(config_dict, NM_PPP_IP6_CONFIG_OUR_IID, &address.address, &iid)) { if (!has_peer) - addr.peer_address = addr.address; - nm_ip6_config_add_address(config, &addr); + address.peer_address = address.address; + nm_l3_config_data_add_address_6(l3cd, &address); - /* Push the IPv6 config and interface identifier up to the device */ - g_signal_emit(self, signals[IP6_CONFIG], 0, &iid, config); + _emit_signal_new_config(self, AF_INET6, l3cd, &iid); } else _LOGE("invalid IPv6 address received!"); @@ -703,7 +724,7 @@ static NM_UTILS_LOOKUP_STR_DEFINE( static void ppp_watch_cb(GPid pid, int status, gpointer user_data) { - NMPPPManager * self = NM_PPP_MANAGER(user_data); + NMPPPManager *self = NM_PPP_MANAGER(user_data); NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE(self); int err; const long long lpid = (long long) pid; @@ -726,7 +747,7 @@ ppp_watch_cb(GPid pid, int status, gpointer user_data) priv->pid = 0; priv->ppp_watch_id = 0; _ppp_cleanup(self); - g_signal_emit(self, signals[STATE_CHANGED], 0, (guint) NM_PPP_STATUS_DEAD); + g_signal_emit(self, signals[STATE_CHANGED], 0, (guint) NM_PPP_STATUS_INTERN_DEAD); } static gboolean @@ -734,28 +755,34 @@ pppd_timed_out(gpointer data) { NMPPPManager *self = NM_PPP_MANAGER(data); + /* FIXME(l3cfg): we should not use NMPPPManager directly, instead use + * NMPppMgr. That one already schedules a (better) timer. We don't need + * a timeout here anymore. + * + * At this moment, NMPPPManager is still used by NMModem. Once that changes, + * this timer needs to go. */ _LOGW("pppd timed out or didn't initialize our dbus module"); _ppp_manager_stop(self, NULL, NULL, NULL); - g_signal_emit(self, signals[STATE_CHANGED], 0, (guint) NM_PPP_STATUS_DEAD); + g_signal_emit(self, signals[STATE_CHANGED], 0, (guint) NM_PPP_STATUS_INTERN_DEAD); return FALSE; } static GPtrArray * -create_pppd_cmd_line(NMPPPManager * self, - NMSettingPpp * setting, +create_pppd_cmd_line(NMPPPManager *self, + NMSettingPpp *setting, NMSettingPppoe *pppoe, - NMSettingAdsl * adsl, - const char * ppp_name, + NMSettingAdsl *adsl, + const char *ppp_name, guint baud_override, gboolean ip4_enabled, gboolean ip6_enabled, - GError ** err) + GError **err) { - NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE(self); - const char * pppd_binary = NULL; - gs_unref_ptrarray GPtrArray *cmd = NULL; + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE(self); + const char *pppd_binary = NULL; + gs_unref_ptrarray GPtrArray *cmd = NULL; gboolean ppp_debug; g_return_val_if_fail(setting != NULL, NULL); @@ -961,23 +988,22 @@ pppoe_fill_defaults(NMSettingPpp *setting) static gboolean _ppp_manager_start(NMPPPManager *self, NMActRequest *req, - const char * ppp_name, + const char *ppp_name, guint32 timeout_secs, guint baud_override, - GError ** err) + GError **err) { - NMPPPManagerPrivate *priv; - NMConnection * connection; - NMSettingPpp * s_ppp; + NMPPPManagerPrivate *priv; + NMConnection *connection; + NMSettingPpp *s_ppp; gs_unref_object NMSettingPpp *s_ppp_free = NULL; - NMSettingPppoe * pppoe_setting; - NMSettingAdsl * adsl_setting; - gs_unref_ptrarray GPtrArray *ppp_cmd = NULL; - gs_free char * cmd_str = NULL; - struct stat st; - const char * ip6_method, *ip4_method; - gboolean ip6_enabled = FALSE; - gboolean ip4_enabled = FALSE; + NMSettingPppoe *pppoe_setting; + NMSettingAdsl *adsl_setting; + gs_unref_ptrarray GPtrArray *ppp_cmd = NULL; + gs_free char *cmd_str = NULL; + struct stat st; + gboolean ip6_enabled; + gboolean ip4_enabled; g_return_val_if_fail(NM_IS_PPP_MANAGER(self), FALSE); g_return_val_if_fail(NM_IS_ACT_REQUEST(req), FALSE); @@ -1022,11 +1048,7 @@ _ppp_manager_start(NMPPPManager *self, adsl_setting = (NMSettingAdsl *) nm_connection_get_setting(connection, NM_TYPE_SETTING_ADSL); - /* Figure out what address methods should be enabled */ - ip4_method = nm_utils_get_ip_config_method(connection, AF_INET); - ip4_enabled = nm_streq(ip4_method, NM_SETTING_IP4_CONFIG_METHOD_AUTO); - ip6_method = nm_utils_get_ip_config_method(connection, AF_INET6); - ip6_enabled = nm_streq(ip6_method, NM_SETTING_IP6_CONFIG_METHOD_AUTO); + nm_utils_ppp_ip_methods_enabled(connection, &ip4_enabled, &ip6_enabled); ppp_cmd = create_pppd_cmd_line(self, s_ppp, @@ -1059,9 +1081,10 @@ _ppp_manager_start(NMPPPManager *self, _LOGI("pppd started with pid %lld", (long long) priv->pid); - priv->ppp_watch_id = g_child_watch_add(priv->pid, (GChildWatchFunc) ppp_watch_cb, self); - priv->ppp_timeout_handler = g_timeout_add_seconds(timeout_secs, pppd_timed_out, self); - priv->act_req = g_object_ref(req); + priv->ppp_watch_id = g_child_watch_add(priv->pid, (GChildWatchFunc) ppp_watch_cb, self); + if (timeout_secs > 0) + priv->ppp_timeout_handler = g_timeout_add_seconds(timeout_secs, pppd_timed_out, self); + priv->act_req = g_object_ref(req); return TRUE; fail: @@ -1096,7 +1119,7 @@ _ppp_cleanup(NMPPPManager *self) /*****************************************************************************/ struct _NMPPPManagerStopHandle { - NMPPPManager * self; + NMPPPManager *self; NMPPPManagerStopCallback callback; gpointer user_data; @@ -1170,13 +1193,13 @@ _stop_cancelled_cb(GCancellable *cancellable, gpointer user_data) } static NMPPPManagerStopHandle * -_ppp_manager_stop(NMPPPManager * self, - GCancellable * cancellable, +_ppp_manager_stop(NMPPPManager *self, + GCancellable *cancellable, NMPPPManagerStopCallback callback, gpointer user_data) { - NMPPPManagerPrivate * priv = NM_PPP_MANAGER_GET_PRIVATE(self); - NMDBusObject * dbus = NM_DBUS_OBJECT(self); + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE(self); + NMDBusObject *dbus = NM_DBUS_OBJECT(self); NMPPPManagerStopHandle *handle; if (nm_dbus_object_is_exported(dbus)) @@ -1290,12 +1313,8 @@ nm_ppp_manager_init(NMPPPManager *self) { NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE(self); - priv->ifindex = -1; - priv->monitor_fd = -1; - priv->ip4_route_table = RT_TABLE_MAIN; - priv->ip4_route_metric = 460; - priv->ip6_route_table = RT_TABLE_MAIN; - priv->ip6_route_metric = 460; + priv->ifindex = -1; + priv->monitor_fd = -1; } static NMPPPManager * @@ -1309,7 +1328,7 @@ _ppp_manager_new(const char *iface) static void dispose(GObject *object) { - NMPPPManager * self = (NMPPPManager *) object; + NMPPPManager *self = (NMPPPManager *) object; NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE(self); /* we expect the user to first stop the manager. As fallback, @@ -1371,7 +1390,7 @@ static const NMDBusInterfaceInfoExtended interface_info_ppp = { static void nm_ppp_manager_class_init(NMPPPManagerClass *manager_class) { - GObjectClass * object_class = G_OBJECT_CLASS(manager_class); + GObjectClass *object_class = G_OBJECT_CLASS(manager_class); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(manager_class); object_class->dispose = dispose; @@ -1400,7 +1419,7 @@ nm_ppp_manager_class_init(NMPPPManagerClass *manager_class) NULL, G_TYPE_NONE, 1, - G_TYPE_UINT); + G_TYPE_UINT /* ppp_state */); signals[IFINDEX_SET] = g_signal_new(NM_PPP_MANAGER_SIGNAL_IFINDEX_SET, G_OBJECT_CLASS_TYPE(object_class), @@ -1411,21 +1430,10 @@ nm_ppp_manager_class_init(NMPPPManagerClass *manager_class) NULL, G_TYPE_NONE, 2, - G_TYPE_INT, - G_TYPE_STRING); - - signals[IP4_CONFIG] = g_signal_new(NM_PPP_MANAGER_SIGNAL_IP4_CONFIG, - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, - NULL, - NULL, - G_TYPE_NONE, - 1, - G_TYPE_OBJECT); + G_TYPE_INT /* ifindex */, + G_TYPE_STRING /* ifname */); - signals[IP6_CONFIG] = g_signal_new(NM_PPP_MANAGER_SIGNAL_IP6_CONFIG, + signals[NEW_CONFIG] = g_signal_new(NM_PPP_MANAGER_SIGNAL_NEW_CONFIG, G_OBJECT_CLASS_TYPE(object_class), G_SIGNAL_RUN_FIRST, 0, @@ -1433,9 +1441,10 @@ nm_ppp_manager_class_init(NMPPPManagerClass *manager_class) NULL, NULL, G_TYPE_NONE, - 2, - G_TYPE_POINTER, - G_TYPE_OBJECT); + 3, + G_TYPE_INT, /* addr_family */ + G_TYPE_POINTER, /* (const NML3ConfigData *) */ + G_TYPE_POINTER); /* (const NMUtilsIPv6IfaceId *) */ signals[STATS] = g_signal_new(NM_PPP_MANAGER_SIGNAL_STATS, G_OBJECT_CLASS_TYPE(object_class), @@ -1451,9 +1460,8 @@ nm_ppp_manager_class_init(NMPPPManagerClass *manager_class) } const NMPPPOps ppp_ops = { - .create = _ppp_manager_new, - .set_route_parameters = _ppp_manager_set_route_parameters, - .start = _ppp_manager_start, - .stop = _ppp_manager_stop, - .stop_cancel = _ppp_manager_stop_cancel, + .create = _ppp_manager_new, + .start = _ppp_manager_start, + .stop = _ppp_manager_stop, + .stop_cancel = _ppp_manager_stop_cancel, }; diff --git a/src/core/ppp/nm-ppp-manager.h b/src/core/ppp/nm-ppp-manager.h index c41dda20..21ea3715 100644 --- a/src/core/ppp/nm-ppp-manager.h +++ b/src/core/ppp/nm-ppp-manager.h @@ -11,15 +11,14 @@ #define NM_PPP_MANAGER_SIGNAL_STATE_CHANGED "state-changed" #define NM_PPP_MANAGER_SIGNAL_IFINDEX_SET "ifindex-set" -#define NM_PPP_MANAGER_SIGNAL_IP4_CONFIG "ip4-config" -#define NM_PPP_MANAGER_SIGNAL_IP6_CONFIG "ip6-config" +#define NM_PPP_MANAGER_SIGNAL_NEW_CONFIG "new-config" #define NM_PPP_MANAGER_SIGNAL_STATS "stats" typedef struct _NMPPPManager NMPPPManager; typedef struct _NMPPPManagerStopHandle NMPPPManagerStopHandle; -typedef void (*NMPPPManagerStopCallback)(NMPPPManager * manager, +typedef void (*NMPPPManagerStopCallback)(NMPPPManager *manager, NMPPPManagerStopHandle *handle, gboolean was_cancelled, gpointer user_data); diff --git a/src/core/ppp/nm-ppp-mgr.c b/src/core/ppp/nm-ppp-mgr.c new file mode 100644 index 00000000..31c173a3 --- /dev/null +++ b/src/core/ppp/nm-ppp-mgr.c @@ -0,0 +1,620 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "src/core/nm-default-daemon.h" + +#include "nm-ppp-mgr.h" + +#include + +#include "NetworkManagerUtils.h" +#include "devices/nm-device-utils.h" +#include "nm-act-request.h" +#include "nm-netns.h" +#include "nm-ppp-manager-call.h" +#include "nm-ppp-status.h" + +/*****************************************************************************/ + +struct _NMPppMgr { + NMPppMgrConfig config; + NMPPPManager *ppp_manager; + GSource *idle_start; + GSource *connect_timeout_source; + union { + struct { + NMPppMgrIPData ip_data_6; + NMPppMgrIPData ip_data_4; + }; + NMPppMgrIPData ip_data_x[2]; + }; + int ifindex; + NMPppMgrStatsData stats_data; + NMPppMgrState state; + NMUtilsIPv6IfaceId ipv6_iid; + bool ppp_started : 1; +}; + +/*****************************************************************************/ + +#define _NMLOG_DOMAIN LOGD_PPP +#define _NMLOG_PREFIX_NAME "ppp-mgr" +#define _NMLOG(level, ...) \ + __NMLOG_DEFAULT_WITH_ADDR(level, _NMLOG_DOMAIN, _NMLOG_PREFIX_NAME, __VA_ARGS__) + +/*****************************************************************************/ + +NM_UTILS_LOOKUP_STR_DEFINE( + nm_ppp_mgr_state_to_string, + NMPppMgrState, + NM_UTILS_LOOKUP_DEFAULT_WARN("???"), + NM_UTILS_LOOKUP_STR_ITEM(NM_PPP_MGR_STATE_STARTING, "starting"), + NM_UTILS_LOOKUP_STR_ITEM(NM_PPP_MGR_STATE_WAITING_FOR_IFINDEX, "waiting-for-ifindex"), + NM_UTILS_LOOKUP_STR_ITEM(NM_PPP_MGR_STATE_HAVE_IFINDEX, "have-ifindex"), + NM_UTILS_LOOKUP_STR_ITEM(NM_PPP_MGR_STATE_HAVE_IP_CONFIG, "have-ip-config"), + NM_UTILS_LOOKUP_STR_ITEM(NM_PPP_MGR_STATE_FAILED_TO_START, "failed-to-start"), + NM_UTILS_LOOKUP_STR_ITEM(NM_PPP_MGR_STATE_FAILED_TO_IFINDEX, "failed-to-ifindex"), + NM_UTILS_LOOKUP_STR_ITEM(NM_PPP_MGR_STATE_FAILED, "failed")); + +NM_UTILS_LOOKUP_STR_DEFINE(nm_ppp_mgr_callback_type_to_string, + NMPppMgrCallbackType, + NM_UTILS_LOOKUP_DEFAULT_WARN("???"), + NM_UTILS_LOOKUP_STR_ITEM(NM_PPP_MGR_CALLBACK_TYPE_STATE_CHANGED, + "state-changed"), + NM_UTILS_LOOKUP_STR_ITEM(NM_PPP_MGR_CALLBACK_TYPE_STATS_CHANGED, + "stats-changed")); + +/*****************************************************************************/ + +#define SELF_TO_USERDATA(self) (&(self)->idle_start) + +#define SELF_FROM_USERDATA(user_data) \ + ((NMPppMgr *) (((const char *) (user_data)) - G_STRUCT_OFFSET(NMPppMgr, idle_start))) + +/*****************************************************************************/ + +gboolean +_nm_assert_is_ppp_mgr(const NMPppMgr *self) +{ + nm_assert(G_IS_OBJECT(self->ppp_manager)); + nm_assert(NM_IS_NETNS(self->config.netns)); + nm_assert(self->config.parent_iface); + + return TRUE; +} + +/*****************************************************************************/ + +static void +_callback_emit_with_data(NMPppMgr *self, const NMPppMgrCallbackData *callback_data) +{ + char sbuf_int[30]; + + switch (callback_data->callback_type) { + case NM_PPP_MGR_CALLBACK_TYPE_STATE_CHANGED: + _LOGT("emit signal: %s, state=%s%s%s%s%s, reason=%s", + nm_ppp_mgr_callback_type_to_string(callback_data->callback_type), + nm_ppp_mgr_state_to_string(callback_data->data.state), + NM_PRINT_FMT_QUOTED2(callback_data->data.state != callback_data->data.old_state, + ", old-state=", + nm_ppp_mgr_state_to_string(callback_data->data.old_state), + ""), + NM_PRINT_FMT_QUOTED2(callback_data->data.ifindex > 0, + ", ifindex=", + nm_sprintf_buf(sbuf_int, "%d", callback_data->data.ifindex), + ""), + callback_data->data.reason_msg); + break; + case NM_PPP_MGR_CALLBACK_TYPE_STATS_CHANGED: + /* This signal might be emitted every 5 seconds. It's too verbose for logging. + * Be silent. */ + break; + default: + nm_assert_not_reached(); + } + + self->config.callback(self, callback_data, self->config.user_data); +} + +static void +_callback_emit_state_change(NMPppMgr *self, + NMPppMgrCallbackType callback_type, + NMPppMgrState old_state, + gboolean ip_changed_4, + gboolean ip_changed_6, + NMDeviceStateReason reason, + const char *reason_msg) +{ + const NMPppMgrCallbackData callback_data = { + .callback_type = callback_type, + .data = + { + .old_state = old_state, + .state = self->state, + .ifindex = self->ifindex, + .reason = reason, + .reason_msg = reason_msg, + .ip_data_4 = &self->ip_data_4, + .ip_data_6 = &self->ip_data_6, + .stats_data = &self->stats_data, + .ip_changed_4 = ip_changed_4, + .ip_changed_6 = ip_changed_6, + }, + }; + + _callback_emit_with_data(self, &callback_data); +} + +/*****************************************************************************/ + +NMPppMgrState +nm_ppp_mgr_get_state(const NMPppMgr *self) +{ + g_return_val_if_fail(NM_IS_PPP_MGR(self), NM_PPP_MGR_STATE_FAILED); + + return self->state; +} + +int +nm_ppp_mgr_get_ifindex(const NMPppMgr *self) +{ + g_return_val_if_fail(NM_IS_PPP_MGR(self), 0); + + return self->ifindex; +} + +const NMPppMgrIPData * +nm_ppp_mgr_get_ip_data(const NMPppMgr *self, int addr_family) +{ + const int IS_IPv4 = NM_IS_IPv4(addr_family); + + g_return_val_if_fail(NM_IS_PPP_MGR(self), NULL); + + return &self->ip_data_x[IS_IPv4]; +} + +const NMPppMgrStatsData * +nm_ppp_mgr_get_stats(const NMPppMgr *self) +{ + g_return_val_if_fail(NM_IS_PPP_MGR(self), NULL); + + return &self->stats_data; +} + +/*****************************************************************************/ + +static void +_set_state(NMPppMgr *self, NMPppMgrState state, NMPppMgrState *out_old_state) +{ + if (state >= NM_PPP_MGR_STATE_HAVE_IP_CONFIG) + nm_clear_g_source_inst(&self->connect_timeout_source); + + NM_SET_OUT(out_old_state, self->state); + if (self->state != state) { + _LOGT("set state: %s (was %s)", + nm_ppp_mgr_state_to_string(state), + nm_ppp_mgr_state_to_string(self->state)); + self->state = state; + } +} + +static void +_set_state_failed(NMPppMgr *self, NMPppMgrState state, NMPppMgrState *out_old_state) +{ + nm_assert(state >= _NM_PPP_MGR_STATE_FAILED_START); + nm_assert(self->state < _NM_PPP_MGR_STATE_FAILED_START); + + _set_state(self, state, out_old_state); + + self->ifindex = 0; + nm_clear_l3cd(&self->ip_data_4.l3cd); + nm_clear_l3cd(&self->ip_data_6.l3cd); + self->ip_data_4 = (NMPppMgrIPData){ + .ip_received = FALSE, + .ip_enabled = FALSE, + }; + self->ip_data_6 = (NMPppMgrIPData){ + .ip_received = FALSE, + .ip_enabled = FALSE, + }; + + if (self->ppp_manager) { + g_signal_handlers_disconnect_by_data(self->ppp_manager, SELF_TO_USERDATA(self)); + if (self->ppp_started) { + self->ppp_started = FALSE; + nm_ppp_manager_stop(self->ppp_manager, NULL, NULL, NULL); + } + g_object_unref(self->ppp_manager); + } +} + +static gboolean +_state_ready_for_have_ifindex(NMPppMgr *self) +{ + if (self->ip_data_4.ip_received) { + /* once we receive an IPv4 config, we consider this as ready. + * + * The problem is that we don't know when we can expect an IPv6 config + * too, so we cannot just keep waiting. I don't know how to solve this, but + * it means IPv4+IPv6 together doesn't work well (because we would not + * wait for IPv6, once IPv4 config is received. */ + return TRUE; + } + + return ((!self->ip_data_4.ip_enabled || self->ip_data_4.ip_received) + && (!self->ip_data_6.ip_enabled || self->ip_data_6.ip_received)); +} + +/*****************************************************************************/ + +static void +_ppp_signal_state_changed(NMPPPManager *ppp_manager, guint ppp_state_u, gpointer user_data) +{ + NMPppMgr *self = SELF_FROM_USERDATA(user_data); + NMPPPStatus ppp_state = ppp_state_u; + NMPppMgrState state; + NMPppMgrState old_state; + NMDeviceStateReason reason; + const char *reason_msg; + + if ((guint) ppp_state != ppp_state_u) + ppp_state = NM_PPP_STATUS_UNKNOWN; + + switch (ppp_state) { + case NM_PPP_STATUS_DISCONNECT: + state = NM_PPP_MGR_STATE_FAILED; + reason = NM_DEVICE_STATE_REASON_PPP_DISCONNECT; + reason_msg = "ppp signals disconnect"; + break; + case NM_PPP_STATUS_DEAD: + case NM_PPP_STATUS_INTERN_DEAD: + state = NM_PPP_MGR_STATE_FAILED; + reason = NM_DEVICE_STATE_REASON_PPP_FAILED; + reason_msg = "ppp signals disconnect"; + break; + default: + _LOGT("ppp signal about state changed: #%u signal (ignored)", ppp_state_u); + return; + } + + _LOGT("ppp signal about state changed: #%u signal, new-state %s, state-reason=%s, %s", + ppp_state_u, + nm_ppp_mgr_state_to_string(state), + nm_device_state_reason_to_string(reason), + reason_msg); + + _set_state_failed(self, state, &old_state); + _callback_emit_state_change(self, + NM_PPP_MGR_CALLBACK_TYPE_STATE_CHANGED, + old_state, + FALSE, + FALSE, + reason, + reason_msg); +} + +static void +_ppp_signal_ifindex_set(NMPPPManager *ppp_manager, + int ifindex, + const char *ifname, + gpointer user_data) +{ + NMPppMgr *self = SELF_FROM_USERDATA(user_data); + NMPppMgrState old_state; + NMPppMgrState new_state; + gboolean ip_changed_4; + gboolean ip_changed_6; + + if (ifindex <= 0) { + nm_assert(self->state == NM_PPP_MGR_STATE_WAITING_FOR_IFINDEX); + _LOGT("ifindex set: invalid ifindex received"); + _set_state_failed(self, NM_PPP_MGR_STATE_FAILED_TO_IFINDEX, &old_state); + _callback_emit_state_change(self, + NM_PPP_MGR_CALLBACK_TYPE_STATE_CHANGED, + old_state, + FALSE, + FALSE, + NM_DEVICE_STATE_REASON_PPP_FAILED, + "invalid ifindex provided by ppp plugin"); + return; + } + + if (self->ifindex > 0) { + nm_assert(self->state > NM_PPP_MGR_STATE_WAITING_FOR_IFINDEX); + nm_assert(self->state < _NM_PPP_MGR_STATE_FAILED_START); + + _LOGT("ifindex set: ignore ifindex %d, already set to %d", ifindex, self->ifindex); + return; + } + + nm_assert(self->state == NM_PPP_MGR_STATE_WAITING_FOR_IFINDEX); + self->ifindex = ifindex; + + if (_state_ready_for_have_ifindex(self)) { + new_state = NM_PPP_MGR_STATE_HAVE_IP_CONFIG; + ip_changed_4 = self->ip_data_4.ip_received; + ip_changed_6 = self->ip_data_6.ip_received; + } else { + new_state = NM_PPP_MGR_STATE_HAVE_IFINDEX; + ip_changed_4 = FALSE; + ip_changed_6 = FALSE; + } + + _LOGT("ifindex set: ifindex %d", ifindex); + + _set_state(self, new_state, &old_state); + _callback_emit_state_change(self, + NM_PPP_MGR_CALLBACK_TYPE_STATE_CHANGED, + old_state, + ip_changed_4, + ip_changed_6, + NM_DEVICE_STATE_REASON_PPP_FAILED, + "invalid ifindex provided by ppp plugin"); +} + +static void +_ppp_signal_new_config(NMPPPManager *ppp_manager, + int addr_family, + const NML3ConfigData *l3cd, + const NMUtilsIPv6IfaceId *iid, + gpointer user_data) +{ + NMPppMgr *self = SELF_FROM_USERDATA(user_data); + const int IS_IPv4 = NM_IS_IPv4(addr_family); + NMPppMgrState old_state; + gboolean ip_changed_4; + gboolean ip_changed_6; + + nm_assert(self->state >= NM_PPP_MGR_STATE_WAITING_FOR_IFINDEX); + nm_assert(self->state < _NM_PPP_MGR_STATE_FAILED_START); + + if (nm_l3_config_data_equal(self->ip_data_x[IS_IPv4].l3cd, l3cd)) + l3cd = self->ip_data_x[IS_IPv4].l3cd; + + nm_l3_config_data_reset(&self->ip_data_x[IS_IPv4].l3cd, l3cd); + if (!IS_IPv4) { + if (iid) + self->ipv6_iid = *iid; + else + self->ipv6_iid = (NMUtilsIPv6IfaceId) NM_UTILS_IPV6_IFACE_ID_INIT; + self->ip_data_6.ipv6_iid = + nm_utils_memeqzero(&self->ipv6_iid, sizeof(self->ipv6_iid)) ? NULL : &self->ipv6_iid; + } + self->ip_data_x[IS_IPv4].ip_received = TRUE; + + if (self->state == NM_PPP_MGR_STATE_WAITING_FOR_IFINDEX) { + /* we still wait for the ifindex. We just cache the IP configuration, + * but leave the state unchanged. */ + _LOGT("ip-config v%c received (still waiting for ifindex)", + nm_utils_addr_family_to_char(addr_family)); + old_state = NM_PPP_MGR_STATE_WAITING_FOR_IFINDEX; + } else { + NMPppMgrState new_state; + + _LOGT("ip-config v%c received", nm_utils_addr_family_to_char(addr_family)); + new_state = _state_ready_for_have_ifindex(self) ? NM_PPP_MGR_STATE_HAVE_IP_CONFIG + : NM_PPP_MGR_STATE_HAVE_IFINDEX; + nm_assert((self->state == NM_PPP_MGR_STATE_HAVE_IFINDEX) + || (self->state == NM_PPP_MGR_STATE_HAVE_IP_CONFIG + && new_state == NM_PPP_MGR_STATE_HAVE_IP_CONFIG)); + _set_state(self, new_state, &old_state); + } + + ip_changed_4 = IS_IPv4; + ip_changed_6 = !IS_IPv4; + + _callback_emit_state_change(self, + NM_PPP_MGR_CALLBACK_TYPE_STATE_CHANGED, + old_state, + ip_changed_4, + ip_changed_6, + NM_DEVICE_STATE_REASON_NONE, + "ip config received"); +} + +static void +_ppp_signal_stats(NMPPPManager *ppp_manager, guint in_bytes, guint out_bytes, gpointer user_data) +{ + NMPppMgr *self = SELF_FROM_USERDATA(user_data); + + if (self->stats_data.in_bytes == in_bytes && self->stats_data.out_bytes == out_bytes) + return; + + self->stats_data.in_bytes = in_bytes; + self->stats_data.out_bytes = out_bytes; + + _callback_emit_state_change(self, + NM_PPP_MGR_CALLBACK_TYPE_STATS_CHANGED, + self->state, + FALSE, + FALSE, + NM_DEVICE_STATE_REASON_NONE, + "stats update"); +} + +/*****************************************************************************/ + +static gboolean +_ifindex_timeout_cb(gpointer user_data) +{ + NMPppMgr *self = user_data; + NMPppMgrState old_state; + + nm_clear_g_source_inst(&self->connect_timeout_source); + + _set_state_failed(self, NM_PPP_MGR_STATE_FAILED_TO_IFINDEX, &old_state); + _callback_emit_state_change(self, + NM_PPP_MGR_CALLBACK_TYPE_STATE_CHANGED, + old_state, + FALSE, + FALSE, + NM_DEVICE_STATE_REASON_PPP_FAILED, + "timeout connecting"); + return G_SOURCE_CONTINUE; +} + +/*****************************************************************************/ + +static gboolean +_idle_start_cb(gpointer user_data) +{ + NMPppMgr *self = user_data; + gs_free_error GError *error = NULL; + NMPppMgrState old_state; + gboolean ip4_enabled; + gboolean ip6_enabled; + NMPlatform *platform; + const NMPlatformLink *plink; + + nm_clear_g_source_inst(&self->idle_start); + + /* We only evaluate ipx_enabled here. That is because nm_ppp_manager_start() + * will evaluate it based on act_req's applied connection (like we do now), + * but as the applied connection can be reapplied, let's do it at the + * same time to be sure we agree. + * + * This should be nicer solved by NMPPPManager not accessing the NMConnection + * or make little/no use of NMActRequest. */ + nm_utils_ppp_ip_methods_enabled(nm_act_request_get_applied_connection(self->config.act_req), + &ip4_enabled, + &ip6_enabled); + self->ip_data_4.ip_enabled = !!ip4_enabled; + self->ip_data_6.ip_enabled = !!ip6_enabled; + + g_signal_connect(self->ppp_manager, + NM_PPP_MANAGER_SIGNAL_STATE_CHANGED, + G_CALLBACK(_ppp_signal_state_changed), + SELF_TO_USERDATA(self)); + g_signal_connect(self->ppp_manager, + NM_PPP_MANAGER_SIGNAL_IFINDEX_SET, + G_CALLBACK(_ppp_signal_ifindex_set), + SELF_TO_USERDATA(self)); + g_signal_connect(self->ppp_manager, + NM_PPP_MANAGER_SIGNAL_NEW_CONFIG, + G_CALLBACK(_ppp_signal_new_config), + SELF_TO_USERDATA(self)); + g_signal_connect(self->ppp_manager, + NM_PPP_MANAGER_SIGNAL_STATS, + G_CALLBACK(_ppp_signal_stats), + SELF_TO_USERDATA(self)); + + platform = nm_netns_get_platform(self->config.netns); + plink = nm_platform_link_get_by_ifname(platform, self->config.parent_iface); + if (plink && !NM_FLAGS_HAS(plink->n_ifi_flags, IFF_UP)) { + nm_platform_link_change_flags(platform, plink->ifindex, IFF_UP, TRUE); + } + + self->ppp_started = TRUE; + if (!nm_ppp_manager_start(self->ppp_manager, + self->config.act_req, + self->config.ppp_username, + 0, + self->config.baud_override, + &error)) { + gs_free char *reason_msg = NULL; + + _set_state_failed(self, NM_PPP_MGR_STATE_FAILED_TO_START, &old_state); + reason_msg = g_strdup_printf("failed to start: %s", error->message); + _callback_emit_state_change(self, + NM_PPP_MGR_CALLBACK_TYPE_STATE_CHANGED, + old_state, + FALSE, + FALSE, + NM_DEVICE_STATE_REASON_PPP_START_FAILED, + reason_msg); + return G_SOURCE_CONTINUE; + } + + nm_assert(self->state == NM_PPP_MGR_STATE_STARTING); + _set_state(self, NM_PPP_MGR_STATE_WAITING_FOR_IFINDEX, &old_state); + + self->connect_timeout_source = + nm_g_timeout_add_seconds_source(self->config.timeout_secs, _ifindex_timeout_cb, self); + + _callback_emit_state_change(self, + NM_PPP_MGR_CALLBACK_TYPE_STATE_CHANGED, + old_state, + FALSE, + FALSE, + NM_DEVICE_STATE_REASON_NONE, + "pppd is starting"); + + return G_SOURCE_CONTINUE; +} + +/*****************************************************************************/ + +NMPppMgr * +nm_ppp_mgr_start(const NMPppMgrConfig *config, GError **error) +{ + NMPppMgr *self; + NMPPPManager *ppp_manager; + + g_return_val_if_fail(config, NULL); + g_return_val_if_fail(NM_IS_NETNS(config->netns), NULL); + g_return_val_if_fail(config->parent_iface, NULL); + g_return_val_if_fail(NM_IS_ACT_REQUEST(config->act_req), NULL); + g_return_val_if_fail(config->callback, NULL); + g_return_val_if_fail(!error || !*error, NULL); + + ppp_manager = nm_ppp_manager_create(config->parent_iface, error); + + if (!ppp_manager) + return NULL; + + self = g_slice_new(NMPppMgr); + + *self = (NMPppMgr){ + .config = *config, + .ppp_manager = ppp_manager, + .idle_start = nm_g_idle_add_source(_idle_start_cb, self), + .state = NM_PPP_MGR_STATE_STARTING, + .ip_data_4 = + { + .ip_received = FALSE, + .ip_enabled = NM_OPTION_BOOL_DEFAULT, + }, + .ip_data_6 = + { + .ip_received = FALSE, + .ip_enabled = NM_OPTION_BOOL_DEFAULT, + }, + .stats_data = + { + .in_bytes = 0, + .out_bytes = 0, + }, + }; + + g_object_ref(self->config.act_req); + g_object_ref(self->config.netns); + self->config.parent_iface = g_strdup(self->config.parent_iface); + self->config.ppp_username = g_strdup(self->config.ppp_username); + + _LOGD("created"); + + return self; +} + +void +nm_ppp_mgr_destroy(NMPppMgr *self) +{ + if (!self) + return; + + _LOGD("destroying"); + + if (self->state < _NM_PPP_MGR_STATE_FAILED_START) + _set_state_failed(self, NM_PPP_MGR_STATE_FAILED, NULL); + + nm_clear_g_source_inst(&self->idle_start); + nm_clear_g_source_inst(&self->connect_timeout_source); + + g_object_unref(self->config.act_req); + + g_free((char *) self->config.parent_iface); + g_free((char *) self->config.ppp_username); + + g_object_unref(self->config.netns); + + nm_g_slice_free(self); +} diff --git a/src/core/ppp/nm-ppp-mgr.h b/src/core/ppp/nm-ppp-mgr.h new file mode 100644 index 00000000..f6165411 --- /dev/null +++ b/src/core/ppp/nm-ppp-mgr.h @@ -0,0 +1,131 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef __NM_PPP_MGR_H__ +#define __NM_PPP_MGR_H__ + +#include "nm-l3cfg.h" + +typedef struct _NMPppMgr NMPppMgr; + +typedef enum _nm_packed { + /* NMPppMgr is starting. It will call nm_ppp_manager_start() on an idle + * handler. */ + NM_PPP_MGR_STATE_STARTING, + + /* NMPppMgr called nm_ppp_manager_start() and is now waiting to get + * an ifindex. At this time, we theoretically might already get IP configuration + * but that is cached and meaningless until we have the ifindex. */ + NM_PPP_MGR_STATE_WAITING_FOR_IFINDEX, + + /* NMPppMgr received an ifindex from NMPPPManager. But no IP configuration + * is yet received. */ + NM_PPP_MGR_STATE_HAVE_IFINDEX, + + /* NMPppMgr received an ifindex and IP configuration from NMPPPManager. + * Whether we have IPv4 and/or IPv6 is unspecified. + * + * If we have only either IPv4 or IPv6, then it's also unclear unknown + * whether the other address family will still arrive or not. */ + NM_PPP_MGR_STATE_HAVE_IP_CONFIG, + + /* Meta enum value which is the first failed state. All states larger than + * this are final (dead) states. */ + _NM_PPP_MGR_STATE_FAILED_START, + + /* NMPPPManager failed to start. This is a final (dead) state. */ + NM_PPP_MGR_STATE_FAILED_TO_START = _NM_PPP_MGR_STATE_FAILED_START, + + /* NMPppMgr started, but it failed to get the ifindex (possibly after timeout). + * This is a final (dead) state. */ + NM_PPP_MGR_STATE_FAILED_TO_IFINDEX, + + /* An unspecified failed state. This is a final (dead) state. */ + NM_PPP_MGR_STATE_FAILED, +} NMPppMgrState; + +const char *nm_ppp_mgr_state_to_string(NMPppMgrState state); + +typedef enum { + NM_PPP_MGR_CALLBACK_TYPE_STATE_CHANGED, + NM_PPP_MGR_CALLBACK_TYPE_STATS_CHANGED, +} NMPppMgrCallbackType; + +const char *nm_ppp_mgr_callback_type_to_string(NMPppMgrCallbackType callback_type); + +typedef struct { + guint32 in_bytes; + guint32 out_bytes; +} NMPppMgrStatsData; + +typedef struct { + const NML3ConfigData *l3cd; + const NMUtilsIPv6IfaceId *ipv6_iid; + NMOptionBool ip_enabled; + bool ip_received; +} NMPppMgrIPData; + +typedef struct { + NMPppMgrCallbackType callback_type; + union { + struct { + const char *reason_msg; + union { + struct { + const NMPppMgrIPData *ip_data_6; + const NMPppMgrIPData *ip_data_4; + }; + const NMPppMgrIPData *ip_data_x[2]; + }; + const NMPppMgrStatsData *stats_data; + int ifindex; + NMDeviceStateReason reason; + NMPppMgrState old_state; + NMPppMgrState state; + union { + struct { + bool ip_changed_6; + bool ip_changed_4; + }; + bool ip_changed_x[2]; + }; + } data; + }; +} NMPppMgrCallbackData; + +typedef void (*NMPppMgrCallback)(NMPppMgr *self, + const NMPppMgrCallbackData *callback_data, + gpointer user_data); + +typedef struct { + NMNetns *netns; + const char *parent_iface; + + NMPppMgrCallback callback; + gpointer user_data; + + NMActRequest *act_req; + const char *ppp_username; + guint32 timeout_secs; + guint baud_override; +} NMPppMgrConfig; + +gboolean _nm_assert_is_ppp_mgr(const NMPppMgr *self); + +#define NM_IS_PPP_MGR(self) \ + ({ \ + const NMPppMgr *_self = (self); \ + \ + nm_assert(_nm_assert_is_ppp_mgr(_self)); \ + !!_self; \ + }) + +NMPppMgr *nm_ppp_mgr_start(const NMPppMgrConfig *config, GError **error); + +NMPppMgrState nm_ppp_mgr_get_state(const NMPppMgr *self); +int nm_ppp_mgr_get_ifindex(const NMPppMgr *self); +const NMPppMgrIPData *nm_ppp_mgr_get_ip_data(const NMPppMgr *self, int addr_family); +const NMPppMgrStatsData *nm_ppp_mgr_get_stats(const NMPppMgr *self); + +void nm_ppp_mgr_destroy(NMPppMgr *self); + +#endif /* __NM_PPP_MGR_H__ */ diff --git a/src/core/ppp/nm-ppp-plugin-api.h b/src/core/ppp/nm-ppp-plugin-api.h index 647e1c24..de4cfae3 100644 --- a/src/core/ppp/nm-ppp-plugin-api.h +++ b/src/core/ppp/nm-ppp-plugin-api.h @@ -11,21 +11,15 @@ typedef const struct { NMPPPManager *(*create)(const char *iface); - void (*set_route_parameters)(NMPPPManager *manager, - guint32 route_table_v4, - guint32 route_metric_v4, - guint32 route_table_v6, - guint32 route_metric_v6); - gboolean (*start)(NMPPPManager *manager, NMActRequest *req, - const char * ppp_name, + const char *ppp_name, guint32 timeout_secs, guint baud_override, - GError ** err); + GError **err); - NMPPPManagerStopHandle *(*stop)(NMPPPManager * manager, - GCancellable * cancellable, + NMPPPManagerStopHandle *(*stop)(NMPPPManager *manager, + GCancellable *cancellable, NMPPPManagerStopCallback callback, gpointer user_data); diff --git a/src/core/ppp/nm-ppp-status.h b/src/core/ppp/nm-ppp-status.h index c346b119..df0ac10b 100644 --- a/src/core/ppp/nm-ppp-status.h +++ b/src/core/ppp/nm-ppp-status.h @@ -22,7 +22,10 @@ typedef enum { NM_PPP_STATUS_TERMINATE, NM_PPP_STATUS_DISCONNECT, NM_PPP_STATUS_HOLDOFF, - NM_PPP_STATUS_MASTER + NM_PPP_STATUS_MASTER, + + /* these states are internal and not announced by the pppd plugin. */ + NM_PPP_STATUS_INTERN_DEAD, } NMPPPStatus; #endif /* __NM_PPP_STATUS_H__ */ diff --git a/src/core/ppp/nm-pppd-plugin.c b/src/core/ppp/nm-pppd-plugin.c index 5ffa7d17..e2e34d2a 100644 --- a/src/core/ppp/nm-pppd-plugin.c +++ b/src/core/ppp/nm-pppd-plugin.c @@ -33,14 +33,14 @@ char pppd_version[] = VERSION; static struct { GDBusConnection *dbus_connection; - char * ipparam; + char *ipparam; } gl; static void nm_phasechange(int arg) { NMPPPStatus ppp_status = NM_PPP_STATUS_UNKNOWN; - char * ppp_phase; + char *ppp_phase; g_return_if_fail(G_IS_DBUS_CONNECTION(gl.dbus_connection)); @@ -332,10 +332,10 @@ get_pap_check(void) static int get_credentials(char *username, char *password) { - gs_unref_variant GVariant *ret = NULL; - gs_free_error GError *error = NULL; - const char * my_username; - const char * my_password; + gs_unref_variant GVariant *ret = NULL; + gs_free_error GError *error = NULL; + const char *my_username; + const char *my_password; if (!password) { /* pppd is checking pap support; return 1 for supported */ diff --git a/src/core/settings/nm-agent-manager.c b/src/core/settings/nm-agent-manager.c index a1c2eb9c..295378bc 100644 --- a/src/core/settings/nm-agent-manager.c +++ b/src/core/settings/nm-agent-manager.c @@ -32,7 +32,7 @@ enum { static guint signals[LAST_SIGNAL] = {0}; typedef struct { - NMAuthManager * auth_mgr; + NMAuthManager *auth_mgr; NMSessionMonitor *session_monitor; CList agent_lst_head; @@ -186,7 +186,7 @@ struct _NMAgentManagerCallId { NMAuthSubject *subject; /* Current agent being asked for secrets */ - NMSecretAgent * current; + NMSecretAgent *current; NMSecretAgentCallId *current_call_id; /* Stores the sorted list of NMSecretAgents which will be asked for secrets */ @@ -196,7 +196,7 @@ struct _NMAgentManagerCallId { union { struct { - char * path; + char *path; NMConnection *connection; NMAuthChain *chain; @@ -209,8 +209,8 @@ struct _NMAgentManagerCallId { union { struct { NMSecretAgentGetSecretsFlags flags; - char * setting_name; - char ** hints; + char *setting_name; + char **hints; GVariant *existing_secrets; @@ -238,7 +238,7 @@ _agent_find_by_owner(NMAgentManagerPrivate *priv, const char *owner) static NMSecretAgent * _agent_find_by_identifier_and_uid(NMAgentManagerPrivate *priv, - const char * identifier, + const char *identifier, gulong sender_uid) { NMSecretAgent *agent; @@ -257,7 +257,7 @@ static void _agent_remove(NMAgentManager *self, NMSecretAgent *agent) { NMAgentManagerPrivate *priv = NM_AGENT_MANAGER_GET_PRIVATE(self); - CList * iter, *safe; + CList *iter, *safe; nm_assert(NM_IS_SECRET_AGENT(agent)); nm_assert(c_list_contains(&priv->agent_lst_head, &agent->agent_lst)); @@ -349,14 +349,14 @@ validate_identifier(const char *identifier, GError **error) } static void -_agent_permissions_check_done(NMAuthChain * chain, +_agent_permissions_check_done(NMAuthChain *chain, GDBusMethodInvocation *context, gpointer user_data) { - NMAgentManager * self = NM_AGENT_MANAGER(user_data); + NMAgentManager *self = NM_AGENT_MANAGER(user_data); NMAgentManagerPrivate *priv = NM_AGENT_MANAGER_GET_PRIVATE(self); - NMSecretAgent * agent; - Request * request; + NMSecretAgent *agent; + Request *request; nm_assert(!context || G_IS_DBUS_METHOD_INVOCATION(context)); @@ -438,16 +438,16 @@ agent_disconnected_cb(NMSecretAgent *agent, gpointer user_data) } static void -agent_manager_register_with_capabilities(NMAgentManager * self, +agent_manager_register_with_capabilities(NMAgentManager *self, GDBusMethodInvocation *context, - const char * identifier, + const char *identifier, guint32 capabilities) { - NMAgentManagerPrivate *priv = NM_AGENT_MANAGER_GET_PRIVATE(self); + NMAgentManagerPrivate *priv = NM_AGENT_MANAGER_GET_PRIVATE(self); gs_unref_object NMAuthSubject *subject = NULL; gulong sender_uid = G_MAXULONG; - GError * error = NULL; - NMSecretAgent * agent; + GError *error = NULL; + NMSecretAgent *agent; subject = nm_dbus_manager_new_auth_subject_from_context(context); if (!subject) { @@ -484,13 +484,13 @@ agent_manager_register_with_capabilities(NMAgentManager * self, } static void -impl_agent_manager_register(NMDBusObject * obj, +impl_agent_manager_register(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { const char *identifier; @@ -499,13 +499,13 @@ impl_agent_manager_register(NMDBusObject * obj, } static void -impl_agent_manager_register_with_capabilities(NMDBusObject * obj, +impl_agent_manager_register_with_capabilities(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { const char *identifier; guint32 capabilities; @@ -518,17 +518,17 @@ impl_agent_manager_register_with_capabilities(NMDBusObject * } static void -impl_agent_manager_unregister(NMDBusObject * obj, +impl_agent_manager_unregister(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMAgentManager * self = NM_AGENT_MANAGER(obj); + NMAgentManager *self = NM_AGENT_MANAGER(obj); NMAgentManagerPrivate *priv = NM_AGENT_MANAGER_GET_PRIVATE(self); - NMSecretAgent * agent; + NMSecretAgent *agent; agent = _agent_find_by_owner(priv, sender); if (!agent) { @@ -549,8 +549,8 @@ impl_agent_manager_unregister(NMDBusObject * obj, static Request * request_new(NMAgentManager *self, RequestType request_type, - const char * detail, - NMAuthSubject * subject) + const char *detail, + NMAuthSubject *subject) { Request *req; @@ -607,11 +607,11 @@ request_free(Request *req) } static void -req_complete_release(Request * req, - GVariant * secrets, +req_complete_release(Request *req, + GVariant *secrets, const char *agent_dbus_owner, const char *agent_username, - GError * error) + GError *error) { NMAgentManager *self = req->self; @@ -653,11 +653,11 @@ req_complete_cancel(Request *req, gboolean is_disposing) } static void -req_complete(Request * req, - GVariant * secrets, +req_complete(Request *req, + GVariant *secrets, const char *agent_dbus_owner, const char *agent_username, - GError * error) + GError *error) { NMAgentManager *self = req->self; @@ -678,9 +678,9 @@ req_complete_error(Request *req, GError *error) static int agent_compare_func(gconstpointer aa, gconstpointer bb, gpointer user_data) { - NMSecretAgent * a = (NMSecretAgent *) aa; - NMSecretAgent * b = (NMSecretAgent *) bb; - Request * req = user_data; + NMSecretAgent *a = (NMSecretAgent *) aa; + NMSecretAgent *b = (NMSecretAgent *) bb; + Request *req = user_data; NMSessionMonitor *sm; gboolean a_active, b_active; gulong a_pid, b_pid, requester; @@ -774,7 +774,7 @@ static void request_add_agents(NMAgentManager *self, Request *req) { NMAgentManagerPrivate *priv = NM_AGENT_MANAGER_GET_PRIVATE(self); - NMSecretAgent * agent; + NMSecretAgent *agent; c_list_for_each_entry (agent, &priv->agent_lst_head, agent_lst) { if (agent->fully_registered) @@ -786,7 +786,7 @@ static void request_next_agent(Request *req) { NMAgentManager *self; - GError * error = NULL; + GError *error = NULL; self = req->self; @@ -887,17 +887,17 @@ out: /*****************************************************************************/ static void -_con_get_request_done(NMSecretAgent * agent, +_con_get_request_done(NMSecretAgent *agent, NMSecretAgentCallId *call_id, - GVariant * secrets, - GError * error, + GVariant *secrets, + GError *error, gpointer user_data) { NMAgentManager *self; - Request * req = user_data; - GVariant * setting_secrets; - const char * agent_dbus_owner; - gs_free char * agent_name = NULL; + Request *req = user_data; + GVariant *setting_secrets; + const char *agent_dbus_owner; + gs_free char *agent_name = NULL; g_return_if_fail(call_id == req->current_call_id); g_return_if_fail(agent == req->current); @@ -962,15 +962,15 @@ static void set_secrets_not_required(NMConnection *connection, GVariant *dict) { GVariantIter iter, setting_iter; - const char * setting_name = NULL; - GVariant * setting_dict = NULL; + const char *setting_name = NULL; + GVariant *setting_dict = NULL; /* Iterate through the settings dicts */ g_variant_iter_init(&iter, dict); while (g_variant_iter_next(&iter, "{&s@a{sv}}", &setting_name, &setting_dict)) { const char *key_name = NULL; - NMSetting * setting; - GVariant * val; + NMSetting *setting; + GVariant *val; setting = nm_connection_get_setting_by_name(connection, setting_name); if (setting) { @@ -985,7 +985,7 @@ set_secrets_not_required(NMConnection *connection, GVariant *dict) && strcmp(key_name, NM_SETTING_VPN_SECRETS) == 0 && g_variant_is_of_type(val, G_VARIANT_TYPE("a{ss}"))) { GVariantIter vpn_secret_iter; - const char * secret_name, *secret; + const char *secret_name, *secret; g_variant_iter_init(&vpn_secret_iter, val); while (g_variant_iter_next(&vpn_secret_iter, "{&s&s}", &secret_name, &secret)) @@ -1046,13 +1046,13 @@ _con_get_request_start_proceed(Request *req, gboolean include_system_secrets) } static void -_con_get_request_start_validated(NMAuthChain * chain, +_con_get_request_start_validated(NMAuthChain *chain, GDBusMethodInvocation *context, gpointer user_data) { NMAgentManager *self; - Request * req = user_data; - const char * perm; + Request *req = user_data; + const char *perm; g_return_if_fail(req->request_type == REQUEST_TYPE_CON_GET); @@ -1080,9 +1080,9 @@ _con_get_request_start_validated(NMAuthChain * chain, static void _con_get_request_start(Request *req) { - NMAgentManager * self; + NMAgentManager *self; NMSettingConnection *s_con; - const char * agent_dbus_owner, *perm; + const char *agent_dbus_owner, *perm; self = req->self; @@ -1138,10 +1138,10 @@ _con_get_request_start(Request *req) static gboolean _con_get_try_complete_early(Request *req) { - NMAgentManager * self; - gs_unref_variant GVariant *setting_secrets = NULL; - gs_unref_object NMConnection *tmp = NULL; - GError * error = NULL; + NMAgentManager *self; + gs_unref_variant GVariant *setting_secrets = NULL; + gs_unref_object NMConnection *tmp = NULL; + GError *error = NULL; self = req->self; @@ -1223,14 +1223,14 @@ _con_get_try_complete_early(Request *req) * Returns: a call-id to cancel the call. */ NMAgentManagerCallId -nm_agent_manager_get_secrets(NMAgentManager * self, - const char * path, - NMConnection * connection, - NMAuthSubject * subject, - GVariant * existing_secrets, - const char * setting_name, +nm_agent_manager_get_secrets(NMAgentManager *self, + const char *path, + NMConnection *connection, + NMAuthSubject *subject, + GVariant *existing_secrets, + const char *setting_name, NMSecretAgentGetSecretsFlags flags, - const char *const * hints, + const char *const *hints, NMAgentSecretsResultFunc callback, gpointer callback_data) { @@ -1288,15 +1288,15 @@ nm_agent_manager_cancel_secrets(NMAgentManager *self, NMAgentManagerCallId reque /*****************************************************************************/ static void -_con_save_request_done(NMSecretAgent * agent, +_con_save_request_done(NMSecretAgent *agent, NMSecretAgentCallId *call_id, - GVariant * secrets, - GError * error, + GVariant *secrets, + GError *error, gpointer user_data) { NMAgentManager *self; - Request * req = user_data; - const char * agent_dbus_owner; + Request *req = user_data; + const char *agent_dbus_owner; g_return_if_fail(call_id == req->current_call_id); g_return_if_fail(agent == req->current); @@ -1344,9 +1344,9 @@ _con_save_request_start(Request *req) void nm_agent_manager_save_secrets(NMAgentManager *self, - const char * path, - NMConnection * connection, - NMAuthSubject * subject) + const char *path, + NMConnection *connection, + NMAuthSubject *subject) { Request *req; @@ -1370,14 +1370,14 @@ nm_agent_manager_save_secrets(NMAgentManager *self, /*****************************************************************************/ static void -_con_del_request_done(NMSecretAgent * agent, +_con_del_request_done(NMSecretAgent *agent, NMSecretAgentCallId *call_id, - GVariant * secrets, - GError * error, + GVariant *secrets, + GError *error, gpointer user_data) { NMAgentManager *self; - Request * req = user_data; + Request *req = user_data; g_return_if_fail(call_id == req->current_call_id); g_return_if_fail(agent == req->current); @@ -1425,7 +1425,7 @@ void nm_agent_manager_delete_secrets(NMAgentManager *self, const char *path, NMConnection *connection) { NMAuthSubject *subject; - Request * req; + Request *req; g_return_if_fail(self != NULL); g_return_if_fail(path && *path); @@ -1450,11 +1450,11 @@ nm_agent_manager_delete_secrets(NMAgentManager *self, const char *path, NMConnec gboolean nm_agent_manager_has_agent_with_permission(NMAgentManager *self, - const char * username, - const char * permission) + const char *username, + const char *permission) { NMAgentManagerPrivate *priv; - NMSecretAgent * agent; + NMSecretAgent *agent; g_return_val_if_fail(NM_IS_AGENT_MANAGER(self), FALSE); g_return_val_if_fail(username, FALSE); @@ -1477,12 +1477,12 @@ nm_agent_manager_has_agent_with_permission(NMAgentManager *self, /*****************************************************************************/ gboolean -nm_agent_manager_all_agents_have_capability(NMAgentManager * manager, - NMAuthSubject * subject, +nm_agent_manager_all_agents_have_capability(NMAgentManager *manager, + NMAuthSubject *subject, NMSecretAgentCapabilities capability) { NMAgentManagerPrivate *priv = NM_AGENT_MANAGER_GET_PRIVATE(manager); - NMSecretAgent * agent; + NMSecretAgent *agent; gboolean subject_is_unix_process = (nm_auth_subject_get_subject_type(subject) == NM_AUTH_SUBJECT_TYPE_UNIX_PROCESS); gulong subject_uid = @@ -1506,7 +1506,7 @@ static void authority_changed_cb(NMAuthManager *auth_manager, NMAgentManager *self) { NMAgentManagerPrivate *priv = NM_AGENT_MANAGER_GET_PRIVATE(self); - NMSecretAgent * agent; + NMSecretAgent *agent; c_list_for_each_entry (agent, &priv->agent_lst_head, agent_lst) _agent_create_auth_chain(self, agent, NULL); @@ -1545,10 +1545,10 @@ constructed(GObject *object) static void dispose(GObject *object) { - NMAgentManager * self = NM_AGENT_MANAGER(object); + NMAgentManager *self = NM_AGENT_MANAGER(object); NMAgentManagerPrivate *priv = NM_AGENT_MANAGER_GET_PRIVATE(self); - Request * request; - NMSecretAgent * agent; + Request *request; + NMSecretAgent *agent; while ((request = c_list_first_entry(&priv->request_lst_head, Request, request_lst))) { c_list_unlink(&request->request_lst); @@ -1596,7 +1596,7 @@ static const NMDBusInterfaceInfoExtended interface_info_agent_manager = { static void nm_agent_manager_class_init(NMAgentManagerClass *agent_manager_class) { - GObjectClass * object_class = G_OBJECT_CLASS(agent_manager_class); + GObjectClass *object_class = G_OBJECT_CLASS(agent_manager_class); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(agent_manager_class); dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_STATIC(NM_DBUS_PATH_AGENT_MANAGER); diff --git a/src/core/settings/nm-agent-manager.h b/src/core/settings/nm-agent-manager.h index b26af4ef..cae8e8e0 100644 --- a/src/core/settings/nm-agent-manager.h +++ b/src/core/settings/nm-agent-manager.h @@ -34,45 +34,45 @@ NMAgentManager *nm_agent_manager_get(void); guint64 nm_agent_manager_get_agent_version_id(NMAgentManager *self); /* If no agent fulfilled the secrets request, agent_dbus_owner will be NULL */ -typedef void (*NMAgentSecretsResultFunc)(NMAgentManager * manager, +typedef void (*NMAgentSecretsResultFunc)(NMAgentManager *manager, NMAgentManagerCallId call_id, - const char * agent_dbus_owner, - const char * agent_uname, + const char *agent_dbus_owner, + const char *agent_uname, gboolean agent_has_modify, - const char * setting_name, + const char *setting_name, NMSecretAgentGetSecretsFlags flags, - GVariant * secrets, - GError * error, + GVariant *secrets, + GError *error, gpointer user_data); -NMAgentManagerCallId nm_agent_manager_get_secrets(NMAgentManager * manager, - const char * path, - NMConnection * connection, - NMAuthSubject * subject, - GVariant * existing_secrets, - const char * setting_name, +NMAgentManagerCallId nm_agent_manager_get_secrets(NMAgentManager *manager, + const char *path, + NMConnection *connection, + NMAuthSubject *subject, + GVariant *existing_secrets, + const char *setting_name, NMSecretAgentGetSecretsFlags flags, - const char *const * hints, + const char *const *hints, NMAgentSecretsResultFunc callback, gpointer callback_data); void nm_agent_manager_cancel_secrets(NMAgentManager *manager, NMAgentManagerCallId request_id); void nm_agent_manager_save_secrets(NMAgentManager *manager, - const char * path, - NMConnection * connection, - NMAuthSubject * subject); + const char *path, + NMConnection *connection, + NMAuthSubject *subject); void nm_agent_manager_delete_secrets(NMAgentManager *manager, - const char * path, - NMConnection * connection); + const char *path, + NMConnection *connection); gboolean nm_agent_manager_has_agent_with_permission(NMAgentManager *self, - const char * username, - const char * permission); + const char *username, + const char *permission); -gboolean nm_agent_manager_all_agents_have_capability(NMAgentManager * manager, - NMAuthSubject * subject, +gboolean nm_agent_manager_all_agents_have_capability(NMAgentManager *manager, + NMAuthSubject *subject, NMSecretAgentCapabilities capability); #endif /* __NETWORKMANAGER_AGENT_MANAGER_H__ */ diff --git a/src/core/settings/nm-secret-agent.c b/src/core/settings/nm-secret-agent.c index 45152c27..b222bd5c 100644 --- a/src/core/settings/nm-secret-agent.c +++ b/src/core/settings/nm-secret-agent.c @@ -37,13 +37,13 @@ static guint signals[LAST_SIGNAL] = {0}; typedef struct _NMSecretAgentPrivate { CList permissions; CList requests; - GDBusConnection * dbus_connection; - char * description; - NMAuthSubject * subject; - char * identifier; - char * owner_username; - char * dbus_owner; - GCancellable * name_owner_cancellable; + GDBusConnection *dbus_connection; + char *description; + NMAuthSubject *subject; + char *identifier; + char *owner_username; + char *dbus_owner; + GCancellable *name_owner_cancellable; guint name_owner_changed_id; NMSecretAgentCapabilities capabilities; bool shutdown_wait_obj_registered : 1; @@ -121,25 +121,25 @@ static NM_UTILS_FLAGS2STR_DEFINE(_capabilities_to_string, struct _NMSecretAgentCallId { CList lst; - NMSecretAgent * self; - GCancellable * cancellable; - char * path; - const char * method_name; - char * setting_name; + NMSecretAgent *self; + GCancellable *cancellable; + char *path; + const char *method_name; + char *setting_name; NMSecretAgentCallback callback; gpointer callback_data; }; static NMSecretAgentCallId * -_call_id_new(NMSecretAgent * self, - const char * method_name, /* this must be a static string. */ - const char * path, - const char * setting_name, +_call_id_new(NMSecretAgent *self, + const char *method_name, /* this must be a static string. */ + const char *path, + const char *setting_name, NMSecretAgentCallback callback, gpointer callback_data) { NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE(self); - NMSecretAgentCallId * call_id; + NMSecretAgentCallId *call_id; call_id = g_slice_new(NMSecretAgentCallId); *call_id = (NMSecretAgentCallId){ @@ -181,8 +181,8 @@ _call_id_free(NMSecretAgentCallId *call_id) static void _call_id_invoke_callback(NMSecretAgentCallId *call_id, - GVariant * secrets, - GError * error, + GVariant *secrets, + GError *error, gboolean cancelled, gboolean free_call_id) { @@ -314,7 +314,7 @@ void nm_secret_agent_add_permission(NMSecretAgent *agent, const char *permission, gboolean allowed) { NMSecretAgentPrivate *priv; - NMCListElem * elem; + NMCListElem *elem; g_return_if_fail(agent != NULL); g_return_if_fail(permission != NULL); @@ -361,10 +361,10 @@ nm_secret_agent_has_permission(NMSecretAgent *agent, const char *permission) static void _dbus_call_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - NMSecretAgentCallId *call_id; + NMSecretAgentCallId *call_id; gs_unref_variant GVariant *ret = NULL; gs_unref_variant GVariant *secrets = NULL; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; ret = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), result, &error); @@ -387,18 +387,18 @@ _dbus_call_cb(GObject *source, GAsyncResult *result, gpointer user_data) /*****************************************************************************/ NMSecretAgentCallId * -nm_secret_agent_get_secrets(NMSecretAgent * self, - const char * path, - NMConnection * connection, - const char * setting_name, - const char ** hints, +nm_secret_agent_get_secrets(NMSecretAgent *self, + const char *path, + NMConnection *connection, + const char *setting_name, + const char **hints, NMSecretAgentGetSecretsFlags flags, NMSecretAgentCallback callback, gpointer callback_data) { NMSecretAgentPrivate *priv; - GVariant * dict; - NMSecretAgentCallId * call_id; + GVariant *dict; + NMSecretAgentCallId *call_id; g_return_val_if_fail(NM_IS_SECRET_AGENT(self), NULL); g_return_val_if_fail(NM_IS_CONNECTION(connection), NULL); @@ -442,9 +442,9 @@ nm_secret_agent_get_secrets(NMSecretAgent * self, static void _call_cancel_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - NMSecretAgentCallId *call_id = user_data; - gs_free_error GError *error = NULL; - gs_unref_variant GVariant *ret = NULL; + NMSecretAgentCallId *call_id = user_data; + gs_free_error GError *error = NULL; + gs_unref_variant GVariant *ret = NULL; ret = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), result, &error); @@ -526,15 +526,15 @@ nm_secret_agent_cancel_call(NMSecretAgent *self, NMSecretAgentCallId *call_id) /*****************************************************************************/ NMSecretAgentCallId * -nm_secret_agent_save_secrets(NMSecretAgent * self, - const char * path, - NMConnection * connection, +nm_secret_agent_save_secrets(NMSecretAgent *self, + const char *path, + NMConnection *connection, NMSecretAgentCallback callback, gpointer callback_data) { NMSecretAgentPrivate *priv; - GVariant * dict; - NMSecretAgentCallId * call_id; + GVariant *dict; + NMSecretAgentCallId *call_id; g_return_val_if_fail(NM_IS_SECRET_AGENT(self), NULL); g_return_val_if_fail(NM_IS_CONNECTION(connection), NULL); @@ -566,15 +566,15 @@ nm_secret_agent_save_secrets(NMSecretAgent * self, /*****************************************************************************/ NMSecretAgentCallId * -nm_secret_agent_delete_secrets(NMSecretAgent * self, - const char * path, - NMConnection * connection, +nm_secret_agent_delete_secrets(NMSecretAgent *self, + const char *path, + NMConnection *connection, NMSecretAgentCallback callback, gpointer callback_data) { NMSecretAgentPrivate *priv; - GVariant * dict; - NMSecretAgentCallId * call_id; + GVariant *dict; + NMSecretAgentCallId *call_id; g_return_val_if_fail(NM_IS_SECRET_AGENT(self), NULL); g_return_val_if_fail(NM_IS_CONNECTION(connection), NULL); @@ -626,15 +626,15 @@ name_owner_changed(NMSecretAgent *self, const char *owner) static void name_owner_changed_cb(GDBusConnection *dbus_connection, - const char * sender_name, - const char * object_path, - const char * interface_name, - const char * signal_name, - GVariant * parameters, + const char *sender_name, + const char *object_path, + const char *interface_name, + const char *signal_name, + GVariant *parameters, gpointer user_data) { NMSecretAgent *self = NM_SECRET_AGENT(user_data); - const char * new_owner = NULL; + const char *new_owner = NULL; if (g_variant_is_of_type(parameters, G_VARIANT_TYPE("(sss)"))) { g_variant_get(parameters, "(&s&s&s)", NULL, NULL, &new_owner); @@ -663,20 +663,20 @@ get_name_owner_cb(const char *name_owner, GError *error, gpointer user_data) /*****************************************************************************/ NMSecretAgent * -nm_secret_agent_new(GDBusMethodInvocation * context, - NMAuthSubject * subject, - const char * identifier, +nm_secret_agent_new(GDBusMethodInvocation *context, + NMAuthSubject *subject, + const char *identifier, NMSecretAgentCapabilities capabilities) { - NMSecretAgent * self; + NMSecretAgent *self; NMSecretAgentPrivate *priv; - const char * dbus_owner; - gs_free char * owner_username = NULL; - char * description = NULL; + const char *dbus_owner; + gs_free char *owner_username = NULL; + char *description = NULL; char buf_subject[64]; char buf_caps[150]; gulong uid; - GDBusConnection * dbus_connection; + GDBusConnection *dbus_connection; g_return_val_if_fail(context != NULL, NULL); g_return_val_if_fail(NM_IS_AUTH_SUBJECT(subject), NULL); @@ -750,7 +750,7 @@ nm_secret_agent_init(NMSecretAgent *self) static void dispose(GObject *object) { - NMSecretAgent * self = NM_SECRET_AGENT(object); + NMSecretAgent *self = NM_SECRET_AGENT(object); NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE(self); nm_assert(c_list_is_empty(&self->agent_lst)); @@ -767,7 +767,7 @@ dispose(GObject *object) static void finalize(GObject *object) { - NMSecretAgent * self = NM_SECRET_AGENT(object); + NMSecretAgent *self = NM_SECRET_AGENT(object); NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE(self); g_free(priv->description); diff --git a/src/core/settings/nm-secret-agent.h b/src/core/settings/nm-secret-agent.h index ce591425..14458b38 100644 --- a/src/core/settings/nm-secret-agent.h +++ b/src/core/settings/nm-secret-agent.h @@ -31,16 +31,16 @@ struct _NMSecretAgentPrivate; struct _NMSecretAgent { GObject parent; CList agent_lst; - struct _NMAuthChain * auth_chain; + struct _NMAuthChain *auth_chain; struct _NMSecretAgentPrivate *_priv; bool fully_registered : 1; }; GType nm_secret_agent_get_type(void); -NMSecretAgent *nm_secret_agent_new(GDBusMethodInvocation * context, - NMAuthSubject * subject, - const char * identifier, +NMSecretAgent *nm_secret_agent_new(GDBusMethodInvocation *context, + NMAuthSubject *subject, + const char *identifier, NMSecretAgentCapabilities capabilities); const char *nm_secret_agent_get_description(NMSecretAgent *agent); @@ -63,30 +63,30 @@ void nm_secret_agent_add_permission(NMSecretAgent *agent, const char *permission gboolean nm_secret_agent_has_permission(NMSecretAgent *agent, const char *permission); -typedef void (*NMSecretAgentCallback)(NMSecretAgent * agent, +typedef void (*NMSecretAgentCallback)(NMSecretAgent *agent, NMSecretAgentCallId *call_id, - GVariant * new_secrets, /* NULL for save & delete */ - GError * error, + GVariant *new_secrets, /* NULL for save & delete */ + GError *error, gpointer user_data); -NMSecretAgentCallId *nm_secret_agent_get_secrets(NMSecretAgent * agent, - const char * path, - NMConnection * connection, - const char * setting_name, - const char ** hints, +NMSecretAgentCallId *nm_secret_agent_get_secrets(NMSecretAgent *agent, + const char *path, + NMConnection *connection, + const char *setting_name, + const char **hints, NMSecretAgentGetSecretsFlags flags, NMSecretAgentCallback callback, gpointer callback_data); -NMSecretAgentCallId *nm_secret_agent_save_secrets(NMSecretAgent * agent, - const char * path, - NMConnection * connection, +NMSecretAgentCallId *nm_secret_agent_save_secrets(NMSecretAgent *agent, + const char *path, + NMConnection *connection, NMSecretAgentCallback callback, gpointer callback_data); -NMSecretAgentCallId *nm_secret_agent_delete_secrets(NMSecretAgent * agent, - const char * path, - NMConnection * connection, +NMSecretAgentCallId *nm_secret_agent_delete_secrets(NMSecretAgent *agent, + const char *path, + NMConnection *connection, NMSecretAgentCallback callback, gpointer callback_data); diff --git a/src/core/settings/nm-settings-connection.c b/src/core/settings/nm-settings-connection.c index 71da97d0..55efaebe 100644 --- a/src/core/settings/nm-settings-connection.c +++ b/src/core/settings/nm-settings-connection.c @@ -135,7 +135,7 @@ typedef struct _NMSettingsConnectionPrivate { struct { NMConnectionSerializationOptions options; - GVariant * variant; + GVariant *variant; } getsettings_cached; NMSettingsStorage *storage; @@ -223,7 +223,7 @@ static const NMDBusInterfaceInfoExtended interface_info_settings_connection; static void update_agent_secrets_cache(NMSettingsConnection *self, NMConnection *new); static guint _get_seen_bssids(NMSettingsConnection *self, - const char * strv_buf[static(SEEN_BSSIDS_MAX + 1)]); + const char *strv_buf[static(SEEN_BSSIDS_MAX + 1)]); /*****************************************************************************/ @@ -264,7 +264,7 @@ void _nm_settings_connection_set_storage(NMSettingsConnection *self, NMSettingsStorage *storage) { NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); - const char * filename; + const char *filename; nm_assert(NM_IS_SETTINGS_STORAGE(storage)); nm_assert(!priv->storage @@ -316,7 +316,7 @@ static GVariant * _getsettings_cached_get(NMSettingsConnection *self, const NMConnectionSerializationOptions *options) { NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); - GVariant * variant; + GVariant *variant; if (priv->getsettings_cached.variant) { if (nm_connection_serialization_options_equal(&priv->getsettings_cached.options, options)) { @@ -362,12 +362,12 @@ nm_settings_connection_get_connection(NMSettingsConnection *self) } void -_nm_settings_connection_set_connection(NMSettingsConnection * self, - NMConnection * new_connection, - NMConnection ** out_connection_old, +_nm_settings_connection_set_connection(NMSettingsConnection *self, + NMConnection *new_connection, + NMConnection **out_connection_old, NMSettingsConnectionUpdateReason update_reason) { - NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); gs_unref_object NMConnection *connection_old = NULL; nm_assert(NM_IS_CONNECTION(new_connection)); @@ -408,7 +408,7 @@ _nm_settings_connection_set_connection(NMSettingsConnection * self, gboolean nm_settings_connection_has_unmodified_applied_connection(NMSettingsConnection *self, - NMConnection * applied_connection, + NMConnection *applied_connection, NMSettingCompareFlags compare_flags) { g_return_val_if_fail(NM_IS_SETTINGS_CONNECTION(self), FALSE); @@ -437,7 +437,7 @@ nm_settings_connection_get_last_secret_agent_version_id(NMSettingsConnection *se gboolean nm_settings_connection_check_visibility(NMSettingsConnection *self, - NMSessionMonitor * session_monitor) + NMSessionMonitor *session_monitor) { NMSettingConnection *s_con; guint32 num, i; @@ -483,9 +483,9 @@ gboolean nm_settings_connection_check_permission(NMSettingsConnection *self, const char *permission) { NMSettingsConnectionPrivate *priv; - NMSettingConnection * s_con; + NMSettingConnection *s_con; guint32 num, i; - const char * puser; + const char *puser; g_return_val_if_fail(NM_IS_SETTINGS_CONNECTION(self), FALSE); @@ -531,8 +531,8 @@ nm_settings_connection_check_permission(NMSettingsConnection *self, const char * static void update_agent_secrets_cache(NMSettingsConnection *self, NMConnection *new) { - NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); - gs_unref_variant GVariant *old_secrets = NULL; + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); + gs_unref_variant GVariant *old_secrets = NULL; old_secrets = g_steal_pointer(&priv->agent_secrets); @@ -552,11 +552,11 @@ update_agent_secrets_cache(NMSettingsConnection *self, NMConnection *new) } static gboolean -_secrets_update(NMConnection * connection, - const char * setting_name, - GVariant * secrets, +_secrets_update(NMConnection *connection, + const char *setting_name, + GVariant *secrets, NMConnection **out_new_connection, - GError ** error) + GError **error) { gs_unref_variant GVariant *secrets_setting = NULL; @@ -605,14 +605,14 @@ _secrets_update(NMConnection * connection, } gboolean -nm_settings_connection_update(NMSettingsConnection * self, - NMConnection * new_connection, +nm_settings_connection_update(NMSettingsConnection *self, + NMConnection *new_connection, NMSettingsConnectionPersistMode persist_mode, NMSettingsConnectionIntFlags sett_flags, NMSettingsConnectionIntFlags sett_mask, NMSettingsConnectionUpdateReason update_reason, - const char * log_context_name, - GError ** error) + const char *log_context_name, + GError **error) { g_return_val_if_fail(NM_IS_SETTINGS_CONNECTION(self), FALSE); @@ -645,10 +645,10 @@ typedef enum { } CallIdType; struct _NMSettingsConnectionCallId { - NMSettingsConnection * self; + NMSettingsConnection *self; CList call_ids_lst; gboolean had_applied_connection; - NMConnection * applied_connection; + NMConnection *applied_connection; NMSettingsConnectionSecretsFunc callback; gpointer callback_data; @@ -666,9 +666,9 @@ struct _NMSettingsConnectionCallId { static void _get_secrets_info_callback(NMSettingsConnectionCallId *call_id, - const char * agent_username, - const char * setting_name, - GError * error) + const char *agent_username, + const char *setting_name, + GError *error) { if (call_id->callback) { call_id->callback(call_id->self, @@ -731,16 +731,16 @@ secret_is_system_owned(NMSettingSecretFlags flags, gpointer user_data) } static void -get_cmp_flags(NMSettingsConnection * self, /* only needed for logging */ - NMSettingsConnectionCallId * call_id, /* only needed for logging */ - NMConnection * connection, - const char * agent_dbus_owner, +get_cmp_flags(NMSettingsConnection *self, /* only needed for logging */ + NMSettingsConnectionCallId *call_id, /* only needed for logging */ + NMConnection *connection, + const char *agent_dbus_owner, gboolean agent_has_modify, - const char * setting_name, /* only needed for logging */ + const char *setting_name, /* only needed for logging */ NMSecretAgentGetSecretsFlags flags, - GVariant * secrets, - gboolean * agent_had_system, - ForEachSecretFlags * cmp_flags) + GVariant *secrets, + gboolean *agent_had_system, + ForEachSecretFlags *cmp_flags) { gboolean is_self = (nm_settings_connection_get_connection(self) == connection); @@ -810,13 +810,13 @@ get_cmp_flags(NMSettingsConnection * self, /* only needed for logging * gboolean nm_settings_connection_new_secrets(NMSettingsConnection *self, - NMConnection * applied_connection, - const char * setting_name, - GVariant * secrets, - GError ** error) + NMConnection *applied_connection, + const char *setting_name, + GVariant *secrets, + GError **error) { gs_unref_object NMConnection *new_connection = NULL; - NMConnection * connection; + NMConnection *connection; if (!nm_settings_connection_has_unmodified_applied_connection(self, applied_connection, @@ -849,8 +849,8 @@ nm_settings_connection_new_secrets(NMSettingsConnection *self, } static gboolean -match_secret_by_setting_name_and_flags_cb(NMSetting * setting, - const char * secret, +match_secret_by_setting_name_and_flags_cb(NMSetting *setting, + const char *secret, NMSettingSecretFlags flags, gpointer user_data) { @@ -861,22 +861,22 @@ match_secret_by_setting_name_and_flags_cb(NMSetting * setting, } static void -get_secrets_done_cb(NMAgentManager * manager, +get_secrets_done_cb(NMAgentManager *manager, NMAgentManagerCallId call_id_a, - const char * agent_dbus_owner, - const char * agent_username, + const char *agent_dbus_owner, + const char *agent_username, gboolean agent_has_modify, - const char * setting_name, + const char *setting_name, NMSecretAgentGetSecretsFlags flags, - GVariant * secrets, - GError * error, + GVariant *secrets, + GError *error, gpointer user_data) { - NMSettingsConnectionCallId * call_id = user_data; - NMSettingsConnection * self; - NMSettingsConnectionPrivate *priv; - NMConnection * applied_connection; - gs_free_error GError *local = NULL; + NMSettingsConnectionCallId *call_id = user_data; + NMSettingsConnection *self; + NMSettingsConnectionPrivate *priv; + NMConnection *applied_connection; + gs_free_error GError *local = NULL; gs_unref_object NMConnection *new_connection = NULL; gboolean agent_had_system = FALSE; ForEachSecretFlags cmp_flags = {NM_SETTING_SECRET_FLAG_NONE, NM_SETTING_SECRET_FLAG_NONE}; @@ -1068,21 +1068,21 @@ get_secrets_idle_cb(NMSettingsConnectionCallId *call_id) * Returns: a call ID which may be used to cancel the ongoing secrets request. **/ NMSettingsConnectionCallId * -nm_settings_connection_get_secrets(NMSettingsConnection * self, - NMConnection * applied_connection, - NMAuthSubject * subject, - const char * setting_name, +nm_settings_connection_get_secrets(NMSettingsConnection *self, + NMConnection *applied_connection, + NMAuthSubject *subject, + const char *setting_name, NMSecretAgentGetSecretsFlags flags, - const char *const * hints, + const char *const *hints, NMSettingsConnectionSecretsFunc callback, gpointer callback_data) { NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); NMAgentManagerCallId call_id_a; - gs_free char * joined_hints = NULL; - NMSettingsConnectionCallId * call_id; - GError * local = NULL; - gs_unref_variant GVariant *system_secrets = NULL; + gs_free char *joined_hints = NULL; + NMSettingsConnectionCallId *call_id; + GError *local = NULL; + gs_unref_variant GVariant *system_secrets = NULL; g_return_val_if_fail(NM_IS_SETTINGS_CONNECTION(self), NULL); g_return_val_if_fail( @@ -1168,12 +1168,12 @@ schedule_dummy: } static void -_get_secrets_cancel(NMSettingsConnection * self, +_get_secrets_cancel(NMSettingsConnection *self, NMSettingsConnectionCallId *call_id, gboolean is_disposing) { - NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); - gs_free_error GError *error = NULL; + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); + gs_free_error GError *error = NULL; nm_assert(c_list_contains(&priv->call_ids_lst_head, &call_id->call_ids_lst)); @@ -1192,7 +1192,7 @@ _get_secrets_cancel(NMSettingsConnection * self, } void -nm_settings_connection_cancel_secrets(NMSettingsConnection * self, +nm_settings_connection_cancel_secrets(NMSettingsConnection *self, NMSettingsConnectionCallId *call_id) { _LOGD("(%p) secrets canceled", call_id); @@ -1202,31 +1202,31 @@ nm_settings_connection_cancel_secrets(NMSettingsConnection * self, /*****************************************************************************/ -typedef void (*AuthCallback)(NMSettingsConnection * self, +typedef void (*AuthCallback)(NMSettingsConnection *self, GDBusMethodInvocation *context, - NMAuthSubject * subject, - GError * error, + NMAuthSubject *subject, + GError *error, gpointer data); typedef struct { CList auth_lst; - NMAuthManagerCallId * call_id; - NMSettingsConnection * self; + NMAuthManagerCallId *call_id; + NMSettingsConnection *self; AuthCallback callback; gpointer callback_data; GDBusMethodInvocation *invocation; - NMAuthSubject * subject; + NMAuthSubject *subject; } AuthData; static void -pk_auth_cb(NMAuthManager * auth_manager, +pk_auth_cb(NMAuthManager *auth_manager, NMAuthManagerCallId *auth_call_id, gboolean is_authorized, gboolean is_challenge, - GError * auth_error, + GError *auth_error, gpointer user_data) { - AuthData * auth_data = user_data; + AuthData *auth_data = user_data; NMSettingsConnection *self; gs_free_error GError *error = NULL; @@ -1293,16 +1293,16 @@ _new_auth_subject(GDBusMethodInvocation *context, GError **error) /* may either invoke callback synchronously or asynchronously. */ static void -auth_start(NMSettingsConnection * self, +auth_start(NMSettingsConnection *self, GDBusMethodInvocation *invocation, - NMAuthSubject * subject, - const char * check_permission, + NMAuthSubject *subject, + const char *check_permission, AuthCallback callback, gpointer callback_data) { NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); - AuthData * auth_data; - GError * error = NULL; + AuthData *auth_data; + GError *error = NULL; nm_assert(nm_dbus_object_is_exported(NM_DBUS_OBJECT(self))); nm_assert(G_IS_DBUS_METHOD_INVOCATION(invocation)); @@ -1342,13 +1342,13 @@ auth_start(NMSettingsConnection * self, /**** DBus method handlers ************************************/ static void -get_settings_auth_cb(NMSettingsConnection * self, +get_settings_auth_cb(NMSettingsConnection *self, GDBusMethodInvocation *context, - NMAuthSubject * subject, - GError * error, + NMAuthSubject *subject, + GError *error, gpointer data) { - const char * seen_bssids_strv[SEEN_BSSIDS_MAX + 1]; + const char *seen_bssids_strv[SEEN_BSSIDS_MAX + 1]; NMConnectionSerializationOptions options = {}; if (error) { @@ -1381,17 +1381,17 @@ get_settings_auth_cb(NMSettingsConnection * self, } static void -impl_settings_connection_get_settings(NMDBusObject * obj, +impl_settings_connection_get_settings(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMSettingsConnection *self = NM_SETTINGS_CONNECTION(obj); + NMSettingsConnection *self = NM_SETTINGS_CONNECTION(obj); gs_unref_object NMAuthSubject *subject = NULL; - GError * error = NULL; + GError *error = NULL; subject = _new_auth_subject(invocation, &error); if (!subject) { @@ -1404,11 +1404,11 @@ impl_settings_connection_get_settings(NMDBusObject * obj, typedef struct { GDBusMethodInvocation *context; - NMAgentManager * agent_mgr; - NMAuthSubject * subject; - NMConnection * new_settings; + NMAgentManager *agent_mgr; + NMAuthSubject *subject; + NMConnection *new_settings; NMSettingsUpdate2Flags flags; - char * audit_args; + char *audit_args; bool is_update2 : 1; } UpdateInfo; @@ -1486,15 +1486,15 @@ _autoconnect_retries_set(NMSettingsConnection *self, int retries, gboolean is_re } static void -update_auth_cb(NMSettingsConnection * self, +update_auth_cb(NMSettingsConnection *self, GDBusMethodInvocation *context, - NMAuthSubject * subject, - GError * error, + NMAuthSubject *subject, + GError *error, gpointer data) { - NMSettingsConnectionPrivate *priv; - UpdateInfo * info = data; - gs_free_error GError * local = NULL; + NMSettingsConnectionPrivate *priv; + UpdateInfo *info = data; + gs_free_error GError *local = NULL; NMSettingsConnectionPersistMode persist_mode; if (error) { @@ -1638,18 +1638,18 @@ get_update_modify_permission(NMConnection *old, NMConnection *new) } static void -settings_connection_update(NMSettingsConnection * self, +settings_connection_update(NMSettingsConnection *self, gboolean is_update2, GDBusMethodInvocation *context, - GVariant * new_settings, + GVariant *new_settings, NMSettingsUpdate2Flags flags) { NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); - NMAuthSubject * subject = NULL; - NMConnection * tmp = NULL; - GError * error = NULL; - UpdateInfo * info; - const char * permission; + NMAuthSubject *subject = NULL; + NMConnection *tmp = NULL; + GError *error = NULL; + UpdateInfo *info; + const char *permission; /* Check if the settings are valid first */ if (new_settings) { @@ -1712,15 +1712,15 @@ error: } static void -impl_settings_connection_update(NMDBusObject * obj, +impl_settings_connection_update(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMSettingsConnection *self = NM_SETTINGS_CONNECTION(obj); + NMSettingsConnection *self = NM_SETTINGS_CONNECTION(obj); gs_unref_variant GVariant *settings = NULL; g_variant_get(parameters, "(@a{sa{sv}})", &settings); @@ -1728,15 +1728,15 @@ impl_settings_connection_update(NMDBusObject * obj, } static void -impl_settings_connection_update_unsaved(NMDBusObject * obj, +impl_settings_connection_update_unsaved(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMSettingsConnection *self = NM_SETTINGS_CONNECTION(obj); + NMSettingsConnection *self = NM_SETTINGS_CONNECTION(obj); gs_unref_variant GVariant *settings = NULL; g_variant_get(parameters, "(@a{sa{sv}})", &settings); @@ -1748,13 +1748,13 @@ impl_settings_connection_update_unsaved(NMDBusObject * obj, } static void -impl_settings_connection_save(NMDBusObject * obj, +impl_settings_connection_save(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { NMSettingsConnection *self = NM_SETTINGS_CONNECTION(obj); @@ -1762,21 +1762,21 @@ impl_settings_connection_save(NMDBusObject * obj, } static void -impl_settings_connection_update2(NMDBusObject * obj, +impl_settings_connection_update2(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMSettingsConnection *self = NM_SETTINGS_CONNECTION(obj); + NMSettingsConnection *self = NM_SETTINGS_CONNECTION(obj); gs_unref_variant GVariant *settings = NULL; gs_unref_variant GVariant *args = NULL; guint32 flags_u; - GError * error = NULL; + GError *error = NULL; GVariantIter iter; - const char * args_name; + const char *args_name; NMSettingsUpdate2Flags flags; g_variant_get(parameters, "(@a{sa{sv}}u@a{sv})", &settings, &flags_u, &args); @@ -1825,10 +1825,10 @@ impl_settings_connection_update2(NMDBusObject * obj, } static void -delete_auth_cb(NMSettingsConnection * self, +delete_auth_cb(NMSettingsConnection *self, GDBusMethodInvocation *context, - NMAuthSubject * subject, - GError * error, + NMAuthSubject *subject, + GError *error, gpointer data) { gs_unref_object NMSettingsConnection *self_keep_alive = NULL; @@ -1869,17 +1869,17 @@ get_modify_permission_basic(NMSettingsConnection *self) } static void -impl_settings_connection_delete(NMDBusObject * obj, +impl_settings_connection_delete(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMSettingsConnection *self = NM_SETTINGS_CONNECTION(obj); + NMSettingsConnection *self = NM_SETTINGS_CONNECTION(obj); gs_unref_object NMAuthSubject *subject = NULL; - GError * error = NULL; + GError *error = NULL; nm_assert(nm_settings_connection_still_valid(self)); @@ -1897,15 +1897,15 @@ err: /*****************************************************************************/ static void -dbus_get_agent_secrets_cb(NMSettingsConnection * self, +dbus_get_agent_secrets_cb(NMSettingsConnection *self, NMSettingsConnectionCallId *call_id, - const char * agent_username, - const char * setting_name, - GError * error, + const char *agent_username, + const char *setting_name, + GError *error, gpointer user_data) { GDBusMethodInvocation *context = user_data; - GVariant * dict; + GVariant *dict; if (error) g_dbus_method_invocation_return_gerror(context, error); @@ -1924,10 +1924,10 @@ dbus_get_agent_secrets_cb(NMSettingsConnection * self, } static void -dbus_get_secrets_auth_cb(NMSettingsConnection * self, +dbus_get_secrets_auth_cb(NMSettingsConnection *self, GDBusMethodInvocation *context, - NMAuthSubject * subject, - GError * error, + NMAuthSubject *subject, + GError *error, gpointer user_data) { char *setting_name = user_data; @@ -1951,18 +1951,18 @@ dbus_get_secrets_auth_cb(NMSettingsConnection * self, } static void -impl_settings_connection_get_secrets(NMDBusObject * obj, +impl_settings_connection_get_secrets(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMSettingsConnection *self = NM_SETTINGS_CONNECTION(obj); + NMSettingsConnection *self = NM_SETTINGS_CONNECTION(obj); gs_unref_object NMAuthSubject *subject = NULL; - GError * error = NULL; - const char * setting_name; + GError *error = NULL; + const char *setting_name; subject = _new_auth_subject(invocation, &error); if (!subject) { @@ -1981,14 +1981,14 @@ impl_settings_connection_get_secrets(NMDBusObject * obj, } static void -dbus_clear_secrets_auth_cb(NMSettingsConnection * self, +dbus_clear_secrets_auth_cb(NMSettingsConnection *self, GDBusMethodInvocation *context, - NMAuthSubject * subject, - GError * error, + NMAuthSubject *subject, + GError *error, gpointer user_data) { - NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); - gs_free_error GError *local = NULL; + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); + gs_free_error GError *local = NULL; gs_unref_object NMConnection *connection_cloned = NULL; if (error) { @@ -2040,17 +2040,17 @@ dbus_clear_secrets_auth_cb(NMSettingsConnection * self, } static void -impl_settings_connection_clear_secrets(NMDBusObject * obj, +impl_settings_connection_clear_secrets(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMSettingsConnection *self = NM_SETTINGS_CONNECTION(obj); + NMSettingsConnection *self = NM_SETTINGS_CONNECTION(obj); gs_unref_object NMAuthSubject *subject = NULL; - GError * error = NULL; + GError *error = NULL; subject = _new_auth_subject(invocation, &error); if (!subject) { @@ -2092,7 +2092,7 @@ _nm_settings_connection_emit_dbus_signal_removed(NMSettingsConnection *self) } void -_nm_settings_connection_emit_signal_updated_internal(NMSettingsConnection * self, +_nm_settings_connection_emit_signal_updated_internal(NMSettingsConnection *self, NMSettingsConnectionUpdateReason update_reason) { g_signal_emit(self, signals[UPDATED_INTERNAL], 0, (guint) update_reason); @@ -2119,7 +2119,7 @@ nm_settings_connection_get_flags(NMSettingsConnection *self) } NMSettingsConnectionIntFlags -nm_settings_connection_set_flags_full(NMSettingsConnection * self, +nm_settings_connection_set_flags_full(NMSettingsConnection *self, NMSettingsConnectionIntFlags mask, NMSettingsConnectionIntFlags value) { @@ -2285,7 +2285,7 @@ void nm_settings_connection_update_timestamp(NMSettingsConnection *self, guint64 timestamp) { NMSettingsConnectionPrivate *priv; - const char * connection_uuid; + const char *connection_uuid; char sbuf[60]; g_return_if_fail(NM_IS_SETTINGS_CONNECTION(self)); @@ -2315,11 +2315,11 @@ nm_settings_connection_update_timestamp(NMSettingsConnection *self, guint64 time void _nm_settings_connection_register_kf_dbs(NMSettingsConnection *self, - NMKeyFileDB * kf_db_timestamps, - NMKeyFileDB * kf_db_seen_bssids) + NMKeyFileDB *kf_db_timestamps, + NMKeyFileDB *kf_db_seen_bssids) { NMSettingsConnectionPrivate *priv; - const char * connection_uuid; + const char *connection_uuid; g_return_if_fail(NM_IS_SETTINGS_CONNECTION(self)); g_return_if_fail(kf_db_timestamps); @@ -2402,7 +2402,7 @@ static guint _get_seen_bssids(NMSettingsConnection *self, const char *strv_buf[static(SEEN_BSSIDS_MAX + 1)]) { NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); - SeenBssidEntry * entry; + SeenBssidEntry *entry; guint i; i = 0; @@ -2450,11 +2450,11 @@ void nm_settings_connection_add_seen_bssid(NMSettingsConnection *self, const char *seen_bssid) { NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); - const char * seen_bssids_strv[SEEN_BSSIDS_MAX + 1]; + const char *seen_bssids_strv[SEEN_BSSIDS_MAX + 1]; NMEtherAddr addr_bin; - const char * connection_uuid; + const char *connection_uuid; SeenBssidEntry entry_stack; - SeenBssidEntry * entry; + SeenBssidEntry *entry; guint i; g_return_if_fail(seen_bssid); @@ -2562,12 +2562,12 @@ nm_settings_connection_autoconnect_blocked_reason_get(NMSettingsConnection *self } gboolean -nm_settings_connection_autoconnect_blocked_reason_set_full(NMSettingsConnection * self, +nm_settings_connection_autoconnect_blocked_reason_set_full(NMSettingsConnection *self, NMSettingsAutoconnectBlockedReason mask, NMSettingsAutoconnectBlockedReason value) { NMSettingsAutoconnectBlockedReason v; - NMSettingsConnectionPrivate * priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); char buf[100]; nm_assert(mask); @@ -2641,7 +2641,7 @@ const char * nm_settings_connection_get_uuid(NMSettingsConnection *self) { NMSettingsConnectionPrivate *priv; - const char * uuid; + const char *uuid; g_return_val_if_fail(NM_IS_SETTINGS_CONNECTION(self), NULL); @@ -2668,7 +2668,7 @@ void _nm_settings_connection_cleanup_after_remove(NMSettingsConnection *self) { NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); - AuthData * auth_data; + AuthData *auth_data; while ((auth_data = c_list_first_entry(&priv->auth_lst_head, AuthData, auth_lst))) nm_auth_manager_check_authorization_cancel(auth_data->call_id); @@ -2730,9 +2730,9 @@ nm_settings_connection_new(void) static void dispose(GObject *object) { - NMSettingsConnection * self = NM_SETTINGS_CONNECTION(object); + NMSettingsConnection *self = NM_SETTINGS_CONNECTION(object); NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); - NMSettingsConnectionCallId * call_id, *call_id_safe; + NMSettingsConnectionCallId *call_id, *call_id_safe; _LOGD("disposing"); @@ -2837,7 +2837,7 @@ static const NMDBusInterfaceInfoExtended interface_info_settings_connection = { static void nm_settings_connection_class_init(NMSettingsConnectionClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); g_type_class_add_private(klass, sizeof(NMSettingsConnectionPrivate)); diff --git a/src/core/settings/nm-settings-connection.h b/src/core/settings/nm-settings-connection.h index fa3dbcfb..5f8a22e8 100644 --- a/src/core/settings/nm-settings-connection.h +++ b/src/core/settings/nm-settings-connection.h @@ -219,9 +219,9 @@ NMSettingsConnection *nm_settings_connection_new(void); NMConnection *nm_settings_connection_get_connection(NMSettingsConnection *self); -void _nm_settings_connection_set_connection(NMSettingsConnection * self, - NMConnection * new_connection, - NMConnection ** out_old_connection, +void _nm_settings_connection_set_connection(NMSettingsConnection *self, + NMConnection *new_connection, + NMConnection **out_old_connection, NMSettingsConnectionUpdateReason update_reason); NMSettingsStorage *nm_settings_connection_get_storage(NMSettingsConnection *self); @@ -236,52 +236,52 @@ guint64 nm_settings_connection_get_last_secret_agent_version_id(NMSettingsConnec gboolean nm_settings_connection_has_unmodified_applied_connection(NMSettingsConnection *self, - NMConnection * applied_connection, + NMConnection *applied_connection, NMSettingCompareFlags compare_flage); -gboolean nm_settings_connection_update(NMSettingsConnection * self, - NMConnection * new_connection, +gboolean nm_settings_connection_update(NMSettingsConnection *self, + NMConnection *new_connection, NMSettingsConnectionPersistMode persist_mode, NMSettingsConnectionIntFlags sett_flags, NMSettingsConnectionIntFlags sett_mask, NMSettingsConnectionUpdateReason update_reason, - const char * log_context_name, - GError ** error); + const char *log_context_name, + GError **error); void nm_settings_connection_delete(NMSettingsConnection *self, gboolean allow_add_to_no_auto_default); -typedef void (*NMSettingsConnectionSecretsFunc)(NMSettingsConnection * self, +typedef void (*NMSettingsConnectionSecretsFunc)(NMSettingsConnection *self, NMSettingsConnectionCallId *call_id, - const char * agent_username, - const char * setting_name, - GError * error, + const char *agent_username, + const char *setting_name, + GError *error, gpointer user_data); gboolean nm_settings_connection_new_secrets(NMSettingsConnection *self, - NMConnection * applied_connection, - const char * setting_name, - GVariant * secrets, - GError ** error); + NMConnection *applied_connection, + const char *setting_name, + GVariant *secrets, + GError **error); NMSettingsConnectionCallId * -nm_settings_connection_get_secrets(NMSettingsConnection * self, - NMConnection * applied_connection, - NMAuthSubject * subject, - const char * setting_name, +nm_settings_connection_get_secrets(NMSettingsConnection *self, + NMConnection *applied_connection, + NMAuthSubject *subject, + const char *setting_name, NMSecretAgentGetSecretsFlags flags, - const char *const * hints, + const char *const *hints, NMSettingsConnectionSecretsFunc callback, gpointer callback_data); -void nm_settings_connection_cancel_secrets(NMSettingsConnection * self, +void nm_settings_connection_cancel_secrets(NMSettingsConnection *self, NMSettingsConnectionCallId *call_id); gboolean nm_settings_connection_check_visibility(NMSettingsConnection *self, - NMSessionMonitor * session_monitor); + NMSessionMonitor *session_monitor); gboolean nm_settings_connection_check_permission(NMSettingsConnection *self, - const char * permission); + const char *permission); /*****************************************************************************/ @@ -300,12 +300,12 @@ nm_settings_connection_get_unsaved(NMSettingsConnection *self) } NMSettingsConnectionIntFlags -nm_settings_connection_set_flags_full(NMSettingsConnection * self, +nm_settings_connection_set_flags_full(NMSettingsConnection *self, NMSettingsConnectionIntFlags mask, NMSettingsConnectionIntFlags value); static inline NMSettingsConnectionIntFlags -nm_settings_connection_set_flags(NMSettingsConnection * self, +nm_settings_connection_set_flags(NMSettingsConnection *self, NMSettingsConnectionIntFlags flags, gboolean set) { @@ -333,8 +333,8 @@ int nm_settings_connection_cmp_autoconnect_priority_p_with_data(gconstpointer pa struct _NMKeyFileDB; void _nm_settings_connection_register_kf_dbs(NMSettingsConnection *self, - struct _NMKeyFileDB * kf_db_timestamps, - struct _NMKeyFileDB * kf_db_seen_bssids); + struct _NMKeyFileDB *kf_db_timestamps, + struct _NMKeyFileDB *kf_db_seen_bssids); gboolean nm_settings_connection_get_timestamp(NMSettingsConnection *self, guint64 *out_timestamp); @@ -353,12 +353,12 @@ gint32 nm_settings_connection_autoconnect_retries_blocked_until(NMSettingsConnec NMSettingsAutoconnectBlockedReason nm_settings_connection_autoconnect_blocked_reason_get(NMSettingsConnection *self); gboolean nm_settings_connection_autoconnect_blocked_reason_set_full( - NMSettingsConnection * self, + NMSettingsConnection *self, NMSettingsAutoconnectBlockedReason mask, NMSettingsAutoconnectBlockedReason value); static inline gboolean -nm_settings_connection_autoconnect_blocked_reason_set(NMSettingsConnection * self, +nm_settings_connection_autoconnect_blocked_reason_set(NMSettingsConnection *self, NMSettingsAutoconnectBlockedReason mask, gboolean set) { @@ -386,7 +386,7 @@ void _nm_settings_connection_emit_dbus_signal_updated(NMSettingsConnection *self void _nm_settings_connection_emit_dbus_signal_removed(NMSettingsConnection *self); void _nm_settings_connection_emit_signal_updated_internal( - NMSettingsConnection * self, + NMSettingsConnection *self, NMSettingsConnectionUpdateReason update_reason); void _nm_settings_connection_cleanup_after_remove(NMSettingsConnection *self); diff --git a/src/core/settings/nm-settings-plugin.c b/src/core/settings/nm-settings-plugin.c index 66cc19b6..60181759 100644 --- a/src/core/settings/nm-settings-plugin.c +++ b/src/core/settings/nm-settings-plugin.c @@ -31,7 +31,7 @@ G_DEFINE_TYPE(NMSettingsPlugin, nm_settings_plugin, G_TYPE_OBJECT) int nm_settings_plugin_cmp_by_priority(const NMSettingsPlugin *a, const NMSettingsPlugin *b, - const GSList * plugin_list) + const GSList *plugin_list) { nm_assert(NM_IS_SETTINGS_PLUGIN(a)); nm_assert(NM_IS_SETTINGS_PLUGIN(b)); @@ -81,7 +81,7 @@ nm_settings_plugin_get_unrecognized_specs(NMSettingsPlugin *self) } void -nm_settings_plugin_reload_connections(NMSettingsPlugin * self, +nm_settings_plugin_reload_connections(NMSettingsPlugin *self, NMSettingsPluginConnectionLoadCallback callback, gpointer user_data) { @@ -122,8 +122,8 @@ nm_settings_plugin_create_connection_load_entries(const char *const *filenames, } void -nm_settings_plugin_load_connections(NMSettingsPlugin * self, - NMSettingsPluginConnectionLoadEntry * entries, +nm_settings_plugin_load_connections(NMSettingsPlugin *self, + NMSettingsPluginConnectionLoadEntry *entries, gsize n_entries, NMSettingsPluginConnectionLoadCallback callback, gpointer user_data) @@ -150,11 +150,11 @@ nm_settings_plugin_load_connections_done(NMSettingsPlugin *self) } gboolean -nm_settings_plugin_add_connection(NMSettingsPlugin * self, - NMConnection * connection, +nm_settings_plugin_add_connection(NMSettingsPlugin *self, + NMConnection *connection, NMSettingsStorage **out_storage, - NMConnection ** out_connection, - GError ** error) + NMConnection **out_connection, + GError **error) { NMSettingsPluginClass *klass; @@ -180,12 +180,12 @@ nm_settings_plugin_add_connection(NMSettingsPlugin * self, } gboolean -nm_settings_plugin_update_connection(NMSettingsPlugin * self, - NMSettingsStorage * storage, - NMConnection * connection, +nm_settings_plugin_update_connection(NMSettingsPlugin *self, + NMSettingsStorage *storage, + NMConnection *connection, NMSettingsStorage **out_storage, - NMConnection ** out_connection, - GError ** error) + NMConnection **out_connection, + GError **error) { NMSettingsPluginClass *klass = NULL; @@ -215,9 +215,9 @@ nm_settings_plugin_update_connection(NMSettingsPlugin * self, } gboolean -nm_settings_plugin_delete_connection(NMSettingsPlugin * self, +nm_settings_plugin_delete_connection(NMSettingsPlugin *self, NMSettingsStorage *storage, - GError ** error) + GError **error) { NMSettingsPluginClass *klass = NULL; diff --git a/src/core/settings/nm-settings-plugin.h b/src/core/settings/nm-settings-plugin.h index a9b9b2ae..198447c0 100644 --- a/src/core/settings/nm-settings-plugin.h +++ b/src/core/settings/nm-settings-plugin.h @@ -13,14 +13,14 @@ typedef struct _NMSettingsPlugin NMSettingsPlugin; -typedef void (*NMSettingsPluginConnectionLoadCallback)(NMSettingsPlugin * self, +typedef void (*NMSettingsPluginConnectionLoadCallback)(NMSettingsPlugin *self, NMSettingsStorage *storage, - NMConnection * connection, + NMConnection *connection, gpointer user_data); typedef struct { const char *filename; - GError * error; + GError *error; bool handled : 1; } NMSettingsPluginConnectionLoadEntry; @@ -70,8 +70,8 @@ typedef struct { /* Requests that the plugin load/reload a set of filenames. */ - void (*load_connections)(NMSettingsPlugin * self, - NMSettingsPluginConnectionLoadEntry * entries, + void (*load_connections)(NMSettingsPlugin *self, + NMSettingsPluginConnectionLoadEntry *entries, gsize n_entries, NMSettingsPluginConnectionLoadCallback callback, gpointer user_data); @@ -79,28 +79,28 @@ typedef struct { /* Requests that the plugin reload all connection files from disk, * and emit signals reflecting new, changed, and removed connections. */ - void (*reload_connections)(NMSettingsPlugin * self, + void (*reload_connections)(NMSettingsPlugin *self, NMSettingsPluginConnectionLoadCallback callback, gpointer user_data); void (*load_connections_done)(NMSettingsPlugin *self); - gboolean (*add_connection)(NMSettingsPlugin * self, - NMConnection * connection, + gboolean (*add_connection)(NMSettingsPlugin *self, + NMConnection *connection, NMSettingsStorage **out_storage, - NMConnection ** out_connection, - GError ** error); + NMConnection **out_connection, + GError **error); - gboolean (*update_connection)(NMSettingsPlugin * self, - NMSettingsStorage * storage, - NMConnection * connection, + gboolean (*update_connection)(NMSettingsPlugin *self, + NMSettingsStorage *storage, + NMConnection *connection, NMSettingsStorage **out_storage, - NMConnection ** out_connection, - GError ** error); + NMConnection **out_connection, + GError **error); - gboolean (*delete_connection)(NMSettingsPlugin * self, + gboolean (*delete_connection)(NMSettingsPlugin *self, NMSettingsStorage *storage, - GError ** error); + GError **error); const char *plugin_name; @@ -137,37 +137,37 @@ nm_settings_plugin_get_plugin_name(NMSettingsPlugin *self) GSList *nm_settings_plugin_get_unmanaged_specs(NMSettingsPlugin *self); GSList *nm_settings_plugin_get_unrecognized_specs(NMSettingsPlugin *self); -void nm_settings_plugin_reload_connections(NMSettingsPlugin * self, +void nm_settings_plugin_reload_connections(NMSettingsPlugin *self, NMSettingsPluginConnectionLoadCallback callback, gpointer user_data); NMSettingsPluginConnectionLoadEntry * nm_settings_plugin_create_connection_load_entries(const char *const *filenames, gsize *out_len); -void nm_settings_plugin_load_connections(NMSettingsPlugin * self, - NMSettingsPluginConnectionLoadEntry * entries, +void nm_settings_plugin_load_connections(NMSettingsPlugin *self, + NMSettingsPluginConnectionLoadEntry *entries, gsize n_entries, NMSettingsPluginConnectionLoadCallback callback, gpointer user_data); void nm_settings_plugin_load_connections_done(NMSettingsPlugin *self); -gboolean nm_settings_plugin_add_connection(NMSettingsPlugin * self, - NMConnection * connection, +gboolean nm_settings_plugin_add_connection(NMSettingsPlugin *self, + NMConnection *connection, NMSettingsStorage **out_storage, - NMConnection ** out_connection, - GError ** error); + NMConnection **out_connection, + GError **error); -gboolean nm_settings_plugin_update_connection(NMSettingsPlugin * self, - NMSettingsStorage * storage, - NMConnection * connection, +gboolean nm_settings_plugin_update_connection(NMSettingsPlugin *self, + NMSettingsStorage *storage, + NMConnection *connection, NMSettingsStorage **out_storage, - NMConnection ** out_connection, - GError ** error); + NMConnection **out_connection, + GError **error); -gboolean nm_settings_plugin_delete_connection(NMSettingsPlugin * self, +gboolean nm_settings_plugin_delete_connection(NMSettingsPlugin *self, NMSettingsStorage *storage, - GError ** error); + GError **error); /*****************************************************************************/ @@ -187,7 +187,7 @@ void _nm_settings_plugin_emit_signal_unrecognized_specs_changed(NMSettingsPlugin int nm_settings_plugin_cmp_by_priority(const NMSettingsPlugin *a, const NMSettingsPlugin *b, - const GSList * plugin_list); + const GSList *plugin_list); /*****************************************************************************/ diff --git a/src/core/settings/nm-settings-storage.h b/src/core/settings/nm-settings-storage.h index 2e5e1c55..198b0e8b 100644 --- a/src/core/settings/nm-settings-storage.h +++ b/src/core/settings/nm-settings-storage.h @@ -30,8 +30,8 @@ struct _NMSettingsPlugin; typedef struct NMSettingsStorage { GObject parent; struct _NMSettingsPlugin *_plugin; - char * _uuid; - char * _filename; + char *_uuid; + char *_filename; CList _storage_lst; CList _storage_by_uuid_lst; } NMSettingsStorage; @@ -106,6 +106,6 @@ nm_settings_storage_get_filename(const NMSettingsStorage *self) int nm_settings_storage_cmp(NMSettingsStorage *sd_a, NMSettingsStorage *sd_b, - const GSList * plugin_list); + const GSList *plugin_list); #endif /* __NM_SETTINGS_STORAGE_H__ */ diff --git a/src/core/settings/nm-settings-utils.c b/src/core/settings/nm-settings-utils.c index 775d0396..4343a376 100644 --- a/src/core/settings/nm-settings-utils.c +++ b/src/core/settings/nm-settings-utils.c @@ -88,9 +88,9 @@ void nm_sett_util_storages_add_take(NMSettUtilStorages *storages, gpointer storage_take_p /* NMSettingsStorage *, take reference */) { - NMSettingsStorage * storage_take = storage_take_p; + NMSettingsStorage *storage_take = storage_take_p; NMSettUtilStorageByUuidHead *sbuh; - const char * uuid; + const char *uuid; nm_assert(storage_take); nm_assert(c_list_is_empty(&storage_take->_storage_lst)); @@ -125,9 +125,9 @@ gpointer /* NMSettingsStorage * */ nm_sett_util_storages_steal(NMSettUtilStorages *storages, gpointer storage_p /* NMSettingsStorage **/) { - NMSettingsStorage * storage = storage_p; + NMSettingsStorage *storage = storage_p; NMSettUtilStorageByUuidHead *sbuh; - const char * uuid; + const char *uuid; nm_assert(storage); nm_assert(nm_sett_util_storages_lookup_by_filename(storages, diff --git a/src/core/settings/nm-settings.c b/src/core/settings/nm-settings.c index b71b9d18..da09571b 100644 --- a/src/core/settings/nm-settings.c +++ b/src/core/settings/nm-settings.c @@ -79,7 +79,7 @@ static NM_CACHED_QUARK_FCN("default-wired-connection-blocked", typedef struct _StorageData { CList sd_lst; NMSettingsStorage *storage; - NMConnection * connection; + NMConnection *connection; bool prioritize : 1; } StorageData; @@ -123,9 +123,9 @@ static void nm_assert_storage_data_lst(CList *head) { #if NM_MORE_ASSERTS > 5 - const char * uuid = NULL; + const char *uuid = NULL; StorageData *sd; - CList * iter; + CList *iter; nm_assert(head); @@ -166,9 +166,9 @@ _storage_data_is_alive(StorageData *sd) /*****************************************************************************/ typedef struct { - const char * uuid; + const char *uuid; NMSettingsConnection *sett_conn; - NMSettingsStorage * storage; + NMSettingsStorage *storage; CList sd_lst_head; CList dirty_sd_lst_head; @@ -239,10 +239,10 @@ _sett_conn_entry_get_conn(SettConnEntry *sett_conn_entry) * Returns: the conflicting storage or %NULL if there is none. */ static NMSettingsStorage * -_sett_conn_entry_storage_find_conflicting_storage(SettConnEntry * sett_conn_entry, - NMSettingsPlugin * target_plugin, +_sett_conn_entry_storage_find_conflicting_storage(SettConnEntry *sett_conn_entry, + NMSettingsPlugin *target_plugin, NMSettingsStorage *storage_check_including, - const GSList * plugins) + const GSList *plugins) { StorageData *sd; @@ -294,8 +294,8 @@ _sett_conn_entry_storage_find_conflicting_storage(SettConnEntry * sett_conn_e } static NMSettingsStorage * -_sett_conn_entry_find_shadowed_storage(SettConnEntry * sett_conn_entry, - const char * shadowed_storage_filename, +_sett_conn_entry_find_shadowed_storage(SettConnEntry *sett_conn_entry, + const char *shadowed_storage_filename, NMSettingsStorage *blacklisted_storage) { StorageData *sd; @@ -327,7 +327,7 @@ _sett_conn_entry_find_shadowed_storage(SettConnEntry * sett_conn_entry, NM_GOBJECT_PROPERTIES_DEFINE(NMSettings, PROP_MANAGER, PROP_UNMANAGED_SPECS, - PROP_HOSTNAME, + PROP_STATIC_HOSTNAME, PROP_CAN_MODIFY, PROP_CONNECTIONS, PROP_STARTUP_COMPLETE, ); @@ -428,8 +428,8 @@ static const NMDBusInterfaceInfoExtended interface_info_settings; static const GDBusSignalInfo signal_info_new_connection; static const GDBusSignalInfo signal_info_connection_removed; -static void default_wired_clear_tag(NMSettings * self, - NMDevice * device, +static void default_wired_clear_tag(NMSettings *self, + NMDevice *device, NMSettingsConnection *sett_conn, gboolean add_to_no_auto_default); @@ -446,8 +446,8 @@ _emit_connection_added(NMSettings *self, NMSettingsConnection *sett_conn) } static void -_emit_connection_updated(NMSettings * self, - NMSettingsConnection * sett_conn, +_emit_connection_updated(NMSettings *self, + NMSettingsConnection *sett_conn, NMSettingsConnectionUpdateReason update_reason) { _nm_settings_connection_emit_signal_updated_internal(sett_conn, update_reason); @@ -483,14 +483,14 @@ _startup_complete_data_destroy(StartupCompleteData *scd) } static gboolean -_startup_complete_check_is_ready(NMSettings * self, +_startup_complete_check_is_ready(NMSettings *self, NMSettingsConnection *sett_conn, gboolean ignore_pending_actions) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); - NMConnection * conn; - const CList * tmp_lst; - NMDevice * device; + NMConnection *conn; + const CList *tmp_lst; + NMDevice *device; if (!priv->manager) return TRUE; @@ -528,7 +528,7 @@ _startup_complete_check_is_ready(NMSettings * self, static gboolean _startup_complete_timeout_cb(gpointer user_data) { - NMSettings * self = user_data; + NMSettings *self = user_data; NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); priv->startup_complete_timeout_id = 0; @@ -539,7 +539,7 @@ _startup_complete_timeout_cb(gpointer user_data) static void _startup_complete_check(NMSettings *self, gint64 now_msec) { - NMSettingsPrivate * priv = NM_SETTINGS_GET_PRIVATE(self); + NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); StartupCompleteData *scd_not_ready; StartupCompleteData *scd_safe; StartupCompleteData *scd; @@ -632,11 +632,11 @@ ready: } static void -_startup_complete_notify_connection(NMSettings * self, +_startup_complete_notify_connection(NMSettings *self, NMSettingsConnection *sett_conn, gboolean forget) { - NMSettingsPrivate * priv = NM_SETTINGS_GET_PRIVATE(self); + NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); StartupCompleteData *scd; gint64 timeout_msec; gint64 now_msec = 0; @@ -697,9 +697,9 @@ check: const char * nm_settings_get_startup_complete_blocked_reason(NMSettings *self, gboolean force_reload) { - NMSettingsPrivate * priv = NM_SETTINGS_GET_PRIVATE(self); + NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); StartupCompleteData *scd; - const char * uuid; + const char *uuid; if (priv->startup_complete_start_timestamp_msec == 0) goto out_done; @@ -776,7 +776,7 @@ update_specs(NMSettings *self, GSList **specs_ptr, GSList *(*get_specs_func)(NMS static void _plugin_unmanaged_specs_changed(NMSettingsPlugin *config, gpointer user_data) { - NMSettings * self = NM_SETTINGS(user_data); + NMSettings *self = NM_SETTINGS(user_data); NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); if (update_specs(self, &priv->unmanaged_specs, nm_settings_plugin_get_unmanaged_specs)) @@ -786,7 +786,7 @@ _plugin_unmanaged_specs_changed(NMSettingsPlugin *config, gpointer user_data) static void _plugin_unrecognized_specs_changed(NMSettingsPlugin *config, gpointer user_data) { - NMSettings * self = NM_SETTINGS(user_data); + NMSettings *self = NM_SETTINGS(user_data); NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); update_specs(self, &priv->unrecognized_specs, nm_settings_plugin_get_unrecognized_specs); @@ -813,7 +813,7 @@ static SettConnEntry * _sett_conn_entries_create_and_add(NMSettings *self, const char *uuid) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); - SettConnEntry * sett_conn_entry; + SettConnEntry *sett_conn_entry; sett_conn_entry = _sett_conn_entry_new(uuid); @@ -841,7 +841,7 @@ _sett_conn_entries_remove_and_destroy(NMSettings *self, SettConnEntry *sett_conn static int _sett_conn_entry_sds_update_cmp_ascending(const StorageData *sd_a, const StorageData *sd_b, - const GSList * plugins) + const GSList *plugins) { const NMSettingsMetaData *meta_data_a; const NMSettingsMetaData *meta_data_b; @@ -997,13 +997,13 @@ _sett_conn_entry_sds_update(NMSettings *self, SettConnEntry *sett_conn_entry) static NMConnection * _connection_changed_normalize_connection(NMSettingsStorage *storage, - NMConnection * connection, - GVariant * secrets_to_merge, - NMConnection ** out_connection_cloned) + NMConnection *connection, + GVariant *secrets_to_merge, + NMConnection **out_connection_cloned) { gs_unref_object NMConnection *connection_cloned = NULL; - gs_free_error GError *error = NULL; - const char * uuid; + gs_free_error GError *error = NULL; + const char *uuid; nm_assert(NM_IS_SETTINGS_STORAGE(storage)); nm_assert(out_connection_cloned && !*out_connection_cloned); @@ -1047,18 +1047,18 @@ _connection_changed_normalize_connection(NMSettingsStorage *storage, /*****************************************************************************/ static void -_connection_changed_update(NMSettings * self, - SettConnEntry * sett_conn_entry, - NMConnection * connection, +_connection_changed_update(NMSettings *self, + SettConnEntry *sett_conn_entry, + NMConnection *connection, NMSettingsConnectionIntFlags sett_flags, NMSettingsConnectionIntFlags sett_mask, NMSettingsConnectionUpdateReason update_reason) { - NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); - gs_unref_object NMConnection *connection_old = NULL; - NMSettingsStorage * storage = sett_conn_entry->storage; - gs_unref_object NMSettingsConnection *sett_conn = g_object_ref(sett_conn_entry->sett_conn); - const char * path; + NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); + gs_unref_object NMConnection *connection_old = NULL; + NMSettingsStorage *storage = sett_conn_entry->storage; + gs_unref_object NMSettingsConnection *sett_conn = g_object_ref(sett_conn_entry->sett_conn); + const char *path; gboolean is_new; nm_assert(!NM_FLAGS_ANY(sett_mask, ~_NM_SETTINGS_CONNECTION_INT_FLAGS_PERSISTENT_MASK)); @@ -1162,15 +1162,15 @@ _connection_changed_update(NMSettings * self, } static void -_connection_changed_delete(NMSettings * self, - NMSettingsStorage * storage, +_connection_changed_delete(NMSettings *self, + NMSettingsStorage *storage, NMSettingsConnection *sett_conn, gboolean allow_add_to_no_auto_default) { - NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); + NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); gs_unref_object NMConnection *connection_for_agents = NULL; - NMDevice * device; - const char * uuid; + NMDevice *device; + const char *uuid; nm_assert(NM_IS_SETTINGS_CONNECTION(sett_conn)); nm_assert(c_list_contains(&priv->connections_lst_head, &sett_conn->_connections_lst)); @@ -1235,8 +1235,8 @@ _connection_changed_delete(NMSettings * self, } static void -_connection_changed_process_one(NMSettings * self, - SettConnEntry * sett_conn_entry, +_connection_changed_process_one(NMSettings *self, + SettConnEntry *sett_conn_entry, gboolean allow_add_to_no_auto_default, NMSettingsConnectionIntFlags sett_flags, NMSettingsConnectionIntFlags sett_mask, @@ -1253,7 +1253,7 @@ _connection_changed_process_one(NMSettings * self, if (!sd_best || !sd_best->connection) { gs_unref_object NMSettingsConnection *sett_conn = NULL; - gs_unref_object NMSettingsStorage *storage = NULL; + gs_unref_object NMSettingsStorage *storage = NULL; if (!sett_conn_entry->sett_conn) { if (!sd_best) { @@ -1310,7 +1310,7 @@ _connection_changed_process_one(NMSettings * self, } static void -_connection_changed_process_all_dirty(NMSettings * self, +_connection_changed_process_all_dirty(NMSettings *self, gboolean allow_add_to_no_auto_default, NMSettingsConnectionIntFlags sett_flags, NMSettingsConnectionIntFlags sett_mask, @@ -1318,7 +1318,7 @@ _connection_changed_process_all_dirty(NMSettings * self, NMSettingsConnectionUpdateReason update_reason) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); - SettConnEntry * sett_conn_entry; + SettConnEntry *sett_conn_entry; while ((sett_conn_entry = c_list_first_entry(&priv->sce_dirty_lst_head, SettConnEntry, sce_dirty_lst))) { @@ -1333,15 +1333,15 @@ _connection_changed_process_all_dirty(NMSettings * self, } static SettConnEntry * -_connection_changed_track(NMSettings * self, +_connection_changed_track(NMSettings *self, NMSettingsStorage *storage, - NMConnection * connection, + NMConnection *connection, gboolean prioritize) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); - SettConnEntry * sett_conn_entry; - StorageData * sd; - const char * uuid; + SettConnEntry *sett_conn_entry; + StorageData *sd; + const char *uuid; nm_assert_valid_settings_storage(NULL, storage); @@ -1358,9 +1358,9 @@ _connection_changed_track(NMSettings * self, _sett_conn_entries_get(self, uuid) ?: _sett_conn_entries_create_and_add(self, uuid); if (_LOGT_ENABLED()) { - const char * filename; + const char *filename; const NMSettingsMetaData *meta_data; - const char * shadowed_storage; + const char *shadowed_storage; gboolean shadowed_owned; filename = nm_settings_storage_get_filename(storage); @@ -1427,9 +1427,9 @@ _connection_changed_track(NMSettings * self, /*****************************************************************************/ static void -_plugin_connections_reload_cb(NMSettingsPlugin * plugin, +_plugin_connections_reload_cb(NMSettingsPlugin *plugin, NMSettingsStorage *storage, - NMConnection * connection, + NMConnection *connection, gpointer user_data) { _connection_changed_track(user_data, storage, connection, FALSE); @@ -1439,7 +1439,7 @@ static void _plugin_connections_reload(NMSettings *self) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); - GSList * iter; + GSList *iter; for (iter = priv->plugins; iter; iter = iter->next) { nm_settings_plugin_reload_connections(iter->data, _plugin_connections_reload_cb, self); @@ -1462,36 +1462,36 @@ _plugin_connections_reload(NMSettings *self) /*****************************************************************************/ static gboolean -_add_connection_to_first_plugin(NMSettings * self, - SettConnEntry * sett_conn_entry, - NMConnection * new_connection, +_add_connection_to_first_plugin(NMSettings *self, + SettConnEntry *sett_conn_entry, + NMConnection *new_connection, gboolean in_memory, NMSettingsConnectionIntFlags sett_flags, - const char * shadowed_storage, + const char *shadowed_storage, gboolean shadowed_owned, - NMSettingsStorage ** out_new_storage, - NMConnection ** out_new_connection, - GError ** error) + NMSettingsStorage **out_new_storage, + NMConnection **out_new_connection, + GError **error) { - NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); + NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); gs_free_error GError *first_error = NULL; - GSList * iter; - const char * uuid; + GSList *iter; + const char *uuid; uuid = nm_connection_get_uuid(new_connection); nm_assert(nm_uuid_is_normalized(uuid)); for (iter = priv->plugins; iter; iter = iter->next) { - NMSettingsPlugin *plugin = NM_SETTINGS_PLUGIN(iter->data); - gs_unref_object NMSettingsStorage *storage = NULL; - gs_unref_object NMConnection *connection_to_add = NULL; - gs_unref_object NMConnection *connection_to_add_cloned = NULL; - NMConnection * connection_to_add_real = NULL; - gs_unref_variant GVariant *agent_owned_secrets = NULL; - gs_free_error GError *add_error = NULL; - gboolean success; - const char * filename; + NMSettingsPlugin *plugin = NM_SETTINGS_PLUGIN(iter->data); + gs_unref_object NMSettingsStorage *storage = NULL; + gs_unref_object NMConnection *connection_to_add = NULL; + gs_unref_object NMConnection *connection_to_add_cloned = NULL; + NMConnection *connection_to_add_real = NULL; + gs_unref_variant GVariant *agent_owned_secrets = NULL; + gs_free_error GError *add_error = NULL; + gboolean success; + const char *filename; if (!in_memory) { NMSettingsStorage *conflicting_storage; @@ -1594,19 +1594,19 @@ _add_connection_to_first_plugin(NMSettings * self, } static gboolean -_update_connection_to_plugin(NMSettings * self, - NMSettingsStorage * storage, - NMConnection * connection, +_update_connection_to_plugin(NMSettings *self, + NMSettingsStorage *storage, + NMConnection *connection, NMSettingsConnectionIntFlags sett_flags, gboolean force_rename, - const char * shadowed_storage, + const char *shadowed_storage, gboolean shadowed_owned, - NMSettingsStorage ** out_new_storage, - NMConnection ** out_new_connection, - GError ** error) + NMSettingsStorage **out_new_storage, + NMConnection **out_new_connection, + GError **error) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); - NMSettingsPlugin * plugin; + NMSettingsPlugin *plugin; gboolean success; plugin = nm_settings_storage_get_plugin(storage); @@ -1646,7 +1646,7 @@ _set_nmmeta_tombstone(NMSettings *self, gboolean tombstone_in_memory, const char *shadowed_storage) { - NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); + NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); gs_unref_object NMSettingsStorage *tombstone_1_storage = NULL; gs_unref_object NMSettingsStorage *tombstone_2_storage = NULL; @@ -1703,27 +1703,27 @@ _set_nmmeta_tombstone(NMSettings *self, * Returns: TRUE on success. */ gboolean -nm_settings_add_connection(NMSettings * self, - NMConnection * connection, +nm_settings_add_connection(NMSettings *self, + NMConnection *connection, NMSettingsConnectionPersistMode persist_mode, NMSettingsConnectionAddReason add_reason, NMSettingsConnectionIntFlags sett_flags, - NMSettingsConnection ** out_sett_conn, - GError ** error) + NMSettingsConnection **out_sett_conn, + GError **error) { - NMSettingsPrivate *priv; - gs_unref_object NMConnection *connection_cloned_1 = NULL; - gs_unref_object NMConnection *new_connection = NULL; - gs_unref_object NMSettingsStorage *new_storage = NULL; - gs_unref_object NMSettingsStorage *shadowed_storage = NULL; - NMSettingsStorage * update_storage = NULL; - gs_free_error GError *local = NULL; - SettConnEntry * sett_conn_entry; - const char * uuid; - StorageData * sd; - gboolean new_in_memory; - gboolean success; - const char * shadowed_storage_filename = NULL; + NMSettingsPrivate *priv; + gs_unref_object NMConnection *connection_cloned_1 = NULL; + gs_unref_object NMConnection *new_connection = NULL; + gs_unref_object NMSettingsStorage *new_storage = NULL; + gs_unref_object NMSettingsStorage *shadowed_storage = NULL; + NMSettingsStorage *update_storage = NULL; + gs_free_error GError *local = NULL; + SettConnEntry *sett_conn_entry; + const char *uuid; + StorageData *sd; + gboolean new_in_memory; + gboolean success; + const char *shadowed_storage_filename = NULL; priv = NM_SETTINGS_GET_PRIVATE(self); @@ -1882,7 +1882,7 @@ again_add_connection: sett_conn_entry = _connection_changed_track(self, new_storage, new_connection, TRUE); c_list_for_each_entry (sd, &sett_conn_entry->sd_lst_head, sd_lst) { - const NMSettingsMetaData *meta_data; + const NMSettingsMetaData *meta_data; gs_unref_object NMSettingsStorage *new_tombstone_storage = NULL; gboolean in_memory; gboolean simulate; @@ -1946,27 +1946,27 @@ again_delete_tombstone: /*****************************************************************************/ gboolean -nm_settings_update_connection(NMSettings * self, - NMSettingsConnection * sett_conn, - NMConnection * connection, +nm_settings_update_connection(NMSettings *self, + NMSettingsConnection *sett_conn, + NMConnection *connection, NMSettingsConnectionPersistMode persist_mode, NMSettingsConnectionIntFlags sett_flags, NMSettingsConnectionIntFlags sett_mask, NMSettingsConnectionUpdateReason update_reason, - const char * log_context_name, - GError ** error) + const char *log_context_name, + GError **error) { - gs_unref_object NMConnection *connection_cloned_1 = NULL; - gs_unref_object NMConnection *new_connection_cloned = NULL; - gs_unref_object NMConnection *new_connection = NULL; - NMConnection * new_connection_real; + gs_unref_object NMConnection *connection_cloned_1 = NULL; + gs_unref_object NMConnection *new_connection_cloned = NULL; + gs_unref_object NMConnection *new_connection = NULL; + NMConnection *new_connection_real; gs_unref_object NMSettingsStorage *cur_storage = NULL; gs_unref_object NMSettingsStorage *new_storage = NULL; - NMSettingsStorage * drop_storage = NULL; - SettConnEntry * sett_conn_entry; + NMSettingsStorage *drop_storage = NULL; + SettConnEntry *sett_conn_entry; gboolean cur_in_memory; gboolean new_in_memory; - const char * uuid; + const char *uuid; gboolean tombstone_in_memory = FALSE; gboolean tombstone_on_disk = FALSE; @@ -2112,13 +2112,13 @@ nm_settings_update_connection(NMSettings * self, log_context_name, nm_connection_get_id(connection)); } else { - NMSettingsStorage *shadowed_storage; - const char * cur_shadowed_storage_filename; - const char * new_shadowed_storage_filename = NULL; - gboolean cur_shadowed_owned; - gboolean new_shadowed_owned = FALSE; - NMSettingsStorage *update_storage = NULL; - gs_free_error GError *local = NULL; + NMSettingsStorage *shadowed_storage; + const char *cur_shadowed_storage_filename; + const char *new_shadowed_storage_filename = NULL; + gboolean cur_shadowed_owned; + gboolean new_shadowed_owned = FALSE; + NMSettingsStorage *update_storage = NULL; + gs_free_error GError *local = NULL; gboolean success; cur_shadowed_storage_filename = @@ -2287,20 +2287,20 @@ nm_settings_update_connection(NMSettings * self, } void -nm_settings_delete_connection(NMSettings * self, +nm_settings_delete_connection(NMSettings *self, NMSettingsConnection *sett_conn, gboolean allow_add_to_no_auto_default) { - NMSettingsStorage *cur_storage; - NMSettingsStorage *shadowed_storage; - NMSettingsStorage *shadowed_storage_unowned = NULL; - NMSettingsStorage *drop_storages[2] = {}; - gs_free_error GError *local = NULL; - SettConnEntry * sett_conn_entry; - const char * cur_shadowed_storage_filename; - const char * new_shadowed_storage_filename = NULL; + NMSettingsStorage *cur_storage; + NMSettingsStorage *shadowed_storage; + NMSettingsStorage *shadowed_storage_unowned = NULL; + NMSettingsStorage *drop_storages[2] = {}; + gs_free_error GError *local = NULL; + SettConnEntry *sett_conn_entry; + const char *cur_shadowed_storage_filename; + const char *new_shadowed_storage_filename = NULL; gboolean cur_shadowed_owned; - const char * uuid; + const char *uuid; gboolean tombstone_in_memory = FALSE; gboolean tombstone_on_disk = FALSE; int i; @@ -2346,7 +2346,7 @@ nm_settings_delete_connection(NMSettings * self, for (i = 0; i < (int) G_N_ELEMENTS(drop_storages); i++) { NMSettingsStorage *storage; - StorageData * sd; + StorageData *sd; storage = drop_storages[i]; if (!storage) @@ -2415,7 +2415,7 @@ nm_settings_delete_connection(NMSettings * self, static void send_agent_owned_secrets(NMSettings *self, NMSettingsConnection *sett_conn, NMAuthSubject *subject) { - NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); + NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); gs_unref_object NMConnection *for_agent = NULL; /* Dupe the connection so we can clear out non-agent-owned secrets, @@ -2433,15 +2433,15 @@ send_agent_owned_secrets(NMSettings *self, NMSettingsConnection *sett_conn, NMAu static void pk_add_cb(NMAuthChain *chain, GDBusMethodInvocation *context, gpointer user_data) { - NMSettings * self = NM_SETTINGS(user_data); - NMAuthCallResult result; - gs_free_error GError *error = NULL; - NMConnection * connection = NULL; - gs_unref_object NMSettingsConnection *added = NULL; + NMSettings *self = NM_SETTINGS(user_data); + NMAuthCallResult result; + gs_free_error GError *error = NULL; + NMConnection *connection = NULL; + gs_unref_object NMSettingsConnection *added = NULL; NMSettingsAddCallback callback; gpointer callback_data; - NMAuthSubject * subject; - const char * perm; + NMAuthSubject *subject; + const char *perm; nm_assert(G_IS_DBUS_METHOD_INVOCATION(context)); @@ -2488,21 +2488,21 @@ pk_add_cb(NMAuthChain *chain, GDBusMethodInvocation *context, gpointer user_data } void -nm_settings_add_connection_dbus(NMSettings * self, - NMConnection * connection, +nm_settings_add_connection_dbus(NMSettings *self, + NMConnection *connection, NMSettingsConnectionPersistMode persist_mode, NMSettingsConnectionAddReason add_reason, NMSettingsConnectionIntFlags sett_flags, - NMAuthSubject * subject, - GDBusMethodInvocation * context, + NMAuthSubject *subject, + GDBusMethodInvocation *context, NMSettingsAddCallback callback, gpointer user_data) { - NMSettingsPrivate * priv = NM_SETTINGS_GET_PRIVATE(self); + NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); NMSettingConnection *s_con; - NMAuthChain * chain; - GError * error = NULL, *tmp_error = NULL; - const char * perm; + NMAuthChain *chain; + GError *error = NULL, *tmp_error = NULL; + const char *perm; g_return_if_fail(NM_IS_CONNECTION(connection)); g_return_if_fail(NM_IS_AUTH_SUBJECT(subject)); @@ -2559,11 +2559,11 @@ done: } static void -settings_add_connection_add_cb(NMSettings * self, - NMSettingsConnection * connection, - GError * error, +settings_add_connection_add_cb(NMSettings *self, + NMSettingsConnection *connection, + GError *error, GDBusMethodInvocation *context, - NMAuthSubject * subject, + NMAuthSubject *subject, gpointer user_data) { gboolean is_add_connection_2 = GPOINTER_TO_INT(user_data); @@ -2597,15 +2597,15 @@ settings_add_connection_add_cb(NMSettings * self, } static void -settings_add_connection_helper(NMSettings * self, - GDBusMethodInvocation * context, +settings_add_connection_helper(NMSettings *self, + GDBusMethodInvocation *context, gboolean is_add_connection_2, - GVariant * settings, + GVariant *settings, NMSettingsAddConnection2Flags flags) { - gs_unref_object NMConnection *connection = NULL; - GError * error = NULL; - gs_unref_object NMAuthSubject * subject = NULL; + gs_unref_object NMConnection *connection = NULL; + GError *error = NULL; + gs_unref_object NMAuthSubject *subject = NULL; NMSettingsConnectionPersistMode persist_mode; connection = _nm_simple_connection_new_from_dbus(settings, @@ -2649,15 +2649,15 @@ settings_add_connection_helper(NMSettings * self, } static void -impl_settings_add_connection(NMDBusObject * obj, +impl_settings_add_connection(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMSettings * self = NM_SETTINGS(obj); + NMSettings *self = NM_SETTINGS(obj); gs_unref_variant GVariant *settings = NULL; g_variant_get(parameters, "(@a{sa{sv}})", &settings); @@ -2669,15 +2669,15 @@ impl_settings_add_connection(NMDBusObject * obj, } static void -impl_settings_add_connection_unsaved(NMDBusObject * obj, +impl_settings_add_connection_unsaved(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMSettings * self = NM_SETTINGS(obj); + NMSettings *self = NM_SETTINGS(obj); gs_unref_variant GVariant *settings = NULL; g_variant_get(parameters, "(@a{sa{sv}})", &settings); @@ -2689,19 +2689,19 @@ impl_settings_add_connection_unsaved(NMDBusObject * obj, } static void -impl_settings_add_connection2(NMDBusObject * obj, +impl_settings_add_connection2(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMSettings * self = NM_SETTINGS(obj); - gs_unref_variant GVariant *settings = NULL; - gs_unref_variant GVariant * args = NULL; + NMSettings *self = NM_SETTINGS(obj); + gs_unref_variant GVariant *settings = NULL; + gs_unref_variant GVariant *args = NULL; NMSettingsAddConnection2Flags flags; - const char * args_name; + const char *args_name; GVariantIter iter; guint32 flags_u; @@ -2760,19 +2760,19 @@ impl_settings_add_connection2(NMDBusObject * obj, /*****************************************************************************/ static void -impl_settings_load_connections(NMDBusObject * obj, +impl_settings_load_connections(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * dbus_connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *dbus_connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMSettings * self = NM_SETTINGS(obj); - NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); + NMSettings *self = NM_SETTINGS(obj); + NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); gs_unref_ptrarray GPtrArray *failures = NULL; - gs_free const char ** filenames = NULL; - gs_free char * op_result_str = NULL; + gs_free const char **filenames = NULL; + gs_free char *op_result_str = NULL; g_variant_get(parameters, "(^a&s)", &filenames); @@ -2791,7 +2791,7 @@ impl_settings_load_connections(NMDBusObject * obj, NMSettingsPluginConnectionLoadEntry *entries; gsize n_entries; gsize i; - GSList * iter; + GSList *iter; entries = nm_settings_plugin_create_connection_load_entries(filenames, &n_entries); @@ -2857,13 +2857,13 @@ impl_settings_load_connections(NMDBusObject * obj, } static void -impl_settings_reload_connections(NMDBusObject * obj, +impl_settings_reload_connections(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { NMSettings *self = NM_SETTINGS(obj); @@ -2933,16 +2933,16 @@ _clear_connections_cached_list(NMSettingsPrivate *priv) } static void -impl_settings_list_connections(NMDBusObject * obj, +impl_settings_list_connections(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * dbus_connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *dbus_connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMSettings * self = NM_SETTINGS(obj); - NMSettingsPrivate * priv = NM_SETTINGS_GET_PRIVATE(self); + NMSettings *self = NM_SETTINGS(obj); + NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); gs_free const char **strv = NULL; strv = @@ -2976,19 +2976,19 @@ nm_settings_get_dbus_path_for_uuid(NMSettings *self, const char *uuid) } static void -impl_settings_get_connection_by_uuid(NMDBusObject * obj, +impl_settings_get_connection_by_uuid(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * dbus_connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *dbus_connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMSettings * self = NM_SETTINGS(obj); - NMSettingsConnection *sett_conn; + NMSettings *self = NM_SETTINGS(obj); + NMSettingsConnection *sett_conn; gs_unref_object NMAuthSubject *subject = NULL; - GError * error = NULL; - const char * uuid; + GError *error = NULL; + const char *uuid; g_variant_get(parameters, "(&s)", &uuid); @@ -3039,9 +3039,9 @@ error: NMSettingsConnection *const * nm_settings_get_connections(NMSettings *self, guint *out_len) { - NMSettingsPrivate * priv; + NMSettingsPrivate *priv; NMSettingsConnection **v; - NMSettingsConnection * con; + NMSettingsConnection *con; guint i; g_return_val_if_fail(NM_IS_SETTINGS(self), NULL); @@ -3145,15 +3145,15 @@ nm_settings_get_connections_sorted_by_autoconnect_priority(NMSettings *self, gui * the contained values do not need to be unrefed. */ NMSettingsConnection ** -nm_settings_get_connections_clone(NMSettings * self, - guint * out_len, +nm_settings_get_connections_clone(NMSettings *self, + guint *out_len, NMSettingsConnectionFilterFunc func, gpointer func_data, GCompareDataFunc sort_compare_func, gpointer sort_data) { NMSettingsConnection *const *list_cached; - NMSettingsConnection ** list; + NMSettingsConnection **list; guint len, i, j; g_return_val_if_fail(NM_IS_SETTINGS(self), NULL); @@ -3192,7 +3192,7 @@ nm_settings_get_connections_clone(NMSettings * self, NMSettingsConnection * nm_settings_get_connection_by_path(NMSettings *self, const char *path) { - NMSettingsPrivate * priv; + NMSettingsPrivate *priv; NMSettingsConnection *connection; g_return_val_if_fail(NM_IS_SETTINGS(self), NULL); @@ -3225,7 +3225,7 @@ nm_settings_has_connection(NMSettings *self, NMSettingsConnection *connection) _connections_lst)); nm_assert(({ NMSettingsConnection *candidate = NULL; - const char * path; + const char *path; path = nm_dbus_object_get_path(NM_DBUS_OBJECT(connection)); if (path) @@ -3268,10 +3268,10 @@ add_plugin(NMSettings *self, NMSettingsPlugin *plugin, const char *pname, const static gboolean add_plugin_load_file(NMSettings *self, const char *pname, GError **error) { - gs_free char * full_name = NULL; - gs_free char * path = NULL; - gs_unref_object NMSettingsPlugin *plugin = NULL; - GModule * module; + gs_free char *full_name = NULL; + gs_free char *path = NULL; + gs_unref_object NMSettingsPlugin *plugin = NULL; + GModule *module; NMSettingsPluginFactoryFunc factory_func; struct stat st; int errsv; @@ -3395,11 +3395,11 @@ load_plugins(NMSettings *self, const char *const *plugins, GError **error) static void pk_hostname_cb(NMAuthChain *chain, GDBusMethodInvocation *context, gpointer user_data) { - NMSettings * self = NM_SETTINGS(user_data); + NMSettings *self = NM_SETTINGS(user_data); NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); NMAuthCallResult result; - GError * error = NULL; - const char * hostname; + GError *error = NULL; + const char *hostname; nm_assert(G_IS_DBUS_METHOD_INVOCATION(context)); @@ -3434,19 +3434,19 @@ pk_hostname_cb(NMAuthChain *chain, GDBusMethodInvocation *context, gpointer user } static void -impl_settings_save_hostname(NMDBusObject * obj, +impl_settings_save_hostname(NMDBusObject *obj, const NMDBusInterfaceInfoExtended *interface_info, - const NMDBusMethodInfoExtended * method_info, - GDBusConnection * connection, - const char * sender, - GDBusMethodInvocation * invocation, - GVariant * parameters) + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) { - NMSettings * self = NM_SETTINGS(obj); + NMSettings *self = NM_SETTINGS(obj); NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); - NMAuthChain * chain; - const char * hostname; - const char * error_reason; + NMAuthChain *chain; + const char *hostname; + const char *error_reason; int error_code; g_variant_get(parameters, "(&s)", &hostname); @@ -3480,9 +3480,11 @@ err: /*****************************************************************************/ static void -_hostname_changed_cb(NMHostnameManager *hostname_manager, GParamSpec *pspec, gpointer user_data) +_static_hostname_changed_cb(NMHostnameManager *hostname_manager, + GParamSpec *pspec, + gpointer user_data) { - _notify(user_data, PROP_HOSTNAME); + _notify(user_data, PROP_STATIC_HOSTNAME); } /*****************************************************************************/ @@ -3490,7 +3492,7 @@ _hostname_changed_cb(NMHostnameManager *hostname_manager, GParamSpec *pspec, gpo static gboolean have_connection_for_device(NMSettings *self, NMDevice *device) { - NMSettingsPrivate * priv = NM_SETTINGS_GET_PRIVATE(self); + NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); NMSettingsConnection *sett_conn; g_return_val_if_fail(NM_IS_SETTINGS(self), FALSE); @@ -3521,8 +3523,8 @@ have_connection_for_device(NMSettings *self, NMDevice *device) } static void -default_wired_clear_tag(NMSettings * self, - NMDevice * device, +default_wired_clear_tag(NMSettings *self, + NMDevice *device, NMSettingsConnection *sett_conn, gboolean add_to_no_auto_default) { @@ -3550,9 +3552,9 @@ static void device_realized(NMDevice *device, GParamSpec *pspec, NMSettings *self) { gs_unref_object NMConnection *connection = NULL; - NMSettingsPrivate * priv; - NMSettingsConnection * added; - GError * error = NULL; + NMSettingsPrivate *priv; + NMSettingsConnection *added; + GError *error = NULL; if (!nm_device_is_real(device)) return; @@ -3664,7 +3666,7 @@ nm_settings_device_removed(NMSettings *self, NMDevice *device, gboolean quitting static void session_monitor_changed_cb(NMSessionMonitor *session_monitor, NMSettings *self) { - NMSettingsPrivate * priv = NM_SETTINGS_GET_PRIVATE(self); + NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); NMSettingsConnection *const *list; guint i, len; guint generation; @@ -3705,8 +3707,8 @@ static void _kf_db_to_file(NMSettings *self, gboolean is_timestamps, gboolean force_write) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); - NMKeyFileDB * kf_db; - bool * p_kf_db_pruned; + NMKeyFileDB *kf_db; + bool *p_kf_db_pruned; if (is_timestamps) { kf_db = priv->kf_db_timestamps; @@ -3739,9 +3741,9 @@ _kf_db_log_fcn(NMKeyFileDB *kf_db, int syslog_level, gpointer user_data, const c if (_NMLOG_ENABLED(level)) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); - gs_free char * msg = NULL; + gs_free char *msg = NULL; va_list ap; - const char * prefix; + const char *prefix; va_start(ap, fmt); msg = g_strdup_vprintf(fmt, ap); @@ -3764,8 +3766,8 @@ static gboolean _kf_db_got_dirty_flush(NMSettings *self, gboolean is_timestamps) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); - const char * prefix; - NMKeyFileDB * kf_db; + const char *prefix; + NMKeyFileDB *kf_db; if (is_timestamps) { prefix = "timestamps"; @@ -3803,11 +3805,11 @@ _kf_db_got_dirty_flush_seen_bssids_cb(gpointer user_data) static void _kf_db_got_dirty_fcn(NMKeyFileDB *kf_db, gpointer user_data) { - NMSettings * self = user_data; + NMSettings *self = user_data; NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); GSourceFunc idle_func; - guint * p_id; - const char * prefix; + guint *p_id; + const char *prefix; if (priv->kf_db_timestamps == kf_db) { prefix = "timestamps"; @@ -3844,7 +3846,7 @@ nm_settings_start(NMSettings *self, GError **error) { NMSettingsPrivate *priv; gs_strfreev char **plugins = NULL; - GSList * iter; + GSList *iter; priv = NM_SETTINGS_GET_PRIVATE(self); @@ -3892,11 +3894,11 @@ nm_settings_start(NMSettings *self, GError **error) _plugin_connections_reload(self); g_signal_connect(priv->hostname_manager, - "notify::" NM_HOSTNAME_MANAGER_HOSTNAME, - G_CALLBACK(_hostname_changed_cb), + "notify::" NM_HOSTNAME_MANAGER_STATIC_HOSTNAME, + G_CALLBACK(_static_hostname_changed_cb), self); - if (nm_hostname_manager_get_hostname(priv->hostname_manager)) - _notify(self, PROP_HOSTNAME); + if (nm_hostname_manager_get_static_hostname(priv->hostname_manager)) + _notify(self, PROP_STATIC_HOSTNAME); priv->started = TRUE; _startup_complete_check(self, 0); @@ -3914,19 +3916,19 @@ nm_settings_start(NMSettings *self, GError **error) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMSettings * self = NM_SETTINGS(object); + NMSettings *self = NM_SETTINGS(object); NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); - const char ** strv; + const char **strv; switch (prop_id) { case PROP_UNMANAGED_SPECS: g_value_take_boxed(value, _nm_utils_slist_to_strv(nm_settings_get_unmanaged_specs(self), TRUE)); break; - case PROP_HOSTNAME: + case PROP_STATIC_HOSTNAME: g_value_set_string(value, priv->hostname_manager - ? nm_hostname_manager_get_hostname(priv->hostname_manager) + ? nm_hostname_manager_get_static_hostname(priv->hostname_manager) : NULL); break; case PROP_CAN_MODIFY: @@ -3952,7 +3954,7 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - NMSettings * self = NM_SETTINGS(object); + NMSettings *self = NM_SETTINGS(object); NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); switch (prop_id) { @@ -4009,9 +4011,9 @@ nm_settings_new(NMManager *manager) static void dispose(GObject *object) { - NMSettings * self = NM_SETTINGS(object); + NMSettings *self = NM_SETTINGS(object); NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); - CList * iter; + CList *iter; nm_assert(c_list_is_empty(&priv->sce_dirty_lst_head)); nm_assert(g_hash_table_size(priv->sce_idx) == 0); @@ -4025,7 +4027,7 @@ dispose(GObject *object) if (priv->hostname_manager) { g_signal_handlers_disconnect_by_func(priv->hostname_manager, - G_CALLBACK(_hostname_changed_cb), + G_CALLBACK(_static_hostname_changed_cb), self); g_clear_object(&priv->hostname_manager); } @@ -4043,9 +4045,9 @@ dispose(GObject *object) static void finalize(GObject *object) { - NMSettings * self = NM_SETTINGS(object); + NMSettings *self = NM_SETTINGS(object); NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); - GSList * iter; + GSList *iter; _clear_connections_cached_list(priv); @@ -4167,7 +4169,9 @@ static const NMDBusInterfaceInfoExtended interface_info_settings = { NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Connections", "ao", NM_SETTINGS_CONNECTIONS), - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Hostname", "s", NM_SETTINGS_HOSTNAME), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Hostname", + "s", + NM_SETTINGS_STATIC_HOSTNAME), NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("CanModify", "b", NM_SETTINGS_CAN_MODIFY), ), ), @@ -4176,7 +4180,7 @@ static const NMDBusInterfaceInfoExtended interface_info_settings = { static void nm_settings_class_init(NMSettingsClass *class) { - GObjectClass * object_class = G_OBJECT_CLASS(class); + GObjectClass *object_class = G_OBJECT_CLASS(class); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(class); dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_STATIC(NM_DBUS_PATH_SETTINGS); @@ -4200,11 +4204,12 @@ nm_settings_class_init(NMSettingsClass *class) G_TYPE_STRV, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_HOSTNAME] = g_param_spec_string(NM_SETTINGS_HOSTNAME, - "", - "", - NULL, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + obj_properties[PROP_STATIC_HOSTNAME] = + g_param_spec_string(NM_SETTINGS_STATIC_HOSTNAME, + "", + "", + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); obj_properties[PROP_CAN_MODIFY] = g_param_spec_boolean(NM_SETTINGS_CAN_MODIFY, diff --git a/src/core/settings/nm-settings.h b/src/core/settings/nm-settings.h index ce18fecc..56cebed0 100644 --- a/src/core/settings/nm-settings.h +++ b/src/core/settings/nm-settings.h @@ -24,7 +24,7 @@ (G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_SETTINGS, NMSettingsClass)) #define NM_SETTINGS_UNMANAGED_SPECS "unmanaged-specs" -#define NM_SETTINGS_HOSTNAME "hostname" +#define NM_SETTINGS_STATIC_HOSTNAME "static-hostname" #define NM_SETTINGS_CAN_MODIFY "can-modify" #define NM_SETTINGS_CONNECTIONS "connections" #define NM_SETTINGS_STARTUP_COMPLETE "startup-complete" @@ -43,7 +43,7 @@ * * Returns: %TRUE to allow the connection, %FALSE to ignore it */ -typedef gboolean (*NMSettingsConnectionFilterFunc)(NMSettings * settings, +typedef gboolean (*NMSettingsConnectionFilterFunc)(NMSettings *settings, NMSettingsConnection *connection, gpointer func_data); @@ -60,20 +60,20 @@ NMSettings *nm_settings_new(NMManager *manager); gboolean nm_settings_start(NMSettings *self, GError **error); -typedef void (*NMSettingsAddCallback)(NMSettings * settings, - NMSettingsConnection * connection, - GError * error, +typedef void (*NMSettingsAddCallback)(NMSettings *settings, + NMSettingsConnection *connection, + GError *error, GDBusMethodInvocation *context, - NMAuthSubject * subject, + NMAuthSubject *subject, gpointer user_data); -void nm_settings_add_connection_dbus(NMSettings * self, - NMConnection * connection, +void nm_settings_add_connection_dbus(NMSettings *self, + NMConnection *connection, NMSettingsConnectionPersistMode persist_mode, NMSettingsConnectionAddReason add_reason, NMSettingsConnectionIntFlags sett_flags, - NMAuthSubject * subject, - GDBusMethodInvocation * context, + NMAuthSubject *subject, + GDBusMethodInvocation *context, NMSettingsAddCallback callback, gpointer user_data); @@ -82,32 +82,32 @@ NMSettingsConnection *const *nm_settings_get_connections(NMSettings *settings, g NMSettingsConnection *const * nm_settings_get_connections_sorted_by_autoconnect_priority(NMSettings *self, guint *out_len); -NMSettingsConnection **nm_settings_get_connections_clone(NMSettings * self, - guint * out_len, +NMSettingsConnection **nm_settings_get_connections_clone(NMSettings *self, + guint *out_len, NMSettingsConnectionFilterFunc func, gpointer func_data, GCompareDataFunc sort_compare_func, gpointer sort_data); -gboolean nm_settings_add_connection(NMSettings * settings, - NMConnection * connection, +gboolean nm_settings_add_connection(NMSettings *settings, + NMConnection *connection, NMSettingsConnectionPersistMode persist_mode, NMSettingsConnectionAddReason add_reason, NMSettingsConnectionIntFlags sett_flags, - NMSettingsConnection ** out_sett_conn, - GError ** error); + NMSettingsConnection **out_sett_conn, + GError **error); -gboolean nm_settings_update_connection(NMSettings * self, - NMSettingsConnection * sett_conn, - NMConnection * new_connection, +gboolean nm_settings_update_connection(NMSettings *self, + NMSettingsConnection *sett_conn, + NMConnection *new_connection, NMSettingsConnectionPersistMode persist_mode, NMSettingsConnectionIntFlags sett_flags, NMSettingsConnectionIntFlags sett_mask, NMSettingsConnectionUpdateReason update_reason, - const char * log_context_name, - GError ** error); + const char *log_context_name, + GError **error); -void nm_settings_delete_connection(NMSettings * self, +void nm_settings_delete_connection(NMSettings *self, NMSettingsConnection *sett_conn, gboolean allow_add_to_no_auto_default); diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c index 8fdc01fb..eb0d733d 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c @@ -43,7 +43,7 @@ typedef struct { struct { GDBusConnection *connection; - GCancellable * cancellable; + GCancellable *cancellable; gulong signal_id; guint regist_id; } dbus; @@ -99,9 +99,9 @@ nm_assert_self(NMSIfcfgRHPlugin *self, gboolean unhandled_specs_consistent) #if NM_MORE_ASSERTS > 5 { - NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self); - NMSIfcfgRHStorage * storage; - gsize n_uuid; + NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self); + NMSIfcfgRHStorage *storage; + gsize n_uuid; gs_unref_hashtable GHashTable *h_unmanaged = NULL; gs_unref_hashtable GHashTable *h_unrecognized = NULL; @@ -177,11 +177,11 @@ nm_assert_self(NMSIfcfgRHPlugin *self, gboolean unhandled_specs_consistent) static NMSIfcfgRHStorage * _load_file(NMSIfcfgRHPlugin *self, const char *filename, GError **error) { - gs_unref_object NMConnection *connection = NULL; - gs_free_error GError *load_error = NULL; - gs_free char * unhandled_spec = NULL; - gboolean load_error_ignore; - struct stat st; + gs_unref_object NMConnection *connection = NULL; + gs_free_error GError *load_error = NULL; + gs_free char *unhandled_spec = NULL; + gboolean load_error_ignore; + struct stat st; if (stat(filename, &st) != 0) { int errsv = errno; @@ -240,9 +240,9 @@ static void _load_dir(NMSIfcfgRHPlugin *self, NMSettUtilStorages *storages) { gs_unref_hashtable GHashTable *dupl_filenames = NULL; - gs_free_error GError *local = NULL; - const char * f_filename; - GDir * dir; + gs_free_error GError *local = NULL; + const char *f_filename; + GDir *dir; dir = g_dir_open(IFCFG_DIR, 0, &local); if (!dir) { @@ -253,9 +253,9 @@ _load_dir(NMSIfcfgRHPlugin *self, NMSettUtilStorages *storages) dupl_filenames = g_hash_table_new_full(nm_str_hash, g_str_equal, NULL, g_free); while ((f_filename = g_dir_read_name(dir))) { - gs_free char * full_path = NULL; + gs_free char *full_path = NULL; NMSIfcfgRHStorage *storage; - char * full_filename; + char *full_filename; full_path = g_build_filename(IFCFG_DIR, f_filename, NULL); full_filename = utils_detect_ifcfg_path(full_path, TRUE); @@ -275,21 +275,21 @@ _load_dir(NMSIfcfgRHPlugin *self, NMSettUtilStorages *storages) } static void -_storages_consolidate(NMSIfcfgRHPlugin * self, - NMSettUtilStorages * storages_new, +_storages_consolidate(NMSIfcfgRHPlugin *self, + NMSettUtilStorages *storages_new, gboolean replace_all, - GHashTable * storages_replaced, + GHashTable *storages_replaced, NMSettingsPluginConnectionLoadCallback callback, gpointer user_data) { - NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self); - CList lst_conn_info_deleted = C_LIST_INIT(lst_conn_info_deleted); - gs_unref_ptrarray GPtrArray *storages_modified = NULL; + NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self); + CList lst_conn_info_deleted = C_LIST_INIT(lst_conn_info_deleted); + gs_unref_ptrarray GPtrArray *storages_modified = NULL; CList storages_deleted; - NMSIfcfgRHStorage * storage_safe; - NMSIfcfgRHStorage * storage_new; - NMSIfcfgRHStorage * storage_old; - NMSIfcfgRHStorage * storage; + NMSIfcfgRHStorage *storage_safe; + NMSIfcfgRHStorage *storage_new; + NMSIfcfgRHStorage *storage_old; + NMSIfcfgRHStorage *storage; guint i; /* when we reload all files, we must signal add/update/modify of profiles one-by-one. @@ -402,20 +402,20 @@ _storages_consolidate(NMSIfcfgRHPlugin * self, /*****************************************************************************/ static void -load_connections(NMSettingsPlugin * plugin, - NMSettingsPluginConnectionLoadEntry * entries, +load_connections(NMSettingsPlugin *plugin, + NMSettingsPluginConnectionLoadEntry *entries, gsize n_entries, NMSettingsPluginConnectionLoadCallback callback, gpointer user_data) { - NMSIfcfgRHPlugin * self = NMS_IFCFG_RH_PLUGIN(plugin); + NMSIfcfgRHPlugin *self = NMS_IFCFG_RH_PLUGIN(plugin); NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self); nm_auto_clear_sett_util_storages NMSettUtilStorages storages_new = NM_SETT_UTIL_STORAGES_INIT(storages_new, nms_ifcfg_rh_storage_destroy); gs_unref_hashtable GHashTable *dupl_filenames = NULL; gs_unref_hashtable GHashTable *storages_replaced = NULL; gs_unref_hashtable GHashTable *loaded_uuids = NULL; - const char * loaded_uuid; + const char *loaded_uuid; GHashTableIter h_iter; gsize i; @@ -430,12 +430,12 @@ load_connections(NMSettingsPlugin * plugin, for (i = 0; i < n_entries; i++) { NMSettingsPluginConnectionLoadEntry *const entry = &entries[i]; - gs_free_error GError * local = NULL; - const char * full_filename; - const char * uuid; - gs_free char * full_filename_keep = NULL; - NMSettingsPluginConnectionLoadEntry *dupl_content_entry; - gs_unref_object NMSIfcfgRHStorage *storage = NULL; + gs_free_error GError *local = NULL; + const char *full_filename; + const char *uuid; + gs_free char *full_filename_keep = NULL; + NMSettingsPluginConnectionLoadEntry *dupl_content_entry; + gs_unref_object NMSIfcfgRHStorage *storage = NULL; if (entry->handled) continue; @@ -499,7 +499,7 @@ load_connections(NMSettingsPlugin * plugin, /* now we visit all UUIDs that are about to change... */ g_hash_table_iter_init(&h_iter, loaded_uuids); while (g_hash_table_iter_next(&h_iter, (gpointer *) &loaded_uuid, NULL)) { - NMSIfcfgRHStorage * storage; + NMSIfcfgRHStorage *storage; NMSettUtilStorageByUuidHead *sbuh; sbuh = nm_sett_util_storages_lookup_by_uuid(&priv->storages, loaded_uuid); @@ -509,9 +509,9 @@ load_connections(NMSettingsPlugin * plugin, c_list_for_each_entry (storage, &sbuh->_storage_by_uuid_lst_head, parent._storage_by_uuid_lst) { - const char * full_filename = nms_ifcfg_rh_storage_get_filename(storage); + const char *full_filename = nms_ifcfg_rh_storage_get_filename(storage); gs_unref_object NMSIfcfgRHStorage *storage_new = NULL; - gs_free_error GError *local = NULL; + gs_free_error GError *local = NULL; if (g_hash_table_contains(dupl_filenames, full_filename)) { /* already re-loaded. */ @@ -544,11 +544,11 @@ load_connections(NMSettingsPlugin * plugin, } static void -reload_connections(NMSettingsPlugin * plugin, +reload_connections(NMSettingsPlugin *plugin, NMSettingsPluginConnectionLoadCallback callback, gpointer user_data) { - NMSIfcfgRHPlugin * self = NMS_IFCFG_RH_PLUGIN(plugin); + NMSIfcfgRHPlugin *self = NMS_IFCFG_RH_PLUGIN(plugin); nm_auto_clear_sett_util_storages NMSettUtilStorages storages_new = NM_SETT_UTIL_STORAGES_INIT(storages_new, nms_ifcfg_rh_storage_destroy); @@ -581,20 +581,20 @@ load_connections_done(NMSettingsPlugin *plugin) /*****************************************************************************/ static gboolean -add_connection(NMSettingsPlugin * plugin, - NMConnection * connection, +add_connection(NMSettingsPlugin *plugin, + NMConnection *connection, NMSettingsStorage **out_storage, - NMConnection ** out_connection, - GError ** error) + NMConnection **out_connection, + GError **error) { - NMSIfcfgRHPlugin * self = NMS_IFCFG_RH_PLUGIN(plugin); - NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self); - gs_unref_object NMSIfcfgRHStorage *storage = NULL; - gs_unref_object NMConnection *reread = NULL; - gs_free char * full_filename = NULL; - GError * local = NULL; - gboolean reread_same; - struct timespec mtime; + NMSIfcfgRHPlugin *self = NMS_IFCFG_RH_PLUGIN(plugin); + NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self); + gs_unref_object NMSIfcfgRHStorage *storage = NULL; + gs_unref_object NMConnection *reread = NULL; + gs_free char *full_filename = NULL; + GError *local = NULL; + gboolean reread_same; + struct timespec mtime; nm_assert_self(self, TRUE); nm_assert(NM_IS_CONNECTION(connection)); @@ -646,19 +646,19 @@ add_connection(NMSettingsPlugin * plugin, } static gboolean -update_connection(NMSettingsPlugin * plugin, - NMSettingsStorage * storage_x, - NMConnection * connection, +update_connection(NMSettingsPlugin *plugin, + NMSettingsStorage *storage_x, + NMConnection *connection, NMSettingsStorage **out_storage, - NMConnection ** out_connection, - GError ** error) + NMConnection **out_connection, + GError **error) { - NMSIfcfgRHPlugin * self = NMS_IFCFG_RH_PLUGIN(plugin); - NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self); - NMSIfcfgRHStorage * storage = NMS_IFCFG_RH_STORAGE(storage_x); - const char * full_filename; - const char * uuid; - GError * local = NULL; + NMSIfcfgRHPlugin *self = NMS_IFCFG_RH_PLUGIN(plugin); + NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self); + NMSIfcfgRHStorage *storage = NMS_IFCFG_RH_STORAGE(storage_x); + const char *full_filename; + const char *uuid; + GError *local = NULL; gs_unref_object NMConnection *reread = NULL; gboolean reread_same; struct timespec mtime; @@ -718,11 +718,11 @@ update_connection(NMSettingsPlugin * plugin, static gboolean delete_connection(NMSettingsPlugin *plugin, NMSettingsStorage *storage_x, GError **error) { - NMSIfcfgRHPlugin * self = NMS_IFCFG_RH_PLUGIN(plugin); + NMSIfcfgRHPlugin *self = NMS_IFCFG_RH_PLUGIN(plugin); NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self); - NMSIfcfgRHStorage * storage = NMS_IFCFG_RH_STORAGE(storage_x); - const char * operation_message; - const char * full_filename; + NMSIfcfgRHStorage *storage = NMS_IFCFG_RH_STORAGE(storage_x); + const char *operation_message; + const char *full_filename; nm_assert_self(self, TRUE); nm_assert(!error || !*error); @@ -736,9 +736,9 @@ delete_connection(NMSettingsPlugin *plugin, NMSettingsStorage *storage_x, GError nm_assert(storage == nm_sett_util_storages_lookup_by_filename(&priv->storages, full_filename)); { - gs_free char * keyfile = utils_get_keys_path(full_filename); - gs_free char * routefile = utils_get_route_path(full_filename); - gs_free char * route6file = utils_get_route6_path(full_filename); + gs_free char *keyfile = utils_get_keys_path(full_filename); + gs_free char *routefile = utils_get_route_path(full_filename); + gs_free char *route6file = utils_get_route6_path(full_filename); const char *const files[] = {full_filename, keyfile, routefile, route6file}; gboolean any_deleted = FALSE; gboolean any_failure = FALSE; @@ -784,10 +784,10 @@ delete_connection(NMSettingsPlugin *plugin, NMSettingsStorage *storage_x, GError static void _unhandled_specs_reset(NMSIfcfgRHPlugin *self) { - NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self); + NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self); gs_unref_hashtable GHashTable *unmanaged_specs = NULL; gs_unref_hashtable GHashTable *unrecognized_specs = NULL; - NMSIfcfgRHStorage * storage; + NMSIfcfgRHStorage *storage; unmanaged_specs = g_hash_table_new_full(nm_str_hash, g_str_equal, g_free, NULL); unrecognized_specs = g_hash_table_new_full(nm_str_hash, g_str_equal, g_free, NULL); @@ -820,7 +820,7 @@ _unhandled_specs_merge_storages(NMSIfcfgRHPlugin *self, NMSettUtilStorages *stor NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self); gboolean unmanaged_changed = FALSE; gboolean unrecognized_changed = FALSE; - NMSIfcfgRHStorage * storage; + NMSIfcfgRHStorage *storage; c_list_for_each_entry (storage, &storages->_storage_lst_head, parent._storage_lst) { if (storage->unmanaged_spec @@ -845,7 +845,7 @@ static GSList * _unhandled_specs_from_hashtable(GHashTable *hash) { gs_free const char **keys = NULL; - GSList * list = NULL; + GSList *list = NULL; guint i, l; keys = nm_strdict_get_keys(hash, TRUE, &l); @@ -873,15 +873,15 @@ get_unrecognized_specs(NMSettingsPlugin *plugin) /*****************************************************************************/ static void -impl_ifcfgrh_get_ifcfg_details(NMSIfcfgRHPlugin * self, +impl_ifcfgrh_get_ifcfg_details(NMSIfcfgRHPlugin *self, GDBusMethodInvocation *context, - const char * in_ifcfg) + const char *in_ifcfg) { NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self); - gs_free char * ifcfg_path = NULL; - NMSIfcfgRHStorage * storage; - const char * uuid; - const char * path; + gs_free char *ifcfg_path = NULL; + NMSIfcfgRHStorage *storage; + const char *uuid; + const char *path; if (in_ifcfg[0] != '/') { g_dbus_method_invocation_return_error(context, @@ -964,7 +964,7 @@ _dbus_clear(NMSIfcfgRHPlugin *self) static void _dbus_connection_closed(GDBusConnection *connection, gboolean remote_peer_vanished, - GError * error, + GError *error, gpointer user_data) { _LOGW("dbus: %s bus closed", IFCFGRH1_BUS_NAME); @@ -974,12 +974,12 @@ _dbus_connection_closed(GDBusConnection *connection, } static void -_method_call(GDBusConnection * connection, - const char * sender, - const char * object_path, - const char * interface_name, - const char * method_name, - GVariant * parameters, +_method_call(GDBusConnection *connection, + const char *sender, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data) { @@ -1014,11 +1014,11 @@ static GDBusInterfaceInfo *const interface_info = NM_DEFINE_GDBUS_INTERFACE_INFO static void _dbus_request_name_done(GObject *source_object, GAsyncResult *res, gpointer user_data) { - GDBusConnection * connection = G_DBUS_CONNECTION(source_object); - NMSIfcfgRHPlugin * self; - NMSIfcfgRHPluginPrivate *priv; - gs_free_error GError *error = NULL; - gs_unref_variant GVariant *ret = NULL; + GDBusConnection *connection = G_DBUS_CONNECTION(source_object); + NMSIfcfgRHPlugin *self; + NMSIfcfgRHPluginPrivate *priv; + gs_free_error GError *error = NULL; + gs_unref_variant GVariant *ret = NULL; guint32 result; ret = g_dbus_connection_call_finish(connection, res, &error); @@ -1072,10 +1072,10 @@ _dbus_request_name_done(GObject *source_object, GAsyncResult *res, gpointer user static void _dbus_create_done(GObject *source_object, GAsyncResult *res, gpointer user_data) { - NMSIfcfgRHPlugin * self; + NMSIfcfgRHPlugin *self; NMSIfcfgRHPluginPrivate *priv; - gs_free_error GError *error = NULL; - GDBusConnection * connection; + gs_free_error GError *error = NULL; + GDBusConnection *connection; connection = g_dbus_connection_new_for_address_finish(res, &error); if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) @@ -1117,8 +1117,8 @@ static void _dbus_setup(NMSIfcfgRHPlugin *self) { NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self); - gs_free char * address = NULL; - gs_free_error GError *error = NULL; + gs_free char *address = NULL; + gs_free_error GError *error = NULL; _dbus_clear(self); @@ -1147,11 +1147,11 @@ _dbus_setup(NMSIfcfgRHPlugin *self) } static void -config_changed_cb(NMConfig * config, - NMConfigData * config_data, +config_changed_cb(NMConfig *config, + NMConfigData *config_data, NMConfigChangeFlags changes, - NMConfigData * old_data, - NMSIfcfgRHPlugin * self) + NMConfigData *old_data, + NMSIfcfgRHPlugin *self) { NMSIfcfgRHPluginPrivate *priv; @@ -1188,7 +1188,7 @@ nms_ifcfg_rh_plugin_init(NMSIfcfgRHPlugin *self) static void constructed(GObject *object) { - NMSIfcfgRHPlugin * self = NMS_IFCFG_RH_PLUGIN(object); + NMSIfcfgRHPlugin *self = NMS_IFCFG_RH_PLUGIN(object); NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self); G_OBJECT_CLASS(nms_ifcfg_rh_plugin_parent_class)->constructed(object); @@ -1204,7 +1204,7 @@ constructed(GObject *object) static void dispose(GObject *object) { - NMSIfcfgRHPlugin * self = NMS_IFCFG_RH_PLUGIN(object); + NMSIfcfgRHPlugin *self = NMS_IFCFG_RH_PLUGIN(object); NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self); if (priv->config) @@ -1227,7 +1227,7 @@ dispose(GObject *object) static void nms_ifcfg_rh_plugin_class_init(NMSIfcfgRHPluginClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingsPluginClass *plugin_class = NM_SETTINGS_PLUGIN_CLASS(klass); object_class->constructed = constructed; @@ -1247,7 +1247,7 @@ nms_ifcfg_rh_plugin_class_init(NMSIfcfgRHPluginClass *klass) /*****************************************************************************/ G_MODULE_EXPORT NMSettingsPlugin * - nm_settings_plugin_factory(void) +nm_settings_plugin_factory(void) { return g_object_new(NMS_TYPE_IFCFG_RH_PLUGIN, NULL); } diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index 6dd5ef05..e62c0227 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -75,9 +75,9 @@ static char * get_full_file_path(const char *ifcfg_path, const char *file_path) { - const char * base = file_path; + const char *base = file_path; gs_free char *dirname = NULL; - char * p; + char *p; g_return_val_if_fail(ifcfg_path != NULL, NULL); g_return_val_if_fail(file_path != NULL, NULL); @@ -99,8 +99,8 @@ static NMSettingSecretFlags _secret_read_ifcfg_flags(shvarFile *ifcfg, const char *flags_key) { NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE; - gs_free char * val_free = NULL; - const char * val; + gs_free char *val_free = NULL; + const char *val; nm_assert(flags_key); nm_assert(g_str_has_suffix(flags_key, "_FLAGS")); @@ -118,10 +118,10 @@ _secret_read_ifcfg_flags(shvarFile *ifcfg, const char *flags_key) } static void -_secret_read_ifcfg(shvarFile * ifcfg, - shvarFile * keys_ifcfg, - const char * name, - char ** value, +_secret_read_ifcfg(shvarFile *ifcfg, + shvarFile *keys_ifcfg, + const char *name, + char **value, NMSettingSecretFlags *flags) { char flags_key[250]; @@ -141,8 +141,8 @@ _secret_read_ifcfg(shvarFile * ifcfg, static void _secret_set_from_ifcfg(gpointer setting, - shvarFile * ifcfg, - shvarFile * keys_ifcfg, + shvarFile *ifcfg, + shvarFile *keys_ifcfg, const char *ifcfg_key, const char *property_name) { @@ -165,8 +165,8 @@ _secret_set_from_ifcfg(gpointer setting, static gboolean _secret_password_raw_to_bytes(const char *ifcfg_key, const char *password_raw, - GBytes ** out_bytes, - GError ** error) + GBytes **out_bytes, + GError **error) { nm_auto_free_secret_buf NMSecretBuf *secret = NULL; gsize len; @@ -222,17 +222,17 @@ _cert_get_cert_bytes(const char *ifcfg_path, const char *value, GError **error) } static gboolean -_cert_get_cert(shvarFile * ifcfg, - const char * ifcfg_key, - GBytes ** out_cert, +_cert_get_cert(shvarFile *ifcfg, + const char *ifcfg_key, + GBytes **out_cert, NMSetting8021xCKScheme *out_scheme, - GError ** error) + GError **error) { nm_auto_free_secret char *val_free = NULL; - const char * val; - gs_unref_bytes GBytes *cert = NULL; - GError * local = NULL; - NMSetting8021xCKScheme scheme; + const char *val; + gs_unref_bytes GBytes *cert = NULL; + GError *local = NULL; + NMSetting8021xCKScheme scheme; val = svGetValueStr(ifcfg, ifcfg_key, &val_free); if (!val) { @@ -266,11 +266,11 @@ err: static gboolean _cert_set_from_ifcfg(gpointer setting, - shvarFile * ifcfg, + shvarFile *ifcfg, const char *ifcfg_key, const char *property_name, - GBytes ** out_cert, - GError ** error) + GBytes **out_cert, + GError **error) { gs_unref_bytes GBytes *cert = NULL; @@ -289,8 +289,8 @@ static void check_if_bond_slave(shvarFile *ifcfg, NMSettingConnection *s_con) { gs_free char *value = NULL; - const char * v; - const char * master; + const char *v; + const char *master; v = svGetValueStr(ifcfg, "MASTER_UUID", &value); if (!v) @@ -322,8 +322,8 @@ static void check_if_team_slave(shvarFile *ifcfg, NMSettingConnection *s_con) { gs_free char *value = NULL; - const char * v; - const char * master; + const char *v; + const char *master; v = svGetValueStr(ifcfg, "TEAM_MASTER_UUID", &value); if (!v) @@ -348,7 +348,7 @@ check_if_team_slave(shvarFile *ifcfg, NMSettingConnection *s_con) } static char * -make_connection_name(shvarFile * ifcfg, +make_connection_name(shvarFile *ifcfg, const char *ifcfg_name, const char *suggested, const char *prefix) @@ -378,21 +378,21 @@ make_connection_name(shvarFile * ifcfg, static NMSetting * make_connection_setting(const char *file, - shvarFile * ifcfg, + shvarFile *ifcfg, const char *type, const char *suggested, const char *prefix) { - NMSettingConnection * s_con; + NMSettingConnection *s_con; NMSettingConnectionLldp lldp; - const char * ifcfg_name = NULL; - gs_free char * new_id = NULL; - const char * uuid; - gs_free char * uuid_free = NULL; - gs_free char * value = NULL; - const char * v; - gs_free char * stable_id = NULL; - const char *const * iter; + const char *ifcfg_name = NULL; + gs_free char *new_id = NULL; + const char *uuid; + gs_free char *uuid_free = NULL; + gs_free char *value = NULL; + const char *v; + gs_free char *stable_id = NULL; + const char *const *iter; int vint64, i_val; ifcfg_name = utils_get_ifcfg_name(file, TRUE); @@ -597,7 +597,7 @@ make_connection_setting(const char *file, if (vint64 != -1) vint64 *= 1000; else if (v[0] != '\0') { - char * endptr; + char *endptr; double d; d = nm_g_ascii_strtod(v, &endptr); @@ -647,14 +647,14 @@ make_connection_setting(const char *file, } static gboolean -read_ip4_address(shvarFile * ifcfg, +read_ip4_address(shvarFile *ifcfg, const char *tag, - gboolean * out_has_key, - guint32 * out_addr, - GError ** error) + gboolean *out_has_key, + guint32 *out_addr, + GError **error) { gs_free char *value_to_free = NULL; - const char * value; + const char *value; in_addr_t a; nm_assert(ifcfg); @@ -714,18 +714,18 @@ is_any_ip4_address_defined(shvarFile *ifcfg, int *idx) /* Returns TRUE on missing address or valid address */ static gboolean -read_full_ip4_address(shvarFile * ifcfg, +read_full_ip4_address(shvarFile *ifcfg, gint32 which, - NMIPAddress * base_addr, + NMIPAddress *base_addr, NMIPAddress **out_address, - char ** out_gateway, - GError ** error) + char **out_gateway, + GError **error) { char tag[256]; char prefix_tag[256]; guint32 ipaddr; gs_free char *value = NULL; - const char * v; + const char *v; int prefix = 0; gboolean has_key; guint32 a; @@ -918,9 +918,9 @@ enum { static int parse_route_line(const char *line, int addr_family, - NMIPRoute * options_route, + NMIPRoute *options_route, NMIPRoute **out_route, - GError ** error) + GError **error) { static const ParseLineInfo parse_infos[] = { [PARSE_LINE_ATTR_ROUTE_TYPE] = @@ -1016,9 +1016,9 @@ parse_route_line(const char *line, }, }; nm_auto_unref_ip_route NMIPRoute *route = NULL; - gs_free const char ** words_free = NULL; - const char *const * words; - const char * s; + gs_free const char **words_free = NULL; + const char *const *words; + const char *s; gsize i_words; guint i; char buf1[256]; @@ -1054,7 +1054,7 @@ parse_route_line(const char *line, const gsize i_words0 = i_words; const char *const w = words[i_words0]; const ParseLineInfo *p_info; - ParseLineData * p_data; + ParseLineData *p_data; gboolean unqualified_addr = FALSE; for (i = 0; i < G_N_ELEMENTS(parse_infos); i++) { @@ -1343,7 +1343,7 @@ next:; for (i = 0; i < G_N_ELEMENTS(parse_infos); i++) { const ParseLineInfo *p_info = &parse_infos[i]; - ParseLineData * p_data = &parse_datas[i]; + ParseLineData *p_data = &parse_datas[i]; if (!p_data->has) continue; @@ -1414,7 +1414,7 @@ read_one_ip4_route(shvarFile *ifcfg, guint32 which, NMIPRoute **out_route, GErro guint32 next_hop; guint32 netmask; gboolean has_key; - const char * v; + const char *v; gs_free char *value = NULL; gint64 prefix, metric; char inet_buf[NM_UTILS_INET_ADDRSTRLEN]; @@ -1499,11 +1499,11 @@ read_one_ip4_route(shvarFile *ifcfg, guint32 which, NMIPRoute **out_route, GErro static gboolean read_route_file_parse(int addr_family, - const char * filename, - const char * contents, + const char *filename, + const char *contents, gsize len, NMSettingIPConfig *s_ip, - GError ** error) + GError **error) { gsize line_num; @@ -1517,10 +1517,10 @@ read_route_file_parse(int addr_family, line_num = 0; while (TRUE) { nm_auto_unref_ip_route NMIPRoute *route = NULL; - gs_free_error GError *local = NULL; - const char * line = contents; - char * eol; - int e; + gs_free_error GError *local = NULL; + const char *line = contents; + char *eol; + int e; eol = strchr(contents, '\n'); if (eol) { @@ -1582,7 +1582,7 @@ static void parse_dns_options(NMSettingIPConfig *ip_config, const char *value) { gs_free const char **options = NULL; - const char *const * item; + const char *const *item; g_return_if_fail(ip_config); @@ -1602,11 +1602,11 @@ parse_dns_options(NMSettingIPConfig *ip_config, const char *value) } static gboolean -parse_full_ip6_address(shvarFile * ifcfg, - const char * addr_str, +parse_full_ip6_address(shvarFile *ifcfg, + const char *addr_str, int i, NMIPAddress **out_address, - GError ** error) + GError **error) { NMIPAddress *addr; NMIPAddr addr_bin; @@ -1639,12 +1639,12 @@ parse_full_ip6_address(shvarFile * ifcfg, static NMSetting * make_user_setting(shvarFile *ifcfg) { - gboolean has_user_data = FALSE; - gs_unref_object NMSettingUser *s_user = NULL; - gs_unref_hashtable GHashTable *keys = NULL; + gboolean has_user_data = FALSE; + gs_unref_object NMSettingUser *s_user = NULL; + gs_unref_hashtable GHashTable *keys = NULL; GHashTableIter iter; - const char * key; - nm_auto_free_gstring GString *str = NULL; + const char *key; + nm_auto_free_gstring GString *str = NULL; keys = svGetKeys(ifcfg, SV_KEY_TYPE_USER); if (!keys) @@ -1652,7 +1652,7 @@ make_user_setting(shvarFile *ifcfg) g_hash_table_iter_init(&iter, keys); while (g_hash_table_iter_next(&iter, (gpointer *) &key, NULL)) { - const char * value; + const char *value; gs_free char *value_to_free = NULL; value = svGetValue(ifcfg, key, &value_to_free); @@ -1679,7 +1679,7 @@ make_user_setting(shvarFile *ifcfg) } static void -make_match_setting_prop(const char * v, +make_match_setting_prop(const char *v, NMSettingMatch **s_match, void (*add_fcn)(NMSettingMatch *s_match, const char *value)) { @@ -1700,11 +1700,11 @@ static NMSetting * make_match_setting(shvarFile *ifcfg) { NMSettingMatch *s_match = NULL; - gs_free char * value_ifn = NULL; - gs_free char * value_kcl = NULL; - gs_free char * value_d = NULL; - gs_free char * value_p = NULL; - const char * v; + gs_free char *value_ifn = NULL; + gs_free char *value_kcl = NULL; + gs_free char *value_d = NULL; + gs_free char *value_p = NULL; + const char *v; v = svGetValueStr(ifcfg, "MATCH_INTERFACE_NAME", &value_ifn); make_match_setting_prop(v, &s_match, nm_setting_match_add_interface_name); @@ -1721,9 +1721,9 @@ make_match_setting(shvarFile *ifcfg) static NMSetting * make_proxy_setting(shvarFile *ifcfg) { - NMSettingProxy * s_proxy = NULL; - gs_free char * value = NULL; - const char * v; + NMSettingProxy *s_proxy = NULL; + gs_free char *value = NULL; + const char *v; NMSettingProxyMethod method; v = svGetValueStr(ifcfg, "PROXY_METHOD", &value); @@ -1767,24 +1767,24 @@ static NMSetting * make_ip4_setting(shvarFile *ifcfg, shvarFile *network_ifcfg, gboolean routes_read, - gboolean * out_has_defroute, - GError ** error) + gboolean *out_has_defroute, + GError **error) { gs_unref_object NMSettingIPConfig *s_ip4 = NULL; - gs_free char * route_path = NULL; - gs_free char * value = NULL; - const char * v; - char * method; - gs_free char * dns_options_free = NULL; - const char * dns_options = NULL; - gs_free char * gateway = NULL; + gs_free char *route_path = NULL; + gs_free char *value = NULL; + const char *v; + char *method; + gs_free char *dns_options_free = NULL; + const char *dns_options = NULL; + gs_free char *gateway = NULL; int i; guint32 a; gboolean has_key; gboolean never_default; gint64 i64; int priority; - const char *const * item; + const char *const *item; guint32 route_table; nm_assert(out_has_defroute && !*out_has_defroute); @@ -1807,7 +1807,7 @@ make_ip4_setting(shvarFile *ifcfg, /* Then check if GATEWAYDEV; it's global and overrides DEFROUTE */ if (network_ifcfg) { gs_free char *gatewaydev_value = NULL; - const char * gatewaydev; + const char *gatewaydev; /* Get the connection ifcfg device name and the global gateway device */ v = svGetValueStr(ifcfg, "DEVICE", &value); @@ -2115,11 +2115,11 @@ make_ip4_setting(shvarFile *ifcfg, static void read_aliases(NMSettingIPConfig *s_ip4, gboolean read_defroute, const char *filename) { - GDir * dir; + GDir *dir; gs_free char *dirname = NULL; gs_free char *base = NULL; - NMIPAddress * base_addr = NULL; - GError * err = NULL; + NMIPAddress *base_addr = NULL; + GError *err = NULL; g_return_if_fail(s_ip4 != NULL); g_return_if_fail(filename != NULL); @@ -2134,17 +2134,17 @@ read_aliases(NMSettingIPConfig *s_ip4, gboolean read_defroute, const char *filen dir = g_dir_open(dirname, 0, &err); if (dir) { - const char * item; + const char *item; NMIPAddress *addr; gboolean ok; while ((item = g_dir_read_name(dir))) { nm_auto_shvar_file_close shvarFile *parsed = NULL; - gs_free char * gateway = NULL; - gs_free char * device_value = NULL; - gs_free char * full_path = NULL; - const char * device; - const char * p; + gs_free char *gateway = NULL; + gs_free char *device_value = NULL; + gs_free char *full_path = NULL; + const char *device; + const char *p; if (!utils_is_ifcfg_alias_file(item, base)) continue; @@ -2239,22 +2239,22 @@ static NMSetting * make_ip6_setting(shvarFile *ifcfg, shvarFile *network_ifcfg, gboolean routes_read, GError **error) { gs_unref_object NMSettingIPConfig *s_ip6 = NULL; - const char * v; - gs_free char * value = NULL; + const char *v; + gs_free char *value = NULL; gboolean ipv6init; gboolean ipv6forwarding; gboolean disabled; gboolean dhcp6 = FALSE; - char * method = NM_SETTING_IP6_CONFIG_METHOD_MANUAL; - const char * ipv6addr, *ipv6addr_secondaries; - gs_free char * ipv6addr_to_free = NULL; - gs_free char * ipv6addr_secondaries_to_free = NULL; - gs_free const char ** list = NULL; - const char *const * iter; + char *method = NM_SETTING_IP6_CONFIG_METHOD_MANUAL; + const char *ipv6addr, *ipv6addr_secondaries; + gs_free char *ipv6addr_to_free = NULL; + gs_free char *ipv6addr_secondaries_to_free = NULL; + gs_free const char **list = NULL; + const char *const *iter; guint32 i; gint64 i64; int i_val; - GError * local = NULL; + GError *local = NULL; int priority; gboolean never_default = FALSE; gboolean ip6_privacy = FALSE, ip6_privacy_prefer_public_ip; @@ -2276,10 +2276,10 @@ make_ip6_setting(shvarFile *ifcfg, shvarFile *network_ifcfg, gboolean routes_rea * When both are set, the device specified in IPV6_DEFAULTGW takes preference. */ if (network_ifcfg) { - const char * ipv6_defaultgw, *ipv6_defaultdev; + const char *ipv6_defaultgw, *ipv6_defaultdev; gs_free char *ipv6_defaultgw_to_free = NULL; gs_free char *ipv6_defaultdev_to_free = NULL; - const char * default_dev = NULL; + const char *default_dev = NULL; /* Get the connection ifcfg device name and the global default route device */ nm_clear_g_free(&value); @@ -2629,10 +2629,10 @@ static NMSetting * make_sriov_setting(shvarFile *ifcfg) { gs_unref_hashtable GHashTable *keys = NULL; - gs_unref_ptrarray GPtrArray *vfs = NULL; - int autoprobe_drivers; - NMSettingSriov * s_sriov; - gint64 total_vfs; + gs_unref_ptrarray GPtrArray *vfs = NULL; + int autoprobe_drivers; + NMSettingSriov *s_sriov; + gint64 total_vfs; total_vfs = svGetValueInt64(ifcfg, "SRIOV_TOTAL_VFS", 10, 0, G_MAXUINT32, -1); @@ -2646,14 +2646,14 @@ make_sriov_setting(shvarFile *ifcfg) keys = svGetKeys(ifcfg, SV_KEY_TYPE_SRIOV_VF); if (keys) { GHashTableIter iter; - const char * key; + const char *key; g_hash_table_iter_init(&iter, keys); while (g_hash_table_iter_next(&iter, (gpointer *) &key, NULL)) { gs_free_error GError *error = NULL; - gs_free char * value_to_free = NULL; - const char * value; - NMSriovVF * vf; + gs_free char *value_to_free = NULL; + const char *value; + NMSriovVF *vf; nm_assert(g_str_has_prefix(key, "SRIOV_VF")); @@ -2705,10 +2705,10 @@ make_tc_setting(shvarFile *ifcfg) s_tc = (NMSettingTCConfig *) nm_setting_tc_config_new(); for (i = 1;; i++) { - NMTCQdisc * qdisc = NULL; + NMTCQdisc *qdisc = NULL; gs_free char *value_to_free = NULL; - const char * value = NULL; - GError * local = NULL; + const char *value = NULL; + GError *local = NULL; value = svGetValueStr(ifcfg, numbered_tag(tag, "QDISC", i), &value_to_free); if (!value) @@ -2727,10 +2727,10 @@ make_tc_setting(shvarFile *ifcfg) } for (i = 1;; i++) { - NMTCTfilter * tfilter = NULL; - gs_free char *value_to_free = NULL; - const char * value = NULL; - gs_free_error GError *local = NULL; + NMTCTfilter *tfilter = NULL; + gs_free char *value_to_free = NULL; + const char *value = NULL; + gs_free_error GError *local = NULL; value = svGetValueStr(ifcfg, numbered_tag(tag, "FILTER", i), &value_to_free); if (!value) @@ -2812,16 +2812,16 @@ read_dcb_flags(shvarFile *ifcfg, DcbFlagsProperty *property) } static gboolean -read_dcb_app(shvarFile * ifcfg, - NMSettingDcb * s_dcb, - const char * app, +read_dcb_app(shvarFile *ifcfg, + NMSettingDcb *s_dcb, + const char *app, DcbFlagsProperty *flags_prop, - const char * priority_prop, - GError ** error) + const char *priority_prop, + GError **error) { NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE; - gs_free char * value = NULL; - const char * v; + gs_free char *value = NULL; + const char *v; gboolean success = TRUE; int priority = -1; char key[255]; @@ -2862,16 +2862,16 @@ read_dcb_app(shvarFile * ifcfg, typedef void (*DcbSetBoolFunc)(NMSettingDcb *, guint, gboolean); static gboolean -read_dcb_bool_array(shvarFile * ifcfg, - NMSettingDcb * s_dcb, +read_dcb_bool_array(shvarFile *ifcfg, + NMSettingDcb *s_dcb, NMSettingDcbFlags flags, - const char * prop, - const char * desc, + const char *prop, + const char *desc, DcbSetBoolFunc set_func, - GError ** error) + GError **error) { gs_free char *value = NULL; - const char * v; + const char *v; guint i; v = svGetValueStr(ifcfg, prop, &value); @@ -2910,14 +2910,14 @@ read_dcb_bool_array(shvarFile * ifcfg, typedef void (*DcbSetUintFunc)(NMSettingDcb *, guint, guint); static gboolean -read_dcb_uint_array(shvarFile * ifcfg, - NMSettingDcb * s_dcb, +read_dcb_uint_array(shvarFile *ifcfg, + NMSettingDcb *s_dcb, NMSettingDcbFlags flags, - const char * prop, - const char * desc, + const char *prop, + const char *desc, gboolean f_allowed, DcbSetUintFunc set_func, - GError ** error) + GError **error) { gs_free char *val = NULL; guint i; @@ -2963,18 +2963,18 @@ read_dcb_uint_array(shvarFile * ifcfg, } static gboolean -read_dcb_percent_array(shvarFile * ifcfg, - NMSettingDcb * s_dcb, +read_dcb_percent_array(shvarFile *ifcfg, + NMSettingDcb *s_dcb, NMSettingDcbFlags flags, - const char * prop, - const char * desc, + const char *prop, + const char *desc, gboolean sum_pct, DcbSetUintFunc set_func, - GError ** error) + GError **error) { - gs_free char * val = NULL; + gs_free char *val = NULL; gs_free const char **split = NULL; - const char *const * iter; + const char *const *iter; guint i, sum = 0; val = svGetValueStr_cp(ifcfg, prop); @@ -3030,7 +3030,7 @@ make_dcb_setting(shvarFile *ifcfg, NMSetting **out_setting, GError **error) gs_unref_object NMSettingDcb *s_dcb = NULL; gboolean dcb_on; NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE; - gs_free char * val = NULL; + gs_free char *val = NULL; g_return_val_if_fail(out_setting, FALSE); *out_setting = NULL; @@ -3165,16 +3165,16 @@ make_dcb_setting(shvarFile *ifcfg, NMSetting **out_setting, GError **error) } static gboolean -add_one_wep_key(shvarFile * ifcfg, - const char * shvar_key, +add_one_wep_key(shvarFile *ifcfg, + const char *shvar_key, guint8 key_idx, gboolean passphrase, NMSettingWirelessSecurity *s_wsec, - GError ** error) + GError **error) { gs_free char *value_free = NULL; - const char * value; - const char * key = NULL; + const char *value; + const char *key = NULL; g_return_val_if_fail(ifcfg != NULL, FALSE); g_return_val_if_fail(shvar_key != NULL, FALSE); @@ -3233,11 +3233,11 @@ add_one_wep_key(shvarFile * ifcfg, } static gboolean -read_wep_keys(shvarFile * ifcfg, +read_wep_keys(shvarFile *ifcfg, NMWepKeyType key_type, guint8 def_idx, NMSettingWirelessSecurity *s_wsec, - GError ** error) + GError **error) { if (key_type != NM_WEP_KEY_TYPE_PASSPHRASE) { if (!add_one_wep_key(ifcfg, "KEY1", 0, FALSE, s_wsec, error)) @@ -3270,8 +3270,8 @@ static NMSetting * make_wep_setting(shvarFile *ifcfg, const char *file, GError **error) { gs_unref_object NMSettingWirelessSecurity *s_wsec = NULL; - gs_free char * value = NULL; - shvarFile * keys_ifcfg = NULL; + gs_free char *value = NULL; + shvarFile *keys_ifcfg = NULL; int default_key_idx = 0; gboolean has_default_key = FALSE; NMSettingSecretFlags key_flags; @@ -3306,7 +3306,7 @@ make_wep_setting(shvarFile *ifcfg, const char *file, GError **error) /* Read keys in the ifcfg file if they are system-owned */ if (key_flags == NM_SETTING_SECRET_FLAG_NONE) { NMWepKeyType key_type; - const char * v; + const char *v; gs_free char *to_free = NULL; v = svGetValueStr(ifcfg, "KEY_TYPE", &to_free); @@ -3393,10 +3393,10 @@ make_wep_setting(shvarFile *ifcfg, const char *file, GError **error) static gboolean fill_wpa_ciphers(shvarFile *ifcfg, NMSettingWirelessSecurity *wsec, gboolean group, gboolean adhoc) { - gs_free char * value = NULL; - const char * p; + gs_free char *value = NULL; + const char *p; gs_free const char **list = NULL; - const char *const * iter; + const char *const *iter; int i = 0; p = svGetValueStr(ifcfg, group ? "CIPHER_GROUP" : "CIPHER_PAIRWISE", &value); @@ -3434,7 +3434,7 @@ fill_wpa_ciphers(shvarFile *ifcfg, NMSettingWirelessSecurity *wsec, gboolean gro static char * parse_wpa_psk(shvarFile *ifcfg, const char *file, GBytes *ssid, GError **error) { - shvarFile * keys_ifcfg; + shvarFile *keys_ifcfg; gs_free char *psk = NULL; size_t plen; @@ -3484,17 +3484,17 @@ parse_wpa_psk(shvarFile *ifcfg, const char *file, GBytes *ssid, GError **error) } static gboolean -eap_simple_reader(const char * eap_method, - shvarFile * ifcfg, - shvarFile * keys_ifcfg, +eap_simple_reader(const char *eap_method, + shvarFile *ifcfg, + shvarFile *keys_ifcfg, NMSetting8021x *s_8021x, gboolean phase2, - GError ** error) + GError **error) { NMSettingSecretFlags flags; - gs_free char * identity_free = NULL; - nm_auto_free_secret char *password_raw_str = NULL; - gs_unref_bytes GBytes *password_raw_bytes = NULL; + gs_free char *identity_free = NULL; + nm_auto_free_secret char *password_raw_str = NULL; + gs_unref_bytes GBytes *password_raw_bytes = NULL; g_object_set(s_8021x, NM_SETTING_802_1X_IDENTITY, @@ -3525,19 +3525,19 @@ eap_simple_reader(const char * eap_method, } static gboolean -eap_tls_reader(const char * eap_method, - shvarFile * ifcfg, - shvarFile * keys_ifcfg, +eap_tls_reader(const char *eap_method, + shvarFile *ifcfg, + shvarFile *keys_ifcfg, NMSetting8021x *s_8021x, gboolean phase2, - GError ** error) + GError **error) { gs_unref_bytes GBytes *privkey = NULL; gs_unref_bytes GBytes *client_cert = NULL; - gs_free char * identity_free = NULL; - gs_free char * value_to_free = NULL; - const char * client_cert_var; - const char * client_cert_prop; + gs_free char *identity_free = NULL; + gs_free char *value_to_free = NULL; + const char *client_cert_var; + const char *client_cert_prop; NMSetting8021xCKFormat format; g_object_set(s_8021x, @@ -3616,16 +3616,16 @@ eap_tls_reader(const char * eap_method, } static gboolean -parse_8021x_phase2_auth(shvarFile * ifcfg, - shvarFile * keys_ifcfg, +parse_8021x_phase2_auth(shvarFile *ifcfg, + shvarFile *keys_ifcfg, NMSetting8021x *s_8021x, - GError ** error) + GError **error) { - gs_free char * inner_auth = NULL; - gs_free char * v_free = NULL; - const char * v; + gs_free char *inner_auth = NULL; + gs_free char *v_free = NULL; + const char *v; gs_free const char **list = NULL; - const char *const * iter; + const char *const *iter; guint num_auth = 0; guint num_autheap = 0; @@ -3699,15 +3699,15 @@ parse_8021x_phase2_auth(shvarFile * ifcfg, } static gboolean -eap_peap_reader(const char * eap_method, - shvarFile * ifcfg, - shvarFile * keys_ifcfg, +eap_peap_reader(const char *eap_method, + shvarFile *ifcfg, + shvarFile *keys_ifcfg, NMSetting8021x *s_8021x, gboolean phase2, - GError ** error) + GError **error) { gs_free char *value = NULL; - const char * v; + const char *v; if (!_cert_set_from_ifcfg(s_8021x, ifcfg, @@ -3754,15 +3754,15 @@ eap_peap_reader(const char * eap_method, } static gboolean -eap_ttls_reader(const char * eap_method, - shvarFile * ifcfg, - shvarFile * keys_ifcfg, +eap_ttls_reader(const char *eap_method, + shvarFile *ifcfg, + shvarFile *keys_ifcfg, NMSetting8021x *s_8021x, gboolean phase2, - GError ** error) + GError **error) { gs_free char *value = NULL; - const char * v; + const char *v; if (!_cert_set_from_ifcfg(s_8021x, ifcfg, @@ -3789,19 +3789,19 @@ eap_ttls_reader(const char * eap_method, } static gboolean -eap_fast_reader(const char * eap_method, - shvarFile * ifcfg, - shvarFile * keys_ifcfg, +eap_fast_reader(const char *eap_method, + shvarFile *ifcfg, + shvarFile *keys_ifcfg, NMSetting8021x *s_8021x, gboolean phase2, - GError ** error) + GError **error) { - gs_free char * anon_ident = NULL; - gs_free char * pac_file = NULL; - gs_free char * real_pac_path = NULL; - gs_free char * fast_provisioning = NULL; + gs_free char *anon_ident = NULL; + gs_free char *pac_file = NULL; + gs_free char *real_pac_path = NULL; + gs_free char *fast_provisioning = NULL; const char *const *iter; - const char * pac_prov_str; + const char *pac_prov_str; gboolean allow_unauth = FALSE, allow_auth = FALSE; pac_file = svGetValueStr_cp(ifcfg, "IEEE_8021X_PAC_FILE"); @@ -3852,12 +3852,12 @@ eap_fast_reader(const char * eap_method, typedef struct { const char *method; - gboolean (*reader)(const char * eap_method, - shvarFile * ifcfg, - shvarFile * keys_ifcfg, + gboolean (*reader)(const char *eap_method, + shvarFile *ifcfg, + shvarFile *keys_ifcfg, NMSetting8021x *s_8021x, gboolean phase2, - GError ** error); + GError **error); gboolean wifi_phase2_only; } EAPReader; @@ -3875,14 +3875,14 @@ static EAPReader eap_readers[] = {{"md5", eap_simple_reader, TRUE}, {NULL, NULL}}; static void -read_8021x_list_value(shvarFile * ifcfg, - const char * ifcfg_var_name, +read_8021x_list_value(shvarFile *ifcfg, + const char *ifcfg_var_name, NMSetting8021x *setting, - const char * prop_name) + const char *prop_name) { - gs_free char * value = NULL; + gs_free char *value = NULL; gs_free const char **strv = NULL; - const char * v; + const char *v; g_return_if_fail(ifcfg != NULL); g_return_if_fail(ifcfg_var_name != NULL); @@ -3901,13 +3901,13 @@ static NMSetting8021x * fill_8021x(shvarFile *ifcfg, const char *file, const char *key_mgmt, gboolean wifi, GError **error) { nm_auto_shvar_file_close shvarFile *keys_ifcfg = NULL; - gs_unref_object NMSetting8021x *s_8021x = NULL; - gs_free char * value = NULL; - const char * v; - gs_free const char ** list = NULL; - const char *const * iter; - gint64 timeout; - int i_val; + gs_unref_object NMSetting8021x *s_8021x = NULL; + gs_free char *value = NULL; + const char *v; + gs_free const char **list = NULL; + const char *const *iter; + gint64 timeout; + int i_val; v = svGetValueStr(ifcfg, "IEEE_8021X_EAP_METHODS", &value); if (!v) { @@ -3928,7 +3928,7 @@ fill_8021x(shvarFile *ifcfg, const char *file, const char *key_mgmt, gboolean wi /* Validate and handle each EAP method */ for (iter = list; iter && *iter; iter++) { - EAPReader * eap = &eap_readers[0]; + EAPReader *eap = &eap_readers[0]; gboolean found = FALSE; gs_free char *lower = NULL; @@ -4040,16 +4040,16 @@ next: } static NMSetting * -make_wpa_setting(shvarFile * ifcfg, - const char * file, - GBytes * ssid, +make_wpa_setting(shvarFile *ifcfg, + const char *file, + GBytes *ssid, gboolean adhoc, NMSetting8021x **s_8021x, - GError ** error) + GError **error) { gs_unref_object NMSettingWirelessSecurity *wsec = NULL; - gs_free char * value = NULL; - const char * v; + gs_free char *value = NULL; + const char *v; gboolean wpa_psk = FALSE, wpa_sae = FALSE, wpa_owe = FALSE, wpa_eap = FALSE, ieee8021x = FALSE, wpa3_eap = FALSE; int i_val; @@ -4089,7 +4089,7 @@ make_wpa_setting(shvarFile * ifcfg, nm_setting_wireless_security_add_proto(wsec, "rsn"); } else { gs_free char *value2 = NULL; - const char * v2; + const char *v2; v2 = svGetValueStr(ifcfg, "WPA_ALLOW_WPA", &value2); if (v2 && svParseBoolean(v2, TRUE)) @@ -4175,8 +4175,8 @@ static NMSetting * make_leap_setting(shvarFile *ifcfg, const char *file, GError **error) { gs_unref_object NMSettingWirelessSecurity *wsec = NULL; - shvarFile * keys_ifcfg; - gs_free char * value = NULL; + shvarFile *keys_ifcfg; + gs_free char *value = NULL; NMSettingSecretFlags flags; wsec = NM_SETTING_WIRELESS_SECURITY(nm_setting_wireless_security_new()); @@ -4232,12 +4232,12 @@ make_leap_setting(shvarFile *ifcfg, const char *file, GError **error) } static NMSetting * -make_wireless_security_setting(shvarFile * ifcfg, - const char * file, - GBytes * ssid, +make_wireless_security_setting(shvarFile *ifcfg, + const char *file, + GBytes *ssid, gboolean adhoc, NMSetting8021x **s_8021x, - GError ** error) + GError **error) { NMSetting *wsec; @@ -4291,9 +4291,9 @@ transform_hwaddr_blacklist(const char *blacklist) static NMSetting * make_wireless_setting(shvarFile *ifcfg, GError **error) { - NMSettingWireless * s_wireless; - const char * cvalue; - char * value = NULL; + NMSettingWireless *s_wireless; + const char *cvalue; + char *value = NULL; gint64 chan = 0; NMSettingMacRandomization mac_randomization; NMSettingWirelessPowersave powersave = NM_SETTING_WIRELESS_POWERSAVE_DEFAULT; @@ -4360,7 +4360,7 @@ make_wireless_setting(shvarFile *ifcfg, GError **error) value = svGetValueStr_cp(ifcfg, "MODE"); if (value) { - char * lcase; + char *lcase; const char *mode = NULL; lcase = g_ascii_strdown(value, -1); @@ -4540,16 +4540,16 @@ error: static NMConnection * wireless_connection_from_ifcfg(const char *file, shvarFile *ifcfg, GError **error) { - NMConnection * connection = NULL; - NMSetting * con_setting = NULL; - NMSetting * wireless_setting = NULL; + NMConnection *connection = NULL; + NMSetting *con_setting = NULL; + NMSetting *wireless_setting = NULL; NMSetting8021x *s_8021x = NULL; - GBytes * ssid; - NMSetting * security_setting = NULL; - gs_free char * ssid_utf8 = NULL; - const char * mode; + GBytes *ssid; + NMSetting *security_setting = NULL; + gs_free char *ssid_utf8 = NULL; + const char *mode; gboolean adhoc = FALSE; - GError * local = NULL; + GError *local = NULL; g_return_val_if_fail(file != NULL, NULL); g_return_val_if_fail(ifcfg != NULL, NULL); @@ -4619,12 +4619,12 @@ typedef struct { * pointing to the next unprocessed option or NULL * in case of failure */ static const char ** -_next_ethtool_options_nmternary(const char ** words, +_next_ethtool_options_nmternary(const char **words, NMEthtoolType ethtool_type, NMEthtoolIfcfgOption *out_value) { - const char * opt; - const char * opt_val; + const char *opt; + const char *opt_val; const NMEthtoolData *d = NULL; NMTernary onoff = NM_TERNARY_DEFAULT; @@ -4671,13 +4671,13 @@ _next_ethtool_options_nmternary(const char ** words, * pointing to the next unprocessed option or NULL * in case of failure */ static const char ** -_next_ethtool_options_uint32(const char ** words, +_next_ethtool_options_uint32(const char **words, NMEthtoolType ethtool_type, NMEthtoolIfcfgOption *out_value) { gint64 i64; - const char * opt; - const char * opt_val; + const char *opt; + const char *opt_val; const NMEthtoolData *d = NULL; nm_assert(out_value); @@ -4727,16 +4727,16 @@ static NM_UTILS_STRING_TABLE_LOOKUP_DEFINE( {"-K", NM_ETHTOOL_TYPE_FEATURE}, ); static void -parse_ethtool_option(const char * value, +parse_ethtool_option(const char *value, NMSettingWiredWakeOnLan *out_flags, - char ** out_password, - gboolean * out_autoneg, - guint32 * out_speed, - const char ** out_duplex, - NMSettingEthtool ** out_s_ethtool) + char **out_password, + gboolean *out_autoneg, + guint32 *out_speed, + const char **out_duplex, + NMSettingEthtool **out_s_ethtool) { guint i; - const char ** w_iter; + const char **w_iter; NMEthtoolIfcfgOption ifcfg_option; gs_free const char **words = NULL; NMEthtoolType ethtool_type = NM_ETHTOOL_TYPE_UNKNOWN; @@ -4904,7 +4904,7 @@ static GPtrArray * read_routing_rules_parse(shvarFile *ifcfg, gboolean routes_read) { gs_unref_ptrarray GPtrArray *arr = NULL; - gs_free const char ** keys = NULL; + gs_free const char **keys = NULL; guint i, len; keys = svGetKeysSorted(ifcfg, SV_KEY_TYPE_ROUTING_RULE4 | SV_KEY_TYPE_ROUTING_RULE6, &len); @@ -4919,12 +4919,12 @@ read_routing_rules_parse(shvarFile *ifcfg, gboolean routes_read) arr = g_ptr_array_new_full(len, (GDestroyNotify) nm_ip_routing_rule_unref); for (i = 0; i < len; i++) { - const char * key = keys[i]; - nm_auto_unref_ip_routing_rule NMIPRoutingRule *rule = NULL; - gs_free_error GError *local = NULL; - gs_free char * value_to_free = NULL; - const char * value; - gboolean key_is_ipv4; + const char *key = keys[i]; + nm_auto_unref_ip_routing_rule NMIPRoutingRule *rule = NULL; + gs_free_error GError *local = NULL; + gs_free char *value_to_free = NULL; + const char *value; + gboolean key_is_ipv4; key_is_ipv4 = (key[NM_STRLEN("ROUTING_RULE")] == '_'); nm_assert(key_is_ipv4 == NM_STR_HAS_PREFIX(key, "ROUTING_RULE_")); @@ -4956,7 +4956,7 @@ read_routing_rules_parse(shvarFile *ifcfg, gboolean routes_read) } static void -read_routing_rules(shvarFile * ifcfg, +read_routing_rules(shvarFile *ifcfg, gboolean routes_read, NMSettingIPConfig *s_ip4, NMSettingIPConfig *s_ip6) @@ -4980,17 +4980,17 @@ read_routing_rules(shvarFile * ifcfg, static void parse_ethtool_options(shvarFile *ifcfg, NMConnection *connection) { - NMSettingWired *s_wired; + NMSettingWired *s_wired; gs_unref_object NMSettingEthtool *s_ethtool = NULL; NMSettingWiredWakeOnLan wol_flags = NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT; - gs_free char * ethtool_opts_free = NULL; - const char * ethtool_opts; - gs_free char * wol_password = NULL; - gs_free char * wol_value_free = NULL; - const char * tmp; + gs_free char *ethtool_opts_free = NULL; + const char *ethtool_opts; + gs_free char *wol_password = NULL; + gs_free char *wol_value_free = NULL; + const char *tmp; gboolean autoneg = FALSE; guint32 speed = 0; - const char * duplex = NULL; + const char *duplex = NULL; gboolean wired_found = FALSE; ethtool_opts = svGetValue(ifcfg, "ETHTOOL_OPTS", ðtool_opts_free); @@ -5001,7 +5001,7 @@ parse_ethtool_options(shvarFile *ifcfg, NMConnection *connection) wol_flags = NM_SETTING_WIRED_WAKE_ON_LAN_IGNORE; else { gs_free const char **opts = NULL; - const char *const * iter; + const char *const *iter; opts = nm_strsplit_set(ethtool_opts, ";"); for (iter = opts; iter && iter[0]; iter++) { @@ -5061,8 +5061,8 @@ static NMSetting * make_wired_setting(shvarFile *ifcfg, const char *file, NMSetting8021x **s_8021x, GError **error) { gs_unref_object NMSettingWired *s_wired = NULL; - const char * cvalue; - gs_free char * value = NULL; + const char *cvalue; + gs_free char *value = NULL; gboolean found = FALSE; NMTernary accept_all_mac_addresses; @@ -5246,11 +5246,11 @@ make_wired_setting(shvarFile *ifcfg, const char *file, NMSetting8021x **s_8021x, static NMConnection * wired_connection_from_ifcfg(const char *file, shvarFile *ifcfg, GError **error) { - NMConnection * connection = NULL; - NMSetting * con_setting = NULL; - NMSetting * wired_setting = NULL; + NMConnection *connection = NULL; + NMSetting *con_setting = NULL; + NMSetting *wired_setting = NULL; NMSetting8021x *s_8021x = NULL; - GError * local = NULL; + GError *local = NULL; g_return_val_if_fail(file != NULL, NULL); g_return_val_if_fail(ifcfg != NULL, NULL); @@ -5288,8 +5288,8 @@ wired_connection_from_ifcfg(const char *file, shvarFile *ifcfg, GError **error) static gboolean parse_infiniband_p_key(shvarFile *ifcfg, int *out_p_key, char **out_parent, GError **error) { - char * device = NULL, *physdev = NULL, *pkey_id = NULL; - char * ifname = NULL; + char *device = NULL, *physdev = NULL, *pkey_id = NULL; + char *ifname = NULL; int id; gboolean ret = FALSE; @@ -5347,7 +5347,7 @@ static NMSetting * make_infiniband_setting(shvarFile *ifcfg, const char *file, GError **error) { NMSettingInfiniband *s_infiniband; - char * value = NULL; + char *value = NULL; s_infiniband = NM_SETTING_INFINIBAND(nm_setting_infiniband_new()); @@ -5399,8 +5399,8 @@ static NMConnection * infiniband_connection_from_ifcfg(const char *file, shvarFile *ifcfg, GError **error) { NMConnection *connection = NULL; - NMSetting * con_setting = NULL; - NMSetting * infiniband_setting = NULL; + NMSetting *con_setting = NULL; + NMSetting *infiniband_setting = NULL; g_return_val_if_fail(file != NULL, NULL); g_return_val_if_fail(ifcfg != NULL, NULL); @@ -5433,7 +5433,7 @@ static void handle_bond_option(NMSettingBond *s_bond, const char *key, const char *value) { gs_free char *sanitized = NULL; - const char * p = value; + const char *p = value; /* Remove any quotes or +/- from arp_ip_target */ if (nm_streq0(key, NM_SETTING_BOND_OPTION_ARP_IP_TARGET) && value && value[0]) { @@ -5463,8 +5463,8 @@ static NMSetting * make_bond_setting(shvarFile *ifcfg, const char *file, GError **error) { NMSettingBond *s_bond; - gs_free char * value = NULL; - const char * v; + gs_free char *value = NULL; + const char *v; v = svGetValueStr(ifcfg, "DEVICE", &value); if (!v) { @@ -5481,12 +5481,12 @@ make_bond_setting(shvarFile *ifcfg, const char *file, GError **error) v = svGetValueStr(ifcfg, "BONDING_OPTS", &value); if (v) { gs_free const char **items = NULL; - const char *const * iter; + const char *const *iter; items = nm_strsplit_set(v, " "); for (iter = items; iter && *iter; iter++) { gs_free char *key = NULL; - const char * val; + const char *val; val = strchr(*iter, '='); if (!val) @@ -5504,9 +5504,9 @@ make_bond_setting(shvarFile *ifcfg, const char *file, GError **error) static NMSetting * make_bond_port_setting(shvarFile *ifcfg) { - NMSetting * s_port = NULL; + NMSetting *s_port = NULL; gs_free char *value_to_free = NULL; - const char * value; + const char *value; guint queue_id; g_return_val_if_fail(ifcfg != NULL, FALSE); @@ -5529,12 +5529,12 @@ make_bond_port_setting(shvarFile *ifcfg) static NMConnection * bond_connection_from_ifcfg(const char *file, shvarFile *ifcfg, GError **error) { - NMConnection * connection = NULL; - NMSetting * con_setting = NULL; - NMSetting * bond_setting = NULL; - NMSetting * wired_setting = NULL; + NMConnection *connection = NULL; + NMSetting *con_setting = NULL; + NMSetting *bond_setting = NULL; + NMSetting *wired_setting = NULL; NMSetting8021x *s_8021x = NULL; - GError * local = NULL; + GError *local = NULL; g_return_val_if_fail(file != NULL, NULL); g_return_val_if_fail(ifcfg != NULL, NULL); @@ -5580,7 +5580,7 @@ bond_connection_from_ifcfg(const char *file, shvarFile *ifcfg, GError **error) static NMSetting * make_team_setting(shvarFile *ifcfg, const char *file, GError **error) { - NMSetting * s_team; + NMSetting *s_team; gs_free char *value_device = NULL; gs_free char *value = NULL; @@ -5600,12 +5600,12 @@ make_team_setting(shvarFile *ifcfg, const char *file, GError **error) static NMConnection * team_connection_from_ifcfg(const char *file, shvarFile *ifcfg, GError **error) { - NMConnection * connection = NULL; - NMSetting * con_setting = NULL; - NMSetting * team_setting = NULL; - NMSetting * wired_setting = NULL; + NMConnection *connection = NULL; + NMSetting *con_setting = NULL; + NMSetting *team_setting = NULL; + NMSetting *wired_setting = NULL; NMSetting8021x *s_8021x = NULL; - GError * local = NULL; + GError *local = NULL; g_return_val_if_fail(file != NULL, NULL); g_return_val_if_fail(ifcfg != NULL, NULL); @@ -5655,22 +5655,22 @@ typedef enum { BRIDGE_OPT_TYPE_PORT_OPTION, } BridgeOptType; -typedef void (*BridgeOptFunc)(NMSetting * setting, +typedef void (*BridgeOptFunc)(NMSetting *setting, gboolean stp, - const char * key, - const char * value, + const char *key, + const char *value, BridgeOptType opt_type); static void -handle_bridge_option(NMSetting * setting, +handle_bridge_option(NMSetting *setting, gboolean stp, - const char * key, - const char * value, + const char *key, + const char *value, BridgeOptType opt_type) { static const struct { - const char * key; - const char * property_name; + const char *key; + const char *property_name; BridgeOptType opt_type; gboolean only_with_stp; gboolean extended_bool; @@ -5809,19 +5809,19 @@ warn: } static void -handle_bridging_opts(NMSetting * setting, +handle_bridging_opts(NMSetting *setting, gboolean stp, - const char * value, + const char *value, BridgeOptFunc func, BridgeOptType opt_type) { gs_free const char **items = NULL; - const char *const * iter; + const char *const *iter; items = nm_strsplit_set(value, " "); for (iter = items; iter && *iter; iter++) { gs_free char *key = NULL; - const char * val; + const char *val; val = strchr(*iter, '='); if (!val) @@ -5837,15 +5837,15 @@ static void read_bridge_vlans(shvarFile *ifcfg, const char *key, NMSetting *setting, const char *property) { gs_unref_ptrarray GPtrArray *array = NULL; - gs_free char * value_to_free = NULL; - const char * value; + gs_free char *value_to_free = NULL; + const char *value; value = svGetValueStr(ifcfg, key, &value_to_free); if (value) { gs_free const char **strv = NULL; - const char *const * iter; - GError * local = NULL; - NMBridgeVlan * vlan; + const char *const *iter; + GError *local = NULL; + NMBridgeVlan *vlan; array = g_ptr_array_new_with_free_func((GDestroyNotify) nm_bridge_vlan_unref); @@ -5871,8 +5871,8 @@ static NMSetting * make_bridge_setting(shvarFile *ifcfg, const char *file, GError **error) { gs_unref_object NMSettingBridge *s_bridge = NULL; - gs_free char * value_to_free = NULL; - const char * value; + gs_free char *value_to_free = NULL; + const char *value; gboolean stp = FALSE; gboolean stp_set = FALSE; @@ -5937,12 +5937,12 @@ make_bridge_setting(shvarFile *ifcfg, const char *file, GError **error) static NMConnection * bridge_connection_from_ifcfg(const char *file, shvarFile *ifcfg, GError **error) { - NMConnection * connection = NULL; - NMSetting * con_setting = NULL; - NMSetting * bridge_setting = NULL; - NMSetting * wired_setting = NULL; + NMConnection *connection = NULL; + NMSetting *con_setting = NULL; + NMSetting *bridge_setting = NULL; + NMSetting *wired_setting = NULL; NMSetting8021x *s_8021x = NULL; - GError * local = NULL; + GError *local = NULL; g_return_val_if_fail(file != NULL, NULL); g_return_val_if_fail(ifcfg != NULL, NULL); @@ -5988,9 +5988,9 @@ bridge_connection_from_ifcfg(const char *file, shvarFile *ifcfg, GError **error) static NMSetting * make_bridge_port_setting(shvarFile *ifcfg) { - NMSetting * s_port = NULL; + NMSetting *s_port = NULL; gs_free char *value_to_free = NULL; - const char * value; + const char *value; g_return_val_if_fail(ifcfg != NULL, FALSE); @@ -6020,7 +6020,7 @@ make_bridge_port_setting(shvarFile *ifcfg) static NMSetting * make_team_port_setting(shvarFile *ifcfg) { - NMSetting * s_port; + NMSetting *s_port; gs_free char *value = NULL; value = svGetValueStr_cp(ifcfg, "TEAM_PORT_CONFIG"); @@ -6071,10 +6071,10 @@ is_wifi_device(const char *name, shvarFile *parsed) static void parse_prio_map_list(NMSettingVlan *s_vlan, shvarFile *ifcfg, const char *key, NMVlanPriorityMap map) { - gs_free char * value = NULL; + gs_free char *value = NULL; gs_free const char **list = NULL; - const char *const * iter; - const char * v; + const char *const *iter; + const char *v; v = svGetValueStr(ifcfg, key, &value); if (!v) @@ -6093,10 +6093,10 @@ static NMSetting * make_vlan_setting(shvarFile *ifcfg, const char *file, GError **error) { gs_unref_object NMSettingVlan *s_vlan = NULL; - gs_free char * parent = NULL; - gs_free char * iface_name = NULL; - gs_free char * value = NULL; - const char * v = NULL; + gs_free char *parent = NULL; + gs_free char *iface_name = NULL; + gs_free char *value = NULL; + const char *v = NULL; int vlan_id = -1; guint32 vlan_flags = 0; int gvrp, reorder_hdr; @@ -6188,7 +6188,7 @@ make_vlan_setting(shvarFile *ifcfg, const char *file, GError **error) v = svGetValueStr(ifcfg, "VLAN_FLAGS", &value); if (v) { gs_free const char **strv = NULL; - const char *const * ptr; + const char *const *ptr; strv = nm_strsplit_set(v, ", "); for (ptr = strv; ptr && *ptr; ptr++) { @@ -6219,12 +6219,12 @@ make_vlan_setting(shvarFile *ifcfg, const char *file, GError **error) static NMConnection * vlan_connection_from_ifcfg(const char *file, shvarFile *ifcfg, GError **error) { - NMConnection * connection = NULL; - NMSetting * con_setting = NULL; - NMSetting * wired_setting = NULL; - NMSetting * vlan_setting = NULL; + NMConnection *connection = NULL; + NMSetting *con_setting = NULL; + NMSetting *wired_setting = NULL; + NMSetting *vlan_setting = NULL; NMSetting8021x *s_8021x = NULL; - GError * local = NULL; + GError *local = NULL; g_return_val_if_fail(file != NULL, NULL); g_return_val_if_fail(ifcfg != NULL, NULL); @@ -6268,14 +6268,14 @@ vlan_connection_from_ifcfg(const char *file, shvarFile *ifcfg, GError **error) static NMConnection * create_unhandled_connection(const char *filename, - shvarFile * ifcfg, + shvarFile *ifcfg, const char *type, - char ** out_spec) + char **out_spec) { NMConnection *connection; - NMSetting * s_con; + NMSetting *s_con; gs_free char *value = NULL; - const char * v; + const char *v; nm_assert(out_spec && !*out_spec); @@ -6329,12 +6329,12 @@ check_dns_search_domains(shvarFile *ifcfg, NMSetting *s_ip4, NMSetting *s_ip6) if (!s_ip4 || nm_setting_ip_config_get_num_dns_searches(NM_SETTING_IP_CONFIG(s_ip4)) == 0) { /* DNS searches */ gs_free char *value = NULL; - const char * v; + const char *v; v = svGetValueStr(ifcfg, "DOMAIN", &value); if (v) { gs_free const char **searches = NULL; - const char *const * item; + const char *const *item; searches = nm_strsplit_set(v, " "); if (searches) { @@ -6351,23 +6351,23 @@ static NMConnection * connection_from_file_full(const char *filename, const char *network_file, /* for unit tests only */ const char *test_type, /* for unit tests only */ - char ** out_unhandled, - GError ** error, - gboolean * out_ignore_error) + char **out_unhandled, + GError **error, + gboolean *out_ignore_error) { nm_auto_shvar_file_close shvarFile *main_ifcfg = NULL; nm_auto_shvar_file_close shvarFile *network_ifcfg = NULL; - gs_unref_object NMConnection *connection = NULL; - gs_free char * type = NULL; - char * devtype, *bootproto; - NMSetting * setting; - NMSetting * s_ip4; - NMSetting * s_ip6; - const char * ifcfg_name = NULL; - gs_free char * s_tmp = NULL; - gboolean has_ip4_defroute = FALSE; - gboolean has_complex_routes_v4; - gboolean has_complex_routes_v6; + gs_unref_object NMConnection *connection = NULL; + gs_free char *type = NULL; + char *devtype, *bootproto; + NMSetting *setting; + NMSetting *s_ip4; + NMSetting *s_ip6; + const char *ifcfg_name = NULL; + gs_free char *s_tmp = NULL; + gboolean has_ip4_defroute = FALSE; + gboolean has_complex_routes_v4; + gboolean has_complex_routes_v6; g_return_val_if_fail(filename != NULL, NULL); g_return_val_if_fail(out_unhandled && !*out_unhandled, NULL); @@ -6463,7 +6463,7 @@ connection_from_file_full(const char *filename, if (!type) { gs_free char *tmp = NULL; - char * device; + char *device; if ((tmp = svGetValueStr_cp(main_ifcfg, "IPV6TUNNELIPV4"))) { NM_SET_OUT(out_ignore_error, TRUE); @@ -6503,7 +6503,7 @@ connection_from_file_full(const char *filename, type = g_strdup(TYPE_WIRELESS); else { gs_free char *p_path = NULL; - char * p_device; + char *p_device; gsize i; /* network-functions detects DEVICETYPE based on the ifcfg-* name and the existence @@ -6714,9 +6714,9 @@ connection_from_file_full(const char *filename, NMConnection * connection_from_file(const char *filename, - char ** out_unhandled, - GError ** error, - gboolean * out_ignore_error) + char **out_unhandled, + GError **error, + gboolean *out_ignore_error) { return connection_from_file_full(filename, NULL, NULL, out_unhandled, error, out_ignore_error); } @@ -6725,8 +6725,8 @@ NMConnection * nmtst_connection_from_file(const char *filename, const char *network_file, const char *test_type, - char ** out_unhandled, - GError ** error) + char **out_unhandled, + GError **error) { return connection_from_file_full(filename, network_file, test_type, out_unhandled, error, NULL); } diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.h b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.h index c7dc2240..c38432b7 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.h +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.h @@ -9,14 +9,14 @@ #include "nm-connection.h" NMConnection *connection_from_file(const char *filename, - char ** out_unhandled, - GError ** error, - gboolean * out_ignore_error); + char **out_unhandled, + GError **error, + gboolean *out_ignore_error); NMConnection *nmtst_connection_from_file(const char *filename, const char *network_file, const char *test_type, - char ** out_unhandled, - GError ** error); + char **out_unhandled, + GError **error); #endif /* __NMS_IFCFG_RH_READER_H__ */ diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-storage.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-storage.c index 3feb4440..16632861 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-storage.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-storage.c @@ -103,9 +103,9 @@ _storage_new(NMSIfcfgRHPlugin *plugin, const char *uuid, const char *filename) } NMSIfcfgRHStorage * -nms_ifcfg_rh_storage_new_connection(NMSIfcfgRHPlugin * plugin, - const char * filename, - NMConnection * connection_take, +nms_ifcfg_rh_storage_new_connection(NMSIfcfgRHPlugin *plugin, + const char *filename, + NMConnection *connection_take, const struct timespec *mtime) { NMSIfcfgRHStorage *self; @@ -123,9 +123,9 @@ nms_ifcfg_rh_storage_new_connection(NMSIfcfgRHPlugin * plugin, NMSIfcfgRHStorage * nms_ifcfg_rh_storage_new_unhandled(NMSIfcfgRHPlugin *plugin, - const char * filename, - const char * unmanaged_spec, - const char * unrecognized_spec) + const char *filename, + const char *unmanaged_spec, + const char *unrecognized_spec) { NMSIfcfgRHStorage *self; @@ -167,7 +167,7 @@ nms_ifcfg_rh_storage_destroy(NMSIfcfgRHStorage *self) static void nms_ifcfg_rh_storage_class_init(NMSIfcfgRHStorageClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingsStorageClass *storage_class = NM_SETTINGS_STORAGE_CLASS(klass); object_class->dispose = dispose; diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-storage.h b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-storage.h index 6fb9838f..2ab6beb6 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-storage.h +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-storage.h @@ -45,14 +45,14 @@ GType nms_ifcfg_rh_storage_get_type(void); struct _NMSIfcfgRHPlugin; NMSIfcfgRHStorage *nms_ifcfg_rh_storage_new_connection(struct _NMSIfcfgRHPlugin *plugin, - const char * filename, - NMConnection * connection_take, - const struct timespec * mtime); + const char *filename, + NMConnection *connection_take, + const struct timespec *mtime); NMSIfcfgRHStorage *nms_ifcfg_rh_storage_new_unhandled(struct _NMSIfcfgRHPlugin *plugin, - const char * filename, - const char * unmanaged_spec, - const char * unrecognized_spec); + const char *filename, + const char *unmanaged_spec, + const char *unrecognized_spec); void nms_ifcfg_rh_storage_destroy(NMSIfcfgRHStorage *self); diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c index 1afdf8ee..15e01ba9 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c @@ -17,7 +17,7 @@ /*****************************************************************************/ gboolean -nms_ifcfg_rh_utils_parse_unhandled_spec(const char * unhandled_spec, +nms_ifcfg_rh_utils_parse_unhandled_spec(const char *unhandled_spec, const char **out_unmanaged_spec, const char **out_unrecognized_spec) { @@ -108,7 +108,7 @@ char * utils_cert_path(const char *parent, const char *suffix, const char *extension) { gs_free char *dir = NULL; - const char * name; + const char *name; g_return_val_if_fail(parent, NULL); g_return_val_if_fail(suffix, NULL); @@ -171,7 +171,7 @@ utils_get_ifcfg_name(const char *file, gboolean only_ifcfg) static char * utils_get_extra_path(const char *parent, const char *tag) { - char * item_path = NULL, *dirname; + char *item_path = NULL, *dirname; const char *name; g_return_val_if_fail(parent != NULL, NULL); @@ -221,7 +221,7 @@ shvarFile * utils_get_extra_ifcfg(const char *parent, const char *tag, gboolean should_create) { shvarFile *ifcfg = NULL; - char * path; + char *path; path = utils_get_extra_path(parent, tag); if (!path) @@ -275,7 +275,7 @@ utils_has_route_file_new_syntax_content(const char *contents, gsize len) while (TRUE) { const char *line = contents; - char * eol; + char *eol; gboolean found = FALSE; /* matches regex "^[[:space:]]*ADDRESS[0-9]+=" */ @@ -374,7 +374,7 @@ utils_detect_ifcfg_path(const char *path, gboolean only_ifcfg) return NULL; if (utils_is_ifcfg_alias_file(base, NULL)) { gs_free char *ifcfg = NULL; - char * ptr; + char *ptr; ifcfg = g_strdup(path); ptr = strrchr(ifcfg, ':'); @@ -773,7 +773,7 @@ gboolean nms_ifcfg_rh_utils_is_numbered_tag_impl(const char *key, const char *tag, gsize tag_len, - gint64 * out_idx) + gint64 *out_idx) { gint64 idx; diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h index 6b396a9a..d7a1cfc6 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h @@ -29,7 +29,7 @@ typedef enum { } NMSIfcfgKeyTypeFlags; typedef struct { - const char * key_name; + const char *key_name; NMSIfcfgKeyTypeFlags key_flags; } NMSIfcfgKeyTypeInfo; @@ -50,7 +50,7 @@ nms_ifcfg_well_known_key_find_info_flags(const char *key) /*****************************************************************************/ -gboolean nms_ifcfg_rh_utils_parse_unhandled_spec(const char * unhandled_spec, +gboolean nms_ifcfg_rh_utils_parse_unhandled_spec(const char *unhandled_spec, const char **out_unmanaged_spec, const char **out_unrecognized_spec); @@ -127,7 +127,7 @@ _nms_ifcfg_rh_utils_numbered_tag(char *buf, gsize buf_len, const char *tag_name, gboolean nms_ifcfg_rh_utils_is_numbered_tag_impl(const char *key, const char *tag, gsize tag_len, - gint64 * out_idx); + gint64 *out_idx); static inline gboolean nms_ifcfg_rh_utils_is_numbered_tag(const char *key, const char *tag, gint64 *out_idx) @@ -158,7 +158,7 @@ nms_ifcfg_rh_utils_get_ethtool_name(NMEthtoolID ethtool_id) return _nm_ethtool_ifcfg_names[ethtool_id]; } -const NMEthtoolData *nms_ifcfg_rh_utils_get_ethtool_by_name(const char * name, +const NMEthtoolData *nms_ifcfg_rh_utils_get_ethtool_by_name(const char *name, NMEthtoolType ethtool_type); #endif /* _UTILS_H_ */ diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c index 263c9253..48c4cae9 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -94,11 +94,11 @@ save_secret_flags(shvarFile *ifcfg, const char *key, NMSettingSecretFlags flags) } static void -set_secret(shvarFile * ifcfg, - GHashTable * secrets, - const char * key, - const char * value, - const char * flags_key, +set_secret(shvarFile *ifcfg, + GHashTable *secrets, + const char *key, + const char *value, + const char *flags_key, NMSettingSecretFlags flags) { /* Save secret flags */ @@ -114,14 +114,14 @@ set_secret(shvarFile * ifcfg, static gboolean write_secrets(shvarFile *ifcfg, GHashTable *secrets, GError **error) { - nm_auto_shvar_file_close shvarFile *keyfile = NULL; - gs_free NMUtilsNamedValue *secrets_arr_free = NULL; - NMUtilsNamedValue secrets_arr_static[30]; - const NMUtilsNamedValue * secrets_arr; - guint secrets_len; - GError * local = NULL; - gboolean any_secrets = FALSE; - guint i; + nm_auto_shvar_file_close shvarFile *keyfile = NULL; + gs_free NMUtilsNamedValue *secrets_arr_free = NULL; + NMUtilsNamedValue secrets_arr_static[30]; + const NMUtilsNamedValue *secrets_arr; + guint secrets_len; + GError *local = NULL; + gboolean any_secrets = FALSE; + guint i; keyfile = utils_get_keys_ifcfg(svFileGetName(ifcfg), TRUE); if (!keyfile) { @@ -164,7 +164,7 @@ write_secrets(shvarFile *ifcfg, GHashTable *secrets, GError **error) typedef struct { const NMSetting8021xSchemeVtable *vtable; - const char * ifcfg_rh_key; + const char *ifcfg_rh_key; } Setting8021xSchemeVtable; static const Setting8021xSchemeVtable setting_8021x_scheme_vtable[] = { @@ -184,23 +184,23 @@ static const Setting8021xSchemeVtable setting_8021x_scheme_vtable[] = { }; static gboolean -write_object(NMSetting8021x * s_8021x, - shvarFile * ifcfg, - GHashTable * secrets, - GHashTable * blobs, +write_object(NMSetting8021x *s_8021x, + shvarFile *ifcfg, + GHashTable *secrets, + GHashTable *blobs, const Setting8021xSchemeVtable *objtype, gboolean force_write, - GError ** error) + GError **error) { NMSetting8021xCKScheme scheme; - const char * value = NULL; - GBytes * blob = NULL; - const char * password = NULL; + const char *value = NULL; + GBytes *blob = NULL; + const char *password = NULL; NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE; char secret_name[100]; char secret_flags[sizeof(secret_name) + NM_STRLEN("_FLAGS")]; - const char * extension; - char * standard_file; + const char *extension; + char *standard_file; g_return_val_if_fail(ifcfg != NULL, FALSE); g_return_val_if_fail(objtype != NULL, FALSE); @@ -277,8 +277,8 @@ static gboolean write_blobs(GHashTable *blobs, GError **error) { GHashTableIter iter; - const char * filename; - GBytes * blob; + const char *filename; + GBytes *blob; if (!blobs) return TRUE; @@ -318,14 +318,14 @@ write_blobs(GHashTable *blobs, GError **error) static gboolean write_8021x_certs(NMSetting8021x *s_8021x, - GHashTable * secrets, - GHashTable * blobs, + GHashTable *secrets, + GHashTable *blobs, gboolean phase2, - shvarFile * ifcfg, - GError ** error) + shvarFile *ifcfg, + GError **error) { const Setting8021xSchemeVtable *pk_otype = NULL; - gs_free char * value_to_free = NULL; + gs_free char *value_to_free = NULL; /* CA certificate */ if (!write_object( @@ -371,20 +371,20 @@ write_8021x_certs(NMSetting8021x *s_8021x, static gboolean write_8021x_setting(NMConnection *connection, - shvarFile * ifcfg, - GHashTable * secrets, - GHashTable * blobs, + shvarFile *ifcfg, + GHashTable *secrets, + GHashTable *blobs, gboolean wired, - GError ** error) + GError **error) { - NMSetting8021x * s_8021x; + NMSetting8021x *s_8021x; NMSetting8021xAuthFlags auth_flags; - const char * value, *match; + const char *value, *match; gconstpointer ptr; - GBytes * bytes; - char * tmp = NULL; - GString * phase2_auth; - GString * str; + GBytes *bytes; + char *tmp = NULL; + GString *phase2_auth; + GString *str; guint32 i, num; gsize size; int vint; @@ -565,20 +565,20 @@ write_8021x_setting(NMConnection *connection, static gboolean write_wireless_security_setting(NMConnection *connection, - shvarFile * ifcfg, - GHashTable * secrets, + shvarFile *ifcfg, + GHashTable *secrets, gboolean adhoc, - gboolean * no_8021x, - GError ** error) + gboolean *no_8021x, + GError **error) { - NMSettingWirelessSecurity * s_wsec; - const char * key_mgmt, *auth_alg, *key, *proto, *cipher; - const char * psk = NULL; + NMSettingWirelessSecurity *s_wsec; + const char *key_mgmt, *auth_alg, *key, *proto, *cipher; + const char *psk = NULL; gboolean wep = FALSE, wpa = FALSE, dynamic_wep = FALSE; NMSettingWirelessSecurityWpsMethod wps_method; - char * tmp; + char *tmp; guint32 i, num; - GString * str; + GString *str; s_wsec = nm_connection_get_setting_wireless_security(connection); if (!s_wsec) { @@ -667,7 +667,7 @@ write_wireless_security_setting(NMConnection *connection, /* And write the new ones out */ if (wep) { NMWepKeyType key_type; - const char * key_type_str = NULL; + const char *key_type_str = NULL; /* Default WEP TX key index */ svSetValueInt64(ifcfg, @@ -711,7 +711,7 @@ write_wireless_security_setting(NMConnection *connection, numbered_tag(tag, "KEY", i + 1); /* Add 's:' prefix for ASCII keys */ - if (strlen(key) == 5 || strlen(key) == 13) { + if (NM_IN_SET(strlen(key), 5, 13)) { ascii_key = g_strdup_printf("s:%s", key); key = ascii_key; } @@ -759,7 +759,7 @@ write_wireless_security_setting(NMConnection *connection, g_free(tmp); } } - if (strlen(str->str) && (dynamic_wep == FALSE)) + if (nm_str_not_empty(str->str) && !dynamic_wep) svSetValueStr(ifcfg, "CIPHER_PAIRWISE", str->str); g_string_free(str, TRUE); @@ -809,17 +809,17 @@ write_wireless_security_setting(NMConnection *connection, static gboolean write_wireless_setting(NMConnection *connection, - shvarFile * ifcfg, - GHashTable * secrets, - gboolean * no_8021x, - GError ** error) + shvarFile *ifcfg, + GHashTable *secrets, + gboolean *no_8021x, + GError **error) { NMSettingWireless *s_wireless; - GBytes * ssid; - const guint8 * ssid_data; + GBytes *ssid; + const guint8 *ssid_data; gsize ssid_len; - const char * mode, *bssid; - const char * device_mac, *cloned_mac; + const char *mode, *bssid; + const char *device_mac, *cloned_mac; guint32 mtu, chan, i; gboolean adhoc = FALSE, hex_ssid = FALSE; const char *const *macaddr_blacklist; @@ -1018,7 +1018,7 @@ static gboolean write_infiniband_setting(NMConnection *connection, shvarFile *ifcfg, GError **error) { NMSettingInfiniband *s_infiniband; - const char * mac, *transport_mode, *parent; + const char *mac, *transport_mode, *parent; guint32 mtu; int p_key; @@ -1223,14 +1223,14 @@ _ethtool_gstring_prepare(GString **str, gboolean *is_first, char cmdline_flag, c static gboolean write_ethtool_setting(NMConnection *connection, shvarFile *ifcfg, GError **error) { - NMSettingWired * s_wired; - NMSettingEthtool * s_ethtool; - const char * duplex; + NMSettingWired *s_wired; + NMSettingEthtool *s_ethtool; + const char *duplex; guint32 speed; - GString * str = NULL; + GString *str = NULL; gboolean auto_negotiate; NMSettingWiredWakeOnLan wol; - const char * wol_password; + const char *wol_password; s_wired = nm_connection_get_setting_wired(connection); s_ethtool = NM_SETTING_ETHTOOL(nm_connection_get_setting(connection, NM_TYPE_SETTING_ETHTOOL)); @@ -1300,7 +1300,7 @@ write_ethtool_setting(NMConnection *connection, shvarFile *ifcfg, GError **error if (s_ethtool) { NMEthtoolID ethtool_id; NMSettingConnection *s_con; - const char * iface; + const char *iface; gboolean is_first; guint32 u32; gboolean b; @@ -1398,7 +1398,7 @@ static char * vlan_priority_maplist_to_stringlist(NMSettingVlan *s_vlan, NMVlanPriorityMap map) { char **strlist; - char * value; + char *value; if (map == NM_VLAN_INGRESS_MAP) g_object_get(G_OBJECT(s_vlan), NM_SETTING_VLAN_INGRESS_PRIORITY_MAP, &strlist, NULL); @@ -1420,7 +1420,7 @@ static gboolean write_vlan_setting(NMConnection *connection, shvarFile *ifcfg, gboolean *wired, GError **error) { NMSettingVlan *s_vlan; - char * tmp; + char *tmp; guint32 vlan_flags = 0; gsize s_buf_len; char s_buf[50], *s_buf_ptr; @@ -1486,7 +1486,7 @@ write_bond_setting(NMConnection *connection, shvarFile *ifcfg, gboolean *wired, num_opts = nm_setting_bond_get_num_options(s_bond); if (num_opts) { nm_auto_free_gstring GString *str = NULL; - const char * name, *value; + const char *name, *value; str = g_string_sized_new(64); for (i = 0; i < num_opts; i++) { @@ -1511,7 +1511,7 @@ static gboolean write_team_setting(NMConnection *connection, shvarFile *ifcfg, gboolean *wired, GError **error) { NMSettingTeam *s_team; - const char * config; + const char *config; s_team = nm_connection_get_setting_team(connection); if (!s_team) { @@ -1562,14 +1562,14 @@ write_team_setting(NMConnection *connection, shvarFile *ifcfg, gboolean *wired, }) static gboolean -write_bridge_vlans(NMSetting * setting, +write_bridge_vlans(NMSetting *setting, gboolean is_port, - shvarFile * ifcfg, + shvarFile *ifcfg, const char *key, - GError ** error) + GError **error) { - GPtrArray * vlans; - NMBridgeVlan * vlan; + GPtrArray *vlans; + NMBridgeVlan *vlan; nm_auto_str_buf NMStrBuf strbuf = NM_STR_BUF_INIT(0, FALSE); guint i; @@ -1608,8 +1608,8 @@ write_bridge_setting(NMConnection *connection, shvarFile *ifcfg, gboolean *wired guint64 u64; guint u; gboolean b; - const char * s; - GString * opts; + const char *s; + GString *opts; s_bridge = nm_connection_get_setting_bridge(connection); if (!s_bridge) { @@ -1847,7 +1847,7 @@ write_bridge_port_setting(NMConnection *connection, shvarFile *ifcfg, GError **e { NMSettingBridgePort *s_port; guint32 u32; - GString * string; + GString *string; s_port = nm_connection_get_setting_bridge_port(connection); if (!s_port) @@ -1903,7 +1903,7 @@ static gboolean write_team_port_setting(NMConnection *connection, shvarFile *ifcfg, GError **error) { NMSettingTeamPort *s_port; - const char * config; + const char *config; s_port = nm_connection_get_setting_team_port(connection); if (!s_port) @@ -1946,9 +1946,9 @@ write_dcb_app(shvarFile *ifcfg, const char *tag, NMSettingDcbFlags flags, int pr typedef gboolean (*DcbGetBoolFunc)(NMSettingDcb *, guint); static void -write_dcb_bool_array(shvarFile * ifcfg, - const char * key, - NMSettingDcb * s_dcb, +write_dcb_bool_array(shvarFile *ifcfg, + const char *key, + NMSettingDcb *s_dcb, NMSettingDcbFlags flags, DcbGetBoolFunc get_func) { @@ -1967,9 +1967,9 @@ write_dcb_bool_array(shvarFile * ifcfg, typedef guint (*DcbGetUintFunc)(NMSettingDcb *, guint); static void -write_dcb_uint_array(shvarFile * ifcfg, - const char * key, - NMSettingDcb * s_dcb, +write_dcb_uint_array(shvarFile *ifcfg, + const char *key, + NMSettingDcb *s_dcb, NMSettingDcbFlags flags, DcbGetUintFunc get_func) { @@ -1993,9 +1993,9 @@ write_dcb_uint_array(shvarFile * ifcfg, } static void -write_dcb_percent_array(shvarFile * ifcfg, - const char * key, - NMSettingDcb * s_dcb, +write_dcb_percent_array(shvarFile *ifcfg, + const char *key, + NMSettingDcb *s_dcb, NMSettingDcbFlags flags, DcbGetUintFunc get_func) { @@ -2018,7 +2018,7 @@ write_dcb_percent_array(shvarFile * ifcfg, static gboolean write_dcb_setting(NMConnection *connection, shvarFile *ifcfg, GError **error) { - NMSettingDcb * s_dcb; + NMSettingDcb *s_dcb; NMSettingDcbFlags flags; s_dcb = nm_connection_get_setting_dcb(connection); @@ -2079,16 +2079,16 @@ write_dcb_setting(NMConnection *connection, shvarFile *ifcfg, GError **error) static void write_connection_setting(NMSettingConnection *s_con, shvarFile *ifcfg) { - guint32 n, i; + guint32 n, i; nm_auto_free_gstring GString *str = NULL; - const char * master, *master_iface = NULL, *type; + const char *master, *master_iface = NULL, *type; int vint; gint32 vint32; NMSettingConnectionMdns mdns; NMSettingConnectionLlmnr llmnr; NMSettingConnectionDnsOverTls dns_over_tls; guint32 vuint32; - const char * tmp, *mud_url; + const char *tmp, *mud_url; svSetValueStr(ifcfg, "NAME", nm_setting_connection_get_id(s_con)); svSetValueStr(ifcfg, "UUID", nm_setting_connection_get_uuid(s_con)); @@ -2284,8 +2284,8 @@ static char * get_route_attributes_string(NMIPRoute *route, int family) { gs_free const char **names = NULL; - GVariant * attr, *lock; - GString * str; + GVariant *attr, *lock; + GString *str; guint i, len; names = _nm_ip_route_get_attribute_names(route, TRUE, &len); @@ -2369,7 +2369,7 @@ write_route_file_svformat(const char *filename, NMSettingIPConfig *s_ip4) num = nm_setting_ip_config_get_num_routes(s_ip4); for (i = 0; i < num; i++) { char buf[INET_ADDRSTRLEN]; - NMIPRoute * route; + NMIPRoute *route; guint32 netmask; gint64 metric; char addr_key[64]; @@ -2409,7 +2409,7 @@ write_route_file_svformat(const char *filename, NMSettingIPConfig *s_ip4) static GString * write_route_file(NMSettingIPConfig *s_ip) { - GString * contents; + GString *contents; NMIPRoute *route; guint32 i, num; int addr_family; @@ -2424,7 +2424,7 @@ write_route_file(NMSettingIPConfig *s_ip) for (i = 0; i < num; i++) { gs_free char *options = NULL; - const char * next_hop; + const char *next_hop; gint64 metric; route = nm_setting_ip_config_get_route(s_ip, i); @@ -2454,9 +2454,9 @@ write_route_file(NMSettingIPConfig *s_ip) static gboolean write_proxy_setting(NMConnection *connection, shvarFile *ifcfg, GError **error) { - NMSettingProxy * s_proxy; + NMSettingProxy *s_proxy; NMSettingProxyMethod method; - const char * pac_url, *pac_script; + const char *pac_url, *pac_script; s_proxy = nm_connection_get_setting_proxy(connection); if (!s_proxy) @@ -2489,7 +2489,7 @@ write_proxy_setting(NMConnection *connection, shvarFile *ifcfg, GError **error) static gboolean write_user_setting(NMConnection *connection, shvarFile *ifcfg, GError **error) { - NMSettingUser * s_user; + NMSettingUser *s_user; guint i, len; const char *const *keys; @@ -2521,9 +2521,9 @@ write_sriov_setting(NMConnection *connection, shvarFile *ifcfg) NMSettingSriov *s_sriov; guint i, num = 0; NMTernary b; - NMSriovVF * vf; + NMSriovVF *vf; char key[32]; - char * str; + char *str; s_sriov = NM_SETTING_SRIOV(nm_connection_get_setting(connection, NM_TYPE_SETTING_SRIOV)); if (!s_sriov) { @@ -2562,7 +2562,7 @@ write_tc_setting(NMConnection *connection, shvarFile *ifcfg) num_qdiscs = nm_setting_tc_config_get_num_qdiscs(s_tc); for (n = 1, i = 0; i < num_qdiscs; i++) { - NMTCQdisc * qdisc; + NMTCQdisc *qdisc; gs_free char *str = NULL; qdisc = nm_setting_tc_config_get_qdisc(s_tc, i); @@ -2574,7 +2574,7 @@ write_tc_setting(NMConnection *connection, shvarFile *ifcfg) num_filters = nm_setting_tc_config_get_num_tfilters(s_tc); for (n = 1, i = 0; i < num_filters; i++) { - NMTCTfilter * tfilter; + NMTCTfilter *tfilter; gs_free char *str = NULL; tfilter = nm_setting_tc_config_get_tfilter(s_tc, i); @@ -2592,9 +2592,9 @@ static void write_match_setting(NMConnection *connection, shvarFile *ifcfg) { nm_auto_free_gstring GString *str = NULL; - NMSettingMatch * s_match; + NMSettingMatch *s_match; guint i, num; - const char * name; + const char *name; s_match = (NMSettingMatch *) nm_connection_get_setting(connection, NM_TYPE_SETTING_MATCH); if (!s_match) @@ -2706,25 +2706,25 @@ write_dns_setting(shvarFile *ifcfg, NMConnection *connection, int addr_family) static void write_ip4_setting(NMConnection *connection, - shvarFile * ifcfg, - shvarFile ** out_route_content_svformat, - GString ** out_route_content) + shvarFile *ifcfg, + shvarFile **out_route_content_svformat, + GString **out_route_content) { - NMSettingIPConfig * s_ip4; - const char * value; - char * tmp; - char tag[64]; - int j; - guint i, num, n; - gint64 route_metric; - NMIPRouteTableSyncMode route_table; - int priority; - int timeout; + NMSettingIPConfig *s_ip4; + const char *value; + char *tmp; + char tag[64]; + int j; + guint i, num, n; + gint64 route_metric; + NMIPRouteTableSyncMode route_table; + int priority; + int timeout; nm_auto_free_gstring GString *str = NULL; - const char * method = NULL; + const char *method = NULL; gboolean has_netmask; NMDhcpHostnameFlags flags; - const char *const * strv; + const char *const *strv; NM_SET_OUT(out_route_content_svformat, NULL); NM_SET_OUT(out_route_content, NULL); @@ -2905,17 +2905,17 @@ static void write_ip4_aliases(NMConnection *connection, const char *base_ifcfg_path) { NMSettingIPConfig *s_ip4; - gs_free char * base_ifcfg_dir = NULL, *base_ifcfg_name = NULL; - const char * base_name; + gs_free char *base_ifcfg_dir = NULL, *base_ifcfg_name = NULL; + const char *base_name; int i, num, base_ifcfg_name_len, base_name_len; - GDir * dir; + GDir *dir; base_ifcfg_dir = g_path_get_dirname(base_ifcfg_path); base_ifcfg_name = g_path_get_basename(base_ifcfg_path); base_ifcfg_name_len = strlen(base_ifcfg_name); if (!g_str_has_prefix(base_ifcfg_name, IFCFG_TAG)) g_return_if_reached(); - base_name = base_ifcfg_name + strlen(IFCFG_TAG); + base_name = base_ifcfg_name + NM_STRLEN(IFCFG_TAG); base_name_len = strlen(base_name); /* Remove all existing aliases for this file first */ @@ -2946,11 +2946,11 @@ write_ip4_aliases(NMConnection *connection, const char *base_ifcfg_path) num = nm_setting_ip_config_get_num_addresses(s_ip4); for (i = 0; i < num; i++) { - GVariant * label_var; - const char * label, *p; - char * path; + GVariant *label_var; + const char *label, *p; + char *path; NMIPAddress *addr; - shvarFile * ifcfg; + shvarFile *ifcfg; addr = nm_setting_ip_config_get_address(s_ip4, i); @@ -2987,17 +2987,17 @@ write_ip4_aliases(NMConnection *connection, const char *base_ifcfg_path) static void write_ip6_setting(NMConnection *connection, shvarFile *ifcfg, GString **out_route6_content) { - NMSettingIPConfig * s_ip6; - const char * value; + NMSettingIPConfig *s_ip6; + const char *value; guint i, num; int priority; - NMIPAddress * addr; + NMIPAddress *addr; gint64 route_metric; NMIPRouteTableSyncMode route_table; - GString * ip_str1, *ip_str2, *ip_ptr; + GString *ip_str1, *ip_str2, *ip_ptr; NMSettingIP6ConfigAddrGenMode addr_gen_mode; NMDhcpHostnameFlags flags; - const char * hostname; + const char *hostname; int timeout; NM_SET_OUT(out_route6_content, NULL); @@ -3183,7 +3183,7 @@ write_ip_routing_rules(NMConnection *connection, shvarFile *ifcfg, gboolean rout num = nm_setting_ip_config_get_num_routing_rules(s_ip); for (i = 0; i < num; i++) { - NMIPRoutingRule * rule = nm_setting_ip_config_get_routing_rule(s_ip, i); + NMIPRoutingRule *rule = nm_setting_ip_config_get_routing_rule(s_ip, i); gs_free const char *s = NULL; char key[64]; @@ -3222,38 +3222,38 @@ escape_id(const char *id) } static gboolean -do_write_construct(NMConnection * connection, - const char * ifcfg_dir, - const char * filename, +do_write_construct(NMConnection *connection, + const char *ifcfg_dir, + const char *filename, NMSIfcfgRHWriterAllowFilenameCb allow_filename_cb, gpointer allow_filename_user_data, - shvarFile ** out_ifcfg, - GHashTable ** out_blobs, - GHashTable ** out_secrets, - gboolean * out_route_ignore, - shvarFile ** out_route_content_svformat, - GString ** out_route_content, - GString ** out_route6_content, - GError ** error) + shvarFile **out_ifcfg, + GHashTable **out_blobs, + GHashTable **out_secrets, + gboolean *out_route_ignore, + shvarFile **out_route_content_svformat, + GString **out_route_content, + GString **out_route6_content, + GError **error) { - NMSettingConnection * s_con; + NMSettingConnection *s_con; nm_auto_shvar_file_close shvarFile *ifcfg = NULL; - const char * ifcfg_name; - gs_free char * ifcfg_name_free = NULL; - gs_free char * route_path = NULL; - gs_free char * route6_path = NULL; - const char * type; - gs_unref_hashtable GHashTable *blobs = NULL; - gs_unref_hashtable GHashTable *secrets = NULL; - gboolean wired; - gboolean no_8021x; - gboolean route_path_is_svformat; - gboolean has_complex_routes_v4; - gboolean has_complex_routes_v6; - gboolean route_ignore; + const char *ifcfg_name; + gs_free char *ifcfg_name_free = NULL; + gs_free char *route_path = NULL; + gs_free char *route6_path = NULL; + const char *type; + gs_unref_hashtable GHashTable *blobs = NULL; + gs_unref_hashtable GHashTable *secrets = NULL; + gboolean wired; + gboolean no_8021x; + gboolean route_path_is_svformat; + gboolean has_complex_routes_v4; + gboolean has_complex_routes_v6; + gboolean route_ignore; nm_auto_shvar_file_close shvarFile *route_content_svformat = NULL; - nm_auto_free_gstring GString *route_content = NULL; - nm_auto_free_gstring GString *route6_content = NULL; + nm_auto_free_gstring GString *route_content = NULL; + nm_auto_free_gstring GString *route6_content = NULL; nm_assert(NM_IS_CONNECTION(connection)); nm_assert(_nm_connection_verify(connection, NULL) == NM_SETTING_VERIFY_SUCCESS); @@ -3478,14 +3478,14 @@ do_write_construct(NMConnection * connection, static gboolean do_write_to_disk(NMConnection *connection, - shvarFile * ifcfg, - GHashTable * blobs, - GHashTable * secrets, + shvarFile *ifcfg, + GHashTable *blobs, + GHashTable *secrets, gboolean route_ignore, - shvarFile * route_content_svformat, - GString * route_content, - GString * route6_content, - GError ** error) + shvarFile *route_content_svformat, + GString *route_content, + GString *route6_content, + GError **error) { /* From here on, we persist data to disk. Before, it was all in-memory * only. But we loaded the ifcfg files from disk, and managled our @@ -3549,23 +3549,23 @@ do_write_to_disk(NMConnection *connection, } gboolean -nms_ifcfg_rh_writer_write_connection(NMConnection * connection, - const char * ifcfg_dir, - const char * filename, +nms_ifcfg_rh_writer_write_connection(NMConnection *connection, + const char *ifcfg_dir, + const char *filename, NMSIfcfgRHWriterAllowFilenameCb allow_filename_cb, gpointer allow_filename_user_data, - char ** out_filename, - NMConnection ** out_reread, - gboolean * out_reread_same, - GError ** error) + char **out_filename, + NMConnection **out_reread, + gboolean *out_reread_same, + GError **error) { nm_auto_shvar_file_close shvarFile *ifcfg = NULL; - nm_auto_free_gstring GString *route_content = NULL; - gboolean route_ignore = FALSE; + nm_auto_free_gstring GString *route_content = NULL; + gboolean route_ignore = FALSE; nm_auto_shvar_file_close shvarFile *route_content_svformat = NULL; - nm_auto_free_gstring GString *route6_content = NULL; - gs_unref_hashtable GHashTable *secrets = NULL; - gs_unref_hashtable GHashTable *blobs = NULL; + nm_auto_free_gstring GString *route6_content = NULL; + gs_unref_hashtable GHashTable *secrets = NULL; + gs_unref_hashtable GHashTable *blobs = NULL; nm_assert(!out_reread || !*out_reread); @@ -3611,8 +3611,8 @@ nms_ifcfg_rh_writer_write_connection(NMConnection * connection, if (out_reread || out_reread_same) { gs_unref_object NMConnection *reread = NULL; gboolean reread_same = FALSE; - gs_free_error GError *local = NULL; - gs_free char * unhandled = NULL; + gs_free_error GError *local = NULL; + gs_free char *unhandled = NULL; reread = connection_from_file(svFileGetName(ifcfg), &unhandled, &local, NULL); nm_assert((NM_IS_CONNECTION(reread) && !local) || (!reread && local)); diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.h b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.h index d0d8a4cd..9b5162f8 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.h +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.h @@ -13,14 +13,14 @@ typedef gboolean (*NMSIfcfgRHWriterAllowFilenameCb)(const char *check_filename, gboolean nms_ifcfg_rh_writer_can_write_connection(NMConnection *connection, GError **error); -gboolean nms_ifcfg_rh_writer_write_connection(NMConnection * connection, - const char * ifcfg_dir, - const char * filename, +gboolean nms_ifcfg_rh_writer_write_connection(NMConnection *connection, + const char *ifcfg_dir, + const char *filename, NMSIfcfgRHWriterAllowFilenameCb allow_filename_cb, gpointer allow_filename_user_data, - char ** out_filename, + char **out_filename, NMConnection **out_reread, - gboolean * out_reread_same, - GError ** error); + gboolean *out_reread_same, + GError **error); #endif /* __NMS_IFCFG_RH_WRITER_H__ */ diff --git a/src/core/settings/plugins/ifcfg-rh/shvar.c b/src/core/settings/plugins/ifcfg-rh/shvar.c index d82efb3c..2ca49558 100644 --- a/src/core/settings/plugins/ifcfg-rh/shvar.c +++ b/src/core/settings/plugins/ifcfg-rh/shvar.c @@ -62,7 +62,7 @@ struct _shvarLine { typedef struct _shvarLine shvarLine; struct _shvarFile { - char * fileName; + char *fileName; CList lst_head; GHashTable *lst_idx; int fd; @@ -151,8 +151,8 @@ static char * _escape_ansic(const char *source) { const char *p; - char * dest; - char * q; + char *dest; + char *q; gsize n_alloc; nm_assert(source); @@ -705,7 +705,7 @@ out_error: shvarFile * svFile_new(const char *name, int fd, const char *content) { - shvarFile * s; + shvarFile *s; const char *p; const char *q; @@ -820,9 +820,9 @@ line_new_parse(const char *value, gsize len) static shvarLine * line_new_build(const char *key, const char *value) { - char * value_escaped = NULL; + char *value_escaped = NULL; shvarLine *line; - char * new_key; + char *new_key; value = svEscape(value, &value_escaped); @@ -841,7 +841,7 @@ line_new_build(const char *key, const char *value) static gboolean line_set(shvarLine *line, const char *value) { - char * value_escaped = NULL; + char *value_escaped = NULL; gboolean changed = FALSE; ASSERT_shvarLine(line); @@ -926,11 +926,11 @@ do_link: static shvarFile * svOpenFileInternal(const char *name, gboolean create, GError **error) { - gboolean closefd = FALSE; - int errsv = 0; - gs_free char *content = NULL; - gs_free_error GError *local = NULL; - nm_auto_close int fd = -1; + gboolean closefd = FALSE; + int errsv = 0; + gs_free char *content = NULL; + gs_free_error GError *local = NULL; + nm_auto_close int fd = -1; if (create) fd = open(name, O_RDWR | O_CLOEXEC); /* NOT O_CREAT */ @@ -1063,8 +1063,8 @@ svNumberedParseKey(const char *key) GHashTable * svGetKeys(shvarFile *s, SvKeyType match_key_type) { - GHashTable * keys = NULL; - CList * current; + GHashTable *keys = NULL; + CList *current; const shvarLine *line; nm_assert(s); @@ -1137,7 +1137,7 @@ static const char * _svGetValue(shvarFile *s, const char *key, char **to_free) { const shvarLine *line; - const char * v; + const char *v; nm_assert(s); nm_assert(_shell_is_name(key, -1)); @@ -1209,7 +1209,7 @@ svGetValueStr(shvarFile *s, const char *key, char **to_free) char * svGetValue_cp(shvarFile *s, const char *key) { - char * to_free; + char *to_free; const char *value; g_return_val_if_fail(s, NULL); @@ -1233,7 +1233,7 @@ svGetValue_cp(shvarFile *s, const char *key) char * svGetValueStr_cp(shvarFile *s, const char *key) { - char * to_free; + char *to_free; const char *value; g_return_val_if_fail(s, NULL); @@ -1260,7 +1260,7 @@ int svGetValueBoolean(shvarFile *s, const char *key, int fallback) { gs_free char *to_free = NULL; - const char * value; + const char *value; value = _svGetValue(s, key, &to_free); return svParseBoolean(value, fallback); @@ -1293,7 +1293,7 @@ svGetValueTernary(shvarFile *s, const char *key) gint64 svGetValueInt64(shvarFile *s, const char *key, guint base, gint64 min, gint64 max, gint64 fallback) { - char * to_free; + char *to_free; const char *value; gint64 result; int errsv; @@ -1320,7 +1320,7 @@ gboolean svGetValueEnum(shvarFile *s, const char *key, GType gtype, int *out_value, GError **error) { gs_free char *to_free = NULL; - const char * svalue; + const char *svalue; gs_free char *err_token = NULL; int value; @@ -1618,7 +1618,7 @@ svWarnInvalid(shvarFile *s, const char *file_type, NMLogDomain log_domain) gboolean svWriteFile(shvarFile *s, int mode, GError **error) { - FILE * f; + FILE *f; int tmpfd; CList *current; int errsv; @@ -1672,8 +1672,8 @@ svWriteFile(shvarFile *s, int mode, GError **error) fseek(f, 0, SEEK_SET); c_list_for_each (current, &s->lst_head) { const shvarLine *line = c_list_entry(current, shvarLine, lst); - const char * str; - char * s_tmp; + const char *str; + char *s_tmp; gboolean valid_value; ASSERT_shvarLine(line); diff --git a/src/core/settings/plugins/ifcfg-rh/shvar.h b/src/core/settings/plugins/ifcfg-rh/shvar.h index cf91642f..4b838eea 100644 --- a/src/core/settings/plugins/ifcfg-rh/shvar.h +++ b/src/core/settings/plugins/ifcfg-rh/shvar.h @@ -43,10 +43,10 @@ const char *svFindFirstNumberedKey(shvarFile *s, const char *key_prefix); * be freed by the caller. */ const char *svGetValue(shvarFile *s, const char *key, char **to_free); -char * svGetValue_cp(shvarFile *s, const char *key); +char *svGetValue_cp(shvarFile *s, const char *key); const char *svGetValueStr(shvarFile *s, const char *key, char **to_free); -char * svGetValueStr_cp(shvarFile *s, const char *key); +char *svGetValueStr_cp(shvarFile *s, const char *key); int svParseBoolean(const char *value, int def); diff --git a/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index b1cfdfec..7960ea2a 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -61,8 +61,8 @@ #define _svOpenFile(testfile) \ ({ \ - shvarFile * _f; \ - GError * _error = NULL; \ + shvarFile *_f; \ + GError *_error = NULL; \ const char *_testfile = (testfile); \ \ g_assert(_testfile); \ @@ -74,9 +74,9 @@ #define _svGetValue_check(f, key, expected_value) \ G_STMT_START \ { \ - const char * _val; \ - gs_free char * _to_free = NULL; \ - gs_free char * _val_string = NULL; \ + const char *_val; \ + gs_free char *_to_free = NULL; \ + gs_free char *_val_string = NULL; \ shvarFile *const _f = (f); \ const char *const _key = (key); \ \ @@ -98,8 +98,8 @@ _assert_reread_same(NMConnection *connection, NMConnection *reread) static void _assert_reread_same_FIXME(NMConnection *connection, NMConnection *reread) { - gs_unref_object NMConnection *connection_normalized = NULL; - gs_unref_hashtable GHashTable *settings = NULL; + gs_unref_object NMConnection *connection_normalized = NULL; + gs_unref_hashtable GHashTable *settings = NULL; /* FIXME: these assertion failures should not happen as we expect * that re-reading a connection after write yields the same result. @@ -125,11 +125,11 @@ _assert_expected_content(NMConnection *connection, const char *filename, const c { gs_free char *content_expectd = NULL; gs_free char *content_written = NULL; - GError * error = NULL; + GError *error = NULL; gsize len_expectd = 0; gsize len_written = 0; gboolean success; - const char * uuid = NULL; + const char *uuid = NULL; g_assert(NM_IS_CONNECTION(connection)); g_assert(filename); @@ -196,9 +196,9 @@ _assert_expected_content(NMConnection *connection, const char *filename, const c if (rewrite > 0) { if (uuid) { gs_free char *search = g_strdup_printf("UUID=%s\n", uuid); - const char * s; + const char *s; gsize i; - GString * str; + GString *str; s = content_written; while (TRUE) { @@ -246,11 +246,11 @@ _assert_expected_content(NMConnection *connection, const char *filename, const c gs_unref_object NMConnection *_connection = \ nmtst_connection_duplicate_and_normalize(connection); \ NMConnection **_out_reread = (out_reread); \ - gboolean * _out_reread_same = (out_reread_same); \ - const char * _ifcfg_dir = (ifcfg_dir); \ - const char * _filename = (filename); \ - const char * _expected = (expected); \ - GError * _error = NULL; \ + gboolean *_out_reread_same = (out_reread_same); \ + const char *_ifcfg_dir = (ifcfg_dir); \ + const char *_filename = (filename); \ + const char *_expected = (expected); \ + GError *_error = NULL; \ gboolean _success; \ \ g_assert(_ifcfg_dir &&_ifcfg_dir[0]); \ @@ -274,7 +274,7 @@ _assert_expected_content(NMConnection *connection, const char *filename, const c G_STMT_START \ { \ gs_unref_object NMConnection *_reread = NULL; \ - NMConnection * _c = (connection); \ + NMConnection *_c = (connection); \ gboolean _reread_same = FALSE; \ \ _writer_update_connection_reread(_c, \ @@ -292,11 +292,11 @@ static NMConnection * _connection_from_file(const char *filename, const char *network_file, const char *test_type, - char ** out_unhandled) + char **out_unhandled) { NMConnection *connection; - GError * error = NULL; - char * unhandled_fallback = NULL; + GError *error = NULL; + char *unhandled_fallback = NULL; g_assert(!out_unhandled || !*out_unhandled); @@ -319,11 +319,11 @@ static void _connection_from_file_fail(const char *filename, const char *network_file, const char *test_type, - GError ** error) + GError **error) { NMConnection *connection; - GError * local = NULL; - char * unhandled = NULL; + GError *local = NULL; + char *unhandled = NULL; connection = nmtst_connection_from_file(filename, network_file, test_type, &unhandled, &local); @@ -334,16 +334,16 @@ _connection_from_file_fail(const char *filename, } static void -_writer_new_connection_reread(NMConnection * connection, - const char * ifcfg_dir, - char ** out_filename, - const char * expected, +_writer_new_connection_reread(NMConnection *connection, + const char *ifcfg_dir, + char **out_filename, + const char *expected, NMConnection **out_reread, - gboolean * out_reread_same) + gboolean *out_reread_same) { - gboolean success; - GError * error = NULL; - gs_free char * filename = NULL; + gboolean success; + GError *error = NULL; + gs_free char *filename = NULL; gs_unref_object NMConnection *con_verified = NULL; gs_unref_object NMConnection *reread_copy = NULL; NMConnection **reread = out_reread ?: ((nmtst_get_rand_uint32() % 2) ? &reread_copy : NULL); @@ -378,9 +378,9 @@ _writer_new_connection_reread(NMConnection * connection, static void _writer_new_connec_exp(NMConnection *connection, - const char * ifcfg_dir, - const char * expected, - char ** out_filename) + const char *ifcfg_dir, + const char *expected, + char **out_filename) { gs_unref_object NMConnection *reread = NULL; gboolean reread_same = FALSE; @@ -425,8 +425,8 @@ _writer_new_connection_fail(NMConnection *connection, const char *ifcfg_dir, GEr gs_unref_object NMConnection *connection_normalized = NULL; gs_unref_object NMConnection *reread = NULL; gboolean success; - GError * local = NULL; - char * filename = NULL; + GError *local = NULL; + char *filename = NULL; g_assert(NM_IS_CONNECTION(connection)); g_assert(ifcfg_dir); @@ -454,13 +454,13 @@ _writer_new_connection_fail(NMConnection *connection, const char *ifcfg_dir, GEr static void test_read_netmask_1(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; - gs_free char * content = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMIPAddress * ip4_addr; - const char * FILENAME = TEST_IFCFG_DIR "/ifcfg-netmask-1"; + gs_free char *content = NULL; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMIPAddress *ip4_addr; + const char *FILENAME = TEST_IFCFG_DIR "/ifcfg-netmask-1"; connection = _connection_from_file(FILENAME, NULL, TYPE_ETHERNET, NULL); @@ -492,14 +492,14 @@ test_read_netmask_1(void) static gboolean verify_cert_or_key(NMSetting8021x *s_compare, - const char * file, - const char * privkey_password, - const char * property) + const char *file, + const char *privkey_password, + const char *property) { gs_unref_object NMSetting8021x *s_8021x = NULL; - GError * error = NULL; + GError *error = NULL; gboolean success = FALSE; - const char * expected = NULL, *setting = NULL; + const char *expected = NULL, *setting = NULL; gboolean phase2 = FALSE; NMSetting8021xCKScheme scheme = NM_SETTING_802_1X_CK_SCHEME_UNKNOWN; @@ -617,11 +617,11 @@ static void test_read_basic(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - const char * mac; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + const char *mac; char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; connection = @@ -662,10 +662,10 @@ static void test_read_miscellaneous_variables(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - char * expected_mac_blacklist[3] = {"00:16:41:11:22:88", + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + 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; @@ -705,10 +705,10 @@ static void test_read_variables_corner_cases(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - const char * mac; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + const char *mac; char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; NMTST_EXPECT_NM_WARN("*key NAME is badly quoted and is treated as \"\"*"); @@ -745,8 +745,8 @@ static void test_read_unmanaged(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - gs_free char * unhandled_spec = NULL; + NMSettingConnection *s_con; + gs_free char *unhandled_spec = NULL; guint64 expected_timestamp = 0; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-nm-controlled", @@ -765,8 +765,8 @@ static void test_read_unmanaged_unrecognized(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - gs_free char * unhandled_spec = NULL; + NMSettingConnection *s_con; + gs_free char *unhandled_spec = NULL; guint64 expected_timestamp = 0; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-nm-controlled-unrecognized", @@ -784,8 +784,8 @@ static void test_read_unrecognized(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - gs_free char * unhandled_spec = NULL; + NMSettingConnection *s_con; + gs_free char *unhandled_spec = NULL; guint64 expected_timestamp = 0; NMTST_EXPECT_NM_WARN("*key NAME is badly quoted and is treated as \"\"*"); @@ -805,16 +805,16 @@ static void test_read_wired_static(gconstpointer test_data) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - char * unmanaged = NULL; - const char * mac; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + char *unmanaged = NULL; + const char *mac; char expected_mac_address[ETH_ALEN] = {0x00, 0x11, 0x22, 0x33, 0x44, 0xee}; NMIPAddress *ip4_addr; NMIPAddress *ip6_addr; - const char * file, *expected_id; + const char *file, *expected_id; gpointer expect_ip6_p; nmtst_test_data_unpack(test_data, &file, &expected_id, &expect_ip6_p); @@ -895,13 +895,13 @@ test_read_wired_static(gconstpointer test_data) static void test_read_wired_static_no_prefix(gconstpointer user_data) { - guint32 expected_prefix = GPOINTER_TO_UINT(user_data); - gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMIPAddress * ip4_addr; - gs_free char * file = NULL; - gs_free char * expected_id = NULL; + guint32 expected_prefix = GPOINTER_TO_UINT(user_data); + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMIPAddress *ip4_addr; + gs_free char *file = NULL; + gs_free char *expected_id = NULL; file = g_strdup_printf(TEST_IFCFG_DIR "/ifcfg-test-wired-static-no-prefix-%u", expected_prefix); expected_id = g_strdup_printf("System test-wired-static-no-prefix-%u", expected_prefix); @@ -931,11 +931,11 @@ static void test_read_wired_dhcp(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - char * unmanaged = NULL; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + char *unmanaged = NULL; char expected_mac_address[ETH_ALEN] = {0x00, 0x11, 0x22, 0x33, 0x44, 0xee}; const char *mac; @@ -983,10 +983,10 @@ static void test_read_wired_dhcp_plus_ip(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMIPAddress * ip4_addr; - NMIPAddress * ip6_addr; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMIPAddress *ip4_addr; + NMIPAddress *ip6_addr; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-dhcp-plus-ip", NULL, @@ -1048,8 +1048,8 @@ static void test_read_wired_shared_plus_ip(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingIPConfig * s_ip4; - NMIPAddress * ip4_addr; + NMSettingIPConfig *s_ip4; + NMIPAddress *ip4_addr; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-shared-plus-ip", NULL, @@ -1077,10 +1077,10 @@ static void test_read_wired_global_gateway(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMIPAddress * ip4_addr; - char * unmanaged = NULL; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMIPAddress *ip4_addr; + char *unmanaged = NULL; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-global-gateway", TEST_IFCFG_DIR "/network-test-wired-global-gateway", @@ -1113,9 +1113,9 @@ static void test_read_wired_global_gateway_ignore(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - char * unmanaged = NULL; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + char *unmanaged = NULL; NMTST_EXPECT_NM_WARN("*ignoring GATEWAY (/etc/sysconfig/network) for * because the connection " "has no static addresses"); @@ -1147,8 +1147,8 @@ static void test_read_wired_obsolete_gateway_n(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingIPConfig * s_ip4; - NMIPAddress * ip4_addr; + NMSettingIPConfig *s_ip4; + NMIPAddress *ip4_addr; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-obsolete-gateway-n", NULL, @@ -1174,10 +1174,10 @@ test_read_wired_obsolete_gateway_n(void) static void test_user_1(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingUser * s_user; + NMSettingUser *s_user; connection = nmtst_create_minimal_connection("Test User 1", NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); @@ -1187,7 +1187,7 @@ test_user_1(void) #define _USER_SET_DATA(s_user, key, val) \ G_STMT_START \ { \ - GError * _error = NULL; \ + GError *_error = NULL; \ gboolean _success; \ \ _success = nm_setting_user_set_data((s_user), (key), (val), &_error); \ @@ -1232,8 +1232,8 @@ static void test_read_wired_never_default(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-never-default", TEST_IFCFG_DIR "/network-test-wired-never-default", @@ -1256,10 +1256,10 @@ static void test_read_wired_defroute_no(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - char * unmanaged = NULL; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + char *unmanaged = NULL; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-defroute-no", NULL, @@ -1285,10 +1285,10 @@ static void test_read_wired_defroute_no_gatewaydev_yes(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - char * unmanaged = NULL; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + char *unmanaged = NULL; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-defroute-no-gatewaydev-yes", @@ -1316,9 +1316,9 @@ static void test_read_wired_static_routes(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMIPRoute * ip4_route; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMIPRoute *ip4_route; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-static-routes", NULL, @@ -1391,10 +1391,10 @@ static void test_read_wired_static_routes_legacy(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - char * unmanaged = NULL; - NMIPRoute * ip4_route; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + char *unmanaged = NULL; + NMIPRoute *ip4_route; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-static-routes-legacy", NULL, @@ -1466,11 +1466,11 @@ static void test_read_wired_ipv4_manual(gconstpointer data) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - char * unmanaged = NULL; - NMIPAddress * ip4_addr; - const char * file, *expected_id; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + char *unmanaged = NULL; + NMIPAddress *ip4_addr; + const char *file, *expected_id; nmtst_test_data_unpack(data, &file, &expected_id); @@ -1516,12 +1516,12 @@ static void test_read_wired_ipv6_manual(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - char * unmanaged = NULL; - NMIPAddress * ip6_addr; - NMIPRoute * ip6_route; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + char *unmanaged = NULL; + NMIPAddress *ip6_addr; + NMIPRoute *ip6_route; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-ipv6-manual", NULL, @@ -1621,13 +1621,13 @@ static void test_read_wired_ipv6_only(gconstpointer test_data) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - char * unmanaged = NULL; - NMIPAddress * ip6_addr; - const char * method; - const char * file, *expected_id; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + char *unmanaged = NULL; + NMIPAddress *ip6_addr; + const char *method; + const char *file, *expected_id; nmtst_test_data_unpack(test_data, &file, &expected_id); @@ -1675,11 +1675,11 @@ static void test_read_wired_dhcp6_only(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - char * unmanaged = NULL; - const char * method; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + char *unmanaged = NULL; + const char *method; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-dhcp6-only", NULL, @@ -1705,9 +1705,9 @@ static void test_read_wired_autoip(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - char * unmanaged = NULL; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + char *unmanaged = NULL; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-autoip", NULL, @@ -1730,8 +1730,8 @@ static void test_read_onboot_no(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - char * unmanaged = NULL; + NMSettingConnection *s_con; + char *unmanaged = NULL; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-onboot-no", NULL, @@ -1748,8 +1748,8 @@ static void test_read_noip(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-noip", NULL, TYPE_ETHERNET, NULL); @@ -1772,15 +1772,15 @@ test_read_noip(void) static void test_read_wired_8021x_peap_mschapv2(void) { - gs_unref_object NMConnection *connection = NULL; - NMSettingIPConfig * s_ip4; - NMSetting8021x * s_8021x; + gs_unref_object NMConnection *connection = NULL; + NMSettingIPConfig *s_ip4; + NMSetting8021x *s_8021x; gs_unref_object NMSetting8021x *tmp_8021x = NULL; - char * unmanaged = NULL; - GError * error = NULL; + char *unmanaged = NULL; + GError *error = NULL; gboolean success = FALSE; - const char * expected_ca_cert_path; - const char * read_ca_cert_path; + const char *expected_ca_cert_path; + const char *read_ca_cert_path; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-8021x-peap-mschapv2", NULL, @@ -1827,11 +1827,11 @@ static void test_read_wired_8021x_tls_secret_flags(gconstpointer test_data) { gs_unref_object NMConnection *connection = NULL; - NMSetting8021x * s_8021x; - gs_free char * dirname = NULL; - gs_free char * tmp1 = NULL; - gs_free char * tmp2 = NULL; - const char * ifcfg; + NMSetting8021x *s_8021x; + gs_free char *dirname = NULL; + gs_free char *tmp1 = NULL; + gs_free char *tmp2 = NULL; + const char *ifcfg; gpointer expected_flags_p; nmtst_test_data_unpack(test_data, &ifcfg, &expected_flags_p); @@ -1861,10 +1861,10 @@ test_read_wired_8021x_tls_secret_flags(gconstpointer test_data) static void test_read_write_802_1X_subj_matches(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSetting8021x * s_8021x; + NMSetting8021x *s_8021x; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-802-1X-subj-matches", NULL, @@ -1926,7 +1926,7 @@ static void test_read_802_1x_ttls_eapgtc(void) { gs_unref_object NMConnection *connection = NULL; - NMSetting8021x * s_8021x; + NMSetting8021x *s_8021x; /* Test that EAP-* inner methods are correctly read into the * NMSetting8021x::autheap property. @@ -1952,8 +1952,8 @@ static void test_read_802_1x_tls_p12_no_client_cert(void) { gs_unref_object NMConnection *connection = NULL; - NMSetting8021x * s_8021x; - const char * path; + NMSetting8021x *s_8021x; + const char *path; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-8021x-tls-p12-no-client-cert", @@ -1978,12 +1978,12 @@ test_read_802_1x_tls_p12_no_client_cert(void) static void test_read_write_802_1x_password_raw(void) { - nmtst_auto_unlinkfile char *testfile = NULL; - nmtst_auto_unlinkfile char *keyfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSetting8021x * s_8021x; - GBytes * bytes; + NMSetting8021x *s_8021x; + GBytes *bytes; gconstpointer data; gsize size; @@ -2019,18 +2019,18 @@ test_read_write_802_1x_password_raw(void) static void test_read_wired_aliases_good(gconstpointer test_data) { - const int N = GPOINTER_TO_INT(test_data); + const int N = GPOINTER_TO_INT(test_data); gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; int expected_num_addresses; - const char * expected_address_0[] = {"192.168.1.5", + const char *expected_address_0[] = {"192.168.1.5", "192.168.1.6", "192.168.1.9", "192.168.1.99", NULL}; - const char * expected_address_3[] = {"192.168.1.5", "192.168.1.6", NULL}; - const char * expected_label_0[] = { + const char *expected_address_3[] = {"192.168.1.5", "192.168.1.6", NULL}; + const char *expected_label_0[] = { NULL, "aliasem0:1", "aliasem0:2", @@ -2070,8 +2070,8 @@ test_read_wired_aliases_good(gconstpointer test_data) /* Addresses */ for (i = 0; i < expected_num_addresses; i++) { NMIPAddress *ip4_addr; - const char * addr; - GVariant * label; + const char *addr; + GVariant *label; ip4_addr = nm_setting_ip_config_get_address(s_ip4, i); g_assert(ip4_addr != NULL); @@ -2108,9 +2108,9 @@ static void test_read_wired_aliases_bad(const char *base, const char *expected_id) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMIPAddress * ip4_addr; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMIPAddress *ip4_addr; g_assert(expected_id); @@ -2156,12 +2156,12 @@ static void test_read_dns_options(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - char * unmanaged = NULL; - const char * option; - const char * options4[] = {"ndots:3", "single-request-reopen"}; - const char * options6[] = {"inet6"}; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + char *unmanaged = NULL; + const char *option; + const char *options4[] = {"ndots:3", "single-request-reopen"}; + const char *options6[] = {"inet6"}; guint32 num; guint32 i; @@ -2195,12 +2195,12 @@ test_read_dns_options(void) static void test_clear_master(void) { - nmtst_auto_unlinkfile char *testfile = NULL; - gs_free char * keyfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_free char *keyfile = NULL; gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - char * unmanaged = NULL; - shvarFile * f; + NMSettingConnection *s_con; + char *unmanaged = NULL; + shvarFile *f; /* 1. load the bridge slave connection from disk */ connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bridge-component", @@ -2250,18 +2250,18 @@ test_clear_master(void) static void test_write_dns_options(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - static const char * mac = "31:33:33:37:be:cd"; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + static const char *mac = "31:33:33:37:be:cd"; guint32 mtu = 1492; - NMIPAddress * addr; - NMIPAddress * addr6; - GError * error = NULL; + NMIPAddress *addr; + NMIPAddress *addr6; + GError *error = NULL; connection = nm_simple_connection_new(); @@ -2328,12 +2328,12 @@ static void test_read_wifi_open(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - GBytes * ssid; - const char * mac; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + GBytes *ssid; + const char *mac; char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; const char *expected_ssid = "blahblah"; @@ -2385,8 +2385,8 @@ static void test_read_wifi_open_auto(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-open-auto", NULL, @@ -2406,10 +2406,10 @@ static void test_read_wifi_open_ssid_hex(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - GBytes * ssid; - const char * expected_ssid = "blahblah"; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + GBytes *ssid; + const char *expected_ssid = "blahblah"; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-open-ssid-hex", NULL, @@ -2435,10 +2435,10 @@ static void test_read_wifi_open_ssid_hex_bad(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - GBytes * ssid; - const char * expected_ssid = "0x626cxx"; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + GBytes *ssid; + const char *expected_ssid = "0x626cxx"; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-open-ssid-bad-hex", NULL, @@ -2470,10 +2470,10 @@ static void test_read_wifi_open_ssid_quoted(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - GBytes * ssid; - const char * expected_ssid = "foo\"bar\\"; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + GBytes *ssid; + const char *expected_ssid = "foo\"bar\\"; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-open-ssid-quoted", NULL, @@ -2499,14 +2499,14 @@ static void test_read_wifi_wep(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - NMSettingIPConfig * s_ip4; - GBytes * ssid; - const char * mac; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig *s_ip4; + GBytes *ssid; + const char *mac; char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; - const char * expected_ssid = "blahblah"; + const char *expected_ssid = "blahblah"; NMWepKeyType key_type; connection = @@ -2566,12 +2566,12 @@ static void test_read_wifi_wep_adhoc(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - NMSettingIPConfig * s_ip4; - GBytes * ssid; - const char * expected_ssid = "blahblah"; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig *s_ip4; + GBytes *ssid; + const char *expected_ssid = "blahblah"; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-adhoc", NULL, @@ -2631,7 +2631,7 @@ static void test_read_wifi_wep_passphrase(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingWirelessSecurity * s_wsec; + NMSettingWirelessSecurity *s_wsec; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-passphrase", NULL, @@ -2658,7 +2658,7 @@ static void test_read_wifi_wep_40_ascii(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingWirelessSecurity * s_wsec; + NMSettingWirelessSecurity *s_wsec; NMWepKeyType key_type; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-40-ascii", @@ -2687,7 +2687,7 @@ static void test_read_wifi_wep_104_ascii(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingWirelessSecurity * s_wsec; + NMSettingWirelessSecurity *s_wsec; NMWepKeyType key_type; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-104-ascii", @@ -2716,8 +2716,8 @@ static void test_read_wifi_leap(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWirelessSecurity * s_wsec; + NMSettingConnection *s_con; + NMSettingWirelessSecurity *s_wsec; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-leap", NULL, TYPE_WIRELESS, NULL); @@ -2738,8 +2738,8 @@ static void test_read_wifi_leap_secret_flags(gconstpointer test_data) { gs_unref_object NMConnection *connection = NULL; - NMSettingWirelessSecurity * s_wsec; - const char * file; + NMSettingWirelessSecurity *s_wsec; + const char *file; gpointer expected_flags_p; nmtst_test_data_unpack(test_data, &file, &expected_flags_p); @@ -2773,12 +2773,12 @@ static void test_read_wifi_wpa_psk(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - NMSettingIPConfig * s_ip4; - GBytes * ssid; - const char * mac; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig *s_ip4; + GBytes *ssid; + const char *mac; char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; const char *expected_ssid = "blahblah"; guint32 n, i; @@ -2887,11 +2887,11 @@ static void test_read_wifi_sae(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - GBytes * ssid; - const char * expected_ssid = "blahblah"; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + GBytes *ssid; + const char *expected_ssid = "blahblah"; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-sae", NULL, TYPE_WIRELESS, NULL); @@ -2926,11 +2926,11 @@ static void test_read_wifi_owe(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - GBytes * ssid; - const char * expected_ssid = "blahblah_owe"; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + GBytes *ssid; + const char *expected_ssid = "blahblah_owe"; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-owe", NULL, TYPE_WIRELESS, NULL); @@ -2965,8 +2965,8 @@ static void test_read_wifi_wpa_psk_2(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWirelessSecurity * s_wsec; + NMSettingConnection *s_con; + NMSettingWirelessSecurity *s_wsec; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-psk-2", NULL, @@ -2988,8 +2988,8 @@ static void test_read_wifi_wpa_psk_unquoted(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWirelessSecurity * s_wsec; + NMSettingConnection *s_con; + NMSettingWirelessSecurity *s_wsec; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-psk-unquoted", NULL, @@ -3022,10 +3022,10 @@ static void test_read_wifi_wpa_psk_adhoc(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - NMSettingIPConfig * s_ip4; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig *s_ip4; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-psk-adhoc", NULL, @@ -3064,12 +3064,12 @@ static void test_read_wifi_wpa_psk_hex(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - NMSettingIPConfig * s_ip4; - GBytes * ssid; - const char * expected_ssid = "blahblah"; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig *s_ip4; + GBytes *ssid; + const char *expected_ssid = "blahblah"; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-psk-hex", NULL, @@ -3105,10 +3105,10 @@ static void test_read_wifi_wpa_eap_tls(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingIPConfig * s_ip4; - NMSetting8021x * s_8021x; - char * unmanaged = NULL; - const char * expected_privkey_password = "test1"; + NMSettingIPConfig *s_ip4; + NMSetting8021x *s_8021x; + char *unmanaged = NULL; + const char *expected_privkey_password = "test1"; NMTST_EXPECT_NM_WARN("*key ONBOOT is duplicated and the early occurrence ignored*"); connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-eap-tls", @@ -3158,10 +3158,10 @@ static void test_read_wifi_wpa_eap_ttls_tls(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingIPConfig * s_ip4; - NMSetting8021x * s_8021x; - char * unmanaged = NULL; - const char * expected_privkey_password = "test1"; + NMSettingIPConfig *s_ip4; + NMSetting8021x *s_8021x; + char *unmanaged = NULL; + const char *expected_privkey_password = "test1"; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-eap-ttls-tls", NULL, @@ -3216,7 +3216,7 @@ static void test_read_wifi_wpa_eap_suite_b_192_tls(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingWirelessSecurity * s_wsec; + NMSettingWirelessSecurity *s_wsec; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-eap-suite-b-192-tls", NULL, @@ -3233,8 +3233,8 @@ static void test_read_wifi_dynamic_wep_leap(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingWirelessSecurity * s_wsec; - NMSetting8021x * s_8021x; + NMSettingWirelessSecurity *s_wsec; + NMSetting8021x *s_8021x; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-dynamic-wep-leap", NULL, @@ -3272,10 +3272,10 @@ static void test_read_wifi_wep_eap_ttls_chap(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingWirelessSecurity * s_wsec; - NMSettingIPConfig * s_ip4; - NMSetting8021x * s_8021x; - char * unmanaged = NULL; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig *s_ip4; + NMSetting8021x *s_8021x; + char *unmanaged = NULL; NMTST_EXPECT_NM_WARN("*key ONBOOT is duplicated and the early occurrence ignored*"); connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-eap-ttls-chap", @@ -3314,8 +3314,8 @@ static void test_read_wired_wake_on_lan(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; + NMSettingConnection *s_con; + NMSettingWired *s_wired; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-wake-on-lan", NULL, @@ -3340,8 +3340,8 @@ static void test_read_wired_auto_negotiate_off(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; + NMSettingConnection *s_con; + NMSettingWired *s_wired; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-wake-on-lan", NULL, @@ -3364,8 +3364,8 @@ static void test_read_wired_auto_negotiate_on(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; + NMSettingConnection *s_con; + NMSettingWired *s_wired; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-auto-negotiate-on", NULL, @@ -3388,8 +3388,8 @@ static void test_read_wired_unknown_ethtool_opt(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; + NMSettingConnection *s_con; + NMSettingWired *s_wired; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-unknown-ethtool-opt", NULL, @@ -3418,8 +3418,8 @@ static void test_roundtrip_ethtool(void) { gs_unref_object NMConnection *connection = NULL; - NMSetting * s_ethtool; - NMSetting * s_wired; + NMSetting *s_ethtool; + NMSetting *s_wired; connection = nmtst_create_minimal_connection("test_roundtrip_ethtool", NULL, @@ -3488,8 +3488,8 @@ static void test_read_wifi_hidden(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-hidden", NULL, TYPE_WIRELESS, NULL); @@ -3506,13 +3506,13 @@ test_read_wifi_hidden(void) static void test_write_wifi_hidden(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - shvarFile * f; - gs_unref_bytes GBytes *ssid = + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + shvarFile *f; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_arr(0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44); connection = nm_simple_connection_new(); @@ -3550,9 +3550,9 @@ static void test_read_wifi_mac_random(gconstpointer user_data) { gs_unref_object NMConnection *connection = NULL; - gs_free char * path = NULL; - NMSettingWireless * s_wifi; - const char * name; + gs_free char *path = NULL; + NMSettingWireless *s_wifi; + const char *name; gpointer value_p; NMSettingMacRandomization value; @@ -3569,16 +3569,16 @@ test_read_wifi_mac_random(gconstpointer user_data) static void test_write_wifi_mac_random(gconstpointer user_data) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - gs_free char * val = NULL; - shvarFile * f; - gs_unref_bytes GBytes *ssid = + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + gs_free char *val = NULL; + shvarFile *f; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_arr(0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44); - const char * name, *write_expected; + const char *name, *write_expected; gpointer value_p; NMSettingMacRandomization value; char cexpected[NM_STRLEN(TEST_IFCFG_DIR) + 100]; @@ -3632,13 +3632,13 @@ test_write_wifi_mac_random(gconstpointer user_data) static void test_write_wired_wake_on_lan(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - gs_free char * val = NULL; - shvarFile * f; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + gs_free char *val = NULL; + shvarFile *f; connection = nm_simple_connection_new(); @@ -3684,12 +3684,12 @@ test_write_wired_wake_on_lan(void) static void test_write_wired_auto_negotiate_off(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingWired * s_wired; - gs_free char * val = NULL; - shvarFile * f; + NMSettingWired *s_wired; + gs_free char *val = NULL; + shvarFile *f; connection = nmtst_create_minimal_connection("Test Write Wired Auto-Negotiate", NULL, @@ -3726,13 +3726,13 @@ test_write_wired_auto_negotiate_off(void) static void test_write_wired_auto_negotiate_on(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingWired * s_wired; - NMSettingEthtool * s_ethtool; - gs_free char * val = NULL; - shvarFile * f; + NMSettingWired *s_wired; + NMSettingEthtool *s_ethtool; + gs_free char *val = NULL; + shvarFile *f; connection = nmtst_create_minimal_connection("Test Write Wired Auto-Negotiate", NULL, @@ -3780,8 +3780,8 @@ static void test_read_wifi_band_a(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-band-a", NULL, TYPE_WIRELESS, NULL); @@ -3798,13 +3798,13 @@ test_read_wifi_band_a(void) static void test_write_wifi_band_a(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - shvarFile * f; - gs_unref_bytes GBytes *ssid = + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + shvarFile *f; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_arr(0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44); connection = nm_simple_connection_new(); @@ -3848,12 +3848,12 @@ test_write_wifi_band_a(void) static void test_write_wifi_ap_mode(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("MySSID"); + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("MySSID"); connection = nm_simple_connection_new(); @@ -3921,11 +3921,11 @@ static void test_read_wired_qeth_static(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - char * unmanaged = NULL; - const char *const * subchannels; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + char *unmanaged = NULL; + const char *const *subchannels; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-qeth-static", NULL, @@ -3964,10 +3964,10 @@ static void test_read_wired_ctc_static(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - char * unmanaged = NULL; - const char *const * subchannels; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + char *unmanaged = NULL; + const char *const *subchannels; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-ctc-static", NULL, @@ -3998,8 +3998,8 @@ static void test_read_wifi_wep_no_keys(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWirelessSecurity * s_wsec; + NMSettingConnection *s_con; + NMSettingWirelessSecurity *s_wsec; NMWepKeyType key_type; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-no-keys", @@ -4039,10 +4039,10 @@ static void test_read_permissions(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; + NMSettingConnection *s_con; gboolean success; guint32 num; - const char * tmp; + const char *tmp; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-permissions", NULL, TYPE_ETHERNET, NULL); @@ -4073,7 +4073,7 @@ static void test_read_wifi_wep_agent_keys(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingWirelessSecurity * s_wsec; + NMSettingWirelessSecurity *s_wsec; NMWepKeyType key_type; NMSettingSecretFlags flags; @@ -4106,18 +4106,18 @@ test_read_wifi_wep_agent_keys(void) static void test_write_wired_static(void) { - nmtst_auto_unlinkfile char *testfile = NULL; - nmtst_auto_unlinkfile char *route6file = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *route6file = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4, *reread_s_ip4; - NMSettingIPConfig * s_ip6, *reread_s_ip6; - NMIPAddress * addr; - NMIPAddress * addr6; - NMIPRoute * route6; - GError * error = NULL; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4, *reread_s_ip4; + NMSettingIPConfig *s_ip6, *reread_s_ip6; + NMIPAddress *addr; + NMIPAddress *addr6; + NMIPRoute *route6; + GError *error = NULL; connection = nm_simple_connection_new(); @@ -4249,18 +4249,18 @@ test_write_wired_static(void) static void test_write_wired_static_with_generic(void) { - nmtst_auto_unlinkfile char *testfile = NULL; - nmtst_auto_unlinkfile char *route6file = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *route6file = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4, *reread_s_ip4; - NMSettingIPConfig * s_ip6, *reread_s_ip6; - NMIPAddress * addr; - NMIPAddress * addr6; - NMIPRoute * route6; - GError * error = NULL; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4, *reread_s_ip4; + NMSettingIPConfig *s_ip6, *reread_s_ip6; + NMIPAddress *addr; + NMIPAddress *addr6; + NMIPRoute *route6; + GError *error = NULL; connection = nm_simple_connection_new(); @@ -4411,12 +4411,12 @@ test_write_wired_static_with_generic(void) static void test_write_wired_dhcp(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = nm_simple_connection_new(); @@ -4477,8 +4477,8 @@ static NMIPRoutingRule * _ip_routing_rule_new(int addr_family, const char *str) { NMIPRoutingRuleAsStringFlags flags = NM_IP_ROUTING_RULE_AS_STRING_FLAGS_NONE; - gs_free_error GError *local = NULL; - NMIPRoutingRule * rule; + gs_free_error GError *local = NULL; + NMIPRoutingRule *rule; if (addr_family != AF_UNSPEC) { if (addr_family == AF_INET) @@ -4512,12 +4512,12 @@ _ip_routing_rule_add_to_setting(NMSettingIPConfig *s_ip, const char *str) static void test_write_routing_rules(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = nm_simple_connection_new(); @@ -4560,13 +4560,13 @@ test_write_routing_rules(void) static void test_write_wired_match(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingMatch * s_match; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingConnection *s_con; + NMSettingMatch *s_match; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = nm_simple_connection_new(); @@ -4615,7 +4615,7 @@ test_write_wired_match(void) static void test_write_wired_dhcp_plus_ip(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; @@ -4634,12 +4634,12 @@ test_write_wired_dhcp_plus_ip(void) static void test_read_write_wired_dhcp_send_hostname(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - const char * dhcp_hostname = "kamil-patka"; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + const char *dhcp_hostname = "kamil-patka"; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-dhcp-send-hostname", NULL, @@ -4676,7 +4676,7 @@ static void test_read_wired_dhcpv6_hostname_fallback(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingIPConfig * s_ip6; + NMSettingIPConfig *s_ip6; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-dhcpv6-hostname-fallback", NULL, @@ -4691,15 +4691,15 @@ test_read_wired_dhcpv6_hostname_fallback(void) static void test_write_wired_static_ip6_only(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMIPAddress * addr6; - GError * error = NULL; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMIPAddress *addr6; + GError *error = NULL; connection = nm_simple_connection_new(); @@ -4745,12 +4745,12 @@ test_write_wired_static_ip6_only(void) static void test_write_ip6_disabled(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = nmtst_create_minimal_connection("Test Write Wired Disabled IP6", NULL, @@ -4792,19 +4792,19 @@ test_write_ip6_disabled(void) static void test_write_wired_static_ip6_only_gw(gconstpointer user_data) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMIPAddress * addr6; - GError * error = NULL; - gs_free char * id = NULL; - gs_free char * written_ifcfg_gateway = NULL; - const char * gateway6 = user_data; - shvarFile * ifcfg; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMIPAddress *addr6; + GError *error = NULL; + gs_free char *id = NULL; + gs_free char *written_ifcfg_gateway = NULL; + const char *gateway6 = user_data; + shvarFile *ifcfg; connection = nm_simple_connection_new(); @@ -4877,14 +4877,14 @@ test_write_wired_static_ip6_only_gw(gconstpointer user_data) static void test_read_write_static_routes_legacy(void) { - nmtst_auto_unlinkfile char *testfile = NULL; - nmtst_auto_unlinkfile char *routefile = NULL; - gs_free char * route6file = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *routefile = NULL; + gs_free char *route6file = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - const char * tmp; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + const char *tmp; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-static-routes-legacy", NULL, @@ -4927,17 +4927,17 @@ test_read_write_static_routes_legacy(void) static void test_write_wired_static_routes(void) { - nmtst_auto_unlinkfile char *testfile = NULL; - nmtst_auto_unlinkfile char *routefile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *routefile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMIPAddress * addr; - NMIPRoute * route; - GError * error = NULL; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMIPAddress *addr; + NMIPRoute *route; + GError *error = NULL; gboolean reread_same = FALSE; connection = nm_simple_connection_new(); @@ -5041,16 +5041,16 @@ test_write_wired_static_routes(void) static void test_write_wired_dhcp_8021x_peap_mschapv2(void) { - nmtst_auto_unlinkfile char *keyfile = NULL; - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSetting8021x * s_8021x; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSetting8021x *s_8021x; gboolean success; - GError * error = NULL; + GError *error = NULL; connection = nm_simple_connection_new(); @@ -5119,21 +5119,21 @@ test_write_wired_dhcp_8021x_peap_mschapv2(void) static void test_write_wired_8021x_tls(gconstpointer test_data) { - nmtst_auto_unlinkfile char *testfile = NULL; - gs_free char * keyfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_free char *keyfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSetting8021x * s_8021x; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSetting8021x *s_8021x; gboolean success; - GError * error = NULL; + GError *error = NULL; NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; - const char * pw; - gs_free char * tmp1 = NULL; - gs_free char * tmp2 = NULL; - gs_free char * tmp3 = NULL; + const char *pw; + gs_free char *tmp1 = NULL; + gs_free char *tmp2 = NULL; + gs_free char *tmp3 = NULL; gpointer scheme_p, flags_p; NMSetting8021xCKScheme scheme; NMSettingSecretFlags flags; @@ -5277,17 +5277,17 @@ test_write_wired_8021x_tls(gconstpointer test_data) static void test_write_wired_aliases(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; int num_addresses = 4; - 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; - GError * error = NULL; - shvarFile * ifcfg; + 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; + GError *error = NULL; + shvarFile *ifcfg; int i, j; nmtst_file_unlink_if_exists(TEST_SCRATCH_ALIAS_BASE ":2"); @@ -5404,14 +5404,14 @@ test_write_wired_aliases(void) static void test_write_gateway(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - GError * error = NULL; - shvarFile * f; - NMIPAddress * addr; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + GError *error = NULL; + shvarFile *f; + NMIPAddress *addr; connection = nm_simple_connection_new(); @@ -5471,14 +5471,14 @@ test_write_gateway(void) static void test_write_wifi_open(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - gs_unref_bytes GBytes *ssid = + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_arr(0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44); shvarFile *ifcfg; @@ -5543,14 +5543,14 @@ test_write_wifi_open(void) static void test_write_wifi_open_hex_ssid(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_arr(0x11, + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_arr(0x11, 0x22, 0x33, 0x44, @@ -5609,17 +5609,17 @@ test_write_wifi_open_hex_ssid(void) static void test_write_wifi_wep(void) { - nmtst_auto_unlinkfile char *testfile = NULL; - nmtst_auto_unlinkfile char *keyfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); - struct stat statbuf; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + struct stat statbuf; connection = nm_simple_connection_new(); @@ -5687,19 +5687,19 @@ test_write_wifi_wep(void) static void test_write_wifi_wep_adhoc(void) { - nmtst_auto_unlinkfile char *testfile = NULL; - nmtst_auto_unlinkfile char *keyfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - GError * error = NULL; - gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); - struct stat statbuf; - NMIPAddress * addr; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + GError *error = NULL; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + struct stat statbuf; + NMIPAddress *addr; connection = nm_simple_connection_new(); @@ -5763,17 +5763,17 @@ test_write_wifi_wep_adhoc(void) static void test_write_wifi_wep_passphrase(void) { - nmtst_auto_unlinkfile char *testfile = NULL; - nmtst_auto_unlinkfile char *keyfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); - struct stat statbuf; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + struct stat statbuf; connection = nm_simple_connection_new(); @@ -5838,17 +5838,17 @@ test_write_wifi_wep_passphrase(void) static void test_write_wifi_wep_40_ascii(void) { - nmtst_auto_unlinkfile char *testfile = NULL; - nmtst_auto_unlinkfile char *keyfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah40"); - struct stat statbuf; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah40"); + struct stat statbuf; connection = nm_simple_connection_new(); @@ -5916,17 +5916,17 @@ test_write_wifi_wep_40_ascii(void) static void test_write_wifi_wep_104_ascii(void) { - nmtst_auto_unlinkfile char *testfile = NULL; - nmtst_auto_unlinkfile char *keyfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah104"); - struct stat statbuf; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah104"); + struct stat statbuf; connection = nm_simple_connection_new(); @@ -5997,17 +5997,17 @@ test_write_wifi_wep_104_ascii(void) static void test_write_wifi_leap(void) { - nmtst_auto_unlinkfile char *testfile = NULL; - nmtst_auto_unlinkfile char *keyfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); - struct stat statbuf; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + struct stat statbuf; connection = nm_simple_connection_new(); @@ -6074,17 +6074,17 @@ test_write_wifi_leap(void) static void test_write_wifi_leap_secret_flags(gconstpointer data) { - nmtst_auto_unlinkfile char *testfile = NULL; - gs_free char * keyfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_free char *keyfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); - NMSettingSecretFlags flags = GPOINTER_TO_UINT(data); + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + NMSettingSecretFlags flags = GPOINTER_TO_UINT(data); connection = nm_simple_connection_new(); g_assert(connection); @@ -6152,16 +6152,16 @@ test_write_wifi_leap_secret_flags(gconstpointer data) static void test_write_wifi_wpa_psk(gconstpointer test_data) { - nmtst_auto_unlinkfile char *testfile = NULL; - nmtst_auto_unlinkfile char *keyfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); struct { const char *name, *psk; gpointer wep_group_p, wpa_p, wpa2_p; @@ -6248,18 +6248,18 @@ test_write_wifi_wpa_psk(gconstpointer test_data) static void test_write_wifi_wpa_psk_adhoc(void) { - nmtst_auto_unlinkfile char *testfile = NULL; - nmtst_auto_unlinkfile char *keyfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - GError * error = NULL; - gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); - NMIPAddress * addr; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + GError *error = NULL; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + NMIPAddress *addr; connection = nm_simple_connection_new(); @@ -6337,19 +6337,19 @@ test_write_wifi_wpa_psk_adhoc(void) static void test_write_wifi_wpa_eap_tls(void) { - nmtst_auto_unlinkfile char *testfile = NULL; - nmtst_auto_unlinkfile char *keyfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - NMSetting8021x * s_8021x; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMSetting8021x *s_8021x; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; gboolean success; - GError * error = NULL; - gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + GError *error = NULL; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); connection = nm_simple_connection_new(); @@ -6441,19 +6441,19 @@ test_write_wifi_wpa_eap_tls(void) static void test_write_wifi_wpa_eap_ttls_tls(void) { - nmtst_auto_unlinkfile char *testfile = NULL; - nmtst_auto_unlinkfile char *keyfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - NMSetting8021x * s_8021x; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMSetting8021x *s_8021x; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; gboolean success; - GError * error = NULL; - gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + GError *error = NULL; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); connection = nm_simple_connection_new(); @@ -6553,19 +6553,19 @@ test_write_wifi_wpa_eap_ttls_tls(void) static void test_write_wifi_wpa_eap_ttls_mschapv2(void) { - nmtst_auto_unlinkfile char *testfile = NULL; - nmtst_auto_unlinkfile char *keyfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - NMSetting8021x * s_8021x; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMSetting8021x *s_8021x; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; gboolean success; - GError * error = NULL; - gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + GError *error = NULL; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); connection = nm_simple_connection_new(); @@ -6643,17 +6643,17 @@ test_write_wifi_wpa_eap_ttls_mschapv2(void) static void test_write_wifi_wpa_then_open(void) { - nmtst_auto_unlinkfile char *testfile = NULL; - gs_free char * keyfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_free char *keyfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread1 = NULL; gs_unref_object NMConnection *reread2 = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); /* Test that writing out a WPA config then changing that to an open * config doesn't leave various WPA-related keys lying around in the ifcfg. @@ -6739,18 +6739,18 @@ test_write_wifi_wpa_then_open(void) static void test_write_wifi_wpa_then_wep_with_perms(void) { - nmtst_auto_unlinkfile char *testfile = NULL; - nmtst_auto_unlinkfile char *keyfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread1 = NULL; gs_unref_object NMConnection *reread2 = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; gboolean success; - gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("SomeSSID"); + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("SomeSSID"); /* Test that writing out a WPA config then changing that to a WEP * config works and doesn't cause infinite loop or other issues. @@ -6848,18 +6848,18 @@ test_write_wifi_wpa_then_wep_with_perms(void) static void test_write_wifi_dynamic_wep_leap(void) { - nmtst_auto_unlinkfile char *testfile = NULL; - nmtst_auto_unlinkfile char *keyfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - NMSetting8021x * s_8021x; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); - shvarFile * ifcfg; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMSetting8021x *s_8021x; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + shvarFile *ifcfg; connection = nm_simple_connection_new(); @@ -6927,13 +6927,13 @@ test_write_wifi_dynamic_wep_leap(void) static void test_write_wired_qeth_dhcp(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = nm_simple_connection_new(); @@ -6985,14 +6985,14 @@ test_write_wired_qeth_dhcp(void) static void test_write_wired_ctc_dhcp(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - shvarFile * ifcfg; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + shvarFile *ifcfg; connection = nm_simple_connection_new(); @@ -7048,12 +7048,12 @@ test_write_wired_ctc_dhcp(void) static void test_write_permissions(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = nm_simple_connection_new(); @@ -7101,15 +7101,15 @@ test_write_permissions(void) static void test_write_wifi_wep_agent_keys(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("foobarbaz"); + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("foobarbaz"); connection = nm_simple_connection_new(); g_assert(connection != NULL); @@ -7177,9 +7177,9 @@ static void test_write_wired_pppoe(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingPppoe * s_pppoe; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingPppoe *s_pppoe; connection = nm_simple_connection_new(); @@ -7221,9 +7221,9 @@ static void test_write_vpn(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingVpn * s_vpn; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingVpn *s_vpn; connection = nm_simple_connection_new(); @@ -7262,10 +7262,10 @@ static void test_write_mobile_broadband(gconstpointer data) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingCdma * s_cdma; - NMSettingSerial * s_serial; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingCdma *s_cdma; + NMSettingSerial *s_serial; gboolean gsm = GPOINTER_TO_UINT(data); connection = nm_simple_connection_new(); @@ -7315,9 +7315,9 @@ static void test_read_bridge_main(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingBridge * s_bridge; - NMSettingWired * s_wired; - const char * mac; + NMSettingBridge *s_bridge; + NMSettingWired *s_wired; + const char *mac; char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; connection = @@ -7346,18 +7346,18 @@ test_read_bridge_main(void) static void test_write_bridge_main(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingBridge * s_bridge; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMIPAddress * addr; - static const char * mac = "31:33:33:37:be:cd"; - GError * error = NULL; - gs_unref_ptrarray GPtrArray *vlans = NULL; - NMBridgeVlan * vlan; + NMSettingConnection *s_con; + NMSettingBridge *s_bridge; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMIPAddress *addr; + static const char *mac = "31:33:33:37:be:cd"; + GError *error = NULL; + gs_unref_ptrarray GPtrArray *vlans = NULL; + NMBridgeVlan *vlan; connection = nm_simple_connection_new(); g_assert(connection); @@ -7437,8 +7437,8 @@ static void test_read_bridge_component(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingBridgePort * s_port; + NMSettingConnection *s_con; + NMSettingBridgePort *s_port; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bridge-component", NULL, @@ -7460,16 +7460,16 @@ test_read_bridge_component(void) static void test_write_bridge_component(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSetting * s_port; - static const char * mac = "31:33:33:37:be:cd"; - guint32 mtu = 1492; - gs_unref_ptrarray GPtrArray *vlans = NULL; - NMBridgeVlan * vlan; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSetting *s_port; + static const char *mac = "31:33:33:37:be:cd"; + guint32 mtu = 1492; + gs_unref_ptrarray GPtrArray *vlans = NULL; + NMBridgeVlan *vlan; connection = nm_simple_connection_new(); g_assert(connection); @@ -7531,7 +7531,7 @@ static void test_read_bridge_missing_stp(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingBridge * s_bridge; + NMSettingBridge *s_bridge; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bridge-missing-stp", NULL, @@ -7550,7 +7550,7 @@ static void test_read_vlan_interface(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingVlan * s_vlan; + NMSettingVlan *s_vlan; guint32 from = 0; guint32 to = 0; @@ -7599,7 +7599,7 @@ static void test_read_vlan_only_vlan_id(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingVlan * s_vlan; + NMSettingVlan *s_vlan; connection = _connection_from_file(TEST_IFCFG_VLAN_ONLY_VLANID, NULL, TYPE_ETHERNET, NULL); @@ -7615,10 +7615,10 @@ test_read_vlan_only_vlan_id(void) static void test_read_vlan_vlanid_use(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingVlan * s_vlan; + NMSettingVlan *s_vlan; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-vlanid-use", NULL, @@ -7647,7 +7647,7 @@ static void test_read_vlan_only_device(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingVlan * s_vlan; + NMSettingVlan *s_vlan; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-only-device", NULL, @@ -7666,7 +7666,7 @@ static void test_read_vlan_physdev(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingVlan * s_vlan; + NMSettingVlan *s_vlan; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-physdev", NULL, TYPE_ETHERNET, NULL); @@ -7683,7 +7683,7 @@ static void test_read_vlan_reorder_hdr_1(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingVlan * s_vlan; + NMSettingVlan *s_vlan; NMTST_EXPECT_NM_WARN("*REORDER_HDR key is deprecated, use VLAN_FLAGS*"); connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-reorder-hdr-1", @@ -7706,7 +7706,7 @@ static void test_read_vlan_reorder_hdr_2(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingVlan * s_vlan; + NMSettingVlan *s_vlan; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-reorder-hdr-2", NULL, @@ -7727,7 +7727,7 @@ static void test_read_vlan_flags_1(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingVlan * s_vlan; + NMSettingVlan *s_vlan; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-flags-1", NULL, TYPE_ETHERNET, NULL); @@ -7747,7 +7747,7 @@ static void test_read_vlan_flags_2(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingVlan * s_vlan; + NMSettingVlan *s_vlan; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-flags-2", NULL, TYPE_ETHERNET, NULL); @@ -7766,7 +7766,7 @@ test_read_vlan_flags_2(void) static void test_write_vlan(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; connection = _connection_from_file(TEST_IFCFG_VLAN_INTERFACE, NULL, TYPE_VLAN, NULL); @@ -7780,7 +7780,7 @@ test_write_vlan(void) static void test_write_vlan_flags(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; @@ -7797,7 +7797,7 @@ test_write_vlan_flags(void) static void test_write_vlan_only_vlanid(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; @@ -7813,11 +7813,11 @@ test_write_vlan_only_vlanid(void) static void test_write_vlan_reorder_hdr(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingVlan * s_vlan; + NMSettingConnection *s_con; + NMSettingVlan *s_vlan; connection = nm_simple_connection_new(); @@ -7858,11 +7858,11 @@ test_write_vlan_reorder_hdr(void) static void test_write_ethernet_missing_ipv6(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; connection = nm_simple_connection_new(); g_assert(connection); @@ -7921,7 +7921,7 @@ static void test_read_bond_main(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingBond * s_bond; + NMSettingBond *s_bond; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bond-main", NULL, TYPE_ETHERNET, NULL); @@ -7939,7 +7939,7 @@ static void test_read_bond_eth_type(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingBond * s_bond; + NMSettingBond *s_bond; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bond-eth-type", NULL, @@ -7961,15 +7961,15 @@ test_read_bond_eth_type(void) static void test_write_bond_main(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingBond * s_bond; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMIPAddress * addr; - GError * error = NULL; + NMSettingConnection *s_con; + NMSettingBond *s_bond; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMIPAddress *addr; + GError *error = NULL; connection = nm_simple_connection_new(); @@ -8030,7 +8030,7 @@ static void test_read_bond_slave(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; + NMSettingConnection *s_con; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bond-slave", NULL, TYPE_ETHERNET, NULL); @@ -8046,12 +8046,12 @@ test_read_bond_slave(void) static void test_write_bond_slave(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - static const char * mac = "31:33:33:37:be:cd"; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + static const char *mac = "31:33:33:37:be:cd"; guint32 mtu = 1492; connection = nm_simple_connection_new(); @@ -8088,8 +8088,8 @@ static void test_read_bond_port(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con = NULL; - NMSettingBondPort * s_port = NULL; + NMSettingConnection *s_con = NULL; + NMSettingBondPort *s_port = NULL; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bond-port", NULL, TYPE_ETHERNET, NULL); @@ -8105,11 +8105,11 @@ test_read_bond_port(void) static void test_write_bond_port(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingBondPort * s_bond_port; + NMSettingConnection *s_con; + NMSettingBondPort *s_bond_port; connection = nm_simple_connection_new(); @@ -8147,9 +8147,9 @@ static void test_read_infiniband(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingInfiniband * s_infiniband; - char * unmanaged = NULL; - const char * mac; + NMSettingInfiniband *s_infiniband; + char *unmanaged = NULL; + const char *mac; char expected_mac_address[INFINIBAND_ALEN] = {0x80, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22}; @@ -8175,17 +8175,17 @@ test_read_infiniband(void) static void test_write_infiniband(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingInfiniband * s_infiniband; - 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"; + NMSettingConnection *s_con; + NMSettingInfiniband *s_infiniband; + 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; NMIPAddress *addr; - GError * error = NULL; + GError *error = NULL; connection = nm_simple_connection_new(); @@ -8242,7 +8242,7 @@ static void test_read_bond_slave_ib(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; + NMSettingConnection *s_con; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bond-slave-ib", NULL, NULL, NULL); @@ -8256,11 +8256,11 @@ test_read_bond_slave_ib(void) static void test_write_bond_slave_ib(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingInfiniband * s_infiniband; + NMSettingConnection *s_con; + NMSettingInfiniband *s_infiniband; static const char *mac = "80:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22"; connection = nm_simple_connection_new(); @@ -8304,8 +8304,8 @@ static void test_read_bond_opts_mode_numeric(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingBond * s_bond; + NMSettingConnection *s_con; + NMSettingBond *s_bond; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bond-mode-numeric", NULL, @@ -8332,7 +8332,7 @@ static void test_read_dcb_basic(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingDcb * s_dcb; + NMSettingDcb *s_dcb; guint i; guint expected_group_ids[8] = {0, 0, 0, 0, 1, 1, 1, 0xF}; guint expected_group_bandwidths[8] = {25, 0, 0, 75, 0, 0, 0, 0}; @@ -8394,13 +8394,13 @@ test_read_dcb_basic(void) static void test_write_dcb_basic(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingDcb * s_dcb; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingConnection *s_con; + NMSettingDcb *s_dcb; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; guint i; const guint group_ids[8] = {4, 0xF, 6, 0xF, 1, 7, 3, 0xF}; const guint group_bandwidths[8] = {10, 20, 15, 10, 2, 3, 35, 5}; @@ -8476,7 +8476,7 @@ static void test_read_dcb_default_app_priorities(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingDcb * s_dcb; + NMSettingDcb *s_dcb; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-dcb-default-app-priorities", NULL, @@ -8611,9 +8611,9 @@ static void test_read_fcoe_mode(gconstpointer user_data) { gs_unref_object NMConnection *connection = NULL; - gs_free char * file = NULL; - const char * expected_mode = user_data; - NMSettingDcb * s_dcb; + gs_free char *file = NULL; + const char *expected_mode = user_data; + NMSettingDcb *s_dcb; file = g_strdup_printf(TEST_IFCFG_DIR "/ifcfg-test-fcoe-%s", expected_mode); connection = _connection_from_file(file, NULL, TYPE_ETHERNET, NULL); @@ -8627,15 +8627,15 @@ test_read_fcoe_mode(gconstpointer user_data) static void test_write_fcoe_mode(gconstpointer user_data) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - const char * expected_mode = user_data; - NMSettingConnection * s_con; - NMSettingDcb * s_dcb; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - shvarFile * ifcfg; + const char *expected_mode = user_data; + NMSettingConnection *s_con; + NMSettingDcb *s_dcb; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + shvarFile *ifcfg; connection = nm_simple_connection_new(); @@ -8683,11 +8683,11 @@ test_write_fcoe_mode(gconstpointer user_data) static void test_read_team_master(gconstpointer user_data) { - const char *const PATH_NAME = user_data; + const char *const PATH_NAME = user_data; gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingTeam * s_team; - const char * expected_config = + NMSettingConnection *s_con; + NMSettingTeam *s_team; + const char *expected_config = "{\"device\": \"team0\", \"link_watch\": {\"name\": \"ethtool\"}}"; connection = _connection_from_file(PATH_NAME, NULL, TYPE_ETHERNET, NULL); @@ -8706,8 +8706,8 @@ test_read_team_master(gconstpointer user_data) static void test_read_team_master_invalid(gconstpointer user_data) { - const char *const PATH_NAME = user_data; - gs_free_error GError *error = NULL; + const char *const PATH_NAME = user_data; + gs_free_error GError *error = NULL; gs_unref_object NMConnection *connection = NULL; if (nm_json_vt()) { @@ -8722,14 +8722,14 @@ test_read_team_master_invalid(gconstpointer user_data) static void test_write_team_master(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingTeam * s_team; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - const char * expected_config = + NMSettingConnection *s_con; + NMSettingTeam *s_team; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + const char *expected_config = "{\"device\": \"team0\", \"link_watch\": {\"name\": \"ethtool\"}}"; shvarFile *f; @@ -8777,11 +8777,11 @@ test_write_team_master(void) static void test_read_team_port(gconstpointer user_data) { - const char *const PATH_NAME = user_data; + const char *const PATH_NAME = user_data; gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingTeamPort * s_team_port; - const char * expected_config = "{\"p4p1\": {\"prio\": -10, \"sticky\": true}}"; + NMSettingConnection *s_con; + NMSettingTeamPort *s_team_port; + const char *expected_config = "{\"p4p1\": {\"prio\": -10, \"sticky\": true}}"; connection = _connection_from_file(PATH_NAME, NULL, TYPE_ETHERNET, NULL); @@ -8798,13 +8798,13 @@ test_read_team_port(gconstpointer user_data) static void test_write_team_port(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingTeamPort * s_team_port; - const char * expected_config = "{\"p4p1\": {\"prio\": -10, \"sticky\": true}}"; - shvarFile * f; + NMSettingConnection *s_con; + NMSettingTeamPort *s_team_port; + const char *expected_config = "{\"p4p1\": {\"prio\": -10, \"sticky\": true}}"; + shvarFile *f; connection = nm_simple_connection_new(); @@ -8849,14 +8849,14 @@ test_write_team_port(void) static void test_write_team_infiniband_port(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingTeamPort * s_team_port; - NMSettingInfiniband * s_infiniband; - const char * expected_config = "{\"inf1\": {\"prio\": -10, \"sticky\": true}}"; - shvarFile * f; + NMSettingConnection *s_con; + NMSettingTeamPort *s_team_port; + NMSettingInfiniband *s_infiniband; + const char *expected_config = "{\"inf1\": {\"prio\": -10, \"sticky\": true}}"; + shvarFile *f; connection = nm_simple_connection_new(); @@ -8905,8 +8905,8 @@ static void test_read_team_port_empty_config(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingTeamPort * s_team_port; + NMSettingConnection *s_con; + NMSettingTeamPort *s_team_port; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-team-port-empty-config", NULL, @@ -8929,12 +8929,12 @@ test_read_team_port_empty_config(void) static void test_team_reread_slave(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection_1 = NULL; gs_unref_object NMConnection *connection_2 = NULL; gs_unref_object NMConnection *reread = NULL; gboolean reread_same = FALSE; - NMSettingConnection * s_con; + NMSettingConnection *s_con; connection_1 = nmtst_create_connection_from_keyfile("[connection]\n" @@ -9006,7 +9006,7 @@ static void test_read_proxy_basic(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingProxy * s_proxy; + NMSettingProxy *s_proxy; /* Test basic proxy configuration */ @@ -9027,13 +9027,13 @@ test_read_proxy_basic(void) static void test_write_proxy_basic(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingProxy * s_proxy; - const char * expected_url = "https://wpad.neverland.org/wpad.dat"; - shvarFile * f; + NMSettingConnection *s_con; + NMSettingProxy *s_proxy; + const char *expected_url = "https://wpad.neverland.org/wpad.dat"; + shvarFile *f; connection = nm_simple_connection_new(); @@ -9076,7 +9076,7 @@ test_write_proxy_basic(void) static const char * _svUnescape(const char *str, char **to_free) { - const char * s; + const char *s; gs_free char *str_free = NULL; g_assert(str); @@ -9097,7 +9097,7 @@ _svUnescape(const char *str, char **to_free) } { - const char * s2; + const char *s2; gs_free char *to_free2 = NULL; gboolean is_utf8 = s && g_utf8_validate(s, -1, NULL); @@ -9140,7 +9140,7 @@ static void do_svUnescape_assert(const char *str, const char *expected) { gs_free char *to_free = NULL; - const char * s; + const char *s; s = _svUnescape(str, &to_free); g_assert_cmpstr(s, ==, expected); @@ -9149,7 +9149,7 @@ do_svUnescape_assert(const char *str, const char *expected) if (expected) { gs_free char *s1_free = NULL; gs_free char *s2_free = NULL; - const char * s1, *s2; + const char *s1, *s2; s1 = svEscape(expected, &s1_free); g_assert(s1); @@ -9162,8 +9162,8 @@ do_svUnescape_assert(const char *str, const char *expected) } static void -do_svUnescape_combine_ansi_append(GString * str_val, - GString * str_exp, +do_svUnescape_combine_ansi_append(GString *str_val, + GString *str_exp, const UnescapeTestData *data, gboolean honor_needs_ascii_separator) { @@ -9180,8 +9180,8 @@ do_svUnescape_combine_ansi_append(GString * str_val, } static void -do_svUnescape_combine_ansi(GString * str_val, - GString * str_exp, +do_svUnescape_combine_ansi(GString *str_val, + GString *str_exp, const UnescapeTestData *data_ansi, gsize data_len, gssize idx) @@ -9401,7 +9401,7 @@ test_svUnescape(void) #undef V0 #undef V1 #undef V2 - gsize i; + gsize i; nm_auto_free_gstring GString *str_val = g_string_new(NULL); nm_auto_free_gstring GString *str_val2 = g_string_new(NULL); nm_auto_free_gstring GString *str_exp = g_string_new(NULL); @@ -9470,13 +9470,13 @@ static void test_write_unknown(gconstpointer test_data) { nmtst_auto_unlinkfile char *filename_tmp_1 = g_strdup(TEST_SCRATCH_DIR_TMP "/tmp-1"); - const char * testfile = test_data; - gs_free char * testfile_expected = g_strconcat(testfile, ".expected", NULL); - shvarFile * sv; - gs_free_error GError *error = NULL; - gboolean success; - gs_free char * file_contents_out = NULL; - gs_free char * file_contents_exp = NULL; + const char *testfile = test_data; + gs_free char *testfile_expected = g_strconcat(testfile, ".expected", NULL); + shvarFile *sv; + gs_free_error GError *error = NULL; + gboolean success; + gs_free char *file_contents_out = NULL; + gs_free char *file_contents_exp = NULL; sv = _svOpenFile(testfile); @@ -9519,12 +9519,12 @@ test_write_unknown(gconstpointer test_data) static void test_read_vlan_trailing_spaces(void) { - const char * testfile = TEST_IFCFG_DIR "/ifcfg-test-vlan-trailing-spaces"; + const char *testfile = TEST_IFCFG_DIR "/ifcfg-test-vlan-trailing-spaces"; gs_unref_object NMConnection *connection = NULL; gboolean success; - GError * error = NULL; - NMSettingVlan * s_vlan; - gs_free char * contents = NULL; + GError *error = NULL; + NMSettingVlan *s_vlan; + gs_free 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 @@ -9681,12 +9681,12 @@ static void test_sriov_read(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingSriov * s_sriov; - NMSriovVF * vf; - GVariant * variant; - GError * error = NULL; - gs_free char * str1 = NULL; - gs_free char * str2 = NULL; + NMSettingSriov *s_sriov; + NMSriovVF *vf; + GVariant *variant; + GError *error = NULL; + gs_free char *str1 = NULL; + gs_free char *str2 = NULL; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-sriov", NULL, TYPE_ETHERNET, NULL); @@ -9730,17 +9730,17 @@ test_sriov_read(void) static void test_sriov_write(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSettingSriov * s_sriov; - NMSriovVF * vf; - gs_unref_ptrarray GPtrArray *vfs = NULL; - NMIPAddress * addr; - GError * error = NULL; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingSriov *s_sriov; + NMSriovVF *vf; + gs_unref_ptrarray GPtrArray *vfs = NULL; + NMIPAddress *addr; + GError *error = NULL; connection = nm_simple_connection_new(); @@ -9819,10 +9819,10 @@ static void test_tc_read(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingTCConfig * s_tc; - NMTCQdisc * qdisc; - NMTCTfilter * filter; - gs_free char * str = NULL; + NMSettingTCConfig *s_tc; + NMTCQdisc *qdisc; + NMTCTfilter *filter; + gs_free char *str = NULL; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-tc", NULL, TYPE_ETHERNET, NULL); @@ -9847,14 +9847,14 @@ test_tc_read(void) static void test_tc_write_empty(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMIPAddress * addr; - GError * error = NULL; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMIPAddress *addr; + GError *error = NULL; connection = nm_simple_connection_new(); @@ -9911,17 +9911,17 @@ test_tc_write_empty(void) static void test_tc_write(void) { - nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSettingTCConfig * s_tc; - NMTCQdisc * qdisc; - NMTCTfilter * tfilter; - NMIPAddress * addr; - GError * error = NULL; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingTCConfig *s_tc; + NMTCQdisc *qdisc; + NMTCTfilter *tfilter; + NMIPAddress *addr; + GError *error = NULL; connection = nm_simple_connection_new(); @@ -10014,7 +10014,7 @@ test_well_known_keys(void) for (i = 0; i < G_N_ELEMENTS(nms_ifcfg_well_known_keys); i++) { const NMSIfcfgKeyTypeInfo *ti = &nms_ifcfg_well_known_keys[i]; - gs_free char * key_name = NULL; + gs_free char *key_name = NULL; gssize idx; g_assert(ti == nms_ifcfg_well_known_key_find_info(ti->key_name, &idx)); @@ -10029,7 +10029,7 @@ test_well_known_keys(void) G_STMT_START \ { \ const NMSIfcfgKeyTypeInfo *_ti; \ - const char * _expected = (expected); \ + const char *_expected = (expected); \ \ _ti = nms_ifcfg_rh_utils_is_well_known_key("" key ""); \ if (!_expected) { \ diff --git a/src/core/settings/plugins/ifupdown/nms-ifupdown-interface-parser.c b/src/core/settings/plugins/ifupdown/nms-ifupdown-interface-parser.c index 84986877..af63a410 100644 --- a/src/core/settings/plugins/ifupdown/nms-ifupdown-interface-parser.c +++ b/src/core/settings/plugins/ifupdown/nms-ifupdown-interface-parser.c @@ -55,8 +55,8 @@ static void add_data(if_parser *parser, const char *key, const char *data) { if_block *last_block; - if_data * ifd; - char * idx; + if_data *ifd; + char *idx; gsize l_key, l_data; last_block = c_list_last_entry(&parser->block_lst_head, if_block, block_lst); @@ -250,11 +250,11 @@ _recursive_ifparser(if_parser *parser, const char *eni_file, int quiet) static void _ifparser_source(if_parser *parser, const char *path, const char *en_dir, int quiet, int dir) { - char * abs_path; + char *abs_path; const char *item; wordexp_t we; - GDir * source_dir; - GError * error = NULL; + GDir *source_dir; + GError *error = NULL; uint i; if (g_path_is_absolute(path)) diff --git a/src/core/settings/plugins/ifupdown/nms-ifupdown-interface-parser.h b/src/core/settings/plugins/ifupdown/nms-ifupdown-interface-parser.h index dd0e15fb..17f858c0 100644 --- a/src/core/settings/plugins/ifupdown/nms-ifupdown-interface-parser.h +++ b/src/core/settings/plugins/ifupdown/nms-ifupdown-interface-parser.h @@ -32,8 +32,8 @@ void ifparser_destroy(if_parser *parser); NM_AUTO_DEFINE_FCN0(if_parser *, _nm_auto_ifparser, ifparser_destroy); #define nm_auto_ifparser nm_auto(_nm_auto_ifparser) -if_block * ifparser_getif(if_parser *parser, const char *iface); -if_block * ifparser_getfirst(if_parser *parser); +if_block *ifparser_getif(if_parser *parser, const char *iface); +if_block *ifparser_getfirst(if_parser *parser); const char *ifparser_getkey(if_block *iface, const char *key); gboolean ifparser_haskey(if_block *iface, const char *key); diff --git a/src/core/settings/plugins/ifupdown/nms-ifupdown-parser.c b/src/core/settings/plugins/ifupdown/nms-ifupdown-parser.c index 5bad2362..c079266e 100644 --- a/src/core/settings/plugins/ifupdown/nms-ifupdown-parser.c +++ b/src/core/settings/plugins/ifupdown/nms-ifupdown-parser.c @@ -58,7 +58,7 @@ _ifupdownplugin_guess_connection_type(if_block *block) } struct _Mapping { - const char * domain; + const char *domain; const gpointer target; }; @@ -78,8 +78,8 @@ map_by_mapping(struct _Mapping *mapping, const char *key) static void update_wireless_setting_from_if_block(NMConnection *connection, if_block *block) { - if_data * curr; - const char * value = ifparser_getkey(block, "inet"); + if_data *curr; + const char *value = ifparser_getkey(block, "inet"); struct _Mapping mapping[] = {{"ssid", "ssid"}, {"essid", "ssid"}, {"mode", "mode"}, @@ -210,7 +210,7 @@ static gpointer string_to_glist_of_strings(const char *data) { GSList *ret = NULL; - char * string = (char *) data; + char *string = (char *) data; while (string) { char *next = NULL; if ((next = strchr(string, ' ')) || (next = strchr(string, '\t')) @@ -237,8 +237,8 @@ slist_free_all(gpointer slist) static void update_wireless_security_setting_from_if_block(NMConnection *connection, if_block *block) { - if_data * curr; - const char * value = ifparser_getkey(block, "inet"); + if_data *curr; + const char *value = ifparser_getkey(block, "inet"); struct _Mapping mapping[] = {{"psk", "psk"}, {"identity", "leap-username"}, {"password", "leap-password"}, @@ -283,7 +283,7 @@ update_wireless_security_setting_from_if_block(NMConnection *connection, if_bloc {NULL, NULL}}; NMSettingWirelessSecurity *wireless_security_setting; - NMSettingWireless * s_wireless; + NMSettingWireless *s_wireless; gboolean security = FALSE; if (nm_streq0(value, "ppp")) @@ -297,10 +297,10 @@ update_wireless_security_setting_from_if_block(NMConnection *connection, if_bloc c_list_for_each_entry (curr, &block->data_lst_head, data_lst) { if (NM_STR_HAS_PREFIX_WITH_MORE(curr->key, "wireless-")) { - const char * key = curr->key + NM_STRLEN("wireless-"); - char * property_value = NULL; + const char *key = curr->key + NM_STRLEN("wireless-"); + char *property_value = NULL; gpointer typed_property_value = NULL; - const char * newkey = map_by_mapping(mapping, key); + const char *newkey = map_by_mapping(mapping, key); IfupdownStrDupeFunc dupe_func = map_by_mapping(dupe_mapping, key); IfupdownStrToTypeFunc type_map_func = map_by_mapping(type_mapping, key); GFreeFunc free_func = map_by_mapping(free_type_mapping, key); @@ -329,10 +329,10 @@ wireless_next: (*free_func)(typed_property_value); } else if (NM_STR_HAS_PREFIX_WITH_MORE(curr->key, "wpa-")) { - const char * key = curr->key + NM_STRLEN("wpa-"); - char * property_value = NULL; + const char *key = curr->key + NM_STRLEN("wpa-"); + char *property_value = NULL; gpointer typed_property_value = NULL; - const char * newkey = map_by_mapping(mapping, key); + const char *newkey = map_by_mapping(mapping, key); IfupdownStrDupeFunc dupe_func = map_by_mapping(dupe_mapping, key); IfupdownStrToTypeFunc type_map_func = map_by_mapping(type_mapping, key); GFreeFunc free_func = map_by_mapping(free_type_mapping, key); @@ -391,7 +391,7 @@ static void ifupdown_ip4_add_dns(NMSettingIPConfig *s_ip4, const char *dns) { gs_free const char **list = NULL; - const char ** iter; + const char **iter; guint32 addr; if (dns == NULL) @@ -413,19 +413,19 @@ static gboolean update_ip4_setting_from_if_block(NMConnection *connection, if_block *block, GError **error) { gs_unref_object NMSettingIPConfig *s_ip4 = NM_SETTING_IP_CONFIG(nm_setting_ip4_config_new()); - const char * type = ifparser_getkey(block, "inet"); + const char *type = ifparser_getkey(block, "inet"); if (!nm_streq0(type, "static")) { g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); } else { guint32 tmp_mask; NMIPAddress *addr; - const char * address_v; - const char * netmask_v; - const char * gateway_v; - const char * nameserver_v; - const char * nameservers_v; - const char * search_v; + const char *address_v; + const char *netmask_v; + const char *gateway_v; + const char *nameserver_v; + const char *nameservers_v; + const char *search_v; guint32 netmask_int = 32; /* Address */ @@ -495,7 +495,7 @@ update_ip4_setting_from_if_block(NMConnection *connection, if_block *block, GErr search_v = ifparser_getkey(block, "dns-search"); if (search_v) { gs_free const char **list = NULL; - const char ** iter; + const char **iter; list = nm_strsplit_set(search_v, " \t"); for (iter = list; iter && *iter; iter++) { @@ -515,7 +515,7 @@ static void ifupdown_ip6_add_dns(NMSettingIPConfig *s_ip6, const char *dns) { gs_free const char **list = NULL; - const char ** iter; + const char **iter; struct in6_addr addr; if (dns == NULL) @@ -537,18 +537,18 @@ static gboolean update_ip6_setting_from_if_block(NMConnection *connection, if_block *block, GError **error) { gs_unref_object NMSettingIPConfig *s_ip6 = NM_SETTING_IP_CONFIG(nm_setting_ip6_config_new()); - const char * type = ifparser_getkey(block, "inet6"); + const char *type = ifparser_getkey(block, "inet6"); if (!NM_IN_STRSET(type, "static", "v4tunnel")) { g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); } else { NMIPAddress *addr; - const char * address_v; - const char * prefix_v; - const char * gateway_v; - const char * nameserver_v; - const char * nameservers_v; - const char * search_v; + const char *address_v; + const char *prefix_v; + const char *gateway_v; + const char *nameserver_v; + const char *nameservers_v; + const char *search_v; guint prefix_int; address_v = ifparser_getkey(block, "address"); @@ -603,7 +603,7 @@ update_ip6_setting_from_if_block(NMConnection *connection, if_block *block, GErr search_v = ifparser_getkey(block, "dns-search"); if (search_v) { gs_free const char **list = NULL; - const char ** iter; + const char **iter; list = nm_strsplit_set(search_v, " \t"); for (iter = list; iter && *iter; iter++) { @@ -623,10 +623,10 @@ NMConnection * ifupdown_new_connection_from_if_block(if_block *block, gboolean autoconnect, GError **error) { gs_unref_object NMConnection *connection = NULL; - const char * type; - gs_free char * idstr = NULL; - gs_free char * uuid = NULL; - NMSettingConnection * s_con; + const char *type; + gs_free char *idstr = NULL; + gs_free char *uuid = NULL; + NMSettingConnection *s_con; connection = nm_simple_connection_new(); diff --git a/src/core/settings/plugins/ifupdown/nms-ifupdown-plugin.c b/src/core/settings/plugins/ifupdown/nms-ifupdown-plugin.c index 602a7327..14c82c55 100644 --- a/src/core/settings/plugins/ifupdown/nms-ifupdown-plugin.c +++ b/src/core/settings/plugins/ifupdown/nms-ifupdown-plugin.c @@ -25,7 +25,7 @@ /*****************************************************************************/ typedef struct { - NMConnection * connection; + NMConnection *connection; NMSettingsStorage *storage; } StorageData; @@ -107,17 +107,17 @@ initialize(NMSIfupdownPlugin *self) } static void -reload_connections(NMSettingsPlugin * plugin, +reload_connections(NMSettingsPlugin *plugin, NMSettingsPluginConnectionLoadCallback callback, gpointer user_data) { - NMSIfupdownPlugin * self = NMS_IFUPDOWN_PLUGIN(plugin); - NMSIfupdownPluginPrivate *priv = NMS_IFUPDOWN_PLUGIN_GET_PRIVATE(self); + NMSIfupdownPlugin *self = NMS_IFUPDOWN_PLUGIN(plugin); + NMSIfupdownPluginPrivate *priv = NMS_IFUPDOWN_PLUGIN_GET_PRIVATE(self); gs_unref_hashtable GHashTable *eni_ifaces_old = NULL; GHashTableIter iter; - StorageData * sd; - StorageData * sd2; - const char * block_name; + StorageData *sd; + StorageData *sd2; + const char *block_name; if (!priv->initialized) initialize(self); @@ -186,7 +186,7 @@ static GSList * _unmanaged_specs(GHashTable *eni_ifaces) { gs_free const char **keys = NULL; - GSList * specs = NULL; + GSList *specs = NULL; guint i, len; keys = nm_strdict_get_keys(eni_ifaces, TRUE, &len); @@ -201,7 +201,7 @@ _unmanaged_specs(GHashTable *eni_ifaces) static GSList * get_unmanaged_specs(NMSettingsPlugin *plugin) { - NMSIfupdownPlugin * self = NMS_IFUPDOWN_PLUGIN(plugin); + NMSIfupdownPlugin *self = NMS_IFUPDOWN_PLUGIN(plugin); NMSIfupdownPluginPrivate *priv = NMS_IFUPDOWN_PLUGIN_GET_PRIVATE(self); if (G_UNLIKELY(!priv->initialized)) @@ -222,9 +222,9 @@ load_eni_ifaces(NMSIfupdownPlugin *self) { gs_unref_hashtable GHashTable *eni_ifaces = NULL; gs_unref_hashtable GHashTable *auto_ifaces = NULL; - nm_auto_ifparser if_parser *parser = NULL; - if_block * block; - StorageData * sd; + nm_auto_ifparser if_parser *parser = NULL; + if_block *block; + StorageData *sd; eni_ifaces = g_hash_table_new_full(nm_str_hash, g_str_equal, @@ -246,11 +246,11 @@ load_eni_ifaces(NMSIfupdownPlugin *self) continue; if (nm_streq(block->type, "iface")) { - gs_free_error GError *local = NULL; - gs_unref_object NMConnection *connection = NULL; - gs_unref_object NMSettingsStorage *storage = NULL; - const char * uuid = NULL; - StorageData * sd_repl; + gs_free_error GError *local = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMSettingsStorage *storage = NULL; + const char *uuid = NULL; + StorageData *sd_repl; /* Bridge configuration */ if (g_str_has_prefix(block->name, "br")) { @@ -369,7 +369,7 @@ nms_ifupdown_plugin_init(NMSIfupdownPlugin *self) static void dispose(GObject *object) { - NMSIfupdownPlugin * plugin = NMS_IFUPDOWN_PLUGIN(object); + NMSIfupdownPlugin *plugin = NMS_IFUPDOWN_PLUGIN(object); NMSIfupdownPluginPrivate *priv = NMS_IFUPDOWN_PLUGIN_GET_PRIVATE(plugin); nm_clear_pointer(&priv->eni_ifaces, g_hash_table_destroy); @@ -380,7 +380,7 @@ dispose(GObject *object) static void nms_ifupdown_plugin_class_init(NMSIfupdownPluginClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingsPluginClass *plugin_class = NM_SETTINGS_PLUGIN_CLASS(klass); object_class->dispose = dispose; @@ -393,7 +393,7 @@ nms_ifupdown_plugin_class_init(NMSIfupdownPluginClass *klass) /*****************************************************************************/ G_MODULE_EXPORT NMSettingsPlugin * - nm_settings_plugin_factory(void) +nm_settings_plugin_factory(void) { return g_object_new(NMS_TYPE_IFUPDOWN_PLUGIN, NULL); } diff --git a/src/core/settings/plugins/ifupdown/tests/test-ifupdown.c b/src/core/settings/plugins/ifupdown/tests/test-ifupdown.c index 0e8db733..86b3619c 100644 --- a/src/core/settings/plugins/ifupdown/tests/test-ifupdown.c +++ b/src/core/settings/plugins/ifupdown/tests/test-ifupdown.c @@ -19,8 +19,8 @@ #define _connection_from_if_block(block) \ ({ \ NMConnection *_con; \ - if_block * _block = (block); \ - GError * _local = NULL; \ + if_block *_block = (block); \ + GError *_local = NULL; \ \ g_assert(_block); \ _con = ifupdown_new_connection_from_if_block(_block, FALSE, &_local); \ @@ -45,8 +45,8 @@ typedef struct { } ExpectedKey; typedef struct { - char * type; - char * name; + char *type; + char *name; GSList *keys; } ExpectedBlock; @@ -142,13 +142,13 @@ static void compare_expected_to_ifparser(if_parser *parser, Expected *e) { if_block *n; - GSList * biter, *kiter; + GSList *biter, *kiter; g_assert_cmpint(g_slist_length(e->blocks), ==, ifparser_get_num_blocks(parser)); biter = e->blocks; c_list_for_each_entry (n, &parser->block_lst_head, block_lst) { - if_data * m; + if_data *m; ExpectedBlock *b = biter->data; g_assert(b->type && n->type); @@ -203,7 +203,7 @@ dump_blocks(if_parser *parser) static if_parser * init_ifparser_with_file(const char *file) { - if_parser * parser; + if_parser *parser; gs_free char *tmp = NULL; tmp = g_strdup_printf("%s/%s", TEST_DIR, file); @@ -216,8 +216,8 @@ static void test1_ignore_line_before_first_block(void) { nm_auto_free_expected Expected *e = NULL; - ExpectedBlock * b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test1"); + ExpectedBlock *b; + nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test1"); e = expected_new(); b = expected_block_new("auto", "eth0"); @@ -233,8 +233,8 @@ static void test2_wrapped_line(void) { nm_auto_free_expected Expected *e = NULL; - ExpectedBlock * b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test2"); + ExpectedBlock *b; + nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test2"); e = expected_new(); b = expected_block_new("auto", "lo"); @@ -247,8 +247,8 @@ static void test3_wrapped_multiline_multiarg(void) { nm_auto_free_expected Expected *e = NULL; - ExpectedBlock * b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test3"); + ExpectedBlock *b; + nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test3"); e = expected_new(); b = expected_block_new("allow-hotplug", "eth0"); @@ -265,8 +265,8 @@ static void test4_allow_auto_is_auto(void) { nm_auto_free_expected Expected *e = NULL; - ExpectedBlock * b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test4"); + ExpectedBlock *b; + nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test4"); e = expected_new(); b = expected_block_new("auto", "eth0"); @@ -279,8 +279,8 @@ static void test5_allow_auto_multiarg(void) { nm_auto_free_expected Expected *e = NULL; - ExpectedBlock * b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test5"); + ExpectedBlock *b; + nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test5"); e = expected_new(); b = expected_block_new("allow-hotplug", "eth0"); @@ -295,8 +295,8 @@ static void test6_mixed_whitespace(void) { nm_auto_free_expected Expected *e = NULL; - ExpectedBlock * b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test6"); + ExpectedBlock *b; + nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test6"); e = expected_new(); b = expected_block_new("iface", "lo"); @@ -326,8 +326,8 @@ static void test9_wrapped_lines_in_block(void) { nm_auto_free_expected Expected *e = NULL; - ExpectedBlock * b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test9"); + ExpectedBlock *b; + nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test9"); e = expected_new(); b = expected_block_new("iface", "eth0"); @@ -345,8 +345,8 @@ static void test11_complex_wrap(void) { nm_auto_free_expected Expected *e = NULL; - ExpectedBlock * b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test11"); + ExpectedBlock *b; + nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test11"); e = expected_new(); b = expected_block_new("iface", "pppoe"); @@ -361,8 +361,8 @@ static void test12_complex_wrap_split_word(void) { nm_auto_free_expected Expected *e = NULL; - ExpectedBlock * b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test12"); + ExpectedBlock *b; + nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test12"); e = expected_new(); b = expected_block_new("iface", "pppoe"); @@ -377,8 +377,8 @@ static void test13_more_mixed_whitespace(void) { nm_auto_free_expected Expected *e = NULL; - ExpectedBlock * b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test13"); + ExpectedBlock *b; + nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test13"); e = expected_new(); b = expected_block_new("iface", "dsl"); @@ -392,8 +392,8 @@ static void test14_mixed_whitespace_block_start(void) { nm_auto_free_expected Expected *e = NULL; - ExpectedBlock * b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test14"); + ExpectedBlock *b; + nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test14"); e = expected_new(); b = expected_block_new("iface", "wlan0"); @@ -413,8 +413,8 @@ static void test15_trailing_space(void) { nm_auto_free_expected Expected *e = NULL; - ExpectedBlock * b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test15"); + ExpectedBlock *b; + nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test15"); e = expected_new(); b = expected_block_new("iface", "bnep0"); @@ -427,8 +427,8 @@ test15_trailing_space(void) static void test16_missing_newline(void) { - nm_auto_free_expected Expected *e = NULL; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test16"); + nm_auto_free_expected Expected *e = NULL; + nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test16"); e = expected_new(); expected_add_block(e, expected_block_new("mapping", "eth0")); @@ -440,10 +440,10 @@ static void test17_read_static_ipv4(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingWired * s_wired; - NMIPAddress * ip4_addr; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingWired *s_wired; + NMIPAddress *ip4_addr; nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test17-wired-static-verify-ip4"); connection = _connection_first_from_parser(parser); @@ -483,10 +483,10 @@ static void test18_read_static_ipv6(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip6; - NMSettingWired * s_wired; - NMIPAddress * ip6_addr; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip6; + NMSettingWired *s_wired; + NMIPAddress *ip6_addr; nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test18-wired-static-verify-ip6"); connection = _connection_first_from_parser(parser); @@ -526,9 +526,9 @@ static void test19_read_static_ipv4_plen(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingIPConfig * s_ip4; - NMIPAddress * ip4_addr; - nm_auto_ifparser if_parser *parser = + NMSettingIPConfig *s_ip4; + NMIPAddress *ip4_addr; + nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test19-wired-static-verify-ip4-plen"); connection = _connection_first_from_parser(parser); @@ -548,8 +548,8 @@ static void test20_source_stanza(void) { nm_auto_free_expected Expected *e = NULL; - ExpectedBlock * b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test20-source-stanza"); + ExpectedBlock *b; + nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test20-source-stanza"); e = expected_new(); @@ -572,8 +572,8 @@ static void test21_source_dir_stanza(void) { nm_auto_free_expected Expected *e = NULL; - ExpectedBlock * b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test21-source-dir-stanza"); + ExpectedBlock *b; + nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test21-source-dir-stanza"); e = expected_new(); @@ -590,8 +590,8 @@ static void test22_duplicate_stanzas(void) { nm_auto_free_expected Expected *e = NULL; - ExpectedBlock * b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test22-duplicate-stanzas"); + ExpectedBlock *b; + nm_auto_ifparser if_parser *parser = init_ifparser_with_file("test22-duplicate-stanzas"); e = expected_new(); diff --git a/src/core/settings/plugins/keyfile/nms-keyfile-plugin.c b/src/core/settings/plugins/keyfile/nms-keyfile-plugin.c index aa36ee8f..efb9bfce 100644 --- a/src/core/settings/plugins/keyfile/nms-keyfile-plugin.c +++ b/src/core/settings/plugins/keyfile/nms-keyfile-plugin.c @@ -92,7 +92,7 @@ G_DEFINE_TYPE(NMSKeyfilePlugin, nms_keyfile_plugin, NM_TYPE_SETTINGS_PLUGIN) /*****************************************************************************/ static const char * -_extra_flags_to_string(char * str, +_extra_flags_to_string(char *str, gsize str_len, gboolean is_nm_generated, gboolean is_volatile, @@ -147,19 +147,19 @@ _get_plugin_dir(NMSKeyfilePluginPrivate *priv) } static gboolean -_path_detect_storage_type(const char * full_filename, - const char *const * dirname_libs, - const char * dirname_etc, - const char * dirname_run, +_path_detect_storage_type(const char *full_filename, + const char *const *dirname_libs, + const char *dirname_etc, + const char *dirname_run, NMSKeyfileStorageType *out_storage_type, - const char ** out_dirname, - const char ** out_filename, - gboolean * out_is_nmmeta_file, - gboolean * out_failed_due_to_invalid_filename) + const char **out_dirname, + const char **out_filename, + gboolean *out_is_nmmeta_file, + gboolean *out_failed_due_to_invalid_filename) { NMSKeyfileStorageType storage_type; - const char * filename = NULL; - const char * dirname = NULL; + const char *filename = NULL; + const char *dirname = NULL; guint i; gboolean is_nmmeta_file = FALSE; @@ -208,15 +208,15 @@ _path_detect_storage_type(const char * full_filename, /*****************************************************************************/ static NMConnection * -_read_from_file(const char * full_filename, - const char * plugin_dir, +_read_from_file(const char *full_filename, + const char *plugin_dir, struct stat *out_stat, - NMTernary * out_is_nm_generated, - NMTernary * out_is_volatile, - NMTernary * out_is_external, - char ** out_shadowed_storage, - NMTernary * out_shadowed_owned, - GError ** error) + NMTernary *out_is_nm_generated, + NMTernary *out_is_volatile, + NMTernary *out_is_external, + char **out_shadowed_storage, + NMTernary *out_shadowed_owned, + GError **error) { NMConnection *connection; @@ -248,7 +248,7 @@ _nm_assert_storage(gpointer plugin /* NMSKeyfilePlugin */, { #if NM_MORE_ASSERTS NMSettUtilStorageByUuidHead *sbuh; - const char * uuid; + const char *uuid; nm_assert(!plugin || NMS_IS_KEYFILE_PLUGIN(plugin)); nm_assert(NMS_IS_KEYFILE_STORAGE(storage)); @@ -256,7 +256,7 @@ _nm_assert_storage(gpointer plugin /* NMSKeyfilePlugin */, nm_assert(({ const char *f = nms_keyfile_storage_get_filename(storage); - f && f[0] == '/'; + f &&f[0] == '/'; })); uuid = nms_keyfile_storage_get_uuid(storage); @@ -294,22 +294,22 @@ _nm_assert_storage(gpointer plugin /* NMSKeyfilePlugin */, /*****************************************************************************/ static NMSKeyfileStorage * -_load_file(NMSKeyfilePlugin * self, - const char * dirname, - const char * filename, +_load_file(NMSKeyfilePlugin *self, + const char *dirname, + const char *filename, NMSKeyfileStorageType storage_type, - GError ** error) + GError **error) { - NMSKeyfilePluginPrivate *priv; + NMSKeyfilePluginPrivate *priv; gs_unref_object NMConnection *connection = NULL; NMTernary is_nm_generated_opt; NMTernary is_volatile_opt; NMTernary is_external_opt; NMTernary shadowed_owned_opt; - gs_free char * shadowed_storage = NULL; - gs_free_error GError *local = NULL; - gs_free char * full_filename = NULL; - struct stat st; + gs_free char *shadowed_storage = NULL; + gs_free_error GError *local = NULL; + gs_free char *full_filename = NULL; + struct stat st; if (_ignore_filename(storage_type, filename)) { gs_free char *nmmeta = NULL; @@ -403,14 +403,14 @@ _load_file(NMSKeyfilePlugin * self, } static NMSKeyfileStorage * -_load_file_from_path(NMSKeyfilePlugin * self, - const char * full_filename, +_load_file_from_path(NMSKeyfilePlugin *self, + const char *full_filename, NMSKeyfileStorageType storage_type, - GError ** error) + GError **error) { gs_free char *f_dirname_free = NULL; - const char * f_filename; - const char * f_dirname; + const char *f_filename; + const char *f_dirname; nm_assert(full_filename && full_filename[0] == '/'); @@ -421,13 +421,13 @@ _load_file_from_path(NMSKeyfilePlugin * self, } static void -_load_dir(NMSKeyfilePlugin * self, +_load_dir(NMSKeyfilePlugin *self, NMSKeyfileStorageType storage_type, - const char * dirname, - NMSettUtilStorages * storages) + const char *dirname, + NMSettUtilStorages *storages) { - const char * filename; - GDir * dir; + const char *filename; + GDir *dir; gs_unref_hashtable GHashTable *dupl_filenames = NULL; dir = g_dir_open(dirname, 0, NULL); @@ -465,21 +465,21 @@ _load_dir(NMSKeyfilePlugin * self, /*****************************************************************************/ static void -_storages_consolidate(NMSKeyfilePlugin * self, - NMSettUtilStorages * storages_new, +_storages_consolidate(NMSKeyfilePlugin *self, + NMSettUtilStorages *storages_new, gboolean replace_all, - GHashTable * storages_replaced, + GHashTable *storages_replaced, NMSettingsPluginConnectionLoadCallback callback, gpointer user_data) { - NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE(self); - CList lst_conn_info_deleted = C_LIST_INIT(lst_conn_info_deleted); - gs_unref_ptrarray GPtrArray *storages_modified = NULL; + NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE(self); + CList lst_conn_info_deleted = C_LIST_INIT(lst_conn_info_deleted); + gs_unref_ptrarray GPtrArray *storages_modified = NULL; CList storages_deleted; - NMSKeyfileStorage * storage_safe; - NMSKeyfileStorage * storage_new; - NMSKeyfileStorage * storage_old; - NMSKeyfileStorage * storage; + NMSKeyfileStorage *storage_safe; + NMSKeyfileStorage *storage_new; + NMSKeyfileStorage *storage_old; + NMSKeyfileStorage *storage; guint i; storages_modified = g_ptr_array_new_with_free_func(g_object_unref); @@ -576,12 +576,12 @@ _storages_consolidate(NMSKeyfilePlugin * self, } static void -reload_connections(NMSettingsPlugin * plugin, +reload_connections(NMSettingsPlugin *plugin, NMSettingsPluginConnectionLoadCallback callback, gpointer user_data) { - NMSKeyfilePlugin * self = NMS_KEYFILE_PLUGIN(plugin); - NMSKeyfilePluginPrivate * priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE(self); + NMSKeyfilePlugin *self = NMS_KEYFILE_PLUGIN(plugin); + NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE(self); nm_auto_clear_sett_util_storages NMSettUtilStorages storages_new = NM_SETT_UTIL_STORAGES_INIT(storages_new, nms_keyfile_storage_destroy); int i; @@ -596,20 +596,20 @@ reload_connections(NMSettingsPlugin * plugin, } static void -load_connections(NMSettingsPlugin * plugin, - NMSettingsPluginConnectionLoadEntry * entries, +load_connections(NMSettingsPlugin *plugin, + NMSettingsPluginConnectionLoadEntry *entries, gsize n_entries, NMSettingsPluginConnectionLoadCallback callback, gpointer user_data) { - NMSKeyfilePlugin * self = NMS_KEYFILE_PLUGIN(plugin); - NMSKeyfilePluginPrivate * priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE(self); + NMSKeyfilePlugin *self = NMS_KEYFILE_PLUGIN(plugin); + NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE(self); nm_auto_clear_sett_util_storages NMSettUtilStorages storages_new = NM_SETT_UTIL_STORAGES_INIT(storages_new, nms_keyfile_storage_destroy); gs_unref_hashtable GHashTable *dupl_filenames = NULL; gs_unref_hashtable GHashTable *storages_replaced = NULL; gs_unref_hashtable GHashTable *loaded_uuids = NULL; - const char * loaded_uuid; + const char *loaded_uuid; GHashTableIter h_iter; gsize i; @@ -625,15 +625,15 @@ load_connections(NMSettingsPlugin * plugin, for (i = 0; i < n_entries; i++) { NMSettingsPluginConnectionLoadEntry *const entry = &entries[i]; NMSKeyfileStorageType storage_type; - gs_free_error GError * local = NULL; - const char * f_filename; - const char * f_dirname; - const char * full_filename; - gs_free char * full_filename_keep = NULL; - gboolean is_nmmeta_file; - NMSettingsPluginConnectionLoadEntry *dupl_content_entry; - gboolean failed_due_to_invalid_filename; - gs_unref_object NMSKeyfileStorage *storage = NULL; + gs_free_error GError *local = NULL; + const char *f_filename; + const char *f_dirname; + const char *full_filename; + gs_free char *full_filename_keep = NULL; + gboolean is_nmmeta_file; + NMSettingsPluginConnectionLoadEntry *dupl_content_entry; + gboolean failed_due_to_invalid_filename; + gs_unref_object NMSKeyfileStorage *storage = NULL; if (entry->handled) continue; @@ -700,7 +700,7 @@ load_connections(NMSettingsPlugin * plugin, /* now we visit all UUIDs that are about to change... */ g_hash_table_iter_init(&h_iter, loaded_uuids); while (g_hash_table_iter_next(&h_iter, (gpointer *) &loaded_uuid, NULL)) { - NMSKeyfileStorage * storage; + NMSKeyfileStorage *storage; NMSettUtilStorageByUuidHead *sbuh; sbuh = nm_sett_util_storages_lookup_by_uuid(&priv->storages, loaded_uuid); @@ -710,9 +710,9 @@ load_connections(NMSettingsPlugin * plugin, c_list_for_each_entry (storage, &sbuh->_storage_by_uuid_lst_head, parent._storage_by_uuid_lst) { - const char * full_filename = nms_keyfile_storage_get_filename(storage); + const char *full_filename = nms_keyfile_storage_get_filename(storage); gs_unref_object NMSKeyfileStorage *storage_new = NULL; - gs_free_error GError *local = NULL; + gs_free_error GError *local = NULL; if (g_hash_table_contains(dupl_filenames, full_filename)) { /* already re-loaded. */ @@ -744,25 +744,25 @@ load_connections(NMSettingsPlugin * plugin, } gboolean -nms_keyfile_plugin_add_connection(NMSKeyfilePlugin * self, - NMConnection * connection, +nms_keyfile_plugin_add_connection(NMSKeyfilePlugin *self, + NMConnection *connection, gboolean in_memory, gboolean is_nm_generated, gboolean is_volatile, gboolean is_external, - const char * shadowed_storage, + const char *shadowed_storage, gboolean shadowed_owned, NMSettingsStorage **out_storage, - NMConnection ** out_connection, - GError ** error) + NMConnection **out_connection, + GError **error) { - NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE(self); - gs_unref_object NMConnection *reread = NULL; - gs_free char * full_filename = NULL; - NMSKeyfileStorageType storage_type; + NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE(self); + gs_unref_object NMConnection *reread = NULL; + gs_free char *full_filename = NULL; + NMSKeyfileStorageType storage_type; gs_unref_object NMSKeyfileStorage *storage = NULL; - GError * local = NULL; - const char * uuid; + GError *local = NULL; + const char *uuid; gboolean reread_same; struct timespec mtime; char strbuf[100]; @@ -849,11 +849,11 @@ nms_keyfile_plugin_add_connection(NMSKeyfilePlugin * self, } static gboolean -add_connection(NMSettingsPlugin * plugin, - NMConnection * connection, +add_connection(NMSettingsPlugin *plugin, + NMConnection *connection, NMSettingsStorage **out_storage, - NMConnection ** out_connection, - GError ** error) + NMConnection **out_connection, + GError **error) { return nms_keyfile_plugin_add_connection(NMS_KEYFILE_PLUGIN(plugin), connection, @@ -869,30 +869,30 @@ add_connection(NMSettingsPlugin * plugin, } gboolean -nms_keyfile_plugin_update_connection(NMSKeyfilePlugin * self, - NMSettingsStorage * storage_x, - NMConnection * connection, +nms_keyfile_plugin_update_connection(NMSKeyfilePlugin *self, + NMSettingsStorage *storage_x, + NMConnection *connection, gboolean is_nm_generated, gboolean is_volatile, gboolean is_external, - const char * shadowed_storage, + const char *shadowed_storage, gboolean shadowed_owned, gboolean force_rename, NMSettingsStorage **out_storage, - NMConnection ** out_connection, - GError ** error) + NMConnection **out_connection, + GError **error) { - NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE(self); - NMSKeyfileStorage * storage = NMS_KEYFILE_STORAGE(storage_x); + NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE(self); + NMSKeyfileStorage *storage = NMS_KEYFILE_STORAGE(storage_x); gs_unref_object NMConnection *connection_clone = NULL; gs_unref_object NMConnection *reread = NULL; - gs_free char * full_filename = NULL; - gs_free_error GError *local = NULL; - struct timespec mtime; - const char * previous_filename; - gboolean reread_same; - const char * uuid; - char strbuf[100]; + gs_free char *full_filename = NULL; + gs_free_error GError *local = NULL; + struct timespec mtime; + const char *previous_filename; + gboolean reread_same; + const char *uuid; + char strbuf[100]; _nm_assert_storage(self, storage, TRUE); nm_assert(NM_IS_CONNECTION(connection)); @@ -971,12 +971,12 @@ nms_keyfile_plugin_update_connection(NMSKeyfilePlugin * self, } static gboolean -update_connection(NMSettingsPlugin * plugin, - NMSettingsStorage * storage, - NMConnection * connection, +update_connection(NMSettingsPlugin *plugin, + NMSettingsStorage *storage, + NMConnection *connection, NMSettingsStorage **out_storage, - NMConnection ** out_connection, - GError ** error) + NMConnection **out_connection, + GError **error) { return nms_keyfile_plugin_update_connection(NMS_KEYFILE_PLUGIN(plugin), storage, @@ -995,13 +995,13 @@ update_connection(NMSettingsPlugin * plugin, static gboolean delete_connection(NMSettingsPlugin *plugin, NMSettingsStorage *storage_x, GError **error) { - NMSKeyfilePlugin * self = NMS_KEYFILE_PLUGIN(plugin); - NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE(self); + NMSKeyfilePlugin *self = NMS_KEYFILE_PLUGIN(plugin); + NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE(self); gs_unref_object NMSKeyfileStorage *storage = g_object_ref(NMS_KEYFILE_STORAGE(storage_x)); - const char * remove_from_disk_errmsg = NULL; - const char * operation_message; - const char * previous_filename; - const char * uuid; + const char *remove_from_disk_errmsg = NULL; + const char *operation_message; + const char *previous_filename; + const char *uuid; gboolean success = TRUE; _nm_assert_storage(self, storage, TRUE); @@ -1087,24 +1087,24 @@ delete_connection(NMSettingsPlugin *plugin, NMSettingsStorage *storage_x, GError * Returns: %TRUE on success. */ gboolean -nms_keyfile_plugin_set_nmmeta_tombstone(NMSKeyfilePlugin * self, +nms_keyfile_plugin_set_nmmeta_tombstone(NMSKeyfilePlugin *self, gboolean simulate, - const char * uuid, + const char *uuid, gboolean in_memory, gboolean set, - const char * shadowed_storage, + const char *shadowed_storage, NMSettingsStorage **out_storage, - gboolean * out_hard_failure) + gboolean *out_hard_failure) { - NMSKeyfilePluginPrivate *priv; - gboolean hard_failure = FALSE; - NMSKeyfileStorage * storage; + NMSKeyfilePluginPrivate *priv; + gboolean hard_failure = FALSE; + NMSKeyfileStorage *storage; gs_unref_object NMSKeyfileStorage *storage_result = NULL; gboolean nmmeta_errno; - gs_free char * nmmeta_filename = NULL; + gs_free char *nmmeta_filename = NULL; NMSKeyfileStorageType storage_type; - const char * loaded_path; - const char * dirname; + const char *loaded_path; + const char *dirname; nm_assert(NMS_IS_KEYFILE_PLUGIN(self)); nm_assert(nm_uuid_is_normalized(uuid)); @@ -1197,11 +1197,11 @@ out: /*****************************************************************************/ static void -config_changed_cb(NMConfig * config, - NMConfigData * config_data, +config_changed_cb(NMConfig *config, + NMConfigData *config_data, NMConfigChangeFlags changes, - NMConfigData * old_data, - NMSKeyfilePlugin * self) + NMConfigData *old_data, + NMSKeyfilePlugin *self) { gs_free char *old_value = NULL; gs_free char *new_value = NULL; @@ -1223,7 +1223,7 @@ static GSList * get_unmanaged_specs(NMSettingsPlugin *config) { NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE(config); - gs_free char * value = NULL; + gs_free char *value = NULL; value = nm_config_data_get_value(nm_config_get_data(priv->config), NM_CONFIG_KEYFILE_GROUP_KEYFILE, @@ -1280,7 +1280,7 @@ nms_keyfile_plugin_init(NMSKeyfilePlugin *plugin) static void constructed(GObject *object) { - NMSKeyfilePlugin * self = NMS_KEYFILE_PLUGIN(object); + NMSKeyfilePlugin *self = NMS_KEYFILE_PLUGIN(object); NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE(self); G_OBJECT_CLASS(nms_keyfile_plugin_parent_class)->constructed(object); @@ -1312,7 +1312,7 @@ nms_keyfile_plugin_new(void) static void dispose(GObject *object) { - NMSKeyfilePlugin * self = NMS_KEYFILE_PLUGIN(object); + NMSKeyfilePlugin *self = NMS_KEYFILE_PLUGIN(object); NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE(self); if (priv->config) @@ -1332,7 +1332,7 @@ dispose(GObject *object) static void nms_keyfile_plugin_class_init(NMSKeyfilePluginClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingsPluginClass *plugin_class = NM_SETTINGS_PLUGIN_CLASS(klass); object_class->constructed = constructed; diff --git a/src/core/settings/plugins/keyfile/nms-keyfile-plugin.h b/src/core/settings/plugins/keyfile/nms-keyfile-plugin.h index 5d9f2da3..19e4122d 100644 --- a/src/core/settings/plugins/keyfile/nms-keyfile-plugin.h +++ b/src/core/settings/plugins/keyfile/nms-keyfile-plugin.h @@ -30,38 +30,38 @@ GType nms_keyfile_plugin_get_type(void); NMSKeyfilePlugin *nms_keyfile_plugin_new(void); -gboolean nms_keyfile_plugin_add_connection(NMSKeyfilePlugin * self, - NMConnection * connection, +gboolean nms_keyfile_plugin_add_connection(NMSKeyfilePlugin *self, + NMConnection *connection, gboolean in_memory, gboolean is_nm_generated, gboolean is_volatile, gboolean is_external, - const char * shadowed_storage, + const char *shadowed_storage, gboolean shadowed_owned, NMSettingsStorage **out_storage, - NMConnection ** out_connection, - GError ** error); + NMConnection **out_connection, + GError **error); -gboolean nms_keyfile_plugin_update_connection(NMSKeyfilePlugin * self, - NMSettingsStorage * storage, - NMConnection * connection, +gboolean nms_keyfile_plugin_update_connection(NMSKeyfilePlugin *self, + NMSettingsStorage *storage, + NMConnection *connection, gboolean is_nm_generated, gboolean is_volatile, gboolean is_external, - const char * shadowed_storage, + const char *shadowed_storage, gboolean shadowed_owned, gboolean force_rename, NMSettingsStorage **out_storage, - NMConnection ** out_connection, - GError ** error); + NMConnection **out_connection, + GError **error); -gboolean nms_keyfile_plugin_set_nmmeta_tombstone(NMSKeyfilePlugin * self, +gboolean nms_keyfile_plugin_set_nmmeta_tombstone(NMSKeyfilePlugin *self, gboolean simulate, - const char * uuid, + const char *uuid, gboolean in_memory, gboolean set, - const char * shadowed_storage, + const char *shadowed_storage, NMSettingsStorage **out_storage, - gboolean * out_hard_failure); + gboolean *out_hard_failure); #endif /* __NMS_KEYFILE_PLUGIN_H__ */ diff --git a/src/core/settings/plugins/keyfile/nms-keyfile-reader.c b/src/core/settings/plugins/keyfile/nms-keyfile-reader.c index 8b9d982f..81e3d633 100644 --- a/src/core/settings/plugins/keyfile/nms-keyfile-reader.c +++ b/src/core/settings/plugins/keyfile/nms-keyfile-reader.c @@ -23,10 +23,10 @@ _fmt_warn(const NMKeyfileHandlerData *handler_data, char **out_message) const char *message = _nm_keyfile_handler_data_warn_get_message(handler_data); if (group) { - NMSetting * setting = handler_data->cur_setting; + NMSetting *setting = handler_data->cur_setting; const char *property_name = handler_data->cur_property; const char *setting_name = setting ? nm_setting_get_name(setting) : NULL; - char * res; + char *res; if (setting_name) { if (property_name && !strcmp(group, setting_name)) @@ -51,18 +51,18 @@ typedef struct { } ReadInfo; static gboolean -_handler_read(GKeyFile * keyfile, - NMConnection * connection, +_handler_read(GKeyFile *keyfile, + NMConnection *connection, NMKeyfileHandlerType handler_type, NMKeyfileHandlerData *handler_data, - void * user_data) + void *user_data) { const ReadInfo *read_info = user_data; if (handler_type == NM_KEYFILE_HANDLER_TYPE_WARN) { const NMKeyfileHandlerDataWarn *warn_data = &handler_data->warn; NMLogLevel level; - char * message_free = NULL; + char *message_free = NULL; if (!read_info->verbose) return TRUE; @@ -90,21 +90,21 @@ _handler_read(GKeyFile * keyfile, } NMConnection * -nms_keyfile_reader_from_keyfile(GKeyFile * key_file, +nms_keyfile_reader_from_keyfile(GKeyFile *key_file, const char *filename, const char *base_dir, const char *profile_dir, gboolean verbose, - GError ** error) + GError **error) { NMConnection *connection; ReadInfo read_info = { - .verbose = verbose, + .verbose = verbose, }; gs_free char *base_dir_free = NULL; gs_free char *profile_filename_free = NULL; gs_free char *filename_id = NULL; - const char * profile_filename = NULL; + const char *profile_filename = NULL; nm_assert(filename && filename[0]); nm_assert(!base_dir || base_dir[0] == '/'); @@ -154,19 +154,19 @@ nms_keyfile_reader_from_keyfile(GKeyFile * key_file, } NMConnection * -nms_keyfile_reader_from_file(const char * full_filename, - const char * profile_dir, +nms_keyfile_reader_from_file(const char *full_filename, + const char *profile_dir, struct stat *out_stat, - NMTernary * out_is_nm_generated, - NMTernary * out_is_volatile, - NMTernary * out_is_external, - char ** out_shadowed_storage, - NMTernary * out_shadowed_owned, - GError ** error) + NMTernary *out_is_nm_generated, + NMTernary *out_is_volatile, + NMTernary *out_is_external, + char **out_shadowed_storage, + NMTernary *out_shadowed_owned, + GError **error) { nm_auto_unref_keyfile GKeyFile *key_file = NULL; - NMConnection * connection = NULL; - GError * verify_error = NULL; + NMConnection *connection = NULL; + GError *verify_error = NULL; nm_assert(full_filename && full_filename[0] == '/'); nm_assert(!profile_dir || profile_dir[0] == '/'); diff --git a/src/core/settings/plugins/keyfile/nms-keyfile-reader.h b/src/core/settings/plugins/keyfile/nms-keyfile-reader.h index 247457d8..3722fb8a 100644 --- a/src/core/settings/plugins/keyfile/nms-keyfile-reader.h +++ b/src/core/settings/plugins/keyfile/nms-keyfile-reader.h @@ -9,23 +9,23 @@ #include "nm-connection.h" -NMConnection *nms_keyfile_reader_from_keyfile(GKeyFile * key_file, +NMConnection *nms_keyfile_reader_from_keyfile(GKeyFile *key_file, const char *filename, const char *base_dir, const char *profile_dir, gboolean verbose, - GError ** error); + GError **error); struct stat; -NMConnection *nms_keyfile_reader_from_file(const char * full_filename, - const char * profile_dir, +NMConnection *nms_keyfile_reader_from_file(const char *full_filename, + const char *profile_dir, struct stat *out_stat, - NMTernary * out_is_nm_generated, - NMTernary * out_is_volatile, - NMTernary * out_is_external, - char ** out_shadowed_storage, - NMTernary * out_shadowed_owned, - GError ** error); + NMTernary *out_is_nm_generated, + NMTernary *out_is_volatile, + NMTernary *out_is_external, + char **out_shadowed_storage, + NMTernary *out_shadowed_owned, + GError **error); #endif /* __NMS_KEYFILE_READER_H__ */ diff --git a/src/core/settings/plugins/keyfile/nms-keyfile-storage.c b/src/core/settings/plugins/keyfile/nms-keyfile-storage.c index ec0634c4..ddbb3c85 100644 --- a/src/core/settings/plugins/keyfile/nms-keyfile-storage.c +++ b/src/core/settings/plugins/keyfile/nms-keyfile-storage.c @@ -41,7 +41,7 @@ nms_keyfile_storage_copy_content(NMSKeyfileStorage *dst, const NMSKeyfileStorage dst->u.meta_data.shadowed_storage = g_strdup(dst->u.meta_data.shadowed_storage); } else { gs_unref_object NMConnection *connection_to_free = NULL; - gs_free char * shadowed_storage_to_free = NULL; + gs_free char *shadowed_storage_to_free = NULL; connection_to_free = g_steal_pointer(&dst->u.conn_data.connection); shadowed_storage_to_free = g_steal_pointer(&dst->u.conn_data.shadowed_storage); @@ -99,9 +99,9 @@ nms_keyfile_storage_init(NMSKeyfileStorage *self) {} static NMSKeyfileStorage * -_storage_new(NMSKeyfilePlugin * plugin, - const char * uuid, - const char * filename, +_storage_new(NMSKeyfilePlugin *plugin, + const char *uuid, + const char *filename, gboolean is_meta_data, NMSKeyfileStorageType storage_type) @@ -128,11 +128,11 @@ _storage_new(NMSKeyfilePlugin * plugin, } NMSKeyfileStorage * -nms_keyfile_storage_new_tombstone(NMSKeyfilePlugin * plugin, - const char * uuid, - const char * filename, +nms_keyfile_storage_new_tombstone(NMSKeyfilePlugin *plugin, + const char *uuid, + const char *filename, NMSKeyfileStorageType storage_type, - const char * shadowed_storage) + const char *shadowed_storage) { NMSKeyfileStorage *self; @@ -149,14 +149,14 @@ nms_keyfile_storage_new_tombstone(NMSKeyfilePlugin * plugin, } NMSKeyfileStorage * -nms_keyfile_storage_new_connection(NMSKeyfilePlugin * plugin, - NMConnection * connection_take /* pass reference */, - const char * filename, +nms_keyfile_storage_new_connection(NMSKeyfilePlugin *plugin, + NMConnection *connection_take /* pass reference */, + const char *filename, NMSKeyfileStorageType storage_type, NMTernary is_nm_generated_opt, NMTernary is_volatile_opt, NMTernary is_external_opt, - const char * shadowed_storage, + const char *shadowed_storage, NMTernary shadowed_owned_opt, const struct timespec *stat_mtime) { @@ -228,7 +228,7 @@ nms_keyfile_storage_destroy(NMSKeyfileStorage *self) static void nms_keyfile_storage_class_init(NMSKeyfileStorageClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingsStorageClass *storage_class = NM_SETTINGS_STORAGE_CLASS(klass); object_class->dispose = dispose; @@ -241,7 +241,7 @@ nms_keyfile_storage_class_init(NMSKeyfileStorageClass *klass) #include "settings/nm-settings-connection.h" void -nm_settings_storage_load_sett_flags(NMSettingsStorage * self, +nm_settings_storage_load_sett_flags(NMSettingsStorage *self, NMSettingsConnectionIntFlags *sett_flags, NMSettingsConnectionIntFlags *sett_mask) { diff --git a/src/core/settings/plugins/keyfile/nms-keyfile-storage.h b/src/core/settings/plugins/keyfile/nms-keyfile-storage.h index 008070df..8343cb2b 100644 --- a/src/core/settings/plugins/keyfile/nms-keyfile-storage.h +++ b/src/core/settings/plugins/keyfile/nms-keyfile-storage.h @@ -106,22 +106,22 @@ GType nms_keyfile_storage_get_type(void); struct _NMSKeyfilePlugin; NMSKeyfileStorage *nms_keyfile_storage_new_tombstone(struct _NMSKeyfilePlugin *self, - const char * uuid, - const char * filename, + const char *uuid, + const char *filename, NMSKeyfileStorageType storage_type, - const char * shadowed_storage); + const char *shadowed_storage); NMSKeyfileStorage * nms_keyfile_storage_new_connection(struct _NMSKeyfilePlugin *self, - NMConnection * connection_take /* pass reference */, - const char * filename, + NMConnection *connection_take /* pass reference */, + const char *filename, NMSKeyfileStorageType storage_type, NMTernary is_nm_generated_opt, NMTernary is_volatile_opt, NMTernary is_external_opt, - const char * shadowed_storage, + const char *shadowed_storage, NMTernary shadowed_owned_opt, - const struct timespec * stat_mtime); + const struct timespec *stat_mtime); void nms_keyfile_storage_destroy(NMSKeyfileStorage *storage); @@ -204,7 +204,7 @@ nm_settings_storage_is_meta_data_alive(const NMSettingsStorage *storage) static inline const char * nm_settings_storage_get_shadowed_storage(const NMSettingsStorage *storage, - gboolean * out_shadowed_owned) + gboolean *out_shadowed_owned) { if (NMS_IS_KEYFILE_STORAGE(storage)) { const NMSKeyfileStorage *self = (const NMSKeyfileStorage *) storage; @@ -248,7 +248,7 @@ nm_settings_storage_get_filename_for_shadowed_storage(const NMSettingsStorage *s enum _NMSettingsConnectionIntFlags; -void nm_settings_storage_load_sett_flags(NMSettingsStorage * self, +void nm_settings_storage_load_sett_flags(NMSettingsStorage *self, enum _NMSettingsConnectionIntFlags *sett_flags, enum _NMSettingsConnectionIntFlags *sett_mask); diff --git a/src/core/settings/plugins/keyfile/nms-keyfile-utils.c b/src/core/settings/plugins/keyfile/nms-keyfile-utils.c index e2c68bbe..7c0e329e 100644 --- a/src/core/settings/plugins/keyfile/nms-keyfile-utils.c +++ b/src/core/settings/plugins/keyfile/nms-keyfile-utils.c @@ -95,21 +95,21 @@ nms_keyfile_nmmeta_filename(const char *dirname, const char *uuid, gboolean temp } gboolean -nms_keyfile_nmmeta_read(const char * dirname, - const char * filename, - char ** out_full_filename, - char ** out_uuid, - char ** out_loaded_path, - char ** out_shadowed_storage, +nms_keyfile_nmmeta_read(const char *dirname, + const char *filename, + char **out_full_filename, + char **out_uuid, + char **out_loaded_path, + char **out_shadowed_storage, struct stat *out_st) { - const char * uuid; + const char *uuid; guint uuid_len; gs_free char *full_filename = NULL; gs_free char *loaded_path = NULL; gs_free char *shadowed_storage = NULL; struct stat st_stack; - struct stat * st = out_st ?: &st_stack; + struct stat *st = out_st ?: &st_stack; nm_assert(dirname && dirname[0] == '/'); nm_assert(filename && filename[0] && !strchr(filename, '/')); @@ -128,7 +128,7 @@ nms_keyfile_nmmeta_read(const char * dirname, if (S_ISREG(st->st_mode)) { nm_auto_unref_keyfile GKeyFile *kf = NULL; - gs_free char * v_uuid = NULL; + gs_free char *v_uuid = NULL; kf = g_key_file_new(); @@ -176,11 +176,11 @@ nms_keyfile_nmmeta_read(const char * dirname, gboolean nms_keyfile_nmmeta_read_from_file(const char *full_filename, - char ** out_dirname, - char ** out_filename, - char ** out_uuid, - char ** out_loaded_path, - char ** out_shadowed_storage) + char **out_dirname, + char **out_filename, + char **out_uuid, + char **out_loaded_path, + char **out_shadowed_storage) { gs_free char *dirname = NULL; gs_free char *filename = NULL; @@ -210,7 +210,7 @@ nms_keyfile_nmmeta_write(const char *dirname, const char *loaded_path, gboolean loaded_path_allow_relative, const char *shadowed_storage, - char ** out_full_filename) + char **out_full_filename) { gs_free char *full_filename_tmp = NULL; gs_free char *full_filename = NULL; @@ -255,7 +255,7 @@ nms_keyfile_nmmeta_write(const char *dirname, if (shadowed_storage) { nm_auto_unref_keyfile GKeyFile *kf = NULL; - gs_free char * contents = NULL; + gs_free char *contents = NULL; gsize length; kf = g_key_file_new(); @@ -313,7 +313,7 @@ nms_keyfile_nmmeta_write(const char *dirname, gboolean nms_keyfile_utils_check_file_permissions_stat(NMSKeyfileFiletype filetype, const struct stat *st, - GError ** error) + GError **error) { g_return_val_if_fail(st, FALSE); @@ -337,7 +337,7 @@ nms_keyfile_utils_check_file_permissions_stat(NMSKeyfileFiletype filetype, g_return_val_if_reached(FALSE); if (!NM_FLAGS_HAS(nm_utils_get_testing(), NM_UTILS_TEST_NO_KEYFILE_OWNER_CHECK)) { - if (st->st_uid != 0) { + if (!NM_IN_SET(st->st_uid, 0, nm_utils_get_nm_uid())) { g_set_error(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, @@ -361,9 +361,9 @@ nms_keyfile_utils_check_file_permissions_stat(NMSKeyfileFiletype filetype, gboolean nms_keyfile_utils_check_file_permissions(NMSKeyfileFiletype filetype, - const char * filename, - struct stat * out_st, - GError ** error) + const char *filename, + struct stat *out_st, + GError **error) { struct stat st; int errsv; diff --git a/src/core/settings/plugins/keyfile/nms-keyfile-utils.h b/src/core/settings/plugins/keyfile/nms-keyfile-utils.h index 419a17ed..0fd83bdf 100644 --- a/src/core/settings/plugins/keyfile/nms-keyfile-utils.h +++ b/src/core/settings/plugins/keyfile/nms-keyfile-utils.h @@ -34,38 +34,38 @@ const char *nms_keyfile_nmmeta_check_filename(const char *filename, guint *out_u char *nms_keyfile_nmmeta_filename(const char *dirname, const char *uuid, gboolean temporary); -gboolean nms_keyfile_nmmeta_read(const char * dirname, - const char * filename, - char ** out_full_filename, - char ** out_uuid, - char ** out_loaded_path, - char ** out_shadowed_storage, +gboolean nms_keyfile_nmmeta_read(const char *dirname, + const char *filename, + char **out_full_filename, + char **out_uuid, + char **out_loaded_path, + char **out_shadowed_storage, struct stat *out_st); gboolean nms_keyfile_nmmeta_read_from_file(const char *full_filename, - char ** out_dirname, - char ** out_filename, - char ** out_uuid, - char ** out_loaded_path, - char ** out_shadowed_storage); + char **out_dirname, + char **out_filename, + char **out_uuid, + char **out_loaded_path, + char **out_shadowed_storage); int nms_keyfile_nmmeta_write(const char *dirname, const char *uuid, const char *loaded_path, gboolean loaded_path_allow_relative, const char *shadowed_storage, - char ** out_full_filename); + char **out_full_filename); /*****************************************************************************/ struct stat; gboolean nms_keyfile_utils_check_file_permissions_stat(NMSKeyfileFiletype filetype, const struct stat *st, - GError ** error); + GError **error); gboolean nms_keyfile_utils_check_file_permissions(NMSKeyfileFiletype filetype, - const char * filename, - struct stat * out_st, - GError ** error); + const char *filename, + struct stat *out_st, + GError **error); #endif /* __NMS_KEYFILE_UTILS_H__ */ diff --git a/src/core/settings/plugins/keyfile/nms-keyfile-writer.c b/src/core/settings/plugins/keyfile/nms-keyfile-writer.c index 70afdc23..ad6f277c 100644 --- a/src/core/settings/plugins/keyfile/nms-keyfile-writer.c +++ b/src/core/settings/plugins/keyfile/nms-keyfile-writer.c @@ -26,21 +26,21 @@ typedef struct { } WriteInfo; static void -cert_writer(NMConnection * connection, - GKeyFile * file, - NMSetting8021x * setting, +cert_writer(NMConnection *connection, + GKeyFile *file, + NMSetting8021x *setting, const NMSetting8021xSchemeVtable *vtable, - WriteInfo * info, - GError ** error) + WriteInfo *info, + GError **error) { - const char * setting_name = nm_setting_get_name(NM_SETTING(setting)); + const char *setting_name = nm_setting_get_name(NM_SETTING(setting)); NMSetting8021xCKScheme scheme; NMSetting8021xCKFormat format; - const char * path = NULL, *ext = "pem"; + const char *path = NULL, *ext = "pem"; scheme = vtable->scheme_func(setting); if (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH) { - char * tmp = NULL; + char *tmp = NULL; const char *accepted_path = NULL; path = vtable->path_func(setting); @@ -92,12 +92,12 @@ cert_writer(NMConnection * connection, vtable->setting_key, vtable->uri_func(setting)); } else if (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB) { - GBytes * blob; + GBytes *blob; const guint8 *blob_data; gsize blob_len; gboolean success; - GError * local = NULL; - char * new_path; + GError *local = NULL; + char *new_path; blob = vtable->blob_func(setting); g_assert(blob); @@ -163,11 +163,11 @@ cert_writer(NMConnection * connection, } static gboolean -_handler_write(NMConnection * connection, - GKeyFile * keyfile, +_handler_write(NMConnection *connection, + GKeyFile *keyfile, NMKeyfileHandlerType type, NMKeyfileHandlerData *type_data, - void * user_data) + void *user_data) { if (type == NM_KEYFILE_HANDLER_TYPE_WRITE_CERT) { cert_writer(connection, @@ -182,39 +182,39 @@ _handler_write(NMConnection * connection, } static gboolean -_internal_write_connection(NMConnection * connection, +_internal_write_connection(NMConnection *connection, gboolean is_nm_generated, gboolean is_volatile, gboolean is_external, - const char * shadowed_storage, + const char *shadowed_storage, gboolean shadowed_owned, - const char * keyfile_dir, - const char * profile_dir, + const char *keyfile_dir, + const char *profile_dir, gboolean with_extension, uid_t owner_uid, pid_t owner_grp, - const char * existing_path, + const char *existing_path, gboolean existing_path_read_only, gboolean force_rename, NMSKeyfileWriterAllowFilenameCb allow_filename_cb, gpointer allow_filename_user_data, - char ** out_path, - NMConnection ** out_reread, - gboolean * out_reread_same, - GError ** error) + char **out_path, + NMConnection **out_reread, + gboolean *out_reread_same, + GError **error) { nm_auto_unref_keyfile GKeyFile *kf_file = NULL; - gs_free char * kf_content_buf = NULL; + gs_free char *kf_content_buf = NULL; gsize kf_content_len; - gs_free char * path = NULL; - const char * id; - WriteInfo info = {0}; - gs_free_error GError *local_err = NULL; - int errsv; - gboolean rename; - int i_path; - gs_unref_object NMConnection *reread = NULL; - gboolean reread_same = FALSE; + gs_free char *path = NULL; + const char *id; + WriteInfo info = {0}; + gs_free_error GError *local_err = NULL; + int errsv; + gboolean rename; + int i_path; + gs_unref_object NMConnection *reread = NULL; + gboolean reread_same = FALSE; g_return_val_if_fail(!out_path || !*out_path, FALSE); g_return_val_if_fail(keyfile_dir && keyfile_dir[0] == '/', FALSE); @@ -417,23 +417,23 @@ _internal_write_connection(NMConnection * connection, } gboolean -nms_keyfile_writer_connection(NMConnection * connection, +nms_keyfile_writer_connection(NMConnection *connection, gboolean is_nm_generated, gboolean is_volatile, gboolean is_external, - const char * shadowed_storage, + const char *shadowed_storage, gboolean shadowed_owned, - const char * keyfile_dir, - const char * profile_dir, - const char * existing_path, + const char *keyfile_dir, + const char *profile_dir, + const char *existing_path, gboolean existing_path_read_only, gboolean force_rename, NMSKeyfileWriterAllowFilenameCb allow_filename_cb, gpointer allow_filename_user_data, - char ** out_path, - NMConnection ** out_reread, - gboolean * out_reread_same, - GError ** error) + char **out_path, + NMConnection **out_reread, + gboolean *out_reread_same, + GError **error) { return _internal_write_connection(connection, is_nm_generated, @@ -444,8 +444,8 @@ nms_keyfile_writer_connection(NMConnection * connection, keyfile_dir, profile_dir, TRUE, - 0, - 0, + nm_utils_get_nm_uid(), + nm_utils_get_nm_gid(), existing_path, existing_path_read_only, force_rename, @@ -458,14 +458,14 @@ nms_keyfile_writer_connection(NMConnection * connection, } gboolean -nms_keyfile_writer_test_connection(NMConnection * connection, - const char * keyfile_dir, +nms_keyfile_writer_test_connection(NMConnection *connection, + const char *keyfile_dir, uid_t owner_uid, pid_t owner_grp, - char ** out_path, + char **out_path, NMConnection **out_reread, - gboolean * out_reread_same, - GError ** error) + gboolean *out_reread_same, + GError **error) { return _internal_write_connection(connection, FALSE, diff --git a/src/core/settings/plugins/keyfile/nms-keyfile-writer.h b/src/core/settings/plugins/keyfile/nms-keyfile-writer.h index dffd3b04..62aaa19d 100644 --- a/src/core/settings/plugins/keyfile/nms-keyfile-writer.h +++ b/src/core/settings/plugins/keyfile/nms-keyfile-writer.h @@ -12,31 +12,31 @@ typedef gboolean (*NMSKeyfileWriterAllowFilenameCb)(const char *check_filename, gpointer allow_filename_user_data); -gboolean nms_keyfile_writer_connection(NMConnection * connection, +gboolean nms_keyfile_writer_connection(NMConnection *connection, gboolean is_nm_generated, gboolean is_volatile, gboolean is_external, - const char * shadowed_storage, + const char *shadowed_storage, gboolean shadowed_owned, - const char * keyfile_dir, - const char * profile_dir, - const char * existing_path, + const char *keyfile_dir, + const char *profile_dir, + const char *existing_path, gboolean existing_path_read_only, gboolean force_rename, NMSKeyfileWriterAllowFilenameCb allow_filename_cb, gpointer allow_filename_user_data, - char ** out_path, - NMConnection ** out_reread, - gboolean * out_reread_same, - GError ** error); + char **out_path, + NMConnection **out_reread, + gboolean *out_reread_same, + GError **error); -gboolean nms_keyfile_writer_test_connection(NMConnection * connection, - const char * keyfile_dir, +gboolean nms_keyfile_writer_test_connection(NMConnection *connection, + const char *keyfile_dir, uid_t owner_uid, pid_t owner_grp, - char ** out_path, + char **out_path, NMConnection **out_reread, - gboolean * out_reread_same, - GError ** error); + gboolean *out_reread_same, + GError **error); #endif /* __NMS_KEYFILE_WRITER_H__ */ diff --git a/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c b/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c index 4ceed49d..b4c30df7 100644 --- a/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c +++ b/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c @@ -42,9 +42,9 @@ check_ip_address(NMSettingIPConfig *config, int idx, const char *address, int pl static void check_ip_route(NMSettingIPConfig *config, int idx, - const char * destination, + const char *destination, int plen, - const char * next_hop, + const char *next_hop, gint64 metric) { NMIPRoute *route = nm_setting_ip_config_get_route(config, idx); @@ -59,7 +59,7 @@ check_ip_route(NMSettingIPConfig *config, #define keyfile_read_connection_from_file(full_filename) \ ({ \ gs_free_error GError *_error = NULL; \ - NMConnection * _connection; \ + NMConnection *_connection; \ \ g_assert(full_filename &&full_filename[0] == '/'); \ \ @@ -84,7 +84,7 @@ assert_reread(NMConnection *connection, gboolean normalize_connection, const cha { gs_unref_object NMConnection *reread = NULL; gs_unref_object NMConnection *connection_clone = NULL; - NMSettingConnection * s_con; + NMSettingConnection *s_con; g_assert(NM_IS_CONNECTION(connection)); @@ -104,7 +104,7 @@ assert_reread(NMConnection *connection, gboolean normalize_connection, const cha static void assert_reread_and_unlink(NMConnection *connection, gboolean normalize_connection, - const char * testfile) + const char *testfile) { assert_reread(connection, normalize_connection, testfile); unlink(testfile); @@ -118,16 +118,16 @@ assert_reread_same(NMConnection *connection, NMConnection *reread) } static void -write_test_connection_reread(NMConnection * connection, - char ** testfile, +write_test_connection_reread(NMConnection *connection, + char **testfile, NMConnection **out_reread, - gboolean * out_reread_same) + gboolean *out_reread_same) { - uid_t owner_uid; - gid_t owner_grp; - gboolean success; - GError * error = NULL; - GError ** p_error = (nmtst_get_rand_uint32() % 2) ? &error : NULL; + uid_t owner_uid; + gid_t owner_grp; + gboolean success; + GError *error = NULL; + GError **p_error = (nmtst_get_rand_uint32() % 2) ? &error : NULL; gs_unref_object NMConnection *connection_normalized = NULL; g_assert(NM_IS_CONNECTION(connection)); @@ -177,7 +177,7 @@ static GKeyFile * keyfile_load_from_file(const char *testfile) { GKeyFile *keyfile; - GError * error = NULL; + GError *error = NULL; gboolean success; g_assert(testfile && *testfile); @@ -193,12 +193,12 @@ keyfile_load_from_file(const char *testfile) static void _setting_copy_property_gbytes(NMConnection *src, NMConnection *dst, - const char * setting_name, - const char * property_name) + const char *setting_name, + const char *property_name) { gs_unref_bytes GBytes *blob = NULL; - NMSetting * s_src; - NMSetting * s_dst; + NMSetting *s_src; + NMSetting *s_dst; g_assert(NM_IS_CONNECTION(src)); g_assert(NM_IS_CONNECTION(dst)); @@ -220,12 +220,12 @@ static void test_read_valid_wired_connection(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMIPRoute * route; - const char * mac; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMIPRoute *route; + const char *mac; char expected_mac_address[ETH_ALEN] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55}; NMTST_EXPECT_NM_INFO("*ipv4.addresses:*semicolon at the end*addresses1*"); @@ -370,7 +370,7 @@ test_read_valid_wired_connection(void) static void add_one_ip_address(NMSettingIPConfig *s_ip, const char *addr, guint32 prefix) { - NMIPAddress * ip_addr; + NMIPAddress *ip_addr; gs_free_error GError *error = NULL; ip_addr = nm_ip_address_new(NM_IS_SETTING_IP4_CONFIG(s_ip) ? AF_INET : AF_INET6, @@ -384,12 +384,12 @@ add_one_ip_address(NMSettingIPConfig *s_ip, const char *addr, guint32 prefix) static void add_one_ip_route(NMSettingIPConfig *s_ip, - const char * dest, - const char * nh, + const char *dest, + const char *nh, guint32 prefix, gint64 metric) { - NMIPRoute * route; + NMIPRoute *route; gs_free_error GError *error = NULL; g_assert(prefix > 0); @@ -409,39 +409,39 @@ test_write_wired_connection(void) { NMTST_UUID_INIT(uuid); gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMIPRoute * rt; - const char * mac = "99:88:77:66:55:44"; - const char * dns1 = "4.2.2.1"; - const char * dns2 = "4.2.2.2"; - const char * address1 = "192.168.0.5"; - const char * address2 = "1.2.3.4"; - 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 = NULL; - const char * route4 = "3.3.3.3"; - const char * route4_nh = NULL; - const char * dns6_1 = "1::cafe"; - const char * dns6_2 = "2::cafe"; - const char * address6_1 = "abcd::beef"; - const char * address6_2 = "dcba::beef"; - const char * route6_1 = "1:2:3:4:5:6:7:8"; - const char * route6_1_nh = "8:7:6:5:4:3:2:1"; - const char * route6_2 = "2001::1000"; - const char * route6_2_nh = "2001::1111"; - const char * route6_3 = "4:5:6:7:8:9:0:1"; - const char * route6_3_nh = "::"; - const char * route6_4 = "5:6:7:8:9:0:1:2"; - const char * route6_4_nh = "::"; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMIPRoute *rt; + const char *mac = "99:88:77:66:55:44"; + const char *dns1 = "4.2.2.1"; + const char *dns2 = "4.2.2.2"; + const char *address1 = "192.168.0.5"; + const char *address2 = "1.2.3.4"; + 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 = NULL; + const char *route4 = "3.3.3.3"; + const char *route4_nh = NULL; + const char *dns6_1 = "1::cafe"; + const char *dns6_2 = "2::cafe"; + const char *address6_1 = "abcd::beef"; + const char *address6_2 = "dcba::beef"; + const char *route6_1 = "1:2:3:4:5:6:7:8"; + const char *route6_1_nh = "8:7:6:5:4:3:2:1"; + const char *route6_2 = "2001::1000"; + const char *route6_2_nh = "2001::1111"; + const char *route6_3 = "4:5:6:7:8:9:0:1"; + const char *route6_3_nh = "::"; + const char *route6_4 = "5:6:7:8:9:0:1:2"; + const char *route6_4_nh = "::"; guint64 timestamp = 0x12345678L; - GError * error = NULL; + GError *error = NULL; connection = nm_simple_connection_new(); @@ -534,10 +534,10 @@ static void test_read_ip6_wired_connection(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = keyfile_read_connection_from_file(TEST_KEYFILES_DIR "/Test_Wired_Connection_IP6"); @@ -573,13 +573,13 @@ test_write_ip6_wired_connection(void) { NMTST_UUID_INIT(uuid); gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - const char * dns = "1::cafe"; - const char * address = "abcd::beef"; - const char * gw = "dcba::beef"; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + const char *dns = "1::cafe"; + const char *address = "abcd::beef"; + const char *gw = "dcba::beef"; connection = nm_simple_connection_new(); @@ -639,9 +639,9 @@ static void test_read_wired_mac_case(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - const char * mac; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + const char *mac; char expected_mac_address[ETH_ALEN] = {0x00, 0x11, 0xaa, 0xbb, 0xcc, 0x55}; NMTST_EXPECT_NM_INFO("*ipv4.addresses*semicolon at the end*addresses1*"); @@ -669,8 +669,8 @@ static void test_read_mac_old_format(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingWired * s_wired; - const char * mac; + NMSettingWired *s_wired; + const char *mac; char expected_mac[ETH_ALEN] = {0x00, 0x11, 0xaa, 0xbb, 0xcc, 0x55}; char expected_cloned_mac[ETH_ALEN] = {0x00, 0x16, 0xaa, 0xbb, 0xcc, 0xfe}; @@ -692,8 +692,8 @@ static void test_read_mac_ib_old_format(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingInfiniband * s_ib; - const char * mac; + NMSettingInfiniband *s_ib; + const char *mac; guint8 expected_mac[INFINIBAND_ALEN] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89, 0x90}; @@ -713,10 +713,10 @@ static void test_read_valid_wireless_connection(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingIPConfig * s_ip4; - const char * bssid; + NMSettingConnection *s_con; + NMSettingWireless *s_wireless; + NMSettingIPConfig *s_ip4; + const char *bssid; const guint8 expected_bssid[ETH_ALEN] = {0x00, 0x1a, 0x33, 0x44, 0x99, 0x82}; connection = keyfile_read_connection_from_file(TEST_KEYFILES_DIR "/Test_Wireless_Connection"); @@ -746,12 +746,12 @@ test_write_wireless_connection(void) { NMTST_UUID_INIT(uuid); gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - const char * bssid = "aa:b9:a1:74:55:44"; - GBytes * ssid; + NMSettingConnection *s_con; + NMSettingWireless *s_wireless; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + const char *bssid = "aa:b9:a1:74:55:44"; + GBytes *ssid; unsigned char tmpssid[] = {0x31, 0x33, 0x33, 0x37}; guint64 timestamp = 0x12344433L; @@ -814,11 +814,11 @@ static void test_read_string_ssid(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingWireless * s_wireless; - GBytes * ssid; - const guint8 * ssid_data; + NMSettingWireless *s_wireless; + GBytes *ssid; + const guint8 *ssid_data; gsize ssid_len; - const char * expected_ssid = "blah blah ssid 1234"; + const char *expected_ssid = "blah blah ssid 1234"; connection = keyfile_read_connection_from_file(TEST_KEYFILES_DIR "/Test_String_SSID"); @@ -836,15 +836,15 @@ static void test_write_string_ssid(void) { NMTST_UUID_INIT(uuid); - gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingIPConfig * s_ip4; - char * tmp; - gs_free char * testfile = NULL; - GBytes * ssid; - unsigned char tmpssid[] = {65, 49, 50, 51, 32, 46, 92, 46, 36, 37, 126, 93}; - nm_auto_unref_keyfile GKeyFile *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection *s_con; + NMSettingWireless *s_wireless; + NMSettingIPConfig *s_ip4; + char *tmp; + gs_free char *testfile = NULL; + GBytes *ssid; + unsigned char tmpssid[] = {65, 49, 50, 51, 32, 46, 92, 46, 36, 37, 126, 93}; + nm_auto_unref_keyfile GKeyFile *keyfile = NULL; connection = nm_simple_connection_new(); @@ -894,11 +894,11 @@ static void test_read_intlist_ssid(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingWireless * s_wifi; - GBytes * ssid; - const guint8 * ssid_data; + NMSettingWireless *s_wifi; + GBytes *ssid; + const guint8 *ssid_data; gsize ssid_len; - const char * expected_ssid = "blah1234"; + const char *expected_ssid = "blah1234"; connection = keyfile_read_connection_from_file(TEST_KEYFILES_DIR "/Test_Intlist_SSID"); @@ -915,16 +915,16 @@ static void test_write_intlist_ssid(void) { NMTST_UUID_INIT(uuid); - gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingIPConfig * s_ip4; - gs_free char * testfile = NULL; - GBytes * ssid; - unsigned char tmpssid[] = {65, 49, 50, 51, 0, 50, 50}; - gs_free_error GError *error = NULL; - nm_auto_unref_keyfile GKeyFile *keyfile = NULL; - int * intlist; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingIPConfig *s_ip4; + gs_free char *testfile = NULL; + GBytes *ssid; + unsigned char tmpssid[] = {65, 49, 50, 51, 0, 50, 50}; + gs_free_error GError *error = NULL; + nm_auto_unref_keyfile GKeyFile *keyfile = NULL; + int *intlist; gsize len = 0, i; connection = nm_simple_connection_new(); @@ -981,9 +981,9 @@ static void test_read_intlike_ssid(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingWireless * s_wifi; - GBytes * ssid; - const char * expected_ssid = "101"; + NMSettingWireless *s_wifi; + GBytes *ssid; + const char *expected_ssid = "101"; connection = keyfile_read_connection_from_file(TEST_KEYFILES_DIR "/Test_Intlike_SSID"); @@ -999,9 +999,9 @@ static void test_read_intlike_ssid_2(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingWireless * s_wifi; - GBytes * ssid; - const char * expected_ssid = "11;12;13;"; + NMSettingWireless *s_wifi; + GBytes *ssid; + const char *expected_ssid = "11;12;13;"; connection = keyfile_read_connection_from_file(TEST_KEYFILES_DIR "/Test_Intlike_SSID_2"); @@ -1017,16 +1017,16 @@ static void test_write_intlike_ssid(void) { NMTST_UUID_INIT(uuid); - gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingIPConfig * s_ip4; - gs_free char * testfile = NULL; - GBytes * ssid; - unsigned char tmpssid[] = {49, 48, 49}; - gs_free_error GError *error = NULL; - nm_auto_unref_keyfile GKeyFile *keyfile = NULL; - char * tmp; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingIPConfig *s_ip4; + gs_free char *testfile = NULL; + GBytes *ssid; + unsigned char tmpssid[] = {49, 48, 49}; + gs_free_error GError *error = NULL; + nm_auto_unref_keyfile GKeyFile *keyfile = NULL; + char *tmp; connection = nm_simple_connection_new(); @@ -1078,16 +1078,16 @@ static void test_write_intlike_ssid_2(void) { NMTST_UUID_INIT(uuid); - gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingIPConfig * s_ip4; - gs_free char * testfile = NULL; - GBytes * ssid; - unsigned char tmpssid[] = {49, 49, 59, 49, 50, 59, 49, 51, 59}; - gs_free_error GError *error = NULL; - nm_auto_unref_keyfile GKeyFile *keyfile = NULL; - char * tmp; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingIPConfig *s_ip4; + gs_free char *testfile = NULL; + GBytes *ssid; + unsigned char tmpssid[] = {49, 49, 59, 49, 50, 59, 49, 51, 59}; + gs_free_error GError *error = NULL; + nm_auto_unref_keyfile GKeyFile *keyfile = NULL; + char *tmp; connection = nm_simple_connection_new(); g_assert(connection); @@ -1140,11 +1140,11 @@ static void test_read_bt_dun_connection(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingBluetooth * s_bluetooth; - NMSettingSerial * s_serial; - NMSettingGsm * s_gsm; - const char * bdaddr; + NMSettingConnection *s_con; + NMSettingBluetooth *s_bluetooth; + NMSettingSerial *s_serial; + NMSettingGsm *s_gsm; + const char *bdaddr; const guint8 expected_bdaddr[ETH_ALEN] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55}; connection = keyfile_read_connection_from_file(TEST_KEYFILES_DIR "/ATT_Data_Connect_BT"); @@ -1181,11 +1181,11 @@ test_write_bt_dun_connection(void) { NMTST_UUID_INIT(uuid); gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingBluetooth * s_bt; - NMSettingIPConfig * s_ip4; - NMSettingGsm * s_gsm; - const char * bdaddr = "aa:b9:a1:74:55:44"; + NMSettingConnection *s_con; + NMSettingBluetooth *s_bt; + NMSettingIPConfig *s_ip4; + NMSettingGsm *s_gsm; + const char *bdaddr = "aa:b9:a1:74:55:44"; guint64 timestamp = 0x12344433L; connection = nm_simple_connection_new(); @@ -1247,9 +1247,9 @@ static void test_read_gsm_connection(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingSerial * s_serial; - NMSettingGsm * s_gsm; + NMSettingConnection *s_con; + NMSettingSerial *s_serial; + NMSettingGsm *s_gsm; connection = keyfile_read_connection_from_file(TEST_KEYFILES_DIR "/ATT_Data_Connect_Plain"); @@ -1286,9 +1286,9 @@ test_write_gsm_connection(void) { NMTST_UUID_INIT(uuid); gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingGsm * s_gsm; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingGsm *s_gsm; guint64 timestamp = 0x12344433L; connection = nm_simple_connection_new(); @@ -1350,10 +1350,10 @@ static void test_read_wired_8021x_tls_blob_connection(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingWired * s_wired; - NMSetting8021x * s_8021x; - const char * tmp; - GBytes * blob; + NMSettingWired *s_wired; + NMSetting8021x *s_8021x; + const char *tmp; + GBytes *blob; NMTST_EXPECT_NM_WARN("keyfile: 802-1x.client-cert: certificate or key file " "'/CASA/dcbw/Desktop/certinfra/client.pem' does not exist*"); @@ -1403,10 +1403,10 @@ static void test_read_wired_8021x_tls_bad_path_connection(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingWired * s_wired; - NMSetting8021x * s_8021x; - const char * tmp; - char * tmp2; + NMSettingWired *s_wired; + NMSetting8021x *s_8021x; + const char *tmp; + char *tmp2; NMTST_EXPECT_NM_WARN("*does not exist*"); connection = @@ -1451,9 +1451,9 @@ static void test_read_wired_8021x_tls_old_connection(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingWired * s_wired; - NMSetting8021x * s_8021x; - const char * tmp; + NMSettingWired *s_wired; + NMSetting8021x *s_8021x; + const char *tmp; NMTST_EXPECT_NM_WARN("keyfile: 802-1x.ca-cert: certificate or key file " "'/CASA/dcbw/Desktop/certinfra/CA/eaptest_ca_cert.pem' does not exist*"); @@ -1493,10 +1493,10 @@ static void test_read_wired_8021x_tls_new_connection(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingWired * s_wired; - NMSetting8021x * s_8021x; - const char * tmp; - char * tmp2; + NMSettingWired *s_wired; + NMSetting8021x *s_8021x; + const char *tmp; + char *tmp2; connection = keyfile_read_connection_from_file(TEST_KEYFILES_DIR "/Test_Wired_TLS_New"); @@ -1540,12 +1540,12 @@ static NMConnection * create_wired_tls_connection(NMSetting8021xCKScheme scheme) { NMTST_UUID_INIT(uuid); - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4; - NMSetting * s_wired; - NMSetting8021x * s_8021x; - gboolean success; + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSetting *s_wired; + NMSetting8021x *s_8021x; + gboolean success; gs_free_error GError *error = NULL; connection = nm_simple_connection_new(); @@ -1617,11 +1617,11 @@ get_path(const char *file, gboolean relative) static void test_write_wired_8021x_tls_connection_path(void) { - gs_unref_object NMConnection *connection = NULL; - gs_unref_object NMConnection *reread = NULL; - char * tmp, *tmp2; - gboolean success; - gs_free char * testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + char *tmp, *tmp2; + gboolean success; + gs_free char *testfile = NULL; nm_auto_unref_keyfile GKeyFile *keyfile = NULL; gboolean relative = FALSE; gboolean reread_same = FALSE; @@ -1705,15 +1705,15 @@ test_write_wired_8021x_tls_connection_blob(void) { gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - NMSettingConnection * s_con; - NMSetting8021x * s_8021x; - gs_free char * testfile = NULL; - char * new_ca_cert; - char * new_client_cert; - char * new_priv_key; - const char * uuid; + NMSettingConnection *s_con; + NMSetting8021x *s_8021x; + gs_free char *testfile = NULL; + char *new_ca_cert; + char *new_client_cert; + char *new_priv_key; + const char *uuid; gboolean reread_same = FALSE; - GBytes * password_raw; + GBytes *password_raw; #define PASSWORD_RAW "password-raw\0test" @@ -1801,9 +1801,9 @@ static void test_read_infiniband_connection(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingInfiniband * s_ib; - const char * mac; + NMSettingConnection *s_con; + NMSettingInfiniband *s_ib; + const char *mac; guint8 expected_mac[INFINIBAND_ALEN] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89, 0x90}; @@ -1830,10 +1830,10 @@ test_write_infiniband_connection(void) { NMTST_UUID_INIT(uuid); gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingInfiniband * s_ib; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingConnection *s_con; + NMSettingInfiniband *s_ib; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; const char *mac = "99:88:77:66:55:44:ab:bc:cd:de:ef:f0:0a:1b:2c:3d:4e:5f:6f:ba"; connection = nm_simple_connection_new(); @@ -1888,11 +1888,11 @@ static void test_read_bridge_main(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingBridge * s_bridge; - const char * expected_id = "Test Bridge Main"; - const char * expected_uuid = "8f061643-fe41-4d4c-a8d9-097d26e2ad3a"; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingBridge *s_bridge; + const char *expected_id = "Test Bridge Main"; + const char *expected_uuid = "8f061643-fe41-4d4c-a8d9-097d26e2ad3a"; connection = keyfile_read_connection_from_file(TEST_KEYFILES_DIR "/Test_Bridge_Main"); @@ -1922,10 +1922,10 @@ test_write_bridge_main(void) { NMTST_UUID_INIT(uuid); gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingBridge * s_bridge; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingConnection *s_con; + NMSettingBridge *s_bridge; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = nm_simple_connection_new(); g_assert(connection); @@ -1981,13 +1981,13 @@ static void test_read_bridge_component(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingBridgePort * s_port; - NMSettingWired * s_wired; - const char * mac; + NMSettingConnection *s_con; + NMSettingBridgePort *s_port; + NMSettingWired *s_wired; + const char *mac; guint8 expected_mac[ETH_ALEN] = {0x00, 0x22, 0x15, 0x59, 0x62, 0x97}; - const char * expected_id = "Test Bridge Component"; - const char * expected_uuid = "d7b4f96c-c45e-4298-bef8-f48574f8c1c0"; + const char *expected_id = "Test Bridge Component"; + const char *expected_uuid = "d7b4f96c-c45e-4298-bef8-f48574f8c1c0"; connection = keyfile_read_connection_from_file(TEST_KEYFILES_DIR "/Test_Bridge_Component"); @@ -2016,10 +2016,10 @@ test_write_bridge_component(void) { NMTST_UUID_INIT(uuid); gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingBridgePort * s_port; - NMSettingWired * s_wired; - const char * mac = "99:88:77:66:55:44"; + NMSettingConnection *s_con; + NMSettingBridgePort *s_port; + NMSettingWired *s_wired; + const char *mac = "99:88:77:66:55:44"; connection = nm_simple_connection_new(); g_assert(connection); @@ -2070,8 +2070,8 @@ static void test_read_new_wired_group_name(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingWired * s_wired; - const char * mac; + NMSettingWired *s_wired; + const char *mac; guint8 expected_mac[ETH_ALEN] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55}; connection = keyfile_read_connection_from_file(TEST_KEYFILES_DIR "/Test_New_Wired_Group_Name"); @@ -2089,14 +2089,14 @@ static void test_write_new_wired_group_name(void) { NMTST_UUID_INIT(uuid); - gs_unref_object NMConnection *connection = NULL; - nm_auto_unref_keyfile GKeyFile *kf = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - gs_free char * testfile = NULL; - gs_free_error GError *error = NULL; - char * s; - int mtu; + gs_unref_object NMConnection *connection = NULL; + nm_auto_unref_keyfile GKeyFile *kf = NULL; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + gs_free char *testfile = NULL; + gs_free_error GError *error = NULL; + char *s; + int mtu; connection = nm_simple_connection_new(); g_assert(connection); @@ -2147,10 +2147,10 @@ static void test_read_new_wireless_group_names(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - GBytes * ssid; - const char * expected_ssid = "foobar"; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + GBytes *ssid; + const char *expected_ssid = "foobar"; connection = keyfile_read_connection_from_file(TEST_KEYFILES_DIR "/Test_New_Wireless_Group_Names"); @@ -2174,17 +2174,17 @@ static void test_write_new_wireless_group_names(void) { NMTST_UUID_INIT(uuid); - gs_unref_object NMConnection *connection = NULL; - nm_auto_unref_keyfile GKeyFile *kf = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity * s_wsec; - GBytes * ssid; + gs_unref_object NMConnection *connection = NULL; + nm_auto_unref_keyfile GKeyFile *kf = NULL; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + GBytes *ssid; unsigned char tmpssid[] = {0x31, 0x33, 0x33, 0x37}; - const char * expected_psk = "asdfasdfasdfa12315"; - gs_free char * testfile = NULL; - gs_free_error GError *error = NULL; - char * s; + const char *expected_psk = "asdfasdfasdfa12315"; + gs_free char *testfile = NULL; + gs_free_error GError *error = NULL; + char *s; connection = nm_simple_connection_new(); @@ -2257,7 +2257,7 @@ static void test_read_missing_vlan_setting(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingVlan * s_vlan; + NMSettingVlan *s_vlan; connection = keyfile_read_connection_from_file(TEST_KEYFILES_DIR "/Test_Missing_Vlan_Setting"); @@ -2271,7 +2271,7 @@ static void test_read_missing_vlan_flags(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingVlan * s_vlan; + NMSettingVlan *s_vlan; connection = keyfile_read_connection_from_file(TEST_KEYFILES_DIR "/Test_Missing_Vlan_Flags"); @@ -2287,8 +2287,8 @@ static void test_read_missing_id_uuid(void) { gs_unref_object NMConnection *connection = NULL; - gs_free char * expected_uuid = NULL; - const char * FILENAME = TEST_KEYFILES_DIR "/Test_Missing_ID_UUID"; + gs_free char *expected_uuid = NULL; + const char *FILENAME = TEST_KEYFILES_DIR "/Test_Missing_ID_UUID"; expected_uuid = nm_uuid_generate_from_strings("keyfile", FILENAME, NULL); @@ -2303,7 +2303,7 @@ test_read_minimal(void) { gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *con_archetype = NULL; - NMSettingConnection * s_con; + NMSettingConnection *s_con; con_archetype = nmtst_create_minimal_connection("Test_minimal_x", "a15bd68f-c32b-40b8-8d27-49e472a85919", @@ -2337,7 +2337,7 @@ test_read_minimal_slave(void) { gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *con_archetype = NULL; - NMSettingConnection * s_con; + NMSettingConnection *s_con; con_archetype = nmtst_create_minimal_connection("Test_minimal_slave_x", "a56b4ca5-7075-43d4-82c7-5d0cb15f7654", @@ -2396,7 +2396,7 @@ static void test_read_enum_property(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingIPConfig * s_ip6; + NMSettingIPConfig *s_ip6; connection = keyfile_read_connection_from_file(TEST_KEYFILES_DIR "/Test_Enum_Property"); @@ -2412,9 +2412,9 @@ test_write_enum_property(void) { NMTST_UUID_INIT(uuid); gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip6; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip6; connection = nm_simple_connection_new(); @@ -2455,7 +2455,7 @@ static void test_read_flags_property(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingGsm * s_gsm; + NMSettingGsm *s_gsm; connection = keyfile_read_connection_from_file(TEST_KEYFILES_DIR "/Test_Flags_Property"); @@ -2471,8 +2471,8 @@ test_write_flags_property(void) { NMTST_UUID_INIT(uuid); gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSetting * s_gsm; + NMSettingConnection *s_con; + NMSetting *s_gsm; connection = nm_simple_connection_new(); @@ -2513,10 +2513,10 @@ static void test_read_tc_config(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingTCConfig * s_tc; - NMTCQdisc * qdisc1, *qdisc2; - NMTCAction * action1, *action2; - NMTCTfilter * tfilter1, *tfilter2; + NMSettingTCConfig *s_tc; + NMTCQdisc *qdisc1, *qdisc2; + NMTCAction *action1, *action2; + NMTCTfilter *tfilter1, *tfilter2; connection = keyfile_read_connection_from_file(TEST_KEYFILES_DIR "/Test_TC_Config"); @@ -2567,11 +2567,11 @@ static void test_write_tc_config(void) { gs_unref_object NMConnection *connection = NULL; - NMSetting * s_tc; - NMTCQdisc * qdisc1, *qdisc2; - NMTCTfilter * tfilter1, *tfilter2; - NMTCAction * action; - GError * error = NULL; + NMSetting *s_tc; + NMTCQdisc *qdisc1, *qdisc2; + NMTCTfilter *tfilter1, *tfilter2; + NMTCAction *action; + GError *error = NULL; connection = nmtst_create_minimal_connection("Test TC", NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); @@ -2751,12 +2751,12 @@ _assert_keyfile_nmmeta(const char *dirname, static void test_nmmeta(void) { - const char * uuid = "3c03fd17-ddc3-4100-a954-88b6fafff959"; + const char *uuid = "3c03fd17-ddc3-4100-a954-88b6fafff959"; gs_free char *filename = g_strdup_printf("%s%s", uuid, NM_KEYFILE_PATH_SUFFIX_NMMETA); gs_free char *full_filename = g_strdup_printf("%s/%s", TEST_SCRATCH_DIR, filename); - const char * loaded_path0 = NM_KEYFILE_PATH_NMMETA_SYMLINK_NULL; - const char * loaded_path1 = "/some/where/but/not/scratch/dir"; - const char * filename2 = "foo1"; + const char *loaded_path0 = NM_KEYFILE_PATH_NMMETA_SYMLINK_NULL; + const char *loaded_path1 = "/some/where/but/not/scratch/dir"; + const char *filename2 = "foo1"; gs_free char *loaded_path2 = g_strdup_printf("%s/%s", TEST_SCRATCH_DIR, filename2); _assert_keyfile_nmmeta(TEST_SCRATCH_DIR, uuid, NULL, FALSE, full_filename, NULL, NULL, NULL); diff --git a/src/core/supplicant/nm-supplicant-config.c b/src/core/supplicant/nm-supplicant-config.c index c486ba1d..96c23579 100644 --- a/src/core/supplicant/nm-supplicant-config.c +++ b/src/core/supplicant/nm-supplicant-config.c @@ -20,7 +20,7 @@ #include "nm-setting-ip4-config.h" typedef struct { - char * value; + char *value; guint32 len; NMSupplOptType type; } ConfigOption; @@ -28,8 +28,8 @@ typedef struct { /*****************************************************************************/ typedef struct { - GHashTable * config; - GHashTable * blobs; + GHashTable *config; + GHashTable *blobs; NMSupplCapMask capabilities; guint32 ap_scan; bool fast_required : 1; @@ -63,7 +63,7 @@ NMSupplicantConfig * nm_supplicant_config_new(NMSupplCapMask capabilities) { NMSupplicantConfigPrivate *priv; - NMSupplicantConfig * self; + NMSupplicantConfig *self; self = g_object_new(NM_TYPE_SUPPLICANT_CONFIG, NULL); priv = NM_SUPPLICANT_CONFIG_GET_PRIVATE(self); @@ -96,16 +96,16 @@ nm_supplicant_config_init(NMSupplicantConfig *self) static gboolean nm_supplicant_config_add_option_with_type(NMSupplicantConfig *self, - const char * key, - const char * value, + const char *key, + const char *value, gint32 len, NMSupplOptType opt_type, - const char * display_value, - GError ** error) + const char *display_value, + GError **error) { NMSupplicantConfigPrivate *priv; - ConfigOption * old_opt; - ConfigOption * opt; + ConfigOption *old_opt; + ConfigOption *opt; NMSupplOptType type; g_return_val_if_fail(NM_IS_SUPPLICANT_CONFIG(self), FALSE); @@ -124,7 +124,7 @@ nm_supplicant_config_add_option_with_type(NMSupplicantConfig *self, type = nm_supplicant_settings_verify_setting(key, value, len); if (type == NM_SUPPL_OPT_TYPE_INVALID) { gs_free char *str_free = NULL; - const char * str; + const char *str; str = nm_utils_buf_utf8safe_escape(value, len, @@ -178,11 +178,11 @@ nm_supplicant_config_add_option_with_type(NMSupplicantConfig *self, static gboolean nm_supplicant_config_add_option(NMSupplicantConfig *self, - const char * key, - const char * value, + const char *key, + const char *value, gint32 len, - const char * display_value, - GError ** error) + const char *display_value, + GError **error) { return nm_supplicant_config_add_option_with_type(self, key, @@ -195,16 +195,16 @@ nm_supplicant_config_add_option(NMSupplicantConfig *self, static gboolean nm_supplicant_config_add_blob(NMSupplicantConfig *self, - const char * key, - GBytes * value, - const char * blobid, - GError ** error) + const char *key, + GBytes *value, + const char *blobid, + GError **error) { NMSupplicantConfigPrivate *priv; - ConfigOption * old_opt; - ConfigOption * opt; + ConfigOption *old_opt; + ConfigOption *opt; NMSupplOptType type; - const guint8 * data; + const guint8 *data; gsize data_len; g_return_val_if_fail(NM_IS_SUPPLICANT_CONFIG(self), FALSE); @@ -256,14 +256,14 @@ nm_supplicant_config_add_blob(NMSupplicantConfig *self, static gboolean nm_supplicant_config_add_blob_for_connection(NMSupplicantConfig *self, - GBytes * field, - const char * name, - const char * con_uid, - GError ** error) + GBytes *field, + const char *name, + const char *con_uid, + GError **error) { if (field && g_bytes_get_size(field)) { gs_free char *uid = NULL; - char * p; + char *p; uid = g_strdup_printf("%s-%s", con_uid, name); for (p = uid; *p; p++) { @@ -317,8 +317,8 @@ nm_supplicant_config_to_variant(NMSupplicantConfig *self) NMSupplicantConfigPrivate *priv; GVariantBuilder builder; GHashTableIter iter; - ConfigOption * option; - const char * key; + ConfigOption *option; + const char *key; g_return_val_if_fail(NM_IS_SUPPLICANT_CONFIG(self), NULL); @@ -364,8 +364,8 @@ wifi_freqs_to_string(gboolean bg_band) { static const char *str_2ghz = NULL; static const char *str_5ghz = NULL; - const char ** f_p; - const char * f; + const char **f_p; + const char *f; f_p = bg_band ? &str_2ghz : &str_5ghz; @@ -374,7 +374,7 @@ again: if (G_UNLIKELY(!f)) { nm_auto_str_buf NMStrBuf strbuf = NM_STR_BUF_INIT(400, FALSE); - const guint * freqs; + const guint *freqs; int i; freqs = bg_band ? nm_utils_wifi_2ghz_freqs() : nm_utils_wifi_5ghz_freqs(); @@ -397,8 +397,8 @@ again: gboolean nm_supplicant_config_add_setting_macsec(NMSupplicantConfig *self, - NMSettingMacsec * setting, - GError ** error) + NMSettingMacsec *setting, + GError **error) { const char *value; char buf[32]; @@ -467,16 +467,16 @@ nm_supplicant_config_add_setting_macsec(NMSupplicantConfig *self, gboolean nm_supplicant_config_add_setting_wireless(NMSupplicantConfig *self, - NMSettingWireless * setting, + NMSettingWireless *setting, guint32 fixed_freq, - GError ** error) + GError **error) { NMSupplicantConfigPrivate *priv; gboolean is_adhoc, is_ap, is_mesh; - const char * mode, *band; + const char *mode, *band; guint32 channel; - GBytes * ssid; - const char * bssid; + GBytes *ssid; + const char *bssid; g_return_val_if_fail(NM_IS_SUPPLICANT_CONFIG(self), FALSE); g_return_val_if_fail(setting != NULL, FALSE); @@ -584,9 +584,9 @@ nm_supplicant_config_add_setting_wireless(NMSupplicantConfig *self, gboolean nm_supplicant_config_add_bgscan(NMSupplicantConfig *self, NMConnection *connection, GError **error) { - NMSettingWireless * s_wifi; + NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; - const char * bgscan; + const char *bgscan; s_wifi = nm_connection_get_setting_wireless(connection); g_assert(s_wifi); @@ -632,11 +632,11 @@ nm_supplicant_config_add_bgscan(NMSupplicantConfig *self, NMConnection *connecti static gboolean add_string_val(NMSupplicantConfig *self, - const char * field, - const char * name, + const char *field, + const char *name, gboolean ucase, - const char * display_value, - GError ** error) + const char *display_value, + GError **error) { if (field) { gs_free char *value = NULL; @@ -671,7 +671,7 @@ add_string_val(NMSupplicantConfig *self, \ if (nm_setting_##setting_name##_get_num_##field_plural(_setting)) { \ const char _separator = (separator); \ - GString * _str = g_string_new(NULL); \ + GString *_str = g_string_new(NULL); \ guint _k, _n; \ \ _n = nm_setting_##setting_name##_get_num_##field_plural(_setting); \ @@ -727,10 +727,10 @@ wep128_passphrase_hash(const char *input, gsize input_len, guint8 *digest /* 13 static gboolean add_wep_key(NMSupplicantConfig *self, - const char * key, - const char * name, + const char *key, + const char *name, NMWepKeyType wep_type, - GError ** error) + GError **error) { gsize key_len; @@ -801,19 +801,19 @@ add_wep_key(NMSupplicantConfig *self, } gboolean -nm_supplicant_config_add_setting_wireless_security(NMSupplicantConfig * self, - NMSettingWirelessSecurity * setting, - NMSetting8021x * setting_8021x, - const char * con_uuid, +nm_supplicant_config_add_setting_wireless_security(NMSupplicantConfig *self, + NMSettingWirelessSecurity *setting, + NMSetting8021x *setting_8021x, + const char *con_uuid, guint32 mtu, NMSettingWirelessSecurityPmf pmf, NMSettingWirelessSecurityFils fils, - GError ** error) + GError **error) { - NMSupplicantConfigPrivate *priv = NM_SUPPLICANT_CONFIG_GET_PRIVATE(self); + NMSupplicantConfigPrivate *priv = NM_SUPPLICANT_CONFIG_GET_PRIVATE(self); nm_auto_free_gstring GString *key_mgmt_conf = NULL; - const char * key_mgmt, *auth_alg; - const char * psk; + const char *key_mgmt, *auth_alg; + const char *psk; gboolean set_pmf, wps_disabled; g_return_val_if_fail(NM_IS_SUPPLICANT_CONFIG(self), FALSE); @@ -1056,10 +1056,10 @@ nm_supplicant_config_add_setting_wireless_security(NMSupplicantConfig * /* WEP keys if required */ if (nm_streq(key_mgmt, "none")) { NMWepKeyType wep_type = nm_setting_wireless_security_get_wep_key_type(setting); - const char * wep0 = nm_setting_wireless_security_get_wep_key(setting, 0); - 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); + const char *wep0 = nm_setting_wireless_security_get_wep_key(setting, 0); + 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); if (!add_wep_key(self, wep0, "wep_key0", wep_type, error)) return FALSE; @@ -1148,18 +1148,18 @@ nm_supplicant_config_add_setting_wireless_security(NMSupplicantConfig * } static gboolean -add_pkcs11_uri_with_pin(NMSupplicantConfig * self, - const char * name, - const char * uri, - const char * pin, +add_pkcs11_uri_with_pin(NMSupplicantConfig *self, + const char *name, + const char *uri, + const char *pin, const NMSettingSecretFlags pin_flags, - GError ** error) + GError **error) { gs_strfreev char **split = NULL; - gs_free char * tmp = NULL; - gs_free char * tmp_log = NULL; - gs_free char * pin_qattr = NULL; - char * escaped = NULL; + gs_free char *tmp = NULL; + gs_free char *tmp_log = NULL; + gs_free char *pin_qattr = NULL; + char *escaped = NULL; if (uri == NULL) return TRUE; @@ -1195,25 +1195,25 @@ add_pkcs11_uri_with_pin(NMSupplicantConfig * self, gboolean nm_supplicant_config_add_setting_8021x(NMSupplicantConfig *self, - NMSetting8021x * setting, - const char * con_uuid, + NMSetting8021x *setting, + const char *con_uuid, guint32 mtu, gboolean wired, - GError ** error) + GError **error) { - NMSupplicantConfigPrivate *priv; - char * tmp; - const char * peapver, *value, *path; - gboolean added; - GString * phase1, *phase2; - GBytes * bytes; - gboolean fast = FALSE; - guint32 i, num_eap; - gboolean fast_provisoning_allowed = FALSE; - const char * ca_path_override = NULL, *ca_cert_override = NULL; - guint32 frag, hdrs; - gs_free char * frag_str = NULL; - NMSetting8021xAuthFlags phase1_auth_flags; + NMSupplicantConfigPrivate *priv; + char *tmp; + const char *peapver, *value, *path; + gboolean added; + GString *phase1, *phase2; + GBytes *bytes; + gboolean fast = FALSE; + guint32 i, num_eap; + gboolean fast_provisoning_allowed = FALSE; + const char *ca_path_override = NULL, *ca_cert_override = NULL; + guint32 frag, hdrs; + gs_free char *frag_str = NULL; + NMSetting8021xAuthFlags phase1_auth_flags; nm_auto_free_gstring GString *eap_str = NULL; g_return_val_if_fail(NM_IS_SUPPLICANT_CONFIG(self), FALSE); diff --git a/src/core/supplicant/nm-supplicant-config.h b/src/core/supplicant/nm-supplicant-config.h index b5619362..349c310f 100644 --- a/src/core/supplicant/nm-supplicant-config.h +++ b/src/core/supplicant/nm-supplicant-config.h @@ -40,34 +40,34 @@ GVariant *nm_supplicant_config_to_variant(NMSupplicantConfig *self); GHashTable *nm_supplicant_config_get_blobs(NMSupplicantConfig *self); gboolean nm_supplicant_config_add_setting_wireless(NMSupplicantConfig *self, - NMSettingWireless * setting, + NMSettingWireless *setting, guint32 fixed_freq, - GError ** error); + GError **error); gboolean nm_supplicant_config_add_bgscan(NMSupplicantConfig *self, NMConnection *connection, GError **error); -gboolean nm_supplicant_config_add_setting_wireless_security(NMSupplicantConfig * self, +gboolean nm_supplicant_config_add_setting_wireless_security(NMSupplicantConfig *self, NMSettingWirelessSecurity *setting, NMSetting8021x *setting_8021x, - const char * con_uuid, + const char *con_uuid, guint32 mtu, NMSettingWirelessSecurityPmf pmf, NMSettingWirelessSecurityFils fils, - GError ** error); + GError **error); gboolean nm_supplicant_config_add_no_security(NMSupplicantConfig *self, GError **error); gboolean nm_supplicant_config_add_setting_8021x(NMSupplicantConfig *self, - NMSetting8021x * setting, - const char * con_uuid, + NMSetting8021x *setting, + const char *con_uuid, guint32 mtu, gboolean wired, - GError ** error); + GError **error); gboolean nm_supplicant_config_add_setting_macsec(NMSupplicantConfig *self, - NMSettingMacsec * setting, - GError ** error); + NMSettingMacsec *setting, + GError **error); gboolean nm_supplicant_config_enable_pmf_akm(NMSupplicantConfig *self, GError **error); diff --git a/src/core/supplicant/nm-supplicant-interface.c b/src/core/supplicant/nm-supplicant-interface.c index 2d56b836..d8276144 100644 --- a/src/core/supplicant/nm-supplicant-interface.c +++ b/src/core/supplicant/nm-supplicant-interface.c @@ -26,11 +26,11 @@ typedef struct { NMSupplicantInterface *self; - char * type; - char * bssid; - char * pin; + char *type; + char *bssid; + char *pin; guint signal_id; - GCancellable * cancellable; + GCancellable *cancellable; bool needs_cancelling : 1; bool is_cancelling : 1; } WpsData; @@ -38,23 +38,23 @@ typedef struct { struct _AddNetworkData; typedef struct { - NMSupplicantInterface * self; - NMSupplicantConfig * cfg; - GCancellable * cancellable; + NMSupplicantInterface *self; + NMSupplicantConfig *cfg; + GCancellable *cancellable; NMSupplicantInterfaceAssocCb callback; gpointer user_data; guint fail_on_idle_id; guint blobs_left; guint calls_left; - struct _AddNetworkData * add_network_data; + struct _AddNetworkData *add_network_data; } AssocData; typedef struct _AddNetworkData { /* the assoc_data at the time when doing the call. */ - AssocData * assoc_data; + AssocData *assoc_data; NMRefString *name_owner; NMRefString *object_path; - GObject * shutdown_wait_obj; + GObject *shutdown_wait_obj; } AddNetworkData; enum { @@ -86,8 +86,8 @@ typedef struct _NMSupplicantInterfacePrivate { NMSupplicantManager *supplicant_manager; GDBusConnection *dbus_connection; - NMRefString * name_owner; - NMRefString * object_path; + NMRefString *name_owner; + NMRefString *object_path; char *ifname; @@ -173,6 +173,8 @@ G_DEFINE_TYPE(NMSupplicantInterface, nm_supplicant_interface, G_TYPE_OBJECT) #define NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self) \ _NM_GET_PRIVATE_PTR(self, NMSupplicantInterface, NM_IS_SUPPLICANT_INTERFACE) +static NMTernary _get_capability(NMSupplicantInterfacePrivate *priv, NMSupplCapType type); + /*****************************************************************************/ static const char * @@ -197,7 +199,7 @@ _log_pretty_object_path(NMSupplicantInterfacePrivate *priv) #define _NMLOG(level, ...) \ G_STMT_START \ { \ - NMSupplicantInterface * _self = (self); \ + NMSupplicantInterface *_self = (self); \ NMSupplicantInterfacePrivate *_priv = \ _self ? NM_SUPPLICANT_INTERFACE_GET_PRIVATE(_self) : NULL; \ char _sbuf[255]; \ @@ -268,10 +270,10 @@ static NM80211ApSecurityFlags security_from_vardict(GVariant *security) { NM80211ApSecurityFlags flags = NM_802_11_AP_SEC_NONE; - const char ** array; - const char * tmp; + const char **array; + const char *tmp; gsize i; - const char * v; + const char *v; nm_assert(g_variant_is_of_type(security, G_VARIANT_TYPE_VARDICT)); @@ -339,13 +341,13 @@ security_from_vardict(GVariant *security) static void _dbus_connection_call(NMSupplicantInterface *self, - const char * interface_name, - const char * method_name, - GVariant * parameters, - const GVariantType * reply_type, + const char *interface_name, + const char *method_name, + GVariant *parameters, + const GVariantType *reply_type, GDBusCallFlags flags, int timeout_msec, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -368,13 +370,13 @@ _dbus_connection_call(NMSupplicantInterface *self, static void _dbus_connection_call_simple_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - NMSupplicantInterface *self; - gs_unref_variant GVariant *res = NULL; - gs_free_error GError *error = NULL; - const char * log_reason; - gs_free char * remote_error = NULL; - gpointer p_suppress_warning; - gboolean suppress_warning; + NMSupplicantInterface *self; + gs_unref_variant GVariant *res = NULL; + gs_free_error GError *error = NULL; + const char *log_reason; + gs_free char *remote_error = NULL; + gpointer p_suppress_warning; + gboolean suppress_warning; nm_utils_user_data_unpack(user_data, &self, &log_reason, &p_suppress_warning); @@ -403,11 +405,11 @@ _dbus_connection_call_simple_cb(GObject *source, GAsyncResult *result, gpointer static void _dbus_connection_call_simple_full_impl(NMSupplicantInterface *self, - const char * interface_name, - const char * method_name, - GVariant * parameters, - const GVariantType * reply_type, - const char * log_reason, + const char *interface_name, + const char *method_name, + GVariant *parameters, + const GVariantType *reply_type, + const char *log_reason, gboolean suppress_warning) { NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); @@ -457,7 +459,7 @@ _dbus_connection_call_simple_full_impl(NMSupplicantInterface *self, /*****************************************************************************/ static void -_emit_signal_state(NMSupplicantInterface * self, +_emit_signal_state(NMSupplicantInterface *self, NMSupplicantInterfaceState new_state, NMSupplicantInterfaceState old_state, gint32 disconnect_reason) @@ -476,7 +478,7 @@ static void _remove_network(NMSupplicantInterface *self) { NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); - gs_free char * net_path = NULL; + gs_free char *net_path = NULL; if (!priv->net_path) return; @@ -588,7 +590,7 @@ _bss_info_destroy(NMSupplicantBssInfo *bss_info) static void _bss_info_changed_emit(NMSupplicantInterface *self, - NMSupplicantBssInfo * bss_info, + NMSupplicantBssInfo *bss_info, gboolean is_present) { _LOGT("BSS %s %s", bss_info->bss_path->str, is_present ? "updated" : "deleted"); @@ -597,20 +599,20 @@ _bss_info_changed_emit(NMSupplicantInterface *self, static void _bss_info_properties_changed(NMSupplicantInterface *self, - NMSupplicantBssInfo * bss_info, - GVariant * properties, + NMSupplicantBssInfo *bss_info, + GVariant *properties, gboolean initial) { gboolean v_b; - GVariant * v_v; - const char * v_s; + GVariant *v_v; + const char *v_s; gint16 v_i16; guint16 v_u16; guint32 v_u32; NM80211ApFlags p_ap_flags; _NM80211Mode p_mode; guint8 p_signal_percent; - const guint8 * arr_data; + const guint8 *arr_data; gsize arr_len; guint32 p_max_rate; gboolean p_max_rate_has; @@ -786,10 +788,10 @@ _bss_info_properties_changed(NMSupplicantInterface *self, static void _bss_info_get_all_cb(GVariant *result, GError *error, gpointer user_data) { - NMSupplicantBssInfo * bss_info; - NMSupplicantInterface * self; + NMSupplicantBssInfo *bss_info; + NMSupplicantInterface *self; NMSupplicantInterfacePrivate *priv; - gs_unref_variant GVariant *properties = NULL; + gs_unref_variant GVariant *properties = NULL; if (nm_utils_error_is_cancelled(error)) return; @@ -814,9 +816,9 @@ _bss_info_get_all_cb(GVariant *result, GError *error, gpointer user_data) static void _bss_info_add(NMSupplicantInterface *self, const char *object_path) { - NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); + NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); nm_auto_ref_string NMRefString *bss_path = NULL; - NMSupplicantBssInfo * bss_info; + NMSupplicantBssInfo *bss_info; bss_path = nm_ref_string_new(nm_dbus_path_not_empty(object_path)); if (!bss_path) @@ -851,7 +853,7 @@ static gboolean _bss_info_remove(NMSupplicantInterface *self, NMRefString **p_bss_path) { NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); - NMSupplicantBssInfo * bss_info; + NMSupplicantBssInfo *bss_info; gpointer unused_but_required; if (!g_hash_table_steal_extended(priv->bss_idx, @@ -893,7 +895,7 @@ _peer_info_destroy(NMSupplicantPeerInfo *peer_info) static void _peer_info_changed_emit(NMSupplicantInterface *self, - NMSupplicantPeerInfo * peer_info, + NMSupplicantPeerInfo *peer_info, gboolean is_present) { g_signal_emit(self, signals[PEER_CHANGED], 0, peer_info, is_present); @@ -901,13 +903,13 @@ _peer_info_changed_emit(NMSupplicantInterface *self, static void _peer_info_properties_changed(NMSupplicantInterface *self, - NMSupplicantPeerInfo * peer_info, - GVariant * properties, + NMSupplicantPeerInfo *peer_info, + GVariant *properties, gboolean initial) { - GVariant * v_v; - const char * v_s; - const char ** v_strv; + GVariant *v_v; + const char *v_s; + const char **v_strv; gint32 v_i32; const guint8 *arr_data; gsize arr_len; @@ -985,10 +987,10 @@ _peer_info_properties_changed(NMSupplicantInterface *self, static void _peer_info_get_all_cb(GVariant *result, GError *error, gpointer user_data) { - NMSupplicantPeerInfo * peer_info; - NMSupplicantInterface * self; + NMSupplicantPeerInfo *peer_info; + NMSupplicantInterface *self; NMSupplicantInterfacePrivate *priv; - gs_unref_variant GVariant *properties = NULL; + gs_unref_variant GVariant *properties = NULL; if (nm_utils_error_is_cancelled(error)) return; @@ -1011,9 +1013,9 @@ _peer_info_get_all_cb(GVariant *result, GError *error, gpointer user_data) static void _peer_info_add(NMSupplicantInterface *self, const char *object_path) { - NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); + NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); nm_auto_ref_string NMRefString *peer_path = NULL; - NMSupplicantPeerInfo * peer_info; + NMSupplicantPeerInfo *peer_info; peer_path = nm_ref_string_new(nm_dbus_path_not_empty(object_path)); if (!peer_path) @@ -1049,7 +1051,7 @@ static gboolean _peer_info_remove(NMSupplicantInterface *self, NMRefString **p_peer_path) { NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); - NMSupplicantPeerInfo * peer_info; + NMSupplicantPeerInfo *peer_info; gpointer unused_but_required; if (!g_hash_table_steal_extended(priv->peer_idx, @@ -1073,12 +1075,12 @@ _peer_info_remove(NMSupplicantInterface *self, NMRefString **p_peer_path) static void set_state_down(NMSupplicantInterface *self, gboolean force_remove_from_supplicant, - const char * reason) + const char *reason) { _nm_unused gs_unref_object NMSupplicantInterface *self_keep_alive = g_object_ref(self); NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); - NMSupplicantBssInfo * bss_info; - NMSupplicantPeerInfo * peer_info; + NMSupplicantBssInfo *bss_info; + NMSupplicantPeerInfo *peer_info; NMSupplicantInterfaceState old_state; nm_assert(priv->state != NM_SUPPLICANT_INTERFACE_STATE_DOWN); @@ -1224,7 +1226,7 @@ parse_capabilities(NMSupplicantInterface *self, GVariant *capabilities) gboolean have_ft = FALSE; gboolean have_sae = FALSE; gint32 max_scan_ssids; - const char ** array; + const char **array; nm_assert(capabilities && g_variant_is_of_type(capabilities, G_VARIANT_TYPE_VARDICT)); @@ -1320,6 +1322,22 @@ _starting_check_ready(NMSupplicantInterface *self) NM_SUPPL_CAP_TO_CHAR(priv->iface_capabilities, NM_SUPPL_CAP_TYPE_FT), NM_SUPPL_CAP_TO_CHAR(priv->iface_capabilities, NM_SUPPL_CAP_TYPE_SAE)); + /* Other global properties are set in constructed() because they don't + * depend on interface capabilities. */ + if (_get_capability(priv, NM_SUPPL_CAP_TYPE_SAE) == NM_TERNARY_TRUE) { + _LOGD("enabling SAE-H2E (SaePwe=2)"); + nm_dbus_connection_call_set(priv->dbus_connection, + priv->name_owner->str, + priv->object_path->str, + NM_WPAS_DBUS_IFACE_INTERFACE, + "SaePwe", + g_variant_new_string("2"), + DBUS_TIMEOUT_MSEC, + NULL, + NULL, + NULL); + } + set_state(self, priv->supp_state); } @@ -1399,7 +1417,7 @@ set_bridge_cb(GVariant *ret, GError *error, gpointer user_data) { NMSupplicantInterface *self; NMLogLevel level; - gs_free const char * bridge = NULL; + gs_free const char *bridge = NULL; nm_utils_user_data_unpack(user_data, &self, &bridge); @@ -1462,7 +1480,7 @@ static void _p2p_group_properties_changed(NMSupplicantInterface *self, GVariant *properties) { NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); - const char * s; + const char *s; if (!properties) priv->p2p_group_owner_property = FALSE; @@ -1474,16 +1492,16 @@ _p2p_group_properties_changed(NMSupplicantInterface *self, GVariant *properties) static void _p2p_group_properties_changed_cb(GDBusConnection *connection, - const char * sender_name, - const char * object_path, - const char * signal_interface_name, - const char * signal_name, - GVariant * parameters, + const char *sender_name, + const char *object_path, + const char *signal_interface_name, + const char *signal_name, + GVariant *parameters, gpointer user_data) { - NMSupplicantInterface * self = NM_SUPPLICANT_INTERFACE(user_data); - NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); - gs_unref_variant GVariant *changed_properties = NULL; + NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE(user_data); + NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); + gs_unref_variant GVariant *changed_properties = NULL; if (priv->p2p_group_properties_cancellable) return; @@ -1498,9 +1516,9 @@ _p2p_group_properties_changed_cb(GDBusConnection *connection, static void _p2p_group_properties_get_all_cb(GVariant *result, GError *error, gpointer user_data) { - NMSupplicantInterface * self; + NMSupplicantInterface *self; NMSupplicantInterfacePrivate *priv; - gs_unref_variant GVariant *properties = NULL; + gs_unref_variant GVariant *properties = NULL; if (nm_utils_error_is_cancelled(error)) return; @@ -1527,7 +1545,7 @@ _p2p_group_properties_get_all_cb(GVariant *result, GError *error, gpointer user_ static void _p2p_group_set_path(NMSupplicantInterface *self, const char *path) { - NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); + NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); nm_auto_ref_string NMRefString *group_path = NULL; group_path = nm_ref_string_new(nm_dbus_path_not_empty(path)); @@ -1583,14 +1601,14 @@ _wps_data_free(WpsData *wps_data, GDBusConnection *dbus_connection) static void _wps_credentials_changed_cb(GDBusConnection *connection, - const char * sender_name, - const char * object_path, - const char * signal_interface_name, - const char * signal_name, - GVariant * parameters, + const char *sender_name, + const char *object_path, + const char *signal_interface_name, + const char *signal_name, + GVariant *parameters, gpointer user_data) { - NMSupplicantInterface *self = user_data; + NMSupplicantInterface *self = user_data; gs_unref_variant GVariant *props = NULL; if (!g_variant_is_of_type(parameters, G_VARIANT_TYPE("(a{sv})"))) @@ -1605,10 +1623,10 @@ _wps_credentials_changed_cb(GDBusConnection *connection, static void _wps_handle_start_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - NMSupplicantInterface *self; - WpsData * wps_data; - gs_unref_variant GVariant *res = NULL; - gs_free_error GError *error = NULL; + NMSupplicantInterface *self; + WpsData *wps_data; + gs_unref_variant GVariant *res = NULL; + gs_free_error GError *error = NULL; res = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), result, &error); if (nm_utils_error_is_cancelled(error)) @@ -1631,9 +1649,9 @@ _wps_handle_start_cb(GObject *source, GAsyncResult *result, gpointer user_data) static void _wps_handle_set_pc_cb(GVariant *res, GError *error, gpointer user_data) { - NMSupplicantInterface * self; + NMSupplicantInterface *self; NMSupplicantInterfacePrivate *priv; - WpsData * wps_data; + WpsData *wps_data; GVariantBuilder start_args; guint8 bssid_buf[ETH_ALEN]; @@ -1715,12 +1733,12 @@ _wps_call_set_pc(NMSupplicantInterface *self, WpsData *wps_data) static void _wps_handle_cancel_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - GDBusConnection * dbus_connection = G_DBUS_CONNECTION(source); - NMSupplicantInterface * self; + GDBusConnection *dbus_connection = G_DBUS_CONNECTION(source); + NMSupplicantInterface *self; NMSupplicantInterfacePrivate *priv; - WpsData * wps_data; - gs_unref_variant GVariant *res = NULL; - gs_free_error GError *error = NULL; + WpsData *wps_data; + gs_unref_variant GVariant *res = NULL; + gs_free_error GError *error = NULL; res = g_dbus_connection_call_finish(dbus_connection, result, &error); nm_assert(!nm_utils_error_is_cancelled(error)); @@ -1763,7 +1781,7 @@ static void _wps_start(NMSupplicantInterface *self, const char *type, const char *bssid, const char *pin) { NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); - WpsData * wps_data; + WpsData *wps_data; if (type) _LOGI("wps: type %s start...", type); @@ -1828,9 +1846,9 @@ _wps_start(NMSupplicantInterface *self, const char *type, const char *bssid, con void nm_supplicant_interface_enroll_wps(NMSupplicantInterface *self, - const char * type, - const char * bssid, - const char * pin) + const char *type, + const char *bssid, + const char *pin) { _wps_start(self, type, bssid, pin); } @@ -1846,12 +1864,12 @@ nm_supplicant_interface_cancel_wps(NMSupplicantInterface *self) static void iface_introspect_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - NMSupplicantInterface * self; + NMSupplicantInterface *self; NMSupplicantInterfacePrivate *priv; - gs_unref_variant GVariant *res = NULL; - gs_free_error GError *error = NULL; - const char * data; - NMTernary value; + gs_unref_variant GVariant *res = NULL; + gs_free_error GError *error = NULL; + const char *data; + NMTernary value; res = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), result, &error); if (nm_utils_error_is_cancelled(error)) @@ -1882,11 +1900,11 @@ static void _properties_changed_main(NMSupplicantInterface *self, GVariant *properties) { NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); - const char ** v_strv; - const char * v_s; + const char **v_strv; + const char *v_s; gboolean v_b; gint32 v_i32; - GVariant * v_v; + GVariant *v_v; gboolean do_log_driver_info = FALSE; gboolean do_set_state = FALSE; gboolean do_notify_current_bss = FALSE; @@ -1951,11 +1969,8 @@ _properties_changed_main(NMSupplicantInterface *self, GVariant *properties) if (nm_g_variant_lookup(properties, "CurrentBSS", "&o", &v_s)) { v_s = nm_dbus_path_not_empty(v_s); - if (!nm_ref_string_equal_str(priv->current_bss, v_s)) { - nm_ref_string_unref(priv->current_bss); - priv->current_bss = nm_ref_string_new(v_s); + if (nm_ref_string_reset_str(&priv->current_bss, v_s)) do_notify_current_bss = TRUE; - } } if (nm_g_variant_lookup(properties, "ApIsolate", "&s", &v_s)) @@ -1972,7 +1987,7 @@ _properties_changed_main(NMSupplicantInterface *self, GVariant *properties) if (nm_g_variant_lookup(properties, "BSSs", "^a&o", &v_strv)) { NMSupplicantBssInfo *bss_info; NMSupplicantBssInfo *bss_info_safe; - const char ** iter; + const char **iter; c_list_for_each_entry (bss_info, &priv->bss_lst_head, _bss_lst) bss_info->_bss_dirty = TRUE; @@ -2010,15 +2025,15 @@ static void _properties_changed_p2p_device(NMSupplicantInterface *self, GVariant *properties) { NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); - const char ** v_strv; - const char * v_s; + const char **v_strv; + const char *v_s; nm_assert(!properties || g_variant_is_of_type(properties, G_VARIANT_TYPE("a{sv}"))); if (nm_g_variant_lookup(properties, "Peers", "^a&o", &v_strv)) { NMSupplicantPeerInfo *peer_info; NMSupplicantPeerInfo *peer_info_safe; - const char *const * iter; + const char *const *iter; c_list_for_each_entry (peer_info, &priv->peer_lst_head, _peer_lst) peer_info->_peer_dirty = TRUE; @@ -2053,7 +2068,7 @@ static void assoc_return(NMSupplicantInterface *self, GError *error, const char *message) { NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); - AssocData * assoc_data; + AssocData *assoc_data; assoc_data = g_steal_pointer(&priv->assoc_data); if (!assoc_data) @@ -2122,11 +2137,11 @@ nm_supplicant_interface_disconnect(NMSupplicantInterface *self) static void disconnect_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - gs_unref_object NMSupplicantInterface *self = NULL; - gs_unref_variant GVariant *res = NULL; - gs_free_error GError * error = NULL; - NMSupplicantInterfaceDisconnectCb callback; - gpointer callback_user_data; + gs_unref_object NMSupplicantInterface *self = NULL; + gs_unref_variant GVariant *res = NULL; + gs_free_error GError *error = NULL; + NMSupplicantInterfaceDisconnectCb callback; + gpointer callback_user_data; nm_utils_user_data_unpack(user_data, &self, &callback, &callback_user_data); @@ -2141,8 +2156,8 @@ disconnect_cb(GObject *source, GAsyncResult *result, gpointer user_data) } void -nm_supplicant_interface_disconnect_async(NMSupplicantInterface * self, - GCancellable * cancellable, +nm_supplicant_interface_disconnect_async(NMSupplicantInterface *self, + GCancellable *cancellable, NMSupplicantInterfaceDisconnectCb callback, gpointer user_data) { @@ -2164,9 +2179,9 @@ nm_supplicant_interface_disconnect_async(NMSupplicantInterface * self, static void assoc_select_network_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - NMSupplicantInterface *self; - gs_unref_variant GVariant *res = NULL; - gs_free_error GError *error = NULL; + NMSupplicantInterface *self; + gs_unref_variant GVariant *res = NULL; + gs_free_error GError *error = NULL; res = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), result, &error); if (nm_utils_error_is_cancelled(error)) @@ -2199,10 +2214,10 @@ assoc_call_select_network(NMSupplicantInterface *self) static void assoc_add_blob_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - NMSupplicantInterface * self; + NMSupplicantInterface *self; NMSupplicantInterfacePrivate *priv; - gs_unref_variant GVariant *res = NULL; - gs_free_error GError *error = NULL; + gs_unref_variant GVariant *res = NULL; + gs_free_error GError *error = NULL; res = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), result, &error); if (nm_utils_error_is_cancelled(error)) @@ -2227,16 +2242,16 @@ assoc_add_blob_cb(GObject *source, GAsyncResult *result, gpointer user_data) static void assoc_add_network_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - AddNetworkData * add_network_data = user_data; - AssocData * assoc_data; - NMSupplicantInterface * self; - NMSupplicantInterfacePrivate *priv; - gs_unref_variant GVariant *res = NULL; - gs_free_error GError *error = NULL; - GHashTable * blobs; - GHashTableIter iter; - const char * blob_name; - GBytes * blob_data; + AddNetworkData *add_network_data = user_data; + AssocData *assoc_data; + NMSupplicantInterface *self; + NMSupplicantInterfacePrivate *priv; + gs_unref_variant GVariant *res = NULL; + gs_free_error GError *error = NULL; + GHashTable *blobs; + GHashTableIter iter; + const char *blob_name; + GBytes *blob_data; nm_auto_ref_string NMRefString *name_owner = NULL; nm_auto_ref_string NMRefString *object_path = NULL; @@ -2322,7 +2337,7 @@ static void add_network(NMSupplicantInterface *self) { NMSupplicantInterfacePrivate *priv; - AddNetworkData * add_network_data; + AddNetworkData *add_network_data; priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); @@ -2359,7 +2374,7 @@ add_network(NMSupplicantInterface *self) static void assoc_set_ap_isolation(GVariant *ret, GError *error, gpointer user_data) { - NMSupplicantInterface * self; + NMSupplicantInterface *self; NMSupplicantInterfacePrivate *priv; gboolean value; @@ -2389,7 +2404,7 @@ assoc_set_ap_isolation(GVariant *ret, GError *error, gpointer user_data) static void assoc_set_ap_scan_cb(GVariant *ret, GError *error, gpointer user_data) { - NMSupplicantInterface * self; + NMSupplicantInterface *self; NMSupplicantInterfacePrivate *priv; if (nm_utils_error_is_cancelled(error)) @@ -2415,9 +2430,9 @@ assoc_set_ap_scan_cb(GVariant *ret, GError *error, gpointer user_data) static gboolean assoc_fail_on_idle_cb(gpointer user_data) { - NMSupplicantInterface * self = user_data; - NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); - gs_free_error GError *error = NULL; + NMSupplicantInterface *self = user_data; + NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); + gs_free_error GError *error = NULL; priv->assoc_data->fail_on_idle_id = 0; g_set_error(&error, @@ -2443,13 +2458,13 @@ assoc_fail_on_idle_cb(gpointer user_data) * an error reason indicating cancellation/disposing (see nm_utils_error_is_cancelled()). */ void -nm_supplicant_interface_assoc(NMSupplicantInterface * self, - NMSupplicantConfig * cfg, +nm_supplicant_interface_assoc(NMSupplicantInterface *self, + NMSupplicantConfig *cfg, NMSupplicantInterfaceAssocCb callback, gpointer user_data) { NMSupplicantInterfacePrivate *priv; - AssocData * assoc_data; + AssocData *assoc_data; gboolean ap_isolation; g_return_if_fail(NM_IS_SUPPLICANT_INTERFACE(self)); @@ -2525,8 +2540,8 @@ nm_supplicant_interface_assoc(NMSupplicantInterface * self, /*****************************************************************************/ typedef struct { - NMSupplicantInterface * self; - GCancellable * cancellable; + NMSupplicantInterface *self; + GCancellable *cancellable; NMSupplicantInterfaceRequestScanCallback callback; gpointer user_data; } ScanRequestData; @@ -2535,11 +2550,11 @@ static void scan_request_cb(GObject *source, GAsyncResult *result, gpointer user_data) { gs_unref_object NMSupplicantInterface *self_keep_alive = NULL; - NMSupplicantInterface * self; - gs_unref_variant GVariant *res = NULL; - gs_free_error GError *error = NULL; - ScanRequestData * data = user_data; - gboolean cancelled = FALSE; + NMSupplicantInterface *self; + gs_unref_variant GVariant *res = NULL; + gs_free_error GError *error = NULL; + ScanRequestData *data = user_data; + gboolean cancelled = FALSE; res = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), result, &error); if (nm_utils_error_is_cancelled(error)) { @@ -2583,16 +2598,16 @@ scan_request_cb(GObject *source, GAsyncResult *result, gpointer user_data) } void -nm_supplicant_interface_request_scan(NMSupplicantInterface * self, - GBytes *const * ssids, +nm_supplicant_interface_request_scan(NMSupplicantInterface *self, + GBytes *const *ssids, guint ssids_len, - GCancellable * cancellable, + GCancellable *cancellable, NMSupplicantInterfaceRequestScanCallback callback, gpointer user_data) { NMSupplicantInterfacePrivate *priv; GVariantBuilder builder; - ScanRequestData * data; + ScanRequestData *data; guint i; g_return_if_fail(NM_IS_SUPPLICANT_INTERFACE(self)); @@ -2662,7 +2677,7 @@ nm_supplicant_interface_get_state(NMSupplicantInterface *self) void _nm_supplicant_interface_set_state_down(NMSupplicantInterface *self, gboolean force_remove_from_supplicant, - const char * reason) + const char *reason) { set_state_down(self, force_remove_from_supplicant, reason); } @@ -2740,9 +2755,9 @@ nm_supplicant_interface_p2p_stop_find(NMSupplicantInterface *self) void nm_supplicant_interface_p2p_connect(NMSupplicantInterface *self, - const char * peer, - const char * wps_method, - const char * wps_pin) + const char *peer, + const char *wps_method, + const char *wps_pin) { GVariantBuilder builder; @@ -2797,8 +2812,8 @@ nm_supplicant_interface_p2p_disconnect(NMSupplicantInterface *self) static void _properties_changed(NMSupplicantInterface *self, - const char * interface_name, - GVariant * properties, + const char *interface_name, + GVariant *properties, gboolean initial) { NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); @@ -2841,15 +2856,15 @@ _properties_changed(NMSupplicantInterface *self, static void _properties_changed_cb(GDBusConnection *connection, - const char * sender_name, - const char * object_path, - const char * signal_interface_name, - const char * signal_name, - GVariant * parameters, + const char *sender_name, + const char *object_path, + const char *signal_interface_name, + const char *signal_name, + GVariant *parameters, gpointer user_data) { - NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE(user_data); - const char * interface_name; + NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE(user_data); + const char *interface_name; gs_unref_variant GVariant *changed_properties = NULL; if (!g_variant_is_of_type(parameters, G_VARIANT_TYPE("(sa{sv}as)"))) @@ -2861,18 +2876,18 @@ _properties_changed_cb(GDBusConnection *connection, static void _bss_properties_changed_cb(GDBusConnection *connection, - const char * sender_name, - const char * object_path, - const char * signal_interface_name, - const char * signal_name, - GVariant * parameters, + const char *sender_name, + const char *object_path, + const char *signal_interface_name, + const char *signal_name, + GVariant *parameters, gpointer user_data) { - NMSupplicantInterface * self = NM_SUPPLICANT_INTERFACE(user_data); - NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); - nm_auto_ref_string NMRefString *bss_path = NULL; - gs_unref_variant GVariant *changed_properties = NULL; - NMSupplicantBssInfo * bss_info; + NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE(user_data); + NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); + nm_auto_ref_string NMRefString *bss_path = NULL; + gs_unref_variant GVariant *changed_properties = NULL; + NMSupplicantBssInfo *bss_info; if (!g_variant_is_of_type(parameters, G_VARIANT_TYPE("(sa{sv}as)"))) return; @@ -2891,18 +2906,18 @@ _bss_properties_changed_cb(GDBusConnection *connection, static void _peer_properties_changed_cb(GDBusConnection *connection, - const char * sender_name, - const char * object_path, - const char * signal_interface_name, - const char * signal_name, - GVariant * parameters, + const char *sender_name, + const char *object_path, + const char *signal_interface_name, + const char *signal_name, + GVariant *parameters, gpointer user_data) { - NMSupplicantInterface * self = NM_SUPPLICANT_INTERFACE(user_data); - NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); - nm_auto_ref_string NMRefString *peer_path = NULL; - gs_unref_variant GVariant *changed_properties = NULL; - NMSupplicantPeerInfo * peer_info; + NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE(user_data); + NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); + nm_auto_ref_string NMRefString *peer_path = NULL; + gs_unref_variant GVariant *changed_properties = NULL; + NMSupplicantPeerInfo *peer_info; if (!g_variant_is_of_type(parameters, G_VARIANT_TYPE("(sa{sv}as)"))) return; @@ -2956,12 +2971,12 @@ _set_p2p_assigned_addr(NMSupplicantInterface *self, gconstpointer addr, guint8 p static void _signal_handle(NMSupplicantInterface *self, - const char * signal_interface_name, - const char * signal_name, - GVariant * parameters) + const char *signal_interface_name, + const char *signal_name, + GVariant *parameters) { NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); - const char * path; + const char *path; if (nm_streq(signal_interface_name, NM_WPAS_DBUS_IFACE_INTERFACE)) { if (!priv->is_ready_main) @@ -2990,8 +3005,8 @@ _signal_handle(NMSupplicantInterface *self, if (nm_streq(signal_name, "EAP")) { NMSupplicantAuthState auth_state = NM_SUPPLICANT_AUTH_STATE_UNKNOWN; - const char * status; - const char * parameter; + const char *status; + const char *parameter; if (g_variant_is_of_type(parameters, G_VARIANT_TYPE("(ss)"))) return; @@ -3044,11 +3059,11 @@ _signal_handle(NMSupplicantInterface *self, if (nm_streq(signal_name, "GroupStarted")) { if (g_variant_is_of_type(parameters, G_VARIANT_TYPE("(a{sv})"))) { - gs_unref_variant GVariant *args = NULL; + gs_unref_variant GVariant *args = NULL; gs_unref_object NMSupplicantInterface *iface = NULL; - const char * group_path; - const char * iface_path; - GVariant * v_v = NULL; + const char *group_path; + const char *iface_path; + GVariant *v_v = NULL; g_variant_get(parameters, "(@a{sv})", &args); if (!g_variant_lookup(args, "group_object", "&o", &group_path)) @@ -3107,7 +3122,7 @@ _signal_handle(NMSupplicantInterface *self, if (nm_streq(signal_name, "GroupFinished")) { if (g_variant_is_of_type(parameters, G_VARIANT_TYPE("(a{sv})"))) { gs_unref_variant GVariant *args = NULL; - const char * iface_path; + const char *iface_path; g_variant_get(parameters, "(@a{sv})", &args); @@ -3134,14 +3149,14 @@ _signal_handle(NMSupplicantInterface *self, static void _signal_cb(GDBusConnection *connection, - const char * sender_name, - const char * object_path, - const char * signal_interface_name, - const char * signal_name, - GVariant * parameters, + const char *sender_name, + const char *object_path, + const char *signal_interface_name, + const char *signal_name, + GVariant *parameters, gpointer user_data) { - NMSupplicantInterface * self = user_data; + NMSupplicantInterface *self = user_data; NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); priv->starting_pending_count++; @@ -3180,8 +3195,8 @@ nm_supplicant_interface_get_p2p_group_owner(NMSupplicantInterface *self) gboolean nm_supplicant_interface_get_p2p_assigned_addr(NMSupplicantInterface *self, - in_addr_t * addr, - guint8 * plen) + in_addr_t *addr, + guint8 *plen) { NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); @@ -3201,7 +3216,7 @@ nm_supplicant_interface_get_p2p_assigned_addr(NMSupplicantInterface *self, static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMSupplicantInterface * self = NM_SUPPLICANT_INTERFACE(object); + NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE(object); NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); switch (prop_id) { @@ -3314,7 +3329,7 @@ nm_supplicant_interface_init(NMSupplicantInterface *self) static void constructed(GObject *object) { - NMSupplicantInterface * self = NM_SUPPLICANT_INTERFACE(object); + NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE(object); NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); G_OBJECT_CLASS(nm_supplicant_interface_parent_class)->constructed(object); @@ -3439,7 +3454,7 @@ constructed(GObject *object) NMSupplicantInterface * nm_supplicant_interface_new(NMSupplicantManager *supplicant_manager, - NMRefString * object_path, + NMRefString *object_path, int ifindex, NMSupplicantDriver driver) { @@ -3460,7 +3475,7 @@ nm_supplicant_interface_new(NMSupplicantManager *supplicant_manager, static void dispose(GObject *object) { - NMSupplicantInterface * self = NM_SUPPLICANT_INTERFACE(object); + NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE(object); NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE(self); if (priv->state != NM_SUPPLICANT_INTERFACE_STATE_DOWN) diff --git a/src/core/supplicant/nm-supplicant-interface.h b/src/core/supplicant/nm-supplicant-interface.h index 4c5d8f64..5ccb455c 100644 --- a/src/core/supplicant/nm-supplicant-interface.h +++ b/src/core/supplicant/nm-supplicant-interface.h @@ -100,7 +100,7 @@ struct _NMSupplicantInterface { GType nm_supplicant_interface_get_type(void); NMSupplicantInterface *nm_supplicant_interface_new(NMSupplicantManager *supplicant_manager, - NMRefString * object_path, + NMRefString *object_path, int ifindex, NMSupplicantDriver driver); @@ -109,36 +109,36 @@ NMRefString *nm_supplicant_interface_get_object_path(NMSupplicantInterface *ifac void _nm_supplicant_interface_set_state_down(NMSupplicantInterface *self, gboolean force_remove_from_supplicant, - const char * reason); + const char *reason); typedef void (*NMSupplicantInterfaceAssocCb)(NMSupplicantInterface *iface, - GError * error, + GError *error, gpointer user_data); -void nm_supplicant_interface_assoc(NMSupplicantInterface * self, - NMSupplicantConfig * cfg, +void nm_supplicant_interface_assoc(NMSupplicantInterface *self, + NMSupplicantConfig *cfg, NMSupplicantInterfaceAssocCb callback, gpointer user_data); void nm_supplicant_interface_disconnect(NMSupplicantInterface *iface); typedef void (*NMSupplicantInterfaceDisconnectCb)(NMSupplicantInterface *iface, - GError * error, + GError *error, gpointer user_data); -void nm_supplicant_interface_disconnect_async(NMSupplicantInterface * self, - GCancellable * cancellable, +void nm_supplicant_interface_disconnect_async(NMSupplicantInterface *self, + GCancellable *cancellable, NMSupplicantInterfaceDisconnectCb callback, gpointer user_data); typedef void (*NMSupplicantInterfaceRequestScanCallback)(NMSupplicantInterface *self, - GCancellable * cancellable, + GCancellable *cancellable, gpointer user_data); -void nm_supplicant_interface_request_scan(NMSupplicantInterface * self, - GBytes *const * ssids, +void nm_supplicant_interface_request_scan(NMSupplicantInterface *self, + GBytes *const *ssids, guint ssids_len, - GCancellable * cancellable, + GCancellable *cancellable, NMSupplicantInterfaceRequestScanCallback callback, gpointer user_data); @@ -165,16 +165,16 @@ const char *nm_supplicant_interface_get_p2p_group_path(NMSupplicantInterface *se gboolean nm_supplicant_interface_get_p2p_group_owner(NMSupplicantInterface *self); gboolean nm_supplicant_interface_get_p2p_assigned_addr(NMSupplicantInterface *self, - in_addr_t * assigned_addr, - guint8 * plen); + in_addr_t *assigned_addr, + guint8 *plen); void nm_supplicant_interface_p2p_start_find(NMSupplicantInterface *self, guint timeout); void nm_supplicant_interface_p2p_stop_find(NMSupplicantInterface *self); void nm_supplicant_interface_p2p_connect(NMSupplicantInterface *self, - const char * peer, - const char * wps_method, - const char * wps_pin); + const char *peer, + const char *wps_method, + const char *wps_pin); void nm_supplicant_interface_p2p_cancel_connect(NMSupplicantInterface *self); void nm_supplicant_interface_p2p_disconnect(NMSupplicantInterface *self); @@ -187,8 +187,8 @@ NMSupplCapMask nm_supplicant_interface_get_capabilities(NMSupplicantInterface *s void nm_supplicant_interface_enroll_wps(NMSupplicantInterface *self, const char *const type, - const char * bssid, - const char * pin); + const char *bssid, + const char *pin); void nm_supplicant_interface_cancel_wps(NMSupplicantInterface *self); diff --git a/src/core/supplicant/nm-supplicant-manager.c b/src/core/supplicant/nm-supplicant-manager.c index 52beae78..1f8f0105 100644 --- a/src/core/supplicant/nm-supplicant-manager.c +++ b/src/core/supplicant/nm-supplicant-manager.c @@ -21,14 +21,14 @@ #define CREATE_IFACE_TRY_COUNT_MAX 7u struct _NMSupplMgrCreateIfaceHandle { - NMSupplicantManager * self; + NMSupplicantManager *self; CList create_iface_lst; - GCancellable * cancellable; + GCancellable *cancellable; NMSupplicantManagerCreateInterfaceCb callback; gpointer callback_user_data; - NMShutdownWaitObjHandle * shutdown_handle; - NMRefString * name_owner; - GError * fail_on_idle_error; + NMShutdownWaitObjHandle *shutdown_handle; + NMRefString *name_owner; + GError *fail_on_idle_error; NMSupplicantDriver driver; int ifindex; guint fail_on_idle_id; @@ -98,19 +98,19 @@ NM_CACHED_QUARK_FCN("nm-supplicant-error-quark", nm_supplicant_error_quark); /*****************************************************************************/ static void _create_iface_proceed_all(NMSupplicantManager *self, GError *error); -static void _supp_iface_add(NMSupplicantManager * self, - NMRefString * iface_path, +static void _supp_iface_add(NMSupplicantManager *self, + NMRefString *iface_path, NMSupplicantInterface *supp_iface); -static void _supp_iface_remove_one(NMSupplicantManager * self, +static void _supp_iface_remove_one(NMSupplicantManager *self, NMSupplicantInterface *supp_iface, gboolean force_remove_from_supplicant, - const char * reason); -static void _create_iface_dbus_call_get_interface(NMSupplicantManager * self, + const char *reason); +static void _create_iface_dbus_call_get_interface(NMSupplicantManager *self, NMSupplMgrCreateIfaceHandle *handle, - const char * ifname); -static void _create_iface_dbus_call_create_interface(NMSupplicantManager * self, + const char *ifname); +static void _create_iface_dbus_call_create_interface(NMSupplicantManager *self, NMSupplMgrCreateIfaceHandle *handle, - const char * ifname); + const char *ifname); static gboolean _create_iface_fail_on_idle_cb(gpointer user_data); static gboolean _available_reset_cb(gpointer user_data); @@ -172,8 +172,8 @@ _caps_set(NMSupplicantManagerPrivate *priv, NMSupplCapType type, NMTernary value static void _dbus_call_remove_interface(GDBusConnection *dbus_connection, - const char * name_owner, - const char * iface_path) + const char *name_owner, + const char *iface_path) { nm_assert(G_IS_DBUS_CONNECTION(dbus_connection)); nm_assert(name_owner); @@ -195,8 +195,8 @@ _dbus_call_remove_interface(GDBusConnection *dbus_connection, void _nm_supplicant_manager_dbus_call_remove_interface(NMSupplicantManager *self, - const char * name_owner, - const char * iface_path) + const char *name_owner, + const char *iface_path) { _dbus_call_remove_interface(NM_SUPPLICANT_MANAGER_GET_PRIVATE(self)->dbus_connection, name_owner, @@ -208,8 +208,8 @@ _nm_supplicant_manager_dbus_call_remove_interface(NMSupplicantManager *self, static void on_supplicant_wfd_ies_set(GObject *source_object, GAsyncResult *result, gpointer user_data) { - gs_unref_variant GVariant *res = NULL; - gs_free_error GError *error = NULL; + gs_unref_variant GVariant *res = NULL; + gs_free_error GError *error = NULL; res = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source_object), result, &error); if (!res) @@ -265,10 +265,10 @@ nm_supplicant_manager_set_wfd_ies(NMSupplicantManager *self, GBytes *wfd_ies) static gboolean _poke_name_owner_timeout_cb(gpointer user_data) { - NMSupplicantManager * self = user_data; - NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE(self); - gs_free_error GError *error = NULL; - gboolean available_changed = FALSE; + NMSupplicantManager *self = user_data; + NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE(self); + gs_free_error GError *error = NULL; + gboolean available_changed = FALSE; nm_assert(!priv->name_owner); @@ -307,8 +307,8 @@ _poke_name_owner_timeout_cb(gpointer user_data) static void _poke_name_owner_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - gs_unref_variant GVariant *res = NULL; - gs_free_error GError *error = NULL; + gs_unref_variant GVariant *res = NULL; + gs_free_error GError *error = NULL; res = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), result, &error); if (nm_utils_error_is_cancelled(error)) @@ -347,8 +347,8 @@ _poke_name_owner(NMSupplicantManager *self) static void _create_iface_complete(NMSupplMgrCreateIfaceHandle *handle, - NMSupplicantInterface * supp_iface, - GError * error) + NMSupplicantInterface *supp_iface, + GError *error) { nm_assert(!supp_iface || NM_IS_SUPPLICANT_INTERFACE(supp_iface)); nm_assert((!!supp_iface) != (!!error)); @@ -385,13 +385,13 @@ _create_iface_complete(NMSupplMgrCreateIfaceHandle *handle, } static void -_create_iface_add(NMSupplicantManager * self, +_create_iface_add(NMSupplicantManager *self, NMSupplMgrCreateIfaceHandle *handle, - const char * iface_path_str, + const char *iface_path_str, gboolean created_by_us) { - NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE(self); - nm_auto_ref_string NMRefString *iface_path = NULL; + NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE(self); + nm_auto_ref_string NMRefString *iface_path = NULL; gs_unref_object NMSupplicantInterface *supp_iface = NULL; iface_path = nm_ref_string_new(iface_path_str); @@ -425,13 +425,13 @@ _create_iface_add(NMSupplicantManager * self, static void _create_iface_dbus_call_get_interface_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - GDBusConnection * dbus_connection = G_DBUS_CONNECTION(source); + GDBusConnection *dbus_connection = G_DBUS_CONNECTION(source); NMSupplMgrCreateIfaceHandle *handle; - NMSupplicantManager * self; - NMSupplicantManagerPrivate * priv; - gs_unref_variant GVariant *res = NULL; - gs_free_error GError *error = NULL; - const char * iface_path_str; + NMSupplicantManager *self; + NMSupplicantManagerPrivate *priv; + gs_unref_variant GVariant *res = NULL; + gs_free_error GError *error = NULL; + const char *iface_path_str; res = g_dbus_connection_call_finish(dbus_connection, result, &error); @@ -478,18 +478,18 @@ _create_iface_dbus_call_get_interface_cb(GObject *source, GAsyncResult *result, } static void -_create_iface_dbus_call_create_interface_cb(GObject * source, +_create_iface_dbus_call_create_interface_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - GDBusConnection * dbus_connection = G_DBUS_CONNECTION(source); + GDBusConnection *dbus_connection = G_DBUS_CONNECTION(source); NMSupplMgrCreateIfaceHandle *handle = user_data; - NMSupplicantManager * self; - NMSupplicantManagerPrivate * priv; - gs_unref_variant GVariant *res = NULL; - gs_free_error GError *error = NULL; - const char * iface_path_str; - char ifname[NMP_IFNAMSIZ]; + NMSupplicantManager *self; + NMSupplicantManagerPrivate *priv; + gs_unref_variant GVariant *res = NULL; + gs_free_error GError *error = NULL; + const char *iface_path_str; + char ifname[NMP_IFNAMSIZ]; res = g_dbus_connection_call_finish(dbus_connection, result, &error); @@ -553,9 +553,9 @@ _create_iface_dbus_call_create_interface_cb(GObject * source, } static void -_create_iface_dbus_call_get_interface(NMSupplicantManager * self, +_create_iface_dbus_call_get_interface(NMSupplicantManager *self, NMSupplMgrCreateIfaceHandle *handle, - const char * ifname) + const char *ifname) { NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE(self); @@ -577,9 +577,9 @@ _create_iface_dbus_call_get_interface(NMSupplicantManager * self, } static void -_create_iface_dbus_call_create_interface(NMSupplicantManager * self, +_create_iface_dbus_call_create_interface(NMSupplicantManager *self, NMSupplMgrCreateIfaceHandle *handle, - const char * ifname) + const char *ifname) { NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE(self); GVariantBuilder builder; @@ -676,13 +676,13 @@ _create_iface_fail_on_idle_cb(gpointer user_data) } NMSupplMgrCreateIfaceHandle * -nm_supplicant_manager_create_interface(NMSupplicantManager * self, +nm_supplicant_manager_create_interface(NMSupplicantManager *self, int ifindex, NMSupplicantDriver driver, NMSupplicantManagerCreateInterfaceCb callback, gpointer user_data) { - NMSupplicantManagerPrivate * priv; + NMSupplicantManagerPrivate *priv; NMSupplMgrCreateIfaceHandle *handle; g_return_val_if_fail(NM_IS_SUPPLICANT_MANAGER(self), NULL); @@ -751,7 +751,7 @@ nm_supplicant_manager_create_interface(NMSupplicantManager * self static void _create_iface_proceed_all(NMSupplicantManager *self, GError *error) { - NMSupplicantManagerPrivate * priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE(self); + NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE(self); NMSupplMgrCreateIfaceHandle *handle; nm_assert(error || priv->name_owner); @@ -810,8 +810,8 @@ nm_supplicant_manager_create_interface_cancel(NMSupplMgrCreateIfaceHandle *handl NMSupplicantInterface * nm_supplicant_manager_create_interface_from_path(NMSupplicantManager *self, const char *object_path) { - NMSupplicantManagerPrivate *priv; - NMSupplicantInterface * supp_iface; + NMSupplicantManagerPrivate *priv; + NMSupplicantInterface *supp_iface; nm_auto_ref_string NMRefString *iface_path = NULL; g_return_val_if_fail(NM_IS_SUPPLICANT_MANAGER(self), NULL); @@ -837,17 +837,17 @@ nm_supplicant_manager_create_interface_from_path(NMSupplicantManager *self, cons static void _dbus_interface_removed_cb(GDBusConnection *connection, - const char * sender_name, - const char * object_path, - const char * signal_interface_name, - const char * signal_name, - GVariant * parameters, + const char *sender_name, + const char *object_path, + const char *signal_interface_name, + const char *signal_name, + GVariant *parameters, gpointer user_data) { - NMSupplicantManager * self = user_data; - NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE(self); - NMSupplicantInterface * supp_iface; - const char * iface_path_str; + NMSupplicantManager *self = user_data; + NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE(self); + NMSupplicantInterface *supp_iface; + const char *iface_path_str; nm_auto_ref_string NMRefString *iface_path = NULL; nm_assert(nm_streq(sender_name, priv->name_owner->str)); @@ -871,7 +871,7 @@ _dbus_interface_removed_cb(GDBusConnection *connection, static void _dbus_get_capabilities_cb(GVariant *res, GError *error, gpointer user_data) { - NMSupplicantManager * self; + NMSupplicantManager *self; NMSupplicantManagerPrivate *priv; if (nm_utils_error_is_cancelled(error)) @@ -905,15 +905,15 @@ _dbus_get_capabilities_cb(GVariant *res, GError *error, gpointer user_data) if (res) { nm_auto_free_variant_iter GVariantIter *res_iter = NULL; - const char * res_key; - GVariant * res_val; + const char *res_key; + GVariant *res_val; g_variant_get(res, "(a{sv})", &res_iter); while (g_variant_iter_loop(res_iter, "{&sv}", &res_key, &res_val)) { if (nm_streq(res_key, "Capabilities")) { if (g_variant_is_of_type(res_val, G_VARIANT_TYPE_STRING_ARRAY)) { gs_free const char **array = NULL; - const char ** a; + const char **a; array = g_variant_get_strv(res_val, NULL); _caps_set(priv, NM_SUPPL_CAP_TYPE_AP, NM_TERNARY_FALSE); @@ -962,7 +962,7 @@ _dbus_get_capabilities_cb(GVariant *res, GError *error, gpointer user_data) if (nm_streq(res_key, "EapMethods")) { if (g_variant_is_of_type(res_val, G_VARIANT_TYPE_STRING_ARRAY)) { gs_free const char **array = NULL; - const char ** a; + const char **a; array = g_variant_get_strv(res_val, NULL); if (array) { @@ -1013,7 +1013,7 @@ _dbus_get_capabilities_cb(GVariant *res, GError *error, gpointer user_data) /*****************************************************************************/ void -_nm_supplicant_manager_unregister_interface(NMSupplicantManager * self, +_nm_supplicant_manager_unregister_interface(NMSupplicantManager *self, NMSupplicantInterface *supp_iface) { NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE(self); @@ -1029,8 +1029,8 @@ _nm_supplicant_manager_unregister_interface(NMSupplicantManager * self, } static void -_supp_iface_add(NMSupplicantManager * self, - NMRefString * iface_path, +_supp_iface_add(NMSupplicantManager *self, + NMRefString *iface_path, NMSupplicantInterface *supp_iface) { NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE(self); @@ -1041,10 +1041,10 @@ _supp_iface_add(NMSupplicantManager * self, } static void -_supp_iface_remove_one(NMSupplicantManager * self, +_supp_iface_remove_one(NMSupplicantManager *self, NMSupplicantInterface *supp_iface, gboolean force_remove_from_supplicant, - const char * reason) + const char *reason) { #if NM_MORE_ASSERTS _nm_unused gs_unref_object NMSupplicantInterface *supp_iface_keep_alive = @@ -1064,10 +1064,10 @@ _supp_iface_remove_one(NMSupplicantManager * self, static void _supp_iface_remove_all(NMSupplicantManager *self, gboolean force_remove_from_supplicant, - const char * reason) + const char *reason) { NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE(self); - NMSupplicantInterface * supp_iface; + NMSupplicantInterface *supp_iface; while ((supp_iface = c_list_first_entry(&priv->supp_lst_head, NMSupplicantInterface, supp_lst))) _supp_iface_remove_one(self, supp_iface, force_remove_from_supplicant, reason); @@ -1078,7 +1078,7 @@ _supp_iface_remove_all(NMSupplicantManager *self, static gboolean _available_reset_cb(gpointer user_data) { - NMSupplicantManager * self = user_data; + NMSupplicantManager *self = user_data; NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE(self); priv->available_reset_id = 0; @@ -1209,16 +1209,16 @@ name_owner_changed(NMSupplicantManager *self, const char *name_owner, gboolean f static void name_owner_changed_cb(GDBusConnection *connection, - const char * sender_name, - const char * object_path, - const char * interface_name, - const char * signal_name, - GVariant * parameters, + const char *sender_name, + const char *object_path, + const char *interface_name, + const char *signal_name, + GVariant *parameters, gpointer user_data) { gs_unref_object NMSupplicantManager *self = g_object_ref(user_data); - NMSupplicantManagerPrivate * priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE(self); - const char * name_owner; + NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE(self); + const char *name_owner; if (!g_variant_is_of_type(parameters, G_VARIANT_TYPE("(sss)"))) return; @@ -1244,7 +1244,7 @@ name_owner_changed_cb(GDBusConnection *connection, static void get_name_owner_cb(const char *name_owner, GError *error, gpointer user_data) { - NMSupplicantManager * self = user_data; + NMSupplicantManager *self = user_data; NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE(self); if (!name_owner && nm_utils_error_is_cancelled(error)) @@ -1297,7 +1297,7 @@ nm_supplicant_manager_init(NMSupplicantManager *self) static void dispose(GObject *object) { - NMSupplicantManager * self = (NMSupplicantManager *) object; + NMSupplicantManager *self = (NMSupplicantManager *) object; NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE(self); _supp_iface_remove_all(self, TRUE, "NMSupplicantManager is disposing"); diff --git a/src/core/supplicant/nm-supplicant-manager.h b/src/core/supplicant/nm-supplicant-manager.h index 3000d064..ab163b0d 100644 --- a/src/core/supplicant/nm-supplicant-manager.h +++ b/src/core/supplicant/nm-supplicant-manager.h @@ -33,21 +33,21 @@ NMSupplicantManager *nm_supplicant_manager_get(void); NMTernary nm_supplicant_manager_is_available(NMSupplicantManager *self); GDBusConnection *nm_supplicant_manager_get_dbus_connection(NMSupplicantManager *self); -NMRefString * nm_supplicant_manager_get_dbus_name_owner(NMSupplicantManager *self); +NMRefString *nm_supplicant_manager_get_dbus_name_owner(NMSupplicantManager *self); NMSupplCapMask nm_supplicant_manager_get_global_capabilities(NMSupplicantManager *self); void nm_supplicant_manager_set_wfd_ies(NMSupplicantManager *self, GBytes *wfd_ies); typedef struct _NMSupplMgrCreateIfaceHandle NMSupplMgrCreateIfaceHandle; -typedef void (*NMSupplicantManagerCreateInterfaceCb)(NMSupplicantManager * self, +typedef void (*NMSupplicantManagerCreateInterfaceCb)(NMSupplicantManager *self, NMSupplMgrCreateIfaceHandle *handle, - NMSupplicantInterface * iface, - GError * error, + NMSupplicantInterface *iface, + GError *error, gpointer user_data); NMSupplMgrCreateIfaceHandle * -nm_supplicant_manager_create_interface(NMSupplicantManager * self, +nm_supplicant_manager_create_interface(NMSupplicantManager *self, int ifindex, NMSupplicantDriver driver, NMSupplicantManagerCreateInterfaceCb callback, @@ -60,11 +60,11 @@ NMSupplicantInterface *nm_supplicant_manager_create_interface_from_path(NMSuppli /*****************************************************************************/ -void _nm_supplicant_manager_unregister_interface(NMSupplicantManager * self, +void _nm_supplicant_manager_unregister_interface(NMSupplicantManager *self, NMSupplicantInterface *supp_iface); void _nm_supplicant_manager_dbus_call_remove_interface(NMSupplicantManager *self, - const char * name_owner, - const char * iface_path); + const char *name_owner, + const char *iface_path); #endif /* __NETWORKMANAGER_SUPPLICANT_MANAGER_H__ */ diff --git a/src/core/supplicant/nm-supplicant-settings-verify.c b/src/core/supplicant/nm-supplicant-settings-verify.c index ceb4b6ae..566173af 100644 --- a/src/core/supplicant/nm-supplicant-settings-verify.c +++ b/src/core/supplicant/nm-supplicant-settings-verify.c @@ -11,8 +11,8 @@ #include struct Opt { - const char * key; - const char *const * str_allowed; + const char *key; + const char *const *str_allowed; const NMSupplOptType type; const guint32 int_low; /* Inclusive */ const guint32 int_high; /* Inclusive; max length for strings */ diff --git a/src/core/supplicant/nm-supplicant-types.h b/src/core/supplicant/nm-supplicant-types.h index 743ef8f0..d5cf1bf7 100644 --- a/src/core/supplicant/nm-supplicant-types.h +++ b/src/core/supplicant/nm-supplicant-types.h @@ -160,7 +160,7 @@ typedef struct _NMSupplicantBssInfo { NMSupplicantInterface *_self; CList _bss_lst; - GCancellable * _init_cancellable; + GCancellable *_init_cancellable; GBytes *ssid; @@ -194,7 +194,7 @@ typedef struct _NMSupplicantPeerInfo { CList _peer_lst; NMSupplicantInterface *_self; - GCancellable * _init_cancellable; + GCancellable *_init_cancellable; char *device_name; char *manufacturer; diff --git a/src/core/supplicant/tests/test-supplicant-config.c b/src/core/supplicant/tests/test-supplicant-config.c index 0cf35d0e..53c5f70f 100644 --- a/src/core/supplicant/tests/test-supplicant-config.c +++ b/src/core/supplicant/tests/test-supplicant-config.c @@ -26,14 +26,14 @@ /*****************************************************************************/ static gboolean -validate_opt(const char * detail, - GVariant * config, - const char * key, +validate_opt(const char *detail, + GVariant *config, + const char *key, NMSupplOptType val_type, gconstpointer expected) { - char * config_key; - GVariant * config_value; + char *config_key; + GVariant *config_value; gboolean found = FALSE; GVariantIter iter; @@ -86,17 +86,17 @@ validate_opt(const char * detail, } static GVariant * -build_supplicant_config(NMConnection * connection, +build_supplicant_config(NMConnection *connection, guint mtu, guint fixed_freq, NMSupplCapMask capabilities) { gs_unref_object NMSupplicantConfig *config = NULL; - gs_free_error GError * error = NULL; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity *s_wsec; - NMSetting8021x * s_8021x; - gboolean success; + gs_free_error GError *error = NULL; + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMSetting8021x *s_8021x; + gboolean success; config = nm_supplicant_config_new(capabilities); @@ -136,11 +136,11 @@ build_supplicant_config(NMConnection * connection, static NMConnection * new_basic_connection(const char *id, GBytes *ssid, const char *bssid_str) { - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - NMSettingWireless * s_wifi; - NMSettingIPConfig * s_ip4; - gs_free char * uuid = nm_utils_uuid_generate(); + NMSettingWireless *s_wifi; + NMSettingIPConfig *s_ip4; + gs_free char *uuid = nm_utils_uuid_generate(); connection = nm_simple_connection_new(); @@ -183,13 +183,13 @@ new_basic_connection(const char *id, GBytes *ssid, const char *bssid_str) static void test_wifi_open(void) { - gs_unref_object NMConnection *connection = NULL; - gs_unref_variant GVariant *config_dict = NULL; - gboolean success; - GError * error = NULL; - const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; - gs_unref_bytes GBytes *ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); - const char * bssid_str = "11:22:33:44:55:66"; + gs_unref_object NMConnection *connection = NULL; + gs_unref_variant GVariant *config_dict = NULL; + gboolean success; + GError *error = NULL; + const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; + gs_unref_bytes GBytes *ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); + const char *bssid_str = "11:22:33:44:55:66"; connection = new_basic_connection("Test Wifi Open", ssid, bssid_str); success = nm_connection_verify(connection, &error); @@ -216,24 +216,24 @@ test_wifi_open(void) } static void -test_wifi_wep_key(const char * detail, +test_wifi_wep_key(const char *detail, gboolean test_bssid, NMWepKeyType wep_type, - const char * key_data, + const char *key_data, const unsigned char *expected, size_t expected_size) { - gs_unref_object NMConnection *connection = NULL; - gs_unref_variant GVariant *config_dict = NULL; - NMSettingWirelessSecurity *s_wsec; - gboolean success; - GError * error = NULL; - const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; - gs_unref_bytes GBytes *ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); - const char * bssid_str = "11:22:33:44:55:66"; - gs_unref_bytes GBytes *wep_key_bytes = g_bytes_new(expected, expected_size); - const char * bgscan_data = "simple:30:-70:86400"; - gs_unref_bytes GBytes *bgscan = g_bytes_new(bgscan_data, strlen(bgscan_data)); + gs_unref_object NMConnection *connection = NULL; + gs_unref_variant GVariant *config_dict = NULL; + NMSettingWirelessSecurity *s_wsec; + gboolean success; + GError *error = NULL; + const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; + gs_unref_bytes GBytes *ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); + const char *bssid_str = "11:22:33:44:55:66"; + gs_unref_bytes GBytes *wep_key_bytes = g_bytes_new(expected, expected_size); + const char *bgscan_data = "simple:30:-70:86400"; + gs_unref_bytes GBytes *bgscan = g_bytes_new(bgscan_data, strlen(bgscan_data)); connection = new_basic_connection("Test Wifi WEP Key", ssid, test_bssid ? bssid_str : NULL); @@ -287,17 +287,17 @@ test_wifi_wep_key(const char * detail, static void test_wifi_wep(void) { - const char * key1 = "12345"; + const char *key1 = "12345"; const unsigned char key1_expected[] = {0x31, 0x32, 0x33, 0x34, 0x35}; - const char * key2 = "ascii test$$$"; + const char *key2 = "ascii test$$$"; const unsigned char key2_expected[] = {0x61, 0x73, 0x63, 0x69, 0x69, 0x20, 0x74, 0x65, 0x73, 0x74, 0x24, 0x24, 0x24}; - const char * key3 = "abcdef1234"; + const char *key3 = "abcdef1234"; const unsigned char key3_expected[] = {0xab, 0xcd, 0xef, 0x12, 0x34}; - const char * key4 = "96aec785c6392675f87f592972"; + const char *key4 = "96aec785c6392675f87f592972"; const unsigned char key4_expected[] = {0x96, 0xae, 0xc7, 0x85, 0xc6, 0x39, 0x26, 0x75, 0xf8, 0x7f, 0x59, 0x29, 0x72}; - const char * key5 = "r34lly l33t w3p p4ssphr4s3 for t3st1ng"; + const char *key5 = "r34lly l33t w3p p4ssphr4s3 for t3st1ng"; const unsigned char key5_expected[] = {0xce, 0x68, 0x8b, 0x35, 0xf6, 0x0a, 0x2b, 0xbf, 0xc9, 0x8f, 0xed, 0x10, 0xda}; @@ -349,22 +349,22 @@ test_wifi_wep(void) } static void -test_wifi_wpa_psk(const char * detail, +test_wifi_wpa_psk(const char *detail, NMSupplOptType key_type, - const char * key_data, - const unsigned char * expected, + const char *key_data, + const unsigned char *expected, size_t expected_size, NMSettingWirelessSecurityPmf pmf) { - gs_unref_object NMConnection *connection = NULL; - gs_unref_variant GVariant *config_dict = NULL; - NMSettingWirelessSecurity *s_wsec; - gboolean success; - GError * error = NULL; - const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; - gs_unref_bytes GBytes *ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); - const char * bssid_str = "11:22:33:44:55:66"; - gs_unref_bytes GBytes *wpa_psk_bytes = g_bytes_new(expected, expected_size); + gs_unref_object NMConnection *connection = NULL; + gs_unref_variant GVariant *config_dict = NULL; + NMSettingWirelessSecurity *s_wsec; + gboolean success; + GError *error = NULL; + const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; + gs_unref_bytes GBytes *ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); + const char *bssid_str = "11:22:33:44:55:66"; + gs_unref_bytes GBytes *wpa_psk_bytes = g_bytes_new(expected, expected_size); connection = new_basic_connection("Test Wifi WPA PSK", ssid, bssid_str); @@ -461,15 +461,15 @@ test_wifi_wpa_psk(const char * detail, static void test_wifi_sae_psk(const char *psk) { - gs_unref_object NMConnection *connection = NULL; - gs_unref_variant GVariant *config_dict = NULL; - NMSettingWirelessSecurity *s_wsec; - gboolean success; - GError * error = NULL; - const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; - gs_unref_bytes GBytes *ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); - const char * bssid_str = "11:22:33:44:55:66"; - int short_psk = strlen(psk) < 8; + gs_unref_object NMConnection *connection = NULL; + gs_unref_variant GVariant *config_dict = NULL; + NMSettingWirelessSecurity *s_wsec; + gboolean success; + GError *error = NULL; + const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; + gs_unref_bytes GBytes *ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); + const char *bssid_str = "11:22:33:44:55:66"; + int short_psk = strlen(psk) < 8; connection = new_basic_connection("Test Wifi SAE", ssid, bssid_str); @@ -537,12 +537,12 @@ test_wifi_sae(void) static void test_wifi_wpa_psk_types(void) { - const char * key1 = "d4721e911461d3cdef9793858e977fcda091779243abb7316c2f11605a160893"; + const char *key1 = "d4721e911461d3cdef9793858e977fcda091779243abb7316c2f11605a160893"; const unsigned char key1_expected[] = {0xd4, 0x72, 0x1e, 0x91, 0x14, 0x61, 0xd3, 0xcd, 0xef, 0x97, 0x93, 0x85, 0x8e, 0x97, 0x7f, 0xcd, 0xa0, 0x91, 0x77, 0x92, 0x43, 0xab, 0xb7, 0x31, 0x6c, 0x2f, 0x11, 0x60, 0x5a, 0x16, 0x08, 0x93}; - const char * key2 = "r34lly l33t wp4 p4ssphr4s3 for t3st1ng"; + const char *key2 = "r34lly l33t wp4 p4ssphr4s3 for t3st1ng"; test_wifi_wpa_psk("wifi-wpa-psk-hex", NM_SUPPL_OPT_TYPE_BYTES, @@ -565,16 +565,16 @@ test_wifi_wpa_psk_types(void) } static NMConnection * -generate_wifi_eap_connection(const char * id, - GBytes * ssid, - const char * bssid_str, +generate_wifi_eap_connection(const char *id, + GBytes *ssid, + const char *bssid_str, NMSettingWirelessSecurityFils fils) { - NMConnection * connection = NULL; + NMConnection *connection = NULL; NMSettingWirelessSecurity *s_wsec; - NMSetting8021x * s_8021x; + NMSetting8021x *s_8021x; gboolean success; - GError * error = NULL; + GError *error = NULL; connection = new_basic_connection(id, ssid, bssid_str); @@ -625,11 +625,11 @@ generate_wifi_eap_connection(const char * id, static NMConnection * generate_wifi_eap_suite_b_192_connection(const char *id, GBytes *ssid, const char *bssid_str) { - NMConnection * connection = NULL; + NMConnection *connection = NULL; NMSettingWirelessSecurity *s_wsec; - NMSetting8021x * s_8021x; + NMSetting8021x *s_8021x; gboolean success; - GError * error = NULL; + GError *error = NULL; connection = new_basic_connection(id, ssid, bssid_str); @@ -669,12 +669,12 @@ generate_wifi_eap_suite_b_192_connection(const char *id, GBytes *ssid, const cha static void test_wifi_eap_locked_bssid(void) { - gs_unref_object NMConnection *connection = NULL; - gs_unref_variant GVariant *config_dict = NULL; - const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; - gs_unref_bytes GBytes *ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); - const char * bssid_str = "11:22:33:44:55:66"; - guint32 mtu = 1100; + gs_unref_object NMConnection *connection = NULL; + gs_unref_variant GVariant *config_dict = NULL; + const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; + gs_unref_bytes GBytes *ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); + const char *bssid_str = "11:22:33:44:55:66"; + guint32 mtu = 1100; connection = generate_wifi_eap_connection("Test Wifi EAP-TLS Locked", ssid, @@ -716,13 +716,13 @@ test_wifi_eap_locked_bssid(void) static void test_wifi_eap_unlocked_bssid(void) { - gs_unref_object NMConnection *connection = NULL; - gs_unref_variant GVariant *config_dict = NULL; - const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; - gs_unref_bytes GBytes *ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); - const char * bgscan_data = "simple:30:-65:300"; - gs_unref_bytes GBytes *bgscan = g_bytes_new(bgscan_data, strlen(bgscan_data)); - guint32 mtu = 1100; + gs_unref_object NMConnection *connection = NULL; + gs_unref_variant GVariant *config_dict = NULL; + const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; + gs_unref_bytes GBytes *ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); + const char *bgscan_data = "simple:30:-65:300"; + gs_unref_bytes GBytes *bgscan = g_bytes_new(bgscan_data, strlen(bgscan_data)); + guint32 mtu = 1100; connection = generate_wifi_eap_connection("Test Wifi EAP-TLS Unlocked", ssid, @@ -768,13 +768,13 @@ test_wifi_eap_unlocked_bssid(void) static void test_wifi_eap_fils_disabled(void) { - gs_unref_object NMConnection *connection = NULL; - gs_unref_variant GVariant *config_dict = NULL; - const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; - gs_unref_bytes GBytes *ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); - const char * bgscan_data = "simple:30:-65:300"; - gs_unref_bytes GBytes *bgscan = g_bytes_new(bgscan_data, strlen(bgscan_data)); - guint32 mtu = 1100; + gs_unref_object NMConnection *connection = NULL; + gs_unref_variant GVariant *config_dict = NULL; + const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; + gs_unref_bytes GBytes *ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); + const char *bgscan_data = "simple:30:-65:300"; + gs_unref_bytes GBytes *bgscan = g_bytes_new(bgscan_data, strlen(bgscan_data)); + guint32 mtu = 1100; connection = generate_wifi_eap_connection("Test Wifi FILS disabled", ssid, @@ -824,12 +824,12 @@ test_wifi_eap_fils_disabled(void) static void test_wifi_eap_suite_b_generation(void) { - gs_unref_object NMConnection *connection = NULL; - gs_unref_variant GVariant *config_dict = NULL; - const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; - gs_unref_bytes GBytes *ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); - const char * bssid_str = "11:22:33:44:55:66"; - guint32 mtu = 1100; + gs_unref_object NMConnection *connection = NULL; + gs_unref_variant GVariant *config_dict = NULL; + const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; + gs_unref_bytes GBytes *ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); + const char *bssid_str = "11:22:33:44:55:66"; + guint32 mtu = 1100; connection = generate_wifi_eap_suite_b_192_connection("EAP-TLS Suite B 192", ssid, bssid_str); diff --git a/src/core/tests/config/nm-test-device.c b/src/core/tests/config/nm-test-device.c index f724b03a..21f9bec4 100644 --- a/src/core/tests/config/nm-test-device.c +++ b/src/core/tests/config/nm-test-device.c @@ -69,7 +69,7 @@ nm_test_device_new(const char *hwaddr) static void nm_test_device_class_init(NMTestDeviceClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->constructed = constructed; diff --git a/src/core/tests/config/test-config.c b/src/core/tests/config/test-config.c index 6794fbf6..fa7fae07 100644 --- a/src/core/tests/config/test-config.c +++ b/src/core/tests/config/test-config.c @@ -23,10 +23,10 @@ static void _assert_config_value(const NMConfigData *config_data, - const char * group, - const char * key, - const char * expected_value, - const char * file, + const char *group, + const char *key, + const char *expected_value, + const char *file, int line) { gs_free char *value = NULL; @@ -59,22 +59,22 @@ _assert_config_value(const NMConfigData *config_data, /*****************************************************************************/ static NMConfig * -setup_config(GError ** error, - const char * config_file, - const char * intern_config, +setup_config(GError **error, + const char *config_file, + const char *intern_config, const char *const *atomic_section_prefixes, - const char * config_dir, - const char * system_config_dir, + const char *config_dir, + const char *system_config_dir, ...) { va_list ap; - GPtrArray * args; - char ** argv, *arg; + GPtrArray *args; + char **argv, *arg; int argc; - GOptionContext * context; + GOptionContext *context; gboolean success; - NMConfig * config; - GError * local_error = NULL; + NMConfig *config; + GError *local_error = NULL; NMConfigCmdLineOptions *cli; g_assert(!error || !*error); @@ -149,9 +149,9 @@ static void test_config_simple(void) { gs_unref_object NMConfig *config = NULL; - gs_strfreev char ** plugins = NULL; - char * value; - const char * cvalue; + gs_strfreev char **plugins = NULL; + char *value; + const char *cvalue; gs_unref_object NMDevice *dev50 = nm_test_device_new("00:00:00:00:00:50"); gs_unref_object NMDevice *dev51 = nm_test_device_new("00:00:00:00:00:51"); gs_unref_object NMDevice *dev52 = nm_test_device_new("00:00:00:00:00:52"); @@ -277,7 +277,7 @@ static void test_config_override(void) { gs_unref_object NMConfig *config = NULL; - gs_strfreev char ** plugins = NULL; + gs_strfreev char **plugins = NULL; config = setup_config(NULL, TEST_DIR "/NetworkManager.conf", @@ -311,10 +311,10 @@ test_config_override(void) static void test_config_global_dns(void) { - NMConfig * config; + NMConfig *config; const NMGlobalDnsConfig *dns; - NMGlobalDnsDomain * domain; - const char *const * strv; + NMGlobalDnsDomain *domain; + const char *const *strv; config = setup_config(NULL, TEST_DIR "/NetworkManager.conf", "", NULL, "/no/such/dir", "", NULL); @@ -382,8 +382,8 @@ static void test_config_connectivity_check(void) { #if WITH_CONCHECK - const char * CONFIG_INTERN = BUILD_DIR "/test-connectivity-check-intern.conf"; - NMConfig * config; + const char *CONFIG_INTERN = BUILD_DIR "/test-connectivity-check-intern.conf"; + NMConfig *config; NMConnectivity *connectivity; g_assert(g_file_set_contents(CONFIG_INTERN, "", 0, NULL)); @@ -425,9 +425,9 @@ static void test_config_no_auto_default(void) { NMConfig *config; - GError * error = NULL; + GError *error = NULL; int fd, nwrote; - char * state_file; + char *state_file; NMDevice *dev1, *dev2, *dev3, *dev4; fd = g_file_open_tmp(NULL, &state_file, &error); @@ -497,9 +497,9 @@ static void test_config_confdir(void) { gs_unref_object NMConfig *config = NULL; - gs_strfreev char ** plugins = NULL; - char * value; - GSList * specs; + gs_strfreev char **plugins = NULL; + char *value; + GSList *specs; config = setup_config(NULL, TEST_DIR "/NetworkManager.conf", "", NULL, TEST_DIR "/conf.d", "", NULL); @@ -680,7 +680,7 @@ static void test_config_warnings(void) { gs_unref_object NMConfig *config = NULL; - const char *const * warnings; + const char *const *warnings; config = setup_config(NULL, TEST_DIR "/NetworkManager-warn.conf", @@ -716,15 +716,15 @@ test_config_warnings(void) /*****************************************************************************/ -typedef void (*TestSetValuesUserSetFcn)(NMConfig * config, +typedef void (*TestSetValuesUserSetFcn)(NMConfig *config, gboolean is_user, - GKeyFile * keyfile_user, + GKeyFile *keyfile_user, NMConfigChangeFlags *out_expected_changes); -typedef void (*TestSetValuesCheckStateFcn)(NMConfig * config, - NMConfigData * config_data, +typedef void (*TestSetValuesCheckStateFcn)(NMConfig *config, + NMConfigData *config_data, gboolean is_change_event, NMConfigChangeFlags changes, - NMConfigData * old_data); + NMConfigData *old_data); typedef struct { NMConfigChangeFlags changes; @@ -732,10 +732,10 @@ typedef struct { } TestSetValuesConfigChangedData; static void -_set_values_config_changed_cb(NMConfig * config, - NMConfigData * config_data, +_set_values_config_changed_cb(NMConfig *config, + NMConfigData *config_data, NMConfigChangeFlags changes, - NMConfigData * old_data, + NMConfigData *old_data, TestSetValuesConfigChangedData *config_changed_data) { g_assert(changes != NM_CONFIG_CHANGE_NONE); @@ -753,19 +753,19 @@ _set_values_config_changed_cb(NMConfig * config, } static void -_set_values_user(NMConfig * config, - const char * CONFIG_USER, +_set_values_user(NMConfig *config, + const char *CONFIG_USER, TestSetValuesUserSetFcn set_fcn, TestSetValuesCheckStateFcn check_state_fcn) { - GKeyFile * keyfile_user; - gboolean success; - gs_free_error GError * error = NULL; + GKeyFile *keyfile_user; + gboolean success; + gs_free_error GError *error = NULL; TestSetValuesConfigChangedData config_changed_data = { .changes = NM_CONFIG_CHANGE_NONE, .check_state_fcn = check_state_fcn, }; - NMConfigChangeFlags expected_changes = NM_CONFIG_CHANGE_NONE; + NMConfigChangeFlags expected_changes = NM_CONFIG_CHANGE_NONE; gs_unref_object NMConfigData *config_data_before = NULL; keyfile_user = nm_config_create_keyfile(); @@ -812,16 +812,16 @@ _set_values_user(NMConfig * config, } static void -_set_values_intern(NMConfig * config, +_set_values_intern(NMConfig *config, TestSetValuesUserSetFcn set_fcn, TestSetValuesCheckStateFcn check_state_fcn) { - GKeyFile * keyfile_intern; + GKeyFile *keyfile_intern; TestSetValuesConfigChangedData config_changed_data = { .changes = NM_CONFIG_CHANGE_NONE, .check_state_fcn = check_state_fcn, }; - NMConfigChangeFlags expected_changes = NM_CONFIG_CHANGE_NONE; + NMConfigChangeFlags expected_changes = NM_CONFIG_CHANGE_NONE; gs_unref_object NMConfigData *config_data_before = NULL; config_data_before = g_object_ref(nm_config_get_data(config)); @@ -860,9 +860,9 @@ _set_values_intern(NMConfig * config, } static void -_set_values_user_intern_section_set(NMConfig * config, +_set_values_user_intern_section_set(NMConfig *config, gboolean set_user, - GKeyFile * keyfile, + GKeyFile *keyfile, NMConfigChangeFlags *out_expected_changes) { g_key_file_set_string(keyfile, @@ -872,11 +872,11 @@ _set_values_user_intern_section_set(NMConfig * config, } static void -_set_values_user_intern_section_check(NMConfig * config, - NMConfigData * config_data, +_set_values_user_intern_section_check(NMConfig *config, + NMConfigData *config_data, gboolean is_change_event, NMConfigChangeFlags changes, - NMConfigData * old_data) + NMConfigData *old_data) { g_assert(changes == NM_CONFIG_CHANGE_NONE); g_assert( @@ -884,9 +884,9 @@ _set_values_user_intern_section_check(NMConfig * config, } static void -_set_values_user_initial_values_set(NMConfig * config, +_set_values_user_initial_values_set(NMConfig *config, gboolean set_user, - GKeyFile * keyfile, + GKeyFile *keyfile, NMConfigChangeFlags *out_expected_changes) { g_key_file_remove_group(keyfile, NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN "section1", NULL); @@ -895,11 +895,11 @@ _set_values_user_initial_values_set(NMConfig * config, } static void -_set_values_user_initial_values_check(NMConfig * config, - NMConfigData * config_data, +_set_values_user_initial_values_check(NMConfig *config, + NMConfigData *config_data, gboolean is_change_event, NMConfigChangeFlags changes, - NMConfigData * old_data) + NMConfigData *old_data) { if (is_change_event) g_assert(changes == (NM_CONFIG_CHANGE_VALUES | NM_CONFIG_CHANGE_VALUES_USER)); @@ -907,9 +907,9 @@ _set_values_user_initial_values_check(NMConfig * config, } static void -_set_values_intern_internal_set(NMConfig * config, +_set_values_intern_internal_set(NMConfig *config, gboolean set_user, - GKeyFile * keyfile, + GKeyFile *keyfile, NMConfigChangeFlags *out_expected_changes) { g_key_file_set_string(keyfile, @@ -921,11 +921,11 @@ _set_values_intern_internal_set(NMConfig * config, } static void -_set_values_intern_internal_check(NMConfig * config, - NMConfigData * config_data, +_set_values_intern_internal_check(NMConfig *config, + NMConfigData *config_data, gboolean is_change_event, NMConfigChangeFlags changes, - NMConfigData * old_data) + NMConfigData *old_data) { if (is_change_event) g_assert(changes @@ -938,9 +938,9 @@ _set_values_intern_internal_check(NMConfig * config, } static void -_set_values_user_atomic_section_1_set(NMConfig * config, +_set_values_user_atomic_section_1_set(NMConfig *config, gboolean set_user, - GKeyFile * keyfile, + GKeyFile *keyfile, NMConfigChangeFlags *out_expected_changes) { g_key_file_set_string(keyfile, "atomic-prefix-1.section-a", "key1", "user-value1"); @@ -952,11 +952,11 @@ _set_values_user_atomic_section_1_set(NMConfig * config, } static void -_set_values_user_atomic_section_1_check(NMConfig * config, - NMConfigData * config_data, +_set_values_user_atomic_section_1_check(NMConfig *config, + NMConfigData *config_data, gboolean is_change_event, NMConfigChangeFlags changes, - NMConfigData * old_data) + NMConfigData *old_data) { if (is_change_event) g_assert(changes == (NM_CONFIG_CHANGE_VALUES | NM_CONFIG_CHANGE_VALUES_USER)); @@ -968,9 +968,9 @@ _set_values_user_atomic_section_1_check(NMConfig * config, } static void -_set_values_intern_atomic_section_1_set(NMConfig * config, +_set_values_intern_atomic_section_1_set(NMConfig *config, gboolean set_user, - GKeyFile * keyfile, + GKeyFile *keyfile, NMConfigChangeFlags *out_expected_changes) { g_key_file_set_string(keyfile, "atomic-prefix-1.section-a", "key1", "intern-value1"); @@ -982,11 +982,11 @@ _set_values_intern_atomic_section_1_set(NMConfig * config, } static void -_set_values_intern_atomic_section_1_check(NMConfig * config, - NMConfigData * config_data, +_set_values_intern_atomic_section_1_check(NMConfig *config, + NMConfigData *config_data, gboolean is_change_event, NMConfigChangeFlags changes, - NMConfigData * old_data) + NMConfigData *old_data) { if (is_change_event) g_assert(changes @@ -1005,9 +1005,9 @@ _set_values_intern_atomic_section_1_check(NMConfig * config, } static void -_set_values_user_atomic_section_2_set(NMConfig * config, +_set_values_user_atomic_section_2_set(NMConfig *config, gboolean set_user, - GKeyFile * keyfile, + GKeyFile *keyfile, NMConfigChangeFlags *out_expected_changes) { g_key_file_set_string(keyfile, "atomic-prefix-1.section-a", "key1", "user-value1-x"); @@ -1019,11 +1019,11 @@ _set_values_user_atomic_section_2_set(NMConfig * config, } static void -_set_values_user_atomic_section_2_check(NMConfig * config, - NMConfigData * config_data, +_set_values_user_atomic_section_2_check(NMConfig *config, + NMConfigData *config_data, gboolean is_change_event, NMConfigChangeFlags changes, - NMConfigData * old_data) + NMConfigData *old_data) { if (is_change_event) g_assert(changes @@ -1040,9 +1040,9 @@ _set_values_user_atomic_section_2_check(NMConfig * config, } static void -_set_values_intern_atomic_section_2_set(NMConfig * config, +_set_values_intern_atomic_section_2_set(NMConfig *config, gboolean set_user, - GKeyFile * keyfile, + GKeyFile *keyfile, NMConfigChangeFlags *out_expected_changes) { /* let's hide an atomic section and one key. */ @@ -1068,11 +1068,11 @@ _set_values_intern_atomic_section_2_set(NMConfig * config, } static void -_set_values_intern_atomic_section_2_check(NMConfig * config, - NMConfigData * config_data, +_set_values_intern_atomic_section_2_check(NMConfig *config, + NMConfigData *config_data, gboolean is_change_event, NMConfigChangeFlags changes, - NMConfigData * old_data) + NMConfigData *old_data) { if (is_change_event) g_assert(changes @@ -1100,9 +1100,9 @@ static void test_config_set_values(void) { gs_unref_object NMConfig *config = NULL; - const char * CONFIG_USER = BUILD_DIR "/test-set-values-user.conf"; - const char * CONFIG_INTERN = BUILD_DIR "/test-set-values-intern.conf"; - const char * atomic_section_prefixes[] = { + const char *CONFIG_USER = BUILD_DIR "/test-set-values-user.conf"; + const char *CONFIG_INTERN = BUILD_DIR "/test-set-values-intern.conf"; + const char *atomic_section_prefixes[] = { "atomic-prefix-1.", "atomic-prefix-2.", NULL, @@ -1150,10 +1150,10 @@ test_config_set_values(void) /*****************************************************************************/ static void -_test_signal_config_changed_cb(NMConfig * config, - NMConfigData * config_data, +_test_signal_config_changed_cb(NMConfig *config, + NMConfigData *config_data, NMConfigChangeFlags changes, - NMConfigData * old_data, + NMConfigData *old_data, gpointer user_data) { const NMConfigChangeFlags *expected = user_data; @@ -1168,10 +1168,10 @@ _test_signal_config_changed_cb(NMConfig * config, } static void -_test_signal_config_changed_cb2(NMConfig * config, - NMConfigData * config_data, +_test_signal_config_changed_cb2(NMConfig *config, + NMConfigData *config_data, NMConfigChangeFlags changes, - NMConfigData * old_data, + NMConfigData *old_data, gpointer user_data) { const NMConfigChangeFlags *expected = user_data; @@ -1183,8 +1183,8 @@ _test_signal_config_changed_cb2(NMConfig * config, static void test_config_signal(void) { - gs_unref_object NMConfig *config = NULL; - NMConfigChangeFlags expected; + gs_unref_object NMConfig *config = NULL; + NMConfigChangeFlags expected; gs_unref_object NMConfigData *config_data_orig = NULL; config = @@ -1234,7 +1234,7 @@ test_config_enable(void) { gs_unref_object NMConfig *config = NULL; guint match_nm_version = _nm_config_match_nm_version; - char * match_env = g_strdup(_nm_config_match_env); + char *match_env = g_strdup(_nm_config_match_env); nm_clear_g_free(&_nm_config_match_env); _nm_config_match_env = g_strdup("something-else"); @@ -1278,11 +1278,11 @@ test_config_enable(void) static void test_config_state_file(void) { - NMConfig * config; - const NMConfigState *state; + NMConfig *config; + const NMConfigState *state; gs_free_error GError *error = NULL; gboolean ret; - gs_free char * file_data = NULL; + gs_free char *file_data = NULL; gsize file_size; const char *const TMP_FILE = BUILD_DIR "/tmp.state"; diff --git a/src/core/tests/meson.build b/src/core/tests/meson.build index 99fa0ae9..78c689f7 100644 --- a/src/core/tests/meson.build +++ b/src/core/tests/meson.build @@ -6,8 +6,6 @@ test_units = [ 'test-core', 'test-core-with-expect', 'test-dcb', - 'test-ip4-config', - 'test-ip6-config', 'test-l3cfg', 'test-utils', 'test-wired-defname', diff --git a/src/core/tests/test-core-with-expect.c b/src/core/tests/test-core-with-expect.c index 01784863..eca098c4 100644 --- a/src/core/tests/test-core-with-expect.c +++ b/src/core/tests/test-core-with-expect.c @@ -98,7 +98,7 @@ test_nm_utils_kill_child_async_do(const char *name, int sig, guint32 wait_before_kill_msec, gboolean expected_success, - const int * expected_child_status) + const int *expected_child_status) { gboolean success; struct test_nm_utils_kill_child_async_data data = {}; @@ -135,7 +135,7 @@ test_nm_utils_kill_child_sync_do(const char *name, int sig, guint32 wait_before_kill_msec, gboolean expected_success, - const int * expected_child_status) + const int *expected_child_status) { gboolean success; int child_status = -1; @@ -226,11 +226,11 @@ static void do_test_nm_utils_kill_child(void) { GLogLevelFlags fatal_mask; - char * argv_watchdog[] = { + char *argv_watchdog[] = { "bash", "-c", "sleep 4; " - "kill -KILL 0; #watchdog for #" TEST_TOKEN, + "kill -KILL 0; #watchdog for #" TEST_TOKEN, NULL, }; char *argv1[] = { @@ -464,7 +464,7 @@ test_nm_utils_kill_child(void) static void _remove_at_indexes_init_random_idx(GArray *idx, guint array_len, guint idx_len) { - GRand * rand = nmtst_get_rand(); + GRand *rand = nmtst_get_rand(); gs_free char *mask = NULL; guint i, max_test_idx; @@ -515,7 +515,7 @@ _remove_at_indexes_init_random_idx(GArray *idx, guint array_len, guint idx_len) static void test_nm_utils_array_remove_at_indexes(void) { - gs_unref_array GArray *idx = NULL, *array = NULL; + gs_unref_array GArray *idx = NULL, *array = NULL; gs_unref_hashtable GHashTable *unique = NULL; guint i_len, i_idx_len, i_rnd, i; diff --git a/src/core/tests/test-core.c b/src/core/tests/test-core.c index 3524cb17..f61d66d9 100644 --- a/src/core/tests/test-core.c +++ b/src/core/tests/test-core.c @@ -389,11 +389,11 @@ test_nm_utils_sysctl_ip_conf_path(void) static NMConnection * _match_connection_new(void) { - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4, *s_ip6; - char * uuid; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4, *s_ip6; + char *uuid; connection = nm_simple_connection_new(); @@ -433,7 +433,7 @@ _match_connection_new(void) } static NMConnection * -_match_connection(GSList * connections, +_match_connection(GSList *connections, NMConnection *original, gboolean device_has_carrier, gint64 default_v4_metric, @@ -466,8 +466,8 @@ _match_connection(GSList * connections, static void test_connection_match_basic(void) { - NMConnection * orig, *copy, *matched; - GSList * connections = NULL; + NMConnection *orig, *copy, *matched; + GSList *connections = NULL; NMSettingIPConfig *s_ip4; orig = _match_connection_new(); @@ -495,8 +495,8 @@ test_connection_match_basic(void) static void test_connection_match_ip6_method(void) { - NMConnection * orig, *copy, *matched; - GSList * connections = NULL; + NMConnection *orig, *copy, *matched; + GSList *connections = NULL; NMSettingIPConfig *s_ip6; orig = _match_connection_new(); @@ -534,8 +534,8 @@ test_connection_match_ip6_method(void) static void test_connection_match_ip6_method_ignore(void) { - NMConnection * orig, *copy, *matched; - GSList * connections = NULL; + NMConnection *orig, *copy, *matched; + GSList *connections = NULL; NMSettingIPConfig *s_ip6; orig = _match_connection_new(); @@ -570,8 +570,8 @@ test_connection_match_ip6_method_ignore(void) static void test_connection_match_ip6_method_ignore_auto(void) { - NMConnection * orig, *copy, *matched; - GSList * connections = NULL; + NMConnection *orig, *copy, *matched; + GSList *connections = NULL; NMSettingIPConfig *s_ip6; orig = _match_connection_new(); @@ -606,8 +606,8 @@ test_connection_match_ip6_method_ignore_auto(void) static void test_connection_match_ip4_method(void) { - NMConnection * orig, *copy, *matched; - GSList * connections = NULL; + NMConnection *orig, *copy, *matched; + GSList *connections = NULL; NMSettingIPConfig *s_ip4; orig = _match_connection_new(); @@ -649,8 +649,8 @@ test_connection_match_ip4_method(void) static void test_connection_match_interface_name(void) { - NMConnection * orig, *copy, *matched; - GSList * connections = NULL; + NMConnection *orig, *copy, *matched; + GSList *connections = NULL; NMSettingConnection *s_con; orig = _match_connection_new(); @@ -679,11 +679,11 @@ test_connection_match_interface_name(void) static void test_connection_match_wired(void) { - NMConnection * orig, *copy, *matched; - GSList * connections = NULL; + NMConnection *orig, *copy, *matched; + GSList *connections = NULL; NMSettingWired *s_wired; - char * subchan_arr[] = {"0.0.8000", "0.0.8001", "0.0.8002", NULL}; - const char * mac = "52:54:00:ab:db:23"; + char *subchan_arr[] = {"0.0.8000", "0.0.8001", "0.0.8002", NULL}; + const char *mac = "52:54:00:ab:db:23"; orig = _match_connection_new(); copy = nm_simple_connection_new_clone(orig); @@ -722,10 +722,10 @@ test_connection_match_wired(void) static void test_connection_match_wired2(void) { - NMConnection * orig, *copy, *matched; - GSList * connections = NULL; + NMConnection *orig, *copy, *matched; + GSList *connections = NULL; NMSettingWired *s_wired; - const char * mac = "52:54:00:ab:db:23"; + const char *mac = "52:54:00:ab:db:23"; orig = _match_connection_new(); s_wired = nm_connection_get_setting_wired(orig); @@ -756,8 +756,8 @@ test_connection_match_wired2(void) static void test_connection_match_cloned_mac(void) { - NMConnection * orig, *exact, *fuzzy, *matched; - GSList * connections = NULL; + NMConnection *orig, *exact, *fuzzy, *matched; + GSList *connections = NULL; NMSettingWired *s_wired; orig = _match_connection_new(); @@ -794,11 +794,11 @@ test_connection_match_cloned_mac(void) static void test_connection_no_match_ip4_addr(void) { - NMConnection * orig, *copy, *matched; - GSList * connections = NULL; + NMConnection *orig, *copy, *matched; + GSList *connections = NULL; NMSettingIPConfig *s_ip4, *s_ip6; - NMIPAddress * nm_addr; - GError * error = NULL; + NMIPAddress *nm_addr; + GError *error = NULL; orig = _match_connection_new(); copy = nm_simple_connection_new_clone(orig); @@ -858,11 +858,11 @@ test_connection_no_match_ip4_addr(void) static void test_connection_no_match_vlan(void) { - NMConnection * orig, *copy, *matched; - GSList * connections = NULL; + NMConnection *orig, *copy, *matched; + GSList *connections = NULL; NMSettingConnection *s_con; - NMSettingVlan * s_vlan_orig, *s_vlan_copy; - char * uuid; + NMSettingVlan *s_vlan_orig, *s_vlan_copy; + char *uuid; orig = nm_simple_connection_new(); s_con = (NMSettingConnection *) nm_setting_connection_new(); @@ -915,9 +915,9 @@ static void test_connection_match_ip4_routes1(void) { gs_unref_object NMConnection *orig = NULL, *copy = NULL; - NMConnection * matched; - nm_auto_free_slist GSList *connections = NULL; - NMSettingIPConfig * s_ip4; + NMConnection *matched; + nm_auto_free_slist GSList *connections = NULL; + NMSettingIPConfig *s_ip4; orig = _match_connection_new(); @@ -952,9 +952,9 @@ static void test_connection_match_ip4_routes2(void) { gs_unref_object NMConnection *orig = NULL, *copy = NULL; - NMConnection * matched; - nm_auto_free_slist GSList *connections = NULL; - NMSettingIPConfig * s_ip4; + NMConnection *matched; + nm_auto_free_slist GSList *connections = NULL; + NMSettingIPConfig *s_ip4; orig = _match_connection_new(); @@ -992,9 +992,9 @@ static void test_connection_match_ip6_routes(void) { gs_unref_object NMConnection *orig = NULL, *copy = NULL; - NMConnection * matched; - nm_auto_free_slist GSList *connections = NULL; - NMSettingIPConfig * s_ip6; + NMConnection *matched; + nm_auto_free_slist GSList *connections = NULL; + NMSettingIPConfig *s_ip6; orig = _match_connection_new(); @@ -1122,7 +1122,7 @@ test_wildcard_match(void) static NMConnection * _create_connection_autoconnect(const char *id, gboolean autoconnect, int autoconnect_priority) { - NMConnection * c; + NMConnection *c; NMSettingConnection *s_con; c = nmtst_create_minimal_connection(id, NULL, NM_SETTING_WIRED_SETTING_NAME, &s_con); @@ -1146,8 +1146,8 @@ _cmp_autoconnect_priority_p_with_data(gconstpointer pa, gconstpointer pb, gpoint static void _test_connection_sort_autoconnect_priority_one(NMConnection **list, gboolean shuffle) { - int i, j; - int count = 0; + int i, j; + int count = 0; gs_unref_ptrarray GPtrArray *connections = g_ptr_array_new(); while (list[count]) @@ -1253,7 +1253,7 @@ _test_match_spec_device(const GSList *specs, const char *match_str) NULL); if (match_str && g_str_has_prefix(match_str, MATCH_DRIVER)) { gs_free char *s = g_strdup(&match_str[NM_STRLEN(MATCH_DRIVER)]); - char * t; + char *t; t = strchr(s, '|'); if (t) { @@ -1266,15 +1266,15 @@ _test_match_spec_device(const GSList *specs, const char *match_str) } static void -_do_test_match_spec_device(const char * spec_str, +_do_test_match_spec_device(const char *spec_str, const char *const *matches, const char *const *no_matches, const char *const *neg_matches) { - GSList * specs, *specs_randperm = NULL, *specs_resplit, *specs_i, *specs_j; + GSList *specs, *specs_randperm = NULL, *specs_resplit, *specs_i, *specs_j; guint i; - gs_free char * specs_joined = NULL; - const char * s; + gs_free char *specs_joined = NULL; + const char *s; static const char *no_matches_default[] = {"e", "em", "em*", @@ -1463,16 +1463,16 @@ test_match_spec_device(void) /*****************************************************************************/ static void -_do_test_match_spec_config(const char * file, +_do_test_match_spec_config(const char *file, int line, - const char * spec_str, + const char *spec_str, guint version, guint v_maj, guint v_min, guint v_mic, NMMatchSpecMatchType expected) { - GSList * specs; + GSList *specs; NMMatchSpecMatchType match_result; guint c_maj, c_min, c_mic; @@ -1500,8 +1500,8 @@ _do_test_match_spec_config(const char * file, if (g_slist_length(specs) == 1 && !g_str_has_prefix(specs->data, "except:")) { /* there is only one spec in the list... test that we match except: */ - char * sss = g_strdup_printf("except:%s", (char *) specs->data); - GSList * specs2 = g_slist_append(NULL, sss); + char *sss = g_strdup_printf("except:%s", (char *) specs->data); + GSList *specs2 = g_slist_append(NULL, sss); NMMatchSpecMatchType match_result2; match_result2 = nm_match_spec_config(specs2, version, NULL); @@ -1731,9 +1731,9 @@ test_nm_utils_strbuf_append(void) #define _strbuf_append(buf, len, format, ...) \ G_STMT_START \ { \ - char ** _buf = (buf); \ - gsize * _len = (len); \ - const char * _str_iter; \ + char **_buf = (buf); \ + gsize *_len = (len); \ + const char *_str_iter; \ gs_free char *_str = NULL; \ \ switch (nmtst_get_rand_uint32() % 4) { \ @@ -1762,8 +1762,8 @@ test_nm_utils_strbuf_append(void) #define _strbuf_append_str(buf, len, str) \ G_STMT_START \ { \ - char ** _buf = (buf); \ - gsize * _len = (len); \ + char **_buf = (buf); \ + gsize *_len = (len); \ const char *_str = (str); \ \ switch (nmtst_get_rand_uint32() % 4) { \ @@ -1813,7 +1813,7 @@ test_nm_utils_strbuf_append(void) for (buf_len = 0; buf_len < 10; buf_len++) { for (rep = 0; rep < 50; rep++) { const int s_len = nmtst_get_rand_uint32() % (sizeof(str) - 5); - char * t_buf; + char *t_buf; gsize t_len; int test_mode; @@ -2044,7 +2044,7 @@ static void test_reverse_dns_ip6(void) { struct in6_addr addr; - GPtrArray * domains = g_ptr_array_new_full(8, g_free); + GPtrArray *domains = g_ptr_array_new_full(8, g_free); inet_pton(AF_INET6, "1234::56", &addr); nm_utils_get_reverse_dns_domains_ip_6(&addr, 16, domains); @@ -2097,11 +2097,11 @@ test_reverse_dns_ip6(void) /*****************************************************************************/ static void -do_test_stable_id_parse(const char * stable_id, +do_test_stable_id_parse(const char *stable_id, NMUtilsStableType expected_stable_type, - const char * expected_generated) + const char *expected_generated) { - gs_free char * generated = NULL; + gs_free char *generated = NULL; NMUtilsStableType stable_type; if (expected_stable_type == NM_UTILS_STABLE_TYPE_GENERATED) @@ -2263,7 +2263,7 @@ test_utils_file_is_in_path(void) const char *const *const _searches = (searches); \ const char *const *const _nameservers = (nameservers); \ const char *const *const _options = (options); \ - gs_free char * _content = NULL; \ + gs_free char *_content = NULL; \ \ _content = nmtst_dns_create_resolv_conf(_searches, _nameservers, _options); \ g_assert_cmpstr(_content, ==, expected); \ @@ -2443,9 +2443,9 @@ test_nm_utils_dhcp_client_id_systemd_node_specific(gconstpointer test_data) g_assert_cmpint(u64, ==, d->duid_id); for (i = 0; i < 2; i++) { - const gboolean legacy_unstable_byteorder = (i != 0); - gs_unref_bytes GBytes *client_id = NULL; - const guint8 * cid; + const gboolean legacy_unstable_byteorder = (i != 0); + gs_unref_bytes GBytes *client_id = NULL; + const guint8 *cid; guint32 iaid = d->iaid_ifname; guint32 tmp; @@ -2489,7 +2489,7 @@ _kernel_cmdline_match(gboolean expected_match, const char *const *patterns) { gs_free_error GError *error = NULL; - GError ** p_error = nmtst_get_rand_bool() ? &error : NULL; + GError **p_error = nmtst_get_rand_bool() ? &error : NULL; gboolean match; nm_assert(proc_cmdline); diff --git a/src/core/tests/test-dcb.c b/src/core/tests/test-dcb.c index fc591fcb..f85e90f9 100644 --- a/src/core/tests/test-dcb.c +++ b/src/core/tests/test-dcb.c @@ -18,7 +18,7 @@ static gboolean test_dcb_func(char **argv, guint which, gpointer user_data, GError **error) { DcbExpected *e = user_data; - char * f; + char *f; g_assert(argv[0] == NULL); argv[0] = (which == DCBTOOL) ? "dcbtool" : "fcoeadm"; @@ -49,7 +49,7 @@ test_dcb_fcoe(void) NULL}, }; NMSettingDcb *s_dcb; - GError * error = NULL; + GError *error = NULL; gboolean success; s_dcb = (NMSettingDcb *) nm_setting_dcb_new(); @@ -82,7 +82,7 @@ test_dcb_iscsi(void) NULL}, }; NMSettingDcb *s_dcb; - GError * error = NULL; + GError *error = NULL; gboolean success; s_dcb = (NMSettingDcb *) nm_setting_dcb_new(); @@ -115,7 +115,7 @@ test_dcb_fip(void) NULL}, }; NMSettingDcb *s_dcb; - GError * error = NULL; + GError *error = NULL; gboolean success; s_dcb = (NMSettingDcb *) nm_setting_dcb_new(); @@ -147,7 +147,7 @@ test_dcb_fip_default_prio(void) NULL}, }; NMSettingDcb *s_dcb; - GError * error = NULL; + GError *error = NULL; gboolean success; s_dcb = (NMSettingDcb *) nm_setting_dcb_new(); @@ -180,7 +180,7 @@ test_dcb_pfc(void) NULL}, }; NMSettingDcb *s_dcb; - GError * error = NULL; + GError *error = NULL; gboolean success; s_dcb = (NMSettingDcb *) nm_setting_dcb_new(); @@ -221,7 +221,7 @@ test_dcb_priority_groups(void) NULL}, }; NMSettingDcb *s_dcb; - GError * error = NULL; + GError *error = NULL; gboolean success; guint i; @@ -267,7 +267,7 @@ test_dcb_cleanup(void) "dcbtool sc eth0 dcb off", NULL}, }; - GError * error = NULL; + GError *error = NULL; gboolean success; success = _fcoe_cleanup("eth0", test_dcb_func, &expected, &error); @@ -292,7 +292,7 @@ test_fcoe_create(void) 0, {"fcoeadm -m vn2vn -c eth0", NULL}, }; - GError * error = NULL; + GError *error = NULL; gboolean success; NMSettingDcb *s_dcb; @@ -323,7 +323,7 @@ test_fcoe_cleanup(void) 0, {"fcoeadm -d eth0", NULL}, }; - GError * error = NULL; + GError *error = NULL; gboolean success; success = _fcoe_cleanup("eth0", test_dcb_func, &expected, &error); diff --git a/src/core/tests/test-ip4-config.c b/src/core/tests/test-ip4-config.c deleted file mode 100644 index 3a095d4a..00000000 --- a/src/core/tests/test-ip4-config.c +++ /dev/null @@ -1,380 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2013 - 2014 Red Hat, Inc. - */ - -#include "src/core/nm-default-daemon.h" - -#include - -#include "nm-ip4-config.h" -#include "libnm-platform/nm-platform.h" - -#include "nm-test-utils-core.h" - -static NMIP4Config * -build_test_config(void) -{ - NMIP4Config * config; - NMPlatformIP4Address addr; - NMPlatformIP4Route route; - - /* Build up the config to subtract */ - config = nmtst_ip4_config_new(1); - - nm_assert(NM_IP_CONFIG_CAST(config)); - - addr = *nmtst_platform_ip4_address("192.168.1.10", "1.2.3.4", 24); - nm_ip4_config_add_address(config, &addr); - - route = *nmtst_platform_ip4_route("10.0.0.0", 8, "192.168.1.1"); - nm_ip4_config_add_route(config, &route, NULL); - - route = *nmtst_platform_ip4_route("172.16.0.0", 16, "192.168.1.1"); - nm_ip4_config_add_route(config, &route, NULL); - - { - const NMPlatformIP4Route r = { - .rt_source = NM_IP_CONFIG_SOURCE_DHCP, - .gateway = nmtst_inet4_from_string("192.168.1.1"), - .table_coerced = 0, - .metric = 100, - }; - - nm_ip4_config_add_route(config, &r, NULL); - } - - nm_ip4_config_add_nameserver(config, nmtst_inet4_from_string("4.2.2.1")); - nm_ip4_config_add_nameserver(config, nmtst_inet4_from_string("4.2.2.2")); - nm_ip4_config_add_domain(config, "foobar.com"); - nm_ip4_config_add_domain(config, "baz.com"); - nm_ip4_config_add_search(config, "blahblah.com"); - nm_ip4_config_add_search(config, "beatbox.com"); - - nm_ip4_config_add_nis_server(config, nmtst_inet4_from_string("1.2.3.9")); - nm_ip4_config_add_nis_server(config, nmtst_inet4_from_string("1.2.3.10")); - - nm_ip4_config_add_wins(config, nmtst_inet4_from_string("4.2.3.9")); - nm_ip4_config_add_wins(config, nmtst_inet4_from_string("4.2.3.10")); - - return config; -} - -static void -test_replace(void) -{ - gs_unref_object NMIP4Config *config1 = NULL; - gs_unref_object NMIP4Config *config2 = NULL; - NMPlatformIP4Address addr; - gboolean relevant_changes; - - config1 = nmtst_ip4_config_new(1); - - addr = *nmtst_platform_ip4_address("172.16.0.1", NULL, 24); - addr.timestamp = 10; - addr.preferred = 3600; - addr.lifetime = 7200; - nm_ip4_config_add_address(config1, &addr); - - addr = *nmtst_platform_ip4_address("172.16.0.2", NULL, 24); - addr.timestamp = 10; - addr.preferred = 3600; - addr.lifetime = 7200; - nm_ip4_config_add_address(config1, &addr); - - config2 = nmtst_ip4_config_new(1); - - addr = *nmtst_platform_ip4_address("192.168.1.1", NULL, 24); - addr.timestamp = 40; - addr.preferred = 60; - addr.lifetime = 120; - nm_ip4_config_add_address(config2, &addr); - - addr = *nmtst_platform_ip4_address("172.16.0.2", NULL, 24); - addr.timestamp = 40; - addr.preferred = 60; - addr.lifetime = 120; - nm_ip4_config_add_address(config2, &addr); - - g_assert(nm_ip4_config_replace(config2, config1, &relevant_changes)); - g_assert(relevant_changes); - g_assert(nm_ip4_config_equal(config1, config2)); -} - -static void -test_subtract(void) -{ - NMIP4Config * src, *dst; - NMPlatformIP4Address addr; - NMPlatformIP4Route route; - const NMPlatformIP4Address *test_addr; - const NMPlatformIP4Route * test_route; - const char * expected_addr = "192.168.1.12"; - guint32 expected_addr_plen = 24; - const char * expected_route_dest = "8.0.0.0"; - guint32 expected_route_plen = 8; - const char * expected_route_next_hop = "192.168.1.1"; - guint32 expected_ns1 = nmtst_inet4_from_string("8.8.8.8"); - guint32 expected_ns2 = nmtst_inet4_from_string("8.8.8.9"); - const char * expected_domain = "wonderfalls.com"; - const char * expected_search = "somewhere.com"; - guint32 expected_nis = nmtst_inet4_from_string("1.2.3.13"); - guint32 expected_wins = nmtst_inet4_from_string("2.3.4.5"); - guint32 expected_mtu = 1492; - - src = build_test_config(); - - /* add a couple more things to the test config */ - dst = build_test_config(); - addr = *nmtst_platform_ip4_address(expected_addr, NULL, expected_addr_plen); - nm_ip4_config_add_address(dst, &addr); - - route = *nmtst_platform_ip4_route(expected_route_dest, - expected_route_plen, - expected_route_next_hop); - nm_ip4_config_add_route(dst, &route, NULL); - - nm_ip4_config_add_nameserver(dst, expected_ns1); - nm_ip4_config_add_nameserver(dst, expected_ns2); - nm_ip4_config_add_domain(dst, expected_domain); - nm_ip4_config_add_search(dst, expected_search); - - nm_ip4_config_add_nis_server(dst, expected_nis); - nm_ip4_config_add_wins(dst, expected_wins); - - nm_ip4_config_set_mtu(dst, expected_mtu, NM_IP_CONFIG_SOURCE_UNKNOWN); - - nm_ip4_config_subtract(dst, src, 0); - - /* ensure what's left is what we expect */ - g_assert_cmpuint(nm_ip4_config_get_num_addresses(dst), ==, 1); - test_addr = _nmtst_ip4_config_get_address(dst, 0); - g_assert(test_addr != NULL); - g_assert_cmpuint(test_addr->address, ==, nmtst_inet4_from_string(expected_addr)); - g_assert_cmpuint(test_addr->peer_address, ==, test_addr->address); - g_assert_cmpuint(test_addr->plen, ==, expected_addr_plen); - - g_assert(!nm_ip4_config_best_default_route_get(dst)); - g_assert_cmpuint(nmtst_ip4_config_get_gateway(dst), ==, 0); - - g_assert_cmpuint(nm_ip4_config_get_num_routes(dst), ==, 1); - test_route = _nmtst_ip4_config_get_route(dst, 0); - g_assert(test_route != NULL); - g_assert_cmpuint(test_route->network, ==, nmtst_inet4_from_string(expected_route_dest)); - g_assert_cmpuint(test_route->plen, ==, expected_route_plen); - g_assert_cmpuint(test_route->gateway, ==, nmtst_inet4_from_string(expected_route_next_hop)); - - g_assert_cmpuint(nm_ip4_config_get_num_nameservers(dst), ==, 2); - g_assert_cmpuint(nm_ip4_config_get_nameserver(dst, 0), ==, expected_ns1); - g_assert_cmpuint(nm_ip4_config_get_nameserver(dst, 1), ==, expected_ns2); - - g_assert_cmpuint(nm_ip4_config_get_num_domains(dst), ==, 1); - g_assert_cmpstr(nm_ip4_config_get_domain(dst, 0), ==, expected_domain); - g_assert_cmpuint(nm_ip4_config_get_num_searches(dst), ==, 1); - g_assert_cmpstr(nm_ip4_config_get_search(dst, 0), ==, expected_search); - - g_assert_cmpuint(nm_ip4_config_get_num_nis_servers(dst), ==, 1); - g_assert_cmpuint(nm_ip4_config_get_nis_server(dst, 0), ==, expected_nis); - - g_assert_cmpuint(nm_ip4_config_get_num_wins(dst), ==, 1); - g_assert_cmpuint(nm_ip4_config_get_wins(dst, 0), ==, expected_wins); - - g_assert_cmpuint(nm_ip4_config_get_mtu(dst), ==, expected_mtu); - - g_object_unref(src); - g_object_unref(dst); -} - -static void -test_compare_with_source(void) -{ - NMIP4Config * a, *b; - NMPlatformIP4Address addr; - NMPlatformIP4Route route; - - a = nmtst_ip4_config_new(1); - b = nmtst_ip4_config_new(2); - - /* Address */ - addr = *nmtst_platform_ip4_address("1.2.3.4", NULL, 24); - addr.addr_source = NM_IP_CONFIG_SOURCE_USER; - nm_ip4_config_add_address(a, &addr); - - addr.addr_source = NM_IP_CONFIG_SOURCE_VPN; - nm_ip4_config_add_address(b, &addr); - - /* Route */ - route = *nmtst_platform_ip4_route("10.0.0.0", 8, "192.168.1.1"); - route.rt_source = NM_IP_CONFIG_SOURCE_USER; - nm_ip4_config_add_route(a, &route, NULL); - - route.rt_source = NM_IP_CONFIG_SOURCE_VPN; - nm_ip4_config_add_route(b, &route, NULL); - - /* Assert that the configs are basically the same, eg that the source is ignored */ - g_assert(nm_ip4_config_equal(a, b)); - - g_object_unref(a); - g_object_unref(b); -} - -static void -test_add_address_with_source(void) -{ - NMIP4Config * a; - NMPlatformIP4Address addr; - const NMPlatformIP4Address *test_addr; - - a = nmtst_ip4_config_new(1); - - /* Test that a higher priority source is not overwritten */ - addr = *nmtst_platform_ip4_address("1.2.3.4", NULL, 24); - addr.addr_source = NM_IP_CONFIG_SOURCE_USER; - nm_ip4_config_add_address(a, &addr); - - test_addr = _nmtst_ip4_config_get_address(a, 0); - g_assert_cmpint(test_addr->addr_source, ==, NM_IP_CONFIG_SOURCE_USER); - - addr.addr_source = NM_IP_CONFIG_SOURCE_VPN; - nm_ip4_config_add_address(a, &addr); - - test_addr = _nmtst_ip4_config_get_address(a, 0); - g_assert_cmpint(test_addr->addr_source, ==, NM_IP_CONFIG_SOURCE_USER); - - /* Test that a lower priority address source is overwritten */ - _nmtst_ip4_config_del_address(a, 0); - addr.addr_source = NM_IP_CONFIG_SOURCE_KERNEL; - nm_ip4_config_add_address(a, &addr); - - test_addr = _nmtst_ip4_config_get_address(a, 0); - g_assert_cmpint(test_addr->addr_source, ==, NM_IP_CONFIG_SOURCE_KERNEL); - - addr.addr_source = NM_IP_CONFIG_SOURCE_USER; - nm_ip4_config_add_address(a, &addr); - - test_addr = _nmtst_ip4_config_get_address(a, 0); - g_assert_cmpint(test_addr->addr_source, ==, NM_IP_CONFIG_SOURCE_USER); - - g_object_unref(a); -} - -static void -test_add_route_with_source(void) -{ - gs_unref_object NMIP4Config *a = NULL; - NMPlatformIP4Route route; - const NMPlatformIP4Route * test_route; - - a = nmtst_ip4_config_new(1); - - /* Test that a higher priority source is not overwritten */ - route = *nmtst_platform_ip4_route("1.2.3.0", 24, "1.2.3.1"); - route.rt_source = NM_IP_CONFIG_SOURCE_USER; - nm_ip4_config_add_route(a, &route, NULL); - - g_assert_cmpint(nm_ip4_config_get_num_routes(a), ==, 1); - test_route = _nmtst_ip4_config_get_route(a, 0); - g_assert_cmpint(test_route->rt_source, ==, NM_IP_CONFIG_SOURCE_USER); - - route.rt_source = NM_IP_CONFIG_SOURCE_VPN; - nm_ip4_config_add_route(a, &route, NULL); - - g_assert_cmpint(nm_ip4_config_get_num_routes(a), ==, 1); - test_route = _nmtst_ip4_config_get_route(a, 0); - g_assert_cmpint(test_route->rt_source, ==, NM_IP_CONFIG_SOURCE_USER); - - _nmtst_ip4_config_del_route(a, 0); - g_assert_cmpint(nm_ip4_config_get_num_routes(a), ==, 0); - - /* Test that a lower priority address source is overwritten */ - route.rt_source = NM_IP_CONFIG_SOURCE_RTPROT_KERNEL; - nm_ip4_config_add_route(a, &route, NULL); - - g_assert_cmpint(nm_ip4_config_get_num_routes(a), ==, 1); - test_route = _nmtst_ip4_config_get_route(a, 0); - g_assert_cmpint(test_route->rt_source, ==, NM_IP_CONFIG_SOURCE_RTPROT_KERNEL); - - route.rt_source = NM_IP_CONFIG_SOURCE_KERNEL; - nm_ip4_config_add_route(a, &route, NULL); - - g_assert_cmpint(nm_ip4_config_get_num_routes(a), ==, 1); - test_route = _nmtst_ip4_config_get_route(a, 0); - g_assert_cmpint(test_route->rt_source, ==, NM_IP_CONFIG_SOURCE_KERNEL); -} - -static void -test_merge_subtract_mtu(void) -{ - NMIP4Config *cfg1, *cfg2, *cfg3; - guint32 expected_mtu2 = 1492; - guint32 expected_mtu3 = 666; - - cfg1 = build_test_config(); - cfg2 = build_test_config(); - cfg3 = build_test_config(); - - /* add MSS, MTU to configs to test them */ - nm_ip4_config_set_mtu(cfg2, expected_mtu2, NM_IP_CONFIG_SOURCE_UNKNOWN); - nm_ip4_config_set_mtu(cfg3, expected_mtu3, NM_IP_CONFIG_SOURCE_UNKNOWN); - - nm_ip4_config_merge(cfg1, cfg2, NM_IP_CONFIG_MERGE_DEFAULT, 0); - /* ensure MSS and MTU are in cfg1 */ - g_assert_cmpuint(nm_ip4_config_get_mtu(cfg1), ==, expected_mtu2); - - nm_ip4_config_merge(cfg1, cfg3, NM_IP_CONFIG_MERGE_DEFAULT, 0); - /* ensure again the MSS and MTU in cfg1 got overridden */ - g_assert_cmpuint(nm_ip4_config_get_mtu(cfg1), ==, expected_mtu3); - - nm_ip4_config_subtract(cfg1, cfg3, 0); - /* ensure MSS and MTU are zero in cfg1 */ - g_assert_cmpuint(nm_ip4_config_get_mtu(cfg1), ==, 0); - - g_object_unref(cfg1); - g_object_unref(cfg2); - g_object_unref(cfg3); -} - -static void -test_strip_search_trailing_dot(void) -{ - NMIP4Config *config; - - config = nmtst_ip4_config_new(1); - - nm_ip4_config_add_search(config, "."); - nm_ip4_config_add_search(config, "foo"); - nm_ip4_config_add_search(config, "bar."); - nm_ip4_config_add_search(config, "baz.com"); - nm_ip4_config_add_search(config, "baz.com."); - nm_ip4_config_add_search(config, "foobar.."); - nm_ip4_config_add_search(config, ".foobar"); - nm_ip4_config_add_search(config, "~."); - - g_assert_cmpuint(nm_ip4_config_get_num_searches(config), ==, 4); - g_assert_cmpstr(nm_ip4_config_get_search(config, 0), ==, "foo"); - g_assert_cmpstr(nm_ip4_config_get_search(config, 1), ==, "bar"); - g_assert_cmpstr(nm_ip4_config_get_search(config, 2), ==, "baz.com"); - g_assert_cmpstr(nm_ip4_config_get_search(config, 3), ==, "~"); - - g_object_unref(config); -} - -/*****************************************************************************/ - -NMTST_DEFINE(); - -int -main(int argc, char **argv) -{ - nmtst_init_with_logging(&argc, &argv, NULL, "DEFAULT"); - - g_test_add_func("/ip4-config/replace", test_replace); - g_test_add_func("/ip4-config/subtract", test_subtract); - g_test_add_func("/ip4-config/compare-with-source", test_compare_with_source); - g_test_add_func("/ip4-config/add-address-with-source", test_add_address_with_source); - g_test_add_func("/ip4-config/add-route-with-source", test_add_route_with_source); - g_test_add_func("/ip4-config/merge-subtract-mtu", test_merge_subtract_mtu); - g_test_add_func("/ip4-config/strip-search-trailing-dot", test_strip_search_trailing_dot); - - return g_test_run(); -} diff --git a/src/core/tests/test-ip6-config.c b/src/core/tests/test-ip6-config.c deleted file mode 100644 index 2e6d8aaa..00000000 --- a/src/core/tests/test-ip6-config.c +++ /dev/null @@ -1,538 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2013 Red Hat, Inc. - */ - -#include "src/core/nm-default-daemon.h" - -#include -#include - -#include "nm-ip6-config.h" - -#include "libnm-platform/nm-platform.h" -#include "nm-test-utils-core.h" - -static NMIP6Config * -build_test_config(void) -{ - NMIP6Config *config; - - /* Build up the config to subtract */ - config = nmtst_ip6_config_new(1); - - nm_ip6_config_add_address(config, - nmtst_platform_ip6_address("abcd:1234:4321::cdde", "1:2:3:4::5", 64)); - nm_ip6_config_add_route( - config, - nmtst_platform_ip6_route("abcd:1200::", 24, "abcd:1234:4321:cdde::2", NULL), - NULL); - nm_ip6_config_add_route(config, - nmtst_platform_ip6_route("2001::", 16, "2001:abba::2234", NULL), - NULL); - - nm_ip6_config_add_route(config, - nmtst_platform_ip6_route("::", 0, "3001:abba::3234", NULL), - NULL); - - nm_ip6_config_add_nameserver(config, nmtst_inet6_from_string("1:2:3:4::1")); - nm_ip6_config_add_nameserver(config, nmtst_inet6_from_string("1:2:3:4::2")); - nm_ip6_config_add_domain(config, "foobar.com"); - nm_ip6_config_add_domain(config, "baz.com"); - nm_ip6_config_add_search(config, "blahblah.com"); - nm_ip6_config_add_search(config, "beatbox.com"); - - return config; -} - -static void -test_subtract(void) -{ - NMIP6Config * src, *dst; - const NMPlatformIP6Address *test_addr; - const NMPlatformIP6Route * test_route; - const char * expected_addr = "1122:3344:5566::7788"; - guint32 expected_addr_plen = 96; - const char * expected_route_dest = "9991:8800::"; - guint32 expected_route_plen = 24; - const char * expected_route_next_hop = "1119:2228:3337:4446::5555"; - struct in6_addr expected_ns1; - struct in6_addr expected_ns2; - const char * expected_domain = "wonderfalls.com"; - const char * expected_search = "somewhere.com"; - struct in6_addr tmp; - - src = build_test_config(); - - /* add a couple more things to the test config */ - dst = build_test_config(); - nm_ip6_config_add_address(dst, - nmtst_platform_ip6_address(expected_addr, NULL, expected_addr_plen)); - nm_ip6_config_add_route(dst, - nmtst_platform_ip6_route(expected_route_dest, - expected_route_plen, - expected_route_next_hop, - NULL), - NULL); - - expected_ns1 = *nmtst_inet6_from_string("2222:3333:4444::5555"); - nm_ip6_config_add_nameserver(dst, &expected_ns1); - expected_ns2 = *nmtst_inet6_from_string("2222:3333:4444::5556"); - nm_ip6_config_add_nameserver(dst, &expected_ns2); - - nm_ip6_config_add_domain(dst, expected_domain); - nm_ip6_config_add_search(dst, expected_search); - - nm_ip6_config_subtract(dst, src, 0); - - /* ensure what's left is what we expect */ - g_assert_cmpuint(nm_ip6_config_get_num_addresses(dst), ==, 1); - test_addr = _nmtst_ip6_config_get_address(dst, 0); - g_assert(test_addr != NULL); - tmp = *nmtst_inet6_from_string(expected_addr); - g_assert(memcmp(&test_addr->address, &tmp, sizeof(tmp)) == 0); - g_assert(memcmp(&test_addr->peer_address, &in6addr_any, sizeof(tmp)) == 0); - g_assert_cmpuint(test_addr->plen, ==, expected_addr_plen); - - g_assert(nm_ip6_config_best_default_route_get(dst) == NULL); - - g_assert_cmpuint(nm_ip6_config_get_num_routes(dst), ==, 1); - test_route = _nmtst_ip6_config_get_route(dst, 0); - g_assert(test_route != NULL); - - tmp = *nmtst_inet6_from_string(expected_route_dest); - g_assert(memcmp(&test_route->network, &tmp, sizeof(tmp)) == 0); - g_assert_cmpuint(test_route->plen, ==, expected_route_plen); - tmp = *nmtst_inet6_from_string(expected_route_next_hop); - g_assert(memcmp(&test_route->gateway, &tmp, sizeof(tmp)) == 0); - - g_assert_cmpuint(nm_ip6_config_get_num_nameservers(dst), ==, 2); - g_assert(memcmp(nm_ip6_config_get_nameserver(dst, 0), &expected_ns1, sizeof(expected_ns1)) - == 0); - g_assert(memcmp(nm_ip6_config_get_nameserver(dst, 1), &expected_ns2, sizeof(expected_ns2)) - == 0); - - g_assert_cmpuint(nm_ip6_config_get_num_domains(dst), ==, 1); - g_assert_cmpstr(nm_ip6_config_get_domain(dst, 0), ==, expected_domain); - g_assert_cmpuint(nm_ip6_config_get_num_searches(dst), ==, 1); - g_assert_cmpstr(nm_ip6_config_get_search(dst, 0), ==, expected_search); - - g_object_unref(src); - g_object_unref(dst); -} - -static void -test_compare_with_source(void) -{ - NMIP6Config * a, *b; - NMPlatformIP6Address addr; - NMPlatformIP6Route route; - - a = nmtst_ip6_config_new(1); - b = nmtst_ip6_config_new(2); - - /* Address */ - addr = *nmtst_platform_ip6_address("1122:3344:5566::7788", NULL, 64); - addr.addr_source = NM_IP_CONFIG_SOURCE_USER; - nm_ip6_config_add_address(a, &addr); - - addr.addr_source = NM_IP_CONFIG_SOURCE_VPN; - nm_ip6_config_add_address(b, &addr); - - /* Route */ - route = *nmtst_platform_ip6_route("abcd:1200::", 24, "abcd:1234:4321:cdde::2", NULL); - route.rt_source = NM_IP_CONFIG_SOURCE_USER; - nm_ip6_config_add_route(a, &route, NULL); - - route.rt_source = NM_IP_CONFIG_SOURCE_VPN; - nm_ip6_config_add_route(b, &route, NULL); - - /* Assert that the configs are basically the same, eg that the source is ignored */ - g_assert(nm_ip6_config_equal(a, b)); - - g_object_unref(a); - g_object_unref(b); -} - -static void -test_add_address_with_source(void) -{ - NMIP6Config * a; - NMPlatformIP6Address addr; - const NMPlatformIP6Address *test_addr; - - a = nmtst_ip6_config_new(1); - - /* Test that a higher priority source is not overwritten */ - addr = *nmtst_platform_ip6_address("1122:3344:5566::7788", NULL, 64); - addr.addr_source = NM_IP_CONFIG_SOURCE_USER; - nm_ip6_config_add_address(a, &addr); - - test_addr = _nmtst_ip6_config_get_address(a, 0); - g_assert_cmpint(test_addr->addr_source, ==, NM_IP_CONFIG_SOURCE_USER); - - addr.addr_source = NM_IP_CONFIG_SOURCE_VPN; - nm_ip6_config_add_address(a, &addr); - - test_addr = _nmtst_ip6_config_get_address(a, 0); - g_assert_cmpint(test_addr->addr_source, ==, NM_IP_CONFIG_SOURCE_USER); - - /* Test that a lower priority address source is overwritten */ - _nmtst_ip6_config_del_address(a, 0); - addr.addr_source = NM_IP_CONFIG_SOURCE_KERNEL; - nm_ip6_config_add_address(a, &addr); - - test_addr = _nmtst_ip6_config_get_address(a, 0); - g_assert_cmpint(test_addr->addr_source, ==, NM_IP_CONFIG_SOURCE_KERNEL); - - addr.addr_source = NM_IP_CONFIG_SOURCE_USER; - nm_ip6_config_add_address(a, &addr); - - test_addr = _nmtst_ip6_config_get_address(a, 0); - g_assert_cmpint(test_addr->addr_source, ==, NM_IP_CONFIG_SOURCE_USER); - - g_object_unref(a); -} - -static void -test_add_route_with_source(void) -{ - gs_unref_object NMIP6Config *a = NULL; - NMPlatformIP6Route route; - const NMPlatformIP6Route * test_route; - - a = nmtst_ip6_config_new(1); - - /* Test that a higher priority source is not overwritten */ - route = *nmtst_platform_ip6_route("abcd:1200::", 24, "abcd:1234:4321:cdde::2", NULL); - route.rt_source = NM_IP_CONFIG_SOURCE_USER; - nm_ip6_config_add_route(a, &route, NULL); - - g_assert_cmpint(nm_ip6_config_get_num_routes(a), ==, 1); - test_route = _nmtst_ip6_config_get_route(a, 0); - g_assert_cmpint(test_route->rt_source, ==, NM_IP_CONFIG_SOURCE_USER); - - route.rt_source = NM_IP_CONFIG_SOURCE_VPN; - nm_ip6_config_add_route(a, &route, NULL); - - g_assert_cmpint(nm_ip6_config_get_num_routes(a), ==, 1); - test_route = _nmtst_ip6_config_get_route(a, 0); - g_assert_cmpint(test_route->rt_source, ==, NM_IP_CONFIG_SOURCE_USER); - - _nmtst_ip6_config_del_route(a, 0); - g_assert_cmpint(nm_ip6_config_get_num_routes(a), ==, 0); - - /* Test that a lower priority address source is overwritten */ - route.rt_source = NM_IP_CONFIG_SOURCE_KERNEL; - nm_ip6_config_add_route(a, &route, NULL); - - g_assert_cmpint(nm_ip6_config_get_num_routes(a), ==, 1); - test_route = _nmtst_ip6_config_get_route(a, 0); - g_assert_cmpint(test_route->rt_source, ==, NM_IP_CONFIG_SOURCE_KERNEL); - - route.rt_source = NM_IP_CONFIG_SOURCE_USER; - nm_ip6_config_add_route(a, &route, NULL); - - g_assert_cmpint(nm_ip6_config_get_num_routes(a), ==, 1); - test_route = _nmtst_ip6_config_get_route(a, 0); - g_assert_cmpint(test_route->rt_source, ==, NM_IP_CONFIG_SOURCE_USER); -} - -static void -test_nm_ip6_config_addresses_sort_check(NMIP6Config * config, - NMSettingIP6ConfigPrivacy use_tempaddr, - int repeat) -{ - int addr_count = nm_ip6_config_get_num_addresses(config); - int i, irepeat; - NMIP6Config *copy, *copy2; - int * idx = g_new(int, addr_count); - - nm_ip6_config_set_privacy(config, use_tempaddr); - copy = nm_ip6_config_clone(config); - g_assert(copy); - copy2 = nm_ip6_config_clone(config); - g_assert(copy2); - - /* initialize the array of indices, and keep shuffling them for every @repeat iteration. */ - for (i = 0; i < addr_count; i++) - idx[i] = i; - - for (irepeat = 0; irepeat < repeat; irepeat++) { - /* randomly shuffle the addresses. */ - nm_ip6_config_reset_addresses(copy); - for (i = 0; i < addr_count; i++) { - int j = g_rand_int_range(nmtst_get_rand(), i, addr_count); - - NM_SWAP(&idx[i], &idx[j]); - nm_ip6_config_add_address(copy, _nmtst_ip6_config_get_address(config, idx[i])); - } - - /* reorder them again */ - _nmtst_ip6_config_addresses_sort(copy); - - /* check equality using nm_ip6_config_equal() */ - if (!nm_ip6_config_equal(copy, config)) { - g_message("%s", "SORTING yields unexpected output:"); - for (i = 0; i < addr_count; i++) { - g_message( - " >> [%d] = %s", - i, - nm_platform_ip6_address_to_string(_nmtst_ip6_config_get_address(config, i), - NULL, - 0)); - g_message(" << [%d] = %s", - i, - nm_platform_ip6_address_to_string(_nmtst_ip6_config_get_address(copy, i), - NULL, - 0)); - } - g_assert_not_reached(); - } - - /* also check equality using nm_ip6_config_replace() */ - g_assert(nm_ip6_config_replace(copy2, copy, NULL) == FALSE); - } - - g_free(idx); - g_object_unref(copy); - g_object_unref(copy2); -} - -static void -test_nm_ip6_config_addresses_sort(void) -{ - NMIP6Config *config = build_test_config(); - -#define ADDR_ADD(...) \ - nm_ip6_config_add_address(config, nmtst_platform_ip6_address_full(__VA_ARGS__)) - - nm_ip6_config_reset_addresses(config); - ADDR_ADD("2607:f0d0:1002:51::4", NULL, 64, 0, NM_IP_CONFIG_SOURCE_USER, 0, 0, 0, 0); - ADDR_ADD("2607:f0d0:1002:51::5", NULL, 64, 0, NM_IP_CONFIG_SOURCE_USER, 0, 0, 0, 0); - ADDR_ADD("2607:f0d0:1002:51::6", - NULL, - 64, - 0, - NM_IP_CONFIG_SOURCE_NDISC, - 0, - 0, - 0, - IFA_F_MANAGETEMPADDR); - ADDR_ADD("2607:f0d0:1002:51::3", - NULL, - 64, - 0, - NM_IP_CONFIG_SOURCE_USER, - 0, - 0, - 0, - IFA_F_SECONDARY); - ADDR_ADD("2607:f0d0:1002:51::8", - NULL, - 64, - 0, - NM_IP_CONFIG_SOURCE_USER, - 0, - 0, - 0, - IFA_F_SECONDARY); - ADDR_ADD("2607:f0d0:1002:51::0", - NULL, - 64, - 0, - NM_IP_CONFIG_SOURCE_KERNEL, - 0, - 0, - 0, - IFA_F_SECONDARY); - ADDR_ADD("fec0::1", NULL, 128, 0, NM_IP_CONFIG_SOURCE_KERNEL, 0, 0, 0, 0); - ADDR_ADD("fe80::208:74ff:feda:625c", NULL, 128, 0, NM_IP_CONFIG_SOURCE_KERNEL, 0, 0, 0, 0); - ADDR_ADD("fe80::208:74ff:feda:625d", NULL, 128, 0, NM_IP_CONFIG_SOURCE_KERNEL, 0, 0, 0, 0); - ADDR_ADD("::1", NULL, 128, 0, NM_IP_CONFIG_SOURCE_USER, 0, 0, 0, 0); - ADDR_ADD("2607:f0d0:1002:51::2", - NULL, - 64, - 0, - NM_IP_CONFIG_SOURCE_USER, - 0, - 0, - 0, - IFA_F_TENTATIVE); - test_nm_ip6_config_addresses_sort_check(config, NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN, 8); - test_nm_ip6_config_addresses_sort_check(config, NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED, 8); - test_nm_ip6_config_addresses_sort_check(config, - NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR, - 8); - - nm_ip6_config_reset_addresses(config); - ADDR_ADD("2607:f0d0:1002:51::3", - NULL, - 64, - 0, - NM_IP_CONFIG_SOURCE_USER, - 0, - 0, - 0, - IFA_F_SECONDARY); - ADDR_ADD("2607:f0d0:1002:51::4", NULL, 64, 0, NM_IP_CONFIG_SOURCE_USER, 0, 0, 0, 0); - ADDR_ADD("2607:f0d0:1002:51::5", NULL, 64, 0, NM_IP_CONFIG_SOURCE_USER, 0, 0, 0, 0); - ADDR_ADD("2607:f0d0:1002:51::8", - NULL, - 64, - 0, - NM_IP_CONFIG_SOURCE_USER, - 0, - 0, - 0, - IFA_F_SECONDARY); - ADDR_ADD("2607:f0d0:1002:51::0", - NULL, - 64, - 0, - NM_IP_CONFIG_SOURCE_KERNEL, - 0, - 0, - 0, - IFA_F_SECONDARY); - ADDR_ADD("2607:f0d0:1002:51::6", - NULL, - 64, - 0, - NM_IP_CONFIG_SOURCE_NDISC, - 0, - 0, - 0, - IFA_F_MANAGETEMPADDR); - ADDR_ADD("fec0::1", NULL, 128, 0, NM_IP_CONFIG_SOURCE_KERNEL, 0, 0, 0, 0); - ADDR_ADD("fe80::208:74ff:feda:625c", NULL, 128, 0, NM_IP_CONFIG_SOURCE_KERNEL, 0, 0, 0, 0); - ADDR_ADD("fe80::208:74ff:feda:625d", NULL, 128, 0, NM_IP_CONFIG_SOURCE_KERNEL, 0, 0, 0, 0); - ADDR_ADD("::1", NULL, 128, 0, NM_IP_CONFIG_SOURCE_USER, 0, 0, 0, 0); - ADDR_ADD("2607:f0d0:1002:51::2", - NULL, - 64, - 0, - NM_IP_CONFIG_SOURCE_USER, - 0, - 0, - 0, - IFA_F_TENTATIVE); - test_nm_ip6_config_addresses_sort_check(config, - NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR, - 8); - -#undef ADDR_ADD - g_object_unref(config); -} - -static void -test_strip_search_trailing_dot(void) -{ - NMIP6Config *config; - - config = nmtst_ip6_config_new(1); - - nm_ip6_config_add_search(config, "."); - nm_ip6_config_add_search(config, "foo"); - nm_ip6_config_add_search(config, "bar."); - nm_ip6_config_add_search(config, "baz.com"); - nm_ip6_config_add_search(config, "baz.com."); - nm_ip6_config_add_search(config, "foobar.."); - nm_ip6_config_add_search(config, ".foobar"); - nm_ip6_config_add_search(config, "~."); - - g_assert_cmpuint(nm_ip6_config_get_num_searches(config), ==, 4); - g_assert_cmpstr(nm_ip6_config_get_search(config, 0), ==, "foo"); - g_assert_cmpstr(nm_ip6_config_get_search(config, 1), ==, "bar"); - g_assert_cmpstr(nm_ip6_config_get_search(config, 2), ==, "baz.com"); - g_assert_cmpstr(nm_ip6_config_get_search(config, 3), ==, "~"); - - g_object_unref(config); -} - -/*****************************************************************************/ - -static void -test_replace(gconstpointer user_data) -{ - nm_auto_unref_dedup_multi_index NMDedupMultiIndex *multi_idx = nm_dedup_multi_index_new(); - const int TEST_IDX = GPOINTER_TO_INT(user_data); - const int IFINDEX = 1; - gs_unref_object NMIP6Config *src_conf = NULL; - gs_unref_object NMIP6Config *dst_conf = NULL; - NMPlatformIP6Address * addr; - NMPlatformIP6Address addrs[5] = {}; - guint addrs_n = 0; - guint i; - - dst_conf = nm_ip6_config_new(multi_idx, IFINDEX); - src_conf = nm_ip6_config_new(multi_idx, IFINDEX); - - switch (TEST_IDX) { - case 1: - addr = &addrs[addrs_n++]; - addr->ifindex = IFINDEX; - addr->address = *nmtst_inet6_from_string("fe80::78ec:7a6d:602d:20f2"); - addr->plen = 64; - addr->n_ifa_flags = IFA_F_PERMANENT; - addr->addr_source = NM_IP_CONFIG_SOURCE_KERNEL; - break; - case 2: - addr = &addrs[addrs_n++]; - addr->ifindex = IFINDEX; - addr->address = *nmtst_inet6_from_string("fe80::78ec:7a6d:602d:20f2"); - addr->plen = 64; - addr->n_ifa_flags = IFA_F_PERMANENT; - addr->addr_source = NM_IP_CONFIG_SOURCE_KERNEL; - - addr = &addrs[addrs_n++]; - addr->ifindex = IFINDEX; - addr->address = *nmtst_inet6_from_string("1::1"); - addr->plen = 64; - addr->addr_source = NM_IP_CONFIG_SOURCE_USER; - - nm_ip6_config_add_address(dst_conf, addr); - break; - default: - g_assert_not_reached(); - } - - g_assert(addrs_n < G_N_ELEMENTS(addrs)); - - for (i = 0; i < addrs_n; i++) - nm_ip6_config_add_address(src_conf, &addrs[i]); - - nm_ip6_config_replace(dst_conf, src_conf, NULL); - - for (i = 0; i < addrs_n; i++) { - const NMPlatformIP6Address *a = _nmtst_ip6_config_get_address(dst_conf, i); - const NMPlatformIP6Address *b = _nmtst_ip6_config_get_address(src_conf, i); - - g_assert(nm_platform_ip6_address_cmp(&addrs[i], a) == 0); - g_assert(nm_platform_ip6_address_cmp(&addrs[i], b) == 0); - } - g_assert(addrs_n == nm_ip6_config_get_num_addresses(dst_conf)); - g_assert(addrs_n == nm_ip6_config_get_num_addresses(src_conf)); -} - -/*****************************************************************************/ - -NMTST_DEFINE(); - -int -main(int argc, char **argv) -{ - nmtst_init_with_logging(&argc, &argv, NULL, "ALL"); - - g_test_add_func("/ip6-config/subtract", test_subtract); - g_test_add_func("/ip6-config/compare-with-source", test_compare_with_source); - g_test_add_func("/ip6-config/add-address-with-source", test_add_address_with_source); - g_test_add_func("/ip6-config/add-route-with-source", test_add_route_with_source); - g_test_add_func("/ip6-config/test_nm_ip6_config_addresses_sort", - test_nm_ip6_config_addresses_sort); - g_test_add_func("/ip6-config/strip-search-trailing-dot", test_strip_search_trailing_dot); - g_test_add_data_func("/ip6-config/replace/1", GINT_TO_POINTER(1), test_replace); - g_test_add_data_func("/ip6-config/replace/2", GINT_TO_POINTER(2), test_replace); - - return g_test_run(); -} diff --git a/src/core/tests/test-l3cfg.c b/src/core/tests/test-l3cfg.c index 100c2496..5501079e 100644 --- a/src/core/tests/test-l3cfg.c +++ b/src/core/tests/test-l3cfg.c @@ -22,9 +22,9 @@ _netns_access_l3cfg(NMNetns *netns, int ifindex) g_assert(NM_IS_NETNS(netns)); g_assert(ifindex > 0); - g_assert(!nm_netns_get_l3cfg(netns, ifindex)); + g_assert(!nm_netns_l3cfg_get(netns, ifindex)); - l3cfg = nm_netns_access_l3cfg(netns, ifindex); + l3cfg = nm_netns_l3cfg_acquire(netns, ifindex); g_assert(NM_IS_L3CFG(l3cfg)); return l3cfg; } @@ -33,11 +33,11 @@ _netns_access_l3cfg(NMNetns *netns, int ifindex) typedef struct { int test_idx; - NMPlatform * platform; - NMNetns * netns; + NMPlatform *platform; + NMNetns *netns; NMDedupMultiIndex *multiidx; - const char * ifname0; - const char * ifname1; + const char *ifname0; + const char *ifname1; NMPLinkAddress hwaddr0; NMPLinkAddress hwaddr1; int ifindex0; @@ -163,9 +163,9 @@ _test_l3cfg_data_set_notify_type(TestL3cfgData *tdata, TestL3cfgNotifyType notif } static void -_test_l3cfg_signal_notify(NML3Cfg * l3cfg, +_test_l3cfg_signal_notify(NML3Cfg *l3cfg, const NML3ConfigNotifyData *notify_data, - TestL3cfgData * tdata) + TestL3cfgData *tdata) { guint i; @@ -327,13 +327,13 @@ test_l3cfg(gconstpointer test_data) const int TEST_IDX = GPOINTER_TO_INT(test_data); const guint32 ACD_TIMEOUT_BASE_MSEC = 1000; nm_auto(_test_fixture_1_teardown) TestFixture1 test_fixture = {}; - const TestFixture1 * f; - NML3CfgCommitTypeHandle * commit_type_1; - NML3CfgCommitTypeHandle * commit_type_2; - gs_unref_object NML3Cfg *l3cfg0 = NULL; - nm_auto_unref_l3cd const NML3ConfigData *l3cd_a = NULL; - TestL3cfgData tdata_stack = { - .f = NULL, + const TestFixture1 *f; + NML3CfgCommitTypeHandle *commit_type_1; + NML3CfgCommitTypeHandle *commit_type_2; + gs_unref_object NML3Cfg *l3cfg0 = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd_a = NULL; + TestL3cfgData tdata_stack = { + .f = NULL, }; TestL3cfgData *const tdata = &tdata_stack; @@ -519,10 +519,10 @@ test_l3cfg(gconstpointer test_data) #define L3IPV4LL_ACD_TIMEOUT_MSEC 1500u typedef struct { - const TestFixture1 * f; + const TestFixture1 *f; NML3CfgCommitTypeHandle *l3cfg_commit_type_1; guint acd_timeout_msec; - NML3IPv4LL * l3ipv4ll; + NML3IPv4LL *l3ipv4ll; bool has_addr4_101; gint8 ready_seen; gint8 addr_commit; @@ -541,8 +541,8 @@ static void _test_l3_ipv4ll_maybe_add_addr_4(const TestL3IPv4LLData *tdata, int ifindex, guint one_case_in_num, - bool * has_addr, - const char * addr) + bool *has_addr, + const char *addr) { if (has_addr) { if (*has_addr || !nmtst_get_rand_one_case_in(one_case_in_num)) @@ -570,9 +570,9 @@ _test_l3_ipv4ll_maybe_add_addr_4(const TestL3IPv4LLData *tdata, } static void -_test_l3_ipv4ll_signal_notify(NML3Cfg * l3cfg, +_test_l3_ipv4ll_signal_notify(NML3Cfg *l3cfg, const NML3ConfigNotifyData *notify_data, - TestL3IPv4LLData * tdata) + TestL3IPv4LLData *tdata) { char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN]; @@ -653,17 +653,17 @@ test_l3_ipv4ll(gconstpointer test_data) { const int TEST_IDX = GPOINTER_TO_INT(test_data); nm_auto(_test_fixture_1_teardown) TestFixture1 test_fixture = {}; - const TestFixture1 * f; - gs_unref_object NML3Cfg *l3cfg0 = NULL; - TestL3IPv4LLData tdata_stack = { - .f = NULL, + const TestFixture1 *f; + gs_unref_object NML3Cfg *l3cfg0 = NULL; + TestL3IPv4LLData tdata_stack = { + .f = NULL, }; - TestL3IPv4LLData *const tdata = &tdata_stack; - NMTstpAcdDefender * acd_defender_1 = NULL; - NMTstpAcdDefender * acd_defender_2 = NULL; - nm_auto_unref_l3ipv4ll NML3IPv4LL * l3ipv4ll = NULL; - gint64 start_time_msec; - gint64 total_poll_time_msec; + TestL3IPv4LLData *const tdata = &tdata_stack; + NMTstpAcdDefender *acd_defender_1 = NULL; + NMTstpAcdDefender *acd_defender_2 = NULL; + nm_auto_unref_l3ipv4ll NML3IPv4LL *l3ipv4ll = NULL; + gint64 start_time_msec; + gint64 total_poll_time_msec; nm_auto_remove_l3ipv4ll_registration NML3IPv4LLRegistration *l3ipv4ll_reg = NULL; char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN]; @@ -805,12 +805,12 @@ test_l3_ipv4ll(gconstpointer test_data) typedef struct { const TestFixture1 *f; - NML3Cfg * l3cfg0; - NML3IPv6LL * l3ipv6ll; + NML3Cfg *l3cfg0; + NML3IPv6LL *l3ipv6ll; int step; int ipv6ll_callback_step; bool steps_done : 1; - const NMPObject * lladdr0; + const NMPObject *lladdr0; } TestL3IPv6LLData; static const NMPlatformIP6Address * @@ -818,7 +818,7 @@ _test_l3_ipv6ll_find_lladdr(TestL3IPv6LLData *tdata, int ifindex) { const NMPlatformIP6Address *found = NULL; NMDedupMultiIter iter; - const NMPObject * obj; + const NMPObject *obj; NMPLookup lookup; g_assert(tdata); @@ -880,21 +880,21 @@ _test_l3_ipv6ll_find_inet6(TestL3IPv6LLData *tdata, const struct in6_addr *addr) } static void -_test_l3_ipv6ll_signal_notify(NML3Cfg * l3cfg, +_test_l3_ipv6ll_signal_notify(NML3Cfg *l3cfg, const NML3ConfigNotifyData *notify_data, - TestL3IPv6LLData * tdata) + TestL3IPv6LLData *tdata) { g_assert_cmpint(tdata->step, >=, 1); g_assert_cmpint(tdata->step, <=, 2); } static void -_test_l3_ipv6ll_callback_changed(NML3IPv6LL * ipv6ll, +_test_l3_ipv6ll_callback_changed(NML3IPv6LL *ipv6ll, NML3IPv6LLState state, const struct in6_addr *lladdr, gpointer user_data) { - TestL3IPv6LLData * tdata = user_data; + TestL3IPv6LLData *tdata = user_data; int step = tdata->ipv6ll_callback_step++; const NMPlatformIP6Address *a1; @@ -950,10 +950,10 @@ test_l3_ipv6ll(gconstpointer test_data) NMTST_UTILS_HOST_ID_CONTEXT("l3-ipv6ll"); const int TEST_IDX = GPOINTER_TO_INT(test_data); nm_auto(_test_fixture_1_teardown) TestFixture1 test_fixture = {}; - gs_unref_object NML3Cfg *l3cfg0 = NULL; - TestL3IPv6LLData tdata_stack = { - .step = 0, - .steps_done = FALSE, + gs_unref_object NML3Cfg *l3cfg0 = NULL; + TestL3IPv6LLData tdata_stack = { + .step = 0, + .steps_done = FALSE, }; TestL3IPv6LLData *const tdata = &tdata_stack; char sbuf1[sizeof(_nm_utils_to_string_buffer)]; @@ -1025,6 +1025,7 @@ test_l3_ipv6ll(gconstpointer test_data) NM_UTILS_STABLE_TYPE_UUID, tdata->f->ifname0, "b6a5b934-c649-43dc-a524-3dfdb74f9419", + 0, _test_l3_ipv6ll_callback_changed, tdata); diff --git a/src/core/tests/test-systemd.c b/src/core/tests/test-systemd.c index be070248..71a6a60d 100644 --- a/src/core/tests/test-systemd.c +++ b/src/core/tests/test-systemd.c @@ -49,7 +49,7 @@ test_lldp_create(void) /*****************************************************************************/ typedef struct { - GMainLoop * mainloop; + GMainLoop *mainloop; sd_event_source *event_source; } TestSdEventData; @@ -76,7 +76,7 @@ test_sd_event(void) guint sd_id = 0; int r; int i, n; - sd_event * other_events[3] = {NULL}, *event = NULL; + sd_event *other_events[3] = {NULL}, *event = NULL; TestSdEventData user_data = {0}; g_assert_cmpint(sd_event_default(NULL), ==, 0); @@ -125,10 +125,10 @@ test_path_equal(void) #define _path_equal_check(path, expected) \ G_STMT_START \ { \ - const char * _path0 = (path); \ - const char * _expected = (expected); \ + const char *_path0 = (path); \ + const char *_expected = (expected); \ gs_free char *_path = g_strdup(_path0); \ - const char * _path_result; \ + const char *_path_result; \ \ _path_result = nm_sd_utils_path_simplify(_path); \ g_assert(_path_result == _path); \ @@ -177,8 +177,8 @@ _test_unbase64char(char ch, gboolean maybe_invalid) static void _test_unbase64mem_mem(const char *base64, const guint8 *expected_arr, gsize expected_len) { - gs_free char *expected_base64 = NULL; - int r; + gs_free char *expected_base64 = NULL; + int r; nm_auto_free guint8 *exp2_arr = NULL; nm_auto_free guint8 *exp3_arr = NULL; gsize exp2_len; diff --git a/src/core/tests/test-utils.c b/src/core/tests/test-utils.c index 59d5fd53..2d2b7340 100644 --- a/src/core/tests/test-utils.c +++ b/src/core/tests/test-utils.c @@ -72,15 +72,15 @@ test_stable_privacy(void) static void _do_test_hw_addr(NMUtilsStableType stable_type, - const char * stable_id, - const guint8 * secret_key, + const char *stable_id, + const guint8 *secret_key, gsize key_len, - const char * ifname, - const char * current_mac_address, - const char * generate_mac_address_mask, + const char *ifname, + const char *current_mac_address, + const char *generate_mac_address_mask, const char *const *expected) { - gs_free char * generated = NULL; + gs_free char *generated = NULL; const char *const *e; gboolean found = FALSE; diff --git a/src/core/tests/test-wired-defname.c b/src/core/tests/test-wired-defname.c index f810c56f..9f7aae16 100644 --- a/src/core/tests/test-wired-defname.c +++ b/src/core/tests/test-wired-defname.c @@ -15,7 +15,7 @@ static NMConnection * _new_connection(const char *id) { NMConnection *a; - NMSetting * setting; + NMSetting *setting; a = nm_simple_connection_new(); setting = nm_setting_connection_new(); @@ -55,7 +55,7 @@ test_defname_no_connections(void) static void test_defname_no_conflict(void) { - GSList * list = NULL; + GSList *list = NULL; gs_free char *name = NULL; list = g_slist_append(list, _new_connection("asdfasdfasdfadf")); @@ -73,7 +73,7 @@ test_defname_no_conflict(void) static void test_defname_conflict(void) { - GSList * list = NULL; + GSList *list = NULL; gs_free char *name = NULL; list = g_slist_append(list, _new_connection("asdfasdfasdfadf")); @@ -91,7 +91,7 @@ test_defname_conflict(void) static void test_defname_multiple_conflicts(void) { - GSList * list = NULL; + GSList *list = NULL; gs_free char *name = NULL; list = g_slist_append(list, _new_connection("random gsm connection")); diff --git a/src/core/vpn/nm-vpn-connection.c b/src/core/vpn/nm-vpn-connection.c index d2034278..bbb73550 100644 --- a/src/core/vpn/nm-vpn-connection.c +++ b/src/core/vpn/nm-vpn-connection.c @@ -8,32 +8,55 @@ #include "nm-vpn-connection.h" -#include -#include #include -#include -#include -#include #include #include +#include +#include +#include +#include +#include -#include "nm-proxy-config.h" -#include "nm-ip4-config.h" -#include "nm-ip6-config.h" +#include "NetworkManagerUtils.h" +#include "dns/nm-dns-manager.h" +#include "libnm-core-intern/nm-core-internal.h" +#include "libnm-glib-aux/nm-dbus-aux.h" #include "libnm-platform/nm-platform.h" +#include "libnm-std-aux/unaligned.h" #include "nm-active-connection.h" -#include "NetworkManagerUtils.h" -#include "settings/nm-settings-connection.h" +#include "nm-config.h" +#include "nm-dbus-manager.h" #include "nm-dispatcher.h" +#include "nm-firewalld-manager.h" +#include "nm-ip-config.h" +#include "nm-l3-config-data.h" #include "nm-netns.h" -#include "settings/nm-agent-manager.h" -#include "libnm-core-intern/nm-core-internal.h" #include "nm-pacrunner-manager.h" -#include "nm-firewalld-manager.h" -#include "nm-config.h" -#include "nm-vpn-plugin-info.h" #include "nm-vpn-manager.h" -#include "dns/nm-dns-manager.h" +#include "nm-vpn-plugin-info.h" +#include "settings/nm-agent-manager.h" +#include "settings/nm-settings-connection.h" + +/* FIXME(l3cfg): Check that we handle it correctly if the parent device is VRF type. */ + +/* FIXME(l3cfg): Proxy settings are no longer configured. That needs to be handled by NML3Cfg. */ + +/*****************************************************************************/ + +#define DBUS_DEFAULT_TIMEOUT_MSEC 10000 + +typedef enum { + L3CD_TYPE_GW_EXTERN, + + L3CD_TYPE_STATIC, + L3CD_TYPE_GENERIC, + L3CD_TYPE_IP_4, + L3CD_TYPE_IP_6, + +#define L3CD_TYPE_IP_X(IS_IPv4) ((IS_IPv4) ? L3CD_TYPE_IP_4 : L3CD_TYPE_IP_6) + + _L3CD_TYPE_NUM, +} L3CDType; typedef enum { /* Only system secrets */ @@ -78,55 +101,94 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMVpnConnection, PROP_VPN_STATE, PROP_BANNER, #define PROP_MASTER 2002 ); +typedef struct { + NMIPConfig *ip_config; + + NMIPAddr gw_internal; + NMIPAddr gw_external; + + /* Whether this address family is enabled. If not, then we won't have a l3cd instance, + * but the activation for this address family is still complete. */ + bool enabled : 1; + + /* Whether this address family is ready. This means we received the IP configuration. + * Usually this implies we also have a corresponding l3cd, but that might not be the + * case if this address family is disabled. */ + bool conf_ready : 1; +} IPData; + typedef struct { gboolean service_can_persist; gboolean connection_can_persist; NMSettingsConnectionCallId *secrets_id; SecretsReq secrets_idx; - char * username; + char *username; VpnState vpn_state; - NMDispatcherCallId * dispatcher_id; + NMDispatcherCallId *dispatcher_id; NMActiveConnectionStateReason failure_reason; NMVpnServiceState service_state; - guint start_timeout; - gboolean service_running; - NMVpnPluginInfo * plugin_info; - char * bus_name; + GSource *start_timeout_source; + NMVpnPluginInfo *plugin_info; + + NMNetns *netns; + + NML3Cfg *l3cfg_if; + NML3CfgCommitTypeHandle *l3cfg_commit_type_if; + + NML3Cfg *l3cfg_dev; + NML3CfgCommitTypeHandle *l3cfg_commit_type_dev; + + struct { + GDBusConnection *connection; + char *bus_name; + char *owner; + guint signal_id_vpn; + guint signal_id_name_changed; + bool name_owner_initialized : 1; + } dbus; NMFirewalldManagerCallId *fw_call; - NMNetns *netns; + union { + const NML3ConfigData *const l3cds[_L3CD_TYPE_NUM]; + const NML3ConfigData *l3cds_[_L3CD_TYPE_NUM]; + }; - GPtrArray *ip4_dev_route_blacklist; + /* This combines the l3cds of the VPN (basically, excluding l3cd_gw_extern which + * is only about configuration for the parent device). This is used to configure + * DNS. */ + const NML3ConfigData *l3cd_combined; - GDBusProxy * proxy; - GCancellable * cancellable; - GVariant * connect_hash; - guint connect_timeout; - NMProxyConfig * proxy_config; + union { + struct { + IPData ip_data_6; + IPData ip_data_4; + }; + IPData ip_data_x[2]; + }; + + GSource *init_fail_on_idle_source; + GSource *connect_timeout_source; + GCancellable *main_cancellable; + GVariant *connect_hash; + char *banner; NMPacrunnerConfId *pacrunner_conf_id; - gboolean has_ip4; - NMIP4Config * ip4_config; - guint32 ip4_internal_gw; - guint32 ip4_external_gw; - gboolean has_ip6; - NMIP6Config * ip6_config; - - /* These config instances are passed on to NMDevice and modified by NMDevice. - * This pointer is only useful for nm_device_replace_vpn4_config() to clear the - * previous configuration. Consider these instances to be owned by NMDevice. */ - NMIP4Config *last_device_ip4_config; - NMIP6Config *last_device_ip6_config; - - struct in6_addr *ip6_internal_gw; - struct in6_addr *ip6_external_gw; - char * ip_iface; - int ip_ifindex; - char * banner; - guint32 mtu; + + int ifindex_if; + int ifindex_dev; + + guint32 mtu; + + bool wait_for_pre_up_state : 1; + + bool dbus_service_started : 1; + + bool generic_config_received : 1; + + bool l3cds_changed : 1; } NMVpnConnectionPrivate; struct _NMVpnConnection { @@ -151,23 +213,22 @@ static const GDBusSignalInfo signal_info_vpn_state_changed; static NMSettingsConnection *_get_settings_connection(NMVpnConnection *self, gboolean allow_missing); -static void get_secrets(NMVpnConnection *self, SecretsReq secrets_idx, const char *const *hints); +static void _secrets_get(NMVpnConnection *self, SecretsReq secrets_idx, const char *const *hints); static guint32 get_route_table(NMVpnConnection *self, int addr_family, gboolean fallback_main); -static void plugin_interactive_secrets_required(NMVpnConnection * self, - const char * message, - const char *const *secrets); - -static void _set_vpn_state(NMVpnConnection * self, +static void _set_vpn_state(NMVpnConnection *self, VpnState vpn_state, NMActiveConnectionStateReason reason, gboolean quitting); +static void +_l3cfg_notify_cb(NML3Cfg *l3cfg, const NML3ConfigNotifyData *notify_data, NMVpnConnection *self); + /*****************************************************************************/ #define _NMLOG_DOMAIN LOGD_VPN -#define _NMLOG_PREFIX_NAME "vpn-connection" +#define _NMLOG_PREFIX_NAME "vpn" #define __NMLOG_prefix_buf_len 128 @@ -175,7 +236,10 @@ static const char * __LOG_create_prefix(char *buf, NMVpnConnection *self, NMSettingsConnection *con) { NMVpnConnectionPrivate *priv; - const char * id; + const char *id; + const char *iface; + char buf1[100]; + char buf2[100]; if (!self) return _NMLOG_PREFIX_NAME; @@ -183,13 +247,16 @@ __LOG_create_prefix(char *buf, NMVpnConnection *self, NMSettingsConnection *con) priv = NM_VPN_CONNECTION_GET_PRIVATE(self); id = con ? nm_settings_connection_get_id(con) : NULL; + iface = nm_vpn_connection_get_ip_iface(self, FALSE); + g_snprintf(buf, __NMLOG_prefix_buf_len, "%s[" "%p" /*self*/ "%s%s" /*con-uuid*/ "%s%s%s%s" /*con-id*/ - ",%d" /*ifindex*/ + "%s" /*ifindex_if*/ + "%s" /*ifindex_dev*/ "%s%s%s" /*iface*/ "]", _NMLOG_PREFIX_NAME, @@ -198,8 +265,9 @@ __LOG_create_prefix(char *buf, NMVpnConnection *self, NMSettingsConnection *con) con ? (nm_settings_connection_get_uuid(con) ?: "??") : "", con ? "," : "", NM_PRINT_FMT_QUOTED(id, "\"", id, "\"", con ? "??" : ""), - priv->ip_ifindex, - NM_PRINT_FMT_QUOTED(priv->ip_iface, ":(", priv->ip_iface, ")", "")); + priv->ifindex_if > 0 ? nm_sprintf_buf(buf1, ",if:%d", priv->ifindex_if) : "", + priv->ifindex_dev > 0 ? nm_sprintf_buf(buf2, ",dev:%d", priv->ifindex_dev) : "", + NM_PRINT_FMT_QUOTED(iface, ":(", iface, ")", "")); return buf; } @@ -216,7 +284,7 @@ __LOG_create_prefix(char *buf, NMVpnConnection *self, NMSettingsConnection *con) _nm_log(_level, \ _NMLOG_DOMAIN, \ 0, \ - (self) ? NM_VPN_CONNECTION_GET_PRIVATE(self)->ip_iface : NULL, \ + (self) ? nm_vpn_connection_get_ip_iface(self, FALSE) : NULL, \ (_con) ? nm_settings_connection_get_uuid(_con) : NULL, \ "%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ __LOG_create_prefix(__prefix, (self), _con) \ @@ -227,18 +295,58 @@ __LOG_create_prefix(char *buf, NMVpnConnection *self, NMSettingsConnection *con) /*****************************************************************************/ -static void -cancel_get_secrets(NMVpnConnection *self) -{ - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); +static NM_UTILS_LOOKUP_STR_DEFINE(_l3cd_type_to_string, + L3CDType, + NM_UTILS_LOOKUP_DEFAULT_NM_ASSERT(NULL), + NM_UTILS_LOOKUP_ITEM_IGNORE_OTHER(), + NM_UTILS_LOOKUP_STR_ITEM(L3CD_TYPE_GW_EXTERN, "gw-extern"), + NM_UTILS_LOOKUP_STR_ITEM(L3CD_TYPE_STATIC, "static"), + NM_UTILS_LOOKUP_STR_ITEM(L3CD_TYPE_GENERIC, "generic"), + NM_UTILS_LOOKUP_STR_ITEM(L3CD_TYPE_IP_4, "ip-4"), + NM_UTILS_LOOKUP_STR_ITEM(L3CD_TYPE_IP_6, "ip-6"), ); - if (priv->secrets_id) { - nm_settings_connection_cancel_secrets(_get_settings_connection(self, FALSE), - priv->secrets_id); - g_warn_if_fail(!priv->secrets_id); - priv->secrets_id = NULL; - } -} +static NM_UTILS_LOOKUP_STR_DEFINE( + _vpn_service_state_to_string, + NMVpnServiceState, + NM_UTILS_LOOKUP_DEFAULT(NULL), + NM_UTILS_LOOKUP_STR_ITEM(NM_VPN_SERVICE_STATE_UNKNOWN, "unknown"), + NM_UTILS_LOOKUP_STR_ITEM(NM_VPN_SERVICE_STATE_INIT, "init"), + NM_UTILS_LOOKUP_STR_ITEM(NM_VPN_SERVICE_STATE_SHUTDOWN, "shutdown"), + NM_UTILS_LOOKUP_STR_ITEM(NM_VPN_SERVICE_STATE_STARTING, "starting"), + NM_UTILS_LOOKUP_STR_ITEM(NM_VPN_SERVICE_STATE_STARTED, "started"), + NM_UTILS_LOOKUP_STR_ITEM(NM_VPN_SERVICE_STATE_STOPPING, "stopping"), + NM_UTILS_LOOKUP_STR_ITEM(NM_VPN_SERVICE_STATE_STOPPED, "stopped"), ); + +#define vpn_service_state_to_string_a(state) \ + NM_UTILS_LOOKUP_STR_A(_vpn_service_state_to_string, state) + +static NM_UTILS_LOOKUP_STR_DEFINE(_vpn_state_to_string, + VpnState, + NM_UTILS_LOOKUP_DEFAULT(NULL), + NM_UTILS_LOOKUP_STR_ITEM(STATE_UNKNOWN, "unknown"), + NM_UTILS_LOOKUP_STR_ITEM(STATE_WAITING, "waiting"), + NM_UTILS_LOOKUP_STR_ITEM(STATE_PREPARE, "prepare"), + NM_UTILS_LOOKUP_STR_ITEM(STATE_NEED_AUTH, "need-auth"), + NM_UTILS_LOOKUP_STR_ITEM(STATE_CONNECT, "connect"), + NM_UTILS_LOOKUP_STR_ITEM(STATE_IP_CONFIG_GET, "ip-config-get"), + NM_UTILS_LOOKUP_STR_ITEM(STATE_PRE_UP, "pre-up"), + NM_UTILS_LOOKUP_STR_ITEM(STATE_ACTIVATED, "activated"), + NM_UTILS_LOOKUP_STR_ITEM(STATE_DEACTIVATING, "deactivating"), + NM_UTILS_LOOKUP_STR_ITEM(STATE_DISCONNECTED, "disconnected"), + NM_UTILS_LOOKUP_STR_ITEM(STATE_FAILED, "failed"), ); + +#define vpn_state_to_string_a(state) NM_UTILS_LOOKUP_STR_A(_vpn_state_to_string, state) + +static NM_UTILS_LOOKUP_STR_DEFINE( + _vpn_plugin_failure_to_string, + NMVpnPluginFailure, + NM_UTILS_LOOKUP_DEFAULT(NULL), + NM_UTILS_LOOKUP_STR_ITEM(NM_VPN_PLUGIN_FAILURE_LOGIN_FAILED, "login-failed"), + NM_UTILS_LOOKUP_STR_ITEM(NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED, "connect-failed"), + NM_UTILS_LOOKUP_STR_ITEM(NM_VPN_PLUGIN_FAILURE_BAD_IP_CONFIG, "bad-ip-config"), ); + +#define vpn_plugin_failure_to_string_a(failure) \ + NM_UTILS_LOOKUP_STR_A(_vpn_plugin_failure_to_string, failure) static NMVpnConnectionState _state_to_nm_vpn_state(VpnState state) @@ -300,6 +408,8 @@ _state_to_ac_state(VpnState vpn_state) return NM_ACTIVE_CONNECTION_STATE_UNKNOWN; } +/*****************************************************************************/ + static NMSettingsConnection * _get_settings_connection(NMVpnConnection *self, gboolean allow_missing) { @@ -325,167 +435,573 @@ _get_applied_connection(NMVpnConnection *connection) return con; } -static void -disconnect_cb(GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) -{ - GVariant *variant; - - variant = g_dbus_proxy_call_finish(proxy, result, NULL); - if (variant) - g_variant_unref(variant); - g_object_unref(user_data); -} +/*****************************************************************************/ static void -fw_call_cleanup(NMVpnConnection *self) +_dbus_connection_call(NMVpnConnection *self, + const char *method_name, + GVariant *parameters, + const GVariantType *reply_type, + GAsyncReadyCallback callback) { NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - if (priv->fw_call) { - nm_firewalld_manager_cancel_call(priv->fw_call); - g_warn_if_fail(!priv->fw_call); - priv->fw_call = NULL; - } + g_return_if_fail(priv->dbus.bus_name); + + _LOGT("dbus: call %s on %s", method_name, priv->dbus.bus_name); + g_dbus_connection_call(priv->dbus.connection, + priv->dbus.bus_name, + NM_VPN_DBUS_PLUGIN_PATH, + NM_VPN_DBUS_PLUGIN_INTERFACE, + method_name, + parameters, + reply_type, + G_DBUS_CALL_FLAGS_NONE, + DBUS_DEFAULT_TIMEOUT_MSEC, + priv->main_cancellable, + callback, + self); } -static void -remove_parent_device_config(NMVpnConnection *connection, NMDevice *device) +static NML3ConfigMergeFlags +_l3cfg_get_merge_flags(NMVpnConnection *self, L3CDType l3cd_type) { - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(connection); + NMConnection *applied; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NML3ConfigMergeFlags merge_flags; - if (priv->last_device_ip4_config) { - nm_device_replace_vpn4_config(device, priv->last_device_ip4_config, NULL); - g_clear_object(&priv->last_device_ip4_config); - } + merge_flags = NM_L3_CONFIG_MERGE_FLAGS_NONE; + + if (l3cd_type == L3CD_TYPE_IP_4) { + applied = _get_applied_connection(self); + s_ip4 = applied ? nm_connection_get_setting_ip_config(applied, AF_INET) : NULL; + + if (s_ip4 && nm_setting_ip_config_get_ignore_auto_routes(s_ip4)) + merge_flags |= NM_L3_CONFIG_MERGE_FLAGS_NO_ROUTES; + if (s_ip4 && nm_setting_ip_config_get_never_default(s_ip4)) + merge_flags |= NM_L3_CONFIG_MERGE_FLAGS_NO_DEFAULT_ROUTES; + if (s_ip4 && nm_setting_ip_config_get_ignore_auto_dns(s_ip4)) + merge_flags |= NM_L3_CONFIG_MERGE_FLAGS_NO_DNS; + } else if (l3cd_type == L3CD_TYPE_IP_6) { + applied = _get_applied_connection(self); + s_ip6 = applied ? nm_connection_get_setting_ip_config(applied, AF_INET6) : NULL; - if (priv->last_device_ip6_config) { - nm_device_replace_vpn6_config(device, priv->last_device_ip6_config, NULL); - g_clear_object(&priv->last_device_ip6_config); + if (s_ip6 && nm_setting_ip_config_get_ignore_auto_routes(s_ip6)) + merge_flags |= NM_L3_CONFIG_MERGE_FLAGS_NO_ROUTES; + if (s_ip6 && nm_setting_ip_config_get_never_default(s_ip6)) + merge_flags |= NM_L3_CONFIG_MERGE_FLAGS_NO_DEFAULT_ROUTES; + if (s_ip6 && nm_setting_ip_config_get_ignore_auto_dns(s_ip6)) + merge_flags |= NM_L3_CONFIG_MERGE_FLAGS_NO_DNS; } + + return merge_flags; } -static void -vpn_cleanup(NMVpnConnection *self, NMDevice *parent_dev) +static NML3ConfigData * +_l3cfg_l3cd_new(NMVpnConnection *self, int ifindex) { NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - if (priv->ip_ifindex) { - NMPlatform *platform = nm_netns_get_platform(priv->netns); - - nm_platform_link_change_flags(platform, priv->ip_ifindex, IFF_UP, FALSE); - nm_platform_ip_route_flush(platform, AF_UNSPEC, priv->ip_ifindex); - nm_platform_ip_address_flush(platform, AF_UNSPEC, priv->ip_ifindex); - } + return nm_l3_config_data_new(nm_netns_get_multi_idx(priv->netns), + ifindex, + NM_IP_CONFIG_SOURCE_VPN); +} - remove_parent_device_config(self, parent_dev); +/*****************************************************************************/ - /* Remove zone from firewall */ - if (priv->ip_iface) { - nm_firewalld_manager_remove_from_zone(nm_firewalld_manager_get(), - priv->ip_iface, - NULL, - NULL, - NULL); - } - /* Cancel pending firewall call */ - fw_call_cleanup(self); +guint32 +nm_vpn_connection_get_ip4_internal_gateway(NMVpnConnection *self) +{ + g_return_val_if_fail(NM_IS_VPN_CONNECTION(self), 0); - g_free(priv->banner); - priv->banner = NULL; + return NM_VPN_CONNECTION_GET_PRIVATE(self)->ip_data_4.gw_internal.addr4; +} - g_free(priv->ip_iface); - priv->ip_iface = NULL; - priv->ip_ifindex = 0; +struct in6_addr * +nm_vpn_connection_get_ip6_internal_gateway(NMVpnConnection *self) +{ + g_return_val_if_fail(NM_IS_VPN_CONNECTION(self), 0); - g_free(priv->bus_name); - priv->bus_name = NULL; + return &NM_VPN_CONNECTION_GET_PRIVATE(self)->ip_data_6.gw_internal.addr6; } -static void -dispatcher_pre_down_done(NMDispatcherCallId *call_id, gpointer user_data) +NMVpnConnectionState +nm_vpn_connection_get_vpn_state(NMVpnConnection *self) { - NMVpnConnection * self = NM_VPN_CONNECTION(user_data); - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + g_return_val_if_fail(NM_IS_VPN_CONNECTION(self), NM_VPN_CONNECTION_STATE_UNKNOWN); - nm_assert(call_id); - nm_assert(priv->dispatcher_id == call_id); + return _state_to_nm_vpn_state(NM_VPN_CONNECTION_GET_PRIVATE(self)->vpn_state); +} - priv->dispatcher_id = NULL; - _set_vpn_state(self, - STATE_DISCONNECTED, - NM_ACTIVE_CONNECTION_STATE_REASON_USER_DISCONNECTED, - FALSE); +const char * +nm_vpn_connection_get_banner(NMVpnConnection *self) +{ + g_return_val_if_fail(NM_IS_VPN_CONNECTION(self), NULL); + + return NM_VPN_CONNECTION_GET_PRIVATE(self)->banner; } -static void -dispatcher_pre_up_done(NMDispatcherCallId *call_id, gpointer user_data) +const NML3ConfigData * +nm_vpn_connection_get_l3cd(NMVpnConnection *self) { - NMVpnConnection * self = NM_VPN_CONNECTION(user_data); - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + NMVpnConnectionPrivate *priv; - nm_assert(call_id); - nm_assert(priv->dispatcher_id == call_id); + g_return_val_if_fail(NM_IS_VPN_CONNECTION(self), NULL); - priv->dispatcher_id = NULL; - _set_vpn_state(self, STATE_ACTIVATED, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); + priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + + if (priv->l3cds_changed) { + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + L3CDType l3cd_type; + int ifindex; + + priv->l3cds_changed = FALSE; + + ifindex = nm_vpn_connection_get_ip_ifindex(self, TRUE); + + if (ifindex > 0) { + const int default_dns_priority_x[2] = { + NM_DNS_PRIORITY_DEFAULT_VPN, + NM_DNS_PRIORITY_DEFAULT_VPN, + }; + guint32 default_route_table_x[2]; + guint32 default_route_metric_x[2]; + + for (l3cd_type = 0; l3cd_type < _L3CD_TYPE_NUM; l3cd_type++) { + if (l3cd_type == L3CD_TYPE_GW_EXTERN) + continue; + if (!priv->l3cds[l3cd_type]) + continue; + + if (!l3cd) { + default_route_table_x[0] = get_route_table(self, AF_INET6, TRUE); + default_route_table_x[1] = get_route_table(self, AF_INET, TRUE); + default_route_metric_x[0] = + nm_vpn_connection_get_ip_route_metric(self, AF_INET6); + default_route_metric_x[1] = + nm_vpn_connection_get_ip_route_metric(self, AF_INET); + l3cd = _l3cfg_l3cd_new(self, ifindex); + } + + nm_l3_config_data_merge(l3cd, + priv->l3cds[l3cd_type], + _l3cfg_get_merge_flags(self, l3cd_type), + default_route_table_x, + default_route_metric_x, + NULL, + default_dns_priority_x, + NULL, + NULL); + } + } + + nm_l3_config_data_reset(&priv->l3cd_combined, l3cd); + } + + return priv->l3cd_combined; } -static void -dispatcher_cleanup(NMVpnConnection *self) +static int +_get_ifindex_for_device(NMVpnConnection *self) { - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + NMDevice *parent_dev; + int ifindex; - if (priv->dispatcher_id) - nm_dispatcher_call_cancel(g_steal_pointer(&priv->dispatcher_id)); + nm_assert(NM_IS_VPN_CONNECTION(self)); + + parent_dev = nm_active_connection_get_device(NM_ACTIVE_CONNECTION(self)); + if (!parent_dev) + return 0; + ifindex = nm_device_get_ip_ifindex(parent_dev); + if (ifindex <= 0) + return 0; + + return ifindex; } -static void -_set_vpn_state(NMVpnConnection * self, - VpnState vpn_state, - NMActiveConnectionStateReason reason, - gboolean quitting) +const char * +nm_vpn_connection_get_ip_iface(NMVpnConnection *self, gboolean fallback_device) { NMVpnConnectionPrivate *priv; - VpnState old_vpn_state; - NMVpnConnectionState new_external_state, old_external_state; - NMDevice * parent_dev = nm_active_connection_get_device(NM_ACTIVE_CONNECTION(self)); - NMConnection *applied; - g_return_if_fail(NM_IS_VPN_CONNECTION(self)); + g_return_val_if_fail(NM_IS_VPN_CONNECTION(self), NULL); priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - if (vpn_state == priv->vpn_state) - return; + if (priv->l3cfg_if) + return nm_l3cfg_get_ifname(priv->l3cfg_if, TRUE); + if (fallback_device && priv->l3cfg_dev) + return nm_l3cfg_get_ifname(priv->l3cfg_dev, TRUE); + return NULL; +} - old_vpn_state = priv->vpn_state; - priv->vpn_state = vpn_state; +int +nm_vpn_connection_get_ip_ifindex(NMVpnConnection *self, gboolean fallback_device) +{ + NMVpnConnectionPrivate *priv; - /* The device gets destroyed by active connection when it enters - * the deactivated state, so we need to ref it for usage below. - */ - if (parent_dev) - g_object_ref(parent_dev); + g_return_val_if_fail(NM_IS_VPN_CONNECTION(self), 0); - /* Update active connection base class state */ - nm_active_connection_set_state(NM_ACTIVE_CONNECTION(self), - _state_to_ac_state(vpn_state), - reason); + priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - /* Clear any in-progress secrets request */ - cancel_get_secrets(self); + if (priv->ifindex_if > 0) + return priv->ifindex_if; + if (fallback_device && priv->ifindex_dev > 0) + return priv->ifindex_dev; + return 0; +} - dispatcher_cleanup(self); +static guint32 +_get_vpn_timeout(NMVpnConnection *self) +{ + guint32 timeout; + NMSettingVpn *s_vpn; - /* 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. - */ - g_object_ref(self); + s_vpn = nm_connection_get_setting_vpn(_get_applied_connection(self)); + g_return_val_if_fail(s_vpn, 60); - old_external_state = _state_to_nm_vpn_state(old_vpn_state); - new_external_state = _state_to_nm_vpn_state(priv->vpn_state); - if (new_external_state != old_external_state) { + /* Timeout waiting for IP config signal from VPN service + * It is a configured value or 60 seconds */ + timeout = nm_setting_vpn_get_timeout(s_vpn); + if (timeout == 0) { + timeout = nm_config_data_get_connection_default_int64(NM_CONFIG_GET_DATA, + NM_CON_DEFAULT("vpn.timeout"), + NULL, + 1, + G_MAXUINT32, + 60); + } + return timeout; +} + +/*****************************************************************************/ + +static gboolean +_l3cfg_l3cd_set(NMVpnConnection *self, L3CDType l3cd_type, const NML3ConfigData *l3cd) +{ + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + + if (nm_l3_config_data_equal(l3cd, priv->l3cds[l3cd_type])) + return FALSE; + + if (_LOGT_ENABLED()) { + if (l3cd) { + char s_name[150]; + + /* Seal hear, so that we don't log about an unsealed instance. + * nm_l3_config_data_reset() anyway seals the instance too. */ + nm_l3_config_data_seal(l3cd); + + _LOGT("l3cd[%s]: set " NM_HASH_OBFUSCATE_PTR_FMT, + _l3cd_type_to_string(l3cd_type), + NM_HASH_OBFUSCATE_PTR(l3cd)); + nm_l3_config_data_log( + l3cd, + nm_sprintf_buf(s_name, "l3cd[%s]", _l3cd_type_to_string(l3cd_type)), + "vpn-config: ", + LOGL_TRACE, + _NMLOG_DOMAIN); + } else + _LOGT("l3cd[%s]: unset", _l3cd_type_to_string(l3cd_type)); + } + + nm_l3_config_data_reset(&priv->l3cds_[l3cd_type], l3cd); + priv->l3cds_changed = TRUE; + return TRUE; +} + +static void +_l3cfg_l3cd_update(NMVpnConnection *self, L3CDType l3cd_type) +{ + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + NML3Cfg *l3cfg; + const NML3ConfigData *const *p_l3cd; + + if (NM_IN_SET(l3cd_type, L3CD_TYPE_IP_4, L3CD_TYPE_IP_6, L3CD_TYPE_GENERIC, L3CD_TYPE_STATIC)) { + l3cfg = priv->l3cfg_if; + if (!l3cfg) { + l3cfg = priv->l3cfg_dev; + } + } else { + nm_assert(NM_IN_SET(l3cd_type, L3CD_TYPE_GW_EXTERN)); + l3cfg = priv->l3cfg_dev; + } + + p_l3cd = &priv->l3cds[l3cd_type]; + + if (!l3cfg) + return; + + if (!*p_l3cd) { + if (!nm_l3cfg_remove_config_all(l3cfg, p_l3cd)) + return; + _LOGT("l3cd[%s]: remove-config " NM_HASH_OBFUSCATE_PTR_FMT, + _l3cd_type_to_string(l3cd_type), + NM_HASH_OBFUSCATE_PTR(*p_l3cd)); + goto handle_changed; + } + + if (!nm_l3cfg_add_config(l3cfg, + p_l3cd, + TRUE, + *p_l3cd, + NM_L3CFG_CONFIG_PRIORITY_VPN, + get_route_table(self, AF_INET, TRUE), + get_route_table(self, AF_INET6, TRUE), + nm_vpn_connection_get_ip_route_metric(self, AF_INET), + nm_vpn_connection_get_ip_route_metric(self, AF_INET6), + 0, + 0, + NM_DNS_PRIORITY_DEFAULT_VPN, + NM_DNS_PRIORITY_DEFAULT_VPN, + NM_L3_ACD_DEFEND_TYPE_ONCE, + 0, + NM_L3CFG_CONFIG_FLAGS_NONE, + _l3cfg_get_merge_flags(self, l3cd_type))) + return; + + _LOGT("l3cd[%s]: add-config " NM_HASH_OBFUSCATE_PTR_FMT, + _l3cd_type_to_string(l3cd_type), + NM_HASH_OBFUSCATE_PTR(*p_l3cd)); + +handle_changed: + nm_l3cfg_commit_on_idle_schedule(l3cfg, NM_L3_CFG_COMMIT_TYPE_AUTO); +} + +static void +_l3cfg_l3cd_update_all(NMVpnConnection *self) +{ + L3CDType l3cd_type; + + for (l3cd_type = 0; l3cd_type < _L3CD_TYPE_NUM; l3cd_type++) + _l3cfg_l3cd_update(self, l3cd_type); +} + +static void +_l3cfg_l3cd_clear_all(NMVpnConnection *self) +{ + L3CDType l3cd_type; + + for (l3cd_type = 0; l3cd_type < _L3CD_TYPE_NUM; l3cd_type++) + _l3cfg_l3cd_set(self, l3cd_type, NULL); + + _l3cfg_l3cd_update_all(self); +} + +static void +_l3cfg_clear(NMVpnConnection *self, NML3Cfg *l3cfg) +{ + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + L3CDType l3cd_type; + gboolean changed = FALSE; + + if (!l3cfg) + return; + + g_signal_handlers_disconnect_by_func(l3cfg, G_CALLBACK(_l3cfg_notify_cb), self); + + for (l3cd_type = 0; l3cd_type < _L3CD_TYPE_NUM; l3cd_type++) { + if (nm_l3cfg_remove_config_all(l3cfg, &priv->l3cds[l3cd_type])) + changed = TRUE; + } + + if (changed) + nm_l3cfg_commit_on_idle_schedule(l3cfg, NM_L3_CFG_COMMIT_TYPE_AUTO); +} + +/*****************************************************************************/ + +static void +cancel_get_secrets(NMVpnConnection *self) +{ + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + + if (priv->secrets_id) { + _LOGT("secrets: cancel request"); + nm_settings_connection_cancel_secrets(_get_settings_connection(self, FALSE), + priv->secrets_id); + nm_assert(!priv->secrets_id); + } +} + +static void +_l3cfg_notify_cb(NML3Cfg *l3cfg, const NML3ConfigNotifyData *notify_data, NMVpnConnection *self) +{ + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + + if (notify_data->notify_type == NM_L3_CONFIG_NOTIFY_TYPE_POST_COMMIT) { + if (l3cfg == (priv->l3cfg_if ?: priv->l3cfg_dev) && priv->wait_for_pre_up_state + && priv->vpn_state < STATE_PRE_UP) + _set_vpn_state(self, STATE_PRE_UP, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); + } +} + +static gboolean +_set_ip_ifindex(NMVpnConnection *self, int ifindex, gboolean is_if) +{ + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + int *p_ifindex = is_if ? &priv->ifindex_if : &priv->ifindex_dev; + NML3Cfg **p_l3cfg = is_if ? &priv->l3cfg_if : &priv->l3cfg_dev; + NML3CfgCommitTypeHandle **p_l3cfg_commit_type = + is_if ? &priv->l3cfg_commit_type_if : &priv->l3cfg_commit_type_dev; + gs_unref_object NML3Cfg *l3cfg_old = NULL; + + if (ifindex < 0) + ifindex = nm_assert_unreachable_val(0); + + if (*p_ifindex == ifindex) + return FALSE; + + _LOGD("set ip-ifindex-%s %d", is_if ? "if" : "dev", ifindex); + + *p_ifindex = ifindex; + + l3cfg_old = g_steal_pointer(p_l3cfg); + nm_l3cfg_commit_type_clear(l3cfg_old, p_l3cfg_commit_type); + _l3cfg_clear(self, l3cfg_old); + + if (ifindex > 0) { + *p_l3cfg = nm_netns_l3cfg_acquire(priv->netns, ifindex); + g_signal_connect(*p_l3cfg, NM_L3CFG_SIGNAL_NOTIFY, G_CALLBACK(_l3cfg_notify_cb), self); + *p_l3cfg_commit_type = + nm_l3cfg_commit_type_register(*p_l3cfg, NM_L3_CFG_COMMIT_TYPE_UPDATE, NULL, "vpn"); + } + + return TRUE; +} + +static void +disconnect_cb(GObject *source, GAsyncResult *result, gpointer user_data) +{ + NMVpnConnection *self; + gs_unref_variant GVariant *res = NULL; + gs_free_error GError *error = NULL; + + res = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), result, &error); + if (nm_utils_error_is_cancelled(error)) + return; + + self = NM_VPN_CONNECTION(user_data); + + _LOGT("dbus: disconnected%s%s", + NM_PRINT_FMT_QUOTED2(error, " failed: ", error->message, " with success")); +} + +static void +fw_call_cleanup(NMVpnConnection *self) +{ + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + + if (priv->fw_call) { + nm_firewalld_manager_cancel_call(priv->fw_call); + g_warn_if_fail(!priv->fw_call); + priv->fw_call = NULL; + } +} + +static void +vpn_cleanup(NMVpnConnection *self, NMDevice *parent_dev) +{ + const char *iface; + + /* Remove zone from firewall */ + iface = nm_vpn_connection_get_ip_iface(self, FALSE); + if (iface) { + nm_firewalld_manager_remove_from_zone(nm_firewalld_manager_get(), iface, NULL, NULL, NULL); + } + + /* Cancel pending firewall call */ + fw_call_cleanup(self); + + _l3cfg_l3cd_clear_all(self); +} + +static void +dispatcher_pre_down_done(NMDispatcherCallId *call_id, gpointer user_data) +{ + NMVpnConnection *self = NM_VPN_CONNECTION(user_data); + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + + nm_assert(call_id); + nm_assert(priv->dispatcher_id == call_id); + + priv->dispatcher_id = NULL; + _set_vpn_state(self, + STATE_DISCONNECTED, + NM_ACTIVE_CONNECTION_STATE_REASON_USER_DISCONNECTED, + FALSE); +} + +static void +dispatcher_pre_up_done(NMDispatcherCallId *call_id, gpointer user_data) +{ + NMVpnConnection *self = NM_VPN_CONNECTION(user_data); + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + + nm_assert(call_id); + nm_assert(priv->dispatcher_id == call_id); + + priv->dispatcher_id = NULL; + _set_vpn_state(self, STATE_ACTIVATED, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); +} + +static void +dispatcher_cleanup(NMVpnConnection *self) +{ + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + + if (priv->dispatcher_id) + nm_dispatcher_call_cancel(g_steal_pointer(&priv->dispatcher_id)); +} + +static void +_set_vpn_state(NMVpnConnection *self, + VpnState vpn_state, + NMActiveConnectionStateReason reason, + gboolean quitting) +{ + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + VpnState old_vpn_state; + NMVpnConnectionState new_external_state; + NMVpnConnectionState old_external_state; + NMDevice *parent_dev = nm_active_connection_get_device(NM_ACTIVE_CONNECTION(self)); + NMConnection *applied; + + if (vpn_state == priv->vpn_state) + return; + + old_vpn_state = priv->vpn_state; + priv->vpn_state = vpn_state; + + _LOGD("set state: %s (was %s)", + vpn_state_to_string_a(priv->vpn_state), + vpn_state_to_string_a(old_vpn_state)); + + /* The device gets destroyed by active connection when it enters + * the deactivated state, so we need to ref it for usage below. + */ + nm_g_object_ref(parent_dev); + + /* Update active connection base class state */ + nm_active_connection_set_state(NM_ACTIVE_CONNECTION(self), + _state_to_ac_state(vpn_state), + reason); + + /* Clear any in-progress secrets request */ + cancel_get_secrets(self); + + dispatcher_cleanup(self); + + /* 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. + */ + g_object_ref(self); + + old_external_state = _state_to_nm_vpn_state(old_vpn_state); + new_external_state = _state_to_nm_vpn_state(priv->vpn_state); + if (new_external_state != old_external_state) { nm_dbus_object_emit_signal(NM_DBUS_OBJECT(self), &interface_info_vpn_connection, &signal_info_vpn_state_changed, @@ -495,9 +1011,9 @@ _set_vpn_state(NMVpnConnection * self, g_signal_emit(self, signals[INTERNAL_STATE_CHANGED], 0, - new_external_state, - old_external_state, - reason); + (guint) new_external_state, + (guint) old_external_state, + (guint) reason); _notify(self, PROP_VPN_STATE); } @@ -513,10 +1029,8 @@ _set_vpn_state(NMVpnConnection * self, _get_settings_connection(self, FALSE), _get_applied_connection(self), parent_dev, - priv->ip_iface, - priv->proxy_config, - priv->ip4_config, - priv->ip6_config, + nm_vpn_connection_get_ip_iface(self, FALSE), + nm_vpn_connection_get_l3cd(self), dispatcher_pre_up_done, self, &priv->dispatcher_id)) { @@ -525,6 +1039,9 @@ _set_vpn_state(NMVpnConnection * self, } break; case STATE_ACTIVATED: + + nm_clear_g_source_inst(&priv->start_timeout_source); + applied = _get_applied_connection(self); /* Secrets no longer needed now that we're connected */ @@ -535,22 +1052,11 @@ _set_vpn_state(NMVpnConnection * self, _get_settings_connection(self, FALSE), applied, parent_dev, - priv->ip_iface, - priv->proxy_config, - priv->ip4_config, - priv->ip6_config, + nm_vpn_connection_get_ip_iface(self, FALSE), + nm_vpn_connection_get_l3cd(self), NULL, NULL, NULL); - - if (priv->proxy_config) { - nm_pacrunner_manager_remove_clear(&priv->pacrunner_conf_id); - priv->pacrunner_conf_id = nm_pacrunner_manager_add(nm_pacrunner_manager_get(), - priv->proxy_config, - priv->ip_iface, - priv->ip4_config, - priv->ip6_config); - } break; case STATE_DEACTIVATING: applied = _get_applied_connection(self); @@ -559,19 +1065,15 @@ _set_vpn_state(NMVpnConnection * self, _get_settings_connection(self, FALSE), applied, parent_dev, - priv->ip_iface, - priv->proxy_config, - priv->ip4_config, - priv->ip6_config); + nm_vpn_connection_get_ip_iface(self, FALSE), + nm_vpn_connection_get_l3cd(self)); } else { if (!nm_dispatcher_call_vpn(NM_DISPATCHER_ACTION_VPN_PRE_DOWN, _get_settings_connection(self, FALSE), applied, parent_dev, - priv->ip_iface, - priv->proxy_config, - priv->ip4_config, - priv->ip6_config, + nm_vpn_connection_get_ip_iface(self, FALSE), + nm_vpn_connection_get_l3cd(self), dispatcher_pre_down_done, self, &priv->dispatcher_id)) { @@ -591,18 +1093,14 @@ _set_vpn_state(NMVpnConnection * self, _get_settings_connection(self, FALSE), _get_applied_connection(self), parent_dev, - priv->ip_iface, - NULL, - NULL, + nm_vpn_connection_get_ip_iface(self, FALSE), NULL); } else { nm_dispatcher_call_vpn(NM_DISPATCHER_ACTION_VPN_DOWN, _get_settings_connection(self, FALSE), _get_applied_connection(self), parent_dev, - priv->ip_iface, - NULL, - NULL, + nm_vpn_connection_get_ip_iface(self, FALSE), NULL, NULL, NULL, @@ -610,17 +1108,8 @@ _set_vpn_state(NMVpnConnection * self, } } - /* Tear down and clean up the connection */ - if (priv->proxy) { - g_dbus_proxy_call(priv->proxy, - "Disconnect", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - priv->cancellable, - (GAsyncReadyCallback) disconnect_cb, - g_object_ref(self)); - } + if (priv->dbus.bus_name) + _dbus_connection_call(self, "Disconnect", NULL, G_VARIANT_TYPE("()"), disconnect_cb); vpn_cleanup(self, parent_dev); /* fall-through */ @@ -650,7 +1139,7 @@ _connection_only_can_persist(NMVpnConnection *self) static void device_state_changed(NMActiveConnection *active, - NMDevice * device, + NMDevice *device, NMDeviceState new_state, NMDeviceState old_state) { @@ -678,203 +1167,152 @@ device_state_changed(NMActiveConnection *active, */ } -static void -add_ip4_vpn_gateway_route(NMIP4Config *config, - NMDevice * parent_device, - in_addr_t vpn_gw, - NMPlatform * platform) -{ - guint32 parent_gw = 0; - gboolean has_parent_gw = FALSE; - NMPlatformIP4Route route; - int ifindex; - guint32 route_metric; +static gboolean +_parent_device_l3cd_add_gateway_route(NML3ConfigData *l3cd, + int addr_family, + NMDevice *parent_device, + const NMIPAddr *vpn_gw, + NMPlatform *platform) +{ + const int IS_IPv4 = NM_IS_IPv4(addr_family); + NMIPAddr parent_gw = NM_IP_ADDR_INIT; + gboolean has_parent_gw = FALSE; nm_auto_nmpobj const NMPObject *route_resolved = NULL; + int ifindex; + NMPlatformIPXRoute route; + int r; + + nm_assert(NM_IS_L3_CONFIG_DATA(l3cd)); + g_return_val_if_fail(vpn_gw, FALSE); - g_return_if_fail(NM_IS_IP4_CONFIG(config)); - g_return_if_fail(NM_IS_DEVICE(parent_device)); - g_return_if_fail(vpn_gw != 0); + if (nm_ip_addr_is_null(addr_family, vpn_gw)) + return FALSE; - ifindex = nm_ip4_config_get_ifindex(config); + ifindex = nm_l3_config_data_get_ifindex(l3cd); nm_assert(ifindex > 0); - nm_assert(ifindex == nm_device_get_ip_ifindex(parent_device)); + + if (parent_device && ifindex != nm_device_get_ip_ifindex(parent_device)) + parent_device = 0; /* Ask kernel how to reach @vpn_gw. We can only inject the route in * @parent_device, so whatever we resolve, it can only be on @ifindex. */ - if (nm_platform_ip_route_get(platform, - AF_INET, - &vpn_gw, + r = nm_platform_ip_route_get(platform, + addr_family, + vpn_gw, ifindex, - (NMPObject **) &route_resolved) - >= 0) { - const NMPlatformIP4Route *r = NMP_OBJECT_CAST_IP4_ROUTE(route_resolved); + (NMPObject **) &route_resolved); + if (r >= 0) { + const NMPlatformIPXRoute *rx = NMP_OBJECT_CAST_IPX_ROUTE(route_resolved); + const NMPObject *obj; - if (r->ifindex == ifindex) { - const NMPObject *obj; + if (rx->rx.ifindex == ifindex && nm_platform_route_table_is_main(rx->rx.table_coerced)) { + gconstpointer gw = nm_platform_ip_route_get_gateway(addr_family, &rx->rx); /* `ip route get` always resolves the route, even if the destination is unreachable. * In which case, it pretends the destination is directly reachable. * * So, only accept direct routes if @vpn_gw is a private network * or if the parent device also has a direct default route */ - if (nm_platform_route_table_is_main(r->table_coerced)) { - if (r->gateway) { - parent_gw = r->gateway; - has_parent_gw = TRUE; - } else if (nm_utils_ip_is_site_local(AF_INET, &vpn_gw)) { - has_parent_gw = TRUE; - } else if ((obj = nm_device_get_best_default_route(parent_device, AF_INET)) - && !NMP_OBJECT_CAST_IP4_ROUTE(obj)->gateway) { - has_parent_gw = TRUE; - } - } + if (!nm_ip_addr_is_null(addr_family, gw)) { + nm_ip_addr_set(addr_family, &parent_gw, gw); + has_parent_gw = TRUE; + } else if (nm_utils_ip_is_site_local(addr_family, vpn_gw)) + has_parent_gw = TRUE; + else if ((obj = nm_device_get_best_default_route(parent_device, addr_family)) + && nm_ip_addr_is_null( + addr_family, + nm_platform_ip_route_get_gateway(addr_family, + NMP_OBJECT_CAST_IP_ROUTE(obj)))) + has_parent_gw = TRUE; } } if (!has_parent_gw) - return; - - route_metric = nm_device_get_route_metric(parent_device, AF_INET); + return FALSE; - memset(&route, 0, sizeof(route)); - route.ifindex = ifindex; - route.network = vpn_gw; - route.plen = 32; - route.gateway = parent_gw; - route.rt_source = NM_IP_CONFIG_SOURCE_VPN; - route.metric = route_metric; - nm_ip4_config_add_route(config, &route, NULL); + if (IS_IPv4) { + route.r4 = (NMPlatformIP4Route){ + .ifindex = ifindex, + .network = vpn_gw->addr4, + .plen = 32, + .gateway = parent_gw.addr4, + .rt_source = NM_IP_CONFIG_SOURCE_VPN, + .metric_any = TRUE, + }; + } else { + route.r6 = (NMPlatformIP6Route){ + .ifindex = ifindex, + .network = vpn_gw->addr6, + .plen = 128, + .gateway = parent_gw.addr6, + .rt_source = NM_IP_CONFIG_SOURCE_VPN, + .metric_any = TRUE, + }; + } + nm_l3_config_data_add_route(l3cd, addr_family, NULL, &route.rx); - if (parent_gw) { + if (!nm_ip_addr_is_null(addr_family, &parent_gw)) { /* Ensure there's a route to the parent device's gateway through the * parent device, since if the VPN claims the default route and the VPN * routes include a subnet that matches the parent device's subnet, * the parent device's gateway would get routed through the VPN and fail. */ - memset(&route, 0, sizeof(route)); - route.network = parent_gw; - route.plen = 32; - route.rt_source = NM_IP_CONFIG_SOURCE_VPN; - route.metric = route_metric; - nm_ip4_config_add_route(config, &route, NULL); + if (IS_IPv4) { + route.r4 = (NMPlatformIP4Route){ + .network = parent_gw.addr4, + .plen = 32, + .rt_source = NM_IP_CONFIG_SOURCE_VPN, + .metric_any = TRUE, + }; + } else { + route.r6 = (NMPlatformIP6Route){ + .network = parent_gw.addr6, + .plen = 128, + .rt_source = NM_IP_CONFIG_SOURCE_VPN, + .metric_any = TRUE, + }; + } + nm_l3_config_data_add_route(l3cd, addr_family, NULL, &route.rx); } + + return TRUE; } -static void -add_ip6_vpn_gateway_route(NMIP6Config * config, - NMDevice * parent_device, - const struct in6_addr *vpn_gw, - NMPlatform * platform) -{ - const struct in6_addr *parent_gw = NULL; - gboolean has_parent_gw = FALSE; - NMPlatformIP6Route route; - int ifindex; - guint32 route_metric; - nm_auto_nmpobj const NMPObject *route_resolved = NULL; +static gboolean +_l3cfg_l3cd_gw_extern_update(NMVpnConnection *self) +{ + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + int ifindex; + gboolean changed; + int IS_IPv4; - g_return_if_fail(NM_IS_IP6_CONFIG(config)); - g_return_if_fail(NM_IS_DEVICE(parent_device)); - g_return_if_fail(vpn_gw != NULL); + ifindex = priv->ifindex_dev; + if (ifindex <= 0) + goto set; - ifindex = nm_ip6_config_get_ifindex(config); + l3cd = _l3cfg_l3cd_new(self, ifindex); - nm_assert(ifindex > 0); - nm_assert(ifindex == nm_device_get_ip_ifindex(parent_device)); + changed = FALSE; + for (IS_IPv4 = 1; IS_IPv4 >= 0; IS_IPv4--) { + if (_parent_device_l3cd_add_gateway_route( + l3cd, + IS_IPv4 ? AF_INET : AF_INET6, + nm_active_connection_get_device(NM_ACTIVE_CONNECTION(self)), + &priv->ip_data_x[IS_IPv4].gw_external, + nm_netns_get_platform(priv->netns))) + changed = TRUE; + } + if (!changed) + nm_clear_pointer(&l3cd, nm_l3_config_data_unref); - /* Ask kernel how to reach @vpn_gw. We can only inject the route in - * @parent_device, so whatever we resolve, it can only be on @ifindex. */ - if (nm_platform_ip_route_get(platform, - AF_INET6, - vpn_gw, - ifindex, - (NMPObject **) &route_resolved) - >= 0) { - const NMPlatformIP6Route *r = NMP_OBJECT_CAST_IP6_ROUTE(route_resolved); +set: + if (!_l3cfg_l3cd_set(self, L3CD_TYPE_GW_EXTERN, l3cd)) + return FALSE; - if (r->ifindex == ifindex) { - const NMPObject *obj; - - /* `ip route get` always resolves the route, even if the destination is unreachable. - * In which case, it pretends the destination is directly reachable. - * - * So, only accept direct routes if @vpn_gw is a private network - * or if the parent device also has a direct default route */ - if (nm_platform_route_table_is_main(r->table_coerced)) { - if (!IN6_IS_ADDR_UNSPECIFIED(&r->gateway)) { - parent_gw = &r->gateway; - has_parent_gw = TRUE; - } else if (nm_utils_ip_is_site_local(AF_INET6, &vpn_gw)) { - has_parent_gw = TRUE; - } else if ((obj = nm_device_get_best_default_route(parent_device, AF_INET6)) - && IN6_IS_ADDR_UNSPECIFIED(&NMP_OBJECT_CAST_IP6_ROUTE(obj)->gateway)) { - has_parent_gw = TRUE; - } - } - } - } - - if (!has_parent_gw) - return; - - route_metric = nm_device_get_route_metric(parent_device, AF_INET6); - - memset(&route, 0, sizeof(route)); - route.ifindex = ifindex; - route.network = *vpn_gw; - route.plen = 128; - if (parent_gw) - route.gateway = *parent_gw; - route.rt_source = NM_IP_CONFIG_SOURCE_VPN; - route.metric = route_metric; - nm_ip6_config_add_route(config, &route, NULL); - - /* Ensure there's a route to the parent device's gateway through the - * parent device, since if the VPN claims the default route and the VPN - * routes include a subnet that matches the parent device's subnet, - * the parent device's gateway would get routed through the VPN and fail. - */ - if (parent_gw && !IN6_IS_ADDR_UNSPECIFIED(parent_gw)) { - memset(&route, 0, sizeof(route)); - route.network = *parent_gw; - route.plen = 128; - route.rt_source = NM_IP_CONFIG_SOURCE_VPN; - route.metric = route_metric; - nm_ip6_config_add_route(config, &route, NULL); - } -} - -NMVpnConnection * -nm_vpn_connection_new(NMSettingsConnection * settings_connection, - NMDevice * parent_device, - const char * specific_object, - NMActivationReason activation_reason, - NMActivationStateFlags initial_state_flags, - NMAuthSubject * subject) -{ - g_return_val_if_fail(!settings_connection || NM_IS_SETTINGS_CONNECTION(settings_connection), - NULL); - g_return_val_if_fail(NM_IS_DEVICE(parent_device), NULL); - g_return_val_if_fail(specific_object, NULL); - - return g_object_new(NM_TYPE_VPN_CONNECTION, - NM_ACTIVE_CONNECTION_INT_SETTINGS_CONNECTION, - settings_connection, - NM_ACTIVE_CONNECTION_INT_DEVICE, - parent_device, - NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, - specific_object, - NM_ACTIVE_CONNECTION_INT_SUBJECT, - subject, - NM_ACTIVE_CONNECTION_INT_ACTIVATION_REASON, - activation_reason, - NM_ACTIVE_CONNECTION_VPN, - TRUE, - NM_ACTIVE_CONNECTION_STATE_FLAGS, - (guint) initial_state_flags, - NULL); -} + return TRUE; +} const char * nm_vpn_connection_get_service(NMVpnConnection *self) @@ -885,332 +1323,49 @@ nm_vpn_connection_get_service(NMVpnConnection *self) return nm_setting_vpn_get_service_type(s_vpn); } -static NM_UTILS_LOOKUP_STR_DEFINE( - _vpn_plugin_failure_to_string, - NMVpnPluginFailure, - NM_UTILS_LOOKUP_DEFAULT(NULL), - NM_UTILS_LOOKUP_STR_ITEM(NM_VPN_PLUGIN_FAILURE_LOGIN_FAILED, "login-failed"), - NM_UTILS_LOOKUP_STR_ITEM(NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED, "connect-failed"), - NM_UTILS_LOOKUP_STR_ITEM(NM_VPN_PLUGIN_FAILURE_BAD_IP_CONFIG, "bad-ip-config"), ); - -#define vpn_plugin_failure_to_string_a(failure) \ - NM_UTILS_LOOKUP_STR_A(_vpn_plugin_failure_to_string, failure) - static void -plugin_failed(NMVpnConnection *self, guint reason) +_apply_config(NMVpnConnection *self) { NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - _LOGW("VPN plugin: failed: %s (%d)", vpn_plugin_failure_to_string_a(reason), reason); - - switch (reason) { - case NM_VPN_PLUGIN_FAILURE_LOGIN_FAILED: - priv->failure_reason = NM_ACTIVE_CONNECTION_STATE_REASON_LOGIN_FAILED; - break; - case NM_VPN_PLUGIN_FAILURE_BAD_IP_CONFIG: - priv->failure_reason = NM_ACTIVE_CONNECTION_STATE_REASON_IP_CONFIG_INVALID; - break; - default: - priv->failure_reason = NM_ACTIVE_CONNECTION_STATE_REASON_UNKNOWN; - break; - } -} - -static NM_UTILS_LOOKUP_STR_DEFINE( - _vpn_service_state_to_string, - NMVpnServiceState, - NM_UTILS_LOOKUP_DEFAULT(NULL), - NM_UTILS_LOOKUP_STR_ITEM(NM_VPN_SERVICE_STATE_UNKNOWN, "unknown"), - NM_UTILS_LOOKUP_STR_ITEM(NM_VPN_SERVICE_STATE_INIT, "init"), - NM_UTILS_LOOKUP_STR_ITEM(NM_VPN_SERVICE_STATE_SHUTDOWN, "shutdown"), - NM_UTILS_LOOKUP_STR_ITEM(NM_VPN_SERVICE_STATE_STARTING, "starting"), - NM_UTILS_LOOKUP_STR_ITEM(NM_VPN_SERVICE_STATE_STARTED, "started"), - NM_UTILS_LOOKUP_STR_ITEM(NM_VPN_SERVICE_STATE_STOPPING, "stopping"), - NM_UTILS_LOOKUP_STR_ITEM(NM_VPN_SERVICE_STATE_STOPPED, "stopped"), ); - -#define vpn_service_state_to_string_a(state) \ - NM_UTILS_LOOKUP_STR_A(_vpn_service_state_to_string, state) - -static NM_UTILS_LOOKUP_STR_DEFINE(_vpn_state_to_string, - VpnState, - NM_UTILS_LOOKUP_DEFAULT(NULL), - NM_UTILS_LOOKUP_STR_ITEM(STATE_UNKNOWN, "unknown"), - NM_UTILS_LOOKUP_STR_ITEM(STATE_WAITING, "waiting"), - NM_UTILS_LOOKUP_STR_ITEM(STATE_PREPARE, "prepare"), - NM_UTILS_LOOKUP_STR_ITEM(STATE_NEED_AUTH, "need-auth"), - NM_UTILS_LOOKUP_STR_ITEM(STATE_CONNECT, "connect"), - NM_UTILS_LOOKUP_STR_ITEM(STATE_IP_CONFIG_GET, "ip-config-get"), - NM_UTILS_LOOKUP_STR_ITEM(STATE_PRE_UP, "pre-up"), - NM_UTILS_LOOKUP_STR_ITEM(STATE_ACTIVATED, "activated"), - NM_UTILS_LOOKUP_STR_ITEM(STATE_DEACTIVATING, "deactivating"), - NM_UTILS_LOOKUP_STR_ITEM(STATE_DISCONNECTED, "disconnected"), - NM_UTILS_LOOKUP_STR_ITEM(STATE_FAILED, "failed"), ); - -#define vpn_state_to_string_a(state) NM_UTILS_LOOKUP_STR_A(_vpn_state_to_string, state) - -static void -plugin_state_changed(NMVpnConnection *self, NMVpnServiceState new_service_state) -{ - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - NMVpnServiceState old_service_state = priv->service_state; - - _LOGI("VPN plugin: state changed: %s (%d)", - vpn_service_state_to_string_a(new_service_state), - new_service_state); - priv->service_state = new_service_state; + _LOGT("apply-config"); - if (new_service_state == NM_VPN_SERVICE_STATE_STOPPED) { - if ((priv->vpn_state >= STATE_WAITING) && (priv->vpn_state <= STATE_ACTIVATED)) { - VpnState old_state = priv->vpn_state; - - _set_vpn_state(self, STATE_FAILED, priv->failure_reason, FALSE); - - /* Reset the failure reason */ - priv->failure_reason = NM_ACTIVE_CONNECTION_STATE_REASON_UNKNOWN; - - /* If the connection failed, the service cannot persist, but the - * connection can persist, ask listeners to re-activate the connection. - */ - if (old_state == STATE_ACTIVATED && priv->vpn_state == STATE_FAILED - && _connection_only_can_persist(self)) - g_signal_emit(self, signals[INTERNAL_RETRY_AFTER_FAILURE], 0); - } - } else if (new_service_state == NM_VPN_SERVICE_STATE_STARTING - && old_service_state == NM_VPN_SERVICE_STATE_STARTED) { - /* The VPN service got disconnected and is attempting to reconnect */ - _set_vpn_state(self, - STATE_CONNECT, - NM_ACTIVE_CONNECTION_STATE_REASON_CONNECT_TIMEOUT, - FALSE); - } -} - -static void -print_vpn_config(NMVpnConnection *self) -{ - NMVpnConnectionPrivate * priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - const NMPlatformIP4Address *address4; - const NMPlatformIP6Address *address6; - char * dns_domain = NULL; - guint32 num, i; - char b1[NM_UTILS_INET_ADDRSTRLEN]; - char b2[NM_UTILS_INET_ADDRSTRLEN]; - NMDedupMultiIter ipconf_iter; - - if (priv->ip4_external_gw) { - _LOGI("Data: VPN Gateway: %s", _nm_utils_inet4_ntop(priv->ip4_external_gw, b1)); - } else if (priv->ip6_external_gw) { - _LOGI("Data: VPN Gateway: %s", _nm_utils_inet6_ntop(priv->ip6_external_gw, b1)); - } - - _LOGI("Data: Tunnel Device: %s%s%s", NM_PRINT_FMT_QUOTE_STRING(priv->ip_iface)); - - if (priv->ip4_config) { - const NMPlatformIP4Route *route; - - _LOGI("Data: IPv4 configuration:"); - - address4 = nm_ip4_config_get_first_address(priv->ip4_config); - nm_assert(address4); - - if (priv->ip4_internal_gw) - _LOGI("Data: Internal Gateway: %s", _nm_utils_inet4_ntop(priv->ip4_internal_gw, b1)); - _LOGI("Data: Internal Address: %s", - address4 ? _nm_utils_inet4_ntop(address4->address, b1) : "??"); - _LOGI("Data: Internal Prefix: %d", address4 ? (int) address4->plen : -1); - _LOGI("Data: Internal Point-to-Point Address: %s", - _nm_utils_inet4_ntop(address4->peer_address, b1)); - - nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, priv->ip4_config, &route) { - _LOGI("Data: Static Route: %s/%d Next Hop: %s", - _nm_utils_inet4_ntop(route->network, b1), - route->plen, - _nm_utils_inet4_ntop(route->gateway, b2)); - } - - num = nm_ip4_config_get_num_nameservers(priv->ip4_config); - for (i = 0; i < num; i++) { - _LOGI("Data: Internal DNS: %s", - _nm_utils_inet4_ntop(nm_ip4_config_get_nameserver(priv->ip4_config, i), b1)); - } - - if (nm_ip4_config_get_num_domains(priv->ip4_config) > 0) - dns_domain = (char *) nm_ip4_config_get_domain(priv->ip4_config, 0); - - _LOGI("Data: DNS Domain: '%s'", dns_domain ?: "(none)"); - } else - _LOGI("Data: No IPv4 configuration"); - - if (priv->ip6_config) { - const NMPlatformIP6Route *route; - - _LOGI("Data: IPv6 configuration:"); - - address6 = nm_ip6_config_get_first_address(priv->ip6_config); - nm_assert(address6); - - if (priv->ip6_internal_gw) - _LOGI("Data: Internal Gateway: %s", _nm_utils_inet6_ntop(priv->ip6_internal_gw, b1)); - _LOGI("Data: Internal Address: %s", _nm_utils_inet6_ntop(&address6->address, b1)); - _LOGI("Data: Internal Prefix: %d", address6->plen); - _LOGI("Data: Internal Point-to-Point Address: %s", - _nm_utils_inet6_ntop(&address6->peer_address, b1)); - - nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, priv->ip6_config, &route) { - _LOGI("Data: Static Route: %s/%d Next Hop: %s", - _nm_utils_inet6_ntop(&route->network, b1), - route->plen, - _nm_utils_inet6_ntop(&route->gateway, b2)); - } - - num = nm_ip6_config_get_num_nameservers(priv->ip6_config); - for (i = 0; i < num; i++) { - _LOGI("Data: Internal DNS: %s", - _nm_utils_inet6_ntop(nm_ip6_config_get_nameserver(priv->ip6_config, i), b1)); - } - - if (nm_ip6_config_get_num_domains(priv->ip6_config) > 0) - dns_domain = (char *) nm_ip6_config_get_domain(priv->ip6_config, 0); - - _LOGI("Data: DNS Domain: '%s'", dns_domain ?: "(none)"); - } else - _LOGI("Data: No IPv6 configuration"); - - if (priv->banner && strlen(priv->banner)) { - _LOGI("Data: Login Banner:"); - _LOGI("Data: -----------------------------------------"); - _LOGI("Data: %s", priv->banner); - _LOGI("Data: -----------------------------------------"); - } -} - -static void -apply_parent_device_config(NMVpnConnection *self) -{ - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - NMDevice * parent_dev = nm_active_connection_get_device(NM_ACTIVE_CONNECTION(self)); - int ifindex; - NMIP4Config *vpn4_parent_config = NULL; - NMIP6Config *vpn6_parent_config = NULL; - - ifindex = nm_device_get_ip_ifindex(parent_dev); - if (ifindex > 0) { - /* If the VPN didn't return a network interface, it is a route-based - * VPN (like kernel IPSec) and all IP addressing and routing should - * be done on the parent interface instead. - */ - if (priv->ip4_config) { - vpn4_parent_config = nm_ip4_config_new(nm_netns_get_multi_idx(priv->netns), ifindex); - if (priv->ip_ifindex <= 0) - nm_ip4_config_merge(vpn4_parent_config, - priv->ip4_config, - NM_IP_CONFIG_MERGE_NO_DNS, - 0); - } - if (priv->ip6_config) { - vpn6_parent_config = nm_ip6_config_new(nm_netns_get_multi_idx(priv->netns), ifindex); - if (priv->ip_ifindex <= 0) - nm_ip6_config_merge(vpn6_parent_config, - priv->ip6_config, - NM_IP_CONFIG_MERGE_NO_DNS, - 0); - } - } - - /* Add any explicit route to the VPN gateway through the parent device */ - if (vpn4_parent_config && priv->ip4_external_gw) { - add_ip4_vpn_gateway_route(vpn4_parent_config, - parent_dev, - priv->ip4_external_gw, - nm_netns_get_platform(priv->netns)); - } - if (vpn6_parent_config && priv->ip6_external_gw) { - add_ip6_vpn_gateway_route(vpn6_parent_config, - parent_dev, - priv->ip6_external_gw, - nm_netns_get_platform(priv->netns)); + if (priv->ifindex_if > 0) { + nm_platform_link_change_flags(nm_netns_get_platform(priv->netns), + priv->ifindex_if, + IFF_UP, + TRUE); } - nm_device_replace_vpn4_config(parent_dev, priv->last_device_ip4_config, vpn4_parent_config); - g_clear_object(&priv->last_device_ip4_config); - priv->last_device_ip4_config = vpn4_parent_config; - - nm_device_replace_vpn6_config(parent_dev, priv->last_device_ip6_config, vpn6_parent_config); - g_clear_object(&priv->last_device_ip6_config); - priv->last_device_ip6_config = vpn6_parent_config; -} - -static gboolean -nm_vpn_connection_apply_config(NMVpnConnection *self) -{ - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - - apply_parent_device_config(self); - - if (priv->ip_ifindex > 0) { + if (priv->ifindex_dev > 0) { nm_platform_link_change_flags(nm_netns_get_platform(priv->netns), - priv->ip_ifindex, + priv->ifindex_dev, IFF_UP, TRUE); + } - if (priv->ip4_config) { - nm_assert(priv->ip_ifindex == nm_ip4_config_get_ifindex(priv->ip4_config)); - if (!nm_ip4_config_commit(priv->ip4_config, - nm_netns_get_platform(priv->netns), - get_route_table(self, AF_INET, FALSE) - ? NM_IP_ROUTE_TABLE_SYNC_MODE_FULL - : NM_IP_ROUTE_TABLE_SYNC_MODE_MAIN)) - return FALSE; - nm_platform_ip4_dev_route_blacklist_set(nm_netns_get_platform(priv->netns), - priv->ip_ifindex, - priv->ip4_dev_route_blacklist); - } - - if (priv->ip6_config) { - nm_assert(priv->ip_ifindex == nm_ip6_config_get_ifindex(priv->ip6_config)); - if (!nm_ip6_config_commit(priv->ip6_config, - nm_netns_get_platform(priv->netns), - get_route_table(self, AF_INET6, FALSE) - ? NM_IP_ROUTE_TABLE_SYNC_MODE_FULL - : NM_IP_ROUTE_TABLE_SYNC_MODE_MAIN, - NULL)) - return FALSE; - } - + if (priv->ifindex_if > 0 && priv->ifindex_if != priv->ifindex_dev) { if (priv->mtu && priv->mtu != nm_platform_link_get_mtu(nm_netns_get_platform(priv->netns), - priv->ip_ifindex)) + priv->ifindex_if)) nm_platform_link_set_mtu(nm_netns_get_platform(priv->netns), - priv->ip_ifindex, + priv->ifindex_if, priv->mtu); } - _LOGI("VPN connection: (IP Config Get) complete"); - if (priv->vpn_state < STATE_PRE_UP) - _set_vpn_state(self, STATE_PRE_UP, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); - return TRUE; -} - -static void -_cleanup_failed_config(NMVpnConnection *self) -{ - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + priv->wait_for_pre_up_state = TRUE; - nm_dbus_object_clear_and_unexport(&priv->ip4_config); - nm_dbus_object_clear_and_unexport(&priv->ip6_config); - - _LOGW("VPN connection: did not receive valid IP config information"); - _set_vpn_state(self, STATE_FAILED, NM_ACTIVE_CONNECTION_STATE_REASON_IP_CONFIG_INVALID, FALSE); + _l3cfg_l3cd_update_all(self); } static void -fw_change_zone_cb(NMFirewalldManager * firewalld_manager, +fw_change_zone_cb(NMFirewalldManager *firewalld_manager, NMFirewalldManagerCallId *call_id, - GError * error, + GError *error, gpointer user_data) { - NMVpnConnection * self = user_data; + NMVpnConnection *self = user_data; NMVpnConnectionPrivate *priv; g_return_if_fail(NM_IS_VPN_CONNECTION(self)); @@ -1223,994 +1378,1072 @@ fw_change_zone_cb(NMFirewalldManager * firewalld_manager, if (nm_utils_error_is_cancelled(error)) return; - if (error) { - // FIXME: fail the activation? - } - - if (!nm_vpn_connection_apply_config(self)) - _cleanup_failed_config(self); + _apply_config(self); } static void -nm_vpn_connection_config_maybe_complete(NMVpnConnection *self, gboolean success) +_check_complete(NMVpnConnection *self, gboolean success) { - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - NMConnection * base_con; - NMSettingConnection * s_con; - const char * zone; + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + NMConnection *connection; + NMSettingConnection *s_con; + const char *zone; + const char *iface; if (priv->vpn_state < STATE_IP_CONFIG_GET || priv->vpn_state > STATE_ACTIVATED) return; if (success) { - if ((priv->has_ip4 && !priv->ip4_config) || (priv->has_ip6 && !priv->ip6_config)) { - /* Need to wait for other config */ + if (!priv->generic_config_received + || (priv->ip_data_4.enabled && !priv->l3cds[L3CD_TYPE_IP_4]) + || (priv->ip_data_6.enabled && !priv->l3cds[L3CD_TYPE_IP_6])) { + /* Need to wait more config. */ return; } } - nm_clear_g_source(&priv->connect_timeout); + nm_clear_g_source_inst(&priv->connect_timeout_source); - if (success) { - print_vpn_config(self); - - /* Add the tunnel interface to the specified firewall zone */ - if (priv->ip_iface) { - base_con = _get_applied_connection(self); - s_con = nm_connection_get_setting_connection(base_con); - zone = nm_setting_connection_get_zone(s_con); - - _LOGD("setting firewall zone %s%s%s for '%s'", - NM_PRINT_FMT_QUOTED(zone, "'", zone, "'", "(default)"), - priv->ip_iface); - fw_call_cleanup(self); - priv->fw_call = nm_firewalld_manager_add_or_change_zone(nm_firewalld_manager_get(), - priv->ip_iface, - zone, - FALSE, - fw_change_zone_cb, - self); - return; - } else if (nm_vpn_connection_apply_config(self)) - return; + if (!success) { + _LOGW("did not receive valid IP config information"); + _set_vpn_state(self, + STATE_FAILED, + NM_ACTIVE_CONNECTION_STATE_REASON_IP_CONFIG_INVALID, + FALSE); + return; + } + + connection = _get_applied_connection(self); + + l3cd = nm_l3_config_data_new_from_connection(nm_netns_get_multi_idx(priv->netns), + nm_vpn_connection_get_ip_ifindex(self, TRUE), + connection); + _l3cfg_l3cd_set(self, L3CD_TYPE_STATIC, l3cd); + + _l3cfg_l3cd_gw_extern_update(self); + + iface = nm_vpn_connection_get_ip_iface(self, FALSE); + + /* Add the tunnel interface to the specified firewall zone */ + if (iface) { + s_con = nm_connection_get_setting_connection(connection); + zone = nm_setting_connection_get_zone(s_con); + + fw_call_cleanup(self); + priv->fw_call = nm_firewalld_manager_add_or_change_zone(nm_firewalld_manager_get(), + iface, + zone, + FALSE, + fw_change_zone_cb, + self); + return; } - _cleanup_failed_config(self); + _apply_config(self); } static gboolean -ip6_addr_from_variant(GVariant *v, struct in6_addr *addr) +_vardict_to_addr(int addr_family, GVariant *dict, const char *key, gpointer dst) { - const guint8 *bytes; - gsize len; + guint32 u32; - g_return_val_if_fail(v, FALSE); - g_return_val_if_fail(addr, FALSE); + if (!NM_IS_IPv4(addr_family)) { + gs_unref_variant GVariant *v = NULL; - if (g_variant_is_of_type(v, G_VARIANT_TYPE("ay"))) { - bytes = g_variant_get_fixed_array(v, &len, sizeof(guint8)); - if (len == sizeof(struct in6_addr) && !IN6_IS_ADDR_UNSPECIFIED(bytes)) { - memcpy(addr, bytes, len); - return TRUE; + if (g_variant_lookup(dict, key, "@ay", &v)) { + if (nm_ip_addr_set_from_variant(AF_INET6, dst, v, NULL)) + return TRUE; } + nm_ip_addr_set(AF_INET6, dst, &nm_ip_addr_zero.addr6); + return FALSE; + } + + /* The way we encode IPv4 addresses is not endianness safe. It works well enough + * on the same host and as we know that the VPN plugin sends the address in the + * same endianness that we expect. + * + * But we read a u32 (natively), and that happens to be already in the right + * endianness to be used directly as IPv4 address. */ + if (g_variant_lookup(dict, key, "u", &u32)) { + unaligned_write_ne32(dst, u32); + return TRUE; } + unaligned_write_ne32(dst, 0); return FALSE; } -static struct in6_addr * -ip6_addr_dup_from_variant(GVariant *v) +guint32 +nm_vpn_connection_get_ip_route_metric(NMVpnConnection *self, int addr_family) { - struct in6_addr *addr; + gint64 route_metric = -1; + NMConnection *applied; - addr = g_malloc0(sizeof(*addr)); - if (ip6_addr_from_variant(v, addr)) - return addr; - g_free(addr); - return NULL; + applied = _get_applied_connection(self); + if (!applied) + g_return_val_if_reached(NM_VPN_ROUTE_METRIC_DEFAULT); + + route_metric = nm_setting_ip_config_get_route_metric( + nm_connection_get_setting_ip_config(applied, addr_family)); + return (route_metric >= 0) ? route_metric : NM_VPN_ROUTE_METRIC_DEFAULT; } -static gboolean -process_generic_config(NMVpnConnection *self, GVariant *dict) +static guint32 +get_route_table(NMVpnConnection *self, int addr_family, gboolean fallback_main) { - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - const char * str; - GVariant * v; - guint32 u32; - gboolean b; - - if (g_variant_lookup(dict, NM_VPN_PLUGIN_CAN_PERSIST, "b", &b) && b) { - /* Defaults to FALSE, so only let service indicate TRUE */ - priv->service_can_persist = TRUE; - } + NMConnection *connection; + NMSettingIPConfig *s_ip; + guint32 route_table = 0; - nm_clear_g_free(&priv->ip_iface); - priv->ip_ifindex = 0; + nm_assert(NM_IN_SET(addr_family, AF_INET, AF_INET6)); - if (g_variant_lookup(dict, NM_VPN_PLUGIN_CONFIG_TUNDEV, "&s", &str)) { - /* Backwards compat with NM-openswan */ - if (g_strcmp0(str, "_none_") != 0) - priv->ip_iface = g_strdup(str); + connection = _get_applied_connection(self); + if (connection) { + s_ip = nm_connection_get_setting_ip_config(connection, addr_family); + if (s_ip) + route_table = nm_setting_ip_config_get_route_table(s_ip); } - if (priv->ip_iface) { - /* Grab the interface index for address/routing operations */ - priv->ip_ifindex = - nm_platform_link_get_ifindex(nm_netns_get_platform(priv->netns), priv->ip_iface); - if (priv->ip_ifindex <= 0) { - nm_platform_process_events(nm_netns_get_platform(priv->netns)); - priv->ip_ifindex = - nm_platform_link_get_ifindex(nm_netns_get_platform(priv->netns), priv->ip_iface); - } - if (priv->ip_ifindex <= 0) { - _LOGE("failed to look up VPN interface index for \"%s\"", priv->ip_iface); - nm_clear_g_free(&priv->ip_iface); - priv->ip_ifindex = 0; - nm_vpn_connection_config_maybe_complete(self, FALSE); - return FALSE; - } - } + return route_table ?: (fallback_main ? RT_TABLE_MAIN : 0); +} - nm_clear_g_free(&priv->banner); - if (g_variant_lookup(dict, NM_VPN_PLUGIN_CONFIG_BANNER, "&s", &str)) { - priv->banner = g_strdup(str); - _notify(self, PROP_BANNER); - } +static gboolean +connect_timeout_cb(gpointer user_data) +{ + NMVpnConnection *self = NM_VPN_CONNECTION(user_data); + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - /* Proxy Config */ - g_clear_object(&priv->proxy_config); - priv->proxy_config = nm_proxy_config_new(); + nm_clear_g_source_inst(&priv->connect_timeout_source); - if (g_variant_lookup(dict, NM_VPN_PLUGIN_CONFIG_PROXY_PAC, "&s", &str)) { - nm_proxy_config_set_method(priv->proxy_config, NM_PROXY_CONFIG_METHOD_AUTO); - nm_proxy_config_set_pac_url(priv->proxy_config, str); - } else - nm_proxy_config_set_method(priv->proxy_config, NM_PROXY_CONFIG_METHOD_NONE); - - /* User overrides if any from the NMConnection's Proxy settings */ - nm_proxy_config_merge_setting(priv->proxy_config, - nm_connection_get_setting_proxy(_get_applied_connection(self))); - - /* External world-visible address of the VPN server */ - priv->ip4_external_gw = 0; - nm_clear_g_free(&priv->ip6_external_gw); - - if (g_variant_lookup(dict, NM_VPN_PLUGIN_CONFIG_EXT_GATEWAY, "u", &u32)) { - priv->ip4_external_gw = u32; - } else if (g_variant_lookup(dict, NM_VPN_PLUGIN_CONFIG_EXT_GATEWAY, "@ay", &v)) { - priv->ip6_external_gw = ip6_addr_dup_from_variant(v); - g_variant_unref(v); - - if (!priv->ip6_external_gw) { - _LOGE("Invalid IPv6 VPN gateway address received"); - nm_vpn_connection_config_maybe_complete(self, FALSE); - return FALSE; - } + /* Cancel activation if it's taken too long */ + if (priv->vpn_state == STATE_CONNECT || priv->vpn_state == STATE_IP_CONFIG_GET) { + _LOGW("connect timeout exceeded"); + _set_vpn_state(self, + STATE_FAILED, + NM_ACTIVE_CONNECTION_STATE_REASON_CONNECT_TIMEOUT, + FALSE); } - priv->mtu = 0; - if (g_variant_lookup(dict, NM_VPN_PLUGIN_CONFIG_MTU, "u", &u32)) - priv->mtu = u32; - - return TRUE; + return G_SOURCE_CONTINUE; } static void -nm_vpn_connection_config_get(NMVpnConnection *self, GVariant *dict) +connect_success(NMVpnConnection *self) { NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - gboolean b; - g_return_if_fail(dict && g_variant_is_of_type(dict, G_VARIANT_TYPE_VARDICT)); + priv->connect_timeout_source = + nm_g_timeout_add_seconds_source(_get_vpn_timeout(self), connect_timeout_cb, self); - _LOGI("VPN connection: (IP Config Get) reply received."); + nm_clear_pointer(&priv->connect_hash, g_variant_unref); +} - if (priv->vpn_state == STATE_CONNECT) - _set_vpn_state(self, STATE_IP_CONFIG_GET, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); +static void +connect_cb(GObject *source, GAsyncResult *result, gpointer user_data) +{ + NMVpnConnection *self; + gs_unref_variant GVariant *res = NULL; + gs_free_error GError *error = NULL; - if (!process_generic_config(self, dict)) + res = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), result, &error); + if (nm_utils_error_is_cancelled(error)) return; - /* Note whether to expect IPv4 and IPv6 configs */ - priv->has_ip4 = FALSE; - if (g_variant_lookup(dict, NM_VPN_PLUGIN_CONFIG_HAS_IP4, "b", &b)) - priv->has_ip4 = b; - nm_dbus_object_clear_and_unexport(&priv->ip4_config); - - priv->has_ip6 = FALSE; - if (g_variant_lookup(dict, NM_VPN_PLUGIN_CONFIG_HAS_IP6, "b", &b)) - priv->has_ip6 = b; - nm_dbus_object_clear_and_unexport(&priv->ip6_config); + self = NM_VPN_CONNECTION(user_data); - nm_vpn_connection_config_maybe_complete(self, TRUE); + if (error) { + g_dbus_error_strip_remote_error(error); + _LOGW("failed to connect: '%s'", error->message); + _set_vpn_state(self, + STATE_FAILED, + NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_FAILED, + FALSE); + } else + connect_success(self); } -guint32 -nm_vpn_connection_get_ip4_route_metric(NMVpnConnection *self) +static void +connect_interactive_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - gint64 route_metric; - NMConnection *applied; + NMVpnConnection *self; + NMVpnConnectionPrivate *priv; + gs_unref_variant GVariant *res = NULL; + gs_free_error GError *error = NULL; - applied = _get_applied_connection(self); - route_metric = - nm_setting_ip_config_get_route_metric(nm_connection_get_setting_ip4_config(applied)); + res = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), result, &error); + if (nm_utils_error_is_cancelled(error)) + return; - return (route_metric >= 0) ? route_metric : NM_VPN_ROUTE_METRIC_DEFAULT; -} + self = NM_VPN_CONNECTION(user_data); + priv = NM_VPN_CONNECTION_GET_PRIVATE(self); -guint32 -nm_vpn_connection_get_ip6_route_metric(NMVpnConnection *self) -{ - gint64 route_metric; - NMConnection *applied; + if (g_error_matches(error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_INTERACTIVE_NOT_SUPPORTED) + && priv->dbus.bus_name) { + _LOGD("connect: falling back to non-interactive connect"); + _dbus_connection_call(self, + "Connect", + g_variant_new("(@a{sa{sv}})", priv->connect_hash), + G_VARIANT_TYPE("()"), + connect_cb); + return; + } - applied = _get_applied_connection(self); - route_metric = - nm_setting_ip_config_get_route_metric(nm_connection_get_setting_ip6_config(applied)); + if (error) { + _LOGW("connect: failed to connect interactively: '%s'", error->message); + _set_vpn_state(self, + STATE_FAILED, + NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_FAILED, + FALSE); + return; + } - return (route_metric >= 0) ? route_metric : NM_VPN_ROUTE_METRIC_DEFAULT; + _LOGD("connect: success from ConnectInteractive"); + connect_success(self); } -static guint32 -get_route_table(NMVpnConnection *self, int addr_family, gboolean fallback_main) +/* Add a username to a hashed connection */ +static GVariant * +_hash_with_username(NMConnection *connection, const char *username) { - NMConnection * connection; - NMSettingIPConfig *s_ip; - guint32 route_table = 0; + gs_unref_object NMConnection *dup = NULL; + NMSettingVpn *s_vpn; - nm_assert(NM_IN_SET(addr_family, AF_INET, AF_INET6)); + /* Shortcut if we weren't given a username or if there already was one in + * the VPN setting; don't bother duplicating the connection and everything. + */ + s_vpn = nm_connection_get_setting_vpn(connection); + g_return_val_if_fail(s_vpn, NULL); - connection = _get_applied_connection(self); - if (connection) { - s_ip = nm_connection_get_setting_ip_config(connection, addr_family); - if (s_ip) - route_table = nm_setting_ip_config_get_route_table(s_ip); - } + if (!username || nm_setting_vpn_get_user_name(s_vpn)) + return nm_connection_to_dbus(connection, NM_CONNECTION_SERIALIZE_ALL); - return route_table ?: (fallback_main ? RT_TABLE_MAIN : 0); -} + dup = nm_simple_connection_new_clone(connection); + nm_assert(dup); -static gboolean -_is_device_vrf(NMVpnConnection *self) -{ - NMDevice *parent; - NMDevice *master; + s_vpn = nm_connection_get_setting_vpn(dup); + g_return_val_if_fail(s_vpn, NULL); - parent = nm_active_connection_get_device(NM_ACTIVE_CONNECTION(self)); - if (!parent) - return FALSE; + g_object_set(s_vpn, NM_SETTING_VPN_USER_NAME, username, NULL); - master = nm_device_get_master(parent); - return master && nm_device_get_link_type(master) == NM_LINK_TYPE_VRF; + return nm_connection_to_dbus(dup, NM_CONNECTION_SERIALIZE_ALL); } static void -nm_vpn_connection_ip4_config_get(NMVpnConnection *self, GVariant *dict) +really_activate(NMVpnConnection *self, const char *username) { - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - NMPlatformIP4Address address; - guint32 u32, route_metric; - NMSettingIPConfig * s_ip; - NMSettingConnection * s_con; - guint32 route_table; - NMIP4Config * config; - GVariantIter * iter; - const char * str; - GVariant * v; - gboolean b; - int ip_ifindex; - guint32 mss = 0; - gboolean never_default = FALSE; + NMVpnConnectionPrivate *priv; + GVariantBuilder details; - g_return_if_fail(dict && g_variant_is_of_type(dict, G_VARIANT_TYPE_VARDICT)); + g_return_if_fail(NM_IS_VPN_CONNECTION(self)); - if (priv->vpn_state == STATE_CONNECT) - _set_vpn_state(self, STATE_IP_CONFIG_GET, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); + priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + g_return_if_fail(priv->vpn_state == STATE_NEED_AUTH); - if (priv->vpn_state > STATE_ACTIVATED) { - _LOGI("VPN connection: (IP4 Config Get) ignoring, the connection is no longer active"); + nm_clear_pointer(&priv->connect_hash, g_variant_unref); + priv->connect_hash = _hash_with_username(_get_applied_connection(self), username); + g_variant_ref_sink(priv->connect_hash); + + if (!priv->dbus.bus_name) { + _set_vpn_state(self, + STATE_FAILED, + NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_STOPPED, + FALSE); return; } - if (priv->has_ip4) { - _LOGI("VPN connection: (IP4 Config Get) reply received"); - - if (g_variant_n_children(dict) == 0) { - priv->has_ip4 = FALSE; - nm_vpn_connection_config_maybe_complete(self, TRUE); - return; - } + /* If at least one agent doesn't support VPN hints, then we can't use + * ConnectInteractive(), because that agent won't be able to pass hints + * from the VPN plugin's interactive secrets requests to the VPN authentication + * dialog and we won't get the secrets we need. In this case fall back to + * the old Connect() call. + */ + if (nm_agent_manager_all_agents_have_capability( + nm_agent_manager_get(), + nm_active_connection_get_subject(NM_ACTIVE_CONNECTION(self)), + NM_SECRET_AGENT_CAPABILITY_VPN_HINTS)) { + _LOGD("connect: allowing interactive secrets as all agents have that capability"); + g_variant_builder_init(&details, G_VARIANT_TYPE_VARDICT); + _dbus_connection_call(self, + "ConnectInteractive", + g_variant_new("(@a{sa{sv}}a{sv})", priv->connect_hash, &details), + G_VARIANT_TYPE("()"), + connect_interactive_cb); } else { - _LOGI("VPN connection: (IP4 Config Get) reply received from old-style plugin"); + _LOGD( + "connect: calling old Connect function as not all agents support interactive secrets"); + _dbus_connection_call(self, + "Connect", + g_variant_new("(@a{sa{sv}})", priv->connect_hash), + G_VARIANT_TYPE("()"), + connect_cb); + } - /* In the old API, the generic and IPv4 configuration items - * were mixed together. - */ - if (!process_generic_config(self, dict)) - return; + _set_vpn_state(self, STATE_CONNECT, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); +} - priv->has_ip4 = TRUE; - priv->has_ip6 = FALSE; +static void +_dbus_signal_failure_cb(NMVpnConnection *self, guint32 reason) +{ + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + + _LOGW("dbus: failure: %s (%d)", vpn_plugin_failure_to_string_a(reason), reason); + + switch (reason) { + case NM_VPN_PLUGIN_FAILURE_LOGIN_FAILED: + priv->failure_reason = NM_ACTIVE_CONNECTION_STATE_REASON_LOGIN_FAILED; + break; + case NM_VPN_PLUGIN_FAILURE_BAD_IP_CONFIG: + priv->failure_reason = NM_ACTIVE_CONNECTION_STATE_REASON_IP_CONFIG_INVALID; + break; + default: + priv->failure_reason = NM_ACTIVE_CONNECTION_STATE_REASON_UNKNOWN; + break; } +} - ip_ifindex = nm_vpn_connection_get_ip_ifindex(self, TRUE); - if (ip_ifindex <= 0) - g_return_if_reached(); +static void +_dbus_signal_state_changed_cb(NMVpnConnection *self, guint32 new_service_state) +{ + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + NMVpnServiceState old_service_state = priv->service_state; - config = nm_ip4_config_new(nm_netns_get_multi_idx(priv->netns), ip_ifindex); - nm_ip4_config_set_dns_priority(config, NM_DNS_PRIORITY_DEFAULT_VPN); + _LOGD("dbus: state changed: %s (%d)", + vpn_service_state_to_string_a(new_service_state), + new_service_state); + priv->service_state = new_service_state; - memset(&address, 0, sizeof(address)); - address.plen = 24; + if (new_service_state == NM_VPN_SERVICE_STATE_STOPPED) { + if ((priv->vpn_state >= STATE_WAITING) && (priv->vpn_state <= STATE_ACTIVATED)) { + VpnState old_state = priv->vpn_state; + + _set_vpn_state(self, STATE_FAILED, priv->failure_reason, FALSE); - /* Internal address of the VPN subnet's gateway */ - if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP4_CONFIG_INT_GATEWAY, "u", &u32)) - priv->ip4_internal_gw = u32; + /* Reset the failure reason */ + priv->failure_reason = NM_ACTIVE_CONNECTION_STATE_REASON_UNKNOWN; + + /* If the connection failed, the service cannot persist, but the + * connection can persist, ask listeners to re-activate the connection. + */ + if (old_state == STATE_ACTIVATED && priv->vpn_state == STATE_FAILED + && _connection_only_can_persist(self)) + g_signal_emit(self, signals[INTERNAL_RETRY_AFTER_FAILURE], 0); + } + } else if (new_service_state == NM_VPN_SERVICE_STATE_STARTING + && old_service_state == NM_VPN_SERVICE_STATE_STARTED) { + /* The VPN service got disconnected and is attempting to reconnect */ + _set_vpn_state(self, + STATE_CONNECT, + NM_ACTIVE_CONNECTION_STATE_REASON_CONNECT_TIMEOUT, + FALSE); + } +} - if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP4_CONFIG_ADDRESS, "u", &u32)) - address.address = u32; +static gboolean +_config_process_generic(NMVpnConnection *self, GVariant *dict) +{ + nm_auto_g_object_thaw_notify GObject *self_thaw = NULL; + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + int IS_IPv4; + int ip_ifindex = 0; + const char *v_str; + guint32 v_u32; + gboolean v_b; + + if (g_variant_lookup(dict, NM_VPN_PLUGIN_CONFIG_TUNDEV, "&s", &v_str)) { + const char *iface = NULL; + + /* Backwards compat with NM-openswan/libreswan */ + if (!NM_IN_STRSET(v_str, "", "_none_")) + iface = v_str; + + if (iface) { + NMPlatform *platform = nm_netns_get_platform(priv->netns); + + ip_ifindex = nm_platform_link_get_ifindex(platform, iface); + if (ip_ifindex <= 0) { + nm_platform_process_events(platform); + ip_ifindex = nm_platform_link_get_ifindex(platform, iface); + } + if (ip_ifindex <= 0) { + _LOGW("config: failed to look up VPN interface index for \"%s\"", iface); + return FALSE; + } + } + } - if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP4_CONFIG_PTP, "u", &u32)) - address.peer_address = u32; - else - address.peer_address = address.address; + self_thaw = nm_g_object_freeze_notify(self); - if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP4_CONFIG_PREFIX, "u", &u32)) - address.plen = u32; + _set_ip_ifindex(self, ip_ifindex, TRUE); + _set_ip_ifindex(self, _get_ifindex_for_device(self), FALSE); - if (address.address && address.plen && address.plen <= 32) { - address.addr_source = NM_IP_CONFIG_SOURCE_VPN; - nm_ip4_config_add_address(config, &address); - } else { - _LOGW("invalid IP4 config received!"); - g_object_unref(config); - nm_vpn_connection_config_maybe_complete(self, FALSE); - return; + ip_ifindex = nm_vpn_connection_get_ip_ifindex(self, TRUE); + if (ip_ifindex <= 0) { + _LOGW("config: no ip-ifindex for the VPN"); + return FALSE; } - if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP4_CONFIG_DNS, "au", &iter)) { - while (g_variant_iter_next(iter, "u", &u32)) - nm_ip4_config_add_nameserver(config, u32); - g_variant_iter_free(iter); + for (IS_IPv4 = 1; IS_IPv4 >= 0; IS_IPv4--) { + NML3Cfg *l3cfg = priv->l3cfg_if ?: priv->l3cfg_dev; + gs_unref_object NMIPConfig *ipconfig_old = NULL; + + ipconfig_old = g_steal_pointer(&priv->ip_data_x[IS_IPv4].ip_config); + if (l3cfg) { + priv->ip_data_x[IS_IPv4].ip_config = + nm_l3cfg_ipconfig_acquire(l3cfg, IS_IPv4 ? AF_INET : AF_INET6); + } + g_object_notify(G_OBJECT(self), + IS_IPv4 ? NM_ACTIVE_CONNECTION_IP4_CONFIG + : NM_ACTIVE_CONNECTION_IP6_CONFIG); } - if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP4_CONFIG_NBNS, "au", &iter)) { - while (g_variant_iter_next(iter, "u", &u32)) - nm_ip4_config_add_wins(config, u32); - g_variant_iter_free(iter); + if (g_variant_lookup(dict, NM_VPN_PLUGIN_CAN_PERSIST, "b", &v_b) && v_b) { + /* Defaults to FALSE, so only let service indicate TRUE */ + priv->service_can_persist = TRUE; } - if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP4_CONFIG_MSS, "u", &u32)) - mss = u32; + if (!g_variant_lookup(dict, NM_VPN_PLUGIN_CONFIG_BANNER, "&s", &v_str)) + v_str = NULL; + if (nm_strdup_reset(&priv->banner, v_str)) + _notify(self, PROP_BANNER); - if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP4_CONFIG_DOMAIN, "&s", &str)) - nm_ip4_config_add_domain(config, str); + _vardict_to_addr(AF_INET, dict, NM_VPN_PLUGIN_CONFIG_EXT_GATEWAY, &priv->ip_data_4.gw_external); + _vardict_to_addr(AF_INET6, + dict, + NM_VPN_PLUGIN_CONFIG_EXT_GATEWAY, + &priv->ip_data_6.gw_external); - if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP4_CONFIG_DOMAINS, "as", &iter)) { - while (g_variant_iter_next(iter, "&s", &str)) - nm_ip4_config_add_domain(config, str); - g_variant_iter_free(iter); + if (nm_ip_addr_is_null(AF_INET, &priv->ip_data_4.gw_external) + && nm_ip_addr_is_null(AF_INET6, &priv->ip_data_6.gw_external)) { + _LOGW("config: no VPN gateway address received"); + return FALSE; } - route_table = get_route_table(self, AF_INET, TRUE); - route_metric = nm_vpn_connection_get_ip4_route_metric(self); - s_ip = nm_connection_get_setting_ip4_config(_get_applied_connection(self)); - s_con = nm_connection_get_setting_connection(_get_applied_connection(self)); - - if (nm_setting_ip_config_get_ignore_auto_routes(s_ip)) { - /* ignore VPN routes */ - } else if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP4_CONFIG_PRESERVE_ROUTES, "b", &b) && b) { - if (priv->ip4_config) { - NMDedupMultiIter ipconf_iter; - const NMPlatformIP4Route *route; + l3cd = _l3cfg_l3cd_new(self, ip_ifindex); - nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, priv->ip4_config, &route) - nm_ip4_config_add_route(config, route, NULL); - } - } else if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP4_CONFIG_ROUTES, "aau", &iter)) { - while (g_variant_iter_next(iter, "@au", &v)) { - NMPlatformIP4Route route = { - 0, - }; - guint32 plen; - - switch (g_variant_n_children(v)) { - case 5: - g_variant_get_child(v, 4, "u", &route.pref_src); - /* fall-through */ - case 4: - g_variant_get_child(v, 0, "u", &route.network); - g_variant_get_child(v, 1, "u", &plen); - g_variant_get_child(v, 2, "u", &route.gateway); - /* 4th item is unused route metric */ - route.table_coerced = nm_platform_route_table_coerce(route_table); - route.metric = route_metric; - route.rt_source = NM_IP_CONFIG_SOURCE_VPN; - - if (plen > 32) - break; - route.plen = plen; - route.network = nm_utils_ip4_address_clear_host_address(route.network, plen); - - if (priv->ip4_external_gw && route.network == priv->ip4_external_gw - && route.plen == 32) { - /* Ignore host routes to the VPN gateway since NM adds one itself - * below. Since NM knows more about the routing situation than - * the VPN server, we want to use the NM created route instead of - * whatever the server provides. - */ - break; - } - - nm_ip4_config_add_route(config, &route, NULL); - break; - default: - break; - } - g_variant_unref(v); - } - g_variant_iter_free(iter); - } - - if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP4_CONFIG_NEVER_DEFAULT, "b", &b)) - never_default = b; - - /* Merge in user overrides from the NMConnection's IPv4 setting */ - nm_ip4_config_merge_setting(config, - s_ip, - nm_setting_connection_get_mdns(s_con), - nm_setting_connection_get_llmnr(s_con), - nm_setting_connection_get_dns_over_tls(s_con), - route_table, - route_metric); - - if (!never_default && !nm_setting_ip_config_get_never_default(s_ip)) { - const NMPlatformIP4Route r = { - .ifindex = ip_ifindex, - .rt_source = NM_IP_CONFIG_SOURCE_VPN, - .gateway = priv->ip4_internal_gw, - .table_coerced = nm_platform_route_table_coerce(route_table), - .metric = route_metric, - .mss = mss, - }; + if (g_variant_lookup(dict, NM_VPN_PLUGIN_CONFIG_PROXY_PAC, "&s", &v_str)) { + nm_l3_config_data_set_proxy_method(l3cd, NM_PROXY_CONFIG_METHOD_AUTO); + nm_l3_config_data_set_proxy_pac_url(l3cd, v_str); + } else + nm_l3_config_data_set_proxy_method(l3cd, NM_PROXY_CONFIG_METHOD_NONE); - nm_ip4_config_add_route(config, &r, NULL); - } + if (g_variant_lookup(dict, NM_VPN_PLUGIN_CONFIG_MTU, "u", &v_u32)) + priv->mtu = v_u32; + else + priv->mtu = 0; - nm_clear_pointer(&priv->ip4_dev_route_blacklist, g_ptr_array_unref); + priv->generic_config_received = TRUE; - nm_ip4_config_add_dependent_routes(config, - route_table, - nm_vpn_connection_get_ip4_route_metric(self), - _is_device_vrf(self), - &priv->ip4_dev_route_blacklist); + nm_g_object_thaw_notify_clear(&self_thaw); - if (priv->ip4_config) { - nm_ip4_config_replace(priv->ip4_config, config, NULL); - g_object_unref(config); - } else { - priv->ip4_config = config; - nm_dbus_object_export(NM_DBUS_OBJECT(config)); - g_object_notify((GObject *) self, NM_ACTIVE_CONNECTION_IP4_CONFIG); - } + _l3cfg_l3cd_set(self, L3CD_TYPE_GENERIC, l3cd); - nm_vpn_connection_config_maybe_complete(self, TRUE); + return TRUE; } static void -nm_vpn_connection_ip6_config_get(NMVpnConnection *self, GVariant *dict) +_dbus_signal_config_cb(NMVpnConnection *self, GVariant *dict) { NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - NMPlatformIP6Address address; - guint32 u32, route_metric; - NMSettingIPConfig * s_ip; - guint32 route_table; - NMIP6Config * config; - GVariantIter * iter; - const char * str; - GVariant * v; - gboolean b; - int ip_ifindex; - guint32 mss = 0; - gboolean never_default = FALSE; + gboolean v_b; - g_return_if_fail(dict && g_variant_is_of_type(dict, G_VARIANT_TYPE_VARDICT)); - - _LOGI("VPN connection: (IP6 Config Get) reply received"); - - if (priv->vpn_state == STATE_CONNECT) - _set_vpn_state(self, STATE_IP_CONFIG_GET, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); + g_return_if_fail(dict); - if (priv->vpn_state > STATE_ACTIVATED) { - _LOGI("VPN connection: (IP6 Config Get) ignoring, the connection is no longer active"); + if (!g_variant_is_of_type(dict, G_VARIANT_TYPE_VARDICT)) { + _LOGD("config: ignore invalid configuration type"); return; } - if (g_variant_n_children(dict) == 0) { - priv->has_ip6 = FALSE; - nm_vpn_connection_config_maybe_complete(self, TRUE); + if (priv->vpn_state < STATE_NEED_AUTH) { + /* Only list to this signals during and after connection */ + _LOGD("config: ignore configuration before need-auth state"); return; } - ip_ifindex = nm_vpn_connection_get_ip_ifindex(self, TRUE); - if (ip_ifindex <= 0) - g_return_if_reached(); + if (g_variant_lookup(dict, NM_VPN_PLUGIN_CONFIG_HAS_IP4, "b", &v_b)) + priv->ip_data_4.enabled = v_b; + else + priv->ip_data_4.enabled = FALSE; - config = nm_ip6_config_new(nm_netns_get_multi_idx(priv->netns), ip_ifindex); - nm_ip6_config_set_dns_priority(config, NM_DNS_PRIORITY_DEFAULT_VPN); + if (g_variant_lookup(dict, NM_VPN_PLUGIN_CONFIG_HAS_IP6, "b", &v_b)) + priv->ip_data_6.enabled = v_b; + else + priv->ip_data_6.enabled = FALSE; - memset(&address, 0, sizeof(address)); - address.plen = 128; + _LOGD("config: reply received (IPv4:%s, IPv6:%s)", + priv->ip_data_4.enabled ? "on" : "off", + priv->ip_data_6.enabled ? "on" : "off"); - /* Internal address of the VPN subnet's gateway */ - nm_clear_g_free(&priv->ip6_internal_gw); - if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP6_CONFIG_INT_GATEWAY, "@ay", &v)) { - priv->ip6_internal_gw = ip6_addr_dup_from_variant(v); - g_variant_unref(v); - } + if (priv->vpn_state == STATE_CONNECT) + _set_vpn_state(self, STATE_IP_CONFIG_GET, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); - if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP6_CONFIG_ADDRESS, "@ay", &v)) { - ip6_addr_from_variant(v, &address.address); - g_variant_unref(v); + if (!_config_process_generic(self, dict)) { + _check_complete(self, FALSE); + return; } - if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP6_CONFIG_PTP, "@ay", &v)) { - ip6_addr_from_variant(v, &address.peer_address); - g_variant_unref(v); - } + _check_complete(self, TRUE); +} - if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP6_CONFIG_PREFIX, "u", &u32)) - address.plen = u32; +static void +_dbus_signal_ip_config_cb(NMVpnConnection *self, int addr_family, GVariant *dict) +{ + const int IS_IPv4 = NM_IS_IPv4(addr_family); + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + GVariantIter *var_iter; + guint32 u32; + const char *v_str; + NMIPAddr v_addr; + GVariant *v; + gboolean v_b; + int ip_ifindex; + guint32 mss = 0; + gboolean never_default; + NMPlatformIPXAddress address; - if (!IN6_IS_ADDR_UNSPECIFIED(&address.address) && address.plen && address.plen <= 128) { - address.addr_source = NM_IP_CONFIG_SOURCE_VPN; - nm_ip6_config_add_address(config, &address); - } else { - _LOGW("invalid IP6 config received!"); - g_object_unref(config); - nm_vpn_connection_config_maybe_complete(self, FALSE); + g_return_if_fail(dict && g_variant_is_of_type(dict, G_VARIANT_TYPE_VARDICT)); + + if (priv->vpn_state < STATE_NEED_AUTH) { + _LOGD("config%c: ignoring, the connection is not in need-auth state", + nm_utils_addr_family_to_char(addr_family)); return; } - if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP6_CONFIG_DNS, "aay", &iter)) { - while (g_variant_iter_next(iter, "@ay", &v)) { - struct in6_addr dns; - - if (ip6_addr_from_variant(v, &dns)) - nm_ip6_config_add_nameserver(config, &dns); - g_variant_unref(v); - } - g_variant_iter_free(iter); + if (priv->vpn_state > STATE_ACTIVATED) { + _LOGD("config%c: ignoring, the connection is no longer active", + nm_utils_addr_family_to_char(addr_family)); + return; } - if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP6_CONFIG_MSS, "u", &u32)) - mss = u32; - - if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP6_CONFIG_DOMAIN, "&s", &str)) - nm_ip6_config_add_domain(config, str); + if (IS_IPv4) { + if (priv->generic_config_received) { + _LOGD("config4: reply received"); - if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP6_CONFIG_DOMAINS, "as", &iter)) { - while (g_variant_iter_next(iter, "&s", &str)) - nm_ip6_config_add_domain(config, str); - g_variant_iter_free(iter); - } + if (g_variant_n_children(dict) == 0) { + priv->ip_data_4.enabled = FALSE; + _check_complete(self, TRUE); + return; + } + } else { + _LOGD("config4: reply received (old style)"); - route_table = get_route_table(self, AF_INET6, TRUE); - route_metric = nm_vpn_connection_get_ip6_route_metric(self); - s_ip = nm_connection_get_setting_ip6_config(_get_applied_connection(self)); + /* In the old API, the generic and IPv4 configuration items + * were mixed together. + */ + if (!_config_process_generic(self, dict)) { + _check_complete(self, FALSE); + return; + } - if (nm_setting_ip_config_get_ignore_auto_routes(s_ip)) { - /* Ignore VPN routes */ - } else if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP6_CONFIG_PRESERVE_ROUTES, "b", &b) && b) { - if (priv->ip6_config) { - NMDedupMultiIter ipconf_iter; - const NMPlatformIP6Route *route; + priv->ip_data_4.enabled = TRUE; + priv->ip_data_6.enabled = FALSE; + } + } else { + _LOGD("config6: reply received"); - nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, priv->ip6_config, &route) - nm_ip6_config_add_route(config, route, NULL); + if (g_variant_n_children(dict) == 0) { + priv->ip_data_6.enabled = FALSE; + _check_complete(self, TRUE); + return; } - } else if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP6_CONFIG_ROUTES, "a(ayuayu)", &iter)) { - GVariant *dest, *next_hop; - guint32 prefix, metric; + } - while (g_variant_iter_next(iter, "(@ayu@ayu)", &dest, &prefix, &next_hop, &metric)) { - NMPlatformIP6Route route; + if (priv->vpn_state == STATE_CONNECT) { + _set_vpn_state(self, STATE_IP_CONFIG_GET, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); + } - memset(&route, 0, sizeof(route)); + ip_ifindex = nm_vpn_connection_get_ip_ifindex(self, TRUE); + if (ip_ifindex <= 0) + g_return_if_reached(); - if (!ip6_addr_from_variant(dest, &route.network)) - goto next; + l3cd = _l3cfg_l3cd_new(self, ip_ifindex); - if (prefix > 128) - goto next; + nm_l3_config_data_set_dns_priority(l3cd, AF_INET, NM_DNS_PRIORITY_DEFAULT_VPN); - route.plen = prefix; - ip6_addr_from_variant(next_hop, &route.gateway); - route.table_coerced = nm_platform_route_table_coerce(route_table); - route.metric = route_metric; - route.rt_source = NM_IP_CONFIG_SOURCE_VPN; + if (IS_IPv4) { + address.a4 = (NMPlatformIP4Address){ + .plen = 24, + }; + } else { + address.a6 = (NMPlatformIP6Address){ + .plen = 128, + }; + } - nm_utils_ip6_address_clear_host_address(&route.network, &route.network, route.plen); + _vardict_to_addr(addr_family, + dict, + IS_IPv4 ? NM_VPN_PLUGIN_IP4_CONFIG_INT_GATEWAY + : NM_VPN_PLUGIN_IP6_CONFIG_INT_GATEWAY, + &priv->ip_data_x[IS_IPv4].gw_internal); + + _vardict_to_addr(addr_family, + dict, + IS_IPv4 ? NM_VPN_PLUGIN_IP4_CONFIG_ADDRESS : NM_VPN_PLUGIN_IP6_CONFIG_ADDRESS, + address.ax.address_ptr); + + if (!_vardict_to_addr(addr_family, + dict, + IS_IPv4 ? NM_VPN_PLUGIN_IP4_CONFIG_PTP : NM_VPN_PLUGIN_IP6_CONFIG_PTP, + nm_platform_ip_address_get_peer_address(addr_family, &address.ax))) { + if (IS_IPv4) + address.a4.peer_address = address.a4.address; + } + + if (g_variant_lookup(dict, + IS_IPv4 ? NM_VPN_PLUGIN_IP4_CONFIG_PREFIX + : NM_VPN_PLUGIN_IP6_CONFIG_PREFIX, + "u", + &u32)) + address.ax.plen = u32; + + if (address.ax.plen > 0 && address.ax.plen <= (IS_IPv4 ? 32 : 128) + && !nm_ip_addr_is_null(addr_family, &address.ax.address_ptr)) { + address.ax.addr_source = NM_IP_CONFIG_SOURCE_VPN; + nm_l3_config_data_add_address(l3cd, addr_family, NULL, &address.ax); + } else { + _LOGW("invalid IP%c config received: no valid IP address/prefix", + nm_utils_addr_family_to_char(addr_family)); + _check_complete(self, FALSE); + return; + } - if (priv->ip6_external_gw && IN6_ARE_ADDR_EQUAL(&route.network, priv->ip6_external_gw) - && route.plen == 128) { - /* Ignore host routes to the VPN gateway since NM adds one itself. - * Since NM knows more about the routing situation than the VPN - * server, we want to use the NM created route instead of whatever - * the server provides. - */ - goto next; + if (IS_IPv4) { + if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP4_CONFIG_DNS, "au", &var_iter)) { + while (g_variant_iter_next(var_iter, "u", &u32)) + nm_l3_config_data_add_nameserver(l3cd, addr_family, &u32); + g_variant_iter_free(var_iter); + } + } else { + if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP6_CONFIG_DNS, "aay", &var_iter)) { + while (g_variant_iter_next(var_iter, "@ay", &v)) { + if (nm_ip_addr_set_from_variant(AF_INET6, &v_addr, v, NULL)) + nm_l3_config_data_add_nameserver(l3cd, addr_family, &v_addr); + g_variant_unref(v); } - - nm_ip6_config_add_route(config, &route, NULL); - -next: - g_variant_unref(dest); - g_variant_unref(next_hop); + g_variant_iter_free(var_iter); } - g_variant_iter_free(iter); } - if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP6_CONFIG_NEVER_DEFAULT, "b", &b)) - never_default = b; + if (IS_IPv4) { + if (g_variant_lookup(dict, NM_VPN_PLUGIN_IP4_CONFIG_NBNS, "au", &var_iter)) { + while (g_variant_iter_next(var_iter, "u", &u32)) + nm_l3_config_data_add_wins(l3cd, u32); + g_variant_iter_free(var_iter); + } + } - /* Merge in user overrides from the NMConnection's IPv6 setting */ - nm_ip6_config_merge_setting(config, s_ip, route_table, route_metric); + if (g_variant_lookup(dict, + IS_IPv4 ? NM_VPN_PLUGIN_IP4_CONFIG_MSS : NM_VPN_PLUGIN_IP6_CONFIG_MSS, + "u", + &u32)) + mss = u32; - if (!never_default && !nm_setting_ip_config_get_never_default(s_ip)) { - const NMPlatformIP6Route r = { - .ifindex = ip_ifindex, - .rt_source = NM_IP_CONFIG_SOURCE_VPN, - .gateway = *(priv->ip6_internal_gw ?: &in6addr_any), - .table_coerced = nm_platform_route_table_coerce(route_table), - .metric = route_metric, - .mss = mss, - }; + if (g_variant_lookup(dict, + IS_IPv4 ? NM_VPN_PLUGIN_IP4_CONFIG_DOMAIN + : NM_VPN_PLUGIN_IP6_CONFIG_DOMAIN, + "&s", + &v_str)) + nm_l3_config_data_add_domain(l3cd, addr_family, v_str); + + if (g_variant_lookup(dict, + IS_IPv4 ? NM_VPN_PLUGIN_IP4_CONFIG_DOMAINS + : NM_VPN_PLUGIN_IP6_CONFIG_DOMAINS, + "as", + &var_iter)) { + while (g_variant_iter_next(var_iter, "&s", &v_str)) + nm_l3_config_data_add_domain(l3cd, addr_family, v_str); + g_variant_iter_free(var_iter); + } + + if (g_variant_lookup(dict, + IS_IPv4 ? NM_VPN_PLUGIN_IP4_CONFIG_PRESERVE_ROUTES + : NM_VPN_PLUGIN_IP6_CONFIG_PRESERVE_ROUTES, + "b", + &v_b) + && v_b) { + if (priv->l3cds[L3CD_TYPE_IP_X(IS_IPv4)]) { + NMDedupMultiIter ipconf_iter; + const NMPObject *route; + + nm_l3_config_data_iter_obj_for_each (&ipconf_iter, + priv->l3cds[L3CD_TYPE_IP_X(IS_IPv4)], + &route, + NMP_OBJECT_TYPE_IP_ROUTE(IS_IPv4)) + nm_l3_config_data_add_route(l3cd, addr_family, route, NULL); + } + } else if (IS_IPv4 ? g_variant_lookup(dict, NM_VPN_PLUGIN_IP4_CONFIG_ROUTES, "aau", &var_iter) + : g_variant_lookup(dict, + NM_VPN_PLUGIN_IP6_CONFIG_ROUTES, + "a(ayuayu)", + &var_iter)) { + _nm_unused nm_auto_free_variant_iter GVariantIter *var_iter_ref_owner = var_iter; + NMPlatformIPXRoute route = {}; + guint32 plen; + GVariant *next_hop; + GVariant *dest; + guint32 prefix; + guint32 metric; + + if (IS_IPv4) { + while (g_variant_iter_next(var_iter, "@au", &v)) { + _nm_unused gs_unref_variant GVariant *v_ref_owner = v; + + switch (g_variant_n_children(v)) { + case 5: + g_variant_get_child(v, 4, "u", &route.r4.pref_src); + /* fall-through */ + case 4: + g_variant_get_child(v, 0, "u", &route.r4.network); + g_variant_get_child(v, 1, "u", &plen); + g_variant_get_child(v, 2, "u", &route.r4.gateway); + /* 4th item is unused route metric */ + route.r4.table_any = TRUE; + route.r4.metric_any = TRUE; + route.r4.rt_source = NM_IP_CONFIG_SOURCE_VPN; + + if (plen > 32) + break; + route.r4.plen = plen; + route.r4.network = + nm_utils_ip4_address_clear_host_address(route.r4.network, plen); + + if (priv->ip_data_4.gw_external.addr4 + && route.r4.network == priv->ip_data_4.gw_external.addr4 + && route.r4.plen == 32) { + /* Ignore host routes to the VPN gateway since NM adds one itself + * below. Since NM knows more about the routing situation than + * the VPN server, we want to use the NM created route instead of + * whatever the server provides. + */ + break; + } + + nm_l3_config_data_add_route_4(l3cd, &route.r4); + break; + default: + break; + } + } + } else { + while ( + g_variant_iter_next(var_iter, "(@ayu@ayu)", &dest, &prefix, &next_hop, &metric)) { + _nm_unused gs_unref_variant GVariant *next_hop_ref_owner = next_hop; + _nm_unused gs_unref_variant GVariant *dest_ref_owner = dest; + + if (prefix > 128) + continue; + + route.r6 = (NMPlatformIP6Route){ + .plen = prefix, + .table_any = TRUE, + .metric_any = TRUE, + .rt_source = NM_IP_CONFIG_SOURCE_VPN, + }; + + if (!nm_ip_addr_set_from_variant(AF_INET6, &route.r6.network, dest, NULL)) + continue; + + nm_ip_addr_set_from_variant(AF_INET6, &route.r6.gateway, next_hop, NULL); + + nm_utils_ip6_address_clear_host_address(&route.r6.network, + &route.r6.network, + route.r6.plen); + + if (!IN6_IS_ADDR_UNSPECIFIED(&priv->ip_data_6.gw_external.addr6) + && IN6_ARE_ADDR_EQUAL(&route.r6.network, &priv->ip_data_6.gw_external.addr6) + && route.r6.plen == 128) { + /* Ignore host routes to the VPN gateway since NM adds one itself. + * Since NM knows more about the routing situation than the VPN + * server, we want to use the NM created route instead of whatever + * the server provides. + */ + continue; + } - nm_ip6_config_add_route(config, &r, NULL); + nm_l3_config_data_add_route_6(l3cd, &route.r6); + } + } } - nm_ip6_config_add_dependent_routes(config, route_table, route_metric, _is_device_vrf(self)); - - if (priv->ip6_config) { - nm_ip6_config_replace(priv->ip6_config, config, NULL); - g_object_unref(config); - } else { - priv->ip6_config = config; - nm_dbus_object_export(NM_DBUS_OBJECT(config)); - g_object_notify((GObject *) self, NM_ACTIVE_CONNECTION_IP6_CONFIG); + if (g_variant_lookup(dict, + IS_IPv4 ? NM_VPN_PLUGIN_IP4_CONFIG_NEVER_DEFAULT + : NM_VPN_PLUGIN_IP6_CONFIG_NEVER_DEFAULT, + "b", + &v_b)) + never_default = v_b; + else + never_default = FALSE; + + if (!never_default) { + NMPlatformIPXRoute route; + + if (IS_IPv4) { + route.r4 = (NMPlatformIP4Route){ + .ifindex = ip_ifindex, + .rt_source = NM_IP_CONFIG_SOURCE_VPN, + .gateway = priv->ip_data_4.gw_internal.addr4, + .table_any = TRUE, + .metric_any = TRUE, + .mss = mss, + }; + } else { + route.r6 = (NMPlatformIP6Route){ + .ifindex = ip_ifindex, + .rt_source = NM_IP_CONFIG_SOURCE_VPN, + .gateway = priv->ip_data_6.gw_internal.addr6, + .table_any = TRUE, + .metric_any = TRUE, + .mss = mss, + }; + } + nm_l3_config_data_add_route(l3cd, addr_family, NULL, &route.rx); } - nm_vpn_connection_config_maybe_complete(self, TRUE); + _l3cfg_l3cd_set(self, L3CD_TYPE_IP_X(IS_IPv4), l3cd); + + _check_complete(self, TRUE); } -static gboolean -connect_timeout_cb(gpointer user_data) +void +nm_vpn_connection_disconnect(NMVpnConnection *self, + NMActiveConnectionStateReason reason, + gboolean quitting) { - NMVpnConnection * self = NM_VPN_CONNECTION(user_data); - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - - priv->connect_timeout = 0; - - /* Cancel activation if it's taken too long */ - if (priv->vpn_state == STATE_CONNECT || priv->vpn_state == STATE_IP_CONFIG_GET) { - _LOGW("VPN connection: connect timeout exceeded."); - _set_vpn_state(self, - STATE_FAILED, - NM_ACTIVE_CONNECTION_STATE_REASON_CONNECT_TIMEOUT, - FALSE); - } + g_return_if_fail(NM_IS_VPN_CONNECTION(self)); - return FALSE; + _set_vpn_state(self, STATE_DISCONNECTED, reason, quitting); } -static void -connect_success(NMVpnConnection *self) +gboolean +nm_vpn_connection_deactivate(NMVpnConnection *self, + NMActiveConnectionStateReason reason, + gboolean quitting) { - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - NMSettingVpn * s_vpn; - guint32 timeout; + NMVpnConnectionPrivate *priv; - s_vpn = nm_connection_get_setting_vpn(_get_applied_connection(self)); - g_assert(s_vpn); + g_return_val_if_fail(NM_IS_VPN_CONNECTION(self), FALSE); - /* Timeout waiting for IP config signal from VPN service - * It is a configured value or 60 seconds */ - timeout = nm_setting_vpn_get_timeout(s_vpn); - if (timeout == 0) { - timeout = nm_config_data_get_connection_default_int64(NM_CONFIG_GET_DATA, - NM_CON_DEFAULT("vpn.timeout"), - NULL, - 1, - G_MAXUINT32, - 60); - } - priv->connect_timeout = g_timeout_add_seconds(timeout, connect_timeout_cb, self); + priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - nm_clear_pointer(&priv->connect_hash, g_variant_unref); + if (priv->vpn_state <= STATE_UNKNOWN || priv->vpn_state > STATE_DEACTIVATING) + return FALSE; + + _set_vpn_state(self, STATE_DEACTIVATING, reason, quitting); + return TRUE; } +/*****************************************************************************/ + static void -connect_cb(GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) +_secrets_dbus_need_secrets_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - NMVpnConnection *self; - gs_unref_variant GVariant *reply = NULL; - gs_free_error GError *error = NULL; + NMVpnConnection *self; + NMVpnConnectionPrivate *priv; + gs_unref_variant GVariant *res = NULL; + gs_free_error GError *error = NULL; + const char *setting_name; - reply = g_dbus_proxy_call_finish(proxy, result, &error); - if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + res = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), result, &error); + if (nm_utils_error_is_cancelled(error)) return; self = NM_VPN_CONNECTION(user_data); + priv = NM_VPN_CONNECTION_GET_PRIVATE(self); if (error) { - g_dbus_error_strip_remote_error(error); - _LOGW("VPN connection: failed to connect: '%s'", error->message); - _set_vpn_state(self, - STATE_FAILED, - NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_FAILED, - FALSE); - } else - connect_success(self); + _LOGW("plugin NeedSecrets request #%d failed: %s", priv->secrets_idx + 1, error->message); + _set_vpn_state(self, STATE_FAILED, NM_ACTIVE_CONNECTION_STATE_REASON_NO_SECRETS, FALSE); + return; + } + + g_variant_get(res, "(&s)", &setting_name); + if (nm_str_is_empty(setting_name)) { + /* No secrets required; we can start the VPN */ + _LOGD("service indicated no additional secrets required"); + really_activate(self, priv->username); + return; + } + + /* More secrets required */ + if (priv->secrets_idx == SECRETS_REQ_NEW) { + _LOGW("final secrets request failed to provide sufficient secrets"); + _set_vpn_state(self, STATE_FAILED, NM_ACTIVE_CONNECTION_STATE_REASON_NO_SECRETS, FALSE); + return; + } + + _LOGD("service indicated additional secrets required"); + _secrets_get(self, priv->secrets_idx + 1, NULL); } static void -connect_interactive_cb(GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) +_secrets_dbus_new_secrets_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - NMVpnConnection * self; - NMVpnConnectionPrivate *priv; - gs_unref_variant GVariant *reply = NULL; - gs_free_error GError *error = NULL; + NMVpnConnection *self; + gs_unref_variant GVariant *res = NULL; + gs_free_error GError *error = NULL; - reply = g_dbus_proxy_call_finish(proxy, result, &error); - if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + res = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), result, &error); + if (nm_utils_error_is_cancelled(error)) return; self = NM_VPN_CONNECTION(user_data); - priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - - _LOGI("VPN connection: (ConnectInteractive) reply received"); - - if (g_error_matches(error, - NM_VPN_PLUGIN_ERROR, - NM_VPN_PLUGIN_ERROR_INTERACTIVE_NOT_SUPPORTED)) { - _LOGD("VPN connection: falling back to non-interactive connect"); - - /* Fall back to Connect() */ - g_dbus_proxy_call(priv->proxy, - "Connect", - g_variant_new("(@a{sa{sv}})", priv->connect_hash), - G_DBUS_CALL_FLAGS_NONE, - -1, - priv->cancellable, - (GAsyncReadyCallback) connect_cb, - self); - } else if (error) { - g_dbus_error_strip_remote_error(error); - _LOGW("VPN connection: failed to connect interactively: '%s'", error->message); - _set_vpn_state(self, - STATE_FAILED, - NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_FAILED, - FALSE); - } else - connect_success(self); -} - -/* Add a username to a hashed connection */ -static GVariant * -_hash_with_username(NMConnection *connection, const char *username) -{ - gs_unref_object NMConnection *dup = NULL; - NMSettingVpn * s_vpn; - /* Shortcut if we weren't given a username or if there already was one in - * the VPN setting; don't bother duplicating the connection and everything. - */ - s_vpn = nm_connection_get_setting_vpn(connection); - g_assert(s_vpn); - if (username == NULL || nm_setting_vpn_get_user_name(s_vpn)) - return nm_connection_to_dbus(connection, NM_CONNECTION_SERIALIZE_ALL); + if (error) { + _LOGW("sending new secrets to the plugin failed: %s", error->message); + _set_vpn_state(self, STATE_FAILED, NM_ACTIVE_CONNECTION_STATE_REASON_NO_SECRETS, FALSE); + return; + } - dup = nm_simple_connection_new_clone(connection); - g_assert(dup); - s_vpn = nm_connection_get_setting_vpn(dup); - g_assert(s_vpn); - g_object_set(s_vpn, NM_SETTING_VPN_USER_NAME, username, NULL); - return nm_connection_to_dbus(dup, NM_CONNECTION_SERIALIZE_ALL); + _set_vpn_state(self, STATE_CONNECT, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); } static void -really_activate(NMVpnConnection *self, const char *username) -{ +_secrets_get_secrets_cb(NMSettingsConnection *connection, + NMSettingsConnectionCallId *call_id, + const char *agent_username, + const char *setting_name, + GError *error, + gpointer user_data) +{ + NMVpnConnection *self = NM_VPN_CONNECTION(user_data); NMVpnConnectionPrivate *priv; - GVariantBuilder details; + GVariant *dict; g_return_if_fail(NM_IS_VPN_CONNECTION(self)); priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - g_return_if_fail(priv->vpn_state == STATE_NEED_AUTH); - nm_clear_pointer(&priv->connect_hash, g_variant_unref); - priv->connect_hash = _hash_with_username(_get_applied_connection(self), username); - g_variant_ref_sink(priv->connect_hash); + g_return_if_fail(connection && connection == _get_settings_connection(self, FALSE)); + g_return_if_fail(call_id == priv->secrets_id); - /* If at least one agent doesn't support VPN hints, then we can't use - * ConnectInteractive(), because that agent won't be able to pass hints - * from the VPN plugin's interactive secrets requests to the VPN authentication - * dialog and we won't get the secrets we need. In this case fall back to - * the old Connect() call. - */ - if (nm_agent_manager_all_agents_have_capability( - nm_agent_manager_get(), - nm_active_connection_get_subject(NM_ACTIVE_CONNECTION(self)), - NM_SECRET_AGENT_CAPABILITY_VPN_HINTS)) { - _LOGD("Allowing interactive secrets as all agents have that capability"); + priv->secrets_id = NULL; - g_variant_builder_init(&details, G_VARIANT_TYPE_VARDICT); - g_dbus_proxy_call(priv->proxy, - "ConnectInteractive", - g_variant_new("(@a{sa{sv}}a{sv})", priv->connect_hash, &details), - G_DBUS_CALL_FLAGS_NONE, - -1, - priv->cancellable, - (GAsyncReadyCallback) connect_interactive_cb, - self); - } else { - _LOGD("Calling old Connect function as not all agents support interactive secrets"); - g_dbus_proxy_call(priv->proxy, - "Connect", - g_variant_new("(@a{sa{sv}})", priv->connect_hash), - G_DBUS_CALL_FLAGS_NONE, - -1, - priv->cancellable, - (GAsyncReadyCallback) connect_cb, - self); + if (nm_utils_error_is_cancelled(error)) + return; + + if (error && priv->secrets_idx >= SECRETS_REQ_NEW) { + _LOGW("secrets: failed to request VPN secrets #%d: %s", + priv->secrets_idx + 1, + error->message); + _set_vpn_state(self, STATE_FAILED, NM_ACTIVE_CONNECTION_STATE_REASON_NO_SECRETS, FALSE); + return; + } + + if (!priv->dbus.bus_name) { + _set_vpn_state(self, + STATE_FAILED, + NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_STOPPED, + FALSE); + return; + } + + /* Cache the username for later */ + if (agent_username) + nm_strdup_reset(&priv->username, agent_username); + + dict = _hash_with_username(_get_applied_connection(self), priv->username); + + if (priv->secrets_idx == SECRETS_REQ_INTERACTIVE) { + _LOGD("secrets: sending secrets to the plugin"); + _dbus_connection_call(self, + "NewSecrets", + g_variant_new("(@a{sa{sv}})", dict), + G_VARIANT_TYPE("()"), + _secrets_dbus_new_secrets_cb); + return; } - _set_vpn_state(self, STATE_CONNECT, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); + _LOGD("secrets: asking service if additional secrets are required"); + _dbus_connection_call(self, + "NeedSecrets", + g_variant_new("(@a{sa{sv}})", dict), + G_VARIANT_TYPE("(s)"), + _secrets_dbus_need_secrets_cb); } static void -failure_cb(GDBusProxy *proxy, guint32 reason, gpointer user_data) +_secrets_get(NMVpnConnection *self, SecretsReq secrets_idx, const char *const *hints) { - NMVpnConnection *self = NM_VPN_CONNECTION(user_data); + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + NMSecretAgentGetSecretsFlags flags = NM_SECRET_AGENT_GET_SECRETS_FLAG_NONE; - plugin_failed(self, reason); -} + g_return_if_fail(secrets_idx < SECRETS_REQ_LAST); -static void -state_changed_cb(GDBusProxy *proxy, guint32 new_service_state, gpointer user_data) -{ - NMVpnConnection *self = NM_VPN_CONNECTION(user_data); + priv->secrets_idx = secrets_idx; - plugin_state_changed(self, new_service_state); -} + cancel_get_secrets(self); -static void -secrets_required_cb(GDBusProxy * proxy, - const char * message, - const char *const *secrets, - gpointer user_data) -{ - NMVpnConnection *self = NM_VPN_CONNECTION(user_data); + _LOGD("secrets: requesting VPN secrets pass #%d", priv->secrets_idx + 1); - plugin_interactive_secrets_required(self, message, secrets); -} + switch (priv->secrets_idx) { + case SECRETS_REQ_SYSTEM: + flags = NM_SECRET_AGENT_GET_SECRETS_FLAG_ONLY_SYSTEM; + break; + case SECRETS_REQ_EXISTING: + flags = NM_SECRET_AGENT_GET_SECRETS_FLAG_NONE; + break; + case SECRETS_REQ_NEW: + case SECRETS_REQ_INTERACTIVE: + flags = NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION; + break; + default: + g_return_if_reached(); + } -static void -config_cb(GDBusProxy *proxy, GVariant *dict, gpointer user_data) -{ - NMVpnConnection * self = NM_VPN_CONNECTION(user_data); - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + if (nm_active_connection_get_user_requested(NM_ACTIVE_CONNECTION(self))) + flags |= NM_SECRET_AGENT_GET_SECRETS_FLAG_USER_REQUESTED; + + priv->secrets_id = nm_settings_connection_get_secrets( + _get_settings_connection(self, FALSE), + _get_applied_connection(self), + nm_active_connection_get_subject(NM_ACTIVE_CONNECTION(self)), + NM_SETTING_VPN_SETTING_NAME, + flags, + hints, + _secrets_get_secrets_cb, + self); - /* Only list to this signals during and after connection */ - if (priv->vpn_state >= STATE_NEED_AUTH) - nm_vpn_connection_config_get(self, dict); + g_return_if_fail(priv->secrets_id); } static void -ip4_config_cb(GDBusProxy *proxy, GVariant *dict, gpointer user_data) +_dbus_signal_secrets_required_cb(NMVpnConnection *self, + const char *message, + const char *const *secrets) { - NMVpnConnection * self = NM_VPN_CONNECTION(user_data); - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + const gsize secrets_len = NM_PTRARRAY_LEN(secrets); + gsize i; + gs_free const char **hints = NULL; + gs_free char *message_hint = NULL; - /* Only list to this signals during and after connection */ - if (priv->vpn_state >= STATE_NEED_AUTH) - nm_vpn_connection_ip4_config_get(self, dict); -} + if (!NM_IN_SET(priv->vpn_state, STATE_CONNECT, STATE_NEED_AUTH)) { + _LOGD("secrets: request ignored in current state %s", + vpn_state_to_string_a(priv->vpn_state)); + return; + } -static void -ip6_config_cb(GDBusProxy *proxy, GVariant *dict, gpointer user_data) -{ - NMVpnConnection * self = NM_VPN_CONNECTION(user_data); - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + _LOGD("secrets: request (state %s)", vpn_state_to_string_a(priv->vpn_state)); - /* Only list to this signals during and after connection */ - if (priv->vpn_state >= STATE_NEED_AUTH) - nm_vpn_connection_ip6_config_get(self, dict); -} + priv->secrets_idx = SECRETS_REQ_INTERACTIVE; + _set_vpn_state(self, STATE_NEED_AUTH, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); -static void -_name_owner_changed(GObject *object, GParamSpec *pspec, gpointer user_data) -{ - NMVpnConnection * self = NM_VPN_CONNECTION(user_data); - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - char * owner; - - owner = g_dbus_proxy_get_name_owner(G_DBUS_PROXY(object)); - - if (owner && !priv->service_running) { - /* service appeared */ - priv->service_running = TRUE; - _LOGI("Saw the service appear; activating connection"); - - /* No need to wait for the timeout any longer */ - nm_clear_g_source(&priv->start_timeout); - - /* Expect success because the VPN service has already appeared */ - _nm_dbus_signal_connect(priv->proxy, - "Failure", - G_VARIANT_TYPE("(u)"), - G_CALLBACK(failure_cb), - self); - _nm_dbus_signal_connect(priv->proxy, - "StateChanged", - G_VARIANT_TYPE("(u)"), - G_CALLBACK(state_changed_cb), - self); - _nm_dbus_signal_connect(priv->proxy, - "SecretsRequired", - G_VARIANT_TYPE("(sas)"), - G_CALLBACK(secrets_required_cb), - self); - _nm_dbus_signal_connect(priv->proxy, - "Config", - G_VARIANT_TYPE("(a{sv})"), - G_CALLBACK(config_cb), - self); - _nm_dbus_signal_connect(priv->proxy, - "Ip4Config", - G_VARIANT_TYPE("(a{sv})"), - G_CALLBACK(ip4_config_cb), - self); - _nm_dbus_signal_connect(priv->proxy, - "Ip6Config", - G_VARIANT_TYPE("(a{sv})"), - G_CALLBACK(ip6_config_cb), - self); - - _set_vpn_state(self, STATE_NEED_AUTH, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); - - /* Kick off the secrets requests; first we get existing system secrets - * and ask the plugin if these are sufficient, next we get all existing - * secrets from system and from user agents and ask the plugin again, - * and last we ask the user for new secrets if required. - */ - get_secrets(self, SECRETS_REQ_SYSTEM, NULL); - } else if (!owner && priv->service_running) { - /* service went away */ - priv->service_running = FALSE; - _LOGI("VPN service disappeared"); - nm_vpn_connection_disconnect(self, - NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_STOPPED, - FALSE); + /* Copy hints and add message to the end */ + hints = g_new(const char *, secrets_len + 2); + for (i = 0; i < secrets_len; i++) + hints[i] = secrets[i]; + if (message) { + message_hint = g_strdup_printf("x-vpn-message:%s", message); + hints[i++] = message_hint; } + hints[i] = NULL; + nm_assert(i < secrets_len + 2); - g_free(owner); + _secrets_get(self, SECRETS_REQ_INTERACTIVE, hints); } -static gboolean -_daemon_exec_timeout(gpointer data) -{ - NMVpnConnection * self = NM_VPN_CONNECTION(data); - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - - _LOGW("Timed out waiting for the service to start"); - priv->start_timeout = 0; - nm_vpn_connection_disconnect(self, - NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT, - FALSE); - return G_SOURCE_REMOVE; -} +/*****************************************************************************/ static int _get_log_level(void) @@ -2252,15 +2485,15 @@ nm_vpn_service_daemon_exec(NMVpnConnection *self, GError **error) { NMVpnConnectionPrivate *priv; GPid pid; - char * vpn_argv[4]; - gboolean success = FALSE; - GError * spawn_error = NULL; - guint i, j, n_environ; - gs_free char ** envp = NULL; + char *vpn_argv[4]; + gs_free char **envp = NULL; char env_log_level[NM_STRLEN("NM_VPN_LOG_LEVEL=") + 100]; char env_log_syslog[NM_STRLEN("NM_VPN_LOG_SYSLOG=") + 10]; - const int N_ENVIRON_EXTRA = 3; - char ** p_environ; + const gsize N_ENVIRON_EXTRA = 3; + char **p_environ; + gsize n_environ; + gsize i; + gsize j; g_return_val_if_fail(NM_IS_VPN_CONNECTION(self), FALSE); @@ -2271,17 +2504,17 @@ nm_vpn_service_daemon_exec(NMVpnConnection *self, GError **error) g_return_val_if_fail(vpn_argv[0], FALSE); if (nm_vpn_plugin_info_supports_multiple(priv->plugin_info)) { vpn_argv[i++] = "--bus-name"; - vpn_argv[i++] = priv->bus_name; + vpn_argv[i++] = priv->dbus.bus_name; } vpn_argv[i++] = NULL; /* we include and "config.h" defines _GNU_SOURCE for us. So, we have @environ. */ p_environ = environ; - n_environ = p_environ ? g_strv_length(p_environ) : 0; + n_environ = NM_PTRARRAY_LEN(p_environ); envp = g_new(char *, n_environ + N_ENVIRON_EXTRA); for (i = 0, j = 0; j < n_environ; j++) { - if (g_str_has_prefix(p_environ[j], "NM_VPN_LOG_LEVEL=") - || g_str_has_prefix(p_environ[j], "NM_VPN_LOG_SYSLOG=")) + if (NM_STR_HAS_PREFIX(p_environ[j], "NM_VPN_LOG_LEVEL=") + || NM_STR_HAS_PREFIX(p_environ[j], "NM_VPN_LOG_SYSLOG=")) continue; envp[i++] = p_environ[j]; } @@ -2300,500 +2533,360 @@ nm_vpn_service_daemon_exec(NMVpnConnection *self, GError **error) envp[i++] = NULL; nm_assert(i <= n_environ + N_ENVIRON_EXTRA); - success = g_spawn_async(NULL, vpn_argv, envp, 0, nm_utils_setpgid, NULL, &pid, &spawn_error); - - if (success) { - _LOGI("Started the VPN service, PID %ld", (long int) pid); - priv->start_timeout = g_timeout_add_seconds(5, _daemon_exec_timeout, self); - } else { - g_set_error(error, - NM_MANAGER_ERROR, - NM_MANAGER_ERROR_FAILED, - "%s", - spawn_error ? spawn_error->message : "unknown g_spawn_async() error"); - - if (spawn_error) - g_error_free(spawn_error); - } - - return success; -} - -static void -on_proxy_acquired(GObject *object, GAsyncResult *result, gpointer user_data) -{ - NMVpnConnection * self; - NMVpnConnectionPrivate *priv; - gs_free_error GError *error = NULL; - GDBusProxy * proxy; - - proxy = g_dbus_proxy_new_for_bus_finish(result, &error); - if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - return; - - self = NM_VPN_CONNECTION(user_data); - priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - - if (error) { - _LOGE("failed to acquire dbus proxy for VPN service: %s", error->message); - _set_vpn_state(self, - STATE_FAILED, - NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_FAILED, - FALSE); - return; - } - - priv->proxy = proxy; - - g_signal_connect(priv->proxy, "notify::g-name-owner", G_CALLBACK(_name_owner_changed), self); - _name_owner_changed(G_OBJECT(priv->proxy), NULL, self); - - if (priv->service_running) - return; - - if (!nm_vpn_service_daemon_exec(self, &error)) { - _LOGW("Could not launch the VPN service. error: %s.", error->message); - - nm_vpn_connection_disconnect(self, - NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_FAILED, - FALSE); - } -} - -void -nm_vpn_connection_activate(NMVpnConnection *self, NMVpnPluginInfo *plugin_info) -{ - NMVpnConnectionPrivate *priv; - NMSettingVpn * s_vpn; - const char * service; - - g_return_if_fail(NM_IS_VPN_CONNECTION(self)); - g_return_if_fail(NM_IS_VPN_PLUGIN_INFO(plugin_info)); - - priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - g_return_if_fail(!priv->plugin_info); - - s_vpn = nm_connection_get_setting_vpn(_get_applied_connection(self)); - g_return_if_fail(s_vpn); - - service = nm_vpn_plugin_info_get_service(plugin_info); - nm_assert(service); - - if (nm_vpn_plugin_info_supports_multiple(plugin_info)) { - const char *path; - - path = nm_dbus_object_get_path(NM_DBUS_OBJECT(self)); - if (path) - path = strrchr(path, '/'); - g_return_if_fail(path); - - priv->bus_name = g_strdup_printf("%s.Connection_%s", service, &path[1]); - } else - priv->bus_name = g_strdup(service); - - priv->connection_can_persist = nm_setting_vpn_get_persistent(s_vpn); - priv->plugin_info = g_object_ref(plugin_info); - priv->cancellable = g_cancellable_new(); - - g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, - NULL, - priv->bus_name, - NM_VPN_DBUS_PLUGIN_PATH, - NM_VPN_DBUS_PLUGIN_INTERFACE, - priv->cancellable, - (GAsyncReadyCallback) on_proxy_acquired, - self); - - _set_vpn_state(self, STATE_PREPARE, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); -} - -NMVpnConnectionState -nm_vpn_connection_get_vpn_state(NMVpnConnection *self) -{ - g_return_val_if_fail(NM_IS_VPN_CONNECTION(self), NM_VPN_CONNECTION_STATE_UNKNOWN); - - return _state_to_nm_vpn_state(NM_VPN_CONNECTION_GET_PRIVATE(self)->vpn_state); -} - -const char * -nm_vpn_connection_get_banner(NMVpnConnection *self) -{ - g_return_val_if_fail(NM_IS_VPN_CONNECTION(self), NULL); - - return NM_VPN_CONNECTION_GET_PRIVATE(self)->banner; -} - -NMProxyConfig * -nm_vpn_connection_get_proxy_config(NMVpnConnection *self) -{ - g_return_val_if_fail(NM_IS_VPN_CONNECTION(self), NULL); - - return NM_VPN_CONNECTION_GET_PRIVATE(self)->proxy_config; -} - -NMIP4Config * -nm_vpn_connection_get_ip4_config(NMVpnConnection *self) -{ - g_return_val_if_fail(NM_IS_VPN_CONNECTION(self), NULL); - - return NM_VPN_CONNECTION_GET_PRIVATE(self)->ip4_config; -} - -NMIP6Config * -nm_vpn_connection_get_ip6_config(NMVpnConnection *self) -{ - g_return_val_if_fail(NM_IS_VPN_CONNECTION(self), NULL); - - return NM_VPN_CONNECTION_GET_PRIVATE(self)->ip6_config; -} - -static int -_get_ip_iface_for_device(NMVpnConnection *self, const char **out_iface) -{ - NMDevice * parent_dev; - int ifindex; - const char *iface; - - nm_assert(NM_IS_VPN_CONNECTION(self)); - - /* the ifindex and the ifname in this case should come together. - * They either must be both set, or none. */ - - parent_dev = nm_active_connection_get_device(NM_ACTIVE_CONNECTION(self)); - if (!parent_dev) - goto none; - ifindex = nm_device_get_ip_ifindex(parent_dev); - if (ifindex <= 0) - goto none; - iface = nm_device_get_ip_iface(parent_dev); - if (!iface) - goto none; - - NM_SET_OUT(out_iface, iface); - return ifindex; -none: - NM_SET_OUT(out_iface, NULL); - return 0; -} - -const char * -nm_vpn_connection_get_ip_iface(NMVpnConnection *self, gboolean fallback_device) -{ - NMVpnConnectionPrivate *priv; - const char * iface; - - g_return_val_if_fail(NM_IS_VPN_CONNECTION(self), NULL); - - priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - - if (priv->ip_iface || !fallback_device) - return priv->ip_iface; + if (!g_spawn_async(NULL, vpn_argv, envp, 0, nm_utils_setpgid, NULL, &pid, error)) + return FALSE; - _get_ip_iface_for_device(self, &iface); - return iface; + _LOGD("starting: VPN service has PID %lld", (long long) pid); + return TRUE; } -int -nm_vpn_connection_get_ip_ifindex(NMVpnConnection *self, gboolean fallback_device) -{ - NMVpnConnectionPrivate *priv; - - g_return_val_if_fail(NM_IS_VPN_CONNECTION(self), 0); - - priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - - if (priv->ip_ifindex > 0) - return priv->ip_ifindex; - if (!fallback_device) - return 0; - - return _get_ip_iface_for_device(self, NULL); -} +/*****************************************************************************/ -guint32 -nm_vpn_connection_get_ip4_internal_gateway(NMVpnConnection *self) +static gboolean +_start_timeout_cb(gpointer data) { - g_return_val_if_fail(NM_IS_VPN_CONNECTION(self), 0); - - return NM_VPN_CONNECTION_GET_PRIVATE(self)->ip4_internal_gw; -} + NMVpnConnection *self = NM_VPN_CONNECTION(data); + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); -struct in6_addr * -nm_vpn_connection_get_ip6_internal_gateway(NMVpnConnection *self) -{ - g_return_val_if_fail(NM_IS_VPN_CONNECTION(self), 0); + nm_clear_g_source_inst(&priv->start_timeout_source); - return NM_VPN_CONNECTION_GET_PRIVATE(self)->ip6_internal_gw; + if (priv->dbus_service_started) + _LOGW("starting: timed out waiting for the service to start"); + else + _LOGW("starting: timed out waiting for the VPN to activate"); + nm_vpn_connection_disconnect(self, + NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT, + FALSE); + return G_SOURCE_CONTINUE; } -void -nm_vpn_connection_disconnect(NMVpnConnection * self, - NMActiveConnectionStateReason reason, - gboolean quitting) -{ - g_return_if_fail(NM_IS_VPN_CONNECTION(self)); +/*****************************************************************************/ - _set_vpn_state(self, STATE_DISCONNECTED, reason, quitting); -} +static void +_dbus_dispatch_cb(GDBusConnection *connection, + const char *sender_name, + const char *object_path, + const char *interface_name, + const char *signal_name, + GVariant *parameters, + gpointer user_data) +{ + NMVpnConnection *self = user_data; + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + guint32 v_u; -gboolean -nm_vpn_connection_deactivate(NMVpnConnection * self, - NMActiveConnectionStateReason reason, - gboolean quitting) -{ - NMVpnConnectionPrivate *priv; - gboolean success = FALSE; + nm_assert(nm_streq0(object_path, NM_VPN_DBUS_PLUGIN_PATH)); + nm_assert(nm_streq0(interface_name, NM_VPN_DBUS_PLUGIN_INTERFACE)); + nm_assert(signal_name); - g_return_val_if_fail(NM_IS_VPN_CONNECTION(self), FALSE); + if (!nm_streq0(priv->dbus.owner, sender_name)) + return; - priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - if (priv->vpn_state > STATE_UNKNOWN && priv->vpn_state <= STATE_DEACTIVATING) { - _set_vpn_state(self, STATE_DEACTIVATING, reason, quitting); - success = TRUE; + if (nm_streq(signal_name, "Failure")) { + if (nm_g_variant_tuple_get_u(parameters, &v_u)) + _dbus_signal_failure_cb(self, v_u); + } else if (nm_streq(signal_name, "StateChanged")) { + if (nm_g_variant_tuple_get_u(parameters, &v_u)) + _dbus_signal_state_changed_cb(self, v_u); + } else if (nm_streq(signal_name, "SecretsRequired")) { + if (g_variant_is_of_type(parameters, G_VARIANT_TYPE("(sas)"))) { + const char *v_s; + gs_free const char **v_strv = NULL; + + g_variant_get(parameters, "(&s^a&s)", &v_s, &v_strv); + _dbus_signal_secrets_required_cb(self, v_s, v_strv); + } + } else if (NM_IN_STRSET(signal_name, "Config", "Ip4Config", "Ip6Config")) { + if (g_variant_is_of_type(parameters, G_VARIANT_TYPE("(a{sv})"))) { + gs_unref_variant GVariant *v_var = NULL; + + g_variant_get(parameters, "(@a{sv})", &v_var); + if (signal_name[0] == 'C') + _dbus_signal_config_cb(self, v_var); + else if (signal_name[2] == '4') + _dbus_signal_ip_config_cb(self, AF_INET, v_var); + else + _dbus_signal_ip_config_cb(self, AF_INET6, v_var); + } } - return success; } -/*****************************************************************************/ - static void -plugin_need_secrets_cb(GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) +_name_owner_changed(NMVpnConnection *self, const char *owner, gboolean initializing) { - NMVpnConnection * self; - NMVpnConnectionPrivate *priv; - gs_unref_variant GVariant *reply = NULL; - gs_free_error GError *error = NULL; - const char * setting_name; + _nm_unused gs_unref_object NMVpnConnection *self_keep_alive = g_object_ref(self); + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - reply = _nm_dbus_proxy_call_finish(proxy, result, G_VARIANT_TYPE("(s)"), &error); - if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - return; + owner = nm_str_not_empty(owner); - self = NM_VPN_CONNECTION(user_data); - priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + if (!owner && initializing) { + gs_free_error GError *error = NULL; - if (error) { - g_dbus_error_strip_remote_error(error); - _LOGE("plugin NeedSecrets request #%d failed: %s", priv->secrets_idx + 1, error->message); - _set_vpn_state(self, STATE_FAILED, NM_ACTIVE_CONNECTION_STATE_REASON_NO_SECRETS, FALSE); + nm_assert(!priv->dbus.owner); + _LOGT("dbus: no name owner for %s (start VPN service)", priv->dbus.bus_name); + + if (!nm_vpn_service_daemon_exec(self, &error)) { + _LOGW("starting: failure to start VPN service: %s", error->message); + nm_vpn_connection_disconnect(self, + NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_FAILED, + FALSE); + } + priv->start_timeout_source = nm_g_timeout_add_seconds_source(5, _start_timeout_cb, self); return; } - g_variant_get(reply, "(&s)", &setting_name); - if (!strlen(setting_name)) { - _LOGD("service indicated no additional secrets required"); + if (!nm_strdup_reset(&priv->dbus.owner, owner)) + return; - /* No secrets required; we can start the VPN */ - really_activate(self, priv->username); + if (!priv->dbus.owner) { + _LOGT("dbus: name owner for %s disappeared", priv->dbus.bus_name); + + /* We don't want to restart if the service re-appears. Disconnect the signal + * so that cannot happen and we don't disconnect the VPN again. */ + nm_clear_g_dbus_connection_signal(priv->dbus.connection, + &priv->dbus.signal_id_name_changed); + + nm_vpn_connection_disconnect(self, + NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_STOPPED, + FALSE); return; } - /* More secrets required */ - if (priv->secrets_idx == SECRETS_REQ_NEW) { - _LOGE("final secrets request failed to provide sufficient secrets"); - _set_vpn_state(self, STATE_FAILED, NM_ACTIVE_CONNECTION_STATE_REASON_NO_SECRETS, FALSE); - } else { - _LOGD("service indicated additional secrets required"); - get_secrets(self, priv->secrets_idx + 1, NULL); - } + _LOGT("dbus: name owner %s for %s", priv->dbus.owner, priv->dbus.bus_name); + + priv->dbus_service_started = TRUE; + nm_clear_g_source_inst(&priv->start_timeout_source); + priv->start_timeout_source = + nm_g_timeout_add_seconds_source(_get_vpn_timeout(self) + 180, _start_timeout_cb, self); + + _set_vpn_state(self, STATE_NEED_AUTH, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); + + /* Kick off the secrets requests; first we get existing system secrets + * and ask the plugin if these are sufficient, next we get all existing + * secrets from system and from user agents and ask the plugin again, + * and last we ask the user for new secrets if required. + */ + _secrets_get(self, SECRETS_REQ_SYSTEM, NULL); } static void -plugin_new_secrets_cb(GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) -{ - NMVpnConnection *self; - gs_unref_variant GVariant *reply = NULL; - gs_free_error GError *error = NULL; +_name_owner_changed_cb(GDBusConnection *connection, + const char *sender_name, + const char *object_path, + const char *interface_name, + const char *signal_name, + GVariant *parameters, + gpointer user_data) +{ + NMVpnConnection *self = user_data; + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + const char *new_owner; - reply = g_dbus_proxy_call_finish(proxy, result, &error); - if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + if (!priv->dbus.name_owner_initialized) return; - self = NM_VPN_CONNECTION(user_data); + if (!g_variant_is_of_type(parameters, G_VARIANT_TYPE("(sss)"))) + return; - if (error) { - g_dbus_error_strip_remote_error(error); - _LOGE("sending new secrets to the plugin failed: %s", error->message); - _set_vpn_state(self, STATE_FAILED, NM_ACTIVE_CONNECTION_STATE_REASON_NO_SECRETS, FALSE); - } else - _set_vpn_state(self, STATE_CONNECT, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); + g_variant_get(parameters, "(&s&s&s)", NULL, NULL, &new_owner); + + _name_owner_changed(self, new_owner, FALSE); } static void -get_secrets_cb(NMSettingsConnection * connection, - NMSettingsConnectionCallId *call_id, - const char * agent_username, - const char * setting_name, - GError * error, - gpointer user_data) -{ - NMVpnConnection * self = NM_VPN_CONNECTION(user_data); +_name_owner_get_cb(const char *name_owner, GError *error, gpointer user_data) +{ + NMVpnConnection *self; NMVpnConnectionPrivate *priv; - GVariant * dict; - g_return_if_fail(NM_IS_VPN_CONNECTION(self)); + if (nm_utils_error_is_cancelled(error)) + return; + self = user_data; priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - g_return_if_fail(connection && connection == _get_settings_connection(self, FALSE)); - g_return_if_fail(call_id == priv->secrets_id); + priv->dbus.name_owner_initialized = TRUE; + _name_owner_changed(self, name_owner, TRUE); +} - priv->secrets_id = NULL; +static gboolean +_init_fail_on_idle_cb(gpointer user_data) +{ + NMVpnConnection *self = user_data; + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - return; + nm_clear_g_source_inst(&priv->init_fail_on_idle_source); + _set_vpn_state(self, + STATE_FAILED, + NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_FAILED, + FALSE); + return G_SOURCE_CONTINUE; +} - if (error && priv->secrets_idx >= SECRETS_REQ_NEW) { - _LOGE("Failed to request VPN secrets #%d: %s", priv->secrets_idx + 1, error->message); - _set_vpn_state(self, STATE_FAILED, NM_ACTIVE_CONNECTION_STATE_REASON_NO_SECRETS, FALSE); - return; - } +/*****************************************************************************/ - /* Cache the username for later */ - if (agent_username) { - g_free(priv->username); - priv->username = g_strdup(agent_username); - } +void +nm_vpn_connection_activate(NMVpnConnection *self, NMVpnPluginInfo *plugin_info) +{ + NMVpnConnectionPrivate *priv; + NMConnection *connection; + NMSettingVpn *s_vpn; + const char *service; - dict = _hash_with_username(_get_applied_connection(self), priv->username); + g_return_if_fail(NM_IS_VPN_CONNECTION(self)); + g_return_if_fail(NM_IS_VPN_PLUGIN_INFO(plugin_info)); - if (priv->secrets_idx == SECRETS_REQ_INTERACTIVE) { - _LOGD("sending secrets to the plugin"); + priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + g_return_if_fail(!priv->plugin_info); - /* Send the secrets back to the plugin */ - g_dbus_proxy_call(priv->proxy, - "NewSecrets", - g_variant_new("(@a{sa{sv}})", dict), - G_DBUS_CALL_FLAGS_NONE, - -1, - priv->cancellable, - (GAsyncReadyCallback) plugin_new_secrets_cb, - self); - } else { - _LOGD("asking service if additional secrets are required"); + connection = _get_applied_connection(self); - /* Ask the VPN service if more secrets are required */ - g_dbus_proxy_call(priv->proxy, - "NeedSecrets", - g_variant_new("(@a{sa{sv}})", dict), - G_DBUS_CALL_FLAGS_NONE, - -1, - priv->cancellable, - (GAsyncReadyCallback) plugin_need_secrets_cb, - self); - } -} + s_vpn = nm_connection_get_setting_vpn(connection); + g_return_if_fail(s_vpn); -static void -get_secrets(NMVpnConnection *self, SecretsReq secrets_idx, const char *const *hints) -{ - NMVpnConnectionPrivate * priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - NMSecretAgentGetSecretsFlags flags = NM_SECRET_AGENT_GET_SECRETS_FLAG_NONE; + service = nm_vpn_plugin_info_get_service(plugin_info); + nm_assert(service); - g_return_if_fail(secrets_idx < SECRETS_REQ_LAST); - priv->secrets_idx = secrets_idx; + if (nm_vpn_plugin_info_supports_multiple(plugin_info)) { + const char *path; - cancel_get_secrets(self); + path = nm_dbus_object_get_path(NM_DBUS_OBJECT(self)); + if (path) + path = strrchr(path, '/'); + g_return_if_fail(path); - _LOGD("requesting VPN secrets pass #%d", priv->secrets_idx + 1); + priv->dbus.bus_name = g_strdup_printf("%s.Connection_%s", service, &path[1]); + } else + priv->dbus.bus_name = g_strdup(service); - switch (priv->secrets_idx) { - case SECRETS_REQ_SYSTEM: - flags = NM_SECRET_AGENT_GET_SECRETS_FLAG_ONLY_SYSTEM; - break; - case SECRETS_REQ_EXISTING: - flags = NM_SECRET_AGENT_GET_SECRETS_FLAG_NONE; - break; - case SECRETS_REQ_NEW: - case SECRETS_REQ_INTERACTIVE: - flags = NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION; - break; - default: - g_assert_not_reached(); - } + _LOGI("starting %s", nm_vpn_plugin_info_get_name(plugin_info)); - if (nm_active_connection_get_user_requested(NM_ACTIVE_CONNECTION(self))) - flags |= NM_SECRET_AGENT_GET_SECRETS_FLAG_USER_REQUESTED; + priv->connection_can_persist = nm_setting_vpn_get_persistent(s_vpn); + priv->plugin_info = g_object_ref(plugin_info); - priv->secrets_id = nm_settings_connection_get_secrets( - _get_settings_connection(self, FALSE), - _get_applied_connection(self), - nm_active_connection_get_subject(NM_ACTIVE_CONNECTION(self)), - NM_SETTING_VPN_SETTING_NAME, - flags, - hints, - get_secrets_cb, - self); - g_return_if_fail(priv->secrets_id); + priv->main_cancellable = g_cancellable_new(); + + priv->dbus.connection = nm_g_object_ref(NM_MAIN_DBUS_CONNECTION_GET); + + if (!priv->dbus.connection) { + _LOGD("starting: no D-Bus connection (will fail)"); + priv->init_fail_on_idle_source = nm_g_idle_add_source(_init_fail_on_idle_cb, self); + goto out; + } + + _LOGD("starting: watch D-Bus service %s", priv->dbus.bus_name); + priv->dbus.signal_id_name_changed = + nm_dbus_connection_signal_subscribe_name_owner_changed(priv->dbus.connection, + priv->dbus.bus_name, + _name_owner_changed_cb, + self, + NULL); + + priv->dbus.signal_id_vpn = g_dbus_connection_signal_subscribe(priv->dbus.connection, + priv->dbus.bus_name, + NM_VPN_DBUS_PLUGIN_INTERFACE, + NULL, + NM_VPN_DBUS_PLUGIN_PATH, + NULL, + G_DBUS_SIGNAL_FLAGS_NONE, + _dbus_dispatch_cb, + self, + NULL); + + nm_dbus_connection_call_get_name_owner(priv->dbus.connection, + priv->dbus.bus_name, + 3000, + priv->main_cancellable, + _name_owner_get_cb, + self); + +out: + _set_vpn_state(self, STATE_PREPARE, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); } +/*****************************************************************************/ + static void -plugin_interactive_secrets_required(NMVpnConnection * self, - const char * message, - const char *const *secrets) +device_changed(NMActiveConnection *active, NMDevice *new_device, NMDevice *old_device) { - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - const gsize secrets_len = NM_PTRARRAY_LEN(secrets); - gsize i; - gs_free const char ** hints = NULL; - gs_free char * message_hint = NULL; + NMVpnConnection *self = NM_VPN_CONNECTION(active); + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(active); + gs_unref_object NML3Cfg *l3cfg_old = NULL; + int ifindex; - if (!NM_IN_SET(priv->vpn_state, STATE_CONNECT, STATE_NEED_AUTH)) { - _LOGD("VPN plugin: requested secrets; state %s (%d); ignore request in current state", - vpn_state_to_string_a(priv->vpn_state), - priv->vpn_state); + if (!priv->generic_config_received) + return; + if (priv->vpn_state > STATE_ACTIVATED) + return; + if (!_service_and_connection_can_persist(self)) + return; + + if (priv->ifindex_if <= 0) { + /* Route-based VPNs must updvate their routing and send a new IP config + * since all their routes need to be adjusted for new_device. + */ return; } - _LOGI("VPN plugin: requested secrets; state %s (%d)", - vpn_state_to_string_a(priv->vpn_state), - priv->vpn_state); + ifindex = _get_ifindex_for_device(self); + if (ifindex <= 0) + return; + if (priv->ifindex_dev == ifindex) + return; - priv->secrets_idx = SECRETS_REQ_INTERACTIVE; - _set_vpn_state(self, STATE_NEED_AUTH, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); + _LOGD("set ip-ifindex-dev %d (was %d)", ifindex, priv->ifindex_dev); - /* Copy hints and add message to the end */ - hints = g_new(const char *, secrets_len + 2); - for (i = 0; i < secrets_len; i++) - hints[i] = secrets[i]; - if (message) { - message_hint = g_strdup_printf("x-vpn-message:%s", message); - hints[i++] = message_hint; + l3cfg_old = g_steal_pointer(&priv->l3cfg_dev); + nm_l3cfg_commit_type_clear(l3cfg_old, &priv->l3cfg_commit_type_dev); + _l3cfg_clear(self, l3cfg_old); + + priv->ifindex_dev = ifindex; + if (ifindex > 0) { + priv->l3cfg_dev = nm_netns_l3cfg_acquire(priv->netns, ifindex); + g_signal_connect(priv->l3cfg_dev, + NM_L3CFG_SIGNAL_NOTIFY, + G_CALLBACK(_l3cfg_notify_cb), + self); + priv->l3cfg_commit_type_dev = nm_l3cfg_commit_type_register(priv->l3cfg_dev, + NM_L3_CFG_COMMIT_TYPE_UPDATE, + NULL, + "vpn"); } - hints[i] = NULL; - nm_assert(i < secrets_len + 2); - get_secrets(self, SECRETS_REQ_INTERACTIVE, hints); + if (_l3cfg_l3cd_gw_extern_update(self)) + nm_l3cfg_commit_on_idle_schedule(priv->l3cfg_dev, NM_L3_CFG_COMMIT_TYPE_AUTO); } /*****************************************************************************/ static void -device_changed(NMActiveConnection *active, NMDevice *new_device, NMDevice *old_device) +get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(active); - - if (!_service_and_connection_can_persist(NM_VPN_CONNECTION(active))) - return; - if (priv->vpn_state < STATE_CONNECT || priv->vpn_state > STATE_ACTIVATED) - return; - - /* Route-based VPNs must update their routing and send a new IP config - * since all their routes need to be adjusted for new_device. - */ - if (priv->ip_ifindex <= 0) - return; - - /* Device changed underneath the VPN connection. Let the plugin figure - * out that connectivity is down and start its reconnect attempt if it - * needs to. - */ - if (old_device) - remove_parent_device_config(NM_VPN_CONNECTION(active), old_device); + NMVpnConnection *self = NM_VPN_CONNECTION(object); + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - if (new_device) - apply_parent_device_config(NM_VPN_CONNECTION(active)); + switch (prop_id) { + case PROP_VPN_STATE: + g_value_set_uint(value, _state_to_nm_vpn_state(priv->vpn_state)); + break; + case PROP_BANNER: + g_value_set_string(value, priv->banner ?: ""); + break; + case PROP_IP4_CONFIG: + nm_dbus_utils_g_value_set_object_path(value, priv->ip_data_4.ip_config); + break; + case PROP_IP6_CONFIG: + nm_dbus_utils_g_value_set_object_path(value, priv->ip_data_6.ip_config); + break; + case PROP_MASTER: + nm_dbus_utils_g_value_set_object_path( + value, + nm_active_connection_get_device(NM_ACTIVE_CONNECTION(self))); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } } /*****************************************************************************/ @@ -2808,34 +2901,68 @@ nm_vpn_connection_init(NMVpnConnection *self) priv->netns = g_object_ref(nm_netns_get()); } +NMVpnConnection * +nm_vpn_connection_new(NMSettingsConnection *settings_connection, + NMDevice *parent_device, + const char *specific_object, + NMActivationReason activation_reason, + NMActivationStateFlags initial_state_flags, + NMAuthSubject *subject) +{ + g_return_val_if_fail(!settings_connection || NM_IS_SETTINGS_CONNECTION(settings_connection), + NULL); + g_return_val_if_fail(NM_IS_DEVICE(parent_device), NULL); + g_return_val_if_fail(specific_object, NULL); + + return g_object_new(NM_TYPE_VPN_CONNECTION, + NM_ACTIVE_CONNECTION_INT_SETTINGS_CONNECTION, + settings_connection, + NM_ACTIVE_CONNECTION_INT_DEVICE, + parent_device, + NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, + specific_object, + NM_ACTIVE_CONNECTION_INT_SUBJECT, + subject, + NM_ACTIVE_CONNECTION_INT_ACTIVATION_REASON, + activation_reason, + NM_ACTIVE_CONNECTION_VPN, + TRUE, + NM_ACTIVE_CONNECTION_STATE_FLAGS, + (guint) initial_state_flags, + NULL); +} + static void dispose(GObject *object) { - NMVpnConnection * self = NM_VPN_CONNECTION(object); + NMVpnConnection *self = NM_VPN_CONNECTION(object); NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); - if (priv->proxy) - g_signal_handlers_disconnect_by_data(priv->proxy, self); + nm_clear_g_dbus_connection_signal(priv->dbus.connection, &priv->dbus.signal_id_vpn); + nm_clear_g_dbus_connection_signal(priv->dbus.connection, &priv->dbus.signal_id_name_changed); + + nm_clear_g_source_inst(&priv->init_fail_on_idle_source); + + nm_clear_g_cancellable(&priv->main_cancellable); - nm_clear_g_source(&priv->start_timeout); + nm_clear_g_source_inst(&priv->start_timeout_source); nm_clear_pointer(&priv->connect_hash, g_variant_unref); - nm_clear_pointer(&priv->ip4_dev_route_blacklist, g_ptr_array_unref); + nm_clear_g_source_inst(&priv->connect_timeout_source); - nm_clear_g_source(&priv->connect_timeout); + if (nm_l3cfg_commit_type_clear(priv->l3cfg_if, &priv->l3cfg_commit_type_if)) + nm_l3cfg_commit_on_idle_schedule(priv->l3cfg_if, NM_L3_CFG_COMMIT_TYPE_AUTO); - dispatcher_cleanup(self); + if (nm_l3cfg_commit_type_clear(priv->l3cfg_dev, &priv->l3cfg_commit_type_dev)) + nm_l3cfg_commit_on_idle_schedule(priv->l3cfg_dev, NM_L3_CFG_COMMIT_TYPE_AUTO); - cancel_get_secrets(self); + g_clear_object(&priv->ip_data_4.ip_config); + g_clear_object(&priv->ip_data_6.ip_config); - nm_clear_g_cancellable(&priv->cancellable); + dispatcher_cleanup(self); - g_clear_object(&priv->proxy_config); - nm_dbus_object_clear_and_unexport(&priv->ip4_config); - nm_dbus_object_clear_and_unexport(&priv->ip6_config); - g_clear_object(&priv->proxy); - g_clear_object(&priv->plugin_info); + cancel_get_secrets(self); fw_call_cleanup(self); @@ -2847,56 +2974,24 @@ dispose(GObject *object) static void finalize(GObject *object) { - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(object); + NMVpnConnection *self = NM_VPN_CONNECTION(object); + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + + G_OBJECT_CLASS(nm_vpn_connection_parent_class)->finalize(object); g_free(priv->banner); - g_free(priv->ip_iface); g_free(priv->username); - g_free(priv->ip6_internal_gw); - g_free(priv->ip6_external_gw); + g_free(priv->dbus.bus_name); - G_OBJECT_CLASS(nm_vpn_connection_parent_class)->finalize(object); + _l3cfg_l3cd_clear_all(self); + _l3cfg_clear(self, priv->l3cfg_if); + _l3cfg_clear(self, priv->l3cfg_dev); + g_clear_object(&priv->plugin_info); + g_clear_object(&priv->l3cfg_if); + g_clear_object(&priv->l3cfg_dev); g_clear_object(&priv->netns); -} - -static gboolean -ip_config_valid(VpnState state) -{ - return (state == STATE_PRE_UP || state == STATE_ACTIVATED); -} - -static void -get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(object); - NMDevice * parent_dev; - - switch (prop_id) { - case PROP_VPN_STATE: - g_value_set_uint(value, _state_to_nm_vpn_state(priv->vpn_state)); - break; - case PROP_BANNER: - g_value_set_string(value, priv->banner ?: ""); - break; - case PROP_IP4_CONFIG: - nm_dbus_utils_g_value_set_object_path(value, - ip_config_valid(priv->vpn_state) ? priv->ip4_config - : NULL); - break; - case PROP_IP6_CONFIG: - nm_dbus_utils_g_value_set_object_path(value, - ip_config_valid(priv->vpn_state) ? priv->ip6_config - : NULL); - break; - case PROP_MASTER: - parent_dev = nm_active_connection_get_device(NM_ACTIVE_CONNECTION(object)); - nm_dbus_utils_g_value_set_object_path(value, parent_dev); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } + g_clear_object(&priv->dbus.connection); } static const GDBusSignalInfo signal_info_vpn_state_changed = NM_DEFINE_GDBUS_SIGNAL_INFO_INIT( @@ -2918,11 +3013,11 @@ static const NMDBusInterfaceInfoExtended interface_info_vpn_connection = { }; static void -nm_vpn_connection_class_init(NMVpnConnectionClass *connection_class) +nm_vpn_connection_class_init(NMVpnConnectionClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(connection_class); - NMActiveConnectionClass *active_class = NM_ACTIVE_CONNECTION_CLASS(connection_class); - NMDBusObjectClass * dbus_object_class = NM_DBUS_OBJECT_CLASS(connection_class); + GObjectClass *object_class = G_OBJECT_CLASS(klass); + NMActiveConnectionClass *active_class = NM_ACTIVE_CONNECTION_CLASS(klass); + NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS(&interface_info_vpn_connection); @@ -2957,18 +3052,19 @@ nm_vpn_connection_class_init(NMVpnConnectionClass *connection_class) PROP_IP6_CONFIG, NM_ACTIVE_CONNECTION_IP6_CONFIG); - signals[INTERNAL_STATE_CHANGED] = g_signal_new(NM_VPN_CONNECTION_INTERNAL_STATE_CHANGED, - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, - NULL, - NULL, - G_TYPE_NONE, - 3, - G_TYPE_UINT, - G_TYPE_UINT, - G_TYPE_UINT); + signals[INTERNAL_STATE_CHANGED] = + g_signal_new(NM_VPN_CONNECTION_INTERNAL_STATE_CHANGED, + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_FIRST, + 0, + NULL, + NULL, + NULL, + G_TYPE_NONE, + 3, + G_TYPE_UINT, /* NMVpnConnectionState new_external_state */ + G_TYPE_UINT, /* NMVpnConnectionState old_external_state */ + G_TYPE_UINT /* NMActiveConnectionStateReason reason */); signals[INTERNAL_RETRY_AFTER_FAILURE] = g_signal_new(NM_VPN_CONNECTION_INTERNAL_RETRY_AFTER_FAILURE, diff --git a/src/core/vpn/nm-vpn-connection.h b/src/core/vpn/nm-vpn-connection.h index 0209ea3d..51e2e500 100644 --- a/src/core/vpn/nm-vpn-connection.h +++ b/src/core/vpn/nm-vpn-connection.h @@ -35,35 +35,32 @@ typedef struct _NMVpnConnectionClass NMVpnConnectionClass; GType nm_vpn_connection_get_type(void); -NMVpnConnection *nm_vpn_connection_new(NMSettingsConnection * settings_connection, - NMDevice * parent_device, - const char * specific_object, +NMVpnConnection *nm_vpn_connection_new(NMSettingsConnection *settings_connection, + NMDevice *parent_device, + const char *specific_object, NMActivationReason activation_reason, NMActivationStateFlags initial_state_flags, - NMAuthSubject * subject); + NMAuthSubject *subject); void nm_vpn_connection_activate(NMVpnConnection *self, NMVpnPluginInfo *plugin_info); NMVpnConnectionState nm_vpn_connection_get_vpn_state(NMVpnConnection *self); -const char * nm_vpn_connection_get_banner(NMVpnConnection *self); -const char * nm_vpn_connection_get_service(NMVpnConnection *self); +const char *nm_vpn_connection_get_banner(NMVpnConnection *self); +const char *nm_vpn_connection_get_service(NMVpnConnection *self); -gboolean nm_vpn_connection_deactivate(NMVpnConnection * self, +gboolean nm_vpn_connection_deactivate(NMVpnConnection *self, NMActiveConnectionStateReason reason, gboolean quitting); -void nm_vpn_connection_disconnect(NMVpnConnection * self, +void nm_vpn_connection_disconnect(NMVpnConnection *self, NMActiveConnectionStateReason reason, gboolean quitting); -NMProxyConfig *nm_vpn_connection_get_proxy_config(NMVpnConnection *self); +const NML3ConfigData *nm_vpn_connection_get_l3cd(NMVpnConnection *self); -NMIP4Config * nm_vpn_connection_get_ip4_config(NMVpnConnection *self); -NMIP6Config * nm_vpn_connection_get_ip6_config(NMVpnConnection *self); -const char * nm_vpn_connection_get_ip_iface(NMVpnConnection *self, gboolean fallback_device); +const char *nm_vpn_connection_get_ip_iface(NMVpnConnection *self, gboolean fallback_device); int nm_vpn_connection_get_ip_ifindex(NMVpnConnection *self, gboolean fallback_device); guint32 nm_vpn_connection_get_ip4_internal_gateway(NMVpnConnection *self); struct in6_addr *nm_vpn_connection_get_ip6_internal_gateway(NMVpnConnection *self); -guint32 nm_vpn_connection_get_ip4_route_metric(NMVpnConnection *self); -guint32 nm_vpn_connection_get_ip6_route_metric(NMVpnConnection *self); +guint32 nm_vpn_connection_get_ip_route_metric(NMVpnConnection *self, int addr_family); #endif /* __NM_VPN_CONNECTION_H__ */ diff --git a/src/core/vpn/nm-vpn-manager.c b/src/core/vpn/nm-vpn-manager.c index f30dba79..6bf8edae 100644 --- a/src/core/vpn/nm-vpn-manager.c +++ b/src/core/vpn/nm-vpn-manager.c @@ -15,7 +15,7 @@ #include "libnm-core-intern/nm-core-internal.h" typedef struct { - GSList * plugins; + GSList *plugins; GFileMonitor *monitor_etc; GFileMonitor *monitor_lib; gulong monitor_id_etc; @@ -44,9 +44,9 @@ G_DEFINE_TYPE(NMVpnManager, nm_vpn_manager, G_TYPE_OBJECT) static void vpn_state_changed(NMVpnConnection *vpn, GParamSpec *pspec, NMVpnManager *manager) { - NMVpnManagerPrivate * priv = NM_VPN_MANAGER_GET_PRIVATE(manager); + NMVpnManagerPrivate *priv = NM_VPN_MANAGER_GET_PRIVATE(manager); NMActiveConnectionState state = nm_active_connection_get_state(NM_ACTIVE_CONNECTION(vpn)); - const char * service_name = nm_vpn_connection_get_service(vpn); + const char *service_name = nm_vpn_connection_get_service(vpn); if (state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) { g_hash_table_remove(priv->active_services, service_name); @@ -59,9 +59,9 @@ gboolean nm_vpn_manager_activate_connection(NMVpnManager *manager, NMVpnConnection *vpn, GError **error) { NMVpnManagerPrivate *priv; - NMVpnPluginInfo * plugin_info; - const char * service_name; - NMDevice * device; + NMVpnPluginInfo *plugin_info; + const char *service_name; + NMDevice *device; g_return_val_if_fail(NM_IS_VPN_MANAGER(manager), FALSE); g_return_val_if_fail(NM_IS_VPN_CONNECTION(vpn), FALSE); @@ -121,7 +121,7 @@ static void try_add_plugin(NMVpnManager *self, NMVpnPluginInfo *plugin_info) { NMVpnManagerPrivate *priv = NM_VPN_MANAGER_GET_PRIVATE(self); - const char * program; + const char *program; program = nm_vpn_plugin_info_get_program(plugin_info); if (!program || !*program) @@ -138,17 +138,17 @@ try_add_plugin(NMVpnManager *self, NMVpnPluginInfo *plugin_info) } static void -vpn_dir_changed(GFileMonitor * monitor, - GFile * file, - GFile * other_file, +vpn_dir_changed(GFileMonitor *monitor, + GFile *file, + GFile *other_file, GFileMonitorEvent event_type, gpointer user_data) { - NMVpnManager * self = NM_VPN_MANAGER(user_data); + NMVpnManager *self = NM_VPN_MANAGER(user_data); NMVpnManagerPrivate *priv = NM_VPN_MANAGER_GET_PRIVATE(self); - NMVpnPluginInfo * plugin_info; - gs_free char * path = NULL; - GError * error = NULL; + NMVpnPluginInfo *plugin_info; + gs_free char *path = NULL; + GError *error = NULL; path = g_file_get_path(file); if (!nm_vpn_plugin_info_validate_filename(path)) @@ -207,10 +207,10 @@ static void nm_vpn_manager_init(NMVpnManager *self) { NMVpnManagerPrivate *priv = NM_VPN_MANAGER_GET_PRIVATE(self); - GFile * file; - GSList * infos, *info; - const char * conf_dir_etc = _nm_vpn_plugin_info_get_default_dir_etc(); - const char * conf_dir_lib = _nm_vpn_plugin_info_get_default_dir_lib(); + GFile *file; + GSList *infos, *info; + const char *conf_dir_etc = _nm_vpn_plugin_info_get_default_dir_etc(); + const char *conf_dir_lib = _nm_vpn_plugin_info_get_default_dir_lib(); /* Watch the VPN directory for changes */ file = g_file_new_for_path(conf_dir_lib); -- cgit 1.3.0-6-gf8a5